E-commerce Tracking on Google Analytics

Ecommerce tracking allows you to measure the number of transactions and revenue that your website generates. On a typical e-commerce site, once a user clicks the "purchase" button in the browser, the user's purchase information is sent to the web server, which carries out the transaction. If successful, the server redirects the user to a "Thank You" or receipt page with transaction details and a receipt of the purchase. You can use the analytics.js library to send the e-commerce data from the "Thank You" page to Google Analytics.

Usefulness

Putting in place an e-commerce tracking allows you to precisely track products bought in your shop.

  • Giving you insight on your tops and flops. With this, you can also add a conversion, which is for me the most important in Google Ads.
  • This conversion will automatically import people coming from your Campaigns, allowing you to have information on your ROI.
  • This conversion will contain a value, that you will be able to use for you can use to target return on ad spend (ROAS) bid strategy. Automated bid strategies automatically set bids to optimize for your performance goals across specific campaigns, ad groups, and keywords. With target ROAS, Google Ads will set maximum cost-per-click (max. CPC) bids to maximize your conversion value, while trying to achieve an average return on ad spend (ROAS) equal to your target

Setup in Google Analytics

In order to receive any kind of information from e-commerce, you need to activate this specific report in  Google Analytics.

Revenue on Google Analytics Home
Revenue on Google Analytics Home

Activate e-commerce

So, let's first initiate the report. On the main page of Google Analytics go to Admin, and then on the right side find E-commerce Settings.

Admin panel on Google Analytics
Admin panel on Google Analytics
Ecommerce Settings on Google Analyitcs
Ecommerce Settings on Google Analyitcs
E-commerce Setup on Google Analytics
E-commerce Setup on Google Analytics

Activate the first report for now. We will go over Enhanced E-commerce in another tutorial.

E-commerce report available after activating E-commerce on Google Analytics
E-commerce report available after activating E-commerce on Google Analytics

This setting allows you to open specific new reports to e-commerce. You can find them in Conversions > E-commerce.

From now on, you will be able to have Sales Performances, in which you can track different products sold, and analyze which one can do better.

Track CPC efficiently - Referral exclusion list

The whole point of having e-commerce on your website is to track efficiently your ROI.  Google Analytics, tracks the last source of a certain user. The source of a user is the last website that the user was on before accessing your website. We are calling it the referral.

The most common problem with e-commerce tracking is payment methods. When on your Cart page, you are choosing an external payment method, when choosing it, you will be redirected externally, pay the bill, and come back to the thank you page.

At this point, what Google Analytics will see as your referral, will be the payment method, and so the source CPC if there was one, will be lost.

In order to counter that, we will have to add all of the payment methods into a referral exclusion list, a sort of blacklist in which we say "Google Analytics, please do not track these sources I am not interested in tracking them".

In order to do that, go to

  • Admin menu
  • Tracking Info
  • Referral Exclusion List
  • Add Referral Exclusion
Referral Exclusion List
Referral Exclusion List
E-commerce Tracking on Google Analytics - Scientia
Add a referral Exclusion list

For each payment method, you have on your website. You need to add its domain to this exclusion.

Technicalities

As of today, there are still two libraries being used by Google Analytics. gTag.js and Universal Analytics. We are going to cover both of them today because the functions are quite different from each other.

Global Tag - Explanation

gTag.js is the newest library. In order to track e-commerce with this one, you will have one global function to track e-commerce. You must be able to loop your articles with the programming language that you are using on your website.

Universal Analytics - Explanation

Universal Analytics is a bit different because you need to call the function that will launch e-commerce and then loop the articles in different manners. In my opinion, Universal Analytics is easier to put in place.

Universal Analytics - Technical

By having Universal Analytics loaded on your website, you will be obliged to use the e-commerce function from the same library. There are two types of e-commerce data you can send using analytics.js: transaction and item data. A transaction represents the entire transaction that occurs on your site.

You typically implement e-commerce tracking once the user has completed the checkout process. This generally occurs on the "Thank You" page. Once you have and are ready to send e-commerce data to Google Analytics, there are a couple of steps you need to go through. These are the values that have to be sent to Google Analytics:

Transaction Data

KeyValue TypeRequiredDescription
idtextYesThe transaction ID. (e.g. 1234)
affiliationtextNoThe store or affiliation from which this transaction occurred (e.g. Scientia Merchandise).
revenuecurrencyNoSpecifies the total revenue or grand total associated with the transaction (e.g. 11.99). This value may include shipping, tax costs, or other adjustments to total revenue that you want to include as part of your revenue calculations.
shippingcurrencyNoSpecifies the total shipping cost of the transaction. (e.g. 5)
taxcurrencyNoSpecifies the total tax of the transaction. (e.g. 1.29)

Once you transmit the transaction data, you will also need to transmit the articles, item data. Usually here, if your shop supports purchasing more than one item you will have to loop this data to retrieve every single item.

Product Data

KeyValue TypeRequiredDescription
idtextYesThe transaction ID. This ID is what links items to the transactions to which they belong. (e.g. 1234)
nametextYesThe item name. (e.g. Fluffy Pink Bunnies)
skutextNoSpecifies the SKU or item code. (e.g. SKU47)
categorytextNoThe category to which the item belongs (e.g. Party Toys)
pricecurrencyNoThe individual, unit, price for each item. (e.g. 11.99)
quantityintegerNoThe number of units purchased in the transaction. If a non-integer value is passed into this field (e.g. 1.5), it will be rounded to the closest integer value.

The Universal Analytics e-commerce code

Let's take a look at how the code should be initiated. This code has to be on the "Thank you" page mentioned above.
We will have 6 mandatory steps in this code.

Note that the codes below are examples, the values included are to be replaced with your code variables.
Example: Revenue should be replaced by the total Revenue of the actual transaction.

  • Have the right Javascript library loaded, we need ga.js (universal analytics) loaded on the page.
  • Load the e-commerce function, we need to load it in order to send Data.
ga('require', 'ecommerce');
  • Load the transaction Data. In this piece of code, you will transmit everything concerning your transaction.
ga('ecommerce:addTransaction', {
    'id': '1234',                     // Transaction ID. Required.
    'affiliation': 'Scientia Merchandise',   // Affiliation or store name.
    'revenue': '11.99',               // Grand Total.
    'shipping': '5',                  // Shipping.
    'tax': '1.29'                     // Tax.
});
  • Load the item data. This is where should be a loop showing the different products that have been bought in this transaction.
ga('ecommerce:addItem', {
    'id': '1234',                     // Transaction ID. Required.
    'name': 'ScientiaDev's Tee Shirt',    // Product name. Required.
    'sku': 'DD23444',                 // SKU/code.
    'category': 'Tee-Shirts',         // Category or variation.
    'price': '11.99',                 // Unit price.
    'quantity': '1'                   //Quantity.
});
  • Send the Data to Analytics
ga('ecommerce:send');
  • And finally clear the data, to avoid having multiple people sending the same data by refreshing the page
ga('ecommerce:clear');

Global Site Tag- Technical

The Global Site Tag, aka gtag.js, is the newest Google Library. It has most of the Universal Analytics options, though the function names are different. In the gTag function, we have one function for all, which means the Transaction and Item data will be within the same function.

Transaction - Impression Data

Item parameterData typeRequiredDescription
idstringYes*Unique ID/SKU for the item.
namestringYes*Item name.
list_namestringNoThe list in which the item was presented to the user
brandstringNoBrand of the item
categorystringNoItem category
variantstringNoItem variant
list_positionintegerNoThe position of the item in the list
pricecurrencyNoPurchase price of the item

Item/Products Data

Item parameterData typeRequiredDescription
idstringYes*Unique ID/SKU for the item.
namestringYes*Item name.
brandstringNoBrand of the item
categorystringNoItem category
variantstringNoItem variant
pricecurrencyNoPurchase price of the item
quantityintegerNoItem quantity
couponstringNoCoupon code for a purchasable item
list_positionintegerNoThe position of the item in the list

The gTag e-commerce code

As mentioned above, this code is a bit different. If you are developing your own website, you will need to again retrieve the same values from your store, the only difference here, is that the global site tag is following this unified style.

Note that the codes below are examples, the values included are to be replaced with your code variables.
Example: Value should be replaced by the total Value of the actual transaction.

gtag('event', 'purchase', {
  "transaction_id": "24.031608523954162",
  "affiliation": "Scientia Online",
  "value": 23.07,
  "currency": "USD",
  "tax": 1.24,
  "shipping": 0,
  "items": [
    {
      "id": "P12345",
      "name": "Astronaut's Tee Shirt",
      "list_name": "Search Results",
      "brand": "Scientia.dev",
      "category": "Apparel/T-Shirts",
      "variant": "Black",
      "list_position": 1,
      "quantity": 2,
      "price": '2.0'
    },
    {
      "id": "P67890",
      "name": "Universe Challenge",
      "list_name": "Search Results",
      "brand": "SCIENTIADEV",
      "category": "Apparel/T-Shirts",
      "variant": "Red",
      "list_position": 2,
      "quantity": 1,
      "price": '3.0'
    }
  ]
});

We need the info on Google Ads

Now that you have Google Analytics e-commerce tracking, your reports will start to fill. But what can be interesting for you now, is to know from which campaign people came from when they bought your products.

E-commerce report

A very nice report on Google Analytics can be found in

  • Acquisition
  • Google Ads
  • Campaigns

Send Data to Google Ads

In order to use this data with Smart Bidding, you will need to import this to Ads.

Go to Google Ads and then

  • Tools & Parameters
  • Conversions
  • Find the blue Plus icon
  • Import from Analytics
  • And there find the conversion name Transaction
Tools > Conversions
Tools > Conversions

How to import a conversion?

Once the conversion named Transactions is there, you will be able to use Smart Bidding on your Bidding strategies.

0
Buy Me A Coffee
searchstaruserlist-altbookcalendarfacebook-squarelinkedin-squarearrow-circle-rightmoneybellyoutube-playinstagramline-chart