Skip to content

fix(next): export track from Next.js binding and fix hard-refresh event loss#198

Merged
feugy merged 1 commit intocanaryfrom
damien/fix-track
Mar 31, 2026
Merged

fix(next): export track from Next.js binding and fix hard-refresh event loss#198
feugy merged 1 commit intocanaryfrom
damien/fix-track

Conversation

@feugy
Copy link
Copy Markdown
Member

@feugy feugy commented Mar 28, 2026

🖖🏻 What's in there?

  • Export track from @vercel/analytics/next — the Next.js binding was missing a track export, requiring users to import it from a the react entry point.

  • Fix track() silently dropping events on hard refresh — when track() was called before inject() ran (which happens on hard refresh because React runs children's useEffects before parents'), window.va was still undefined and the optional chain ?. silently swallowed the event. Fixed by calling initQueue() at the start of track() so events are always buffered, regardless of initialization order.

  • Type improvements in types.ts — reorganized type declarations and added TrackEventPayload and a payload field on CustomEvent in BeforeSendEvent for better typing of the beforeSend callback.

🔬 Notes to reviewers

I made an Experiment page in the next-15 demo app to illustrate the lost tracked events. And slightly improved the look of these test pages.

Also fixed the damn e2e tests that were failing since ages

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
analytics-astro Ready Ready Preview, Comment Mar 29, 2026 1:09am
analytics-next15 Ready Ready Preview, Comment Mar 29, 2026 1:09am
analytics-nextjs Ready Ready Preview, Comment Mar 29, 2026 1:09am
analytics-nuxt Ready Ready Preview, Comment Mar 29, 2026 1:09am
analytics-remix Ready Ready Preview, Comment Mar 29, 2026 1:09am
analytics-sveltekit Ready Ready Preview, Comment Mar 29, 2026 1:09am
analytics-vue Ready Ready Preview, Comment Mar 29, 2026 1:09am

Request Review

Copy link
Copy Markdown
Collaborator

@tobiaslins tobiaslins left a comment

Choose a reason for hiding this comment

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

Thanks for finding and fixing!

@feugy feugy changed the base branch from main to canary March 31, 2026 09:41
@feugy feugy merged commit b525453 into canary Mar 31, 2026
14 checks passed
@feugy feugy deleted the damien/fix-track branch March 31, 2026 09:41
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.

2 participants