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 want to increase your website sales and ROI within 8 weeks?

If yes then checkout our Digital Analytics Implementation program.

The Digital Analytics Implementation Program is made up of following three courses:

 

#1 Sales & ROI Accelerator - This course is designed to help you quickly increase your website sales and ROI in a short period of time. Here the focus is on creating a strategic road-map for your business and on setting up goals, strategies, KPIs and funnels.

#2 Google Analytics Mastery - This course is designed to help you get the most out of Google Analytics. Here the focus is on learning and using Google Analytics.

#3 The ‘Data, Maths and Stats Mastery’ - This course is designed to help you learn the maths and statistics behind digital analytics and conversion optimization in great detail. So that you can correctly interpret data and make data smart business decisions.

  Learn More

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

Certified web analyst and founder of OptimizeSmart.com

My name is Himanshu Sharma and I help businesses find and fix their Google Analytics and conversion issues. If you have any questions or comments please contact me.

  • Over twelve years' experience in SEO, PPC and web analytics
  • Google Analytics certified
  • Google AdWords certified
  • Nominated for Digital Analytics Association Award for Excellence
  • Bachelors degree in Internet Science
  • Founder of OptimizeSmart.com and EventEducation.com

I am also the author of four books:

error: Alert: Content is protected !!