Skip to content

Instantly share code, notes, and snippets.

@robisatthefunction
Last active March 3, 2025 16:14
Show Gist options
  • Save robisatthefunction/e25d92c365cdb724388d56b9daca1e7c to your computer and use it in GitHub Desktop.
Save robisatthefunction/e25d92c365cdb724388d56b9daca1e7c to your computer and use it in GitHub Desktop.
async function checkIPAddress() {
// Using a public IP API service to get the visitor's IP
const response = await fetch('https://api.ipify.org?format=json');
const data = await response.json();
const visitorIP = data.ip;
return visitorIP
}
window.optimizely = window.optimizely || [];
window["optimizely"].push({
"type": "holdEvents"
});
(() => {
var excludedIPs = ['225.37.219.110', '198.94.96.31', '198.94.96.31'];
var visitorIP = checkIPAddress();
// If not in the excluded list of IPs, send Optimizely events
if (!excludedIps.includes(visitorIP)) {
window["optimizely"].push({
"type": "sendEvents"
});
console.log("Optimizely Web events sent");
} else {
console.log(" Optimizely Web events disabled");
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment