Skip to content

JS tracker: visitor cookie is set before configuration #14978

@ThomasWeinert

Description

@ThomasWeinert

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

Metadata

Metadata

Assignees

Labels

BugFor errors / faults / flaws / inconsistencies etc.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions