Skip to content

Instantly share code, notes, and snippets.

@IronistM
Created June 6, 2017 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IronistM/31ab72d125324ba5227aa6dc21d90884 to your computer and use it in GitHub Desktop.
Save IronistM/31ab72d125324ba5227aa6dc21d90884 to your computer and use it in GitHub Desktop.
<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