gtm-module
gtm-module copied to clipboard
A huge setTimeout delay of 250ms
Triggering tags has a delay, that may impact data gathering (especially first load call). I have found this peace of code:
function startPageTracking(ctx) {
ctx.app.router.afterEach((to) => {
setTimeout(() => {
ctx.$gtm.push(to.gtm || {
routeName: to.name,
pageType: 'PageView',
pageUrl: '' + to.fullPath,
pageTitle: (typeof document !== 'undefined' && document.title) || '',
event: 'smt'
})
}, 250)
})
}
And I do understand why setTimeout(250) is here, because of DOM re-rendering delay. As soon as I set it to 0, gtm pushes a title of a previous page instead of a current one. Is there more reliable way of catching it?
for a reference:
- https://github.com/nuxt-community/analytics-module/issues/8#issuecomment-573637447
- https://github.com/MatteoGabriele/vue-analytics/commit/e0a92e301aa992a64936075d5da141c2c0821b38
function startPageTracking (ctx) {
ctx.app.router.afterEach((to) => {
Vue.nextTick().then(() => {
ctx.$gtm.push(to.gtm || {
routeName: to.name,
pageType: 'PageView',
pageUrl: '<%= options.routerBase %>' + to.fullPath,
pageTitle: (typeof document !== 'undefined' && document.title) || '',
event: '<%= options.pageViewEventName %>'
})
})
})
}
nuxt.config.js
export default {
......
features: {
transitions: false
},
vueMeta: {
refreshOnceOnNavigation: true
},
......
}
app/router.scrollBehavior.js
export default function () {
return { x: 0, y: 0 };
}
related https://github.com/nuxt-community/analytics-module/issues/8#issuecomment-573637447 https://nuxtjs.org/api/configuration-router#scrollbehavior