Tracking Wordpress user ID with Tag Manager

I am just starting to dive into Tag Manager. I am using a small Wordpress installation for that. I changed the old piwik code for the Tag Manager code in the header. All works fine. However before I was able to track wordpress user ID’s via the Piwik plugin settings. I am not sure how do to the same via Tag Managers Matomo configuration.

Can someone help me out here?

Kind regards

Anyone willing to help me out here?

Hi Japhy,

what was the old code you used in the wordpress site to track the user ID’s?

Regards,
Peter

HI Peter,

<!-- Matomo -->
<script type="text/javascript">
  var _paq = _paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['setUserId', 'john']);
_paq.push(['trackPageView']);
  _paq.push(['trackAllContentImpressions']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u="//domain.com/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', '3']);
    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+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<!-- End Matomo Code -->

I was using wordpress plugin WP-Piwik 1.0.19

I suppose I have to pick a viariable here in the matomo config?

And I suppose somehow I have to use


_paq.push(['setUserId', 'john']);

But I am not a developer, just a user, it’s been quite a steep learning curve for me.

Hi,

The logged in user in Wordpress isn’t something that you can simply read via Javascript. You would need to modify Wordpress so it stores the username in a Javascript variable. (Which I think is what WP-Matomo does out of the box)

Maybe when @WP_PiwikDev or someone else has time to add Tag Manager support to WP-Matomo they could make it possible to set the User ID without the rest of the tracking code.

Hi Lukas, thanks so much for clearing that up for me. Much appreciated.

Hopefully someone adds support for TM in the future!

Hi there.

If you are using the Wordpress plugin, you can just enable the user tracking without changing the tracking code. Just have a look at WP-Matomo’s settings, tracking tab, and choose the user ID (mail address, WordPress user name, WP-User-ID, …) from the last select box shown there.

Afterwards WP-Matomo will set setUserId automatically.

1 Like

Hi,
I am not sure I follow. I already did that and it works perfectly. However the tracking code field in the wp-matomo plugin contains my matomo tracking code, not the matomo tag manager code. I would like to use user id with the tag manager tracking code.