Skip to content

TOF-438: Fix broken code snippets on Next.js integration page - #171

Open
tylergoerzen-mxp with Copilot wants to merge 3 commits into
mainfrom
copilot/tof-438-fix-nextjs-integration-code
Open

TOF-438: Fix broken code snippets on Next.js integration page#171
tylergoerzen-mxp with Copilot wants to merge 3 commits into
mainfrom
copilot/tof-438-fix-nextjs-integration-code

Conversation

Copilot AI commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Two broken code snippets on the Next.js integration page caused runtime errors for users following the guide.

Changes

  • Missing trackPageView export — the page router example imported trackPageView from mixpanelClient but the function was never defined in that file. Added the export:

    export const trackPageView = (url) => {
      mixpanel.track('Page View', { url });
    }
  • Incorrect import style for MixpanelProviderlayout.js snippet used a named import ({ MixpanelProvider }) but the component is a default export. Fixed to:

    import MixpanelProvider from '../components/MixpanelProvider';

@linear-code

linear-code Bot commented Aug 18, 2026

Copy link
Copy Markdown

TOF-438

Co-authored-by: tylergoerzen-mxp <259741734+tylergoerzen-mxp@users.noreply.github.com>
@mintlify

mintlify Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
mixpanel-docs 🟢 Ready View Preview Aug 18, 2026, 6:58 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

Copilot AI changed the title [WIP] Fix broken code on the Next.js integration page TOF-438: Fix broken code snippets on Next.js integration page Aug 18, 2026
Copilot AI requested a review from tylergoerzen-mxp August 18, 2026 18:55
@greptile-apps

greptile-apps Bot commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5

The PR is not safe to merge until the Pages Router snippet retains exactly one page-view event for client-side navigation.

Removing the route-change listener resolves duplicate events, but autocapture: true alone does not enable SPA route-change page views, so documented applications lose navigation analytics.

Files Needing Attention: docs/tracking-methods/integrations/nextjs.mdx

Important Files Changed

Filename Overview
docs/tracking-methods/integrations/nextjs.mdx The import correction is sound, but the Pages Router update drops client-side navigation page views because SPA tracking is not enabled.

Reviews (2): Last reviewed commit: "Rely on Autocapture for Next.js pageview..." | Re-trigger Greptile

Comment thread docs/tracking-methods/integrations/nextjs.mdx Outdated
@tylergoerzen-mxp
tylergoerzen-mxp marked this pull request as ready for review August 18, 2026 19:06
@tylergoerzen-mxp
tylergoerzen-mxp requested a review from a team as a code owner August 18, 2026 19:06
The page initializes with autocapture: true, which defaults pageview to
"full-url" (see docs/tracking-methods/sdks/javascript.mdx). Next.js route
changes are history.pushState calls, so Autocapture already emits a
pageview on each one. The added trackPageView helper fired a second,
billable "Page View" event alongside it.

Drop the manual pageview path so the Pages Router example matches the
App Router example, which already inits only. Also fix the .env block
mislabeled as javascript, and _app.tsx (app.tsx is just a route).

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
4. Initialize Mixpanel in your Next.js application

a. **If using page router**, open or create the file `_app.js` or `app.tsx` in your pages/ directory. Then import and initialize Mixpanel inside `useEffect`. You’ll also need to track pageviews manually using `useRouter`.
a. **If using page router**, open or create the file `_app.js` or `_app.tsx` in your `pages/` directory. Then import and initialize Mixpanel inside `useEffect`. Autocapture tracks pageviews on route change for you, so you don't need to track them manually.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Client-side page views disappear

When a Pages Router user navigates through Next.js links or the router, autocapture: true without an SPA-compatible track_pageview setting does not record the route change, causing all page views after the initial load to be missing from analytics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants