我已从网页中检索 ID 数据作为自定义 Javascript 变量:
function() {
var productID = document.querySelectorAll('a[data-productID]');
var allproductID = Array.prototype.map.call(productID, function(a) {
return a.getAttribute('data-productID');
});
return allproductID;
}
这个函数返回页面中的所有id,这很好。
但现在我需要通过跟踪代码管理器将这些 ID 发送给谷歌,
我正在寻找的是如何在这些返回数组中循环并将值从 Array 放入“id”并将其推送到 Google,最终结果必须如下:
<script>
gtag('event','view_item', {
value: 'somevalue'
'items': [
{
'id': 1234,
'google_business_vertical': 'retail'
},
{
'id': 45678,
'google_business_vertical': 'retail'
}
]
});
</script>
谢谢