I'm trying to block internal IP and have to add a code which can give me this :
<script type="text/javascript">
dataLayer = [{
'visitorIP': '155.55.155.155'
}];
</script>
Normally i should create it using my server and php because i can't get visitorIP with only js in GTM, but i have to add this js into a gtm variable :
function() {
var newIP = '{{visitorIP}}';
//INTERNAL TRAFFIC
var patt = new RegExp("^28.28.128.1[0-9]?$");
if(patt.test(newIP) == true) {return('internal');}
//MONITORING SYSTEM
patt = new RegExp("^65.65.65.12[0-9]$");
if(patt.test(newIP) == true) {return('monitoring');}
return('external');
}
And i was thinking of getting easily this IP directly in GTM using a code like this and not datalayer, or directly add datalayer code with the function in the GTM variable. To do this i was thinking using something like this :
$.getJSON('https://api.ipify.org?format=json', function(data){
console.log(data.ip);
});
But it's jquery and i don't want GTM to override my website jquery version using this, so i would like in js ; and i don't know how to implement this to have a variable retrieving only the ip in js and using it in my script to have something like this :
function() {
getJSON('https://api.ipify.org?format=json', function(data){
var visitorIP = data.ip;
});
var newIP = visitorIP;
//INTERNAL TRAFFIC
var patt = new RegExp("^28.28.128.1[0-9]?$");
if(patt.test(newIP) == true) {return('internal');}
//MONITORING SYSTEM
patt = new RegExp("^65.65.65.12[0-9]$");
if(patt.test(newIP) == true) {return('monitoring');}
return('external');
}
Do you have an idea ?