Report of accepted cookies

Hi,

I would like to know how many visitors clicked on my “accept cookies” button, which is shown by a wordpress plugin. Is there any mechanism ootb which Matomo offers to do this? I would rather not mess with the plugin code, as this is a pain with updates.

If I do track the clicks on the accept button, or how many users go with _paq.push([‘setConsentGiven’]); I don’t care. I would just like to know how many users have allowed to use cookies on my website.

Thanks, Martin

Well, if you use opt-in every user that is tracked accepted your cookies?

No. Definitely not.

On my page users are tracked without cookies until they give their consent to the storage of the Cookie. Additional both cases can opt out to be not tracked at all.

I would simply attach a onclick handler to the button and push an event to Matomo if it is clicked.

OK. This would mean to edit the Wordpress Plugin which handles the consent question. Would work. I rather would not like to mess with plugins, as I would have to keep an eye on the changes with every update.

I found a working, but not very elegant solution by myself in the meanwhile: I created a goal. This is defined to be counted only once. If the consent has been given I use this two lines:
_paq.push([‘setConsentGiven’]);
_paq.push([‘trackGoal’, ID of the goal]);

Otherwise I set _paq.push([“disableCookies”]);

This is done via PHP in my own child-theme code.

If there is a more elegant solution in existance, I would love to hear it!

Well, you do not need to touch the plugins code. You could just attach a click handler after the site is loaded.

Aha. Then I do not know how to do this. Could you please give me a hint?

$(document).ready(function () {
    $('#awesome_consent_button').click(function () {
        _paq.push(['trackEvent', 'Cookies', 'Accepted']);
        // Add all the over code you might want to run after the user has given consent here
    });
});
1 Like

Cool. Thanks!
I will try that.

Hello,
As I read you want to know how many visitors press the cookies button.
To do that you would simple attach onclick handler button.

To assign an onclickhandler buttton you can follow this code.

$(document).ready(function () {
    $('consent_button').click(function () {
        _paq.push(['trackEvent', 'Cookies', 'Accepted']);
        // enter you code which you want to run for consent
    });
});

Hope this will help you
Thanks

And why exactly are you posting the code I posted 7 days ago, again?