Show cookie consent on selected page

Hi, in case, if I want to show Cookie Consent dialog only on specific URL, is there a way to show it conditionally (only on select page or pages)?

What would be the behaviour on those where it’s not shown? I’d go with the CM JS api here. There are dedicated methods to save the consent decision as well as to simply display the form once again. There are also code samples available here.

So, we want to have 2 different behaviors.

  1. Pages without consent: analytics collects data as it is.
  2. Pages with consent: analytics supposes to collect data after user accept it.
    Is it possible to do with CM API?

Try to run the following code on pages where you’d like the consent to be applied automatically:
  { consents: ["analytics"] },
  function () {},
  function () {}
  { consents: { analytics: { status: 1 } } },
  function () {},
  function () {}
document.getElementById('ppms_cm_consent_popup_<your site id>').style.display = "none";

But this will also store the consent decision globally for all other pages. Not sure what you’d like to achieve.

You can also do it the other way round. To open the consent form after the consents have been saved, you can use the following code:'openConsentForm', function(){}, function(){});

Alternatively, you could install another container code on those sites that you’d like to track always. You configure this container to not require consent and add the custom async tag to start tracking data. Here you have example code: how to install analytics via custom tag.

For better understanding what I want to achieve:
We have an application where users can create landing pages and publish with unique URL. Then users can track analytics on that pages. On our app, PIWIK analytics installed globally, and we filter data by user id, org id etc. to show specific data for specific URL. And we want to have an option to add or remove cookie consent for each page user creates.
As I understood from your message above, it’s not really achievable?

Didn’t say that. There are multiple ways to configure it. I suggested a few, and hope those will be useful.

Hi, I tried your solution:'openConsentForm', function(){}, function(){});

to show the form after page load. But this do not work. If I call this in the browser console, the form will appear.
I guess I have to wait for the API to be ready and therefore i put this call into

  document.addEventListener("DOMContentLoaded", function(){'openConsentForm', function(){}, function(){});

but without luck. Is there a callback function which I can use for it?

Background is, since it is not possible to hide the consent on specific pages
like Privacy Policy or Impressum.

(or did this change menawhile?)
We use a link to another page where the user can modify the settings.
To avoid the user must click once more to get the modal open, we would like to show this after loading the page automaticly.

I’d suggest to fire this code via our integrated Tag Manager. Just pick the custom async tag type and that will make sure you fire the code at the right time.

Thank you for your answer.
as suggested I created a custom async tag with trigger
“Load this tag right after the browser” → Loaded all page elements (page load)
but this do not open the modal.
Then I used the trigger stg.timer which do open the modal, but a bit late.
What would be the best trigger for the goal to show the modal right after the page was opened

That’s weird. Can you share the website URL where it’s implemented? Here or on priv.

No sorry, it is a local docker environment. I didn’t deploy this on the production page

Ok, so maybe some more details on how the container is implemented? What’s the technology used to build the app?

It is a ddev environment based on docker container. It is a 1:1 image from production CMS. We build an extension (TYPO3) to implement Piwik pro on.
It is already running at

There is the requirement that the modal should not show on defined pages.
We use a link to another page where the user can modify the settings.
To avoid the user must click once more to get the modal open, we would like to show this after loading the page automatically.

Thanks for the context. And how this extension adds the installation code to the website? I know that different CMS have different policies on that.

By a script tag in the html code. You can see this by viewing the source code.

The script tag position is at the end and we are working with variables for the key and the url,
but this should not be the probem, isn’t?

        <script type="text/javascript">
            const consentManagerKey = `xxx`;
            const consentManagerURL = `xxx`;

            (function(window, document, dataLayerName, id) {
                window[dataLayerName]=window[dataLayerName]||[],window[dataLayerName].push({start:(new Date).getTime(),event:"stg.start"});var scripts=document.getElementsByTagName('script')[0],tags=document.createElement('script');
                function stgCreateCookie(a,b,c){var d="";if(c){var e=new Date;e.setTime(e.getTime()+24*c*60*60*1e3),d="; expires="+e.toUTCString()}document.cookie=a+"="+b+d+"; path=/"}
                var isStgDebug=(window.location.href.match("stg_debug")||document.cookie.match("stg_debug"))&&!window.location.href.match("stg_disable_debug");stgCreateCookie("stg_debug",isStgDebug?1:"",isStgDebug?14:-1);
                var qP=[];dataLayerName!=="dataLayer"&&qP.push("data_layer_name="+dataLayerName),isStgDebug&&qP.push("stg_debug");var qPString=qP.length>0?("?"+qP.join("&")):"";
                tags.async=!0,tags.src="//" + consentManagerURL + "/"+id+".js"+qPString,scripts.parentNode.insertBefore(tags,scripts);
                !function(a,n,i){a[n]=a[n]||{};for(var c=0;c<i.length;c++)!function(i){a[n][i]=a[n][i]||{},a[n][i].api=a[n][i].api||function(){var a=[],0);"string"==typeof a[0]&&window[dataLayerName].push({event:n+"."+i+":"+a[0],parameters:[],1)})}}(i[c])}(window,"ppms",["tm","cm"]);
            })(window, document, 'dataLayer', consentManagerKey);

No. Those are the URL for the tag manager container and the property ID. I’ve forwarded the question about needed delay to the dev team, maybe they will have some ideas.

1 Like

Some additional information from debug screen.
My custom tag is fired and the string ‘tag’ will get out in the Browser devtools, but the modal do not open


Let’s try with'openConsentForm', console.log, console.error); to see a bit more.

Uh, yes. If I switch from'openConsentForm', function(){}, function(){});

to'openConsentForm', console.log, console.error);

do I get the following error in the Browser console.

ApiCommandError: Failed to render consent popup: No templates