I have a wordpress site where I want to track logged in users.
I’m attempting to do this via the UserID in Piwik and I’ve added the following into the tracking script (after the line that says: var _paq = _paq || []; )
Figured this out by following the docs. Added this to my footer script:
<?php
global $current_user;
?>
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
<?php
// If used is logged-in then call 'setUserId'
// $userId variable must be set by the server when the user has successfully authenticated to your app.
if (isset($current_user->ID)) {
echo sprintf("_paq.push(['setUserId', '%s']);", $current_user->ID);
}
?>
//Set Any other custom variables here
</script>
If you are using Wordpress and want to use Piwik for tracking, then you don’t need to add any custom code for this.
You can just download the wp-Piwik plugin and activate it.
now login to your website/wp-admin and click on “wp-Piwik” from the settings menu.
now "Connect to Piwik tab and select Self-hosted(PHP API)
now you need to get the auth token from Piwik
for that just log in to Piwik and plateform->API then under “user authentication” copy the alphanumeric string, that is your auth key.
now in wp click on auto config checkbox and save.
now you can just “Enable Tracking”.