Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 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
dbb4092
Merge remote-tracking branch 'origin/main' into fe3119-2
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
4168df7
fix(billing-web): report an abandon after coming back from a hosted step
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
2 changes: 1 addition & 1 deletion apps/billing-web/src/checkout/checkoutJourney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type PromoPhase = Extract<CheckoutJourneyPhaseEvent, { phase: 'promo' }>
export type PaymentRail = MethodSelectedPhase['rail']
export type PromoResult = PromoPhase['result']

function methodKindOf(
export function methodKindOf(
methodType: string | undefined
): MethodSelectedPhase['method_kind'] {
if (methodType === undefined || methodType === '') return undefined
Expand Down
40 changes: 40 additions & 0 deletions apps/billing-web/src/composables/useCheckoutJourney.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type {
CheckoutEndingAttribution,
CheckoutEndingKind,
CheckoutEntryFlow,
CheckoutExit,
CheckoutJourneyPhase,
CheckoutJourneyPhaseEvent,
PreviewSubscribeResult,
SubscriptionPreview
Expand Down Expand Up @@ -38,8 +42,15 @@ export function useCheckoutJourney(uiMode: 'embedded' | 'full_page') {
let presses = 0
let linkingPress: number | undefined
let billingOpId: string | undefined
let lastPhase:
| Exclude<CheckoutJourneyPhase, 'abandoned' | 'ended'>
| undefined
let lastEnding: CheckoutEndingKind | undefined
let left = false

function track(phase: CheckoutJourneyPhaseEvent) {
if (phase.phase !== 'abandoned' && phase.phase !== 'ended')
lastPhase = phase.phase
billingWebTelemetry.trackCheckoutJourneyEvent({
checkout_journey_id: journeyId,
checkout_entered_at: enteredAt,
Expand Down Expand Up @@ -143,9 +154,38 @@ export function useCheckoutJourney(uiMode: 'embedded' | 'full_page') {
if (failed) track(failed)
}

/** Once per ending screen shown; an ending resolves the journey. */
function ended(
kind: CheckoutEndingKind,
attribution: CheckoutEndingAttribution | undefined
) {
if (kind === lastEnding) return
lastEnding = kind
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
track({
phase: 'ended',
ending_kind: kind,
...(attribution !== undefined && { attribution })
})
}

/** The checkout left its ending for a retry, so the journey is open again. */
function resumed() {
lastEnding = undefined
}

/** The customer left a journey no ending resolved; only the first way out counts. */
function abandoned(exit: CheckoutExit) {
if (left || lastEnding !== undefined || lastPhase === undefined) return
left = true
track({ phase: 'abandoned', last_phase: lastPhase, exit })
}

return {
enter,
track,
ended,
resumed,
abandoned,
submitted,
submitSettled,
operationIssued,
Expand Down
74 changes: 67 additions & 7 deletions apps/billing-web/src/composables/useFullPageCheckout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { tryOnScopeDispose, useIntervalFn } from '@vueuse/core'
import {
tryOnScopeDispose,
useEventListener,
useIntervalFn
} from '@vueuse/core'
import { computed, shallowReadonly, shallowRef, watch } from 'vue'

import {
Expand Down Expand Up @@ -42,6 +46,8 @@ import {
reduceCheckoutPage,
settledPlanSource
} from '@/checkout/checkoutPage'
import { methodKindOf } from '@/checkout/checkoutJourney'
import { endingOf } from '@/checkout/endingScreen'
import { pricingTableUrl } from '@/checkout/cloudLinks'
import { createOperationChannel } from '@/checkout/operationChannel'
import { promoEntryLive, promoRejectionOf } from '@/checkout/promoEntry'
Expand All @@ -63,6 +69,7 @@ import { useCheckoutJourney } from '@/composables/useCheckoutJourney'
import { useCheckoutPromo } from '@/composables/useCheckoutPromo'
import { awaitBillingWebStripeKey } from '@/config/stripeKey'
import { useBillingEntry } from '@/entry/billingEntry'
import type { BillingEntryState } from '@/entry/billingEntry'
import { useBillingWebSession } from '@/session/billingWebSession'
import { createDeferredStripeChallengePort } from '@/session/stripeChallengePort'
import {
Expand Down Expand Up @@ -160,6 +167,13 @@ function railOf(
} as const
}

/** A link that names no plan has nothing to quote, so it is as unreadable as a malformed one. */
function arrivalPage({ entry, error }: BillingEntryState): CheckoutPage {
return error.value === undefined && entry.value?.plan !== undefined
? RESOLVING
: UNREADABLE_LINK
}

/**
* The full-page checkout's effects around one `CheckoutPage` state: the
* reconciliation with whatever operation the workspace is already waiting
Expand Down Expand Up @@ -191,11 +205,8 @@ export function useFullPageCheckout() {
const journey = useCheckoutJourney('full_page')
journey.enter()

/** A link that names no plan has nothing to quote, so it is as unreadable as a malformed one. */
const page = shallowRef<CheckoutPage>(
unreadableLink.value === undefined && entry.value?.plan !== undefined
? RESOLVING
: UNREADABLE_LINK
arrivalPage({ entry, error: unreadableLink })
)

/** Busy from the Pay click until the attempt resolves, whatever the lifecycle's promise does. */
Expand All @@ -211,11 +222,19 @@ export function useFullPageCheckout() {
* reopens only a challenge that stays on this page (below), and anything
* else waits for Complete verification.
*/
let handedToHostedStep = false
const checkout = useCheckout({
openUrl: (url) => window.location.assign(url),
openUrl: (url) => {
handedToHostedStep = true
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
window.location.assign(url)
},
navigationMode: 'redirect',
challengePort,
autoContinue: () => submitting.value
autoContinue: () => submitting.value,
methodKind: () =>
page.value.kind === 'capture' && page.value.attempt.kind === 'sent'
? methodKindOf(page.value.attempt.redirectMethod)
: undefined
})
const attempts = createSubscriptionCheckoutTelemetry({ ui: 'full_page' })

Expand Down Expand Up @@ -583,6 +602,46 @@ export function useFullPageCheckout() {

const { returnLink, openedByScript, close } = useCheckoutExit(page)

watch(
() => endingOf(page.value)?.kind,
(kind) => {
if (kind === undefined) {
journey.resumed()
return
}
const current = page.value
journey.ended(
kind,
current.kind === 'terminal' ? current.attribution : undefined
)
},
{ immediate: true }
)

/**
* A page handed to a method's own site by the challenge of the operation
* its Pay issued has not been abandoned.
*/
function leftForPayment() {
const current = page.value
if (current.kind !== 'capture' || current.attempt.kind !== 'sent')
return false
const { redirectMethod, operation } = current.attempt
const challenge = operation?.challenge?.status
return (
redirectMethod !== undefined &&
operation?.presentation === 'embedded' &&
(challenge === 'required' || challenge === 'in_progress')
)
}

/** A hosted handoff covers only the page exit it caused, not one after coming Back. */
useEventListener(window, 'pagehide', () => {
const handedOff = handedToHostedStep
handedToHostedStep = false
if (!handedOff && !leftForPayment()) journey.abandoned('page_exit')
})

/**
* The live catalog, on the Team tab when the link asked for a team plan:
* one the quote named without its stop, or a link that carries a stop.
Expand Down Expand Up @@ -797,6 +856,7 @@ export function useFullPageCheckout() {
viewPlansLink,
openedByScript,
close,
abandon: journey.abandoned,
retryLoad,
onPaymentPhase,
savedMethods: saved.methods,
Expand Down
21 changes: 21 additions & 0 deletions apps/billing-web/src/telemetry/billingWebTelemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,27 @@ describe('trackCheckoutJourneyEvent', () => {
)
})

it('sends an abandoned checkout to PostHog by beacon, since the page is going away', async () => {
const telemetry = createBillingWebTelemetry()
await telemetry.startPostHog({
config: Promise.resolve(CONFIGURED),
identity: ref<SessionIdentity>({ kind: 'unknown' })
})

telemetry.trackCheckoutJourneyEvent({
...ENTERED,
phase: 'abandoned',
last_phase: 'entered',
exit: 'page_exit'
})

expect(posthog.capture).toHaveBeenCalledExactlyOnceWith(
'billing.checkout.abandoned',
expect.objectContaining({ last_phase: 'entered', exit: 'page_exit' }),
{ transport: 'sendBeacon' }
)
})

it('holds back the journey phases the backend switched off, and only those', async () => {
const telemetry = createBillingWebTelemetry()
await telemetry.startPostHog({
Expand Down
13 changes: 10 additions & 3 deletions apps/billing-web/src/telemetry/billingWebTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ interface BillingEvent {
| CheckoutJourneyTelemetryEventName
| WebSessionTelemetryEvent['name']
readonly properties: Readonly<Record<string, unknown>>
/** Sent while the page goes away, after PostHog has drained its queue on `pagehide`. */
readonly onPageExit?: true
}

interface IdentitySink {
Expand Down Expand Up @@ -181,8 +183,12 @@ export function createBillingWebTelemetry() {
posthog.waiting.push(event)
return
case 'ready':
if (!posthog.disabledEvents.has(event.name))
posthog.client.capture(event.name, event.properties)
if (posthog.disabledEvents.has(event.name)) return
if (event.onPageExit)
posthog.client.capture(event.name, event.properties, {
transport: 'sendBeacon'
})
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
else posthog.client.capture(event.name, event.properties)
}
}

Expand Down Expand Up @@ -244,7 +250,8 @@ export function createBillingWebTelemetry() {
properties: {
...getCheckoutJourneyTelemetryEventPayload(event),
billing_surface: 'billing_web'
}
},
...(event.phase === 'abandoned' && { onPageExit: true })
})
)
}
Expand Down
8 changes: 8 additions & 0 deletions apps/billing-web/src/test/fakeBillingClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export interface FakeBillingClient {
readonly reportChallengeStarted: Mock<
BillingClient['lifecycle']['reportChallengeStarted']
>
readonly reportHostedStepOpened: Mock<
BillingClient['lifecycle']['reportHostedStepOpened']
>
readonly reportChallengeSettled: Mock<
BillingClient['lifecycle']['reportChallengeSettled']
>
Expand Down Expand Up @@ -177,6 +180,9 @@ export function createFakeBillingClient(
const reportChallengeStarted: Mock<
BillingClient['lifecycle']['reportChallengeStarted']
> = vi.fn()
const reportHostedStepOpened: Mock<
BillingClient['lifecycle']['reportHostedStepOpened']
> = vi.fn()
const reportChallengeSettled: Mock<
BillingClient['lifecycle']['reportChallengeSettled']
> = vi.fn()
Expand Down Expand Up @@ -261,6 +267,7 @@ export function createFakeBillingClient(
switchPresentation: unusedByHostedSurfaces(
'lifecycle.switchPresentation'
),
reportHostedStepOpened,
reportChallengeStarted,
reportChallengeSettled,
get: (id) => operations.get(id),
Expand Down Expand Up @@ -344,6 +351,7 @@ export function createFakeBillingClient(
readPlans,
readPaymentMethods,
invalidatePaymentMethods,
reportHostedStepOpened,
reportChallengeStarted,
reportChallengeSettled,
previewSubscribe,
Expand Down
Loading
Loading