Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Console error "There was an error setting cookie mtm_cookie_consent. Please check domain and path." when calling 'rememberCookieConsentGiven' #17926

Closed
McSodbrenner opened this issue Aug 27, 2021 · 8 comments · Fixed by #17928
Assignees
Labels
Bug For errors / faults / flaws / inconsistencies etc. Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Milestone

Comments

@McSodbrenner
Copy link

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
@McSodbrenner McSodbrenner added the Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. label Aug 27, 2021
@Findus23
Copy link
Member

Findus23 commented Aug 27, 2021

Just FYI: The same function in the original readable source is here:

matomo/js/piwik.js

Lines 2451 to 2455 in c2ab6e5

// check the cookie was actually set
if ((!msToExpire || msToExpire >= 0) && getCookie(cookieName) !== value) {
var msg = 'There was an error setting cookie `' + cookieName + '`. Please check domain and path.';
logConsoleError(msg);
}

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']);.

@Findus23 Findus23 added Bug For errors / faults / flaws / inconsistencies etc. and removed Potential Bug Something that might be a bug, but needs validation and confirmation it can be reproduced. labels Aug 27, 2021
@tsteur tsteur added the Regression Indicates a feature used to work in a certain way but it no longer does even though it should. label Aug 29, 2021
@tsteur tsteur added this to the 4.5.0 milestone Aug 29, 2021
@justinvelluppillai
Copy link
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
Copy link

marcing commented Aug 31, 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
Copy link
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
Copy link

A20N commented Sep 5, 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.

@justinvelluppillai justinvelluppillai changed the title "There was an error setting cookie mtm_cookie_consent. Please check domain and path." Fixed "There was an error setting cookie mtm_cookie_consent. Please check domain and path." Oct 6, 2021
@justinvelluppillai justinvelluppillai changed the title Fixed "There was an error setting cookie mtm_cookie_consent. Please check domain and path." Fixed "There was an error setting cookie mtm_cookie_consent. Please check domain and path." when calling 'rememberCookieConsentGiven' Oct 6, 2021
@justinvelluppillai justinvelluppillai changed the title Fixed "There was an error setting cookie mtm_cookie_consent. Please check domain and path." when calling 'rememberCookieConsentGiven' Console error "There was an error setting cookie mtm_cookie_consent. Please check domain and path." when calling 'rememberCookieConsentGiven' Oct 6, 2021
@niklasternstedt
Copy link

@tsteur I have experienced the same problem recently. What can I do to solve this?

@tsteur
Copy link
Member

tsteur commented Oct 11, 2022

@niklasternstedt do you mind creating a new issue for this so the team can triage?

@niklasternstedt
Copy link

@tsteur sure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Regression Indicates a feature used to work in a certain way but it no longer does even though it should.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants