From 62b610a63e05fb5004473c0cbef0ddda8d42b471 Mon Sep 17 00:00:00 2001 From: Bruce Tian Date: Wed, 30 Oct 2024 09:45:47 -0700 Subject: [PATCH] chore(metrics): add metrics to identify who attempte to upgrade organization (#10432) --- .../graphql/public/mutations/createStripeSubscription.ts | 2 ++ packages/server/utils/analytics/analytics.ts | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/packages/server/graphql/public/mutations/createStripeSubscription.ts b/packages/server/graphql/public/mutations/createStripeSubscription.ts index 6b65428c4b2..c3754c0d2eb 100644 --- a/packages/server/graphql/public/mutations/createStripeSubscription.ts +++ b/packages/server/graphql/public/mutations/createStripeSubscription.ts @@ -1,4 +1,5 @@ import Stripe from 'stripe' +import {analytics} from '../../../utils/analytics/analytics' import {getUserId} from '../../../utils/authorization' import standardError from '../../../utils/standardError' import {getStripeManager} from '../../../utils/stripe' @@ -50,6 +51,7 @@ const createStripeSubscription: MutationResolvers['createStripeSubscription'] = const paymentIntent = latestInvoice.payment_intent as Stripe.PaymentIntent const clientSecret = paymentIntent.client_secret + analytics.organizationUpgradeAttempted(viewer, orgId) const data = {stripeSubscriptionClientSecret: clientSecret} return data } diff --git a/packages/server/utils/analytics/analytics.ts b/packages/server/utils/analytics/analytics.ts index 765e16efc66..28ff7432ab0 100644 --- a/packages/server/utils/analytics/analytics.ts +++ b/packages/server/utils/analytics/analytics.ts @@ -132,6 +132,7 @@ export type AnalyticsEvent = | 'Notification Email Sent' // org | 'Upgrade CTA Clicked' + | 'Organization Upgrade Attempted' | 'Organization Upgraded' | 'Downgrade Clicked' | 'Downgrade Continue Clicked' @@ -506,6 +507,10 @@ class Analytics { this.track(user, 'Upgrade CTA Clicked', {upgradeCTALocation}) } + organizationUpgradeAttempted = (user: AnalyticsUser, orgId: string) => { + this.track(user, 'Organization Upgrade Attempted', {orgId}) + } + organizationUpgraded = ( user: AnalyticsUser, upgradeEventProperties: OrgTierChangeEventProperties