E-commerce Tracking in Google Analytics & Magento

We often get questions from developers asking why their Google Analytics (GA) accounts are not showing transaction data from Magento.

Our typical response is a quick list of questions:

  1. Have you hard-coded your GA tracking code into your head.phtml rather than using the Magento configuration?
  2. Have you removed some vital code from your root template files?
  3. Have you forgot to enable e-commerce tracking in GA?

If the answer is yes to any of the above then, well…there you go.

1. Add your GA tracking code through Magento Configuration

The reason why you need to add your GA tracking code into the admin configuration rather that hard-coding the copy/paste job from Google Analytics itself is because Magento dynamically inserts the transaction data into your GA tag.

Without this transaction data – GA will not pick up on sold items / prices / shipping etc on your checkout’s thank-you page.

2. Stop removing vital code from the root template files

It can sometimes be tempting to remove lots of ‘un-used’ tags from root template files (1-column.phtml, 2columns-left.phtml, 3columns.phtml etc) to make your code ‘cleaner’ and ‘less cluttered’.

Unfortunately removing the following two snippets from these template files will cause some core functionality to fail – including GA tracking that has been set up within the configuration.

<?php echo $this->getChildHtml('after_body_start') ?>
<?php echo $this->getChildHtml('before_body_end') ?>

Check your root template files and make sure that these two snippets are still present and not commented-out or removed. If you’re struggling to spot them perhaps compare your theme against the base>default theme.

3. Enable E-commerce Tracking in Google Analytics

Another common misconception is that GA will automatically track transaction data as long as the two points above are followed. Unfortunately there’s one incredibly important – yet incredibly simple step to complete to get everything working as it should. Enable e-commerce tracking in GA.

In the new-look GA panel simply head over to your websites reporting dashboard and click on the big Admin button.

Within ‘Admin‘ and then within the ‘View‘ column click on ‘View Settings‘.

Scroll down a bit and make sure that Ecommerce tracking (under Ecommerce Settings) is set to On (you can also set your currency here as well).

Any other issues

Hopefully by making sure that these 3 elements are all correct your Magento transactions will start appearing in GA.

If you’re still having problems then we may be looking at extension conflicts/bespoke code getting in the way!

I hope you enjoyed this quick blog about Magento Ecommerce Tracking in Google Analytics – for more info about tracking your visitors and analysing sales – I’ve a chapter for it in my Magento SEO book.