这是我的dataLayer数组:
dataLayer = [{
'giftBatch' : {
'giftID': '',
'giftAmount': 0,
'giftCount': 0,
'giftUpdate': {
'giftPhase': 'Gift Empty'
}
},
'txBatch': {
'txID': '',
'txTotal': 0,
'txURL': window.location.href,
'txUpdate': {
'txPhase': 'Transaction Opened',
'txT0': new Date(),
'txT1': ''
'txT2': ''
}
}
}];
Run Code Online (Sandbox Code Playgroud)
控制台结果为:Array [Object1]
根据需要,Object1包含“ giftBatch”和“ txBatch”对象。
我有一个触发器,稍后触发以更新dataLayer中的对象。
例如,将“ giftAmount”更新为50,将“ giftCount”更新为1。
我尝试了以下方法(我仅展示了一次修改“一个对象”的失败尝试),
尝试1:
dataLayer.push({giftAmount : 50});
Run Code Online (Sandbox Code Playgroud)
结果:
数组[object1,object2]
Object1与上面相同,
Object2是一个新对象,其属性为'Gift Amount':50,
尝试2:
dataLayer.push({giftBatch.giftAmount: 222});
Run Code Online (Sandbox Code Playgroud)
结果: SyntaxError:缺少:属性ID之后
尝试3:
dataLayer.push({'giftBatch.giftAmount' : 50});
Run Code Online (Sandbox Code Playgroud)
结果:
数组[object1,object2]
Object1与上面相同,
Object2是一个具有'giftBatch.giftAmount'属性的新对象:50 …
javascript arrays google-analytics google-tag-manager google-datalayer