Hello, thank you for developping Matomo!
I’m trying to have the global optout feature working as described here: https://developer.matomo.org/guides/tracking-javascript-guide#optional-creating-a-custom-opt-out-form
When i copy&paste the example and test this.isUserOptedOut(), the return value is always FALSE despite the fact that i check or uncheck the opt in/out box.
How could i debug this please?
Thank you.
Can you share the full custom opt-out JavaScript code?
Sure:
document.addEventListener("DOMContentLoaded", function(event) {
function setOptOutText(element) {
_paq.push([function() {
element.checked = !this.isUserOptedOut();
document.querySelector('label[for=matomo-optout]').innerText = this.isUserOptedOut()
? "Vous refusez le suivi dans nos statistiques. Cocher cette case pour l'autoriser."
: 'Vous autorisez le suivi dans nos statistiques. Décocher cette case pour le refuser.';
}]);
}
var optOut = document.getElementById("matomo-optout");
optOut.addEventListener("click", function() {
if (this.checked) {
_paq.push(['forgetUserOptOut']);
} else {
_paq.push(['optUserOut']);
}
setOptOutText(optOut);
});
setOptOutText(optOut);
});
Just to be sure (sometimes one can spent hours on a spelling error ): Are you sure you pass inside the if (this.checked) {
clause (on check) and other in the else
clause?
Yes, i removed the debug but the two cases of the if statement are triggered correctly.
I just saw that Matomo announced a new version of the feature and fixed an issue that might be related:
https://developer.matomo.org/guides/tracking-optout
opened 04:41PM - 12 Oct 22 UTC
closed 08:18AM - 14 Oct 22 UTC
Bug
## Expected Behavior
No error, no warning
## Current Behavior
After 4.12 up… date:
```
WARNING: /tmp/templates_c/08/086087ec6b1f49536aca0dde3949a877ff4f4f1d35c2087ab45bea9f74ddf14d.php(48): Notice - Array to string conversion - Matomo 4.12.0 - Please report this message in the Matomo forums: https://forum.matomo.org/ (please do a search first as it might have been reported already) (Module: PrivacyManager, Action: usersOptOut, In CLI mode: false)
```
Also (in line 48) ?
```
echo \Piwik\piwik_escape_filter($this->env, (isset($context["language"]) || array_key_exists("language", $context) ? $context["language"] : (function () { throw new RuntimeError('Variable "language" does not exist.', 2, $this->source); })()), "html", null, true);
```
## Possible Solution
Fix the bug 🤣
## Steps to Reproduce (for Bugs)
Module: PrivacyManager, Action: usersOptOut, In CLI mode: false?
## Context
https://forum.matomo.org/t/mise-a-jour-4-12-message-pour-info-pas-bloquant/47700
## Your Environment
* Matomo Version: 4.12.0 after update
* PHP Version:
* Server Operating System:
* Additionally installed plugins:
I’ll test if this fixes the above issue.
1 Like
Several tickets about user opt out have been closed: The one you mentioned , but also:
matomo-org:4.x-dev
← matomo-org:m-19879-optout-toggles-on-load
opened 03:33AM - 27 Oct 22 UTC
### Description:
Fixes #19888
Fixed #19879
The JavaScript tracker opt-o… ut was setting the current opt-out state on page load which was incorrectly causing the state to toggle, this bit of code has now been removed.
The standalone opt-out was interpreting no 'consent cookie' or 'remove consent cookie' to mean the user was opted out, which is incorrect. An extra check has been added so that if neither the 'consent cookie' or the 'remove consent' cookie are set the the user is considered to be currently opted-in.
### Review
* [ ] [Functional review done](https://developer.matomo.org/guides/pull-request-reviews#functional-review-done)
* [ ] [Potential edge cases thought about](https://developer.matomo.org/guides/pull-request-reviews#potential-edge-cases-thought-about) (behavior of the code with strange input, with strange internal state or possible interactions with other Matomo subsystems)
* [ ] [Usability review done](https://developer.matomo.org/guides/pull-request-reviews#usability-review-done) (is anything maybe unclear or think about anything that would cause people to reach out to support)
* [ ] [Security review done](https://developer.matomo.org/guides/security-in-piwik#checklist)
* [ ] [Wording review done](https://developer.matomo.org/guides/pull-request-reviews#translations-wording-review-done)
* [ ] [Code review done](https://developer.matomo.org/guides/pull-request-reviews#code-review-done)
* [ ] [Tests were added if useful/possible](https://developer.matomo.org/guides/pull-request-reviews#tests-were-added-if-usefulpossible)
* [ ] [Reviewed for breaking changes](https://developer.matomo.org/guides/pull-request-reviews#reviewed-for-breaking-changes)
* [ ] [Developer changelog updated if needed](https://developer.matomo.org/guides/pull-request-reviews#developer-changelog-updated-if-needed)
* [ ] [Documentation added if needed](https://developer.matomo.org/guides/pull-request-reviews#documentation-added-if-needed)
* [ ] Existing documentation updated if needed
opened 01:09PM - 19 Oct 22 UTC
closed 09:44PM - 06 Nov 22 UTC
Bug
We are using Matomo 4.12.1 .
We integrated the new script to Opt-out without … the previous iframe (#17452).
Since we track without cookies and do not use a consent tool, the behavior is incorrect.
In the default case, the checkbox is off and it means that I would not be tracked.
## Steps to Reproduce
1. Integrate Tracking-script without consent tool
2. integrate Opt-out script with DIV-Container
3. The Opt-out dialog shows that I would not be tracked. But that is wrong. I'm being tracked.
opened 02:59PM - 18 Oct 22 UTC
closed 09:44PM - 06 Nov 22 UTC
Bug
## Expected Behavior
The opt-out checkbox should only change when clicked. The … checkbox and text should display the actual current state of the users choosen settings.
- If the cookie `mtm_consent_removed` is set, the opt-out text should state, the user has opted-out. The checkbox should **not** be checked and say: "You are currently opted out. Check this box to opt-in."
- If there is **no** `mtm_consent_removed` cookie set, the checkbox should be checked and the text should say: "You are not opted out. Uncheck this box to opt-out."
## Current Behavior
Everytime the page with the opt-out is loaded, the state of the opt-out is toggled. So if there is no `mtm_consent_removed` cookie set, it will be set. Meanwhile the checkbox and text displays the opposite of the cookie state. It seems like the JS is just toggling the state everytime.
## Steps to Reproduce (for Bugs)
1. See this [example page](https://www.trafficon.eu/matomo-test.html), it only inlcudes the tracking snippet and the opt-out snippet
2. Simply reload the page multiple times
## Context
We are trying to implement the cookieless, opt-in method. Therefore the tracking code has set the following options:
```js
_paq.push(["setDoNotTrack", true]);
_paq.push(["disableCookies"]);
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
```
No other cookies are set for the domain. There are results beeing tracked by this example page.
(The different single and double quote styles are actually generated by Matomo UI).
## Your Environment
* Matomo Version: 4.12.1 (previously also occured on 4.12.0)
* PHP Version: 7.4.3
* Server Operating System: Linux
* Additionally installed plugins: CustomVariables
* Browser: Chrome, Firefox
* Operating System: macOS
I tested the new optout process and the cookie was never set to remember the user choice
I gave up on having this working for now.
Hi, I don’t know if it’s the same problem of thread.
In my case, every time I refresh the page that contains the opt out script, it changes the status alternating between accepted flag and rejected flag.
In the meantime, analyzing the site, the mtm_consent_removed cookie is always injected in both modes and the tracking takes place in both modes.
If it helps in the investigation, I tried to implement Matomo on the site with the WP plugin, inserting the script in the header and having it configured by the plugin I use for the cookie banner (Complianz).
In all three cases the problem is the same.
Is it a software bug or is it my specific problem?
Thanks in advance to who can give me a suggestion.
Fixed in last version of Matomo: Matomo 4.13.0 Changelog