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.
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.
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!
$(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
});
});
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
});
});