Enable opt-in options for cookies and local storage

  • Updated
  • Optimizely Feature Experimentation
  • Optimizely Full Stack (Legacy)
  • Optimizely Web Experimentation
  • Optimizely Performance Edge

Optimizely Experimentation is used by customers around the world to analyze and personalize their web traffic. In some regions, websites may be required to offer visitors the option to opt-in to certain types of browser storage, such as cookies and local storage.

For example, the European ePrivacy Regulation and the national laws of certain European countries require you to let visitors actively opt-in to cookies and local storage objects. Some countries allow for exceptions when cookies are used for website analytics.

You should review the data protection laws applicable to your site and business. Optimizely provides ways to handle opt-in options for cookies and local storage set by Optimizely Experimentation. For information on how Optimizely Experimentation works with Intelligent Tracking Prevention and Optimizely Experimentation.

Use Optimizely Web Experimentation without a tag manager

If you do not use a Tag Manager on your site, you can instruct Optimizely Web Experimentation not to track a site visitor by setting a cookie called optimizelyOptOut to true. Optimizely Web Experimentation checks for the presence of the optimizelyOptOut cookie before executing the contents of the JavaScript snippet. Use the officially supported optOut API rather than setting the cookie directly.

The following example shows how to use the optOut API. Add the code above the Optimizely Web Experimentation snippet on your page. Otherwise, the JavaScript snippet will run and set the tracking cookie(s) and storage items on your visitor. 

  window["optimizely"] = window["optimizely"] || [];
   "type": "optOut",
   "isOptOut": true
<script src=”https://cdn.optimizely.com/js/{project_id].js”></script>

If a visitor opts into cookie tracking, you can re-enable tracking of that visitor by removing the cookie altogether:

window["optimizely"] = window["optimizely"] || [];
  "type": "optOut",
  "isOptOut": false

For example, if you display a cookie banner (an overlay element asking for visitor tracking consent), you might run the code snippet above upon obtaining consent.

Use Optimizely Web Experimentation with a tag manager

If you use a tag manager on your site, you can use conditional logic in the tag manager to load the Optimizely Web Experimentation JavaScript snippet only if a visitor has provided consent.

Since a cookie opt-in option is not required in all regions or for all cookies, Optimizely Web Experimentation does not set the optimizelyOptOut cookie by default. If you are the site owner, you are responsible for determining whether you need to do this, and for using one of the methods above where required.

If you set the optimizelyOptOut to true by default as indicated above, the Optimizely Web Experimentation snippet will run “normally” (such as being able to track the visitors on your site) only when the optOut API is called with a value of false.

With the opt-in solutions above, the Optimizely Web Experimentation JavaScript snippet activates on the page reload after a visitor has opted-in since it is deactivated on the initial page load.

Optimizely Feature Experimentation

Optimizely Feature Experimentation does not rely on cookies to conduct experiments, so the cookie-related requirements of the upcoming EU ePrivacy Regulation does not impact this product.

Nevertheless, Optimizely Feature Experimentation users in the EU should ensure that they are fulfilling their obligations under the General Data Protection Regulation (GDPR), which requires that companies have a proper legal basis for processing personal data gathered from the EU. Your responsibility as the data controller is to ensure that you have a proper legal basis for processing, such as consent, before including any of this personal data in an Optimizely Feature Experimentation experiment.

You should make explicit to your website visitors that your experiments involve first-party efforts to improve user experience and that your data is not shared with third-parties (such as advertising partners) if that is the case.

As the data controller, you should also exclude users from Optimizely Feature Experimentation experiments if they withdraw consent.