How do I indicate which “list” of a product has been added to the cart? Enhanced Ecommerce

Trying to implement Google Analytics Ecommerce Tracking for my website.

How do I indicate which “list” of a product has been added to the cart?

Here is the standard tracking code for adding a product to the cart:

    // 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.
}

There is no function for specifying the name of the product list into which the add to cart button was clicked.

There should be something like this:

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

but this only works for the 'click' action (not "add"). (according to https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference# (product action) )

In addition, I need to indicate the position of the product in the list. Any ideas?

+4
4

List Field click detail. , .

, , 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.
}
+1

list detail ( , ).

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

:

  • - , . .
  • , click, .
  • detail, list ( setAction).
  • " ", add.

list detail detail, add > Product List Performance Google Analytics, ( ).

,

0

, .

, , , . GA GTM, "cookieDomain" = "auto", - Google.

, , :

  • . 'list' : 'Search result'
  • ( ). 'actionField': {'list': 'Search Results'},

- ( , , ).

, .

0

, .

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

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

Google Analytics - , . , Google Analytics Bug Tracker.

0

All Articles