Duplicate transactions in Google Analytics are among the most common errors of implementing electronic commerce in Google Analytics.

This error leads to increasing actual revenues from advertising channels, which result in incorrect conclusions about their efficiency.

Why does data duplication occur?

  1. When the EE code works out more than once. Upon repeated download of the thank you page with order details. The customer can visit it several times. For instance, he can use an e-mail with details of the order or upon page update during repeated browser download.
  2. Your website logic not so frequently comes across transaction IDs. You need to fix it on the back end level.

How to identify duplicated transactions?

The simplest way to identify duplicated transactions is to make a custom report with two fields: transactionId and transactions.

To make this report, you can follow the link and automatically add it to your account. Or you can create a custom report with the following parameters.

Fixing duplicated transactions via Google Tag Manager

In our case duplicated transactions came from one device. To solve this issue, we decided to augment the solution that we found on the blog called Lunametrics. We liked the idea, but it turned out there is no need to involve a developer.

The essence of the method

We have prepared the script which is activated when the electronic commerce data are sent, and performs two functions:

  1. It saves the transaction ID to the browser cookies. Thus, the user browser always saves the last transaction identifier.
  2. When the transaction ID is saved to cookies, it checks if this is a unique transaction. Depending on the answer, a user event is sent: newTransaction or duplicateTransaction.

The transaction ID check is made as follows: the transaction ID we are planning to put down in cookie files is compared to the transaction ID which is already in cookies.

If a transaction is unique, then the tag responsible for sending the transaction data to Google Analytics should be activated in Google Tag Manager.

For that you need to create:

  • transaction_id — data level variable.
  • Transaction Checker — custom html tag.
  • newTransaction — trigger — custom event.

DataLayer TransactionId

It returns the number of the order transaction.

The value: ecommerce.purchase.actionField.id.

This variable will put the transaction ID to javascript code responsible for writing this transaction to the user cookie.

Transaction Checker

Create a custom tag. Place the following code in it (please mind that it refers to the variable transaction_id which was created at the first stage):

Set a condition that shows the electronic commerce data on a page if delivered as a trigger for tag execution.

That is, the data layer containing the order data, including transaction_idshould be initialized before the Transaction Checker tag.

In our case this is the “thank you” page.

NewTransaction trigger

You need to refresh the response trigger in the tag responsible for sending transactions to Google Analytics. It should only be executed if the tag Transaction Checker returned newTransaction as a response.

Thus, only unique transaction IDs will be submitted to Google Analytics.

To do that, you need to go to triggers and create a new one:

Set Custom Event as the trigger type and specify newTransaction as the value.

You can also create an additional trigger and use duplicateTransaction as the value. This trigger can later be used to count duplicated transactions. For instance, via events.

Please keep in mind:

  1. If a user clears their cookies, and after that the code sending transactions responses again — this transaction is duplicated.
  2. Google Analytics is filtering duplicated transactions, which happen within one session. This means that if for some reason your code responses twice in a row, this will not lead to transaction duplication.