✓ 100% independent
New Metrics

Knowledge base article

Segment Google Ads campaigns by a transaction ID custom variable

In Metrics & KPIs4 minutes reading time

Do you have doubts about the accuracy of your Google Ads tracking? Want to know which transaction came from which Google Ads campaign? Well, you can. There is a way to send specific transaction IDs to Google Ads so that you can segment your campaign data by transaction ID. In this article we will look at why it is useful and how to do it. Let’s go.

Why use transaction ID as a custom variable?

Often, in Google Ads, the product that was clicked on is not the one that the user actually buys. For this reason Google added cart data to its conversion tags. This shows you which products are bought in what quantity. A great start. But what if you want to match exact orders to a campaign?

Perhaps your tracking is set up incorrectly and you are having problems debugging Google Ads. Unlike GA4, you cannot export exact transaction IDs per campaign to compare with your shop data. That is where custom variables come in. They add your own dimensions to conversions, so you can segment the Conversions and All conversions columns by them. So how do you set it up?

How to send custom variables to Google Ads?

If you use gtag.js directly, you add the variable as an extra parameter to the conversion event snippet, next to “send_to”. Google’s example looks like this: gtag(‘event’, ‘conversion’, {‘send_to’: ‘TAG_ID/AW-CONVERSION_LABEL’, ‘color’: ‘example_blue’});. Every parameter you pass shows up on the custom variable page in Google Ads, ready to be activated. In Google Tag Manager it is less simple. The web Google Ads Conversion Tracking tag only has fields for conversion value, transaction ID and currency, so there is nowhere to add a custom variable. Luckily there still is a way if you are using server-side GTM. Let me show you.

custom variable gtm
  1. Add your transaction ID variable to the GA4 purchase event tag sending events to your server container. Use a custom name like “order_id” so you can tell it apart from other variables. Keep tag strings short: Google allows up to 100 characters.
  2. In the server container, be sure to have a Google Ads Conversion Tracking tag sending the purchase event to your Google Ads account.
  3. Also make sure you have a Google Ads Remarketing tag in your sGTM container.
  4. Add the “order_id” variable from your incoming event data to the custom variables in the server remarketing tag.
  5. Activate the custom variable in the Google Ads UI under Goals > Conversions > Custom variable. Variables sent by a tag appear there automatically with the status “Activation needed”, so you can simply click Activate. If it is not in the list yet, you can create it yourself with the same tag string.
custom variables in Google ads

Once activated, data starts recording within a few hours, but give it a day or two before you judge it. Only conversions recorded after activation get a value. As you can see, it can give you the warning “event level key detected”. When you hover over it, it tells you “Too few events per value on average. This may reduce the usefulness of reports based on this custom variable. Consider fixing your setup to send coarser grained values.” That means each value only belongs to one or a few events, and Google would prefer values that repeat. For a transaction ID on the purchase event that is exactly the point, so you can ignore it. It is still worth checking that the value is always available in your server hit.

Keep the limits in mind. Google Ads only records the first 100,000 values of a custom variable, and values can be at most 100 characters. An account can have up to 50 custom variables. With a transaction ID you will hit the 100,000 values sooner or later on a busy shop, so create a new variable when that happens. Never send personal data such as email addresses or phone numbers as a custom variable.

Now you can segment your campaigns by custom variables to see the result. Go to the campaign overview, click Segment > Conversions > Custom variable and select your variable. This works for Conversions and All conv., not for ratio metrics like Conv. rate or Cost/conv. You might see a mix of IDs and “not set” rows.

Reasons why custom variables can be “not set”

As you might see, you can have “not set” values. This can occur for a few reasons, namely when:

1. The variable is not present on the conversion action

If a variable is not present on the primary action that is used as a conversion in Google Ads, then you will see not set when you segment your primary conversion by that variable. If it’s present on some other conversion, like a secondary conversion, add the All conversions column and see if there are values there. If yes, you need to change your setup.

2. The variable is no longer populated

Perhaps your tracking broke and it’s not being sent anymore. As seen in the image, every custom variable has a received time. This is the last time the variable was populated. It also means that if you segment conversions by this variable using recent dates, you might see not set since the variable is no longer populated. The same goes for conversions from before you activated the variable, or from a period when it was paused. Debug your setup to see why it is not being sent.

3. Consent mode is active

Even when everything is set up correctly, some conversions will remain unpopulated. It is unclear how many exactly, but we have seen up to 25% missing variables. Chances are this is because of consent settings.

So, as you can see, it’s not 100% bulletproof, but it gives you relevant insight.

Hopefully it helps. If you encounter any issues, feel free to reach out.

Continue learning

Freek KampenIvo Taris

Need an answer for your own setup?

Questions about your tracking, GA4 or which tool fits? Ask Freek and Ivo, the analytics specialists behind New Metrics. You get a reply from one of us, not a bot.

Contact us