0405123696 petra@web-data-analytics.com

 2,268 total views,  9 views today

The tracking codes used by Google Analytics can get a bit complicated, especially if you’re not a developer. I’ll do by best to explain in this article how it all works.

There are two eCommerce frameworks that you can use in Google Analytics – Standard Ecommerce and Enhanced Ecommerce. This article will discuss the background information along with some examples from Standard Ecommerce. If you are using Enhanced Ecommerce then you can go to the relevant article.

Essentially, if you are using the Google Analytics with Ecommerce turned on, you want to include transaction data with every transaction.

To do this, you will typically generate a post-transaction “thank you” page, which is intended to be seen by all customers as soon as they purchase. The tracking code will be placed on that page.

Ecommerce tracking is executed in three distinct steps.

Firstly, the website’s “server-side” code is responsible for working out the price, the quantity, the tax, shipping etc. (This is often written in PHP, but may be written in another language – it doesn’t really matter). This website code contains instructions that write the Google Analytics tracking code on to the HTML page, or alternatively it might just list all the data values so that it can be dynamically created in Javascript. Irrespective of which language is used to write the website pages, the Google Analytics Ecommerce tracking code will be written in Javascript because that is the language that Google Analytics uses to send data.

Once the thank-you page has loaded, the HTML page will have been rendered with a Google Analytics tracking code. This tracking code will be updated with all the values that the eCommerce server has sent to the page. The code will include a “send” command that will send the data to Google Analytics.

As the page is rendering the Google Analytics tracking code will execute and send the data over to Google Analytics. This is why it is important that the Google Analytics tracking code is placed as high up in the page as possible, in order for it to have the opportunity to finish executing before your website visitor closes their browser window.

Now lets look at how this is done with Google Analytics Standard Ecommerce framework. If you are using the Google Analytics Enhanced Ecommerce framework then skip to the relevant article.

The Google Analytics Standard Ecommerce tracking code is made up of two components, namely the Transaction data and the Item data.

Transaction Data

The following table shows you the format for the Google Analytics Standard Ecommerce transaction data.

Google Analytics. Retrieved from https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

Here is a bit of a summary:

  • Transaction ID is a required field. This will be a generated ID made up of letters and/or numbers which will uniquely identify the transaction.
  • Affiliation an optional field, and is the name of your store. It is useful to include this if you have more than one eCommerce store sharing the same Google Analytics property, or if you have more than one department, each with its own shopping cart.
  • Revenue is an optional field. It tells you the total amount that your customers are paying for the transaction, irrespective of how many items are being purchased; I.e. it is the final total price. Google Analytics can determine the amount from the total revenue of the products if the revenue is excluded from the transaction.
  • Shipping and Tax are optional fields and may be added if you know these details.

Item Data

The following table shows you the format for the Google Analytics Standard Ecommerce item data.

Google Analytics. Retrieved from https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

Here is my summary about the item data:

  • The ID must match the transaction ID from the transaction (above).
  • Name is a required field that describes the human readable name of the product.
  • SKU is an optional field that uniquely identifies a product, i.e. it is a product code.
  • Category is an optional field that describes which product category this product belongs to.
  • Price is an optional field that lists the unit price for the product. While it is optional, it really should be included.
  • Quantity is a required field that lists how many of this product were purchased in this transaction. While it is optional it ideally should be included.

Standard Ecommerce is reasonably straightforward, so you end up with a fairly simple piece of code that you can then enter on the transaction thank you page.

Important note: You will see examples of Standard Ecommerce code written for Google Tag Manager, as well as Google Analytics. These are very similar in format, with a few notable differences. Google Tag Manager code is pushed to the Data Layer, whereas Google Analytics code is pushed to Google Analytics directly. We won’t be covering Google Tag Manager in this article series, but Google Tag Manager is my area of expertise so please contact me if you require assistance with Google Tag Manager.

Here is what a completed tracking code would look like:

Step 1: Let Google Analytics know that we will be sending eCommerce data.

Step 2: Add the transaction data.

Step 3: Add the item data.

Step 4: Send it all to Google Analytics so that it turns up in your Google Analytics Ecommerce reports

Google Analytics.Retrieved from https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce

Effectively adding tracking data to your thank-you pages will take a bit of getting your head around, especially if you don’t come from a developer background. It is well worth the effort to get it done however, as adding Ecommerce data to your Google Analytics reports will prove to be invaluable for your business.


Erica Stacey Scout Digital

I recently worked with Petra to improve my understanding of Google Tag Manager.

Petra not only provided a solid overview of GTM set up and event tracking, she also provided many tips on best practice, and answered the questions that I didn't even know to ask!

Petra is patient, fun to work with, and her analytical programming mind is hell bent on finding the BEST solution to any data, analytics or tracking problem.

Erica Stacey Scout Digital Marketing Strategy Session June 21, 2017

leesa dawson

I am so grateful to have met you, as I think your insights are the BEST I have ever come across.

Leesa Dawson CEO, The Uniform Stylist Ecommerce Google Ads April 23, 2020

Nadia Rossi

It has been an absolute pleasure working with Petra over the last year and a half. 1834 Hotels centralises marketing for over 20 hotels around Australia, all with different branding and websites. On an analytics level Petra’s skills have allowed us to monitor and track our marketing efforts in the digital space. Bringing Petra onboard to manage our Google Ads was one of the best marketing decisions we have made. Her thoroughness and attention to detail is incredible, her insights have helped develop better marketing strategies and demonstrate to shareholders return on investment. I would highly recommend working with Petra.

Nadia Rossi Digital Marketing at 1834 Hotels Ecommerce / Hotel Google Ads April 23, 2020

claudia impedovo

Our main purpose for generating these reports is about findings out information that will curb our strategy. The Audience Engagement Report provided us with new findings about our audience. We implemented new marketing elements based on those findings and they have increased sales.

Claudia Impedovo Brand Manager at Spendless Shoes Ecommerce Google Analytics, Google Tag Manager & Google Data Studio Integration April 23, 2020

Michelle Bridger

Petra's detailed reports and her personal assistance has been helping us to know where to concentrate our efforts and even showed us technical issues we needed to fix. Our Audience Engagement Report identified several key interests of our buying audience. We tried targeting one of those interests and it brought in two sales almost immediately! I highly recommend working with Petra and accessing her brilliance to scale your business.

Michelle Bridger Michelle Bridger, Facebook Advertising Specialist Ecommerce Google Tag Manager, Google Analytics & Google Data Studio Configuration April 23, 2020