-
Notifications
You must be signed in to change notification settings - Fork 195
feat: add option to capture pageviews on navigation history transitions #2435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Size Change: +3.14 kB (+0.07%) Total Size: 4.84 MB
ℹ️ View Unchanged
|
03ad51c to
2148ad7
Compare
Add new 'on_navigation' option for capture_pageleave config that captures pageleave events on every SPA navigation (pushState, replaceState, popstate) in addition to window unload. This enables the expected behavior pattern for pure client-side navigation: - pageView A → (navigate) → pageLeave A + pageView B → (navigate) → pageLeave B + pageView C
2148ad7 to
0be6d6f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 files reviewed, no comments
|
@lricoy what's the use case for this? |
@rafaeelaudibert This is mostly for people using SPA/Client side navigation that would expect to have the pageview/pageleave events matching the same behavior as non-SPAs (each non-first navigation has a pageleave from the previous page and a pageview on the new page). They could implement this themselves on each framework but I think we should have this config available since we're the ones controlling the SDK behavior. It is a recurrent question if people need the |
Yeah, but ultimately the answer is: "no, you don't need that", right? They can run the same analysis just by using the existing events. So that's why I'm playing bad cop here lol Will approve in case you still think strongly that this should be an option - make sure you add the right labels to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you testing that you're not capturing two page leaves when you actually leave the page/browser?
| if (this._instance._shouldCapturePageleaveOnNavigation()) { | ||
| const pageleaveProps = this._instance.pageViewManager.doPageLeave(new Date()) | ||
| // Only capture pageleave if there was a previous page ($prev_pageview_id will be present) | ||
| if (pageleaveProps.$prev_pageview_id) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When could this not be the case? (prev_pageview_id is not present)
Changes
Adds a new
'on_navigation'option for thecapture_pageleaveconfig that captures pageleave events on every history navigation event (pushState, replaceState, popstate) in addition to window unload.This is an extension to the
capture:_pageview: 'history_change'option to allow people who rely on client-side navigation to have this behavior:When
capture_pageleave: 'on_navigation'is set:The regular
trueorif_capture_pageviewwould be:The pageleave event is captured before the new pageview during navigation and has a timestamp as well as all the other expected props because this PR only changes the trigger, everything is still handled by
PageViewManager.$pageleavebehavior.