Skip to content

Instantly share code, notes, and snippets.

@voltane
Created April 14, 2020 13:58
Show Gist options
  • Save voltane/d1ca4efadef7f7c7bfd65e3f18039a66 to your computer and use it in GitHub Desktop.
Save voltane/d1ca4efadef7f7c7bfd65e3f18039a66 to your computer and use it in GitHub Desktop.
GTM for Nuxt - PageView problem proposal
const createMixin = (): VueConstructor | ComponentOptions<Vue> => ({
beforeRouteEnter: (to: Route, from: Route, next: Function) => {
next((vm: Vue) => {
setTimeout(() => {
// Enter Your code which send event to GTM
// @ts-ignore
window[this.options.layer].push(to.gtm || {
event: this.options.pageViewEventName,
pageType: 'PageView',
pageUrl: to.fullPath,
pageTitle: document.title,
routeName: to.name,
})
}, 0)
})
},
})
Vue.mixin(createMixin())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment