Optimize for non-Webflow sites

Integrate with OneTrust

Updated

Let visitors opt in or out of Optimize using OneTrust cookie preferences.

OneTrust is a service that helps companies manage privacy and data protection compliance. If your company uses OneTrust, you can modify the Optimize snippet to respect a visitor’s cookie preferences — either by blocking the snippet by default (opt-in) or loading it by default (opt-out).

Good to know

Optimize does not use cookies to apply variations.

How to implement

  1. Decide whether you want to use the opt-in or opt-out snippet version
  2. Replace all 123456789 placeholders with your actual Optimize account ID
  3. Add the snippet to every page on your website — use the default snippet install doc as a reference

Snippet with opt-out behavior

This version loads Optimize by default. If the visitor later opts out of functional cookies, the snippet will no longer run.

Steps:

  • Find your account ID in your Optimize Account Settings
  • Replace all 123456789 instances in the code below with your actual account ID
<!-- Optimize opt-out snippet -->
<style>.anti-flicker, .anti-flicker * {visibility: hidden !important; opacity: 0 !important;}</style>
<script>(function(e,t,p){var n=document.documentElement,s={p:[],r:[]},u={p:s.p,r:s.r,push:function(e){s.p.push(e)},ready:function(e){s.r.push(e)}};e.intellimize=u,n.className+=" "+p,setTimeout(function(){n.className=n.className.replace(RegExp(" ?"+p),"")},t)})(window, 4000, 'anti-flicker')</script>
<link rel="preload" href="https://cdn.intellimize.co/snippet/123456789.js" as="script">
<link rel="preconnect" href="https://api.intellimize.co" crossorigin>
<link rel="preconnect" href="https://123456789.intellimizeio.com">
<link rel="preconnect" href="https://log.intellimize.co" crossorigin>
<script>
  (function(){
    function removeFlickerGuard() {
      document.documentElement.className = document.documentElement.className.replace(RegExp(' ?anti-flicker'), '');
    }

    function retrieveStrValByPrefix(arr, str) {
      return arr.find(function(val) {
        return val.indexOf(str) === 0;
      }).replace(str, '');
    }

    let hasOptedOut = false;
    try {
      const ot_cookie_key = 'OptanonConsent=';
      const ot_cookie = retrieveStrValByPrefix(document.cookie.split('; '), ot_cookie_key);
      const ot_groups_key = 'groups=';
      const ot_groups = decodeURIComponent(retrieveStrValByPrefix(ot_cookie.split('&'), ot_groups_key));

      // OneTrust tracks each cookie group permission separately
      // OneTrust groups: 1 = necessary, 2 = performance, 3 = functional, 4 = targeting
      const OT_FUNCTIONAL = '3:1';
      // Check if "functional" preference is set
      hasOptedOut = ot_groups.indexOf(OT_FUNCTIONAL) === -1;
    } catch(xx) { /* OneTrust preferences not set */ }

    // if user has opted out
    if (hasOptedOut) {
      // Remove page hiding
      removeFlickerGuard();
      return;
    }

    // Load Intellimize
    const iS = document.createElement('script');
    iS.type = 'text/javascript';
    iS.async = true;
    iS.src = 'https://cdn.intellimize.co/snippet/123456789.js';
    iS.onerror = function() { removeFlickerGuard(); }
    const s = document.getElementsByTagName('script')[0];
    s.parentNode.insertBefore(iS, s);
  })();
</script>
<!-- Optimize end -->

Snippet with opt-in behavior

This version blocks Optimize by default. The snippet only loads if the visitor explicitly opts in to functional cookies.

Steps:

  • Find your account ID in your Optimize Account Settings
  • Replace all 123456789 instances in the code below with your actual account ID
<!-- Optimize opt-in snippet -->

<style>.anti-flicker, .anti-flicker * {visibility: hidden !important; opacity: 0 !important;}</style>
<script>(function(e,t,p){var n=document.documentElement,s={p:[],r:[]},u={p:s.p,r:s.r,push:function(e){s.p.push(e)},ready:function(e){s.r.push(e)}};e.intellimize=u,n.className+=" "+p,setTimeout(function(){n.className=n.className.replace(RegExp(" ?"+p),"")},t)})(window, 4000, 'anti-flicker')</script>
<link rel="preload" href="https://cdn.intellimize.co/snippet/123456789.js" as="script">
<link rel="preconnect" href="https://api.intellimize.co" crossorigin>
<link rel="preconnect" href="https://123456789.intellimizeio.com">
<link rel="preconnect" href="https://log.intellimize.co" crossorigin>
<script>
  (function(){
    function removeFlickerGuard() {
      document.documentElement.className = document.documentElement.className.replace(RegExp(' ?anti-flicker'), '');
    }

    function retrieveStrValByPrefix(arr, str) {
      return arr.find(function(val) {
        return val.indexOf(str) === 0;
      }).replace(str, '');
    }

    let hasOptedIn = false;
    try {
      const ot_cookie_key = 'OptanonConsent=';
      const ot_cookie = retrieveStrValByPrefix(document.cookie.split('; '), ot_cookie_key);
      const ot_groups_key = 'groups=';
      const ot_groups = decodeURIComponent(retrieveStrValByPrefix(ot_cookie.split('&'), ot_groups_key));

      // OneTrust tracks each cookie group permission separately
      // OneTrust groups: 1 = necessary, 2 = performance, 3 = functional, 4 = targeting
      const OT_FUNCTIONAL = '3:1';
      // Check if "functional" preference is set
      hasOptedIn = ot_groups.indexOf(OT_FUNCTIONAL) !== -1;
    } catch(xx) { /* OneTrust preferences not set */ }

    // if user has opted in
    if (hasOptedIn) {
      // Load Intellimize
      const iS = document.createElement('script');
      iS.type = 'text/javascript';
      iS.async = true;
      iS.src = 'https://cdn.intellimize.co/snippet/123456789.js';
      iS.onerror = function() { removeFlickerGuard(); }
      const s = document.getElementsByTagName('script')[0];
      s.parentNode.insertBefore(iS, s);
    } else {
      // Remove page hiding
      removeFlickerGuard();
    }
  })();
</script>

<!-- Optimize end -->