×

How to Process Refunds in Google Analytics with Google Forms

Julian Juenemann

Last Modified on August 23, 2024

Are you looking into a way to process Google Analytics refunds?

The most common way to send data into Google Analytics 4 is the tracking code you have installed on your website. It is how you send most of the user interactions to Google Analytics.

However, there are instances where it is insufficient because the user is not on the website, such as for refunds after purchase.

Depending on how you have set up your website, refunds may be a button on your site or another interface your customer service personnel click in the background.

So, we need another mechanism to send data into GA4. This is where the measurement protocol comes in.

The measurement protocol is the API of GA4. It is a standard way to interface with GA4 so that other servers and computers can understand and send information. It is a protocol, so it has standards on how you need to send that information in.

Theoretically, you could connect any other system to it, such as a different server, POS system, or even your smartwatch. In our case, it aids in sending Google Analytics refunds.

Here is an overview of what we’ll cover:

Let’s dive in.

Measurement Protocol Overview

To start, open the GA4 measurement protocol developers’ page documentation.

GA4 measurement protocol developers’ page

We will find more information about the measurement protocol in this help section. You can read through it to understand it better.

Scrolling below, we see a diagram of the measurement protocol architecture.

What we want to do here is to send data from a server with a payload to the collection endpoint, then transfer that information to the Google Analytics UI and BigQuery, if you have that installed.

Measurement protocol architecture

You must meet specific standards to send data to Google Analytics 4 via the measurement protocol.

First, the GA4 measurement protocol is an authenticated endpoint, so you need a secret key that only you know to send data in.

Second, we have a POS request that we need to send in a specific format with parameters for this to be accepted and processed by GA4.

Let’s try this out by testing a tool built by the Google team called Event Builder.

Event Builder Tool Overview

To access the Event Builder, go to ga-dev-tools.google/ga4/event-builder.

GA4 Event Builder tool

It is a simple form with fields for all the data needed to send a hit. We have the api_secret, measurement_id, client_id, and user_id.

General inputs for the GA4 Event Builder tool

💡 Top Tip: To learn more about what the measurement ID is, how to find it in your GA4 property, and the methods of installing it to your site or app, check out our GA4 Measurement ID guide.

Scrolling down, you can select a specific event name and include the event parameters you send along with your hit.

Select the refund event. The event details parameters will expand to include affiliation, coupon, currency, transaction_id, value, etc.

Event name and event parameter inputs for the GA4 Event Builder tool

There is also a feature to validate your hit. When you have finished editing the form, click the Validate Event button.

The validate event feature of the GA4 Event Builder tool

If there are any errors in your hit, dialogue boxes will appear specifying which properties have errors and a button to go directly to the concerned property.

Event invalid dialogue box

Once you correct all the information, you can send the hit from this tool. You can also see the payload below, encoded in the correct format inside the POST request you send to Google Analytics 4.

Valid event and payload request

This tool allows us to send Google Analytics refunds, but it could be more user-friendly, especially if someone else is filling this out.

If your customer service staff were to fill this out, they may find it difficult if you don’t point out where each specific field goes.

So, we thought of a solution that would be more versatile and show proof of concept.

Using the GA4 Refunder Tool for Processing Google Analytics Refunds

To process Google Analytics refunds, we have built an integration with Google Forms called the GA4 Refunder tool.

Get your copy of the GA4 Refunder tool

GA4 Refunder Tool

It is a simple Google form that lives in your Google Drive where you can fill out this information in a better format. It gives more explanations on each property and allows you to leave out some parameters you don’t need.

We need the following information to demonstrate how the tool will work: the GA4 measurement ID, measurement protocol API secret, client ID, and transaction ID.

Required fields in the GA4 Refunder Tool

First, let’s determine where we can obtain the GA4 measurement ID.

Go to your GA4 account’s admin section. Next, go to Data Streams and select the data stream connected to your website.

Opening the web data stream

💡 Top Tip: Learn more about How GA4 Data Streams Work by checking out our guide.

Copy the measurement ID into our GA4 Refunder tool.

Copying the measurement ID

Next, we need the measurement protocol API secret.

You can get a key in this same data stream section. Scroll down and click the Measurement Protocol API Secrets option.

The measurement protocol API secrets

Click Create if you haven’t created one previously.

Creating a new measurement protocol API secret

Let’s give it the nickname GA4Refunder. Copy the API secret under the secret value column.

Copying the measurement protocol API secret

Ensure that you keep this API secret private. Otherwise, other people could send data to your Google Analytics 4 account.

Next, it gets tricky to put in the remaining fields because you need all the information about the transaction you’re trying to refund. Since you cannot see this information in the GA4 standard reports, we created an exploration report in GA4.

With this report, we have a list of purchases that happened over a certain period with the transaction ID, purchase value, and tax amount.

Purchases exploration report

If you want to rebuild this report, start with a Free-form report, then add the transaction ID in the rows.

Creating a free-form exploration report and adding the transaction ID in the rows

Next, add the Purchase revenue and Tax amount metrics in the values section.

Adding the purchase revenue and tax amount in the values section

With that, we almost have all the information needed. We can obtain the transaction ID, transaction value, and currency from this report.

What we’re missing from this report is the client ID. How do we get this value?

You can right-click on a row and select View users.

Viewing the users for a specific transaction ID

Doing this will open up a new user explorer report with the client ID in the Effective User ID column.

Client ID in the Effective User ID column

The client ID may seem odd, but it is because we have a server integration going. Remove the spaces when you copy this client ID to our GA4 Refunder tool.

Now, why do we need the exact client ID? Google Analytics can still send and validate data when you input a random client ID. However, GA4 will not record this data because the processing engine will filter it out.

Be aware of this and ensure you put in the exact client ID.

Finally, you can do partial refunds when processing Google Analytics refunds.

Partial refunds in the GA4 Refunder tool

If you want, you could refund only one or two items from a transaction. Click Yes → Next if you wish to proceed with the partial refund. You will provide the item ID, quantity, and price on this next page.

Partial refund item details

🚨 Note: You can add up to four items for the partial refund feature of the GA4 Refunder Tool.

We will proceed with the full refund for this example, so let’s go back and select No for the partial refund. Finally, click Submit.

Submitting an entry to the GA4 Refunder tool

That’s it! We have now sent Google Analytics refunds to our GA4 measurement protocol.

Unfortunately, Google Analytics won’t show us this information in its standard reports. However, you can build a report that shows the refunds that come in.

Start with a free-form exploration report. Put refunds and refund amounts in the values section.

Adding refunds and refund amounts to the values section

Finally, put the transaction ID in the rows section.

Adding the transaction ID to the rows section

If you have rebuilt this report, it can take up to 48 hours to see a refund entry.

Alternatively, you can check if your refund information is received by Google Analytics by viewing the Real-Time Report. Check the event count by event name card for the refund event.

Checking the real-time report for refund event

Unfortunately, we don’t have the refund event on this list. It shows up here, but sometimes, it can get blocked because of batching issues. Therefore, you shouldn’t discount it if you don’t see the refund event here.

Later, we will discuss another method for checking if the data has been sent to Google Analytics. 

So, we hope this GA4 Refunder tool is something you will use in your customer service and utilize to send Google Analytics refunds.

Then, you need to create a copy of this document.

Copying the GA4 Refunder tool

It will copy the Google Forms and the attached Apps Script responsible for sending the data to the measurement protocol.

You should see this copied over directly to your Google Drive account. You’ll have full ownership of it later.

Once you are in the edit mode of the GA4 Refunder form, you first need to initialize the whole thing by clicking on the menu at the top-right corner and selecting Script Editor.

Opening the script editor of the GA4 Refunder form

You will see the Apps Script code we have written to make our measurement protocol hit work.

Click Run, and this Apps Script will send data to Google Analytics 4.

Running the app script for the first time

There are some permissions involved that you should review and accept to make this work. Click Review permissions.

Reviewing permissions for the app script code

Log into the Google account connected to your GA4 account, review the permissions involved, and click allow. That will then set up the trigger for us to work whenever someone submits the form to send data to the measurement protocol.

You can now close this Apps Script window and modify the form as you wish by changing the form name and removing the setup steps instructions.

After your edits, you can send this form to your customer service staff by clicking Send and copying the link.

Sending the GA4 Refunder form

Alternatively, you can build a pre-filled link so you don’t have to fill out the measurement ID and measurement protocol API secret key each time you process Google Analytics refunds.

To do this, open the menu icon and select Get Pre-filled Link.

Creating a pre-filled link for the GA4 Refunder form

Next, fill in your measurement ID and measurement protocol API secret key.

Pre-filling the measurement ID and measurement protocol API secret fields

Finally, scroll down and click the Get link button.

Getting the pre-filled link

Once the user opens this link, the measurement ID and measurement protocol API secret key will already be filled up.

Testing the GA4 Refunder Tool

Now, let’s show how you can view the information this form sends to Google Analytics.

First, we will send a hypothetical hit. We will fill in a bogus client ID, transaction ID, value, etc., and submit this entry.

Filling test information in the GA4 Refunder tool

Go to the Script Editor again by opening the menu and selecting Script Editor.

Opening the script editor

Next, go to the menu item Executions.

Opening the executions section

Here, you will see that the process refund function has been completed, and more detailed information is in the execution log.

Executions section of the Apps Script

Summary

Great! We have covered how to send Google Analytics refunds through the measurement protocol. You can use Google’s Event Builder Tool or our in-house GA4 Refunder Tool.

This tool is not an end-all solution, but it is the one we propose. We covered how to use the tool and view the refund entries in the GA4 and Google Forms interface.

If you want to track specific actions you want your users to take, check out our guide on Conversion Tracking in Google Analytics 4.

Have you used the Event Builder Tool? Did you try to use our GA4 Refunder Tool? Let us know in the comments below!

Julian Juenemann

Julian is the web analytics instructor and the owner of MeasureSchool. He has 10+ years of experience in teaching analytics tools such as Google Analytics, Google Tag Manager and Looker Studio. He founded MeasureSchool to help marketers with the data-driven way of digital marketing.

Related Posts

Retargeting without Cookies blog featured image

Retargeting Without Cookies [Ultimate Guide]

Usman Qureshi

How to Build Google Analytics 4 Dashboards blog featured image

How to Build Google Analytics 4 Dashboards

Eric Huguenin

Subscribe
Notify of
guest
14 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Stub
Stub
7 years ago

comment image Have just tried to use the script but there’s not option to include a trigger as you can see from the screenshot. Any ideas what’s wrong?

Julian
Julian
7 years ago
Reply to  Stub

ah yes. The triggers were moved to the Edit menu

Stub
Stub
7 years ago
Reply to  Julian

Nice one, works perfectly!

Frank Jaenicke-R.
Frank Jaenicke-R.
7 years ago
Reply to  Stub

Great! Could you tell more details what is a “partial refund” or “full refund”? What would change with the form or HIT?

FO
FO
7 years ago

I should be seen the video completely before i post a question 😉

Stub
Stub
7 years ago

comment image Have just tried to use the script but there’s not option to include a trigger as you can see from the screenshot. Any ideas what’s wrong?

Julian
Julian
7 years ago
Reply to  Stub

ah yes. The triggers were moved to the Edit menu

Stub
Stub
7 years ago
Reply to  Julian

Nice one, works perfectly!

Frank Jaenicke-R.
Frank Jaenicke-R.
7 years ago

Great! Could you tell more details what is a “partial refund” or “full refund”? What would change with the form or HIT?

FO
FO
7 years ago

I should be seen the video completely before i post a question 😉

Frank Jaenicke-R.
Frank Jaenicke-R.
7 years ago

Great! Could you tell more details what is a “partial refund” or “full refund”? What would change with the form or HIT?

bechy
bechy
3 years ago

Wow! You’re a rock star, Julian!

david
david
3 months ago

Hi Julian. Awesome resource. I tried to use the form, however i’ve encountered this error when i tried to run the script;

This app is blockedThis app tried to access sensitive info in your Google Account. To keep your account safe, Google blocked this access.

Any idea what to do next?

Zsolt Oroszlány
Zsolt Oroszlány
1 month ago

I have a question about partial refund. In example I have sent a partial reufund it seems that I can not send another refund (same transactional ID, client ID etc.), neither full refund. Can someone answer if the refund proces as far as I understand is just a one time proces, means once and never again? Because I can not see any events happening after I have sent the first refund to GA4 . Thanks.

NOW IT'S TIME TO

Start Measuring Like A Master

Itching to jump into the world of MeasureMasters? This is what you have to look forward to.

Ready to take your digital marketing to the next level?

Subscribe to our newsletter and stay ahead with our latest tips and strategies.