Skip to content

[CI] (8f345fc) next-js/15-pages-router-saas#277

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

[CI] (8f345fc) next-js/15-pages-router-saas#277
wizard-ci-bot[bot] wants to merge 1 commit intomainfrom
wizard-ci-8f345fc-next-js-15-pages-router-saas

Conversation

@wizard-ci-bot
Copy link

@wizard-ci-bot wizard-ci-bot bot commented Jan 28, 2026

Automated wizard CI run

Source: scheduled
Trigger ID: 8f345fc
App: next-js/15-pages-router-saas
App directory: apps/next-js/15-pages-router-saas
Workbench branch: wizard-ci-8f345fc-next-js-15-pages-router-saas
Wizard branch: main
Context Mill branch: main
PostHog (MCP) branch: master
Timestamp: 2026-01-28T16:25:07.831Z
Duration: 547.4s

@wizard-ci-bot
Copy link
Author

wizard-ci-bot bot commented Jan 28, 2026

TypeScript compilation passes. Now I have all the information I need to write the evaluation report.


PR Evaluation Report

Summary

This PR integrates PostHog analytics into a Next.js 15 Pages Router SaaS application. It adds both client-side (posthog-js) and server-side (posthog-node) tracking, implements a reverse proxy to bypass ad blockers, and tracks comprehensive user journey events including authentication, checkout, subscriptions, and team management.

Files changed Lines added Lines removed
19 +688 -7

Confidence score: 4/5 👍

  • Server-side PostHog client missing flush calls: The posthog-node client uses flushAt: 1 and flushInterval: 0 for immediate flushing, but serverless API routes may terminate before events are sent. Consider calling posthog.flush() after capturing events. [MEDIUM]
  • Potential PII in events: The invited_email property in team_member_invited event captures email addresses which could be considered PII. Consider hashing or removing this property. [LOW]
  • Missing PostHog env vars in .env.example: NEXT_PUBLIC_POSTHOG_KEY and NEXT_PUBLIC_POSTHOG_HOST are not documented in .env.example, though they are mentioned in the setup report. [LOW]

File changes

Filename Score Description
instrumentation-client.ts 4/5 Proper PostHog client initialization with reverse proxy, exception capture, and debug mode. Uses correct /ingest api_host for proxy.
lib/posthog-server.ts 4/5 Singleton pattern for server-side PostHog client with proper lazy initialization. Missing explicit flush in serverless context.
next.config.ts 5/5 Clean reverse proxy setup with rewrites for PostHog ingestion and static assets. Includes skipTrailingSlashRedirect for API compatibility.
package.json 5/5 Both posthog-js and posthog-node added with appropriate versions.
components/header.tsx 5/5 Proper logout tracking with posthog.reset() to unlink future events. Exception capture in error handler.
components/login.tsx 5/5 Client-side identify and auth events with distinct ID correlation to server. Exception capture on errors.
pages/pricing.tsx 5/5 Tracks pricing plan selection with relevant properties. Passes distinct ID to server for correlation.
pages/api/auth/sign-up.ts 4/5 Server-side signup tracking with identify. Captures meaningful properties including team and invitation context.
pages/api/auth/sign-in.ts 4/5 Server-side sign-in tracking with identify. Good user context properties.
pages/api/auth/sign-out.ts 4/5 Tracks sign-out with conditional capture when distinct ID is available.
pages/api/stripe/checkout.ts 4/5 Tracks checkout completion with subscription and plan details.
pages/api/stripe/create-checkout.ts 4/5 Tracks checkout initiation with price and team context.
pages/api/stripe/customer-portal.ts 4/5 Tracks customer portal access with plan context.
pages/api/stripe/webhook.ts 4/5 Tracks subscription updates/cancellations from Stripe webhooks with proper distinct ID fallback.
pages/api/team/invite.ts 4/5 Tracks team invitations. Contains invited_email which may be PII.
pages/api/team/remove-member.ts 4/5 Tracks team member removal with relevant context.
pages/api/account/update.ts 5/5 Tracks account updates and properly updates person properties via identify.
pnpm-lock.yaml 5/5 Lock file properly updated with new dependencies.
posthog-setup-report.md 5/5 Comprehensive documentation of implementation and next steps.

App sanity check: 4/5 ✅

Criteria Result Description
App builds and runs Partial TypeScript compilation passes. Build fails due to pre-existing POSTGRES_URL requirement (not PostHog-related).
Preserves existing env vars & configs Yes Existing .env.example unchanged; PostHog vars documented separately in setup report.
No syntax or type errors Yes tsc --noEmit passes without errors.
Correct imports/exports Yes All PostHog imports are correct and modules properly exported.
Minimal, focused changes Yes Changes are confined to PostHog integration; no unnecessary modifications to app logic.

Issues

  • Missing env var documentation: PostHog environment variables (NEXT_PUBLIC_POSTHOG_KEY, NEXT_PUBLIC_POSTHOG_HOST) should be added to .env.example for discoverability. [LOW]

Other completed criteria

  • Code is clear and readable with helpful comments
  • Consistent patterns across all API route modifications
  • Appropriate error handling preserved
  • No hardcoded API keys
  • Build configuration valid

PostHog implementation: 4/5 ✅

Criteria Result Description
PostHog SDKs installed Yes posthog-js@^1.335.5 and posthog-node@^5.24.3 in package.json
PostHog client initialized Yes Client-side via instrumentation-client.ts; server-side via singleton in lib/posthog-server.ts
capture() Yes 14 distinct events captured across auth, checkout, subscriptions, and team management
identify() Yes User identification on sign-up, sign-in, and account update via both client and server
Error tracking Yes capture_exceptions: true in client config; posthog.captureException() in error handlers
Reverse proxy Yes Properly configured in next.config.ts with rewrites to us.i.posthog.com and us-assets.i.posthog.com

Issues

  • Missing flush in serverless context: Server-side posthog.capture() calls in API routes may not complete before the function terminates. Add await posthog.flush() after captures or use await posthog.shutdownAsync() in response cleanup. [MEDIUM]

Other completed criteria

  • API key accessed via environment variable (NEXT_PUBLIC_POSTHOG_KEY)
  • Correct API host configuration with reverse proxy
  • Client-server distinct ID correlation via X-PostHog-Distinct-ID header
  • Proper posthog.reset() on logout to unlink anonymous events
  • Debug mode enabled in development

PostHog insights and events: 5/5 ✅

Filename PostHog events Description
components/login.tsx user_logged_in, user_signed_up, captureException Client-side auth events with email identification
components/header.tsx user_logged_out, captureException Logout tracking with session reset
pages/pricing.tsx pricing_plan_selected, captureException Plan selection with price and interval details
pages/api/auth/sign-up.ts user_signed_up Server-side signup with team context and invitation tracking
pages/api/auth/sign-in.ts user_signed_in Server-side sign-in with user and team identification
pages/api/auth/sign-out.ts user_signed_out Server-side logout tracking
pages/api/stripe/create-checkout.ts checkout_started Checkout initiation with price and team context
pages/api/stripe/checkout.ts checkout_completed Successful checkout with plan and subscription details
pages/api/stripe/webhook.ts subscription_updated, subscription_cancelled Subscription lifecycle from Stripe webhooks
pages/api/stripe/customer-portal.ts customer_portal_opened Billing portal access tracking
pages/api/team/invite.ts team_member_invited Team growth tracking with role context
pages/api/team/remove-member.ts team_member_removed Team churn tracking
pages/api/account/update.ts account_updated Profile changes with person property updates

Issues

None critical. Events are well-designed for funnel analysis and product insights.

Other completed criteria

  • Events capture real user actions and business-critical flows
  • Properties enriched with relevant context (user_id, team_id, plan details)
  • Enables key funnels: signup → checkout → subscription
  • Tracks full subscription lifecycle including cancellations
  • Team collaboration events for growth analysis
  • Source property (api, webhook) distinguishes event origins

Reviewed by wizard workbench PR evaluator

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