#GTMTips: Gather your ISP as a custom dimension in Google Analytics – News Couple

#GTMTips: Gather your ISP as a custom dimension in Google Analytics

Update 6 April 2020: I updated the template in the gallery to the latest version of the IP Geolocation API SDK, which no longer requires jQuery. Also, the SDK now handles caching of the browser’s storage API request automatically, so an “Enable session storage” option has been added to the model.

Google Analytics was alarming negligence network range And service provider Custom components since late 2019. February 4Finally, the plug is pulled out, and both dimensions are beginning to sag (not set) In Google Analytics reports. For more information on this, see these articles:

This article is not a postmortem. I won’t go into speculating why they made this change, nor will I be concerned about losing those dimensions. Instead, I want to give you a practical way forward: a way that you can roll back some From early lost information like … today!

We’ll be using Google Tag Manager, my geolocation IP API template in the template gallery, and you’ll also need a (free) API key from ipgeolocation.io.


Simmer . Newsletter

Subscribe to the Simmer newsletter to get the latest news and content from Simo Ahava right in your inbox!

Tip 109: Retrieve Service Provider Data

As you can see, this solution only returns the ISP information – not the network domain. This should usually be enough to remove the bot/spam, but if you want domain names that are eligible for IP addresses, you’ll need to look at the other IP APIs out there.

Get an API key

First, you will need to visit ipgeolocation.io and get the API key. The free key gives you 30k requests per month (1k max per day), which is not a lot, I know. You can upgrade to paid plans to increase stakes, and you can add some restrictions on the client side (covered later in this article) to reduce the number of API calls made.

Get an API key

Template configuration

Once you have the API key, visit the template gallery and fetch the custom template for the IP Geolocation API.

Then, in your workspace, create a new tag, and choose the IP Geolocation API template as the base.

add your own API key to the relevant field. You can leave the other settings at their defaults, but if you want, you can expand Other settings And check out what’s new Add an IP hash settings.

fragmented IP

This setting hashes the user’s IP address (using SHA256), and writes it to a file dataLayer object with key geoData.hashedIp. Since it is hashed and cannot be decoded, you can submit it as a custom dimension to Google Analytics. Since the identification of the device the user is using can no longer be undone, it will not violate the Google Analytics Terms of Service. Of course, it’s still a potential user ID, so you need to make sure that sending it complies with the laws governing passing and processing of such IDs.

You can set the tag to shoot at all pages Effects.

Create custom dimensions

Once the tag is in place, you can create custom dimensions in Google Analytics. whether you use Session scope or User domain It is up to you. The first gives you some flexibility to track/block internal traffic, and the second may be more useful for identifying bots.

Custom Dimensions

Create event tag, trigger and variables

Finally, you need to create the event tag, the trigger to fire it, and any data layer variables you want to send.

IP information is written to a file dataLayer An object that looks roughly like this:

  event: 'geolocate',
    ip: '',
    hashedIp: '9iCCGWzjVQPV74KJa3iiS9RKiof6m7y/8aSD9WyT0mw=',
    isp: 'My ISP Org',

To launch your tag, create a file Custom event trigger:

Custom event trigger

You can then create data layer variables for isp And hashedIp fields (and any other fields you might want to use from the API response object).

Here is an example of what a data layer variable for ISP information looks like:

ISP data layer variable

Finally, you need a file Event Tag to send information to Google Analytics. It could look like this:

ISP event tag

Basic things are of course custom dimensions, but also set hit non-interaction domain for true.

Make sure the flag is activated on the Custom Event Trigger you just created.

Setup test

To test the setup, use the GTM/GA Debug extension.

Load the preview container version into your browser, with the extension active, then check that a result is sent to Google Analytics with all the information you’ve included in it.

ISP Event GA Debug

Remember to check your Google Analytics data within a few hours (you may need to wait longer if it’s a new custom component) to make sure the data is filled in correctly.

throttle API requests

Remember that in the free version of the API, you only have 1000 requests per day? This is definitely not much. so you can throttle Requests to make sure they are activated only once per session, or even once per user.

That’s why you need Browser cookies or any other form of browser storage.

The Session cookie It is something you can manipulate with a customTask. In fact, I wrote a solution to update the session cookie with every hit in Google Analytics.

Once you get a file customTask In place, you will need to modify the launcher on IP Geolocation API A flag to activate only if there is no cookie (ie no active session). instead of all pages Launcher, you will need a file page width Effects. Also, you will need a file First Party Cookie Variable as instructed in the manual. The last trigger should look like this:

Page view player

By using this trigger on the IP Geolocation API tag, you will restrict the API request to only occuring once every 30 minutes of GA inactivity. This should keep the number of requests nicely low.

You can also choke per user, by creating a cookie after an API request has completed (eg in a new custom template or custom HTML tag), and then using the presence of that cookie to prevent the API tag from running again.

I personally recommend throttling only per session, as ISPs can change as the user moves, and limiting the user’s ISP range may block actual and valid traffic as well.


In this article, we learned how to reset the purpose of a gallery template to return some data that we lost because Google turned off service provider And network range dimensions.

In addition, we go to the additional bonus to collect hashed ip address to the user. This can be used to filter bots further, as you can identify hashed IP addresses belonging to bots and add them to a blacklist either in Google Tag Manager triggers or in Google Analytics filters.

The downside of the IP Geolocation API is that it does not display a file network range The dimension. For this, you will need some other API and some other solutions. I’m sure other authors will be quick to provide solutions similar to my case, which you can then check out and implement if they sound better for your use cases.

There is an upside to using your own API solution instead of relying on reverse Google searches – you have more transparency, more options, and more ways to comply with laws and regulations that govern the analysis of user IDs, personal data, and IP address searches.

I hope you found this useful! Please let me know in the comments if you have suggestions to improve the setup, or if you don’t understand something – I’m here to help.

Source link

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button