From d38488b1526bca885f58325ac750db8074d5e6e4 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 21 May 2025 11:42:45 +0200 Subject: [PATCH] Feat: Add Intercom tracking events (#4780) --- .../header/WorkspaceSwitcher/ListItem.vue | 2 -- .../lib/billing/composables/actions.ts | 18 ++++++++++++++++-- .../lib/common/generated/gql/gql.ts | 6 +++--- .../lib/common/generated/gql/graphql.ts | 4 ++-- .../lib/intercom/graphql/queries.ts | 3 +++ .../lib/navigation/composables/navigation.ts | 2 ++ .../lib/workspaces/composables/wizard.ts | 14 ++++++++++---- .../frontend-2/plugins/intercom.client.ts | 19 ++++++++++++++++--- 8 files changed, 52 insertions(+), 16 deletions(-) diff --git a/packages/frontend-2/components/header/WorkspaceSwitcher/ListItem.vue b/packages/frontend-2/components/header/WorkspaceSwitcher/ListItem.vue index 950272ec8..9ec2a4d53 100644 --- a/packages/frontend-2/components/header/WorkspaceSwitcher/ListItem.vue +++ b/packages/frontend-2/components/header/WorkspaceSwitcher/ListItem.vue @@ -56,7 +56,6 @@ const props = defineProps<{ const { mutateActiveWorkspaceSlug, mutateIsProjectsActive, activeWorkspaceSlug } = useNavigation() -const { $intercom } = useNuxtApp() const formattedName = computed(() => props.name || props.workspace?.name || '') const tag = computed(() => { @@ -73,7 +72,6 @@ const onClick = () => { if (props.workspace) { navigateTo(workspaceRoute(props.workspace.slug)) mutateActiveWorkspaceSlug(props.workspace.slug) - $intercom.updateCompany() } else { mutateIsProjectsActive(true) navigateTo(projectsRoute) diff --git a/packages/frontend-2/lib/billing/composables/actions.ts b/packages/frontend-2/lib/billing/composables/actions.ts index 31c1a7f0e..3e0824c97 100644 --- a/packages/frontend-2/lib/billing/composables/actions.ts +++ b/packages/frontend-2/lib/billing/composables/actions.ts @@ -50,6 +50,7 @@ export const useBillingActions = () => { settingsBillingCancelCheckoutSessionMutation ) const logger = useLogger() + const { $intercom } = useNuxtApp() const billingPortalRedirect = async (workspaceId: MaybeNullOrUndefined) => { if (!workspaceId) { @@ -156,12 +157,18 @@ export const useBillingActions = () => { .catch(convertThrowIntoFetchResult) if (result.data) { - mixpanel.track('Workspace Upgraded', { + const metaData = { plan, cycle, // eslint-disable-next-line camelcase workspace_id: workspaceId + } + mixpanel.track('Workspace Upgraded', metaData) + $intercom.track('Workspace Upgraded', { + ...metaData, + isExistingSubscription: false }) + $intercom.updateCompany() triggerNotification({ type: ToastNotificationType.Success, @@ -212,12 +219,19 @@ export const useBillingActions = () => { title: 'Your workspace plan was successfully updated' }) - mixpanel.track('Workspace Upgraded', { + const metaData = { plan: workspace.plan?.name, cycle: workspace.subscription?.billingInterval, // eslint-disable-next-line camelcase workspace_id: workspace.id + } + + mixpanel.track('Workspace Upgraded', metaData) + $intercom.track('Workspace Upgraded', { + ...metaData, + isExistingSubscription: false }) + $intercom.updateCompany() } const currentQueryParams = { ...route.query } diff --git a/packages/frontend-2/lib/common/generated/gql/gql.ts b/packages/frontend-2/lib/common/generated/gql/gql.ts index 3f830fc00..f83c244b7 100644 --- a/packages/frontend-2/lib/common/generated/gql/gql.ts +++ b/packages/frontend-2/lib/common/generated/gql/gql.ts @@ -204,7 +204,7 @@ type Documents = { "\n query GendoAIRenders($versionId: String!, $projectId: String!) {\n project(id: $projectId) {\n id\n version(id: $versionId) {\n id\n gendoAIRenders {\n totalCount\n items {\n id\n createdAt\n updatedAt\n status\n gendoGenerationId\n prompt\n camera\n }\n }\n }\n }\n }\n": typeof types.GendoAiRendersDocument, "\n subscription ProjectVersionGendoAIRenderCreated($id: String!, $versionId: String!) {\n projectVersionGendoAIRenderCreated(id: $id, versionId: $versionId) {\n id\n createdAt\n updatedAt\n status\n gendoGenerationId\n prompt\n camera\n }\n }\n": typeof types.ProjectVersionGendoAiRenderCreatedDocument, "\n subscription ProjectVersionGendoAIRenderUpdated($id: String!, $versionId: String!) {\n projectVersionGendoAIRenderUpdated(id: $id, versionId: $versionId) {\n id\n projectId\n modelId\n versionId\n createdAt\n updatedAt\n gendoGenerationId\n status\n prompt\n camera\n responseImage\n }\n }\n": typeof types.ProjectVersionGendoAiRenderUpdatedDocument, - "\n query IntercomActiveWorkspace($slug: String!) {\n workspaceBySlug(slug: $slug) {\n id\n name\n plan {\n name\n status\n }\n subscription {\n createdAt\n updatedAt\n currentBillingCycleEnd\n }\n team {\n totalCount\n }\n }\n }\n": typeof types.IntercomActiveWorkspaceDocument, + "\n query IntercomActiveWorkspace($slug: String!) {\n workspaceBySlug(slug: $slug) {\n id\n name\n plan {\n name\n status\n }\n subscription {\n createdAt\n updatedAt\n currentBillingCycleEnd\n }\n team {\n totalCount\n }\n projects {\n totalCount\n }\n }\n }\n": typeof types.IntercomActiveWorkspaceDocument, "\n query InviteUserSearch($input: UsersRetrievalInput!) {\n users(input: $input) {\n items {\n id\n name\n avatar\n }\n }\n }\n": typeof types.InviteUserSearchDocument, "\n mutation CreateNewRegion($input: CreateServerRegionInput!) {\n serverInfoMutations {\n multiRegion {\n create(input: $input) {\n id\n ...SettingsServerRegionsAddEditDialog_ServerRegionItem\n ...SettingsServerRegionsTable_ServerRegionItem\n }\n }\n }\n }\n": typeof types.CreateNewRegionDocument, "\n mutation UpdateRegion($input: UpdateServerRegionInput!) {\n serverInfoMutations {\n multiRegion {\n update(input: $input) {\n id\n ...SettingsServerRegionsAddEditDialog_ServerRegionItem\n ...SettingsServerRegionsTable_ServerRegionItem\n }\n }\n }\n }\n": typeof types.UpdateRegionDocument, @@ -618,7 +618,7 @@ const documents: Documents = { "\n query GendoAIRenders($versionId: String!, $projectId: String!) {\n project(id: $projectId) {\n id\n version(id: $versionId) {\n id\n gendoAIRenders {\n totalCount\n items {\n id\n createdAt\n updatedAt\n status\n gendoGenerationId\n prompt\n camera\n }\n }\n }\n }\n }\n": types.GendoAiRendersDocument, "\n subscription ProjectVersionGendoAIRenderCreated($id: String!, $versionId: String!) {\n projectVersionGendoAIRenderCreated(id: $id, versionId: $versionId) {\n id\n createdAt\n updatedAt\n status\n gendoGenerationId\n prompt\n camera\n }\n }\n": types.ProjectVersionGendoAiRenderCreatedDocument, "\n subscription ProjectVersionGendoAIRenderUpdated($id: String!, $versionId: String!) {\n projectVersionGendoAIRenderUpdated(id: $id, versionId: $versionId) {\n id\n projectId\n modelId\n versionId\n createdAt\n updatedAt\n gendoGenerationId\n status\n prompt\n camera\n responseImage\n }\n }\n": types.ProjectVersionGendoAiRenderUpdatedDocument, - "\n query IntercomActiveWorkspace($slug: String!) {\n workspaceBySlug(slug: $slug) {\n id\n name\n plan {\n name\n status\n }\n subscription {\n createdAt\n updatedAt\n currentBillingCycleEnd\n }\n team {\n totalCount\n }\n }\n }\n": types.IntercomActiveWorkspaceDocument, + "\n query IntercomActiveWorkspace($slug: String!) {\n workspaceBySlug(slug: $slug) {\n id\n name\n plan {\n name\n status\n }\n subscription {\n createdAt\n updatedAt\n currentBillingCycleEnd\n }\n team {\n totalCount\n }\n projects {\n totalCount\n }\n }\n }\n": types.IntercomActiveWorkspaceDocument, "\n query InviteUserSearch($input: UsersRetrievalInput!) {\n users(input: $input) {\n items {\n id\n name\n avatar\n }\n }\n }\n": types.InviteUserSearchDocument, "\n mutation CreateNewRegion($input: CreateServerRegionInput!) {\n serverInfoMutations {\n multiRegion {\n create(input: $input) {\n id\n ...SettingsServerRegionsAddEditDialog_ServerRegionItem\n ...SettingsServerRegionsTable_ServerRegionItem\n }\n }\n }\n }\n": types.CreateNewRegionDocument, "\n mutation UpdateRegion($input: UpdateServerRegionInput!) {\n serverInfoMutations {\n multiRegion {\n update(input: $input) {\n id\n ...SettingsServerRegionsAddEditDialog_ServerRegionItem\n ...SettingsServerRegionsTable_ServerRegionItem\n }\n }\n }\n }\n": types.UpdateRegionDocument, @@ -1619,7 +1619,7 @@ export function graphql(source: "\n subscription ProjectVersionGendoAIRenderUpd /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function graphql(source: "\n query IntercomActiveWorkspace($slug: String!) {\n workspaceBySlug(slug: $slug) {\n id\n name\n plan {\n name\n status\n }\n subscription {\n createdAt\n updatedAt\n currentBillingCycleEnd\n }\n team {\n totalCount\n }\n }\n }\n"): (typeof documents)["\n query IntercomActiveWorkspace($slug: String!) {\n workspaceBySlug(slug: $slug) {\n id\n name\n plan {\n name\n status\n }\n subscription {\n createdAt\n updatedAt\n currentBillingCycleEnd\n }\n team {\n totalCount\n }\n }\n }\n"]; +export function graphql(source: "\n query IntercomActiveWorkspace($slug: String!) {\n workspaceBySlug(slug: $slug) {\n id\n name\n plan {\n name\n status\n }\n subscription {\n createdAt\n updatedAt\n currentBillingCycleEnd\n }\n team {\n totalCount\n }\n projects {\n totalCount\n }\n }\n }\n"): (typeof documents)["\n query IntercomActiveWorkspace($slug: String!) {\n workspaceBySlug(slug: $slug) {\n id\n name\n plan {\n name\n status\n }\n subscription {\n createdAt\n updatedAt\n currentBillingCycleEnd\n }\n team {\n totalCount\n }\n projects {\n totalCount\n }\n }\n }\n"]; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/packages/frontend-2/lib/common/generated/gql/graphql.ts b/packages/frontend-2/lib/common/generated/gql/graphql.ts index 038649ebf..3a4103abc 100644 --- a/packages/frontend-2/lib/common/generated/gql/graphql.ts +++ b/packages/frontend-2/lib/common/generated/gql/graphql.ts @@ -5762,7 +5762,7 @@ export type IntercomActiveWorkspaceQueryVariables = Exact<{ }>; -export type IntercomActiveWorkspaceQuery = { __typename?: 'Query', workspaceBySlug: { __typename?: 'Workspace', id: string, name: string, plan?: { __typename?: 'WorkspacePlan', name: WorkspacePlans, status: WorkspacePlanStatuses } | null, subscription?: { __typename?: 'WorkspaceSubscription', createdAt: string, updatedAt: string, currentBillingCycleEnd: string } | null, team: { __typename?: 'WorkspaceCollaboratorCollection', totalCount: number } } }; +export type IntercomActiveWorkspaceQuery = { __typename?: 'Query', workspaceBySlug: { __typename?: 'Workspace', id: string, name: string, plan?: { __typename?: 'WorkspacePlan', name: WorkspacePlans, status: WorkspacePlanStatuses } | null, subscription?: { __typename?: 'WorkspaceSubscription', createdAt: string, updatedAt: string, currentBillingCycleEnd: string } | null, team: { __typename?: 'WorkspaceCollaboratorCollection', totalCount: number }, projects: { __typename?: 'ProjectCollection', totalCount: number } } }; export type InviteUserSearchQueryVariables = Exact<{ input: UsersRetrievalInput; @@ -7380,7 +7380,7 @@ export const GendoAiRenderDocument = {"kind":"Document","definitions":[{"kind":" export const GendoAiRendersDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"GendoAIRenders"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"versionId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"projectId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"project"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"projectId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"version"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"versionId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"gendoAIRenders"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"totalCount"}},{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"gendoGenerationId"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"camera"}}]}}]}}]}}]}}]}}]} as unknown as DocumentNode; export const ProjectVersionGendoAiRenderCreatedDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"subscription","name":{"kind":"Name","value":"ProjectVersionGendoAIRenderCreated"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"versionId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"projectVersionGendoAIRenderCreated"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}},{"kind":"Argument","name":{"kind":"Name","value":"versionId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"versionId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"gendoGenerationId"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"camera"}}]}}]}}]} as unknown as DocumentNode; export const ProjectVersionGendoAiRenderUpdatedDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"subscription","name":{"kind":"Name","value":"ProjectVersionGendoAIRenderUpdated"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"id"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}},{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"versionId"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"projectVersionGendoAIRenderUpdated"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"id"},"value":{"kind":"Variable","name":{"kind":"Name","value":"id"}}},{"kind":"Argument","name":{"kind":"Name","value":"versionId"},"value":{"kind":"Variable","name":{"kind":"Name","value":"versionId"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"projectId"}},{"kind":"Field","name":{"kind":"Name","value":"modelId"}},{"kind":"Field","name":{"kind":"Name","value":"versionId"}},{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"gendoGenerationId"}},{"kind":"Field","name":{"kind":"Name","value":"status"}},{"kind":"Field","name":{"kind":"Name","value":"prompt"}},{"kind":"Field","name":{"kind":"Name","value":"camera"}},{"kind":"Field","name":{"kind":"Name","value":"responseImage"}}]}}]}}]} as unknown as DocumentNode; -export const IntercomActiveWorkspaceDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"IntercomActiveWorkspace"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"slug"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"workspaceBySlug"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"slug"},"value":{"kind":"Variable","name":{"kind":"Name","value":"slug"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"plan"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"status"}}]}},{"kind":"Field","name":{"kind":"Name","value":"subscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"currentBillingCycleEnd"}}]}},{"kind":"Field","name":{"kind":"Name","value":"team"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"totalCount"}}]}}]}}]}}]} as unknown as DocumentNode; +export const IntercomActiveWorkspaceDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"IntercomActiveWorkspace"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"slug"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"String"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"workspaceBySlug"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"slug"},"value":{"kind":"Variable","name":{"kind":"Name","value":"slug"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"plan"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"status"}}]}},{"kind":"Field","name":{"kind":"Name","value":"subscription"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"createdAt"}},{"kind":"Field","name":{"kind":"Name","value":"updatedAt"}},{"kind":"Field","name":{"kind":"Name","value":"currentBillingCycleEnd"}}]}},{"kind":"Field","name":{"kind":"Name","value":"team"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"totalCount"}}]}},{"kind":"Field","name":{"kind":"Name","value":"projects"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"totalCount"}}]}}]}}]}}]} as unknown as DocumentNode; export const InviteUserSearchDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"query","name":{"kind":"Name","value":"InviteUserSearch"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UsersRetrievalInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"users"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"items"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"avatar"}}]}}]}}]}}]} as unknown as DocumentNode; export const CreateNewRegionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"CreateNewRegion"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"CreateServerRegionInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"serverInfoMutations"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"multiRegion"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"create"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"FragmentSpread","name":{"kind":"Name","value":"SettingsServerRegionsAddEditDialog_ServerRegionItem"}},{"kind":"FragmentSpread","name":{"kind":"Name","value":"SettingsServerRegionsTable_ServerRegionItem"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SettingsServerRegionsAddEditDialog_ServerRegionItem"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerRegionItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"key"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SettingsServerRegionsTable_ServerRegionItem"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerRegionItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"description"}}]}}]} as unknown as DocumentNode; export const UpdateRegionDocument = {"kind":"Document","definitions":[{"kind":"OperationDefinition","operation":"mutation","name":{"kind":"Name","value":"UpdateRegion"},"variableDefinitions":[{"kind":"VariableDefinition","variable":{"kind":"Variable","name":{"kind":"Name","value":"input"}},"type":{"kind":"NonNullType","type":{"kind":"NamedType","name":{"kind":"Name","value":"UpdateServerRegionInput"}}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"serverInfoMutations"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"multiRegion"},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"update"},"arguments":[{"kind":"Argument","name":{"kind":"Name","value":"input"},"value":{"kind":"Variable","name":{"kind":"Name","value":"input"}}}],"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"FragmentSpread","name":{"kind":"Name","value":"SettingsServerRegionsAddEditDialog_ServerRegionItem"}},{"kind":"FragmentSpread","name":{"kind":"Name","value":"SettingsServerRegionsTable_ServerRegionItem"}}]}}]}}]}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SettingsServerRegionsAddEditDialog_ServerRegionItem"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerRegionItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"description"}},{"kind":"Field","name":{"kind":"Name","value":"key"}}]}},{"kind":"FragmentDefinition","name":{"kind":"Name","value":"SettingsServerRegionsTable_ServerRegionItem"},"typeCondition":{"kind":"NamedType","name":{"kind":"Name","value":"ServerRegionItem"}},"selectionSet":{"kind":"SelectionSet","selections":[{"kind":"Field","name":{"kind":"Name","value":"id"}},{"kind":"Field","name":{"kind":"Name","value":"name"}},{"kind":"Field","name":{"kind":"Name","value":"key"}},{"kind":"Field","name":{"kind":"Name","value":"description"}}]}}]} as unknown as DocumentNode; diff --git a/packages/frontend-2/lib/intercom/graphql/queries.ts b/packages/frontend-2/lib/intercom/graphql/queries.ts index a51d50a02..f75f89c9b 100644 --- a/packages/frontend-2/lib/intercom/graphql/queries.ts +++ b/packages/frontend-2/lib/intercom/graphql/queries.ts @@ -17,6 +17,9 @@ export const intercomActiveWorkspaceQuery = graphql(` team { totalCount } + projects { + totalCount + } } } `) diff --git a/packages/frontend-2/lib/navigation/composables/navigation.ts b/packages/frontend-2/lib/navigation/composables/navigation.ts index 45455e2c4..11d06428e 100644 --- a/packages/frontend-2/lib/navigation/composables/navigation.ts +++ b/packages/frontend-2/lib/navigation/composables/navigation.ts @@ -13,6 +13,7 @@ export const useNavigationState = () => export const useNavigation = () => { const state = useNavigationState() const { mutate } = useMutation(setActiveWorkspaceMutation) + const { $intercom } = useNuxtApp() const activeWorkspaceSlug = computed({ get: () => state.value.activeWorkspaceSlug, @@ -28,6 +29,7 @@ export const useNavigation = () => { state.value.activeWorkspaceSlug = newVal state.value.isProjectsActive = false await mutate({ slug: newVal, isProjectsActive: false }) + $intercom.updateCompany() } const mutateIsProjectsActive = async (isActive: boolean) => { diff --git a/packages/frontend-2/lib/workspaces/composables/wizard.ts b/packages/frontend-2/lib/workspaces/composables/wizard.ts index e01587d0c..744030f78 100644 --- a/packages/frontend-2/lib/workspaces/composables/wizard.ts +++ b/packages/frontend-2/lib/workspaces/composables/wizard.ts @@ -66,6 +66,7 @@ export const useWorkspacesWizard = () => { updateWorkspaceCreationStateMutation ) const { mutateActiveWorkspaceSlug } = useNavigation() + const { $intercom } = useNuxtApp() const isLoading = computed({ get: () => wizardState.value.isLoading, @@ -272,18 +273,23 @@ export const useWorkspacesWizard = () => { ).catch(convertThrowIntoFetchResult) if (result?.data?.workspaceMutations.updateCreationState) { - mixpanel.track('Workspace Created', { + const metaPayload = { plan: state.plan, billingInterval: state.billingInterval, source: 'wizard', + // eslint-disable-next-line camelcase + workspace_id: workspaceId + } + + mixpanel.track('Workspace Created', { + ...metaPayload, fields: Object.keys(state).filter( (key) => key !== 'id' && (key !== 'invites' || (state.invites && state.invites.length > 0)) - ) as Array, - // eslint-disable-next-line camelcase - workspace_id: workspaceId + ) as Array }) + $intercom.track('Workspace Created', metaPayload) } if ( diff --git a/packages/frontend-2/plugins/intercom.client.ts b/packages/frontend-2/plugins/intercom.client.ts index b47639eb2..7f99a28ae 100644 --- a/packages/frontend-2/plugins/intercom.client.ts +++ b/packages/frontend-2/plugins/intercom.client.ts @@ -2,7 +2,13 @@ import { useOnAuthStateChange } from '~/lib/auth/composables/auth' import { useIsWorkspacesEnabled } from '~/composables/globals' import { useNavigation } from '~/lib/navigation/composables/navigation' import { watch, computed, ref } from 'vue' -import Intercom, { shutdown, show, hide, update } from '@intercom/messenger-js-sdk' +import Intercom, { + shutdown, + show, + hide, + update, + trackEvent +} from '@intercom/messenger-js-sdk' import { useApolloClient } from '@vue/apollo-composable' import { intercomActiveWorkspaceQuery } from '~~/lib/intercom/graphql/queries' @@ -78,9 +84,14 @@ export const useIntercom = () => { isInitialized.value = false } + const trackIntercom = (event: string, metadata?: Record) => { + if (!isInitialized.value) return + trackEvent(event, metadata) + } + // Fetch active workspace and add to the user as a company const updateCompany = async () => { - if (!activeWorkspaceSlug.value) return + if (!activeWorkspaceSlug.value || !isInitialized.value) return const workspace = await apollo.query({ query: intercomActiveWorkspaceQuery, @@ -95,8 +106,9 @@ export const useIntercom = () => { company: { id: workspace.data?.workspaceBySlug.id, name: workspace.data?.workspaceBySlug.name, - people: workspace.data?.workspaceBySlug.team?.totalCount, /* eslint-disable camelcase */ + project_count: workspace.data?.workspaceBySlug.projects?.totalCount, + team_count: workspace.data?.workspaceBySlug.team?.totalCount, plan_name: workspace.data?.workspaceBySlug.plan?.name, plan_status: workspace.data?.workspaceBySlug.plan?.status, subscription_created_at: @@ -131,6 +143,7 @@ export const useIntercom = () => { show: showIntercom, hide: hideIntercom, shutdown: shutdownIntercom, + track: trackIntercom, updateCompany } }