Skip to content

Commit bd145ca

Browse files
committed
Add grouping
1 parent a73c2b3 commit bd145ca

File tree

6 files changed

+31
-6
lines changed

6 files changed

+31
-6
lines changed

packages/app/src/app/overmind/actions.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,15 @@ export const refetchSandboxInfo: AsyncAction = async ({
244244
await actions.editor.internal.initializeSandbox(sandbox);
245245
};
246246

247-
export const acceptTeamInvitation: Action<{ teamName: string }> = (
248-
{ effects },
249-
{ teamName }
250-
) => {
247+
export const acceptTeamInvitation: Action<{
248+
teamName: string;
249+
teamId: string;
250+
}> = ({ effects }, { teamName, teamId }) => {
251251
effects.analytics.track('Team - Invitation Accepted', {});
252252

253+
effects.analytics.setGroup('teamName', teamName);
254+
effects.analytics.setGroup('teamId', teamId);
255+
253256
effects.notificationToast.success(`Accepted invitation to ${teamName}`);
254257
};
255258

packages/app/src/app/overmind/effects/analytics.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import track, {
33
logError,
44
setAnonymousId,
55
setUserId,
6+
setGroup,
67
} from '@codesandbox/common/lib/utils/analytics';
78

89
export default (() => {
@@ -21,5 +22,6 @@ export default (() => {
2122
identify,
2223
setAnonymousId,
2324
setUserId,
25+
setGroup,
2426
};
2527
})();

packages/app/src/app/pages/Dashboard/Content/routes/CreateTeam/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Mutation } from 'react-apollo';
33

44
import Input from '@codesandbox/common/lib/components/Input';
55
import { Button } from '@codesandbox/common/lib/components/Button';
6-
import track from '@codesandbox/common/lib/utils/analytics';
6+
import track, { setGroup } from '@codesandbox/common/lib/utils/analytics';
77
import history from 'app/utils/history';
88
import { teamOverviewUrl } from '@codesandbox/common/lib/utils/url-generator';
99
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
@@ -88,6 +88,9 @@ export default class CreateTeam extends React.PureComponent {
8888
});
8989
},
9090
}).then(({ data }) => {
91+
setGroup('teamName', data.createTeam.name);
92+
setGroup('teamId', data.createTeam.id);
93+
9194
notificationState.addNotification({
9295
message: `Succesfully created team '${data.createTeam.name}'`,
9396
status: NotificationStatus.SUCCESS,

packages/app/src/app/pages/common/Navigation/Notifications/notifications/TeamInvite.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export const TeamInvite: FunctionComponent<Props> = ({
6161
mutation={ACCEPT_TEAM_INVITATION}
6262
refetchQueries={['RecentNotifications', 'TeamsSidebar']}
6363
onCompleted={() => {
64-
acceptTeamInvitation({ teamName });
64+
acceptTeamInvitation({ teamName, teamId });
6565

6666
history.push(teamOverviewUrl(teamId));
6767
}}

packages/common/src/utils/analytics/amplitude.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,3 +107,11 @@ export const track = async (eventName: string, data: any) => {
107107
);
108108
}
109109
};
110+
111+
export const setGroup = async (group: string, value: string | string[]) => {
112+
const amplitude = await getAmplitude();
113+
if (amplitude) {
114+
debug('[Amplitude] Grouping', group, value);
115+
amplitude.setGroup(group, value);
116+
}
117+
};

packages/common/src/utils/analytics/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@ export function trackPageview() {
8787
}
8888
}
8989

90+
/**
91+
* Assign the user to a group. Can be multiple under one key.
92+
*/
93+
export function setGroup(name: string, value: string | string[]) {
94+
if (!DO_NOT_TRACK_ENABLED) {
95+
amplitude.setGroup(name, value);
96+
}
97+
}
98+
9099
export default function track(eventName, secondArg: Object = {}) {
91100
if (!DO_NOT_TRACK_ENABLED && isAllowedEvent(eventName, secondArg)) {
92101
const data = {

0 commit comments

Comments
 (0)