Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discount values in google analytics ecommerce tracking via tag manager

We're implementing GA conversion tracking with GTM per the following documentation, but I'm not finding any information about how to handle discounts (coupons) at the order level. https://support.google.com/tagmanager/answer/6106097?hl=en https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

I can send revenue, shipping, and tax, but these won't total correctly for orders that include a discount. If an order is placed as follows:

T-Shirt:     $5
Socks:       $5
subtotal:   $10
tax:         $2
shipping:    $3
discount:   -$5
order total: $10

Should my dataLayer look like this?

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

Will that cause any inaccuracies or inconsistencies in GA?

like image 574
elleeott Avatar asked Sep 11 '15 19:09

elleeott


2 Answers

A co-worker and I are tackling the same question right now.

Before I get into that though you should never, ever declare your dataLayer like that. Sadly it seems to be the way that Google themselves do it in all their code examples, but it's incredibly dangerous because it will overwrite your existing dataLayer with a new one that only contains those key : value pairs. Instead check if dataLayer exists, creating it if it doesn't, and push to it.

window.dataLayer = window.dataLayer || [];
dataLayer.push({
  'key' : 'value'
});

Additionally assuming you've switched over to Universal Analytics consider toggling Enhanced Ecommerce Tracking. It's simultaneously a much more powerful, and cleaner implementation of ecommerce tracking.

So far we've come up with a couple seemingly workable approaches. You can ignore the discount all together, like you did above, and report the total revenue manually after the discount has been applied. One thing I would add if you switch to Enhanced Ecommerce is a coupon code to acknowledge that a product has a discount applied.

<script>
  window.dataLayer = window.dataLayer || [];
  dataLayer.push({
    'ecommerce': {
      'purchase': {
        'actionField': {
          'id': '1234',
          'affiliation': 'Acme Clothing',
          'revenue': '10.00',
          'tax':'2.00',
          'shipping': '3.00',
          'coupon': 'SUMMER_SALE' //Transaction-scope coupon. This would
//be where you'd include discounts like '$10 off purchases of $50 or more'
        },
        'products': [{
          'name': 'T-Shirt',
          'id': 'DD44',
          'price': '5.00',
          'category': 'Apparel',
          'quantity': 1
         },
         {
          'name': 'Socks',
          'id': 'AA1243544',
          'price': '5.00',
          'category': 'Apparel',
          'quantity': 1,
          'coupon': 'FREE_SOCKS' //Product-scope coupon. This would be for 
//discounts like 'free socks with purchase of a t-shirt'
         }]
      }
    }
  });
</script>

Alternatively you can enter the discounts as negative value SKUs and track them as their own line items in the transaction.

<script>
  window.dataLayer = window.dataLayer || [];
  dataLayer.push({
    'ecommerce': {
      'purchase': {
        'actionField': {
          'id': '1234',
          'affiliation': 'Acme Clothing',
          'revenue': '10.00',
          'tax':'2.00',
          'shipping': '3.00'
        },
        'products': [{
          'name': 'T-Shirt',
          'id': 'DD44',
          'price': '5.00',
          'category': 'Apparel',
          'quantity': 1
         },
         {
          'name': 'Socks',
          'id': 'AA1243544',
          'price': '5.00',
          'category': 'Apparel',
          'quantity': 1,
         },
         {
          'name': 'Socks-Discount',
          'id': 'free-socks',
          'price': '-5.00',
          'category': 'Apparel',
          'quantity': 1,
         }]
      }
    }
  });
</script>

Ultimately my recommendation is to mirror the logic for how you're handling the discount in the cart itself. If discounts are their own line items with their own SKUs in your cart report them in GA the same way. If coupon codes make more sense do that. You can even combine the two if you'd like.

like image 76
Tearlach Avatar answered Nov 15 '22 08:11

Tearlach


Use the coupon field to specify the fact that the transaction and/or product is being discounted. e.g.

"coupon" : "10% summer sale" or just "general discount"

Then use a custom metric (scope=hit, format=decimal) to track the total amount of discount applied for the transaction.

'dimension1': '50.0'

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

like image 26
Brian Clifton Avatar answered Nov 15 '22 08:11

Brian Clifton