Skip to content

Conversation

@wizard-ci-bot
Copy link

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

Automated wizard CI run

Source: manual
Trigger ID: 3864784
App: next-js/15-pages-router-saas
App directory: apps/next-js/15-pages-router-saas
Workbench branch: wizard-ci-3864784-next-js-15-pages-router-saas
Wizard branch: main
Examples branch: main
PostHog (MCP) branch: master
Timestamp: 2026-01-21T22:28:40.526Z
Duration: 545.2s

@wizard-ci-bot
Copy link
Author

wizard-ci-bot bot commented Jan 21, 2026

Now I have all the information I need. Let me write the comprehensive PR 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) SDKs, implements a reverse proxy for ad-blocker circumvention, and adds comprehensive event tracking across authentication flows, subscription management, and team operations.

Files changed Lines added Lines removed
18 +694 -4

Confidence score: 4/5 👍

  • Client-side PostHog initialization may not load correctly: The instrumentation-client.ts file relies on Next.js 15's client instrumentation feature, but this is primarily designed for App Router. For Pages Router, PostHog should be initialized in _app.tsx or via a provider component to ensure it loads on all pages. [MEDIUM]
  • Server-side events not flushed before response: The posthog-node capture calls are fire-and-forget without awaiting posthog.flush(). In serverless environments, events may be lost if the function terminates before the async buffer flushes. [MEDIUM]
  • Duplicate event tracking on client and server: Sign-in/sign-up events are captured both client-side (login.tsx) and server-side (sign-in.ts, sign-up.ts) with slightly different event names (user_logged_in vs user_signed_in), which could cause analytics confusion. [LOW]

File changes

Filename Score Description
instrumentation-client.ts 3/5 New file for PostHog client init. Uses Next.js 15 instrumentation pattern which may not work correctly with Pages Router.
lib/posthog-server.ts 4/5 Clean singleton pattern for server-side PostHog client. Uses aggressive flush settings (flushAt: 1, flushInterval: 0).
next.config.ts 5/5 Correctly implements reverse proxy rewrites for PostHog to circumvent ad blockers.
package.json 5/5 Adds posthog-js and posthog-node dependencies with appropriate versions.
components/header.tsx 5/5 Clean integration of sign-out tracking with posthog.reset() call.
components/login.tsx 4/5 Adds user identification and event capture, but duplicates server-side events.
pages/api/account/update.ts 4/5 Adds account_updated event and identify call. No flush await.
pages/api/auth/sign-in.ts 4/5 Comprehensive sign-in tracking with user properties. No flush await.
pages/api/auth/sign-up.ts 4/5 Tracks sign-up and invitation_accepted events. No flush await.
pages/api/stripe/checkout.ts 4/5 Tracks checkout_completed with rich subscription properties. No flush await.
pages/api/stripe/create-checkout.ts 4/5 Tracks checkout_started with plan context. No flush await.
pages/api/stripe/webhook.ts 4/5 Tracks subscription_updated and subscription_cancelled from webhooks. Uses customer ID as distinct_id which is reasonable.
pages/api/team/invite.ts 4/5 Tracks team_member_invited with relevant properties. No flush await.
pages/api/team/remove-member.ts 4/5 Tracks team_member_removed event. No flush await.
pages/dashboard/index.tsx 5/5 Adds manage_subscription_clicked event and exception capture.
pages/pricing.tsx 5/5 Tracks pricing_plan_selected with plan details and exception capture.
pnpm-lock.yaml 5/5 Lock file correctly updated with PostHog dependencies.
posthog-setup-report.md 5/5 Well-documented setup report with event inventory.

App sanity check: 4/5 ✅

Criteria Result Description
App builds and runs Yes Build completes successfully with no errors
Preserves existing env vars & configs Yes Existing .env vars preserved, PostHog vars added
No syntax or type errors Yes TypeScript compilation succeeds
Correct imports/exports Yes All imports resolve correctly
Minimal, focused changes Yes Changes are focused on PostHog integration only

Issues

  • Client instrumentation may not load in Pages Router: The instrumentation-client.ts pattern is designed for App Router. In Pages Router, this file may not be automatically loaded. Consider importing PostHog initialization in _app.tsx instead. [MEDIUM]

Other completed criteria

  • Environment variables properly documented in .env
  • No PII exposed in committed files
  • API key uses NEXT_PUBLIC_ prefix appropriately for client-side access
  • Consistent code style matching existing patterns

PostHog implementation: 4/5 ✅

Criteria Result Description
PostHog SDKs installed Yes posthog-js@^1.333.0 and posthog-node@^5.24.1 in package.json
PostHog client initialized Partial Client initialized in instrumentation-client.ts, server singleton in lib/posthog-server.ts. Client init may not load for Pages Router.
capture() Yes 14+ distinct events captured across auth, checkout, team, and subscription flows
identify() Yes User identification on sign-in, sign-up, and account update with email, name, role properties
Error tracking Yes capture_exceptions: true in client config, captureException() calls in login, dashboard, pricing
Reverse proxy Yes Correctly configured in next.config.ts with /ingest rewrites to us.i.posthog.com

Issues

  • Client instrumentation pattern: instrumentation-client.ts is a Next.js 15 App Router feature. For Pages Router, initialize PostHog in _app.tsx or use a custom <PostHogProvider>. [MEDIUM]
  • Server-side events may be lost: posthog.capture() calls are not awaited and no flush() is called before response ends. In serverless/edge environments, events may be lost. Add await posthog.flush() or use posthog.capture(...); await posthog.flush() pattern. [MEDIUM]
  • Duplicate event names: Client captures user_logged_in while server captures user_signed_in for same action. Consider consistent naming. [LOW]

Other completed criteria

  • API host correctly set to /ingest for reverse proxy
  • ui_host set to https://us.posthog.com for toolbar/recordings
  • Debug mode enabled only in development
  • defaults: '2025-05-24' option included
  • skipTrailingSlashRedirect: true added for PostHog API compatibility
  • posthog.reset() called on sign-out

PostHog insights and events: 5/5 ✅

Filename PostHog events Description
components/header.tsx user_signed_out Captures sign-out with reset for session tracking
components/login.tsx user_logged_in, user_signed_up, captureException Client-side auth events with invite tracking
pages/api/auth/sign-in.ts user_signed_in Server-side with team_id, subscription status
pages/api/auth/sign-up.ts user_signed_up, invitation_accepted Tracks invite flow separately for funnel analysis
pages/api/account/update.ts account_updated Tracks profile changes with identify update
pages/api/stripe/create-checkout.ts checkout_started Funnel entry point with plan context
pages/api/stripe/checkout.ts checkout_completed Conversion event with subscription details
pages/api/stripe/webhook.ts subscription_updated, subscription_cancelled Churn and upgrade tracking from Stripe webhooks
pages/api/team/invite.ts team_member_invited Team growth tracking
pages/api/team/remove-member.ts team_member_removed Team churn tracking
pages/dashboard/index.tsx manage_subscription_clicked, captureException Engagement tracking
pages/pricing.tsx pricing_plan_selected, captureException Pricing funnel with plan details

Issues

None - event coverage is comprehensive and well-designed.

Other completed criteria

  • Events cover full user lifecycle: signup → subscription → team management → churn
  • Rich properties enable segmentation (team_id, plan_name, subscription_status)
  • Source property (api, stripe_webhook) enables channel analysis
  • Funnel-ready events: pricing_plan_selectedcheckout_startedcheckout_completed
  • Team analytics: team_member_invitedinvitation_acceptedteam_member_removed
  • Error tracking integrated into critical user flows

Reviewed by wizard workbench PR evaluator

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

1 participant