User IP in Google Tag Manager

In Google Tag Manager you can’t create a Trigger with a filter by IP. Why? Because you haven’t a Variable with the user IP. How can you use it?

You have 2 solution:

My javascript function is a simple code. It calls asynchronously a (proxy) site who gives the user IP. Pay attention: “ajax” calls are made by user browser, with his IP!

You just put function in a GTM “Custom JavaScript” Variable.

function () { if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest(); else xmlhttp = new ActiveXObject(“Microsoft.XMLHTTP”);“GET”,”",false); xmlhttp.send(); hostipInfo = xmlhttp.responseText.split(“\n”); for (i=0; hostipInfo.length >= i; i++) { ipAddress = hostipInfo[i].split(“:”); if ( ipAddress[0] == “IP” ) return ipAddress[1]; } return false;

Now you can use GTM Variable into your Triggers or Tags.

Original post: