Track usernames in Wordpress


I’m wondering if there is a way to send current logged Wordpress username to Piwik and display it beside the ip address in the stats.

I need to see which users viewed a specific pages and which users downloaded a specific files.

Is it possible to accomplish that with custom variables?

(Matthieu Aubry) #2

yes, simply set the custom variable and inplace of the value call the wordpress php function to get the username


Thanks Matt, this is what I did. Actually it shows the field “User” in the Visitors Log (but not in the realtime visits on dashboard), but it’s empty.

<!-- Piwik --> 
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "" : "");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
1, // Index, the number from 1 to 5 where this Custom Variable name is stored
"User", // Name, the name of the variable, for example: Gender, VisitorType
"<?php echo $user->user_firstname . ' ' .  $user->user_lastname; ?>", // Value, for example: "Male", "Female" or "new", "engaged", "customer"
"visit" // Scope of the Custom Variable, "visit" means the Custom Variable applies to the current visit
} catch( err ) {}
</script><noscript><p><img src="" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->


Never mind, it works! I was echoing the wrong parameter in php.

Now, I see it in the Visitors Log, is it possible to view on a page (visited pages), which users opened them?


(ITfee) #5

Is the code below still working?

(ITfee) #6

Anyone who has the same issue should take a look here 301 Moved Permanently