如何指定 "list" 产品是从哪个 "list" 添加到购物车的?增强型电子商务

How to specify what "list" the product was added to cart from? Enhanced Ecommerce

正在尝试为我的网站实施 Google Analytics 增强型电子商务跟踪。

如何指定 "list" 将产品添加到购物车的来源?

这是将产品添加到购物篮的标准跟踪代码:

    // Called when a product is added to a shopping cart.
function addToCart(product) {
  ga('ec:addProduct', {
    'id': product.id,
    'name': product.name,
    'category': product.category,
    'brand': product.brand,
    'variant': product.variant,
    'price': product.price,
    'quantity': product.qty
  });
  ga('ec:setAction', 'add');
  ga('send', 'event', 'UX', 'click', 'add to cart');     // Send data using an event.
}

没有任何功能可以指定单击按钮 "add to cart" 的产品列表的名称。

一定是这样的:

ga('ec:setAction', 'click', {'list': 'Search Results'});

但这仅适用于 'click' 操作(不适用于 'add')。 (根据 https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#(product action)

此外,我需要指定产品在列表中的位置。 有什么想法吗?

actionField 中的列表变量仅对 clickdetail 操作有效。 如果你想跟踪客户旅程,你必须合并点击并添加到一个逻辑事件中。

因此,如果您可以直接从列表中添加并且希望在 UA 中将数据绑定在一起,您可以采取一些小的解决方法,例如:

function addToCart(product) {
  ga('ec:addProduct', {
    'id': product.id,
    'name': product.name,
    'category': product.category,
    'brand': product.brand,
    'variant': product.variant,
    'price': product.price,
    'quantity': product.qty    
  });
  ga('ec:setAction', 'click', {'list': 'Search Results'});
  ga('send', 'event', 'automatic', 'click', 'add to cart',{'nonInteraction': 1});     // Send data using an event.

  ga('ec:addProduct', {
    'id': product.id,
    'name': product.name,
    'category': product.category,
    'brand': product.brand,
    'variant': product.variant,
    'price': product.price,
    'quantity': product.qty
  });
  ga('ec:setAction', 'add');
  ga('send', 'event', 'UX', 'click', 'add to cart');     // Send data using an event.
}

添加 detail 操作时应发送 list 属性(应在用户查看产品页面时发送)。

ga('ec:setAction', 'detail', { list: 'Search Results' });

考虑以下场景:

  1. 用户在您的网站上搜索产品,显示结果。此时会为每个产品结果创建印象。
  2. 用户点击其中一个产品结果,您添加一个 click 操作,然后用户被重定向到产品页面。
  3. 页面加载后,您发送 detail 操作,指定 list 属性(作为 setAction 中的参数)。
  4. 用户点击 'Add To Cart',您发送 add 操作。

如果在detail动作中没有指定list 属性,或者根本不发送detail动作,然后调用add 操作,在 Analytics 中查看 Product List Performance 下的数据时,Add To Cart 数据将显示在 产品列表名称 as (未设置).

文档未能在其完整示例中包含这一重要信息,可以在 here

中找到

我遇到了同样的问题,并被困了几个小时。

我的问题是我在与列出和点击产品印象的地方不同的子域上进行结帐过程。 通过简单地在 GA 页面浏览标签 i GTM 上添加一个字段,"cookieDomain" = "auto",所有开始工作 - Cross Domain Tracking with Google Tag Manager

我唯一需要添加有关列表的信息的地方是:

  • 产品印象列表。 'list' : 'Search result'
  • 产品点击(来自印象列表)。 'actionField': {'list': 'Search Results'},

我没有将它添加到产品详细信息中,也没有在结帐过程中的任何地方添加它(添加到购物车、结帐、购买)。

对于结帐过程中的其他外部域,我想您将需要跨域跟踪。

你必须做三件事。

1.跟踪您的产品列表点击您的产品列表页面

/**
 * Binds click event on product detail page links at product list page.
 */
var bindProductListClickTracking = function() {
    jQuery('a.detail-link-track:not(.ga-click-bound)').on('click', function (e) {
        e.preventDefault();

        var href = jQuery(this).attr('href');
        //all my product data are attributes á la data-product-sku
        var product = jQuery('li[data-product-detail-link="' + href + '"]')[0];

        ga('ec:addProduct', {
            'id': product.dataset.productSku,
            'name': product.dataset.productName,
            'category':product.dataset.productCategory,
            'brand': product.dataset.productBrand,
            'variant': product.dataset.productVariant,
            'position': jQuery(product).index() + 1
        });

        var list = product.dataset.productList;
        /**
          * IMPORTANT: save your product list name into a cookie
          */
        jQuery.cookie('productlist', list, { path: '/', domain: cookieDomain});

        ga('ec:setAction', 'click', {list: list});

        ga('send', 'event', {
            eventCategory: 'productlist',
            eventAction: 'click',
            eventLabel: list,
            hitCallback: function () {
                if (!(e.ctrlKey || e.which == 2)) {
                    document.location = href;
                }
            }
        });
    }).addClass('ga-click-bound');
}

提示: 如果您有延迟加载或加载更多按钮,请注意不要在您的产品详情页面链接上绑定此事件两次。

2。在产品详情页面将产品列表的 actionObject 添加到添加到购物车操作中

var manipulationOfCart = function(product, type, productList) {
    ga('ec:addProduct', {
        'id': product.id,
        'name': product.name,
        'category': product.category,
        'brand': product.brand,
        'variant': product.variant,
        'price': product.price,
        'quantity': product.qty
    });

    ga('ec:setAction', type, {list: productList});

    if (type == 'add') {
        ga('send', {
            hitType: 'event',
            eventCategory: 'Cart',
            eventAction: 'click',
            eventLabel: 'Add To Cart',
            nonInteraction: 1
        });
    } else if (type == 'remove') {
        ga('send', {
            hitType: 'event',
            eventCategory: 'Cart',
            eventAction: 'click',
            eventLabel: 'Remove From Cart',
            nonInteraction: 1
        });
    }
}

3。在您将产品添加到购物车或用户离开产品详细信息页面后删除 cookie

manipulationOfCart(productToBasket, 'add', productlist);
$.removeCookie('productlist', { path: '/', domain: cookieDomain});

AND

$(window).unload(function() {
    $.removeCookie('productlist', { path: '/', domain: cookieDomain});
});

实际上Google Analytics Docs are wrong - it does not work what they are saying. And there is already a bug reported at Google Analytics Bug Tracker