Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
5ae4c8d
feat(billing): add the checkout challenge events to the shared teleme…
dante01yoon Oct 2, 2026
c8d44b5
test(billing): expect the lifecycle to report challenges and retryabl…
dante01yoon Oct 2, 2026
8c37a94
feat(billing): report 3DS challenges and retryable declines from the …
dante01yoon Oct 2, 2026
70fb051
feat(billing): add the hosted redirect events to the shared telemetry…
dante01yoon Oct 2, 2026
6de149d
test(billing): expect hosted steps and the return from them to be rep…
dante01yoon Oct 2, 2026
62e449c
feat(billing): report hosted redirects and the return from them on bo…
dante01yoon Oct 2, 2026
203943a
style(billing): format the hosted step return report
dante01yoon Oct 2, 2026
67d5cf8
fix(billing): report a later decline after an echoed failed challenge
dante01yoon Oct 3, 2026
b01782f
Merge branch 'fe3119-1' into fe3119-2
dante01yoon Oct 3, 2026
38f5b4d
refactor(billing): split hosted-step reporting branches and unexport …
dante01yoon Oct 3, 2026
8814fe1
FE-3119 feat(billing-web): report an abandoned checkout and the endin…
dante01yoon Oct 3, 2026
abda3fe
Merge remote-tracking branch 'origin/main' into jaewon/fe-3119-cloud-…
dante01yoon Oct 3, 2026
7952ab7
feat(billing): add the dialog_close exit to the shared checkout journ…
dante01yoon Oct 3, 2026
288f05d
test(billing): expect cloud checkout dialogs to report where an unbou…
dante01yoon Oct 3, 2026
dbb4092
Merge remote-tracking branch 'origin/main' into fe3119-2
dante01yoon Oct 3, 2026
0befcf7
feat(billing): report where a cloud checkout dialog left a journey wi…
dante01yoon Oct 3, 2026
54eef8c
Merge remote-tracking branch 'origin/jaewon/fe-3119-payment-friction-…
dante01yoon Oct 3, 2026
03d073f
test(billing-web): expect an abandon before a provider handoff and af…
dante01yoon Oct 3, 2026
0688712
fix(billing-web): reopen the journey after a retried ending and count…
dante01yoon Oct 3, 2026
001fb64
test(billing): open the hosted page into the real window instead of a…
dante01yoon Oct 3, 2026
d167ad2
Merge remote-tracking branch 'origin/main' into work-19947
dante01yoon Oct 3, 2026
7d702d9
Merge remote-tracking branch 'origin/jaewon/fe-3119-payment-friction-…
dante01yoon Oct 3, 2026
4168df7
fix(billing-web): report an abandon after coming back from a hosted step
dante01yoon Oct 3, 2026
40a1616
Merge remote-tracking branch 'origin/jaewon/fe-3119-payment-friction-…
dante01yoon Oct 3, 2026
bd719ed
Merge remote-tracking branch 'origin/main' into work-19975
dante01yoon Oct 3, 2026
2290288
test(billing): spell out the phase sequence in each cloud checkout ex…
dante01yoon Oct 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ type CheckoutJourneyProgressEvent =
| CheckoutJourneySubmitted
| CheckoutJourneyOperationLinked

/** How the customer left: the page went away, or a control of this page led out. */
export type CheckoutExit = 'page_exit' | 'back' | 'close' | 'host_link'
/** How the customer left: the page went away, a control of this page led out, or the cloud app's checkout dialog closed. */
export type CheckoutExit =
| 'page_exit'
| 'back'
| 'close'
| 'host_link'
| 'dialog_close'
/** The ending screens of the full-page checkout. */
export type CheckoutEndingKind =
| 'success'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1191,6 +1191,38 @@ describe('PostHogTelemetryProvider', () => {
)
})

it.for([
{
exit: 'page_exit',
options: [{ transport: 'sendBeacon', send_instantly: true }]
},
{ exit: 'dialog_close', options: [] }
] as const)(
'captures a checkout abandoned at $exit with the matching transport',
async ({ exit, options }) => {
const provider = createProvider()
const event = {
checkout_journey_id: 'journey-1',
checkout_entered_at: '2026-10-01T00:00:00.000Z',
assignment_status: 'unavailable',
entry_flow: 'topup',
entry_source: 'settings_billing',
phase: 'abandoned',
last_phase: 'entered',
exit
} satisfies CheckoutJourneyTelemetryEvent
await vi.dynamicImportSettled()

provider.trackCheckoutJourneyEvent(event)

expect(hoisted.mockCapture).toHaveBeenCalledWith(
'billing.checkout.abandoned',
{ ...event, schema_version: 1, billing_surface: 'cloud_app' },
...options
)
}
)

it('captures widget favorite toggled events with their metadata', async () => {
const provider = createProvider()
await vi.dynamicImportSettled()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,10 +526,13 @@ export class PostHogTelemetryProvider implements TelemetryProvider {
}

trackCheckoutJourneyEvent(event: CheckoutJourneyTelemetryEvent): void {
this.trackEvent(
getCheckoutJourneyTelemetryEventName(event),
getCloudAppCheckoutJourneyTelemetryEventPayload(event)
)
const name = getCheckoutJourneyTelemetryEventName(event)
const payload = getCloudAppCheckoutJourneyTelemetryEventPayload(event)
if (event.phase === 'abandoned' && event.exit === 'page_exit') {
this.captureOnTeardown(name, payload)
return
}
this.trackEvent(name, payload)
}

trackAgentPaywallShown(metadata: AgentPaywallShownMetadata): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,15 @@ import { useI18n } from 'vue-i18n'
import type { TeamPlanSelection } from '@/platform/cloud/subscription/constants/teamPlanCreditStops'
import type { TierKey } from '@/platform/cloud/subscription/constants/tierPricing'
import type { BillingCycle } from '@/platform/cloud/subscription/utils/subscriptionTierRank'
import { useTelemetry } from '@/platform/telemetry'
import type {
BillingAuthenticationState,
PreviewSubscribeResponse,
SavedPaymentMethod
} from '@/platform/workspace/api/workspaceApi'
import { resolveStripePublishableKey } from '@/platform/workspace/billing/stripePublishableKey'
import { useCheckoutCopy } from '@/platform/workspace/composables/useCheckoutCopy'
import {
getActiveCheckoutJourney,
toCheckoutJourneyContext
} from '@/platform/workspace/utils/checkoutJourney'
import { getActiveCheckoutJourney } from '@/platform/workspace/utils/checkoutJourney'
import { trackCheckoutJourneyPhase } from '@/platform/workspace/utils/checkoutJourneyTelemetry'
import { useColorPaletteStore } from '@/stores/workspace/colorPaletteStore'

interface Props {
Expand Down Expand Up @@ -111,7 +108,6 @@ const selectedSavedMethodId = defineModel<string | null>(

const { locale } = useI18n()
const { copy, checkoutPlan } = useCheckoutCopy()
const telemetry = useTelemetry()
const colorPaletteStore = useColorPaletteStore()

const publishableKey = resolveStripePublishableKey() ?? ''
Expand All @@ -123,9 +119,6 @@ function emitPaymentJourneyPhase(phase: StripePaymentPhase): void {
// the active journey is still the one this checkout started.
const journey = getActiveCheckoutJourney()
if (!journey) return
telemetry?.trackCheckoutJourneyEvent({
...toCheckoutJourneyContext(journey),
...phase
})
trackCheckoutJourneyPhase(journey, phase)
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,68 @@ describe('TopUpCreditsDialogContentWorkspace', () => {
expect(getActiveCheckoutJourney()?.billing_op_id).toBeUndefined()
})

describe('checkout exit', () => {
function abandonedEvents() {
return (
vi.mocked(useTelemetry()?.trackCheckoutJourneyEvent)?.mock.calls ?? []
)
.map(([event]) => event)
.filter((event) => event.phase === 'abandoned')
}

it.for([
{ exit: 'dialog_close', leave: (unmount: () => void) => unmount() },
{
exit: 'page_exit',
leave: () => window.dispatchEvent(new Event('pagehide'))
}
] as const)(
'reports a $exit from a top-up with no operation',
async ({ exit, leave }) => {
const { unmount } = renderDialog()
await nextTick()

leave(unmount)

expect(abandonedEvents()).toEqual([
expect.objectContaining({
entry_flow: 'topup',
last_phase: 'entered',
exit
})
])
}
)

it('reports the close once when the page goes away afterwards', async () => {
const { unmount } = renderDialog()
await nextTick()

unmount()
window.dispatchEvent(new Event('pagehide'))

expect(abandonedEvents().map((event) => event.exit)).toEqual([
'dialog_close'
])
})

it('reports no exit once the purchase linked an operation', async () => {
vi.mocked(mockBillingContext().topup).mockResolvedValue(
topupResponse('pending')
)
const { unmount } = renderDialog()
await clickAddCredits()
await userEvent.click(screen.getByRole('button', { name: 'Pay $50.00' }))
await waitFor(() =>
expect(getActiveCheckoutJourney()?.billing_op_id).toBe('op-1')
)

unmount()

expect(abandonedEvents()).toEqual([])
})
})

it('reports failure telemetry when topup resolves with no response', async () => {
renderDialog()
await clickAddCredits()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,7 @@
</template>

<script setup lang="ts">
import type {
BillingOperationTerminal,
CheckoutJourneyPhaseEvent
} from '@comfyorg/account-core/billing'
import type { BillingOperationTerminal } from '@comfyorg/account-core/billing'
import {
getTopupAmountPreset,
TOPUP_AMOUNT_PRESETS_USD
Expand Down Expand Up @@ -339,10 +336,12 @@ import {
getActiveCheckoutJourney,
resolveCheckoutAssignment,
resolveCheckoutJourney,
resolveEntrySource,
toCheckoutJourneyContext
resolveEntrySource
} from '@/platform/workspace/utils/checkoutJourney'
import type { CheckoutJourneyRecord } from '@/platform/workspace/utils/checkoutJourney'
import {
trackCheckoutJourneyPhase,
useCheckoutJourneyExit
} from '@/platform/workspace/utils/checkoutJourneyTelemetry'
import { api } from '@/scripts/api'
import { useAuthStore } from '@/stores/authStore'
import { useDialogStore } from '@/stores/dialogStore'
Expand All @@ -364,16 +363,6 @@ const { canTopUp } = useBillingCapabilities()

const workspaceStore = useTeamWorkspaceStore()

function emitTopupJourneyPhase(
record: CheckoutJourneyRecord,
phase: CheckoutJourneyPhaseEvent
): void {
telemetry?.trackCheckoutJourneyEvent({
...toCheckoutJourneyContext(record),
...phase
})
}

function enterTopupJourney(): void {
const workspaceId = workspaceStore.activeWorkspaceId
const ownerUid = useAuthStore().userId
Expand All @@ -391,10 +380,11 @@ function enterTopupJourney(): void {
})
if (resolved.status === 'blocked' || resolved.resumed) return

emitTopupJourneyPhase(resolved.record, { phase: 'entered' })
trackCheckoutJourneyPhase(resolved.record, { phase: 'entered' })
}

onMounted(enterTopupJourney)
useCheckoutJourneyExit()
const {
isAddingCredits,
topupOperation,
Expand Down Expand Up @@ -635,7 +625,7 @@ async function handleBuy() {

const submittingJourney = getActiveCheckoutJourney()
if (submittingJourney) {
emitTopupJourneyPhase(submittingJourney, { phase: 'submitted' })
trackCheckoutJourneyPhase(submittingJourney, { phase: 'submitted' })
}

const response = await topup(amountCents)
Expand All @@ -660,7 +650,7 @@ async function handleBuy() {
response.billing_op_id
)
if (linkedJourney) {
emitTopupJourneyPhase(linkedJourney, {
trackCheckoutJourneyPhase(linkedJourney, {
phase: 'operation_linked',
billing_op_id: response.billing_op_id
})
Expand Down
111 changes: 109 additions & 2 deletions src/platform/workspace/composables/useSubscriptionCheckout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,21 @@ describe('useSubscriptionCheckout', () => {
paymentIntentSource?: PaymentIntentSource,
tierPlanType: 'personal' | 'team' = 'personal',
embeddedCheckoutEnabled = true
) {
return mountCheckout(
paymentIntentSource,
tierPlanType,
embeddedCheckoutEnabled
).checkout
}

function mountCheckout(
paymentIntentSource?: PaymentIntentSource,
tierPlanType: 'personal' | 'team' = 'personal',
embeddedCheckoutEnabled = true
) {
let checkout!: ReturnType<typeof useSubscriptionCheckout>
render(
const { unmount } = render(
{
setup() {
checkout = useSubscriptionCheckout(emit, paymentIntentSource, {
Expand All @@ -490,7 +502,7 @@ describe('useSubscriptionCheckout', () => {
},
{ global: { plugins: [i18n] } }
)
return checkout
return { checkout, unmount }
}

function activeJourneyId(): string {
Expand Down Expand Up @@ -824,6 +836,101 @@ describe('useSubscriptionCheckout', () => {
expect(failed.checkout_journey_id).toBe(entered.checkout_journey_id)
expect('billing_op_id' in failed).toBe(false)
})

describe('checkout exit', () => {
function abandonedEvents() {
return journeyEvents().filter((event) => event.phase === 'abandoned')
}

it.for([
{ exit: 'dialog_close', leave: (unmount: () => void) => unmount() },
{
exit: 'page_exit',
leave: () => window.dispatchEvent(new Event('pagehide'))
}
] as const)(
'reports a $exit after the quote with no operation',
async ({ exit, leave }) => {
const { checkout, unmount } = mountCheckout()
await checkout.handleSubscribeClick({
tierKey: 'standard',
billingCycle: 'yearly'
})

leave(unmount)

expect(abandonedEvents()).toEqual([
expect.objectContaining({
checkout_journey_id: activeJourneyId(),
entry_flow: 'initial_subscription',
last_phase: 'preview_ready',
exit
})
])
}
)

it('reports no exit when the dialog closes after the operation was linked', async () => {
const { checkout, unmount } = mountCheckout()
await checkout.handleSubscribeClick({
tierKey: 'standard',
billingCycle: 'yearly'
})
mockSubscribe.mockResolvedValueOnce({
status: 'subscribed',
billing_op_id: 'op-1'
})
await checkout.handleConfirmTransition()

unmount()

expect(journeyPhases()).toContain('operation_linked')
expect(abandonedEvents()).toEqual([])
})

it('reports no exit when the dialog closes for the hosted checkout', async () => {
mockOpenHostedBillingTab.mockReturnValue(true)
const { checkout, unmount } = mountCheckout()
await checkout.handleSubscribeClick({
tierKey: 'standard',
billingCycle: 'yearly'
})

unmount()

expect(emit).toHaveBeenCalledWith('close', false)
expect(abandonedEvents()).toEqual([])
})

it('reports a reopened journey again only after new progress', async () => {
const first = mountCheckout()
await first.checkout.handleSubscribeClick({
tierKey: 'standard',
billingCycle: 'yearly'
})
first.unmount()

const idle = mountCheckout()
idle.unmount()

const resumed = mountCheckout()
await resumed.checkout.handleSubscribeClick({
tierKey: 'standard',
billingCycle: 'yearly'
})
resumed.unmount()

expect(
abandonedEvents().map((event) => [
event.checkout_journey_id,
event.last_phase
])
).toEqual([
[activeJourneyId(), 'preview_ready'],
[activeJourneyId(), 'preview_ready']
])
})
})
})

describe('handleSubscribeClick', () => {
Expand Down
Loading
Loading