0

我正在尝试使用 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 事件中。

有人对如何解决这个问题有想法吗?

4

1 回答 1

1

不知道为什么要为每个产品调用 dataLayer 推送。您需要首先创建一个包含所有产品的数组,然后使用所有产品调用 dataLayer.push。此外,我建议将您一次推送的产品数量限制为 10 或 20 个,否则请求可能会变得太大而可能无法发送。

似乎您正在两次推动相同的产品。

于 2017-05-01T19:00:56.377 回答