简体   繁体   中英

Ecommerce Tracking via Google Tag Manager

I have a question regarding ecommerce tracking.

I wanted to track the products added from cart/removed from cart.

How can I track if a user adds multiple products to cart,or how can we add the details of a single product when we cannot decide which product user will click. And if a user can take different quantities, How can we assign quantities in a macro?

I found a JavaScript which goes like this:

function() {
    var ecommerceData = {
        'event': 'addToCart',
        'ecommerce': {
            'currencyCode': 'USD',
            'add': {
                'products': [{
                    'id': '122',
                    'name': 'Shirt',
                    'quantity': '2'
                }]
            }
        }
    };
    return ecommerceData;
}

Multiple products:

function() {
    var ecommerceData = {
        'event': 'addToCart',
        'ecommerce': {
            'currencyCode': 'USD',
            'add': {
                'products': [
                    {
                        'id': '122',
                        'name': 'Shirt',
                        'quantity': 1 // integer type
                    },
                    {
                        'id': '125',
                        'name': 'Shirt with Coffe',
                        'quantity': {{Quantity}} // via macro in GTM
                    },
                    {
                        'id': '129',
                        'name': 'Coffee with cottage cheese',
                        'quantity': item.qty // via js variable/object
                    }
                ]
            }
        }
    };
    return ecommerceData;
}

Documentation:

GTM and Enhanced Ecommerce

https://developers.google.com/tag-manager/enhanced-ecommerce

Field reference

https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM