Cookiebot integration

Tag Manager

Consent Manager

If you use Cookiebot as your consent manager, you can set up Piwik PRO to collect data based on the visitor’s consent. The consent types used by Cookiebot differ from those used by Piwik PRO, so you’ll need to map them and run a JavaScript code on each page of your website.

In this article, we’ll show you how to do it.

Set up Piwik PRO

In the first step, you’ll need to set up Consent Manager in Piwik PRO so that it doesn’t display our consent form but still uses the consent management mechanism in Tag Manager. In the next steps, you’ll integrate Cookiebot into that mechanism.

To set up Consent Manager in Piwik PRO for your integration, follow these steps:

  1. Log in to Piwik PRO.
  2. Go to Menu > Administration.
  3. Navigate to Sites & apps.
  4. On the left, pick the site or app you want to set up.
  5. Navigate to Privacy.
  6. Turn on Ask visitors for consent.
    Ask visitor for consent in Piwik PRO
  7. Click View to customize the consent setting:
    • Collect anonymous data from non-consenting visitors: You can collect anonymous data from visitors who haven’t given their consent. Their IP addresses will be completely masked. You will not recognize new and returning visitors. And you will only know their country. It’s up to you to decide whether to use a session hash and visitor cookies for these visitors or not.
    • Use a session hash: If you use a session hash, it’ll be created for each session based on the visitor’s IP address, operating system, browser name, browser version, browser language, enabled browser plugins and site/app ID. This hash will help us recognize events that belong to the same session. Note: This setting applies to non-consenting visitors.
    • Use visitor cookies: If you use visitor cookies (_pk_id and _pk_ses), we’ll use them to recognize events that belong to the same session. They will expire 30 minutes after the last event. Note: This setting only applies to non-consenting visitors.

    Note: Some triggers in Tag Manager create cookies to function correctly. If you use one of the following conditions in triggers, we’ll set a cookie:

    • Event condition > Traffic source
    • Event condition > Returning visitor
    • Event condition > Campaign
    • Event condition > External referrer 
    • Multiplicity > Fire tag once per session
    • Multiplicity > Fire tag multiple times per session, excluding first
    • Multiplicity > Fire tag once per page view

    Make sure that tags with those triggers are set with the right consent type.
    We also set essential cookies that store a visitor’s consent decision. More about cookies

  8. Turn on Use a custom consent form.
    Cookiebot integration in Piwik PRO
  9.  Click Save.
  10. All done! Now Piwik PRO is ready for the integration with Cookiebot.

In the next step, you’ll need to map at least one consent type from Cookiebot to one or more consent types in Piwik PRO. But before you do this, it’s important to understand the differences in consent types between the two products.

In Piwik PRO, consent types are used to determine whether a specific tag (such as a tracking or marketing tag) should be fired for a visitor. If a tag requires the Analytics consent, it will only be activated for visitors who have given their consent for Analytics. This allows you to control which tags are activated for which visitors, based on their consent preferences.

Here’s a list of consent types in Piwik PRO.

Name API Description in UI
Analytics “analytics” We’ll collect information about your visit to our site. It helps us understand how the site is used –– what’s working, what might be broken and what we should improve.
A/B testing and personalization “ab_testing_and_personalization” We’ll use your data to customize our site to your needs. We’ll show you more relevant content and carry out A/B tests.
Conversion tracking “conversion_tracking” We’ll use your data to measure how effective our ads and on-site campaigns are.
Marketing automation “marketing_automation” We’ll use your data to send you more relevant email or text message campaigns. We’ll also use it to exclude you from campaigns that you might not like.
Remarketing “remarketing” We’ll use your data to show you more relevant ads on other sites and social media. We’ll use it to measure how effective our ads are. We’ll also use it to exclude you from campaigns that you might not like.
User feedback “user_feedback” We’ll use your data to learn how our user interface is working. It’ll help us to improve our site for all users.
Custom consent “custom_consent”

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Note: You can set an additional consent type here. In Tag Manager, it’ll be still called: Custom consent.

No consent is required

Note: It’s the type you can use for tags that don’t collect data. For example, tags that add a popup or content, or tags that change the look of your site.

Here’s a list of consent types in Cookiebot.

Name API
Statistics “statistics”
Preferences “preferences”
Marketing “marketing”

Once you know what the consent types in each product are, you can decide to map them. Here’s an example that we’ll use.

Cookiebot Piwik PRO
“statistics” “analytics”
“preferences” “ab_testing_and_personalization”
“marketing”

“conversion_tracking”

“marketing_automation”

“remarketing”

Add a tag with the JS code

Now you need to prepare a JS code that will translate consents from Cookiebot to the ones in Piwik PRO and add it to your site using a tag.

To add a tag with the JS code, follow these steps:

  1. Here’s how the code you’ll use works. Take a moment to understand it, then adapt the example below to suit your needs.
    <script>
      	 (function(consentMap, options) {...})
             (consentMap, options)
    </script>

    Parameters

    consentMap (object, required)
    An object that accepts consent IDs from Cookiebot as keys and a list of consent IDs from Piwik PRO as values. For the values, you need to use the API names for the consent types, not the names from the UI. Example: 'analytics'.

    options (object, optional)
    An object containing the options used by the integration. List of options:

    • logLevel (integer, optional)
      The integration will display the required level of information and error messages in the browser console. Possible values: 0 (displays nothing), 1 (displays errors), 2 (displays errors and successful requests). Default value: 1.
    • consentDetectionType (string, optional)
      This option lets you choose whether to detect consent changes using an API or a cookie. The cookie is more reliable, but adds performance overhead to the website. Possible values: 'api', 'cookie'. Default value: 'api'.

    Example:

    <script>
        (function(e,t){var i,n=0,o=!1,c="Piwik PRO Cookiebot integration: ",s=["statistics","preferences","marketing"],a=!t||isNaN(t.logLevel)?1:t.logLevel,l=t&&t.consentDetectionType||"api";function r(e){a>0&&console.error(c+e)}function u(e){a>1&&console.info(c+e)}function f(){ppms.cm.api("trackMainFormView",function(){u("trackMainFormView request successful")},function(){r("trackMainFormView request failed")})}function k(){ppms.cm.api("trackReminderWidgetView",function(){u("trackReminderWidgetView request successful")},function(){r("trackReminderWidgetView request failed")})}function C(e){ppms.cm.api("setInitialComplianceSettings",e,function(){u("setInitialComplianceSettings request successful")},function(){r("setInitialComplianceSettings request failed")})}function g(){var e,t,i,n,o,c={},a=0;if("cookie"===l&&document.cookie&&(e=document.cookie.match(/CookieConsent=(.*?)(; |$)/))){for(n=0,t=decodeURIComponent(e[1]);n<s.length;n+=1)if(o=RegExp("\\W"+s[n]+":(true|false)\\W"),e=t.match(o)){switch(e[1]){case"true":i=!0;break;case"false":i=!1;break;default:i=null}null!==i&&(c[s[n]]=i,a+=1)}}return a===s.length?c:("cookie"===l&&r("Cookie detection failed. Falling back on API."),window.Cookiebot.consent)}function d(){var t,i,c,a,l,f={consents:{}},k={consents:[]},d=["analytics","ab_testing_and_personalization","conversion_tracking","marketing_automation","remarketing","user_feedback","custom_consent"],m={},p=g();for(t=0;t<s.length;t+=1)if(c=s[t],e.hasOwnProperty(c))for(i=0,l=p[c]?1:0;i<e[c].length;i+=1)a=e[c][i],d.indexOf(a)>=0&&(m[a]=c,f.consents[a]={status:l},l&&k.consents.push(a));n=0,ppms.cm.api("getComplianceSettings",function(e){if(o)C(k),o=!1,n=0;else if(void 0!==e.consents){var t,i,c,s,a=g();for(t=0;t<d.length;t+=1)s=a[c=m[i=d[t]]]?1:0,m.hasOwnProperty(i)&&(void 0===e.consents[i]||e.consents[i].status!==s)&&(n=1)}u("getComplianceSettings request successful"),1===n&&ppms.cm.api("setComplianceSettings",f,function(){u("setComplianceSettings request successful")},function(){r("setComplianceSettings request failed")})},function(){r("getComplianceSettings request failed")})}ppms.cm.api("getNewComplianceTypes",function(e){var t;(t=e).length>0?(o=!0,C({consents:t})):o=!1,u("getNewComplianceTypes request successful")},function(){r("getNewComplianceTypes request failed")}),d(),(i=document.getElementById("CookiebotWidget"))&&i.className&&(i.className.indexOf("CookiebotWidget-inactive")&&f(),i.className.indexOf("CookiebotWidget-open")&&k()),window.addEventListener("click",function(e){var t=function e(t,i){return t?t.closest?t.closest(i):(t.tagName||"").toLowerCase()===i.toLowerCase()?t:e(t.parentNode,i):null}(e.target,"button");if(t)switch(t.getAttribute("id")){case"CookiebotWidget-btn-withdraw":case"CybotCookiebotDialogBodyButtonDecline":ppms.cm.api("trackRejectAllClick",function(){u("trackRejectAllClick request successful")},function(){r("trackRejectAllClick request failed")});return;case"CybotCookiebotDialogBodyLevelButtonLevelOptinAllowallSelection":ppms.cm.api("trackSaveChoicesClick",function(){u("trackSaveChoicesClick request successful")},function(){r("trackSaveChoicesClick request failed")});return;case"CybotCookiebotDialogBodyLevelButtonLevelOptinAllowAll":ppms.cm.api("trackAgreeToAllClick",function(){u("trackAgreeToAllClick request successful")},function(){r("trackAgreeToAllClick request faied")});return;default:t.className&&(-1!==t.className.indexOf("CookiebotWidget-logo")&&k(),-1!==t.className.indexOf("CookiebotWidget-close")&&ppms.cm.api("trackCloseButtonClick",function(){u("trackCloseButtonClick request successful")},function(){r("trackCloseButtonClick request failed")}))}},!1),window.addEventListener("CookiebotOnDialogDisplay",f,!1),window.addEventListener("CookiebotOnConsentReady",d)})
        ({
           statistics: ['analytics'],
           preferences: ['ab_testing_and_personalization'],
           marketing: ['marketing_automation', 'remarketing', 'conversion_tracking']
        }, {
           logLevel: 2, // logLevel=2 will display errors and successes in the browser console
           consentDetectionType: 'cookie' // (default) api, cookie
        });
    </script>
    
  2. Log in to Piwik PRO.
  3. Go to Menu > Tag Manager.
  4. Navigate to Tags.
  5. Click Add a tag.
  6. Name your tag. Example: Cookiebot consent mapping.
  7. Pick the following tag type: Custom code (async).
  8. Click Next.
  9. In Tag code, paste the code from step 1.
    Cookiebot integration with Piwik PRO
  10. In Consent type, set the following type: No consent is required.
  11. Click Choose existing trigger.
  12. Pick the following trigger: All page views.
  13. Click Add a tag.
  14. Test your tag in debug mode.
  15. When you’re happy with how the tag works, click Publish.
  16. All done! Now tags in Piwik PRO will fire when the consent assigned to them is given on your Cookiebot consent form. If we look at our example, the integration will work like this:
    A visitor consents on your Cookiebot form Piwik PRO fires tags with this consent type
    Statistics Analytics
    Preferences A/B testing and personalization
    Marketing

    Conversion tracking

    or

    Marketing automation

    or

    Remarketing

Was this article helpful?

Technical support

If you still have any questions, visit our community.
There’s always someone happy to help!

Back to help center