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

Better detection for cookies for browser plugins report for hybrid consent #16101

Merged
merged 3 commits into from Jun 29, 2020

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Jun 22, 2020

Track actual cookie value so when implementing a hybrid consent screen where you first disable cookies and then enable cookies if consent given, then no new visitor is being created. If user doesn't give consent, then cookies stay disabled.

Setting actual cookie value is important because we include whether the user has cookies or not in the fingerprint: https://github.com/matomo-org/matomo/blob/3.13.6/core/Tracker/Settings.php#L145 . disableCookies / enableCookies otherwise creates a different fingerprint.

refs #13056

Creating this as part of 3.x since this is rather "urgently" needed as nowadays this behaviour is often wanted/needed and already used by various users.

@tsteur tsteur added the Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. label Jun 22, 2020
@tsteur tsteur added this to the 3.13.7 milestone Jun 22, 2020
@tsteur
Copy link
Member Author

tsteur commented Jun 22, 2020

build js

@tsteur tsteur changed the title Better detection for cookies for browser plugins report Better detection for cookies for browser plugins report for hybrid consent Jun 22, 2020
@tsteur tsteur added Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. and removed Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. labels Jun 25, 2020
} else {
// Eg IE11 ... prevent error when cookieEnabled is requested within modal dialog. see #11507
browserFeatures.cookie = hasCookies();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually don't understand why that should be needed here. Isn't that actually the same that is already done here:

matomo/js/piwik.js

Lines 3056 to 3063 in aeaa91c

function hasCookies() {
if (configCookiesDisabled) {
return '0';
}
if(!isDefined(windowAlias.showModalDialog) && isDefined(navigatorAlias.cookieEnabled)) {
return navigatorAlias.cookieEnabled ? '1' : '0';
}

So only calling hasCookies would have the same effect, besides the additional check for configCookiesDisabled

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sgiehl yes it is the same code and kind of copied from there... we can't reuse the same method there though as it's different behaviour.

Basically here we want to detect if cookies are generally enabled unless it is IE11 or older. for IE 11 and older we need to execute different logic. It would end up in complicated code to put it in the method itself therefore rather copying code so it's in the end easier... so for IE 11 we might report cookies are disabled when cookies are disabled in Matomo and that's fine. But for all other browsers when cookies are disabled we still report the correct value.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User tested and confirms it works: #13056 (comment)

Except for IE 11 where we will follow up in #16113

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't see any complexity here 🤷 The only difference is about to ignore the check for configCookiesDisabled. So it would be basically the same to change the hasCookies method like that:

 function hasCookies(ignoreConfig) { 
     if (ignoreConfig !== true && configCookiesDisabled) { 
         return '0'; 
     } 
  
     if(!isDefined(windowAlias.showModalDialog) && isDefined(navigatorAlias.cookieEnabled)) { 
         return navigatorAlias.cookieEnabled ? '1' : '0'; 
     } 

and then call

browserFeatures.cookie = hasCookies(true);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Config should not be ignored for IE eg when windowAlias.showModalDialog is defined.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. Guess simply switching the code blocks in hasCookies would cause an issue if hasCookies is called eg here:

} else if ('0' === hasCookies()){

Right? If that's the case, should be good to merge...

@tsteur tsteur merged commit a780db0 into 3.x-dev Jun 29, 2020
@tsteur tsteur deleted the cookieenabled branch June 29, 2020 21:26
jonasgrilleres pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 22, 2020
jbuget pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants