Common Issues

Reverse an Ecommerce transaction

You can reverse an Ecommerce transaction when an order does not go through or is disallowed. In this way, you can ensure that your Google Analytics reports provide accurate value and quantity information.

In a nutshell

To reverse an order or transaction, you will create and load a duplicate receipt page that contains negative values for transaction total, tax, shipping, and item quantity. For example, if the the original transaction total is $699, the duplicate entry will have -$699 as the transaction total. Google Analytics records this negative value and applies it against your totals, effectively reversing the transaction.

When you reverse an Ecommerce transaction, check that:

  • You are using the same transaction ID for the transaction and item-form data as the one you used for the original purchase.
  • The value for the total field in your transaction is negative.
  • The item field has a positive per-unit price and a negative quantity.
  • Tax or shipping charges that were credited back are shown as negative values in the respective fields in the transaction-form data.

Note: Reversing a transaction does not remove it. Both the original transaction and the reversal transaction are included in the transaction count.

For information about how to configure the tracking code on your receipt page, see Setting Up Ecommerce Tracking.

The changes you need to make depend on which tracking code you’re using. See if you have Classic Analytics (ga.js) or Universal Analytics (analytics.js).

 

Universal Analytics (analytics.js)

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.
});
 

Remove the 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.
});

Classic Analytics (ga.js)

Original transaction

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

		_gaq.push(['_addTrans',
		   '1234',           // order ID - required
		   'Womens Apparel', // affiliation or store name
		   '28.28',          // total - required
		   '1.29',           // tax
		   '15.00',          // shipping
		   'San Jose',       // city
		   'California',     // state or province
		   'USA'             // country
		]);
		_gaq.push(['_addItem',
		   '1234',           // order ID - necessary to associate item with transaction
		   'DD44',           // SKU/code - required
		   'T-Shirt',        // product name
		   'Olive Medium',   // category or variation
		   '11.99',          // unit price - required
		   '1'               // item quantity - required
		]);
		_gaq.push(['_trackTrans']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
 
</script>

Remove the transaction

<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-XXXXX-X']);
  _gaq.push(['_trackPageview']);

	_gaq.push(['_addTrans',
	   '1234',           // order ID - required
	   'Womens Apparel', // affiliation or store name
	   '-28.28',          // total - required
	   '-1.29',           // tax
	   '-15.00',          // shipping
	   'San Jose',       // city
	   'California',     // state or province
	   'USA'             // country
	]);
	_gaq.push(['_addItem',
	   '1234',           // order ID - necessary to associate item with transaction
	   'DD44',           // SKU/code - required
	   'T-Shirt',        // product name
	   'Olive Medium',   // category or variation
	   '11.99',          // unit price - required
	   '-1'               // item quantity - required
	]);
	_gaq.push(['_trackTrans']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>