我正在尝试使用 Universal Analytics 在电子商务目录页面上实现产品印象( https://developers.google.com/tag-manager/enhanced-ecommerce#product-impressions )。我遇到的问题具有实际性质,我想推送一个包含每个印象对象的事件,而不是每个正在显示的目录产品的事件,但情况并非如此:
目录列表中显示的每个产品最终都成为 dataLayer 中的一个印象数对象,而不是拥有一个包含所有信息的印象数对象(例如 Google 自己的示例)。有没有办法将每个 productImpressions 事件嵌套到一个中,然后推送包含所有目录页面结果的那个对象?这是我目前实现的代码,用于推送到 dataLayer:
// Product View, triggered when product is viewed on any page:
function googleTagManagerProductViewDataLayerPush(productName, productSKU, productPrice,
productBrand, productCategory, productVariant, productList, positionInList, regularProductPrice) {
dataLayer.push({
'event': 'productImpressions',
'ecommerce': {
'currencyCode': 'SEK',
'impressions': [{
'name': productName,
'id': productSKU,
'price': productPrice,
'brand': productBrand,
'category': productCategory,
'variant': productVariant,
'list': productList,
'position': positionInList,
'metric1': regularProductPrice
},
{
'name': productName,
'id': productSKU,
'price': productPrice,
'brand': productBrand,
'category': productCategory,
'variant': productVariant,
'list': productList,
'position': positionInList,
'metric1': regularProductPrice
}]
}
});
}
我为我的产品目录中的每个产品/项目调用此函数,例如搜索结果。我想我可以发送数组,但这不会动态地创建每个产品的对象,这些对象嵌套在我想要的一个 productImpressions 事件中。
有人对如何解决这个问题有想法吗?