The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

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();