Skip to content

Conversation

@Mercy811
Copy link
Contributor

When a user directly visits a page in an SPA (e.g., Next.js), the plugin's saveURLInfo() function was being triggered by SPA hydration events (history.replaceState) before the first event was tracked. This caused the storage to be initialized with both current and previous page set to the same URL.

The fix updates saveURLInfo() to check if storage already exists:

  • If storage exists: move current page to previous (normal navigation)
  • If storage is empty: use document.referrer as previous page (first load)

This ensures that on direct visits with no referrer, Previous Page Type is set to "direct" and Previous Page Location is empty, rather than being incorrectly set to the current page URL.

Fixes #1359

Summary

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?:

When a user directly visits a page in an SPA (e.g., Next.js), the plugin's
saveURLInfo() function was being triggered by SPA hydration events
(history.replaceState) before the first event was tracked. This caused the
storage to be initialized with both current and previous page set to the
same URL.

The fix updates saveURLInfo() to check if storage already exists:
- If storage exists: move current page to previous (normal navigation)
- If storage is empty: use document.referrer as previous page (first load)

This ensures that on direct visits with no referrer, Previous Page Type is
set to "direct" and Previous Page Location is empty, rather than being
incorrectly set to the current page URL.

Fixes #1359
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.

[plugin-page-url-enrichment-browser] Previous Page incorrectly set to current page on direct visit in Next.js/SPAs

3 participants