Matomo userID configuration Topic is solved

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Post Reply
lingeron
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Fri Feb 03, 2023 12:06 pm

Matomo userID configuration

Post by lingeron » Fri Feb 03, 2023 12:14 pm

Hi,

I'm trying to setup Matomo with Joomla's user id or email. But with no success.
I'm using the Matomo's java Tracking code in a Joomla plugin and added the following as instructed by Matomo help:

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

I then set a variable in Matomo to get the content of usedID and use it to track users by ID.
I understand that i have to populate userdID with Joomla's user id and i've tried a lot of attempts to do that that with no success. Mainly because i don't know where to put the code. I've inserted in the plugin above the Tracking script ... :)

So, any ideas please?

lingeron
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Fri Feb 03, 2023 12:06 pm

Re: Matomo userID configuration

Post by lingeron » Fri Feb 03, 2023 1:55 pm

UPDATE:

I've created a simple module that retrieves the joomla user id and i've pubished and can see the user id in the frontsite when log in.

testing Motomo i see whatever i change in HERE (_paq.push(['setUserId', 'HERE']);) it displays in real time tracking.
what i need is to replace HERE with the userID from the module.

Help?

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24226
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Matomo userID configuration

Post by pe7er » Fri Feb 03, 2023 2:48 pm

Welcome to Joomla forum!

Do you mean that you've coded a custom module yourself? Or used Joomla's Custom Module?
You cannot do that in Joomla's Custom HTML Module because it does not accept PHP code.

You could program a small Joomla 4 Module and add the following to get the User ID:

Code: Select all

use Joomla\CMS\Factory;
$userid = Factory::getApplication()->getIdentity()->id
And in your JavaScript code that you echo in this module, you could add the userid like this:

Code: Select all

_paq.push(['setUserId', '<?php echo $userid; ?>']);
However, the Matomo documentation instructs to add the Matomo JavaScript to the head of the HTML document.
To do that you could write a System Plugin to look for the </head> and add your JavaScript code just before that.
That's how I've implemented Matomo on my Joomla websites.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

lingeron
Joomla! Apprentice
Joomla! Apprentice
Posts: 8
Joined: Fri Feb 03, 2023 12:06 pm

Re: Matomo userID configuration

Post by lingeron » Fri Feb 03, 2023 4:30 pm

That indeed was a fabulous help!
Thank you very much

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24226
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Matomo userID configuration

Post by pe7er » Fri Feb 03, 2023 4:40 pm

You're welcome!
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com


Post Reply

Return to “Joomla! 4.x Coding”