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.

  • drimendo

    Hey Rob, what do you mean by the term “Magento Configuration”?

    as far as I Know there a are ways to integrate GA:

    1.) Insert the HTML/JS-Snippet (“This will be included before head closing tag in page HTML.”)
    2.) Using Google-API by just inserting your UA-XXXXXXXX-1

    Unfortunately you wouldn’t any chance for inserting the DoubleClick-extension for GA-Snippet (“ga(‘require’, ‘displayfeatures’);”) when using option 2…

    • Hi Drimendo, You’re right – by using the in-built Magento GA code you are restricted to their own code base for how they present data to GA. If you need to change it you can do so by overriding their Ga.php block or ga.phtml template and add your own code in there.

      The problem is that if you disable or remove the automatic Magento GA code and simply add a snippet into the core template then e-commerce transaction data will not automatically be sent to GA (it’s processed through Magento’s own Ga.php / ga.phtml

  • Justin Walmsley

    Hi, have you succesfully set up Google Analytics tracking for Multiple Shipping checkout? It seems that it can’t pass the Magento Order Number but the database number. I’m also missing TAX and Delivery values. the normal checkout is fine though.

    Great post by the way, Creare is a great source of Magento information!

  • MrJoshFisher

    Absolutley useless, no code just basically telling you bits on how to achieve this but no actual help whatssoever