Skip to content

[CI] (362fa9c) next-js/15-pages-router-saas#316

Closed
wizard-ci-bot[bot] wants to merge 1 commit intomainfrom
wizard-ci-362fa9c-next-js-15-pages-router-saas
Closed

[CI] (362fa9c) next-js/15-pages-router-saas#316
wizard-ci-bot[bot] wants to merge 1 commit intomainfrom
wizard-ci-362fa9c-next-js-15-pages-router-saas

Conversation

@wizard-ci-bot
Copy link

@wizard-ci-bot wizard-ci-bot bot commented Feb 11, 2026

Automated wizard CI run

Source: manual
Trigger ID: 362fa9c
App: next-js/15-pages-router-saas
App directory: apps/next-js/15-pages-router-saas
Workbench branch: wizard-ci-362fa9c-next-js-15-pages-router-saas
Wizard branch: main
Context Mill branch: main
PostHog (MCP) branch: master
Timestamp: 2026-02-11T17:38:33.498Z
Duration: 579.0s

@wizard-ci-bot
Copy link
Author

wizard-ci-bot bot commented Feb 11, 2026

The TypeScript check passes. Now I have enough information to write the evaluation report.


PR Evaluation Report

Summary

This PR adds a comprehensive PostHog analytics integration to a Next.js 15 Pages Router SaaS application. It implements client-side initialization via instrumentation-client.ts, server-side tracking with posthog-node, reverse proxy configuration for ad-block circumvention, and event tracking across authentication, checkout, subscription, and team management flows.

Files changed Lines added Lines removed
19 +736 -6

Confidence score: 4/5 👍

  • Server-side PostHog host mismatch: The server-side client in lib/posthog-server.ts uses NEXT_PUBLIC_POSTHOG_HOST which may not be set (not in .env.example), while the client-side correctly uses the reverse proxy /ingest. [MEDIUM]
  • Missing page view tracking: No automatic page view tracking is configured - only custom events are captured. Consider adding capture_pageview: true or manual page view tracking for complete analytics. [MEDIUM]
  • Client-side user identification issue: In login.tsx, posthog.identify() uses email as the distinctId, but server-side uses user.id - this creates potential identity mismatch. [MEDIUM]

File changes

Filename Score Description
instrumentation-client.ts 4/5 New file - PostHog client initialization with correct reverse proxy, exception capture enabled, and recommended defaults preset
lib/posthog-server.ts 4/5 New file - Server-side PostHog singleton with proper shutdown method. Uses NEXT_PUBLIC_POSTHOG_HOST which should be verified
next.config.ts 5/5 Added reverse proxy rewrites for PostHog to circumvent ad blockers, with proper trailing slash handling
package.json 5/5 Added posthog-js (^1.345.5) and posthog-node (^5.24.15) dependencies
components/header.tsx 4/5 Added logout event capture, posthog.reset() on signout, and error tracking
components/login.tsx 3/5 Added client-side identify and error tracking, but uses email as distinctId (inconsistent with server)
pages/api/auth/sign-in.ts 5/5 Added server-side identify and user_signed_in event with rich properties
pages/api/auth/sign-up.ts 5/5 Added server-side identify and user_signed_up event with comprehensive properties
pages/api/auth/sign-out.ts 5/5 Added user_signed_out event tracking with user context before session clear
pages/api/stripe/webhook.ts 4/5 Added subscription lifecycle events, but uses Stripe customer ID as distinctId (may not link to user)
pages/api/stripe/checkout.ts 5/5 Added checkout_completed event with plan and subscription details
pages/api/stripe/create-checkout.ts 5/5 Added checkout_started event tracking
pages/api/account/update.ts 5/5 Added account update tracking with property updates via identify
pages/api/team/invite.ts 5/5 Added team_member_invited event with inviter and invitee context
pages/api/team/remove-member.ts 5/5 Added team_member_removed event tracking
pages/pricing.tsx 5/5 Added pricing_plan_clicked event with plan details
.gitignore 5/5 Added .env.local to gitignore
pnpm-lock.yaml 5/5 Updated lockfile with PostHog dependencies
posthog-setup-report.md 5/5 Comprehensive documentation of the integration

App sanity check: 4/5 ✅

Criteria Result Description
App builds and runs Yes* TypeScript compilation succeeds. Build fails only due to missing POSTGRES_URL in CI (expected)
Preserves existing env vars & configs No Missing PostHog env vars in .env.example
No syntax or type errors Yes TypeScript check passes with no errors
Correct imports/exports Yes All imports are valid and correctly structured
Minimal, focused changes Yes Changes are focused on PostHog integration only

Issues

  • Missing environment variables in .env.example: The .env.example file doesn't include NEXT_PUBLIC_POSTHOG_KEY or NEXT_PUBLIC_POSTHOG_HOST which are required for the integration. [MEDIUM]

Other completed criteria

  • Existing app logic preserved - all original functionality maintained
  • New files follow existing project patterns
  • Error handling implemented consistently across all new code
  • Clear, descriptive comments added for PostHog integration points
  • Build configuration is valid (next.config.ts changes are correct)

PostHog implementation: 4/5 ✅

Criteria Result Description
PostHog SDKs installed Yes posthog-js (^1.345.5) and posthog-node (^5.24.15) in package.json
PostHog client initialized Yes Client-side via instrumentation-client.ts, server-side via singleton in lib/posthog-server.ts
capture() Yes 11 custom events captured across auth, checkout, subscription, and team flows
identify() Yes Server-side identify on sign-in/sign-up, client-side identify on login
Error tracking Yes captureException() calls in all catch blocks, capture_exceptions: true enabled
Reverse proxy Yes Properly configured in next.config.ts with /ingest route and trailing slash handling

Issues

  • Identity mismatch between client and server: Client-side posthog.identify() in login.tsx uses data.email as distinctId, while server-side uses user.id.toString(). This can cause user identity fragmentation. Use consistent user ID across both. [MEDIUM]
  • Server-side host configuration: The server client uses NEXT_PUBLIC_POSTHOG_HOST which may point to the public PostHog URL, not the reverse proxy. For server-side, this is acceptable but should be documented. [LOW]
  • Stripe webhook distinctId: Uses Stripe customer ID as distinctId for subscription events, which may not link to the user's PostHog profile unless aliased. [LOW]

Other completed criteria

  • API key properly loaded from environment variable (not hardcoded)
  • Correct API host configuration (/ingest for client)
  • UI host set correctly (https://us.posthog.com)
  • Debug mode enabled in development
  • Defaults preset configured (2025-11-30)
  • posthog.reset() called on logout
  • Shutdown method provided for server client

PostHog insights and events: 4/5 ✅

Filename PostHog events Description
pages/api/auth/sign-in.ts user_signed_in User authentication with email, team info, and checkout redirect flag
pages/api/auth/sign-up.ts user_signed_up User registration with role, team, invitation status, and checkout flow
pages/api/auth/sign-out.ts user_signed_out Logout tracking with user email
components/header.tsx user_logged_out, captureException Client-side logout and error tracking
components/login.tsx captureException Authentication error capture
pages/api/stripe/create-checkout.ts checkout_started Checkout initiation with price and team details
pages/api/stripe/checkout.ts checkout_completed Successful checkout with plan and subscription info
pages/api/stripe/webhook.ts subscription_updated, subscription_cancelled Subscription lifecycle events
pages/api/account/update.ts account_updated Account changes with old/new values
pages/api/team/invite.ts team_member_invited Team invitation with role and inviter info
pages/api/team/remove-member.ts team_member_removed Team member removal tracking
pages/pricing.tsx pricing_plan_clicked Plan selection with pricing details

Issues

  • No page view tracking: The integration captures custom events but lacks automatic page view tracking. Add capture_pageview: true to client config or implement manual page view tracking for complete user journey analytics. [MEDIUM]
  • Missing failed login/signup events: Only successful auth events are tracked. Consider adding user_sign_in_failed and user_sign_up_failed events when validation fails to track conversion friction. [LOW]

Other completed criteria

  • Events capture real user actions (sign-up, sign-in, checkout, team management)
  • Events support funnel analysis (signup → checkout_started → checkout_completed)
  • Events enriched with relevant properties (team_id, email, plan details)
  • Subscription lifecycle tracked for churn analysis
  • Error tracking enables debugging and user experience monitoring
  • No PII exposed inappropriately - email used appropriately for identification

Reviewed by wizard workbench PR evaluator

@wizard-ci-bot wizard-ci-bot bot added the CI/CD label Feb 11, 2026
@wizard-ci-bot wizard-ci-bot bot closed this Feb 11, 2026
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