Skip to content

feat(kiloclaw): add claw_trial_started and claw_transaction PostHog events#1346

Merged
pedroheyerdahl merged 5 commits intomainfrom
feat/kiloclaw-posthog-trial-transaction-events
Mar 25, 2026
Merged

feat(kiloclaw): add claw_trial_started and claw_transaction PostHog events#1346
pedroheyerdahl merged 5 commits intomainfrom
feat/kiloclaw-posthog-trial-transaction-events

Conversation

@pedroheyerdahl
Copy link
Copy Markdown
Contributor

Summary

Adds two server-side PostHog events to close the KiloClaw funnel visibility gap between signup and paid conversion:

  • claw_trial_started — fires in ensureProvisionAccess when a new trial subscription row is created during first provisioning. Properties: user_id, plan, trial_ends_at.
  • claw_transaction — fires on invoice.paid for KiloClaw subscription invoices with amount_paid > 0. Wires up the previously-unused invoiceLooksLikeKiloClawByPriceId classifier. Properties: user_id, plan, amount_cents, currency, stripe_invoice_id, stripe_subscription_id.

Both events use google_user_email as distinctId, matching the codebase convention. claw_transaction runs inside after() with IS_IN_AUTOMATED_TEST guard, matching the organization-seats.ts pattern for Stripe webhook PostHog events. claw_trial_started captures inline, matching the user.ts pattern for tRPC-context events.

Verification

  • pnpm typecheck — passes (no new errors, all pre-existing)
  • oxfmt --list-different — passes
  • oxlint — passes (0 warnings, 0 errors)
  • eslint — passes
  • Pre-push hook (format + lint + typecheck) — passes

Visual Changes

N/A

Reviewer Notes

  • The changes are additive — no existing queries or handler logic is modified. The INSERT in ensureProvisionAccess is unchanged (no .returning() chain).
  • invoiceLooksLikeKiloClawByPriceId was written previously but never wired up — this PR connects it to the invoice.paid handler in stripe.ts.
  • PostHog captures are no-ops outside production (the client returns stubs in dev/test), so these changes cannot affect test behavior.

Comment thread src/routers/kiloclaw-router.ts Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Mar 20, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
src/lib/kiloclaw/stripe-handlers.ts 787 Drops claw_transaction when invoice snapshot metadata is missing
Other Observations (not in diff)

N/A

Files Reviewed (3 files)
  • src/lib/kiloclaw/stripe-handlers.ts - 1 issue
  • src/lib/stripe.ts - 0 issues
  • src/routers/kiloclaw-router.ts - 0 issues

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.
@pedroheyerdahl pedroheyerdahl force-pushed the feat/kiloclaw-posthog-trial-transaction-events branch from 4104c8a to 60bddfe Compare March 20, 2026 21:46
const stripeSubscriptionId =
typeof subDetails?.subscription === 'string' ? subDetails.subscription : null;

if (!kiloUserId) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@pedroheyerdahl pedroheyerdahl merged commit 5381082 into main Mar 25, 2026
19 checks passed
@pedroheyerdahl pedroheyerdahl deleted the feat/kiloclaw-posthog-trial-transaction-events branch March 25, 2026 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants