@McSodbrenner opened this Issue on August 27th 2021

I get the error "There was an error setting cookie mtm_cookie_consent. Please check domain and path." on every page load in my Chrome browser.
I was able to narrow it down to this location in the minified matomo.js:

                if ((!dt || dt >= 0) && aD(dp) !== dq) {
                    var dk = "There was an error setting cookie `" + dp + "`. Please check domain and path.";
                    ak(dk)
                }

The problem is the second part of the condition. aD(dp) !== dq is indeed unequal, but only because the type is not correct. The first part returns 1630087076907 as a string, while the second part returns the same 1630087076907 as an integer.

Expected Behavior

No console error should be thrown.

Possible Solution

A typecasting would have to take place before (or a != would have to be set instead of a !==).

Steps to Reproduce (for Bugs)

I don't know why others don't see the error message. I can reproduce the error locally and on prod.

Your Environment

  • Matomo Version: 4.4.1
  • PHP Version: 7.2.23
  • Browser: Chrome 92
  • Operating System: Windows 10
@Findus23 commented on August 27th 2021 Member

Just FYI: The same function in the original readable source is here:
https://github.com/matomo-org/matomo/blob/c2ab6e589636fdbe0b550486b4a9ac61cbfa37bc/js/piwik.js#L2451-L2455

And this function only logs the warning and should not break anything else. It was added in #17744 to find exactly such corner-cases.

And I can reproduce this by calling _paq.push(['rememberCookieConsentGiven']);.

@justinvelluppillai commented on August 29th 2021 Contributor

Yes I suppose it would make sense to always typecast value before checking it against the cookie value, since cookies are always strings.

@marcing commented on August 31st 2021

I just encountered this when trying to integrate Matomo with cookiebot:

window.addEventListener('CookiebotOnAccept', function()
{
  if(Cookiebot.consent.statistics === true)
  {
          _paq.push(['rememberCookieConsentGiven']);
  }
});
@Findus23 commented on August 31st 2021 Member

@marcing Indeed _paq.push(['rememberCookieConsentGiven']); is what triggers this warning. You can simply ignore it and with the next release (and #17928 merged) it should be gone.

@A20N commented on September 5th 2021

@marcing Indeed _paq.push(['rememberCookieConsentGiven']); is what triggers this warning. You can simply ignore it and with the next release (and #17928 merged) it should be gone.

FYI
I also experience the bug by using _paq.push(["rememberConsentGiven"]);
Everything works fine and the cookie is set as expected.

This Issue was closed on September 6th 2021
Powered by GitHub Issue Mirror