MatteoGabriele / vue-gtag

Global Site Tag plugin for Vue (gtag.js)
https://matteo-gabriele.gitbook.io/vue-gtag/
MIT License
870 stars 67 forks source link

Incorrect page title reported via Analytics #282

Closed popovicidinu closed 3 years ago

popovicidinu commented 3 years ago

Description

Hi! I'm working on a project with NuxtJS (SSR mode) and I've installed this library to use with GA v4. It pretty much works outside the box, but I've noticed that if you use "pageTrackerScreenviewEnabled", the dt value is not properly reported on subsequent navigations.

Example:

Page 1: (rendered from SSR): correctly reports the values on the screenview event Page 2: (navigating to a link - I think this is rendered browser based): the screenview event "dt" property still has the old value Page 3: (navigating to another link): the screenview event "dt" property has the value from page 2

I checked the code and it seems to be correct, by using the router.onReady and router.afterEach events, but somehow, even if Vue.nextTick is used, it doesn't actually ensure the entire DOM was loaded.

Expected behavior

The library should report the correct page title to analytics.

Actual behavior

The library reports the previous page title to analytics on subsequent navigations in the browser.

Environment

Run this command in the project folder and fill in their results:

npm ls vue-gtag: vue-gtag@1.11.0

Then, specify:

  1. Operating system: Mac OS
  2. Browser and version: Chrome

Reproducible Demo

export default ({ app }) => { Vue.use(VueGtag, { config: { id: 'G-XXXXX' }, appName: 'XXXX', pageTrackerScreenviewEnabled: true }, app.router) }

Screenshot 2021-04-08 at 18 16 49 Screenshot 2021-04-08 at 18 17 08 Screenshot 2021-04-08 at 18 20 00

The third image show the title from the second image. The second image from the first image. And the first image is correct, because the page was rendered via SSR.

MatteoGabriele commented 3 years ago

unfortunately, SSR always gives issues with vue-router, I can't do much more than waiting for VueRouter to be ready and triggering a nextTick on each route change. This is more an issue with Nuxt or VueRouter or both combined.