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.isTracked
You will get an Response whether the current user get's tracked or not.your.piwik/index.php?module=API&method=AjaxOptOut.doIgnore
Matomo will set the ignore cookie for the current user.your.piwik/index.php?module=API&method=AjaxOptOut.doTrack
Matomo 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.
There is a Demo available for you to mention how to use it in your Project.
- Set the correct Matomo Url in
demo/jquery/index.html
(update the Rowvar piwikUrl = 'http://piwik.lc/';
). - Open the
index.html
via an running WebServer in your favorit Browser - Use the Buttons to toggle the tracking state
- In parallel, watch the Tracking-Status in Matomo Backend or the Matomo Tracking iFrame
- Implement jQuery Module
- Share jQuery Module via npm
- Implement AngularJS Module
- Share AngularJS Module via npm
- Implement Angular Module
- Share Angular Module via npm
- Implement TypeScript Definition
- Share TypeScript Definition via @types-Repository