How to Refund and Cancel Orders in Google Analytics
Learn how to import refund and order reversal data in Google Analytics for more accurate revenue by channel metrics.
Refund or cancellation data within Google Analytics is not something I’ve seen much…probably less than 5% of businesses I’ve worked with in my career either had this process in place or worked to get there.
One common trait between these companies (that had a solid GA cancellation & refund import process in place) – they ran highly successful marketing & advertising campaigns.
Granted, cancellations and/or refunds are only a fraction of ensuring business-wide data accuracy, however it was clear that decisions were made on accurate data.
A few callouts:
- There is a difference between reversing a transaction and refunding a transaction. Reversing a transaction is done by sending a negative value while refunding a transaction will populate the native refund metrics available in Google Analytics.
- In order to import refund data via the Data Import feature in GA you need to be utilizing Enhanced eCommerce.
- You can’t “fix” refunds that have been already imported…so be sure you test refund imports on a test view first to verify it works as expected.
- To be safe, check reports the following day after importing data to minimize freaking out if the data looks weird a few hours after.
How to Import Refunds into Google Analytics
There are three ways to manage this:
- Manual CSV import into GA (say, what?! Yes, you can upload CSVs to GA)
- Using the measurement protocol hit builder
- Automating imports via API
Import via CSV
If you are refunding complete transactions then all you need is a CSV file that contains your transaction IDs like this:
Then you’ll want to head to Google Analytics => Property Settings => Data Import => Create New Import => Refund Data:
Then name your import in Step 2 Data Set Details and leave your Data Set Schema in Step 3 as is (you should only see Transaction ID column) and click Done.
Your next step is to upload your CSV file in the Manage Uploads Settings of this new data import:
Once you upload your file, you should see a status screen which shows the success of your import:
If you are importing partial items as part of an order (e.g. only 1 qty of an order that has > 1 qty or partial amount on a single qty) then you’ll need to configure an import with a few more columns (shown below).
In your data schema details from step 3, be sure to select these fields shown in row 1 below that you’re including in your import:
Note: If you’re importing a file with partial refunds then you need to have every field completed. You can’t have one row with only transaction ID for a full refund and another row that is completed for a partial refund.
Import via Measurement Protocol
This step takes advantage of the Google Analytics Hit Builder which allows you to send your own hits to Google Analytics.
This example shows how to do it through an event hit but you can also do with a pageview hit type as well.
If you’ve never used the hit builder – it’s pretty awesome! We use it quite frequently to validate test hits we’re sending for Elevar clients pushing offline data into Google Analytics.
You can view the full list of parameters here, but here are the ones we’re showing in this refund hit example:
- v: 1 (can’t change)
- t: event
- tid: this is your GA property ID
- cid: you can use any number for this (click the little generate button on right side)
- ec: this is the Event Category and 100% subjective.
- ea: this is the Event Action and up to you.
- ni: this is Non Interaction hit. It can be 0 or 1, with 1 being “True”.
- pa: this is the Product Action we’re setting on this hit which is refund (see all available actions here)
- pr1id: this is the line item of the SKU in the order. So if you had two SKUs you were sending in a single hit then you’d have pr1id AND pr2id.
- pr1qt: this is quantity of SKU with same application for multiple SKUs in an order.
- dh: this is setting the hostname and is optional. The reason I included this is just in case you have a custom filter on your Google Analytics account to only include your hostname in reports.
Once you have this completed then you can click “Validate Hit” which will verify your hit is good and give you the option to send the hit.
That’s it! Once you send the hit, I’ve found it can be up to 20-30 minutes before the refunds display in GA.
To save you time, you can just copy this hit below into the hit payload shown in the above screenshot and it will create the parameter fields for you:
Automate Import Process via API
This will require some development chops, but you can set up an automated process by:
- Automating the process of sending hits in batches or individually via Measurement Protocol HTTP POST request (similar to previous step). Google’s documentation on this is pretty solid.
- Another option is to automate the process of uploading your Data Import CSV file (from the first option above) through the Management API. Here is where you can get started on this and there are a few good examples of hooking this up via Google Sheets as well (here’s one example).
How to Reverse a Transaction in Google Analytics
This is close to a refund import hit except we’re sending another transaction hit with negative values to zero out the data from the original order.
The difference from refunds is we just aren’t populating the native refund metrics in Google Analytics…I think that’s about it?!
Here is how this looks in the hit builder:
A few things to note in red:
- Total transaction revenue, tax, and shipping are negative values.
- Product quantity is a negative value.
- Individual product price is a positive value.
That’s pretty much it. Validate and send your hit then wait a bit to see this show up as an additional hit for this transaction ID.
How to Analyze Reversed or Refunded Reports
If you’ve never refunded orders in Google Analytics then you might get a bit confused when reviewing your transaction reports the first time.
Remember – GA is not going to delete the original order data so depending on the date range you are viewing you might see orders you expected to be refunded like this:
Notice the revenue and refund amount columns?
Once you include the date when you imported your refund data, you should see something like this:
Wait…why do some of my orders have $0 revenue and others don’t?
Well in this case these orders were placed in October but my report is November – December. Once I change my date, I now see revenue here too (phew):
Now we can begin creating reports to slice our refund data further; like by medium:
Google states one caveat of viewing refund data by source/medium – if the user returns to your site after placing an order and still has their original GA cookie in place then this refund will be attributed to the last session they visited from…not the session where they completed the purchase.
Not very helpful.
I hope this quick tutorial on importing refunds to Google Analytics helps :).
Get Exclusive Elevar Insights directly to your inbox.
Get free analytics tips and resources delivered directly to your inbox.
Shopify Tagging Experts
Learn how Elevar helps Shopify brands scale with expert taggingLearn More