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

JS tracker: visitor cookie is set before configuration #14978

Closed
ThomasWeinert opened this issue Oct 9, 2019 · 2 comments · Fixed by #15814
Closed

JS tracker: visitor cookie is set before configuration #14978

ThomasWeinert opened this issue Oct 9, 2019 · 2 comments · Fixed by #15814
Assignees
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Milestone

Comments

@ThomasWeinert
Copy link

The "_pk_id" cookie is set by the setSiteId() method before the setVisitorCookieTimeout() and setCookieNamePrefix() are executed. As a result it is not possible to change the prefix and lifetime for that cookie. The other cookies change with the the prefix and you will get a second id cookie sometimes.

Tracking Code example:

<!-- Matomo -->
<script type="text/javascript">
  var _paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['setCookieNamePrefix', 'stats']);
  _paq.push(['setVisitorCookieTimeout', '0']);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="https://matomo-dev/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '1']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

Call Stack:

matomo-visitor-cookie-set-before-prefix

@tsteur tsteur added the Bug For errors / faults / flaws / inconsistencies etc. label Oct 9, 2019
@tsteur
Copy link
Member

tsteur commented Oct 9, 2019

Thanks @ThomasWeinert

I can see how this is an issue.
For now fixed it for setVisitorCookieTimeout in #14980

With setCookieNamePrefix I'm not 100% sure if we can also fix it that way and don't have the time right now unfortunately. It's not only setting a name prefix but also fetching the customVariables and not sure if the custom variables can cause side effects and whether they are always loaded again.

@tsteur tsteur added this to the 4.0.0 milestone Oct 9, 2019
@ThomasWeinert
Copy link
Author

Thanks for the fast response. The timeout is the critical part.

As a workaround I load the matomo.js manually before the tracking code and call Matomo.addTracker();. Not perfect but it should do for now.

@tsteur tsteur self-assigned this Apr 15, 2020
@mattab mattab changed the title Visitor cookie is set before configuration. JS tracker: visitor cookie is set before configuration Sep 29, 2020
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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants