我正在尝试使用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事件中的每个产品的对象,我想要。
有没有人有关于如何解决这个问题的想法?
I'm trying to implement product impressions (https://developers.google.com/tag-manager/enhanced-ecommerce#product-impressions) on an ecommerce catalog page using Universal Analytics. The problem i'm having is of practical nature, where I want to push one event containing every impression-object rather than an event for each catalogue product being displayed, but that is not the case as can be seen here:
Each product being displayed in the catalogue list ends up becoming an impressions-object by itself in the dataLayer, rather than having one impressions-object with all the information (such as Google's own example). Is there a way of nesting each productImpressions event into one, and then pushing that one object containing all catalogue-page results? This is the code I have implemented at the moment which does the pushing to the 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 }] } }); }I call this function for each product/item on my product catalogue, for instance search results. I'm thinking I could send in arrays but that wouldn't dynamically create objects of each product being displayed nested within one productImpressions event, which I would like.
Does anyone have ideas on how to solve this?
最满意答案
不确定为什么要为每个产品调用dataLayer。 您需要首先创建所有产品的数组,然后使用所有产品调用dataLayer.push。 此外,我建议限制您一次推送的产品数量,可能是10或20,否则请求可能会变得太大而且可能无法发送。
您似乎也在推动同一产品两次。
Not sure why you are calling the dataLayer push for every single product. You need to first create an array of all the products and then call dataLayer.push with all of them. Also I'd recommend limiting the number of products you push at once, to maybe 10 or 20 because otherwise the request can get too big and might not be sent.
It also seems like you are pushing the same product twice.
更多推荐
发布评论