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 containpage activations,events, orexperiment 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 sends 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
InProject JavaScript, add the following code snippet:
window.optimizely = window.optimizely || [];// PJS: Check list of allowed domainsvar allowedOptimizelyDomains = ['firstdomain.com', 'anotherdomain.com', 'thirddomain.com'];// Check allowed Optimizely Web domainsfunction checkOptimizelyDomains() {var currentDomain = window.location.hostname;// If not in the allowed list, disable Optimizelyif (!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 8 days ago