Repository navigation
fix: record client navigations in apps without pages - #235
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With
trackOnRouteChange: true, an app without apages/directory recorded only the landing visit. Later client-side navigations to new campaign URLs were never captured.Without pages, Nuxt uses its minimal router. It keeps one reactive route object and updates it with
Object.assignbefore it calls theafterEachguards, and thefromargument is that same object. By the time the plugin's guard ran,fromalready matchedto, so theto.fullPath !== from.fullPathcheck skipped every navigation.The plugin now compares each navigation with the last full path it saw, starting from the route it records on mount. The starting point is the visited route the landing capture already uses. While a prerendered page hydrates, the live route is still the prerendered path without its query, and Nuxt then replays the visited URL with
router.replace. Starting from the live route would treat that replay as a navigation and runutm:before-tracka second time for the landing visit.Release note
Apps without a
pages/directory that enabletrackOnRouteChangenow record client-side navigations, as the option describes. Apps with pages record the same navigations as before.Validation
A browser test in an app without pages lands on
/?utm_source=landing, navigates to/?utm_source=newsletter, and expects the newsletter visit as the last touch, with both visits in history. On main it fails withexpected 'Last touch: landing' to be 'Last touch: newsletter', and with this change it passes. A second browser test, in a pages app, lands on a prerendered page with async setup, follows a link to a new campaign, and expectsutm:before-trackto run once for each. It passes on main and with this change, and fails with three calls when the comparison starts from the live route. Built against Nuxt 3.21.11, the same app without pages behaves the same way: main's plugin keepslandingas the last touch and stores one visit, while this change stores both.pnpm test(153 passed, 1 skipped), lint, format, and the root and playground type checks pass locally.