0

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 || [];
_paq.push(['setCustomVariable',  
    1, 
    "Visitor",
    "<?php
    if(isset($_SESSION['user'])){ // this is where I track my users
        echo  $_SESSION['user'];
    }?>", 
    "visit" 
    ]);
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "MySiteAdress";
    _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!

3 Answers3

0

The custom variable is set in a cookie that your are overwriting. If you clear cache/cookie you will see no issue.

Adrian
  • 546
  • 3
  • 7
0
_paq.push(['setCustomVariable',  
    1, 
    "Visitor",
    "<?php
    if(isset($_SESSION['user'])){ // this is where I track my users
        echo  $_SESSION['user'];
    }?>", 
    "visit" 
    ]);

You have set the 4th paramater (scope) to "visit". Maybe you want to try "page" instead and see if that's a good tracking plan for you?

James
  • 3,265
  • 4
  • 22
  • 28
0

Those guys obviously didn't read the question ^^

Yes, when you are tracking things and logged in as User X then log in as User Y on the same machine with the same browser, Piwik will update the records attributed to User X to be User Y... Since Piwik doesn't know you are logging in as different users, only that you are the same person on the same machine.

Joshua Smickus
  • 1,011
  • 10
  • 14