SetUserId will also create a new Visit


i’m trying to implement a pretty simple tracking, but as soon as i set an userId a new Visit is created. This is the code i’m using:

example code
<script type="text/javascript">
  var _paq = window._paq || [];


  (function() {
    _paq.push(['setTrackerUrl', '']);
    _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);

<div id="click-me" onclick="track('meow')">set user id</div>
<div id="click-me" onclick="track()">track without</div>

<script type="text/javascript">
    function track(id) {
      var _paq = window._paq || [];
      if (!!id && id.length > 0) {
        _paq.push(['setUserId', id]);

If i understand the documentation correct ( it should reuse the current visit and match it with he new userId

When a visitor connects to your website and is not logged-in (User ID is not set) then a visit is created. If the visitor then logs-in your website and has a User ID set then their existing visit will be re-used

I’ve found a couple of topics regarding this issue, but no answers/solutions.

Has anybody any Idea what i’m doing wrong?

Thanks in advance,

Okay, so apparently this behaviour is intended, even though the documentation states otherwise.
In Version 3.12 this should be fixed:

1 Like