From 2f9382615f883b11ecfc22f398ff0a98c584ef25 Mon Sep 17 00:00:00 2001 From: "wizard-ci-bot[bot]" <254716194+wizard-ci-bot[bot]@users.noreply.github.com> Date: Wed, 28 Oct 2026 17:14:25 +0000 Subject: [PATCH] wizard-ci: stripe/stripe-next-js-saas-starter --- .../lib/payments/stripe.ts | 11 ++++++-- .../posthog-revenue-report.md | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 apps/revenue/stripe/stripe-next-js-saas-starter/posthog-revenue-report.md diff --git a/apps/revenue/stripe/stripe-next-js-saas-starter/lib/payments/stripe.ts b/apps/revenue/stripe/stripe-next-js-saas-starter/lib/payments/stripe.ts index 6f24b794d..7d8592296 100644 --- a/apps/revenue/stripe/stripe-next-js-saas-starter/lib/payments/stripe.ts +++ b/apps/revenue/stripe/stripe-next-js-saas-starter/lib/payments/stripe.ts @@ -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: [ @@ -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 + } } }); diff --git a/apps/revenue/stripe/stripe-next-js-saas-starter/posthog-revenue-report.md b/apps/revenue/stripe/stripe-next-js-saas-starter/posthog-revenue-report.md new file mode 100644 index 000000000..1337b81f3 --- /dev/null +++ b/apps/revenue/stripe/stripe-next-js-saas-starter/posthog-revenue-report.md @@ -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.