2
votes

I just switched over to using Google Tag Manager so everything is mostly in one place. I have to say I love it so far, but I think I have a problem with the analytics ecommerce values.

In Google's documentation they show this as an example as per doc using the dataLayer :

<script>
dataLayer = [{
    'transactionId': '1234',
    'transactionAffiliation': 'Acme Clothing',
    'transactionTotal': 38.26,
    'transactionTax': 1.29,
    'transactionShipping': 5,
    'transactionProducts': [{
        'sku': 'DD44',
        'name': 'T-Shirt',
        'category': 'Apparel',
        'price': 11.99,
        'quantity': 1
    },{
        'sku': 'AA1243544',
        'name': 'Socks',
        'category': 'Apparel',
        'price': 9.99,
        'quantity': 2
    }]
}];
</script>

The above is what I followed. Using Tag Assistant plugin for Chrome shows everything working fine and the values come in as expected, BUT... today I have had a few sales and the data is not showing in my GA account...

I also found this page in the help doc which shows a completely different method for adding the ecommerce data with completely different values. Here they use something like this which is how I was doing it with the regular Google Analytics script (not the tag manager) :

ga('ecommerce:addTransaction', { 
  'id':'1234',
  'affiliation':'some site',
  'revenue':100.00,
  'currency':'USD'
});

ga('ecommerce:addItem', {
  'id': '1234',
  'name': 'some product',
  'sku': 'some sku',
  'price': 150.00, 
  'quantity': 1
});

So, what is the correct method to specify these values when using the Google Tag Manager?

2
Not sure of all the details, so just adding this as a comment. When using GTM, use the method that is specific for GTM, that is, the first method with the dataLayer. The second block of code is used when you are not using GTM, so all that would be inpage code.nyuen
As it turns out I forgot to add a 'transaction' track type of GA to fire in my GTM account. I don't have time to check it right now, but will report back when I do... it is the first thing mentioned in the link I posted above.user756659

2 Answers

1
votes

you are mixing two types of tracking - 1) using GTM and then 2) using the actual JavaScript in source code to send the data to GA.

I would stick with GTM, it just makes everything easier. It seems that you have everything ready in DataLayer with product names, so now you just need to create a new Tag with those attributes:

  • Tag Type = Google / Universal Analytics
  • Track Type = Transaction
  • add any other configuration fields you are using across your website...

Then just create a rule when to fire this tag (usually a conversion page - probably the same as your Goal URL in GA setup).

That should do the trick - if a visitor makes a purchase successfully, then after loading the conversion page, GTM will send 1 pageview reqeust and 1 transaction request (they needs to be fired separately).

Also, you might be interested in new version of E-commerce tracking, named Enhanced Ecommerce. It add tons of new and very useful stuff (apart from measuring transaction, it's focused on the whole process of purchasing - browsing products, adding to carts etc.). Here is the manual how to set it up using GTM. It's a bit more difficult, but worth the effort in my opinion.

Hope this helps.

1
votes

For anyone interested this is what I came up with for my needs. Works fine, values are just examples of course. Sorry for the late response on this one.

//repeat for each product
myProducts.push({
    'name': 'some name',
    'id': 'some id',
    'price':  100.00,
    'category': 'some category',
    'brand': 'some brand',
    'quantity': 10
});

//full push for the dl
dataLayer.push({
    'event': 'TrackOrderComplete',
    'google_conversion_value': 100.00,
    'google_conversion_currency': 'USD',
    'ecommerce': {
        'purchase': {
            'actionField': {
                'id': 'some id',
                'affiliation': 'some affiliation',
                'revenue': 100.00,
                'tax': 5.00,
                'shipping': 10.00,
                'coupon': 'some coupon'
            },
            'products': myProducts
        }
    }
});