Documentation

Table of Contents

How to Configure Your Cookie Solution (Advanced Guide)

This article refers to the latest version of the Cookie Solution. If you haven’t already, we strongly recommend that you upgrade your Cookie Solution by simply copying the new code here (Dashboard > [Your website/app] > Cookie Solution > Embed) to avoid any CSS related conflicts and to access all the new features of the latest version. Alternately, you can find the old guide related to the legacy version here.

Cookie banner features

  • It’s implemented by inserting a simple code/script in all pages of the site;
  • It shows a notice containing a standard text, it is fully customizable and contains a link to the cookie policy;
  • It has a completely responsive design — optimized for various resolutions and device sizes;
  • We ensure that the cookie policy can be viewed even before the user consent is provided;
  • We ensure a proper functioning of the blocking of scripts – see the introductory guide for the blocking of cookies for more information regarding this topic;
  • Registers preferences via the continued browsing of the user, for instance, through the scroll action;
  • After the consent has been collected, it asynchronously activates (namely without reloading the page) all the scripts that were previously blocked;
  • If the consent has previously been provided by the user, the cookie banner does not appear and the scripts are automatically executed;
  • Easily customize with our configurator. Edit the look, details, features of the solution, all within a few clicks.

Installation

Generic installation

In order to enable the iubenda Cookie Solution you just need to insert the following code before closing the closing of the HEAD Tag

<script type="text/javascript">
    var _iub = _iub || [];
    _iub.csConfiguration = {
        "lang": "en",
        "siteId": XXXXXX, //use your siteId
        "cookiePolicyId": YYYYYY, //use your cookiePolicyId
        "banner": {
            "position": "float-top-center",
            "acceptButtonDisplay": true,
            "customizeButtonDisplay": true
        }
    };
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></script>
Important

The code shown above is an example. To generate your own code, just click on Activate / Edit Cookie Solution located on the edit page of each website in your iubenda dashboard.

WordPress integration

If you are a WordPress user, you can configure the iubenda Cookie Solution by adding the code within the file header.php of the theme you are using before the closing of the HEAD tag.

Alternatively, we also offer a dedicated plugin that further simplifies the task. You can find more information about it in the dedicated WordPress guide.

Joomla! integration

In order to configure the iubenda Cookie Solution on a Joomla! website, you can either install a module like the Custom HTML advanced module. Here’s an article that explains how to use this module to integrate the privacy policy generated with iubenda. We remind you that, as always, the iubenda Cookie Solution code must be entered before the closing of the HEAD tag.

We’ve also released a dedicated Joomla! plugin. For more information, check the comprehensive guide to the iubenda plugin for Joomla!.

Caution

The iubenda Cookie Solution requires a jQuery version 1.4.4 or later. If your site has an older version, you will need to update it. If jQuery is not present, iubenda will take care of the installation.

Configuration

Available parameters _iub.csConfiguration {}:

Required parameters

siteId: – Your site’s ID code (notice: This ID is used to share the preference among multiple cookies policies in different languages that are attributable to the same website/app)

cookiePolicyId: – Your cookie policy’s ID code

lang: – This parameter defines the language in which to display the content of the cookie banner (for example, “it” for the Italian, “en” for English, “es” for Spanish, etc..). All the language localizations available within the generator are also available for the content of the banner.

Optional parameters

priorConsent: (boolean, default true) – Enables the blocking of scripts and their reactivation only after having collected the consent. If false, the blocked scripts are always reactivated regardless of whether or not consent has been provided (we strongly advise against setting priorConsent to false if you want to be complying with EU legislation and thus the Italian legislation except if you are using the Light Cookie Solution deliberately, which requires you to set priorConsent on false). Please note that if the “Prior consent” setting has been disabled directly in your Cookie Solution’s configuration panel on iubenda.com, this configuration parameter will be ineffective.

consentOnScroll: (boolean, default true) – you can set this parameter to false to avoid the registration of the user’s consent when the page is scrolled.

consentOnLinkAndButton: (boolean, default true) – The user’s consent is normally recorded also after a click on a button (button) on the page, as well as on the links (a). Set to false, the consentOnLinkAndButton parameter (formerly consentOnButton) changes the default behavior by ensuring that the consent results as “not given” in these cases.

consentOnElement: (string, default “input, textarea, form”) – The user’s consent is recorded by clicking on one of the html elements listed in the parameter. Unlike consentOnLinkAndButton (see above), the option does not manage the tags a and button. Important: if new html elements are added and you need the default elements to be still active, you must declare them again.

If you’re using the Beta channel, consentOnElement (string|DOMElement, default null) will also accept CSS selectors like classes and ids.

consentOnDocument: (boolean, default false) – If set to true, the user’s consent will be registered if you click anywhere on the page (excluding the banner area).

consentOnContinuedBrowsing: (boolean, default true) – If set to false, consentOnScroll, consentOnDocument and consentOnLinkAndButton are set to false, and consentOnElement is set to no element. This way you only accept explicit consent, while consent on scroll and page interaction is not given.

consentOnScrollHorizontal: (boolean, default false) – By setting this parameter to true, the consent is given even in cases of horizontal scrolling.

consentOnScrollOnElement: (DOMElement, default window.document) – The scrolling event is observed on the element passed as a parameter. The DOM element may not yet be available when the Cookie Solution is initialized. In this case, you can use the setConsentOnScrollOnElement API method.

If you’re using the Beta channel, consentOnScrollOnElement (string|DOMElement, default null) will also accept CSS selectors like classes and ids.

reloadOnConsent:(boolean, default false) – You can set this parameter to true if you want the page to be reloaded after the collection of the consent.

localConsentDomain: (string, default null) – the domain on which you want to save the consent collected from the users. If not set, the consent will be saved in a cookie on the domain of the current page (for example, by visiting www.example.com, the consent will be saved in a cookie placed in the domain example.com). If the default behavior is not appropriate, for example, if the website is located on the domain www.paesaggiurbani.italia.it the consent must be provided for paesaggiurbani.italia.it (and not for italia.it), in that case, you are required to set the localConsentDomain to the value ‘paesaggiurbani.italia.it’.

Notice: in a similar scenario, if the parameter is not given, the banner could continue to appear to the same user at each subsequent visit/page view.

localConsentPath: (string, default ‘/’) – The path in which you want to save, in the local domain, the consent provided by the user. By default, the consent given by the user is saved in the local domain in the cookie in the path ‘/’. In this way, the cookie is available regardless of the page of the domain being accessed. If you want, for example, that the preference cookie set for www.example.com/percorso1 will not be available by browsing on www.example.com/percorso2, and vice versa, it will be necessary to provide this parameter the value ‘/percorso1’ in the first case and ‘/percorso2’ value in the second case.

enableRemoteConsent: (boolean, default false) – You can set this parameter to true to enable a cross-site registration of the consent (it can be useful when the script is implemented in more than one websites of the same network). In particular, if you set this parameter to true, our solution creates a technical cookie on iubenda.com (domain) which is used when the cookie on the local domain is not found.

skipSaveConsent: (boolean, default false) – By setting this parameter to true, the consent is not saved in a preference cookie.

Here are additional optional parameters that call for the definition of one or more objects:

banner {} (object) – Use this object to customize the look (or appearance) of the banner. The options are listed below and must be contained within the object banner {}.

View a sample configuration ↓

  • position (string, default “float-top-center”) – It defines the position of the cookie banner. Available values: top, bottom, float-top-left, float-top-right, float-bottom-left, float-bottom-right, float-top-center, float-bottom-center and float-center.

  • consentOnScrollDelay (integer, milliseconds, default 500) – The delay with which the consent via scroll is detected, once the banner has been shown.

  • slideDown (boolean, default true) – You can set this parameter to false in order to disable the animation of the banner.

  • zIndex (number) – This is the zIndex of the banner’s div. The default value is 99999998.

  • content (string) – This is the textual content inside the cookie banner. For example, for the English version the default value is:

    Notice
    This website or its third-party tools use cookies, which are necessary for its functioning and required to achieve the purposes illustrated in the cookie policy. If you want to learn more or withdraw your consent to all or some of the cookies, please refer to the %{cookie_policy_link}.
    You accept the use of cookies by closing or dismissing this banner, by scrolling this page, by clicking a link or button or by continuing to browse otherwise.

    Note: %{cookie_policy_link} is the placeholder where the link of the cookie policy is placed. Remember that by default, the cookie policy linked in the banner is the one hosted on our servers. In order to change the default behavior, you need to modify the cookiePolicyUrl parameter (please refer to the related section of this guide for more information on this parameter).

    The content of the cookie banner will be localized in all languages available in the generator (the language in which to display the banner content is defined through the parameter lang).

    Warning: in order to make sure that the cookie policy is correctly displayed, it’s necessary that the iubenda-cs-cookie-policy-lnk class is not used elsewhere on the same page.

  • cookiePolicyLinkCaption (string) – Anchor text of the link to the cookie policy (the default value is “cookie policy”).

  • backgroundColor (string, default “#000”) – The background color of the banner.

  • backgroundOverlay (boolean, default false) – Set this parameter to true in order to add an opaque background overlay effect to the rest of the page when the cookie banner is shown.

  • textColor (string, default “#fff”) – The color of the banner’s text.

  • fontSize (string, default null) – The dimension of the banner’s text (including the closing button). If this option is active the possible values in the options banner.fontSizeCloseButton and banner.fontSizeBody will not be taken into account.

  • fontSizeCloseButton (string, default “20px”) – The dimension of the banner’s closing button.

  • fontSizeBody (string, default “14px”) – The dimension of the banner’s text content.

  • innerHtmlCloseBtn (string, default “x”) – The text of the banner’s close button.

  • acceptButtonDisplay (boolean, default false) – Determines whether or not the “Accept” button is displayed.

  • acceptButtonCaption (string, default “Accept”) – The text of the banner’s “Accept” button.

  • acceptButtonColor (string, default “#0073ce”) – Background color of the “Accept” button.

  • acceptButtonCaptionColor (string, default “#fff”) – Text color of the “Accept” button.

  • customizeButtonDisplay (boolean, default false) – Determines whether or not the “Learn more and customize” button is displayed.

  • customizeButtonCaption (string, default “#fff”) – The text of the banner’s “Learn more and customize” button.

  • customizeButtonColor (string, dark theme default “#212121”, light theme default “#dadada”) – Background color of the “Learn more and customize” button.

  • customizeButtonCaptionColor (string, dark theme default “#fff”, light theme default “#4d4d4d”) – Text color of the “Learn more and customize” button.

  • applyStyles (boolean, default true) – By setting this parameter to false, the default style/CSS is not applied to the banner; this parameter can be useful, for example when you want to give the banner a different style than the standard one. The starting point should always be our CSS, that you can find here. It reapplies the same style excluded from this option but has the advantage of being editable once inserted into the pages.

    Here’s an example: Banner with custom CSS

  • html (string, default null) – It is the default HTML of the banner, through this parameter it can be replaced with a customized one. Note: some elements are in any case necessary for the proper functioning of the banner, in particular:

    • div.iubenda-cs-content (the main container)
    • a.iubenda-cs-cookie-policy-lnk (the href link set to link to the cookie policy, i.e. https://www.iubenda.com/privacy-policy/417383/cookie-policy?an=no&s_ck=false)
    • a.iubenda-cs-close-btn (the banner’s close button)
  • prependOnBody (boolean, default false) – If this parameter is set on true, the HTML code of the banner is injected into the site as the first element of the BODY. By default “prependOnBody” is set to false and the banner is placed as the last element of the BODY.

    You must set the prependOnBody on true when you want, for example, to place the banner above the header. In this way, the banner will be the first element on the page, and in order to display it on top of the header, simply apply a “padding-top” to the next item: #iubenda-cs-banner + * { padding-top: 180px; }

    Example with the banner placed over the header

footer {} (object)

  • message (string) – This is the text message displayed below the window where the extended policy is displayed (cookie policy) when you click the cookie policy link within the banner (for example, the default value is “By continuing to browse or by closing this window, you accept the use of cookies“).

  • btnCaption (string) – This is the text displayed in the button (located at the bottom of the window in which the extended policy is displayed when you click the cookie policy link within the banner) used to confirm your consent to the installation of cookies; for example, the default value is “Continue to browse“.

View a sample configuration ↓

callback {} (object) – This is the parameter through which you can define the callback that iubenda Cookie Solution can perform upon the occurrence of an event, namely:

  • onReady (function) – If the consent of the user has not yet been processed (for example, because it’s his first visit) the onReady callback is invoked as soon as the banner cookie is displayed; on the contrary, if the user has already given their consent to the installation of cookies, this callback is invoked as soon as the iubenda Cookie Solution is initialized. The consent given or not is passed as an argument, which can be true or false.

  • onBannerShown (function) – Using this feature you can run a script when the banner is shown.

  • onCookiePolicyShown (function) – Called when the cookie policy is shown (either in modal window or on a separate page).

  • onConsentGiven (function) – This callback is invoked if the user has given the consent to the installation of cookies, both when consenting for the first time and in all subsequent visits.

  • onConsentFirstGiven (function) – It is invoked only for the first time that the user gives their consent. One of the following strings is passed as an argument: documentScroll, documentMoved, bannerXClose, documentClicked or cookiePolicyClosed.

  • onConsentRead (function) – It is invoked the first time the user gives consent and each subsequent loading when the consent is detected. The callback onConsentGiven becomes an alias for onConsentRead and it is not invoked if the latter is defined.

  • onStartupFailed (function) – It is invoked in the case where the iubenda Cookie Solution fails the startup phase. An error message is passed as an argument.

  • onError (function) – It is invoked in the case where the iubenda Cookie Solution is experiencing an error. An error message is passed as an argument.

  • onFatalError (function) – It is invoked in the case where the iubenda Cookie Solution experiencing an error that does not allow it to continue. An error message is passed as an argument.

  • onActivationDone (function) – It is invoked when the snippet activation is complete.

  • onBeforePreload (function) – Invoked when the Cookie Solution preloads, that is before the cookies are loaded.

View a sample configuration ↓

preferenceCookie {} (object) – This is the parameter through which you can customize the lasting of the preference cookie iubenda installs in the user’s browser in order to record its consent. In particular, the object to be defined is:

  • expireAfter (number, default 365) – It represents the number of days of validity of the consent given by the user on a given web site. Note: This value is updated at each subsequent visit by the user.

View a sample configuration ↓

Further parameters for developers

cookiePolicyUrl (string) – This is the cookie policy’s URL linked within the banner. It is available in your privacy policy’s edit page in the “integration” tab. If you don’t define this parameter it will refer to the cookie policy generated by iubenda and hosted on our servers. You can alternatively choose to host the cookie policy on a page of your website and thus fill this field with the related URL. Remember that if you decide to host the cookie policy on your own page, this page should not use cookies, beyond the technical ones. Note: this parameter will be ineffective if you are using a custom HTML for the banner (see the configuration banner.html below).

cookiePolicyInOtherWindow (boolean, default false) – If you set this parameter to true the cookie policy will open in another window instead of the iubenda modal window.

rebuildIframe (boolean, default false) – Once the user’s consent has been recorded, the default behavior of the Cookie Solution is to restore the iframes previously modified in order to make them working again. By setting this parameter to true, the iframes previously blocked are fully regenerated (or reintegrated) after the collection of consent.

preserveOriginalClasses (boolean, default false) – By default, the original classes of the snippets are deleted as a result of their reactivation. By setting this parameter to true, it makes sure that the original classes remain intact even after the activation.

preserveIubClasses (boolean, default false) – By default, the “_iub_cs_activate” class is deleted as a result of the reactivation of the snippet. By setting this parameter on true you allow this class to remain defined after the reactivation. Note: to be effective, this parameter requires also the parameter preseveOriginalClasses to be set to true (see above for further details). Moreover, this parameter has no effect on the snippets tagged with _iub_activate-inline.

inlineDelay (integer, milliseconds, default 500) – The maximum time between the activations of snippets tagged with the class _iub_cs_activate-inline (the snippet tagged in this way are activated sequentially). By decreasing this value you will reduce the total time of activation. Caution: the default value is set in order for the snippets to work properly; reducing it may prevent the successful activation of some snippet. It is highly recommended to check the activation of the snippet shown on your page if this setting is changed.

startOnDomReady (boolean, default true) – if true banner rendering and/or activation of blocked snippets will be performed as soon as the document status is ‘loaded’ (i.e. when the DOM reaches the ‘loaded’ status). If the option is set to false, then the Cookie Solution will start when the page has been fully loaded (i.e. when the DOM status is ‘completed’ and all resources included in the page have been loaded).

logLevel (string) – It defines the verbosity of the logger (available values: ‘debug’, ‘info’, ‘warn’, ‘error’, ‘fatal’; the default value is ‘nolog’)).

logViaAlert (boolean, default false) – By setting this parameter to true, the logging is shown via alert.

Classes

  • iubenda-cs-close-btn – By adding this class to any element of the page, the click on the item closes the banner and assumes that the consent is provided (in an equivalent manner to the click on the X button of the banner).

  • iubenda-cs-cookie-policy-lnk – By adding this class to any element of the page, the click on that element allows the displaying of the Cookie Policy (it’s equivalent to the click on the link to the Cookie Policy). Note: in order to ensure proper display of the cookie policy, the class iubenda-cs-cookie-policy-lnk (assigned to the link to the cookie policy in the banner) must not be used elsewhere on the page.

IAB Transparency and Consent Framework

enableCMP (boolean, default false) – If true, a “customize advertising tracking” link will appear in the bottom section of Cookie Policy modal window. When clicked, this link will open a window that allows users to manage their advertising tracking preferences according to the IAB Transparency and Consent Framework. Learn more.

googleAdsPreferenceManagement (boolean, default false) – If true, end-users will see an additional “Google toggle” that allows them to set preferences for and explicitly consent to either personalized or non-personalized Google ads (required by Google for EU-based users). This setting requires that enableCMP be set to true (or it will not work).

askConsentIfCMPNotFound (boolean, default true) – If set to true, and the IAB Framework preference is not found, the Cookie Solution will, by default, request a new consent from users that had provided consent prior to the activation of the Framework. Set this option to false to disable this default behavior.

gdprApplies (boolean, default true) – If false, you won’t apply GDPR protections to the current user.

gdprAppliesGlobally (boolean, default true) – If true, you’ll apply GDPR protections to all users. If you set gdprAppliesGlobally to false, you’ll need to also specify gdprApplies true and false depending on whether the user is from EU (gdprApplies=true) or not (gdprApplies=false), based on whatever criteria you choose.

isTCFConsentGlobal (boolean, default true) – If set to true, the TCF consent is saved on both consensu.org and local. If set to false, the TCF consent is saved only on the local domain (meaning the TCF cookie won’t be shared with other publishers). This value proxies the IAB CMP JS API hasGlobalScope value.

newConsentAtVendorListUpdate (number, default undefined) – Number of days to wait to trigger a new consent request after the vendorlist.json is updated. If set to undefined, users who have already given consent will not be shown the cookie banner again, and consent for new vendors will be set to off. If set to 0 users will get prompted with a new consent request whenever the vendor list is updated.

Classes

  • iubenda-advertising-preferences-link – By adding this class to any element of the page, the click on the item triggers the opening of the advertising tracking settings modal (allowing users to update their TCF preferences even after closing the cookie banner).

Examples

Here is an example of configuration with the optional parameters:

<script type="text/javascript">
    var _iub = _iub || [];
    _iub.csConfiguration = {
        "lang": "en",
        "siteId": 896537, //use your siteId
        "cookiePolicyId": 8207462, //use your cookiePolicyId
        "enableRemoteConsent": "false",
        "consentOnScroll": "false",
        "banner": {
            "position": "top",
            "slideDown": "false",
            "content": "This website or its third-party tools use cookies. Please refer to the %{cookie_policy_link} if you want to learn more or withdraw your consent.",
            "cookiePolicyLinkCaption": "cookie policy",
            "backgroundColor": "#CCC",
            "textColor": "#000",
            "fontSize": "14px",
            "innerHtmlCloseBtn": "OK"
        },
        "footer": {
            "message": "By closing this window, you accept the use of cookies.",
            "btnCaption": "Close this window"
        },
        "preferenceCookie": {
            "expireAfter": 180
        }
    };
</script>
<script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></script>

Other examples of possible configurations:

Inline activator

It’s possible to include the part of the code relative to the scripts, directly in-page (inline); this code is known as the inline activator. Scripts can be activated through the inline activator even if the iubenda_cs.js primary resource is generically unavailable or in error.

The inline activator only guaranties script activation but can also take on a provided permission (see the following forceSafeActivation option). It cannot be used to show the banner, the cookie policy or manage the obtaining of consent.

It serves only as another layer of protection in case of errors and does not at all act as a substitute for the main iubenda Cookie Solution code (for additional information on how to set up the Cookie Solution, you can read this article).

Note that the inline activator will only invoke the onActivationDone, while others will be ignored.

Two additional configuration options are available for the inline activator:

  • safeTimeout: (milliseconds, default 0) – 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 at:

Important

The content of this file is to be included in-page after the initial configurations and before the code that loads iubenda_cs.js.

Examples

Current

<head>
    ...

    <script type="text/javascript">
        var _iub = _iub || [];
        _iub.csConfiguration = {
            "siteId": XXXXXX, //use your siteId
            "cookiePolicyId": YYYYYY, //use your cookiePolicyId
            //other config options
        };
        _iub.csConfiguration.safeTimeout = 500; //custom option
        _iub.csConfiguration.forceSafeActivation = false; //custom option
    </script>
    
    <script type="text/javascript">
    //<![CDATA[
        //copy content from cdn.iubenda.com/cs/safe.js and paste here
    //]]>
    </script>
    
    <script type="text/javascript" src="//cdn.iubenda.com/cs/iubenda_cs.js" charset="UTF-8" async></script>

    ...
</head>

Beta

<head>
    ...

    <script type="text/javascript">
        var _iub = _iub || [];
        _iub.csConfiguration = {
            "siteId": XXXXXX, //use your siteId
            "cookiePolicyId": YYYYYY, //use your cookiePolicyId
            //other config options
        };
        _iub.csConfiguration.safeTimeout = 500; //custom option
        _iub.csConfiguration.forceSafeActivation = false; //custom option
    </script>
    
    <script type="text/javascript">
    //<![CDATA[
        //copy content from cdn.iubenda.com/cs/beta/safe.js and paste here
    //]]>
    </script>
    
    <script type="text/javascript" src="//cdn.iubenda.com/cs/beta/iubenda_cs.js" charset="UTF-8" async></script>

    ...
</head>

Stable

<head>
    ...

    <script type="text/javascript">
        var _iub = _iub || [];
        _iub.csConfiguration = {
            "siteId": XXXXXX, //use your siteId
            "cookiePolicyId": YYYYYY, //use your cookiePolicyId
            //other config options
        };
        _iub.csConfiguration.safeTimeout = 500; //custom option
        _iub.csConfiguration.forceSafeActivation = false; //custom option
    </script>
    
    <script type="text/javascript">
    //<![CDATA[
        //copy content from cdn.iubenda.com/cs/stable/safe.js and paste here
    //]]>
    </script>
    
    <script type="text/javascript" src="//cdn.iubenda.com/cs/stable/iubenda_cs.js" charset="UTF-8" async></script>

    ...
</head>

The activator code is an integral part of the iubenda Cookie Solution and as such can be modified to include new features, upgrades and fixes.

Releases of new versions of the iubenda Cookie Solution that also include the modification of the inline activator are marked in changelog with the [safe.js updated].

To facilitate the management of the activator version in your page, the _iub.csSafeActivatorVersion variable is available, which recalls the iubenda_cs.js version from which the activator was extracted.

API

The iubenda Cookie Solution features a JS API for easy interaction with some of its main functions.

Syntax: _iub.cs.api.METHOD_NAME

The available methods are:

  • printErrors(): prints any errors in the iubenda Cookie Solution on the browser console.

  • showCP(): shows the Cookie Policy (similarly to when you click on the link to the Cookie Policy in the banner or on another link with the iubenda-cs-cookie-policy-lnk class, as described here)

  • consentGiven(): provides consent. The method accepts the following as optional parameters:

    • eventName: (string), one of the following: documentClicked (default), documentScrolled, documentMoved, bannerXclose, cookiePolicyClosed; indicates the type of action by which consent is provided.
    • force: (boolean), true | false (default): if false, iubenda CS ensures that the banner is shown before actually accepting the consent; instead, by providing this option to true, consent is received in any case.

      Note: the call to this method assumes the consent provided is completely equivalent to when it is provided via UI, e.g. with page scrolling. Therefore, all actions downstream of the consent provided are performed, including the updating of the preference cookie, the activation of the previously blocked snippets and the invocation of the onConsentFirstGiven and onConsentRead callbacks.

      To activate only the snippets there’s the activateSnippets() method.

  • activateSnippets(): activate the previously blocked snippets.
    Note: this method can be invoked repeatedly – already-activated snippets will not be taken into account. It is therefore useful in those installations where, upon collection of consent, previously blocked content that now needs to be activated, is dynamically added to the page (e.g. lazy loading or infinite scrolling).

    The option runOnActivationDoneCallback (boolean, default false), if true, will execute the onActivationDone callback upon completion of the activation of the snippet (see onActivationDone callback).

  • isConsentGiven()(DOMElement, default window.document): returns true if the consent was given, otherwise it returns false.

  • setConsentOnScrollOnElement()(boolean): the call to this method defines the element on which the scroll will be observed for the purpose of consent.

    Note: this method is useful when you want to take advantage of the consentOnScrollOnElement option, but the DOMelement is not yet available when the Cookie Solution is initialized. In this regard it’s possible to use the onBannerShow callback (example) which occurs when the CS is initialized.

  • storeConsent(): stores consent in cookies. If, for example, you want to migrate consents from a previous provider, you could call this method inside the onBeforePreload callback when consent is already given by another platform.

The consent provided by the user is saved in some cookies within the host page’s domain. By verifying the presence or the absence of these cookies you can determine whether the user has given their consent or not.

In particular, the consent is considered provided if there is the cookie _iub_cs-s[siteId] or the cookie _iub_cs-[cookiePolicyId], where siteId and cookiePolicyId are the parameters provided in the embedding code (in the case shown above, the two cookies to look for will be _iub_cs-s234578 and _iub_cs-340542). Below is an example of JavaScript code for reading out the client-side consent:

function isConsentGiven (siteId,cookiePolicyId){
        var cs = document.cookie.split(';');
  for (var i = 0; i < cs.length; i++) {
    while (cs[i].charAt(0) == ' ') cs[i] = cs[i].substring(1);
    if(cs[i].indexOf('_iub_cs-s'+ siteId) == 0||cs[i].indexOf('_iub_cs-'+ cookiePolicyId) == 0) return true;}
  return false;
}

By placing this code as high as possible within the page you can read the consent given and transmit this information to all other JavaScripts that follow.

Still have questions?

Visit our support forum Email us