Matomo supports an opt out iframe, which may supports your needs. But in some cases it is more handy to realize opt out / opt in via ajax requests and with no iframes. May due to security reasons.
I had such a project and implemented this nice small plugin which offers you three new API URLs:
your.piwik/index.php?module=API&method=AjaxOptOut.isTrackedYou will get an Response whether the current user get's tracked or not.
your.piwik/index.php?module=API&method=AjaxOptOut.doIgnorePiwik will set the ignore cookie for the current user.
your.piwik/index.php?module=API&method=AjaxOptOut.doTrackPiwik will remove the ignore cookie for the current user.
You have to use JSONP Requests, as of the AJAX requests needs to manipulate the cookies.
This plugin is for free, feel free to spend me a coffee and send me your feedback. Further information you can find in Matomo marketplace.
Some years ago I worked as an senior web developer for some cool agency. We wanted to level up the typical german opt out from tracking game by some nice website overlay. Therefor we needed ajax endpoints in piwik / matomo to take control over the ignore cookie.
After 2016 the development stuck. Plugin worked, no changes needed. But this is not how open source works.
When Matomo 4 came out, I feared to update my on-premise instance because this plugin maybe doesn't work. Stupid right?
So in 2021 I investigated a significant effort in test automation for my matomo plugins. Right now, the logic of this plugin is covered by integration tests which will run against all supported Matomo versions. In addition to run those tests against my code changes, I run them once a week against the newest developments so in case of problems, I get notified by CI/CD instead of you.
For the Matomo marketplace it is needed to have a GitHub project hosting the code.
Even if for this plugin there is a GitHub project, it is just a kind of mirror to my GitLab project. Changes are automatically pushed to GitHub, also releases will be automaticcally be created.
Feel free to fork my GitHub project. Even if I do not accept pull requests, I'm looking forward to take over your changes manually.
This plugin is tested by using GitLab CI.
I make sure all code changes are compatible to:
I make sure that the plugin works as expected with this Matomo versions:
Does this plugin provide an UI?
No. This plugin just provides API endpoints.
Is this plugin under support?
Yes. Please review the support options in the marketplace.
Is there some alternative to jQuery?
Yes for sure. This Plugin is just an API which you can call from wherever you like. For example here you can find a web component to leverege this plugins API.
View and download this plugin for a specific Matomo version: