如何覆盖Nuxt的GTM模块中的GTM事件对象以进行页面跟踪?

我正在查看模块中的这一行:

window[this.options.layer].push(to.gtm || { event: this.options.pageViewEventName,pageType: 'PageView',pageUrl: to.fullPath,routeName: to.name })

来源:https://github.com/nuxt-community/modules/blob/24427eb4dce4e516a68e6523297d3375a024df0b/packages/google-tag-manager/plugin.js#L24

任何想法都应如何提供在上一行中传递的to.gtm值?我尝试挂钩到组件中的beforeRouteEnter,但是即使更改to.gtm属性,传递给to.params的值似乎也无法通过。

beforeRouteEnter(to,from,next) {
    if (process.client) {
      console.log('BRE',to,window.dataLayer);
      if (to.params.test123) {
        next();
      } else {
        const newTo = Object.assign({},to);
        newTo.gtm = { event: 'nuxtRoute3' };
        newTo.params.test123 = 'test';
        console.log(newTo);
        next(newTo);
      }
    } else {
      next();
    }
  }
nihaolizhiguo 回答:如何覆盖Nuxt的GTM模块中的GTM事件对象以进行页面跟踪?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3168433.html

大家都在问