klaro-js icon indicating copy to clipboard operation
klaro-js copied to clipboard

klaro + Matomo's requireCookieConsent Feature

Open futureweb opened this issue 3 years ago • 4 comments

Hey there,

I've got a Question and I hope someone here can give me a helping hand on that! ;-)

I'm using klaro this way:

  • within klaro - Matomo Consent is deactivated by default
  • within Matomo I'm using the requireCookieConsent - so it won't use cookies without consent given
  • When consent is given within klaro - the rememberCookieConsentGiven Function of Matomo is triggered which itself turns on some more features/cookies ...

The Problem: Matomo is deactivated within klaro - but the matomo script should be normally executed and only the rememberCookieConsentGiven should be triggered when consent is given.

To execute the Script even Matomo is deactivated within klaro i'm using type="application/javascript" instead of type="text/plain" ... but since one of the latest klaro updates it seems klaro is reverting the type to type="text/plain" itself on load. And when consent is given ... the

grafik

{
  name: 'matomo',
  default: false,
  required: false,
  optOut: false,
  title : 'Matomo',
  purposes: ['analytics'],
  cookies: [
    [/^_pk_.*$/i, '/'],
    [/^piwik_ignore/, '/', 'stats.futureweb.at'],
    [/^piwik_ignore/, '/']
  ],
  callback: function(consent, app) {
    if (consent == true) {
	    _paq.push(['rememberCookieConsentGiven']);
    } else {
	    _paq.push(['forgetCookieConsentGiven']);
    }
  }
}
<script type="application/javascript" data-type="application/javascript" data-name="matomo">
  Matomo Script Things ...
</script>

How can I achieve the old behaviour?

  • Matomo deactivated within klaro but Matomo script executed
  • klaro only toggling a JS Function when consernt is given / taken?

grafik

Reproduce:

  1. go to https://www.futureweb.at/
  2. accept all Cookies
  3. reload Page and have a look into Console

Thank you, bye from sunny Austria Andreas

btw) initially we had it solved it this way within this Issue: https://github.com/kiprotect/klaro/issues/223

futureweb avatar Mar 08 '22 09:03 futureweb

Does anyone have a idea how to solve this bug/problem?

mathi1993 avatar Apr 08 '24 12:04 mathi1993

@thmull / @adewes - by any chance - do you maybe have an idea on how to tackle this problem? thx, bye from Tirol Andy

futureweb avatar Apr 08 '24 12:04 futureweb

Hey @futureweb, @mathi1993, you can mark the script as required (i.e. set required: true) in the service config, Klaro will then always load the service. You can use a global callback config to interact with the Matomo Javascript. Let me know if that doesn't work.

If you want to let the user disable the Matomo script you can set it to optOut instead of required. Services that are opt-out will be loaded before consent is given, but can be disabled if the user chooses to do so. Required services don't have the option of being disabled.

To make sure the script will only be executed once, you can use the onlyOnce option. Klaro will then never execute the script more than once even if the user e.g. toggles it on and off in the consent dialog.

adewes avatar Apr 09 '24 09:04 adewes

Hey @adewes, thank you for your fast answer. We are aware of these 2 options. However, unfortunately, they do not allow us to configure this scenario.

  • The Matomo script should be executed on page load (in the minimal version with the Matomo 'requireCookieConsent' function), meaning without cookies, ...
  • klaro should display it as DEACTIVATED even after it has been loaded (since it was called with the requireCookieConsent function and so NO cookies are set).
  • When consenting via klaro, _paq.push(['rememberCookieConsentGiven']); is called - which switches Matomo to "full mode" including cookies, etc. - klaro shows Matomo as active
  • If consent is revoked via klaro, _paq.push(['forgetCookieConsentGiven']); is called, and Matomo switches back to minimal mode and klaro shows it again as deactivated as no more cookies are used.

So Matomo is always active - but switching between it's 2 Modes ... with and without cookies. klaro should reflect the Status Matomo is currently running in.

This scenario cannot be implemented with required/optOut unfortunately. Previously it worked as described above - but functionality was lost with some klaro update when klaro started to modify script type itself from "application/javascript" to "text/plain" on initial page load.

thx

futureweb avatar Apr 09 '24 14:04 futureweb