feat: fire subscription_success telemetry on subscription activation

Wire trackMonthlySubscriptionSucceeded() into both subscription
detection paths so GTM receives a client-side subscription_success
event for ad platform conversion tags (LinkedIn, Meta):

- Legacy flow: SubscriptionRequiredDialogContent watcher
- Workspace flow: billingOperationStore.handleSuccess()

Uses subscription_success (not purchase) to avoid double-counting
with the server-side GA4 Measurement Protocol purchase event and
the existing Google Ads Purchase conversion tag in GTM.
This commit is contained in:
bymyself
2026-03-17 07:23:41 -07:00
parent 2af3940867
commit a391d89158
3 changed files with 45 additions and 0 deletions

View File

@@ -236,6 +236,7 @@ watch(
() => isActiveSubscription.value,
(isActive) => {
if (isActive && showCustomPricingTable.value) {
telemetry?.trackMonthlySubscriptionSucceeded()
emit('close', true)
}
}

View File

@@ -47,6 +47,14 @@ vi.mock('@/stores/dialogStore', () => ({
})
}))
const mockTrackMonthlySubscriptionSucceeded = vi.fn()
vi.mock('@/platform/telemetry', () => ({
useTelemetry: () => ({
trackMonthlySubscriptionSucceeded: mockTrackMonthlySubscriptionSucceeded
})
}))
import { workspaceApi } from '@/platform/workspace/api/workspaceApi'
import { useBillingOperationStore } from './billingOperationStore'
@@ -159,6 +167,37 @@ describe('billingOperationStore', () => {
})
})
it('fires purchase telemetry on subscription success', async () => {
vi.mocked(workspaceApi.getBillingOpStatus).mockResolvedValue({
id: 'op-1',
status: 'succeeded',
started_at: new Date().toISOString(),
completed_at: new Date().toISOString()
})
const store = useBillingOperationStore()
store.startOperation('op-1', 'subscription')
await vi.advanceTimersByTimeAsync(0)
expect(mockTrackMonthlySubscriptionSucceeded).toHaveBeenCalledOnce()
})
it('does not fire purchase telemetry on topup success', async () => {
vi.mocked(workspaceApi.getBillingOpStatus).mockResolvedValue({
id: 'op-1',
status: 'succeeded',
started_at: new Date().toISOString()
})
const store = useBillingOperationStore()
store.startOperation('op-1', 'topup')
await vi.advanceTimersByTimeAsync(0)
expect(mockTrackMonthlySubscriptionSucceeded).not.toHaveBeenCalled()
})
it('shows topup success message for topup operations', async () => {
vi.mocked(workspaceApi.getBillingOpStatus).mockResolvedValue({
id: 'op-1',

View File

@@ -4,6 +4,7 @@ import { computed, ref } from 'vue'
import { useBillingContext } from '@/composables/billing/useBillingContext'
import { t } from '@/i18n'
import { useTelemetry } from '@/platform/telemetry'
import { useToastStore } from '@/platform/updates/common/toastStore'
import { workspaceApi } from '@/platform/workspace/api/workspaceApi'
import { useSettingsDialog } from '@/platform/settings/composables/useSettingsDialog'
@@ -133,6 +134,10 @@ export const useBillingOperationStore = defineStore('billingOperation', () => {
updateOperationStatus(opId, 'succeeded', null)
cleanup(opId)
if (operation.type === 'subscription') {
useTelemetry()?.trackMonthlySubscriptionSucceeded()
}
const billingContext = useBillingContext()
await Promise.all([
billingContext.fetchStatus(),