Я смотрел на эту конкретную строку в модуле:
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();
}
}