Stape
Search
Try for free

Accessing original user IP when using Own CDN

Updated
Sep 10, 2024
Published
Nov 15, 2023

We already discussed why you would want to use your Own CDN for server side tracking.

The part that a lot of people omit, is that in such a setup your server GTM will receive a request from an IP of your CDN provider, not the actual IP of the user, which may have an effect on your reporting. Here’s an example:

My IP is: 193.193.212.69 but since the subdomain pointed to my sGTM is proxied through Cloudflare, I get a completely different address in the Common Event Data:

address in the Common Event Data

This means incorrect geo data in your destinations (GA4 would be the most obvious one), and of course also throws a wrench into whatever tags/functionality you may have directly reliant on IP address.

Request headers come to the rescue

Let's look at the Cloudflare example, the most commonly used CDN. The original IP address will always be available in Cf-Connecting-Ip header:

Cf-Connecting-Ip header

We can access this data with a native Request Header variable, very straightforward:

Request Header variable

Now that we have a proper IP available to us in a variable, we need to apply to our tags. The simplest way to apply to all your sGTM tags is to use Transformations:

1. Go to Transformations section of your sGTM.

2. Create a new one, pick ‘Augment Event’:

Augment Event in server Google Tag Manager

3. We want to augment event data, so that ip_override (a common event data parameter used by all the tags) is replaced with the value of our header, which we’ve previously created a variable for:

augment event data

4. Hit ‘Save’ - now all your sGTM tags will reference a proper user IP:

a proper user IP

Happy tagging!

Tagged with:gtm server

Try Stape for all things server-sideright now!