If I understood the User-ID feature and the Piwik documentation on custom variables (JavaScript Tracking Client: API Reference - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3) right, this must be the correct code snippet for Wordpress user/login tracking:
<!-- Function to get the username from WordPress for Piwik User Tracking -->
<?php
global $current_user;
get_currentuserinfo();
$user_info = get_userdata(1);
$Username = $current_user->user_login;
?>
<!-- Piwik Code -->
<script type="text/javascript">
var _paq = _paq || [];
<!-- Piwik Custom Variable for User Tracking -->
<?php if (!empty($Username)) {echo "piwikTracker.setCustomVariable(1, 'Visitor', '".$Username."', 'visit');";} else {}?>
<!-- End Piwik Custom Variable for User Tracking -->
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://mydomain.com/";
_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);
})();
</script>
<noscript>
<!-- Piwik Image Tracker Fallback -->
<img src="http://mydomain.com/piwik.php?idsite=1&rec=1" style="border:0" alt="" />
<!-- End Piwik Image Tracker Fallback -->
</noscript>
<!-- End Piwik Code -->
But I can’t see any statistics for Wordpress users on my Piwik site. Who can help?