Skip to content

Conversation

mattab
Copy link
Member

@mattab mattab commented Mar 29, 2019

Steps to reproduce:

  • Create a Matomo tag on a container, configured with cookie domain .example.com
  • Load the website www.example.com
  • Got: Two cookies are created on domains .example.com and www.example.com eg.
9b1feac345884afb.1553796770.0.1553796834.. on domaine www.example.com
97b1f55eea218e3e.1553796770.1.1553796834.1553796770. on .example.com
  • Expected only one cookie on .example.com

Looked a bit into it and found that:

  • in the container it calls tracker = Piwik.addTracker(trackerUrl, matomoConfig.idSite);
  • which then triggers the line setVisitorIdCookie(); in the Tracker constructor
  • which creates the wrong cookie on www.example.com
  • the wrong cookie is created because at this point, the function setCookieDomains hasn't been called yet. It's called a bit later in: https://github.com/matomo-org/tag-manager/blob/0.2.6/Template/Tag/MatomoTag.web.js#L121-L123
  • hence why in this PR by moving the setSiteId to after the setCookie* functions are called, I think may fix the issue

Note: it is un-tested

Steps to reproduce:
* Create a Matomo tag on a container, configured with cookie domain `.example.com`
* Load the website www.example.com
* Got: Two cookies are created on domains .example.com and www.example.com eg.
```
9b1feac345884afb.1553796770.0.1553796834.. on domaine www.example.com
97b1f55eea218e3e.1553796770.1.1553796834.1553796770. on .example.com
```
* Expected only one cookie on .example.com

Looked a bit into it and found that:
* in the container it calls `        tracker = Piwik.addTracker(trackerUrl, matomoConfig.idSite);`
* which then triggers the line `setVisitorIdCookie();` in the Tracker constructor
* which creates the wrong cookie on `www.example.com`
* the wrong cookie is created because at this point, the function `setCookieDomains` hasn't been called yet. It's called a bit later in: https://github.com/matomo-org/tag-manager/blob/0.2.6/Template/Tag/MatomoTag.web.js#L121-L123
* hence why in this PR by moving the setSiteId to after the `setCookie*` functions are called, I think may fix the issue

Note: it is un-tested
@mattab mattab requested a review from tsteur March 29, 2019 04:04
@@ -148,6 +148,8 @@
if (matomoConfig.trackVisibleContentImpressions) {
tracker.trackVisibleContentImpressions();
}

tracker.setSiteId(matomoConfig.idSite);
Copy link
Member Author

Choose a reason for hiding this comment

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

maybe it should be rather just below the call to setCookiePath as the functions above (alwaysUseSendBeacon, enableLinkTracking, etc.) may need the id site to function properly.

Copy link
Member

Choose a reason for hiding this comment

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

var applyFirst = ['addTracker', 'disableCookies', 'setTrackerUrl', 'setAPIUrl', 'enableCrossDomainLinking', 'setCrossDomainLinkingTimeout', 'setSecureCookie', 'setCookiePath', 'setCookieDomain', 'setDomains', 'setUserId', 'setSiteId', 'alwaysUseSendBeacon', 'enableLinkTracking', 'requireConsent', 'setConsentGiven'];
this is the order

@mattab mattab added this to the Current sprint milestone Mar 29, 2019
@tsteur
Copy link
Member

tsteur commented Mar 29, 2019

Looks good to merge. In general this should be ideally fixed in core though cause what this is showing is that all users that use getTracker/addTracker/getAsyncTracker have problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants