Hi. 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? Thanks.
<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2721">#c2721</a>)</em></sub></div>