Created
June 6, 2017 09:00
-
-
Save IronistM/31ab72d125324ba5227aa6dc21d90884 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function matchIP(ipaddress) { | |
// Comment following three lines if you want to use the IP range method | |
if (ipaddress == "111.222.333.444") { | |
dataLayer.push({"internal": "true"}); | |
} | |
// To use the following IP range check, comment the previous three lines | |
// of code and uncomment the following lines | |
// | |
// var ipRange = ipaddress.split("."); | |
// var lastOctet = parseInt(ipRange.pop()); | |
// if(lastOctet >= 1 && lastOctet <= 100) { | |
// dataLayer.push({"internal": "true"}); | |
// } | |
} | |
var ipaddress = ""; | |
try { | |
jQuery.ajax({ | |
type : "GET", | |
dataType : "json", | |
url : "http://api.hostip.info/get_json.php", | |
async : true, | |
success : function(data) { | |
ipaddress = data.ip; | |
},error : function(errorData) { | |
ipaddress = "none"; | |
},complete : function() { | |
matchIP(ipaddress); | |
} | |
}); | |
} catch(e) { | |
console.log("Oops, something went wrong: " + e.message); | |
} | |
dataLayer.push({"event": "ipComplete"}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment