Tracking Wordpress user ID with Tag Manager

(Japhy) #1

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

(Japhy) #2

Anyone willing to help me out here?

(Peter) #3

Hi Japhy,

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


(Japhy) #4

HI Peter,

<!-- Matomo -->
<script type="text/javascript">
  var _paq = _paq || [];
  /* tracker methods like "setCustomDimension" should be called before "trackPageView" */
  _paq.push(['setUserId', 'john']);
  (function() {
    var u="//";
    _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);
<!-- End Matomo Code -->

I was using wordpress plugin WP-Piwik 1.0.19

(Japhy) #5

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.

(Lukas Winkler) #6


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.

(Japhy) #7

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.

(Japhy) #9

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.