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

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
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: 24876
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/en/ - 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: 24876
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/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

ruudjs
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Feb 14, 2012 8:40 am

Re: Matomo userID configuration

Post by ruudjs » Mon Dec 04, 2023 2:56 pm

Hi All, trying to figure out how to implement this solution - but without success - as indeed - the Matomo script goes before the </head>.
So how do you get this variable in the Matomo script?
Any clue is welcome

User avatar
AMurray
Joomla! Exemplar
Joomla! Exemplar
Posts: 9556
Joined: Sat Feb 13, 2010 7:35 am
Location: Australia

Re: Matomo userID configuration

Post by AMurray » Mon Dec 04, 2023 10:04 pm

There are plugins that can assist with that, such as https://extensions.joomla.org/extension ... ss-script/

If doing so manually it's not advisable to edit the index.php of the template, but perhaps you can do so on a child template, that is then not affected by core updates.

If using a template other than Cassioepia, it may have a "custom script" section in the template's configuration where you can place the Matomo code snippet.
Regards - A Murray

ruudjs
Joomla! Fledgling
Joomla! Fledgling
Posts: 3
Joined: Tue Feb 14, 2012 8:40 am

Re: Matomo userID configuration

Post by ruudjs » Wed Dec 06, 2023 10:17 am

Hi A Murray - thanks for your reply but I was not clear enough. Adding the javascript in the header is no problem - but how do you get the php variable in this script working.

_paq.push(['setUserId', '<?php echo $userid; ?>']);

Where do you declare this $userid - the header can not contain php but needs this variable for Matomo to work?
So where to put the "use Joomla\CMS\Factory; etc" code so it's variable is passed on to the header script?

gsmela
Joomla! Explorer
Joomla! Explorer
Posts: 281
Joined: Thu Jun 10, 2010 12:38 pm
Contact:

Re: Matomo userID configuration

Post by gsmela » Wed Dec 06, 2023 1:22 pm

Why not use the plugin Matomo docs point to specifically for this:

https://it-conserv.de/joomla/downloads/ ... mla-4.html


Post Reply

Return to “Joomla! 4.x Coding”