Skip to content

[CI] (38ef7e6) next-js/15-app-router-saas - #2597

Closed
wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-38ef7e6-next-js-15-app-router-saas
Closed

wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-38ef7e6-next-js-15-app-router-saas

Conversation

@wizard-ci-bot

@wizard-ci-bot wizard-ci-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown

Automated wizard CI run

Source: wizard-pr
Trigger ID: 38ef7e6
App: next-js/15-app-router-saas
App directory: apps/next-js/15-app-router-saas
Workbench branch: wizard-ci-38ef7e6-next-js-15-app-router-saas
Wizard branch: release-please--branches--main--components--wizard
Context Mill branch: main
PostHog (MCP) branch: master
Timestamp: 2026-07-09T19:19:45.713Z
Duration: 472.9s

YARA Scanner

✓ 56 tool calls scanned, 0 violations detected

No violations: ✓ 56 clean scans

@wizard-ci-bot

wizard-ci-bot Bot commented Jul 9, 2026

Copy link
Copy Markdown
Author

Good — the .env.example exists but was NOT updated by this PR to include the PostHog env vars. Now I have everything I need.


PR Evaluation Report

Summary

This PR integrates PostHog into a Next.js 15 App Router SaaS application with both client-side (posthog-js via instrumentation-client.ts) and server-side (posthog-node singleton) tracking. It adds a reverse proxy via Next.js rewrites, user identification on login/signup and page load, error tracking, and comprehensive server-side event capture across authentication, team management, and Stripe payment flows.

Files changed Lines added Lines removed
11 +245 -2

Confidence score: 4/5 👍

  • Stripe webhook uses Stripe customer ID as distinct_id: The webhook handler in route.ts uses subscription.customer (a Stripe cus_xxx ID) as the distinctId for subscription_updated and subscription_canceled events. All other events use the database user ID (user.id). These will create separate persons in PostHog, fragmenting user data. The existing handleSubscriptionChange already calls getTeamByStripeCustomerId() to look up the team — the handler could resolve the actual user ID from there. [MEDIUM]
  • PostHog env vars not added to .env.example: The existing .env.example file was not updated to include NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN and NEXT_PUBLIC_POSTHOG_HOST. New developers cloning the repo won't know these are required. [MEDIUM]

File changes

Filename Score Description
instrumentation-client.ts 5/5 Client-side PostHog init with reverse proxy host, error tracking, and debug mode
lib/posthog-server.ts 5/5 Server-side singleton client with flushAt:1/flushInterval:0 for immediate sends
next.config.ts 5/5 Reverse proxy rewrites with correct static/array asset routing
package.json 5/5 Both posthog-js and posthog-node added as dependencies
app/(dashboard)/layout.tsx 4/5 Client-side identify on user load, reset on sign-out; uses useEffect appropriately for external system sync
app/(login)/actions.ts 4/5 Comprehensive server-side events for auth and team management flows
app/api/stripe/checkout/route.ts 5/5 Checkout completion event with rich properties and error tracking
app/api/stripe/webhook/route.ts 3/5 Subscription events captured but uses Stripe customer ID instead of user database ID
lib/payments/actions.ts 5/5 Checkout started event with proper user/team context
.gitignore 5/5 Ignores .env.local
posthog-setup-report.md 5/5 Comprehensive setup documentation with event table and next steps

App sanity check ⚠️

Criteria Result Description
App builds and runs Yes No syntax errors, all imports resolve, TypeScript types are correct
Preserves existing env vars & configs Yes All existing code preserved; PostHog additions are purely additive
No syntax or type errors Yes Valid TypeScript throughout, non-null assertions on env vars are standard Next.js pattern
Correct imports/exports Yes posthog-js used client-side only, posthog-node used server-side only
Minimal, focused changes Yes All changes directly serve PostHog integration
Pre-existing issues None Base app appears clean

Issues

  • PostHog env vars missing from .env.example: The existing .env.example file lists Postgres, Stripe, and auth env vars but was not updated with NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN and NEXT_PUBLIC_POSTHOG_HOST. Add these to ensure discoverability for new developers. [MEDIUM]

Other completed criteria

  • Build configuration is valid — next.config.ts rewrites are syntactically correct with skipTrailingSlashRedirect
  • Package.json dependencies are properly formatted with valid version ranges

PostHog implementation ✅

Criteria Result Description
PostHog SDKs installed Yes posthog-js@^1.399.1 and posthog-node@^5.40.0 in package.json
PostHog client initialized Yes Client via instrumentation-client.ts (correct Next.js 15.3+ pattern), server via singleton factory in lib/posthog-server.ts with flushAt:1, flushInterval:0
capture() Yes 12+ meaningful server-side capture calls plus client-side autocapture
identify() Yes Client-side identify in dashboard layout using user.id; server-side identify on sign-in and sign-up with person properties; posthog.reset() on logout
Error tracking Yes capture_exceptions: true in client init for automatic exception capture; manual captureException() in Stripe checkout error handler
Reverse proxy Yes Next.js rewrites route /ingest/static/* and /ingest/array/* to us-assets.i.posthog.com, /ingest/* to us.i.posthog.com; ui_host set correctly

Issues

  • Stripe webhook distinct_id mismatch: The webhook handler uses subscription.customer (Stripe customer ID like cus_xxx) as distinctId for subscription_updated and subscription_canceled events. All other events use the user's database ID. This creates separate person profiles in PostHog, breaking funnels and user timelines. Since handleSubscriptionChange already resolves the team via getTeamByStripeCustomerId(), the handler should look up the user ID from the team and use that as the distinctId. [MEDIUM]

Other completed criteria

  • API key loaded from process.env.NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN environment variable (not hardcoded)
  • Host correctly configured — client uses /ingest (reverse proxy), server uses process.env.NEXT_PUBLIC_POSTHOG_HOST
  • defaults: '2026-01-30' is slightly older than the latest '2026-05-30' shown in docs, but still a valid configuration snapshot

PostHog insights and events ✅

Filename PostHog events Description
instrumentation-client.ts autocapture, , , captureException Client-side init with automatic event capture and exception tracking
app/(dashboard)/layout.tsx identify, reset Identifies authenticated users on page load; resets on sign-out
app/(login)/actions.ts user_signed_in, user_signed_up, user_signed_out, invitation_accepted, password_updated, account_deleted, team_member_removed, team_member_invited Comprehensive auth and team management funnel events with team_id, role, and contextual properties
app/api/stripe/checkout/route.ts subscription_checkout_completed, captureException Tracks successful checkout with plan, product, and subscription details; captures checkout errors
app/api/stripe/webhook/route.ts subscription_updated, subscription_canceled Tracks subscription lifecycle changes (uses Stripe customer ID as distinct_id — see issue above)
lib/payments/actions.ts checkout_started Tracks checkout initiation with price_id and team context

Issues

  • No additional event quality issues beyond the webhook distinct_id problem noted above.

Other completed criteria

  • Events represent real user actions mapping to SaaS product flows (signup → checkout → subscription lifecycle)
  • Events enable product insights — can build signup-to-checkout funnel, track subscription churn, measure team collaboration
  • Events include relevant properties (team_id, role, subscription_status, plan_name, etc.)
  • No PII in capture() properties — name and role are correctly placed in identify() person properties only
  • Event names are descriptive and consistent snake_case convention

Reviewed by wizard workbench PR evaluator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants