feat(kiloclaw): add claw_trial_started and claw_transaction PostHog events#1346
Conversation
Code Review SummaryStatus: 1 Issue Found | Recommendation: Address before merge Overview
Fix these issues in Kilo Cloud Issue Details (click to expand)WARNING
Other Observations (not in diff)N/A Files Reviewed (3 files)
Reviewed by gpt-5.4-20260305 · 939,259 tokens |
…vents Add server-side PostHog tracking for KiloClaw trial creation and subscription payments to close the funnel visibility gap between signup and paid conversion.
4104c8a to
60bddfe
Compare
| const stripeSubscriptionId = | ||
| typeof subDetails?.subscription === 'string' ? subDetails.subscription : null; | ||
|
|
||
| if (!kiloUserId) { |
There was a problem hiding this comment.
WARNING: Missing fallback when the invoice snapshot omits subscription metadata
processStripePaymentEventHook has already classified this invoice as KiloClaw by price ID, but this handler drops the analytics event whenever invoice.parent?.subscription_details?.metadata.kiloUserId is absent. The Kilo Pass invoice.paid path handles the same case by refetching the Stripe subscription and falling back to subscription.metadata; without that fallback here, claw_transaction silently undercounts paid conversions on invoices whose embedded snapshot metadata is missing or stale.
Summary
Adds two server-side PostHog events to close the KiloClaw funnel visibility gap between signup and paid conversion:
claw_trial_started— fires inensureProvisionAccesswhen a new trial subscription row is created during first provisioning. Properties:user_id,plan,trial_ends_at.claw_transaction— fires oninvoice.paidfor KiloClaw subscription invoices withamount_paid > 0. Wires up the previously-unusedinvoiceLooksLikeKiloClawByPriceIdclassifier. Properties:user_id,plan,amount_cents,currency,stripe_invoice_id,stripe_subscription_id.Both events use
google_user_emailasdistinctId, matching the codebase convention.claw_transactionruns insideafter()withIS_IN_AUTOMATED_TESTguard, matching theorganization-seats.tspattern for Stripe webhook PostHog events.claw_trial_startedcaptures inline, matching theuser.tspattern for tRPC-context events.Verification
pnpm typecheck— passes (no new errors, all pre-existing)oxfmt --list-different— passesoxlint— passes (0 warnings, 0 errors)eslint— passesVisual Changes
N/A
Reviewer Notes
ensureProvisionAccessis unchanged (no.returning()chain).invoiceLooksLikeKiloClawByPriceIdwas written previously but never wired up — this PR connects it to theinvoice.paidhandler instripe.ts.