How do you anonymize your IP adresses, while still being able to see how your internal traffic is performing? In this presentation for #mccph18, I did a discussion around the topic.
4. User
enters the
site
If the user is internal
Set cookie isInternal
Check for cookie in GTM
Use lookup table to set
anonymize IP to nothing
If the user is external
Set cookie isExternal
Check for cookie in GTM
Anonymize IP
Script
checks if
IP is
internal or
external
How it works
8. • First pageview will always be anonymized as no
cookie is set
• Script is fired to check the users IP with a regex
• To find what IP adresses that should be excluded
you need to grab them from your current Google
Analytics settings
1. USER VISITS THE SITE AND
GETS A COOKIE var client = new HttpClient();
client.get('https://api.ipify.or
g?format=json', function(response) {
var result =
JSON.parse(response);
var ip = result.ip;
var ipInternal =
/^((94.231.106.19)|(217.195.188
.30)|(94.231.104.(1[6-9]|2[0-
9]|3[0-1]))|(93.176.86.(19[2-
9]|2[0-5][0-9]))|(94.231.99.(1[6-
8][0-9]|19[0-
1]))|(80.198.126.162)|(192.168.
126.162)|(93.176.86.194)|(93.17
6.86.209)|(50.23.94.74)|(46.20
.45.18)|(94.46.4.1)|(108.62.1
15.226)|(69.64.56.47)|(46.165.
195.139)|(94.247.174.83)|(199.8
7.228.66)|(76.72.167.90)|(184.
75.210.186)|(93.176.86.252)|(94
.231.99.)|(3[2-9]|[4-5][0-9]|6[0-
3])|(5.56.154.58)|(212.237.134
.78)|(93.176.86.149)|(93.176.86
.149))$/i;
13. • Make sure that the you choose an appropriate
time period to save the cookie in the browser
• Set a triggerrule on pages to not fire the script if
the cookie is already set – the developers will
love you for it
• The developers will probably not love you for it,
they will probably be annoyed that you are
adding code on their website
• I will also present a version where the
developers do all the technical stuff for you – no
worries!
3. MAKE SURE IT DOESN’T
FIRE ALL THE TIME!
14. 4. WRITE A SCRIPT TO RETURN IF THE
USER IS INTERNAL
function () {
var returnValue = "true";
var external = {{cookie - External traffic}};
var internal = {{cookie - internal traffic}};
if(external == 1) {
returnValue = "true";
}
else if (internal == 1) {
returnValue = "false";
}
else {
returnValue = "true";
}
return returnValue;
}
• The script checks the cookie and finds out
weather the user is internal or external.
• We are using this to create a boolean value to
which we can send the value through a custom
dimension (not needed though)
15. 5. USE IT IN A CUSTOM DIMENSION IF YOU NEED TO
EXCLUDE TRAFFIC WITH THAT!
16. 6. IF YOU ARE EVEN MORE LAZY, ANONYMIZE IP
ADRESSES WHEN IT HITS GA,AND PREVENT
CHANGING YOUR CURRENT SETTINGS !
18. 1. Exclude IP adress
through your current
GTM Filters
• Quite nice, as you can
just keep your current
settings
• It does however provide
a threat as you are not
anonymizing all IP
traffic, and it is possible
something you have to
talk about with your
vendors and
consultants.
2. Exclude based on the
custom dimension
• Data is already avaliable
from the custom
dimension, so dividing
internal and external is
easy
• It does however take a
bit longer than the first
solution
3. You could also make
your developers do it
• If you have a list of IP
adresses that should be
included, you can make
your IT department
expost them as a
boolean ”internal or
external” value in the
datalayer
• You do however have to
fight with the IT guys to
make it happen
THIS LEAVES US WITH A LOT OF
OPPORTUNITIES!