Issue: 3141

Google analytics tracks the default title set in nuxt.config.js.

[issue link]

I track the site with Google analytics.


export default ({app}) => {
  if (process.env.NODE_ENV !== 'production') return;
  (function (win, doc, script, url) {
    let a = doc.createElement(script);
    let m = doc.getElementsByTagName(script)[0];
    a.async = 1;
    a.src = url;
    m.parentNode.insertBefore(a, m);
  })(window, document, 'script', 'https://www.googletagmanager.com/gtag/js?id=UA-xxxxxxxx-1');

  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-xxxxxxxx-1');

  app.router.afterEach((to, from) => {
    gtag('config', 'UA-xxxxxxxx-1', to.fullPath);

In most cases, this code works fine, but sometimes the title set in nuxt.config.js is tracked instead of the original page title, when the page is initially displayed.

I want to track Google analytics at the time when vue-meta resolves the correct page title, what is the solution?

Could anyone help me?

This question is available on Nuxt.js community (#c2721)