Google Analytics lost guide for solving returns and changes in ecommerce

Dealing with ecommerce in Google Analytics is always a challenge – taking into account all details you need to fulfill in order for data to be stored properly. Once things start behaving strange (wrong calculation during submission of ecommerce data) you have to make things right. And the question beckons: “How to reverse transactions in Google Analytics?

Disclaimer: following post is summary of various posts across internet, Google help and real life experience dealing with storage of data. Presumption of how data is stored is based on deduction and knowledge about database architecture. 

Google help on that matter is pretty straightforward – explaining how to cancel transaction or initiate return, but you have to read every single word in order to understand what happens deep down inside Analytics engine.

Some of the colleagues in Analytics community went through explaining how to handle returns (using tools available within Analytics), older tracking code setup explains inner working and some new (regarding analytics.js setup).

Purpose of this “lost guide” is to explain how this really works and how to deal with adjustments of values, using Measurement protocol.

How ecommerce data is stored within Google Analytics?

Pretty simple, if you think of it, but never explained in details. Two tables, one for transaction information (invoice header), and second with items data (invoice items). Connecting tissue is transactionID.

How google analytics store data?

How Google Analytics store data?

Important this to mention, if you are familiar with databases – when sending data to Google Analytics servers you are not updating anything! You are merely sending additional row of data which is summarized within GA interface.

Due to the nature of Bigtable it is not really possible to update things and work in SQL matter (sorry for tech talk here). This means that data is stored as it comes. Outcome is that, if you have transaction on Monday and some change happening of Friday, on your graph within GA interface you will see changes on both days. This can mislead people looking at graphs and not selecting right time period.

Looking at interface and data (presuming you selected period between Monday and Friday) information about transaction (revenue, tax, item info) will be summarized correctly.

There is no reference integrity between two tables

You think it would be easy?

If you change data on item level (somebody returned one item out of 2) and you inform GA servers about this change, transaction data will not reflect this change. This means that transactionId used to connect data between two tables is just for reference, not for automated update of transaction data.

Once you update item information, update transaction information as well. GA will not do this for you.

How to change things quickly?

The best way is to have the change of item and transaction data on the same day when purchase occurs, but it is not always the case. Returns (partial) or errors get noticed when some time passes. The easiest way is to use Universal Analytics and its measurement protocol to send information.

This is plain URL you place in browser’s address bar and hit Enter.

http://www.google-analytics.com/collect?v=1&tid=UA-xxxxxxx-x&cid=clientId_of_person(555 if_unknown)&t=transaction&ti=transactionId&tr=value_of_transaction_with_dot&ts=shipping_value_with_dot&tt=tax_value_with_dot&cu=currency_code

http://www.google-analytics.com/collect?v=1&tid=UA-xxxxxxx-x&cid=clientId_of_person(555 if_unknown)&t=item&ti=transactionId&in=item_name&ip=value_of_item_with_dot&iq=quantity_with_dot&ic=item_SKU&cu=currency_code

With two hits to Google Analytics server you will solve your (or your client) problem.

Things to take into consideration…

  • Values (numeric) are always delimited with dot “.”
  • When sending data, both for transaction and items, if they contain the same values, storing will not occur
  • If you want to decrease quantity of certain item, use negative quantity
  • Date and time of storing data is when it occur
  • Data stored on Google Analytics servers can not be “erased”, you can only sum it up
  • Negative quantity will decrease quantity but have in mind that value must be positive (-1*1000 will decrease quantity of item by 1 and decrease value) / in other way if you put positive quantity and negative value you will increase quantity but decrease value

Update

Every hit to collection with Measurement protocol will collect some “extra information” like location, source/medium… which will change your other reports. This is important to have in mind.