Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -24,6 +24,7 @@ export async function createCheckoutSession({
redirect(`/sign-up?redirect=checkout&priceId=${priceId}`);
}

const posthogDistinctId = String(user.id);
const session = await stripe.checkout.sessions.create({
payment_method_types: ['card'],
line_items: [
Expand All @@ -36,10 +37,16 @@ export async function createCheckoutSession({
success_url: `${process.env.BASE_URL}/api/stripe/checkout?session_id={CHECKOUT_SESSION_ID}`,
cancel_url: `${process.env.BASE_URL}/pricing`,
customer: team.stripeCustomerId || undefined,
client_reference_id: user.id.toString(),
client_reference_id: posthogDistinctId,
metadata: {
posthog_person_distinct_id: posthogDistinctId
},
allow_promotion_codes: true,
subscription_data: {
trial_period_days: 14
trial_period_days: 14,
metadata: {
posthog_person_distinct_id: posthogDistinctId
}
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# PostHog Revenue Analytics Setup

## Changes made

- Configured the existing PostHog SDK through `.env.local` using the supplied project token and host.
- Confirmed that the project’s canonical PostHog distinct ID is `String(user.id)`.
- Updated the existing Stripe Checkout Session creation flow to attach `posthog_person_distinct_id` to both Checkout Session metadata and the created Subscription metadata.
- Reused the same distinct ID for `client_reference_id` so checkout completion can continue resolving the authenticated user.
- Added no Stripe API calls, packages, or payment-logic changes.

## Files modified or created

- Modified `lib/payments/stripe.ts`
- Created `.env.local`
- Created `posthog-revenue-report.md`

## Verification

- The edited application compiled successfully and passed the TypeScript phase of `pnpm build`.
- The full build could not finish page-data collection because `POSTGRES_URL` is not configured in the local environment. This is unrelated to the revenue metadata change.

## Manual next steps

1. Set `POSTGRES_URL` in the local/deployment environment, then run `pnpm build` again.
2. Complete a test subscription checkout and confirm the resulting Stripe Checkout Session and Subscription contain `posthog_person_distinct_id`.
3. After Stripe data syncs into PostHog, verify that the customer appears in Top Customers and the `persons_revenue_analytics` table.
Loading