John
John

Reputation: 167

Correct implementation of custome metrics in Google Analytics

We have implemented the google analytics ecommerce tracking: https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

The standard ecommerce tracking gives us the options to send the following data to analytics from our "order complete" page:

ga('ecommerce:addTransaction', {
  'id': '1234',                     // Transaction ID. Required.
  'affiliation': 'Acme Clothing',   // Affiliation or store name.
  'revenue': '11.99',               // Grand Total.
  'shipping': '5',                  // Shipping.
  'tax': '1.29'                     // Tax.
});

And for each item in the transaction:

ga('ecommerce:addItem', {
  'id': '1234',                     // Transaction ID. Required.
  'name': 'Fluffy Pink Bunnies',    // Product name. Required.
  'sku': 'DD23444',                 // SKU/code.
  'category': 'Party Toys',         // Category or variation.
  'price': '11.99',                 // Unit price.
  'quantity': '1'                   // Quantity.
});

We also want to send the profit/margin for each transaction/item. To solve this we have used custom metrics. So now our ecommerce tracking script looks like this:

<script type="text/javascript">
    ga('require', 'ecommerce', 'ecommerce.js');
    ga('ecommerce:addTransaction', {
        'id': '1078163',                     // Transaction ID. Required.
        'affiliation': 'www.website.com',   // Affiliation or store name.
        'revenue': '138'              // Grand Total.
    });
    //Dimension
    var dimensionValue = 'www.website.com';
    ga('set', 'dimension1', dimensionValue);

    //Revenue
    var metricValue = '138';
    ga('set', 'metric1', metricValue);

    //Profit:
    var metricValue = '55';
    ga('set', 'metric2', metricValue);

     ga('ecommerce:addItem', { 
'id': '1078163', 
'name': 'F-91W', 
'sku': 'F-91W', 
'category': 'Casio Watches', 
'price': '138', 
'quantity': '1' 
}); ga('ecommerce:addItem', { 
'id': '1078163', 
'name': 'Fragt2-FI', 
'sku': 'Fragt2-FI', 
'Category': 'Fragt', 
'price': '0', 
'quantity': '1' 
});
    ga('ecommerce:send');
</script>

This implementation gives us the opportunity to see the profit for specific days/channels etc. But we have two concerns. First of all the data collected in our custom report are incorrect. Second, we would like to have the profit as a dimension in the standard ecommerce report. Any idea if this is possible?

The custom metrics are set up with scope=hit, and formatting type=currency.

NB. we want the profit to show direcly in the code even though competitors could utilize this.

Upvotes: 0

Views: 373

Answers (1)

Ruslan Konygin
Ruslan Konygin

Reputation: 1019

  1. If you data in custom report is incorrect, make sense to give more details about this. As you said, that each transaction counted 3 times, then you should have higher revenue, count of products sold, ecommerce conversion rate, etc. that should be. To fix that you should fire your code above only one time for each transaction. For example, if user reloaded your thank you page, this code shouldn't fire again. Because GA counting transactions each time, when code was fired on page, even if transactions are duplicating.
  2. If you want to see profit for each transaction in standart Ecommerce report, then you may use "Secondary dimension" at this report. But before you should also send your profit as custom dimension(simple string, hit level) in addition to custom metric. But in fact you should be possible to use that now in custom report(if apply custom metric2 as column).

Upvotes: 0

Related Questions