Skip to content

[CI] (8dccaac) next-js/15-pages-router-saas - #2359

Closed
wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-8dccaac-next-js-15-pages-router-saas
Closed

wizard-ci-bot[bot] wants to merge 1 commit into
mainfrom
wizard-ci-8dccaac-next-js-15-pages-router-saas

Conversation

@wizard-ci-bot

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

Copy link
Copy Markdown

Automated wizard CI run

Source: wizard-pr
Trigger ID: 8dccaac
App: next-js/15-pages-router-saas
App directory: apps/next-js/15-pages-router-saas
Workbench branch: wizard-ci-8dccaac-next-js-15-pages-router-saas
Wizard branch: release-please--branches--main--components--wizard
Context Mill branch: main
PostHog (MCP) branch: master
Timestamp: 2026-07-03T00:40:05.325Z
Duration: 584.2s

YARA Scanner

✓ 83 tool calls scanned, 0 violations detected

No violations: ✓ 83 clean scans

@wizard-ci-bot

wizard-ci-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown
Author

PR Evaluation Report

Summary

This PR integrates PostHog into a Next.js 15 Pages Router SaaS application with both client-side (posthog-js) and server-side (posthog-node) SDKs. It adds initialization via instrumentation-client.ts, a reverse proxy through Next.js rewrites, user identification on sign-in/sign-up, and 13 tracked events covering the full user and revenue lifecycle (pricing → checkout → subscription → team management).

Files changed Lines added Lines removed
16 +158 -3

Confidence score: 4/5 👍

  • Email used as distinct_id: Both client-side posthog.identify(data.email, ...) and server-side posthog.identify({ distinctId: foundUser.email, ... }) use raw email addresses as distinct IDs. Emails can change and cause fragmented user profiles. Use a stable database user ID (e.g., foundUser.id) instead. [MEDIUM]
  • No .env.example update: The PR introduces NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN and NEXT_PUBLIC_POSTHOG_HOST environment variables but does not document them in an .env.example or equivalent — the setup report itself flags this as a TODO. [LOW]

File changes

Filename Score Description
instrumentation-client.ts 5/5 Correct Next.js client-side PostHog initialization with env vars, reverse proxy host, error tracking, and debug mode
lib/posthog-server.ts 5/5 Singleton server-side PostHog client with flushAt: 1 / flushInterval: 0 per Next.js docs
next.config.ts 5/5 Properly configured reverse proxy with /ingest/static/* and /ingest/array/* routing to us-assets.i.posthog.com, general /ingest/* to us.i.posthog.com, correct ordering
package.json 5/5 Both posthog-js and posthog-node added as dependencies
components/login.tsx 3/5 Identify and capture on login, but uses email as distinct_id
components/header.tsx 5/5 Captures sign-out event and calls posthog.reset() correctly
pages/api/auth/sign-in.ts 3/5 Server-side identify and capture, but uses email as distinct_id
pages/api/auth/sign-up.ts 3/5 Server-side identify and capture, but uses email as distinct_id
pages/api/stripe/create-checkout.ts 4/5 Server-side checkout capture with relevant properties
pages/api/stripe/webhook.ts 4/5 Captures subscription_updated and subscription_cancelled with Stripe customer ID as distinct_id
pages/api/team/invite.ts 4/5 Server-side team invitation event capture
pages/dashboard/index.tsx 5/5 Client-side captures for subscription management, team member removal, and invite submission
pages/dashboard/general.tsx 5/5 Client-side capture for account update
pages/pricing.tsx 4/5 Captures pricing_page_viewed (via useEffect) and checkout_started
.gitignore 5/5 Ensures .env.local is not committed
posthog-setup-report.md 5/5 Comprehensive setup report with event table and next steps

App sanity check ⚠️

Criteria Result Description
App builds and runs Yes No syntax errors, all imports valid, TypeScript types correct
Preserves existing env vars & configs Yes Existing next.config.ts extended with rewrites; webhook handler restructured but functionality preserved
No syntax or type errors Yes All code is syntactically valid TypeScript/TSX
Correct imports/exports Yes posthog-js imported client-side, posthog-node server-side, no cross-environment contamination
Minimal, focused changes Yes All changes directly related to PostHog integration
Pre-existing issues None —

Issues

  • Environment variables not documented: NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN and NEXT_PUBLIC_POSTHOG_HOST are required but not added to any .env.example file. The setup report acknowledges this as a TODO. [LOW]

Other completed criteria

  • App builds without errors — no missing dependencies or invalid syntax
  • Build configuration valid — package.json dependencies properly added
  • Existing functionality preserved — webhook handler logic unchanged, just wrapped in block scopes

PostHog implementation ⚠️

Criteria Result Description
PostHog SDKs installed Yes posthog-js@^1.396.5 and posthog-node@^5.39.4 in package.json
PostHog client initialized Yes instrumentation-client.ts uses posthog.init() with env vars, correct for Next.js 15+
capture() Yes 13 meaningful events across client and server
identify() No Uses raw email addresses as distinct_id instead of stable user IDs
Error tracking Yes capture_exceptions: true in init config enables automatic exception capture
Reverse proxy Yes Next.js rewrites properly configured: /ingest/static/* and /ingest/array/* → us-assets.i.posthog.com, /ingest/* → us.i.posthog.com

Issues

  • Email used as distinct_id: posthog.identify(data.email, { email: data.email }) on the client and posthog.identify({ distinctId: foundUser.email, ... }) on the server both use the user's email as their distinct ID. Emails can change, and using them as the primary identifier causes fragmented user profiles. Use foundUser.id.toString() (or equivalent stable database ID) as the distinct_id, and pass email only as a person property. [MEDIUM]
  • No re-identification for returning sessions: Users who return with an active session cookie (visiting /dashboard directly) remain on their anonymous distinct ID until they explicitly sign in again. Consider calling posthog.identify() when the /api/user SWR response resolves with a known user. [LOW]

Other completed criteria

  • API key loaded from NEXT_PUBLIC_POSTHOG_PROJECT_TOKEN environment variable
  • API host correctly configured via reverse proxy (/ingest)
  • ui_host set to https://us.posthog.com for toolbar access through proxy
  • posthog.reset() called on sign-out
  • Server-side client uses singleton pattern with proper flush settings
  • skipTrailingSlashRedirect: true added for proxy compatibility

PostHog insights and events ✅

Filename PostHog events Description
pages/pricing.tsx pricing_page_viewed, checkout_started Top-of-funnel: tracks pricing page views and checkout initiation with plan details
components/header.tsx user_signed_out Captures sign-out with posthog.reset() to unlink future events
components/login.tsx identify Identifies user on sign-in/sign-up (client-side)
pages/dashboard/index.tsx manage_subscription_clicked, team_member_removed, team_member_invite_submitted Dashboard engagement events with relevant properties
pages/dashboard/general.tsx account_updated Tracks account settings changes
pages/api/auth/sign-in.ts user_signed_in Server-side sign-in with team_id property
pages/api/auth/sign-up.ts user_signed_up Server-side sign-up with team_id and via_invite properties
pages/api/stripe/create-checkout.ts checkout_session_created Server-side Stripe checkout creation with price_id
pages/api/stripe/webhook.ts subscription_updated, subscription_cancelled Server-side webhook events for subscription lifecycle
pages/api/team/invite.ts team_member_invitation_sent Server-side team invitation tracking

Issues

  • No critical or medium issues with event quality.

Other completed criteria

  • Events represent real user actions across the full SaaS lifecycle
  • Events enable product insights — checkout conversion funnel, signup trends, subscription churn analysis
  • Events include enriched properties (plan_name, price_id, team_id, role, status, interval)
  • No PII in event properties — emails only in identify calls, not in capture properties
  • Consistent snake_case naming convention across all events

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