Unable to Integrate 3rd party consent manager using Piwik Pro's JavaScript Methods

Hi,

I’m currently trying to integrate a 3rd party consent manager (Cookiehub) with Piwik pro so that the user’s decision is recorded and remembered within Piwik pro.

I’ve managed to use Cookiehub’s code placed into tag manager and then used Piwik pro’s JavaScript methods/commands, and it almost works, however I’m stuck at the last hurdle.

The user’s decision is recorded within Piwik (each category of consent), and their choice is remembered, and also a returning visitor is not repeatedly asked to select consent either.

However once a user has selected their consent and browses through the site as normal, a new consent decision is recorded as “changed consent” within Piwik Pro each time a new page is loaded - this shows up within tracker debugger and also within the reports under consent.

<script type="text/javascript">
var setComplianceSettings = function(c)
{
    if (ppms != undefined)
    {
        ppms.cm.api('setComplianceSettings',
            {
                consents: {
                    ab_testing_and_personalization: {status: (c.hasConsented('preferences') ? 1 : 0)},
                    analytics: {status: (c.hasConsented('analytics') ? 1 : 0)},
                    conversion_tracking: {status: (c.hasConsented('analytics') ? 1 : 0)},
                    marketing_automation: {status: (c.hasConsented('marketing') ? 1 : 0)},
                    remarketing: {status: (c.hasConsented('marketing') ? 1 : 0)},
                    user_feedback: {status: (c.hasConsented('analytics') ? 1 : 0)}
                }
            },
            function() {}
        );
    }
}

var cpm = {
	onInitialise: function(status) {
		setComplianceSettings(this);
	},
	onStatusChange: function(status, previousStatus) {
        setComplianceSettings(this);
	}
};
(function(h,u,b){
var d=h.getElementsByTagName("script")[0],e=h.createElement("script");
e.async=true;e.src='https://cookiehub.net/c2/64bc4e3f.js';
e.onload=function(){u.cookiehub.load(b);}
d.parentNode.insertBefore(e,d);
})(document,window,cpm);
</script>

The code above is the code that’s placed into tag manager which is Cookiehub’s code with Piwik Pro’s JavaScript commands within it.

Below is a picture of tracker debugger duplicating the user’s consent decisions each time the page is changed (the latest consent decision was just a page view and not reselecting consents).

Thank you in advance for your help :slight_smile:

Hi. I guess you need some additional logic that would call ppms.cm.api('setComplianceSettings') only when the consents change. There’s no need to call it on page view since the current status is stored in a cookie.

1 Like

Ah I see, thank you for your help :slight_smile: