Snippet deactivation
Describes how to deactivate the snippet to ensure the Optimizely Web Experimentation snippet does not send events from the wrong domain.
In Optimizely Web Experimentation, each unique visitor that encounters a page where the snippet is loaded counts as an MAU, even if the snippet is empty and does not contain page activations, events, or experiment evaluations. You may encounter instances where a website scrapes some of your code, including the snippet, and places it on their site.
It is highly unlikely that the snippet will send decision or conversion events to Optimizely because the targeting conditions for events and experiments set in Optimizely will not match the domain sent. To ensure the snippet does not send events from the wrong domain, you can check the domains before sending.
Validate domains before sending events
In Project JavaScript, add the following code snippet:
window.optimizely = window.optimizely || [];
// PJS: Check list of allowed domains
var allowedOptimizelyDomains = ['firstdomain.com', 'anotherdomain.com', 'thirddomain.com'];
// Check allowed Optimizely Web domains
function checkOptimizelyDomains() {
var currentDomain = window.location.hostname;
// If not in the allowed list, disable Optimizely
if (!allowedOptimizelyDomains.includes(currentDomain)) {
window.optimizely.push({
"type": "disable"
});
console.log(`[PJS] ${currentDomain} is not an allowed domain. Optimizely Web is disabled.`);
} else {
console.log(`[PJS] ${currentDomain} is an allowed domain. Optimizely Web is enabled.`);
}
}
checkOptimizelyDomains();
Updated 10 months ago