-
Notifications
You must be signed in to change notification settings - Fork 494
[backport cloud/1.38] telemetry: route GTM, reactive begin_checkout user_id, and Impact attribution #8813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[backport cloud/1.38] telemetry: route GTM, reactive begin_checkout user_id, and Impact attribution #8813
Changes from all commits
090da3e
d44924a
ebc57e7
4367aea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| name: 'CI: Dist Telemetry Scan' | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches-ignore: [wip/*, draft/*, temp/*] | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| scan: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | ||
|
|
||
| - name: Install pnpm | ||
| uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0 | ||
| with: | ||
| version: 10 | ||
|
|
||
| - name: Use Node.js | ||
| uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0 | ||
| with: | ||
| node-version: 'lts/*' | ||
| cache: 'pnpm' | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Build project | ||
| run: pnpm build | ||
|
|
||
| - name: Scan dist for telemetry references | ||
| run: | | ||
| set -euo pipefail | ||
| if rg --no-ignore -n \ | ||
| -g '*.html' \ | ||
| -g '*.js' \ | ||
| -e 'Google Tag Manager' \ | ||
| -e '(?i)\bgtm\.js\b' \ | ||
| -e '(?i)googletagmanager\.com/gtm\.js\\?id=' \ | ||
| -e '(?i)googletagmanager\.com/ns\.html\\?id=' \ | ||
| dist; then | ||
| echo 'Telemetry references found in dist assets.' | ||
| exit 1 | ||
| fi | ||
| echo 'No telemetry references found in dist assets.' | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -243,6 +243,7 @@ | |
|
|
||
| <script setup lang="ts"> | ||
| import { cn } from '@comfyorg/tailwind-utils' | ||
| import { storeToRefs } from 'pinia' | ||
| import Popover from 'primevue/popover' | ||
| import SelectButton from 'primevue/selectbutton' | ||
| import type { ToggleButtonPassThroughMethodOptions } from 'primevue/togglebutton' | ||
|
|
@@ -266,6 +267,9 @@ import { performSubscriptionCheckout } from '@/platform/cloud/subscription/utils | |
| import { isPlanDowngrade } from '@/platform/cloud/subscription/utils/subscriptionTierRank' | ||
| import type { BillingCycle } from '@/platform/cloud/subscription/utils/subscriptionTierRank' | ||
| import { isCloud } from '@/platform/distribution/types' | ||
| import { useTelemetry } from '@/platform/telemetry' | ||
| import type { CheckoutAttributionMetadata } from '@/platform/telemetry/types' | ||
| import { useFirebaseAuthStore } from '@/stores/firebaseAuthStore' | ||
| import type { components } from '@/types/comfyRegistryTypes' | ||
|
|
||
| type SubscriptionTier = components['schemas']['SubscriptionTier'] | ||
|
|
@@ -277,6 +281,19 @@ const getCheckoutTier = ( | |
| billingCycle: BillingCycle | ||
| ): CheckoutTier => (billingCycle === 'yearly' ? `${tierKey}-yearly` : tierKey) | ||
|
|
||
| const getCheckoutAttributionForCloud = | ||
| async (): Promise<CheckoutAttributionMetadata> => { | ||
| // eslint-disable-next-line no-undef | ||
| if (__DISTRIBUTION__ !== 'cloud') { | ||
| return {} | ||
| } | ||
|
|
||
| const { getCheckoutAttribution } = | ||
| await import('@/platform/telemetry/utils/checkoutAttribution') | ||
|
|
||
| return getCheckoutAttribution() | ||
| } | ||
|
|
||
| interface BillingCycleOption { | ||
| label: string | ||
| value: BillingCycle | ||
|
|
@@ -330,6 +347,8 @@ const tiers: PricingTierConfig[] = [ | |
| const { n } = useI18n() | ||
| const { isActiveSubscription, subscriptionTier, isYearlySubscription } = | ||
| useSubscription() | ||
| const telemetry = useTelemetry() | ||
| const { userId } = storeToRefs(useFirebaseAuthStore()) | ||
| const { accessBillingPortal, reportError } = useFirebaseAuthActions() | ||
| const { wrapWithErrorHandlingAsync } = useErrorHandling() | ||
|
|
||
|
|
@@ -410,6 +429,19 @@ const handleSubscribe = wrapWithErrorHandlingAsync( | |
|
|
||
| try { | ||
| if (isActiveSubscription.value) { | ||
| const checkoutAttribution = await getCheckoutAttributionForCloud() | ||
| if (userId.value) { | ||
| telemetry?.trackBeginCheckout({ | ||
| user_id: userId.value, | ||
|
Comment on lines
431
to
+435
|
||
| tier: tierKey, | ||
| cycle: currentBillingCycle.value, | ||
| checkout_type: 'change', | ||
| ...checkoutAttribution, | ||
| ...(currentTierKey.value | ||
| ? { previous_tier: currentTierKey.value } | ||
| : {}) | ||
| }) | ||
| } | ||
| // Pass the target tier to create a deep link to subscription update confirmation | ||
| const checkoutTier = getCheckoutTier(tierKey, currentBillingCycle.value) | ||
| const targetPlan = { | ||
|
|
@@ -430,7 +462,11 @@ const handleSubscribe = wrapWithErrorHandlingAsync( | |
| await accessBillingPortal(checkoutTier) | ||
| } | ||
| } else { | ||
| await performSubscriptionCheckout(tierKey, currentBillingCycle.value) | ||
| await performSubscriptionCheckout( | ||
| tierKey, | ||
| currentBillingCycle.value, | ||
| true | ||
| ) | ||
| } | ||
| } finally { | ||
| isLoading.value = false | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Calling
initTelemetry()here runs provider constructors beforecreatePinia()/app.use(pinia), butMixpanelTelemetryProvider'sloadedcallback invokesuseCurrentUser()(which immediately calls Pinia stores). In cloud builds with a Mixpanel token, that callback can throw "no active Pinia", causing the provider's import chain to hit its error path and disable Mixpanel tracking for the session.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I want to fix this in main, then backport that PR instead of fixing it here:
a. Per Impact's technical guide, we only need the generated ref for subscription attribution. And Pinia only provides the fallback as customerId + customerEmail