Enable opt-in options for Optimizely Experimentation cookies and local storage

  • Updated

This topic describes how to:

  • Handle opt-in options for cookies and local storage
  • Comply with electronic privacy laws in your region

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 allow visitors to actively opt-in to cookies and local storage objects. Note that some countries allow for exceptions when cookies are used for website analytics.

We recommend that you review the data protection laws applicable to your site and business. Below, we provide 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 (ITP), see 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. It is important to use the officially supported optOut API rather than setting the cookie directly.

Below, we provide an example of 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. 

<script>
  window["optimizely"] = window["optimizely"] || [];
  window["optimizely"].push({
   "type": "optOut",
   "isOptOut": true
  });
</script>
<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"] || [];
window["optimizely"].push({
  "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.

Helpful tips

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” (i.e. to be 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 will activate 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 in order to conduct experiments, so the cookie-related requirements of the upcoming EU ePrivacy Regulation will 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. It is your responsibility as the data controller 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.

We suggest that you 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 (e.g. 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.