Track usernames in Wordpress


#1

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


#3

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) ? "https://mysite.com/intranet/piwik/" : "http://mysite.com/intranet/piwik/");
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);
piwikTracker.setCustomVariable(
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
);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://mysite.com/intranet/piwik/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->


#4

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?

Thanks


(ITfee) #5

Is the code below still working?


(ITfee) #6

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