A simple guide to ecommerce tracking in Google Analytics

Demand for ecommerce reports in Google Analytics seems to be on the rise. Having recently consulted on a full Google Analytics Enhanced Ecommerce implementation, I thought I would share some straightforward, limited-jargon insights into how to best set up Google Analytics ecommerce tracking.

Although I’ve tried to make things simple and clear, this article does assume prior analytics knowledge and focuses more on approach than technical detail. For step-by-step technical guides, I’d recommend additional resources such as the excellent Simo Ahava’s blog.

Ecommerce reporting doesn’t have to be an onerous task. It’s true that the ecommerce reports are among the most complicated in Google Analytics, and the best implementation practice involves some backend development expertise, but ecommerce data is quite flexible and you can get very far with a basic configuration. For example, simply tracking your add to basket/add to cart button, the basket/cart page, and completed transactions or sales can give you so much insight about your user experience and products.

As with all data, it’s better to configure and collect what you are actually going to use, rather than seeking comprehensive or complete data collection which then languishes for eternity in invisible reports and databases.

General approach

Google Analytics tagging is far less painful these days due to the advent of Google Tag Manager. I recommend, where at all possible, using these two platforms in concert for robust, streamlined, easy-to-maintain analytics tracking.

You will also need to work with a developer (or have access to the website backend) to implement ecommerce tracking in Google Analytics. Best practice uses a data layer to implement Enhanced Ecommerce tracking, which is just a scary way of saying that we need to pass some information from the website backend to the pages themselves, in a format that Google Tag Manager is able to read. This in turn will enable us to set up the Google Analytics ecommerce reporting with ease.

Finally, Google’s own Enhanced Ecommerce documentation really is very good. It may be full of detail and a lot of unnecessary or niche tracking in terms of your own needs, but it offers a solid overview of what exactly needs to be configured, in what format, etc.

1. Strategy & ecommerce tracking plan

All good analytics projects begin with a strategy, and a plan to help achieve that strategy. Think about what you want to track in Google Analytics and, even more importantly, why you want to track it. It’s no good just wanting “ecommerce reports” or setting up Enhanced Ecommerce because everyone’s doing it or your boss asked for it.

Are you redesigning your checkout funnel? Launching new products? Want to benchmark donations and fundraising against seasonal trends? Continuously optimising your user journey? Each scenario will require some thought and subtle (some not-so-subtle) changes to your Google Analytics ecommerce tracking plan.

Once you have figured out the purpose of your ecommerce reports, you are ready to develop the plan. This should be a semi-technical specification of the pages and user interactions where you want to track ecommerce data. I like to include template and example tracking code, along with rationale to make the intention crystal clear. A simple spreadsheet will do for the ecommerce tracking plan. Here are my recommendations for what to include:

  • Page or interaction to be tracked, i.e. the step in the shopping process.
  • Example URLs of the page or interaction
  • Rationale for tracking and reporting on that information
  • Template tracking code (e.g. in JavaScript or HTML)
  • Example tracking code for a particular interaction, such as a product view or a completed purchase

2. Backend data layer setup

Ecommerce tracking is one of the rare cases in the modern Google Analytics/Google Tag Manager age that still requires some custom code to be added to web pages. If you have access to the site backend, or are working with a developer to do this, you will need to populate a JavaScript data layer with the ecommerce information. (Of course, you could in theory do this by scraping information from the page using JavaScript, but that’s pretty risky and and needs careful maintenance. It’s generally much better to use your actual site shopping processes to be able to set up the data layer with confidence.)

You can also use various website plugins to configure ecommerce data. Feel free to give these a go – and potentially save a lot of work – however I have worked with clients who have had issues with a number of Google Analytics ecommerce plugins, such as substantial differences in order volumes reported. The approach I personally favour is manually setting up the data layer code in tandem with the site backend processes for the cleanest, most accurate sales and conversion reports.

Ecommerce data layer objects can look intimidating, but all they are doing is A) telling Google Tag Manager that an ecommerce event is happening, and B) passing through metadata such as order revenue, product information, etc. It’s important to preserve the code structure shown in Google’s documentation, but you only need to implement the variables and values you need (while making sure to include mandatory fields).

You (or your developer) will need to identify the backend variables that you can use to populate the data layer. The relevant variables are generally available in most content management systems and will vary according to the platform. The method for populating the data is down to you – the important thing is that the resulting JavaScript data layer object is in the right format.

I also recommend firing a Google Analytics custom event for each ecommerce step. This will help in debugging the reports, and also provide simplified shopping data in the events reports for other potential uses like segmentation or simple funnel visualisations. As you will be using custom events, that means that the data layer code will need to be pushed to the page after Google Tag Manager has initialised. To prevent double-counting in ecommerce reports, it is also necessary to execute the data layer code after the main Google Analytics pageview tracker, as ecommerce data, once pushed to the data layer, gets sent to Google Analytics with every hit.

With functioning data layer pushes taking data from the site backed to the frontend data layer, it’s now time to set up Google Tag Manager to fire the actual Google Analytics tracking.

3. Google Tag Manager configuration for Enhanced Ecommerce

Now that you have the data layer set up, the actual configuration of Google Analytics – through Google Tag Manager – should be pleasantly straightforward. Essentially, you just need to set up the following:

  • Variables to capture dynamic information such as checkout step or categories, actions, or labels for your custom events.
  • Triggers for each ecommerce step.
  • Tags to fire Google Analytics custom events.

An example here would be on a product page. Say you are tracking product impressions and have the data layer already populated with the information you want to pick up. Capturing this in Google Tag Manager would involve the following:

  • Variables: Although your Google Analytics custom event category may be static (e.g. “Product Page”), you may want to pull through some dynamic values such as the action – “View” – and the product name or SKU. You can set up some Google Tag Manager variables to reference the data layer object and later use these variables in your tag.
  • Trigger: Generally with Enhanced Ecommerce and the data layer approach, our triggers will be of the type “Custom Event” in Google Tag Manager (not to be confused with Google Analytics custom events!) Simply set the trigger “Event name” to whatever event value you set in the data product page data layer, e.g. something like “Product detail view”.
  • Tag: Finally, to pass all of that ecommerce data into Google Analytics, we need to set up the Google Analytics tag itself. This is simply a Google Analytics tag of track type “Event”. Populate the category, action, and label fields as you see fit: using either static text or variables as outlined above. The ecommerce metadata – like product name, variant, brand – that you set in the data layer will be automatically passed to Google Analytics when the custom event fires. That’s the beauty of this approach – with a good data layer implementation, the Google Analytics and Google Tag Manager parts become very satisfying and easy to manage.

That’s all for now! Please let me know if you have any queries in the comments section below.

You can also email me at [email protected] or find me on LinkedIn if you want more detail or want to discuss my support on any data analytics projects.

linkedininstagram

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.