Question about custom variable in Visitor Log

Hi everyone,

I’ve installed Piwik and was trying out the custom variable features to track individual users of my website when I noticed something in the Visitor Log.

For example…when I logged in as “User1” , Visitor Log is able to capture this user’s activities and set the custom variable as Visitor:User1, however when I switch to another username e.g “User2” using the same browser, somehow only the custom variable is replaced (in this case, User1 is replaced by User2). That is, there is no longer Visitor:User1, Visitor Log only shows Visitor:User2 and all the previous activities of User1 is now belong to User2.

So it looks like Visitor log will overwrite the custom variable whenever the IP(or when you are using the same browser? I’m not sure.) is the same, am I doing anything wrong? Or is this how it supposed to work?

Below is the code that I currently use to set my custom variable.

<script type="text/javascript"> 
  var _paq = _paq || [];
    if(isset($_SESSION['user'])){ // this is where i track my users
        echo  $_SESSION['user'];
  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "XYXYXYXYXXY";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 1]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
    g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);


Could anyone clarify this? Thanks in advance for your help!

By design, custom variables of “scope = ‘visit’” will be stored once per visit. See: Custom Variables Analytics - Analytics Platform - Matomo
If you want to store multiple values for a same variable, use scope = ‘page’

Yes, as Matt said, this is the design. I needed to track users with multiple accounts, so this is what I used: one variable with visit scope, and one with page scope I only set at sign up/log in. Then, from the Live API I request:


(customer_id is enclosed in - - because search is based on LIKE), and then add


(note the , in the beginning - means “OR”).

So, you get everything about this user if the visit scope variable matches, or a page scope variable matches. You end up with the full session, including the parts where he was logged in with another account.

Thanks a lot for the explanation guys!
Yeah it does make sense…