@ThomasWeinert opened this Issue on October 9th 2019

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 commented on October 9th 2019 Member

Thanks @ThomasWeinert

I can see how this is an issue.
For now fixed it for setVisitorCookieTimeout in https://github.com/matomo-org/matomo/pull/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.

@ThomasWeinert commented on October 10th 2019

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.

Powered by GitHub Issue Mirror