Documentation index

Cookie solution ›

Introduction to Safemode


What the changes mean in short:

Safemode is the new version of the iubenda cookie solution that will gradually replace the one in use currently. Safemode introduces drastic performance improvements for the iubenda cookie solution:

  • Up to 40% faster – Reduces time to banner appearance and scripts reactivation
  • Inline activator – With the inline activator – or the part of code that deals with activation of the script – a script can also be activated in the event that the main resource iubenda_cs.js is found to be generally unavailable or resulting in error
  • No more compatibility issues – Safemode doesn’t depend on external libraries (jQuery and Zepto) with the result that we’ve eliminated compatibility issues with particular version of these libraries

What is Safemode

Safemode is a new version of the iubenda cookie solution, improved in terms of speed and execution, dependence of external libraries and security in terms of activation of the scripts. Safemode therefore is an alternative to the cookie solution version currently in use, from now on we call it Classic.

The upsides of Safemode

Using Safemode guarantess a series of advantages among which:

  • The reduction of times for banner appearance in cases where consent hasn’t been given, as well as activation of scripts following the given consent. Our internal test have shown a reduction of timesof 15% to 40% compared to the Classic version; the difference depends on a series of factors like the browsers, the state of consent, mobile or desktop user, the host page and the included resources
  • The option to include in the host page only the part of the activation of the scripts, ensuring the activation also in cases in which the complete Javascript resource is found to be generally unavailable or resulting in error
  • No dependence on external libraries (jQuery and Zepto), with the resulting elimination of all compatibility problems with particular versions of these libraries that may be provided by solutions like Joomla! and sometimes, WordPress. In addition, in this way we’re also getting rid of the loading of these scripts (where there not present anyway)

How to activate Safemode

Safemode is currently available at a dedicated URL:

[cdn.iubenda.com/cookie_solution/safemode/iubenda_cs.js]

The initial version of Safemode is 1.0.3 that will be gradually tested and introduced in the next weeks, in order to then definitely replace the Classic cookie solution – following the usual release pattern as described in this article. The complete changelog is available on this page.

In oder to use Safemode on your own site, it’s sufficient to modify the code of the cookie solution inserting the URL above while substituting the default one, as shown in the example below.

Before

<head>
...

<script type="text/javascript">
  var _iub = _iub || [];
  _iub.csConfiguration = {
    cookiePolicyId: XxX,
    siteId: YyY,
    // ...other config options...
  };
  (function (w, d) {
    var loader = function () { var s = d.createElement("script"), tag = d.getElementsByTagName("script")[0]; s.src = "//cdn.iubenda.com/cookie_solution/iubenda_cs.js"; tag.parentNode.insertBefore(s, tag); };
    if (w.addEventListener) { w.addEventListener("load", loader, false); } else if (w.attachEvent) { w.attachEvent("onload", loader); } else { w.onload = loader; }
  })(window, document);
</script>

...

</head>

After

<head>
...
<script type="text/javascript">
  var _iub = _iub || [];
  _iub.csConfiguration = {
    cookiePolicyId: XxX,
    siteId: YyY,
    // other config options
  };
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cookie_solution/safemode/iubenda_cs.js" charset="UTF-8" async></script>
...
</head>

Configuration options

All the configuration options available for the Classic version (described in this article) are preserved, except for the following which aren’t available anymore:

preserveOriginalClasses: (boolean, default false)

  • Classic – By default, the original classes of the script are deleted following their reactivation. Instead, setting this parameter to true, leave the original classes unaltered also after the activation.
  • Safemode – The script classes are always preserved

preserveIubClasses: (boolean, default false)

  • Classic – By default the class “_iub_cs_activate” gets cancelled following the reactivation of the script. Setting this parameter to true will keep this class defined in the script after the reactivation as well. Nota bene: in order for this to be effective, this parameter requires that preserveOriginalClasses is also set to true (see above for more details). What’s more, this parameter has no effect on the scripts tagged with the class “_iub_cs_activate-inline”
  • Safemode – The class “_iub_cs_activate” is always preserved

We’re adding however a new callback:

<head>
 ...
 _iub.csConfiguration = {
    // other options
    callback: {
      onActivationDone: function(){
       // this call back is invoked when all the snippets are activated
      }
    }
 }
 ...
</head>

Direct inclusion of the activator inside the page

It’s possible to include the part of the code which takes care of the activation of the scripts directly on the page (inline); this code is defined as the inline activator. Using the inline activator, the scripts can be activated even in the event that the main resource iubenda_cs.js is found to be generally unavailable or resulting in error.

Note

The inline activator ensures only the activation of scripts, while it can assume the consent given (see the following option forceSafeActivation); It is not able to show the banner, the cookie policy nor to manage the collection of the provided consent. It should therefore be understood only as an additional precautionary measure in case of errors, and does not replace in any way the main iubenda cookie solution code (for more information on how to properly configure the cookie solution, please visit this article). Note that the inline activator is able to invoke only the callback onActivationDone, while other callbacks will be ignored.

Two further specific configuration options are available for the inline activator:

safeTimeout: (millisecondonds, default 5000) – the time the inline activator waits before it's starting to work

forceSafeActivation: (boolean, default false) – If set to true scripts are activated independently of the given consent. If set to false the inline activator activates the scripts only if consent has been given (as memorized in the preference cookie of the domain of the host page)

The inline activator is available on this URL:

The contents of this file are to be included in the page AFTER the initial configurations and BEFORE the code that loads the resource iubenda_cs.js.

Example

<head>
...

<script type="text/javascript">
    var _iub = _iub || [];
  _iub.csConfiguration = {
    cookiePolicyId: XxX,
    siteId: YyY,
    // other config options...
  };
_iub.csConfiguration.safeTimeout = 2000; // Custom option for Safemode
_iub.csConfiguration.forceSafeActivation = false; // Custom option for Safemode
</script>

<script type="text/javascript">
//<![CDATA[
  //copy content from cdn.iubenda.com/cookie_solution/safemode/safe.js and paste here.
//]]>
</script>

<script type="text/javascript" src="//cdn.iubenda.com/cookie_solution/safemode/iubenda_cs.js" charset="UTF-8" async></script>

...
</head>

Note

The activator code is an integral part of iubenda's cookie solution and as such may be amended in order to introduce new features, improvements and bug fixes. The releases of new versions of the iubenda cookie solution which also involve changing the inline activator, are marked in the changelog with [safe.js updated]. In order to facilitate the monitoring of the activator version integrated within your page, there is the variable _iub.csSafeActivatorVersion that matches the iubenda_cs.js version from which the activator was extracted.


Still have questions?

Visit our support forum Email us