User_id tracking implementation

Hello all,

To track the user_id, what is your recommendation?

  1. Trigger only the datalayer when the user logged in
  2. Trigger the datalayer on every page where the user is logged in?

In the case of the solution 2: is possible to have a double counting issue?

Thks :slight_smile:


Both solutions are perfectly okay. The difference is that in the case of the first one, you need to write a short script. While in the case of the second one, you can use the toggle “Set a user ID” in the Piwik PRO tag and then put in the variable with the user ID.
Here is article: Set up a user ID | Piwik PRO help center

Whenever you send a user ID during one session, the previous value gets overwritten by the new one. There should not be an issue with double counting.


Hi @Oliwer_Kaczmarek ,

Thank you for the answer.

We chose the scenario 2.
We implemented it for GA4 through Piwik PRO TMS, not yet for Piwik but the process is similar.

The weird thing is that we have a double counting in GA4, so I would avoid the same story in Piwik…

<!-- Google tag (gtag.js) -->
<script async src=""></script>

 window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXXXX', { 
    'page_location': location.hostname + location.pathname + location.hash 

  // set user_id and user properties
  gtag('set', {'user_id': {{ DLV | User ID }}});
  gtag('set', {'user_properties': {
    'city': {{ DLV | City }},
     'country': {{ DLV | Country }},
    'language': {{ DLV | Language }},

Do you see something weird in this code that could explain the double counting?
I assume that the same code adapted for Piwik will have the same issue…

Many thanks,

Not sure why GA4 is double counting data as it’s not the tool I’m familiar with. The script doesn’t appear to have any visible bugs. When it comes to Piwik PRO, there should not be a problem with double counting.


Thank you for your answer :slight_smile: It confirms me in the fact to have chosen the good scenario

@Oliwer_Kaczmarek ,

Is it possible that Piwik trigger the tag twice in asynchronous way?
First the TMS load the GA4 tag, once is done, it sents a kind of notification to Piwik to trigger the user_id and user_properties?
So the tag is triggered twice

I see two requests in the dev tool:


In debug mode you can see how many times a tag is triggered on a page and what datalayer events went through. If it shows that the tag was fired multiple times than there might be an issue with the trigger.

in the debug, it is triggered one time, but I don’t understand in this case I see the tag twice in the dev tool.

If the GA have some API for checking what is the user id on the frontend than you could check if it’s empty before sending new one. in Piwik PRO we have:

_paq.push([function () {

Maybe Google have something similar that you could use to check if the value was already set.