Custom cookie consent banner disappearing without consent

I’m trying to use a custom cookie banner. I’ve used the code that is shown in the example to get started. The cookie banner shows up alright, but only once, because when refreshing the page and not clicking anything, it disappears as if I had given consent. I then need to delete the cookies and/or localStorage of the browser to see the banner again. This is of course not expected behaviour. What might be the reason for this issue?
thanks for help!

The custom cookie banner code examples don’t include this part. I’ll forward the feedback to the product team but for now, it has to be done manually.

don’t include which part?

The reminder widget.

I see, so how can I add it manually then? It’s also just hard to edit if it disappears after the first page refresh. It could just stay there until I consent, that’d be better then just disappearing after the first refresh without consenting, because the way it is it’s quite useless. If there’s no way to do this, I need to return to the provided consent banners then.

You can use the API.'openConsentForm') would reopen the form. You can also use this method to decide whether or not display the option to opt-in.

I added this code:

        <a href="#" id="openConsent">openConsentForm</a>
        <script type="text/javascript">
            document.getElementById('openConsent').addEventListener('click', (e) => {

which worked for a second, now it doesn’t anymore. It seems quite random to me. It also showed the default consent banner, even though the custom consent banner was enabled.

does this have to do with async and sync js? Anyway, it doesn’t work either way…

I just want the consent banner to show until the user has given consent OR a reminder widget with which you can open the consent banner again manually. That can’t be that hard and should be a basic feature for any CMP, right? I mean it works for the default consent banners, what API do those use for the reminder widget?

My bad here. Have you checked the code examples here? The openconsentform function is defined there. Maybe you have it already in your code if you were using those examples?

OK so the function (or method?) is defined in the code alright. But how does that change my code? I would still call this method with'openConsentForm');
So nothing changes the way I see it…
What am I not getting?

Hi. The code examples from here automatically add listener for all clicks on element with ID PiwikPROConsentForm-open-consent-form.

So, if you add a button:

<button id="PiwikPROConsentForm-open-consent-form">
  Open bottom bar

Clicking on it should open the consent form.

doesn’t work either
this is the console log

1234567890-piwik-site-ID.js:8 TypeError: Cannot read properties of null (reading 'addEventListener')
    at addEventListenersToConsentFormButtons (<anonymous>:180:43)
    at <anonymous>:201:7
    at 1234567890-piwik-site-ID.js:8:65854
    at Object.execute [as api] (1234567890-piwik-site-ID.js:8:88048)
    at openConsentForm (<anonymous>:196:13)
    at HTMLButtonElement.<anonymous> (<anonymous>:219:9)

It worked for a moment but not anymore, seems quite buggy.
I followed all instructions very closely.
I guess it’s an DOM-issue, the addEventListener cannot be added when the DOM (including the button in question) isn’t added to the DOM yet, yet I have to add the piwik script (custom consent form js) to the head tag and the button somewhere else.

Also, I would like the consent banner to not disappear until the user clicks on a close-button (X), i.e. stay on the page even after refreshing. Because who gives consent if the banner disappears on its own and who would open the banner manually if they don’t have to.
Is that feasable?

Should I switch to matomo instead or is that even more limited or limited in other aspects?

thanks for help

It’s hard to debug without seeing the code. Looks like an issue in line 8. I just set up the custom consent form on my testing site and the button provided in the example works. I’ll ask the dev team to improve the examples to handle your use case, but I can’t promise any ETA.

As for matomo, they don’t offer consent management as far as I know.