nuxt-community / google-gtag-module

Enable google gtagjs for NuxtJs
MIT License
147 stars 27 forks source link

Google analytics tracks wrong page title on `disableAutoPageTrack: false` #10

Closed TugayYaldiz closed 5 years ago

TugayYaldiz commented 5 years ago

The problem is head() executed so late in the lifecycle and router.afterEach executes before that. This causes the analytics send incompatible path and page title.

Anyways, until this issue resolved you can set disableAutoPageTrack: true and manually handle each route change in pages folder mounted() hooks.

Example:

 mounted() {
    if (process.browser) {
      this.$gtag('config', 'UA-XXXX-XXX', {
        page_title: this.$metaInfo.title,
        page_path: this.$route.fullPath,
      })
    }
  },

this would execute after head()so the page_title and page_path are sent compatible now.

dohomi commented 5 years ago

I think this is the recommended way to be bullet proof. Will add this example to the readme