2
votes

Here is my Universal Analytics code for custom definatons and e-commerce tracking.ecommerce tracking is working fine all the data are fetching in google analytics dashboard but custom dimensions and metrics data is not showing there.

ga('create', 'UA-XXXXXX',XXXXX);
ga('send', 'pageview');
ga('require', 'ecommerce', 'ecommerce.js');   
ga('ecommerce:addTransaction', {
'id': '<?php echo $ordr_id; ?>',             
'affiliation': 'XXXXXX',
'revenue': '<?php echo $amount; ?>',      
'shipping': '<?php echo $shipping_amount; ?>',    
'tax': '0.00',                    
'currency': 'USD'
});



ga('ecommerce:addItem', {
'id': '<?php echo $ordr_id; ?>',                 
'name': '<?php echo $product_name; ?>',          
'sku': '<?php echo $sku; ?>',                 
'category': '<?php echo $category_name; ?>',  
'price': '<?php echo $final_price; ?>',          
'quantity': '<?php echo $quantity; ?>'         
});




ga('send', 'pageview', {
'dimension1': '<?php echo $product_name; ?>',
'metric2': '<?php echo $final_price; ?>',
'metric3': '<?php echo $final_price; ?>'
});


ga('ecommerce:send');

any help related to this is greatly appreciated. thnx!!

3
Did you create your custom dimensions/metrics in the property settings ? Did you wait for some time (custom values may take a day to show up) ? Unrelated, currency code should be USD (or any other of the supported 3 letter codes developers.google.com/analytics/devguides/platform/currencies).Eike Pierstorff
@EikePierstorff yes i have created dimensions and metrics. which is also showing in custom report section of google analytics dashboard but with no data in it.Raj
@EikePierstorff ecommerce code is working fine. is there any problem with custom defination code above?Raj
did you find a solution? I'm having the same problem. I don't see the custom dimension data showing up even though I do know that it's getting sent. Any ideas??user2306941
@user2306941 check the below solutions may be it will help..Raj

3 Answers

1
votes

If you use ecommerce with custom dimensions and metrics in analytics.js, do not set ga() function. Because it send CD, CM to google server on two times that is addTransaction and addItem.

So, you can use CD and CM in ga('ecommerce:addItem', {...}).

For example,

`

ga('ecommerce:addItem', {
'id': '<?php echo $ordr_id; ?>',
'name': '<?php echo $product_name; ?>',
'sku': '<?php echo $sku; ?>',
'category': '<?php echo $category_name; ?>',
'price': '<?php echo $final_price; ?>',
'quantity': '<?php echo $quantity; ?>',
'metric1': value,
'dimension1': value
});

`

0
votes

Above Code is working Fine. just a little change in it works for me.

ga('send', 'event', 'category', 'action', {
'dimension1': '<?php echo $product_name; ?>',
'metric2': '<?php echo $final_price; ?>',
'metric3': '<?php echo $final_price; ?>'
});
0
votes

If you want to add dimension and metrics to ecommerce tracking than this might help:

...

ga('set', 'dimension1', '<?php echo $product_name; ?>');
ga('set', 'metric2', '<?php echo $final_price; ?>');
ga('set', 'metric3', '<?php echo $final_price; ?>');

ga('ecommerce:send');

ga('send', 'pageview');