How to reverse ecommerce transaction 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 (37 Pages)

Learn to read e-commerce reports book banner

Get the E-Book (104 Pages)

Reversing an E-commerce Transaction if you use gtag.js

If you use gtag.js JavaScript library then follow the steps below to reverse an e-commerce 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 E-commerce Transaction if you use analytics.js

If you use analytics.js JavaScript library then follow the steps below to reverse an e-commerce 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 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.

Another article you will find useful: How to remove / modify Google Analytics ecommerce transaction in one click

Do you want to Learn Web Analytics in 4 Weeks?

  • Learn and Master Web Analytics, Conversion Optimization & Google Analytics from Industry Expert in 4 weeks.
  • Lifetime access to the course + Lifelong FREE course updates.
  • New study material added every few months (lifelong learning).
  • Up to date training material.
  • Most exhaustive course on Google Analytics on the internet.
  • Hundreds of Assessments to test your learning.
  • Your 24/7, 365 days a year reference source.
  • Learn at your own pace and from any place.
  • Risk Free with 30 days 100% Money Back Guarantee.

Take your Analytics knowledge to the next level. Checkout my Best Selling Books on Amazon

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.

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 eleven 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 three books:

error: Alert: Content is protected !!