How to reverse ecommerce transactions in Google Analytics for gtag.js and analytics.js

You can fix test orders and cancelled orders in Google Analytics by reversing an ecommerce transaction.

Google Analytics does not automatically reverse an ecommerce transaction, in the event the transaction is later declined or cancelled.

So if someone has placed an order on your website and later he cancelled the order or his order did not go through for some reason, Google Analytics will still report that order and the corresponding sale generated from that order.

Introduction to reversal transaction

In order to maintain the accuracy of your ecommerce data in Google Analytics Ecommerce reports, you should manually reverse an ecommerce transaction in Google Analytics.

The transaction that is reversed is known as Reversal Transaction.

There is a common misconception that reversing a transaction means removing the transaction.

But unfortunately this is not true.

When you reverse a transaction in Google Analytics, it does not remove it.

GA simply deduct a particular amount from the revenue total.

So what is removed is the revenue/sales associated with the reversal transaction.

No other information associated with the transaction is removed.

For example,

Lets say User ‘A’ placed an order of $200 on Monday.

Lets say the total website sales on Monday was $500.

Now if you reverse the transaction on Monday, then the total sales amount for Monday would be reported to be: $500 – $200 = $300

If you reverse the transaction on say Tuesday, then

the total sales amount for Monday would remain $500

the total sales amount for Tuesday would be: Total website sales for Tuesday – $200

So if the original transaction occurred on Monday and you reversed it on Tuesday then make sure that you are analyzing a date range that includes both Monday and Tuesday.

Google in fact recommends to do the reversal on the same day as the original transaction.

Note: Both original and reversal transaction will be included and reported in the transaction count.

Get the E-book (52 Pages)

Get the E-Book (37 Pages)

Reversing an ecommerce transaction if you use gtag.js

If you use gtag.js JavaScript library then follow the steps below to reverse an ecommerce transaction:

Step-1: Create and load a duplicate of your order confirmation page (receipt page) and name it ‘order cancellation page‘ for easy reference.

Step-2: Update the ecommerce tracking code on the ‘order cancellation’ page.

Follow the steps below:

#2.1 Add negative values for the following transaction fields:

  1. revenue
  2. shipping
  3. tax

For example:

gtag(‘event’, ‘purchase’, {
“transaction_id”: “1234”,
“affiliation”: “Acme Clothing”,
“value”: -11.99, // Negative revenue
“currency”: “USD”,
“tax”: -1.29, // Negative tax
“shipping”: -5, // Negative shipping

#2.2 Add negative value for the ‘quantity’ item field. But keep the ‘price’ item field positive.

For example:

“items”: [
{
“id”: “1234”,
“name”: “Fluffy Pink Bunnies”,
“list_name”: “Search Results”,
“brand”: “ToysRus”,
“category”: “Party Toys”,
“variant”: “Black”,
“list_position”: 1,
“quantity”: -1, // Negative Quantity.
“price”: ‘11.99’ // Positive Unit price.
},

So if following was your original transaction:

gtag('event', 'purchase', {
"transaction_id": "1234",
"affiliation": "Acme Clothing",
"value": 11.99,
"currency": "USD",
"tax": 1.29,
"shipping": 5,

"items": [
{
"id": "1234",
"name": "Fluffy Pink Bunnies",
"list_name": "Search Results",
"brand": "ToysRus",
"category": "Party Toys",
"variant": "Black",
"list_position": 1,
"quantity": 1,
"price": '11.99'
},

Then your Reversal transaction may look like the one below:

gtag('event', 'purchase', {
"transaction_id": "1234",
"affiliation": "Acme Clothing",
"value": -11.99, // Negative revenue
"currency": "USD",
"tax": -1.29, // Negative tax
"shipping": -5, // Negative shipping

"items": [
{
"id": "1234",
"name": "Fluffy Pink Bunnies",
"list_name": "Search Results",
"brand": "ToysRus",
"category": "Party Toys",
"variant": "Black",
"list_position": 1,
"quantity": -1, // Negative Quantity.
"price": '11.99' // Positive Unit price.
},

Note: Do not use the code mentioned above. This is just an example code and not even complete code.

Reversing an ecommerce transaction if you use analytics.js

If you use analytics.js JavaScript library then follow the steps below to reverse an ecommerce transaction:

Step-1: Create and load a duplicate of your order confirmation page (receipt page) and name it ‘order cancellation page‘ for easy reference.

Step-2: Update the ecommerce tracking code on the ‘order cancellation’ page.

Follow the steps below:

#2.1 Add negative values for the following transaction fields:

  1. revenue
  2. shipping
  3. tax

For example:

ga(‘ecommerce:addTransaction’, {
‘id’: ‘1234’, // Transaction ID. Required. Same as original transaction
‘affiliation’: ‘Acme Clothing’, // Affiliation or store name.
‘revenue’: ‘-11.99’, // Negative revenue
‘shipping’: ‘-5’, // Negative shipping
‘tax’: ‘-1.29’ // Negative tax
});

#2.2 Add negative value for the ‘quantity’ item field. But keep the ‘price’ item field positive.

For example:

ga(‘ecommerce:addItem’, {
‘id’: ‘1234’, // Transaction ID. Required.
‘name’: ‘Fluffy Pink Bunnies’, // Product name. Required.
‘sku’: ‘DD23444’, // SKU/code.
‘category’: ‘Party Toys’, // Category or variation.
‘price’: ‘11.99’, // Positive Unit price.
‘quantity’: ‘-1’ // Negative Quantity.
});

So if following was your original transaction:

ga('ecommerce:addTransaction', {
'id': '1234', // Transaction ID. Required.
'affiliation': 'Acme Clothing', // Affiliation or store name.
'revenue': '11.99', // Grand Total.
'shipping': '5', // Shipping.
'tax': '1.29' // Tax.
});

ga('ecommerce:addItem', {
'id': '1234', // Transaction ID. Required.
'name': 'Fluffy Pink Bunnies', // Product name. Required.
'sku': 'DD23444', // SKU/code.
'category': 'Party Toys', // Category or variation.
'price': '11.99', // Unit price.
'quantity': '1' // Quantity.
});

Then your Reversal transaction may look like the one below:

ga('ecommerce:addTransaction', {
'id': '1234', // Transaction ID. Required. Same as original transaction
'affiliation': 'Acme Clothing', // Affiliation or store name.
'revenue': '-11.99', // Negative revenue
'shipping': '-5', // Negative shipping
'tax': '-1.29' // Negative tax
});

// Use the ecommerce:addItem object of the original transaction
ga('ecommerce:addItem', {
'id': '1234', // Transaction ID. Required.
'name': 'Fluffy Pink Bunnies', // Product name. Required.
'sku': 'DD23444', // SKU/code.
'category': 'Party Toys', // Category or variation.
'price': '11.99', // Positive Unit price.
'quantity': '-1' // Negative Quantity.
});

Important points about reversing an ecommerce transaction

Keep the following points in mind before you reverse an ecommerce transaction, regardless of the JavaScript library (gtag.js or analytics.js) you use:

#1 Use the transaction ID (order ID) of the original transaction, as the transaction ID for the reversal transaction.

#2 Use negative values for the following transaction fields: ‘revenue’, ‘shipping’ and ‘tax’.

#3 Use negative value for the ‘quantity’ item field. But keep the ‘price’ item field positive.

#4 Do the reversal on the same day as the original transaction.

#5 Whenever you do a reversal on a date different than the original transaction date, annotate that reversal transaction date via GA annotation feature.

#6 If the original transaction occurred on say January 4 and you reversed it on January 7 then make sure that you are analyzing a date range that includes both dates.

Related Articles

 

Do you know the difference between Digital Analytics and Google Analytics?


99.99% of course creators themselves don’t know the difference between Digital analytics, Google Analytics (GA) and Google Tag Manager (GTM).

So they are teaching GA and GTM in the name of teaching Digital analytics.

They just copy each other. Monkey see, monkey do.

But Digital analytics is not about GA, GTM.

It is about analyzing and interpreting data, setting up goals, strategies and KPIs.

It’s about creating strategic roadmap for your business.


Digital Analytics is the core skill. Google Analytics is just a tool used to implement ‘Digital Analytics’.

You can also implement ‘Digital analytics’ via other tools like ‘adobe analytics’, ‘kissmetrics’ etc.

Using Google Analytics without the good understanding of ‘Digital analytics’ is like driving around in a car, in a big city without understanding the traffic rules and road signs.

You are either likely to end up somewhere other than your destination or you get involved in an accident.


You learn data analysis and interpretation from Digital analytics and not from Google Analytics.

The direction in which your analysis will move, will determine the direction in which your marketing campaigns and eventually your company will move to get the highest possible return on investment.

You get that direction from ‘Digital analytics’ and not from ‘Google Analytics’.


You learn to set up KPIs, strategies and measurement framework for your business from ‘Digital analytics’ and not from ‘Google Analytics’.

So if you are taking a course only on 'Google Analytics’, you are learning to use one of the tools of ‘Digital analytics’. You are not learning the ‘Digital analytics’ itself.

Since any person can learn to use Google Analytics in couple of weeks, you do no get any competitive advantage in the marketplace just by knowing GA.

You need to know lot more than GA in order to work in digital analytics and marketing field.


So what I have done, if you are interested, is I have put together a completely free training that will teach you exactly how I have been able to leverage digital analytics to generate floods of news sales and customers and how you can literally copy what I have done to get similar results.

Here what You'll Learn On This FREE Web Class!


1) The number 1 reason why most marketers and business owners are not able to scale their advertising and maximise sales.

2) Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.

3) The number 1 reason why conversion optimization is not working for your business.

4) How to advertise on any marketing platform for FREE with an unlimited budget.

5) How to learn and master digital analytics in record time.

 
 

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and Beyond
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

Himanshu Sharma

Digital Marketing Consultant and Founder of Optimizesmart.com

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence.

The Digital Analytics Association is a world renowned not-for-profit association which helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!