Google Universal Analytics:在一次展示事件中推送多个子事件(电子商务)

Google Universal Analytics: push several sub-events in one impressions event (E-commerce)

我正在尝试使用 Universal Analytics 在电子商务目录页面上实施产品印象 (https://developers.google.com/tag-manager/enhanced-ecommerce#product-impressions)。我遇到的问题是实际问题,我想推送一个包含每个印象对象的事件,而不是针对正在显示的每个目录产品的事件,但情况并非如此,如下所示:

显示在目录列表中的每个产品最终都成为数据层中的一个印象对象,而不是一个包含所有信息的印象对象(例如 Google 自己的示例) .有没有一种方法可以将每个 productImpressions 事件嵌套到一个事件中,然后推送包含所有目录页面结果的那个对象?这是我目前实现的代码,用于推送到数据层:

// 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 
         }]
     }
 });
}

我为产品目录中的每个 product/item 调用此函数,例如搜索结果。我在想我可以发送数组,但这不会动态创建嵌套在一个 productImpressions 事件中显示的每个产品的对象,这是我想要的。

有没有人知道如何解决这个问题?

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

你也好像推了同一个产品两次。