question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Track landing page view before router redirect

See original GitHub issue

In our app we have router redirect to sign in page if user’s auth token has expired. If we want additionally track UTM parameters (utm_source, utm_medium, etc), we pass it in the URL. For example:

/dashboard?utm_source=push&utm_medium=welcome

If a user is signed in, the VueGtag takes this URL with utm_* params and tracks them correctly. If a user is not signed in and we redirect it immediately to /sign-up, and it tracks the latter URL. Probably to the race condition.

Of course possible solutions are:

  • Pass utm_* params to redirected URL. However there is not the only such case and dragging querystring through all redirects is a bit ugly in a large app.
  • Wait for the tracking event to happen and redirect then. We tried:
Vue.use(VueGtag, {
  config: { id: "..." },
  onAfterTrack () {
     redirectNow()
  }
}, router)

But for some reason onAfterTrack() is never called (vue-gtag version 1.16.1). Moreover it’s not clear if it is called always. For example when adblocker is active, or what if there is a network latency or Analytics service down.

If there any recommendation how to handle such race conditions in a best way or do we miss something?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
snekocommented, May 16, 2022

@ipa1981 in case you still want to solve this issue I worked on a third-party library (https://github.com/sneko/utm-synapse) that I integrated into vue-gtag. Please see https://github.com/MatteoGabriele/vue-gtag/pull/445 for details 👍

PS: about your wondering on onAfterTrack(), this one is not called for the first track, just for subsequent ones (see https://github.com/MatteoGabriele/vue-gtag/blob/8c2e39555fb867a38251ca48c6011256603df69d/src/add-routes-tracker.js#L18-L47).

0reactions
HugoMullercommented, Jul 13, 2022

Hi,

@MatteoGabriele is there any reason why the hooks onBeforeTrack() and onAfterTrack()are not called on the landing page (first track)? They could be called at least with the current route, like track.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Track Landing Page Redirects Using Google Analytics
Tracking your redirects can be a helpful way to measure your site's progress and goals. This article explores the use of query strings...
Read more >
Redirects in React Router - Stack Abuse
For instance, if you would be redirecting to the "/error-page" route, ensure you have already declared the route previously before setting ...
Read more >
How to Track Landing Page Redirects ... - Elegant Themes
Make sure that is set to Landing Page. Then in the search bar just beneath that, type in the redirect query string that...
Read more >
How to use Chrome's network debugger with redirects
Another great solution to debug the Network calls before redirecting to other pages is to select the beforeunload event break point.
Read more >
Track Single Page App with Google Analytics 4 and Google ...
Tracking page views on regular websites is fairly easy: you just add a tracking code to every page and done! Whenever a visitor...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found