试图在我的数据播放器中更新一个值,但我无法让它工作。请参阅下面的代码。这在一个具有btn单击方法的类中。顺便说一下。
if (window.google_tag_manager["GTM-XXXXX"].dataLayer.get('ecommerce') !== undefined) {
console.log('update')
window.google_tag_manager["GTM-XXXXXX"].dataLayer.set('ecommerce', {
'productId': `${this.product.id}`,
'productName': `${this.product.productName}`
})
} else {
console.log('create')
window.dataLayer.push({
'ecommerce': {
'productId': `${this.product.id}`,
'productName': `${this.product.productName}`
}});
}根据这份文件,它应该能工作。https://javascript.tutorialink.com/how-to-update-a-datalayer-variable/
这些值在单击时会被拾取。
发布于 2022-09-14 02:39:44
不知道为什么你需要update the dataLayer
如果您使用Google - DataLayer变量来获取数据,您只需按下它,它就会自动更新。
是否有特定的用例或需求?
https://stackoverflow.com/questions/73706896
复制相似问题