UserId Woes :-(

I followed instructions to the letter at https://matomo.org/faq/tag-manager/how-do-i-set-the-user-id-using-matomo-tag-manager/#1-first-we-need-to-declare-the-matomo-tag-manager-data-layer-variable-in-our-website-with-the-following



  <!-- Matomo -->
<script>
  var _paq = window._paq = window._paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//www.mydomain.com/matomo/";
    _paq.push(['setTrackerUrl', u+'matomo.php']);
    _paq.push(['setSiteId', '3']);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
    g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

<!-- Matomo Tag Manager -->
<script>
var _mtm = window._mtm = window._mtm || [];
_mtm.push({'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'});
var userVar123 = 'userVar123';
_mtm.push({'uid':'userVar123' });
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src='https://www.mydomain.com/matomo/js/container_5Z3WE6XJ.js'; s.parentNode.insertBefore(g,s);
</script>
<!-- End Matomo Tag Manager -->

Of course… “mydomain” has the actual name of my domain

Above JS is within the tags

UserId doesn’t show up in “visits logs” → “view visitor profile”

& the “User IDs” in the “visitors section” says “There is no data for this report.”. I had tried moving the push for uid after the other code, as well, but same results :frowning:

p.s. ignore the userVar123: i added it because i wasn’t sure if it was a string or if it had to be a javascript variable. I couldn’t understand the documentation clearly… so just added it for testing.

The visits are getting logged… it is just the userIds which are missing

Any help please?

Thanks

Hi @vmds7777
I see several problemsin your configuration.

  1. Don’t use Matomo JavaScript bootstrap at the same time than MTM bootstrap. You have to choose if you do with JavaScript API or with MTM…
  2. For the userID, in the MTM configuration variable, you can set where the user ID comes from:

    In my case, you have also to define an MTM variable uid of type Data-Layer. This is the one you pushed in the MTM bootstrap script: _mtm.push({'uid':'userVar123' });

Thanks !

I will just stick to the javascript API. I included userId as per the documents for javascript API and it worked like a charm!

It will be nice if this part (using either Matomo tags, or the javascript API) can be explicitly mentioned in the documents to avoid confusion for users in the future :slight_smile: