javascript - 谷歌通用分析 : push several sub-events in one impressions event (E-commerce)

标签 javascript google-analytics e-commerce google-tag-manager google-datalayer

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

enter image description here

目录列表中显示的每个产品最终都会成为数据层中的一个印象对象,而不是拥有一个包含所有信息的印象对象(例如 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 
         }]
     }
 });
}

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

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

最佳答案

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

您似乎还两次推销同一个产品。

关于javascript - 谷歌通用分析 : push several sub-events in one impressions event (E-commerce),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43709075/

相关文章:

windows-phone-8 - 适用于 Windows Phone 的 Google Analytics UTM 跟踪

javascript - 可以忘记没有打开 javascript 的人吗?

testing - 如何测试信用卡电子商务软件?

javascript - 滚动子 iframe 时接收 touchmove 事件

javascript - jQuery 多个 Accordion |仅展开一个选项卡

javascript - 如何检查对象名称?

google-analytics - 使用 Google Analytics 跟踪线下转化

javascript - 同一用户在同一天拥有多个 IP,并使用 Analytics JavaScript 跟踪器

e-commerce - 如何在magento中调整媒体图像的大小?

javascript - Bootstrap 日期选择器未在自定义灯箱中打开