Refunds in Google Analytics 4: GTM4WP 2.1 connects to the Google Data Manager API
Send WooCommerce and Easy Digital Downloads refunds to Google Analytics 4 from your server: GTM4WP 2.1 connects to the Google Data Manager API.
Sending refunds to Google Analytics 4 has been one of the most frequently requested features of GTM4WP. With version 2.1 it is finally possible: when you refund an order in WooCommerce or Easy Digital Downloads, GTM4WP sends a GA4 refund event straight from your server to Google, so your revenue reports show what you actually earned.
Why refunds need a server
Until now, GTM4WP worked through the pages your visitors open. It wrote data into the data layer of the page, and Google Tag Manager sent it on from the browser. A refund does not fit this model. It happens in the WordPress admin, often days after the purchase, and the buyer is not on your website at that moment. There is no page view that could carry the event.
So GTM4WP 2.1 sends refunds from the server. It does that with the Google Data Manager API, which needs a Google Cloud service account to sign every request.
Why not the Measurement Protocol?
If you have worked with server-side GA4 tracking before, you may ask why GTM4WP does not use the GA4 Measurement Protocol, the usual way to send events to Google Analytics from a server.
Google’s documentation says that the Measurement Protocol has reached a mature, finalized product state and will remain operational with no plans for deprecation. For new server-to-server integrations, it recommends the Data Manager API, which Google calls its central infrastructure for future data ingestion innovations. Google also publishes a guide for upgrading from the Measurement Protocol to the Data Manager API. A new feature built today should use the API that Google recommends for new integrations, so GTM4WP starts with the Data Manager API and does not have to migrate later.
What the new features do
- Google service accounts: a new section in the plugin settings where you upload the JSON key file of a Google Cloud service account. You can store several accounts, test each one, and delete them. The private key is stored encrypted and is never shown again.
- Google Data Manager destinations: each destination names a GA4 property, a measurement ID and the service account that sends to it. A Test button sends a validation-only request, so a missing permission or a mistyped ID shows up before any real data is sent.
- Server-side refund events: every refund, full or partial, is sent as a GA4 refund event with the refunded amount, shipping and tax, and with the refunded items when the store recorded them. Google Analytics matches it to the original purchase through the transaction ID and to the visitor through the client ID.
- Attribution capture: while refund sending is on, each new order stores the Analytics client and session IDs, the Google Ads click IDs and the consent state, so that the refund can be matched to the right visitor later. A GA4 tag has to fire in your container for the measurement ID of the destination. Refunds of orders placed before you turn refund sending on cannot be sent, because those orders have no client ID stored.
- Consent handling: the “Require consent before sending” setting decides which orders need analytics storage granted before anything about them is sent. By default this applies to buyers in the EEA, the UK and Switzerland, based on their billing country.
- Recent sends: a list of the 50 most recent sends to Google and what became of them, with the reason for every skipped refund. Failed refunds, and skipped refunds that a settings change can fix, can be sent again from the same list, one by one or all at once.
Google Analytics currently processes only the first of several refunds on the same order. We have reported this to Google. GTM4WP already sends every refund, so no plugin update is needed once Google fixes it.
More setup, but only once
This is the part that needs the most work from you. A server-side connection to Google needs a Google Cloud project, the Data Manager API enabled in it, a service account with a key file, and Editor access for that account in your GA4 property. It takes more steps than pasting a container ID, and the guide linked below walks you through each one.
You do not need a billing account for it, though. Enabling the Data Manager API in a Google Cloud project works without one, so you can set up the project without entering any payment details.
The service account is not only for refunds. Future features of GTM4WP that talk to Google from your server can use the same account, so you do this setup once.
Why your own service account?
We could have made the setup much shorter: GTM4WP could use a service account of its own, and you would only sign in with your Google account and give it access to your property.
We decided against it. With your own service account, you own every part of the data pipeline: the Google Cloud project, the service account and its key. Order data travels from your server directly to Google, through infrastructure you control, and never passes through a server of ours. You can also revoke the key at any time in your own Google Cloud project.
Where to start
The documentation is in the Google Data Manager for WordPress section. Two guides cover the setup:
- Create a Google service account for the Data Manager API: the Google Cloud project, the service account, access to GA4 and uploading the key file.
- Send WooCommerce and Easy Digital Downloads refunds to Google Analytics 4: the destination, the consent setting and how to check the result in GA4.
Availability
The new features ship in GTM4WP 2.1 and are marked experimental for now. You can try them today with the 2.1 release candidate from the GitHub releases page, on a staging site rather than a live store. The final 2.1 release on wordpress.org is planned for early November.
Please report anything you find on GitHub with “2.1” in the title.
