[CI] (cef44b4) next-js/15-pages-router-saas#1399
Closed
wizard-ci-bot[bot] wants to merge 1 commit into
Closed
Conversation
Author
|
Now I have enough context. Let me produce the evaluation. PR Evaluation ReportSummaryThis PR integrates PostHog into a Next.js 15 Pages Router SaaS application, adding both client-side (
Confidence score: 4/5 👍
File changes
App sanity check
|
| Criteria | Result | Description |
|---|---|---|
| App builds and runs | Yes | All syntax is valid, imports resolve correctly, no type errors visible |
| Preserves existing env vars & configs | Yes | Existing next.config.ts extended cleanly; no existing code removed |
| No syntax or type errors | Yes | All TypeScript is valid; proper type assertions used |
| Correct imports/exports | Yes | posthog-js imported client-side, posthog-node server-side — correct separation |
| Minimal, focused changes | Yes | All changes relate to PostHog integration |
| Pre-existing issues | None | Base app appears clean |
Issues
.env.examplenot updated with PostHog variables: New environment variablesNEXT_PUBLIC_POSTHOG_PROJECT_TOKENandNEXT_PUBLIC_POSTHOG_HOSTare not documented in.env.example, only in.env.local(which is gitignored). Other developers cloning the repo won't know these variables are needed. [MEDIUM]- Server-side PostHog host may resolve incorrectly:
posthog-server.tsusesprocess.env.NEXT_PUBLIC_POSTHOG_HOSTfor the server-side client host. If this is set tohttps://us.i.posthog.comit's fine, but the.env.localvalue should be verified — the client uses/ingestvia the reverse proxy, which wouldn't work server-side. [LOW]
Other completed criteria
- All changes are PostHog-related with no unrelated edits
- Code follows existing codebase patterns (async handlers, error handling style)
- Both SDK packages correctly added to dependencies
- Build configuration (next.config.ts) is valid with proper rewrite rules
PostHog implementation ⚠️
| Criteria | Result | Description |
|---|---|---|
| PostHog SDKs installed | Yes | posthog-js@^1.372.6 and posthog-node@^5.32.1 in package.json |
| PostHog client initialized | Yes | Client via instrumentation-client.ts (correct for Next.js 15.3+), server via singleton in lib/posthog-server.ts |
| capture() | Yes | 10+ meaningful capture calls across client and server |
| identify() | Yes | Called on both client (login.tsx) and server (sign-in/sign-up APIs), though uses email as distinct_id which is fragile |
| Error tracking | Yes | capture_exceptions: true in init config, plus manual captureException() in catch blocks |
| Reverse proxy | Yes | Correctly configured via Next.js rewrites: /ingest/static/* and /ingest/array/* → us-assets.i.posthog.com, /ingest/* → us.i.posthog.com |
Issues
- Email used as distinct_id: All server-side
capture()andidentify()calls useuser.emailas thedistinct_id. If a user changes their email (which this app supports via account update), their event history fragments. Should use a stable user ID (e.g., databaseuser.id). [MEDIUM] - No
posthog.reset()on logout: The app presumably has a logout flow, but noposthog.reset()call is implemented. This is important for shared devices and is a PostHog best practice. [MEDIUM] - Missing
await posthog.shutdown()in API routes: The server-side singleton client is never shut down after captures. WhileflushAt: 1helps, in serverless environments (common with Next.js), the process may terminate before the HTTP request completes. Each API route should callawait posthog.shutdown()or at minimumawait posthog.flush(). [MEDIUM] - API key env var naming: Uses
NEXT_PUBLIC_POSTHOG_PROJECT_TOKENinstead of the conventionalNEXT_PUBLIC_POSTHOG_KEY. Not a bug, but unconventional. [LOW]
Other completed criteria
- API key loaded from environment variable, not hardcoded
- Host correctly configured via reverse proxy (
/ingest) for client, env var for server - Tracing headers (
X-POSTHOG-DISTINCT-ID,X-POSTHOG-SESSION-ID) passed from client to server for session correlation - `` used in server-side captures to support anonymous-to-identified user merging
PostHog insights and events ⚠️
| Filename | PostHog events | Description |
|---|---|---|
components/login.tsx |
user_signed_in, user_signed_up, captureException |
Client-side auth events with identify, plus error tracking |
pages/pricing.tsx |
checkout_started, captureException |
Checkout initiation with plan/price properties |
pages/api/auth/sign-in.ts |
user_signed_in |
Server-side sign-in with session linking |
pages/api/auth/sign-up.ts |
user_signed_up |
Server-side sign-up with invitation flag |
pages/api/stripe/checkout.ts |
checkout_completed |
Stripe checkout success with subscription details |
pages/api/stripe/webhook.ts |
subscription_updated, subscription_cancelled |
Subscription lifecycle from Stripe webhooks |
pages/api/stripe/customer-portal.ts |
customer_portal_accessed |
Portal access tracking |
pages/api/team/invite.ts |
team_member_invited |
Team invitation with role context |
pages/api/team/remove-member.ts |
team_member_removed |
Team member removal |
pages/api/account/update.ts |
account_updated |
Account settings change |
Issues
- PII in event properties across multiple files:
emailappears incapture()event properties insign-in.ts,sign-up.ts,login.tsx,invite.ts(invited_email), andupdate.ts(updated_email). Emails should only appear in person properties viaidentify()or ``, never in event properties. This violates PostHog best practices and may cause compliance issues. [CRITICAL] - Duplicate client+server captures for auth events: Both
login.tsxandsign-in.ts/sign-up.tscaptureuser_signed_in/user_signed_up. This will result in duplicate events in PostHog for every auth action. Either the client or server should capture these, not both. [MEDIUM]
Other completed criteria
- Events represent real user actions mapping to actual SaaS product flows (signup → checkout → subscription lifecycle)
- Events enable product insights: signup-to-subscription funnel, churn tracking, team growth
- Events include relevant contextual properties (plan names, subscription status, price intervals)
- Event names are descriptive and use consistent snake_case convention
Reviewed by wizard workbench PR evaluator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Automated wizard CI run
Source: context-mill-pr
Trigger ID:
cef44b4App:
next-js/15-pages-router-saasApp directory:
apps/next-js/15-pages-router-saasWorkbench branch:
wizard-ci-cef44b4-next-js-15-pages-router-saasWizard branch:
mainContext Mill branch:
basic-skills-v2PostHog (MCP) branch:
masterTimestamp: 2026-05-01T20:58:17.620Z
Duration: 491.9s