How to get User ID inside a plugin


I’ve been reading the documentation and learning how to write plugins and finally got something to work today (sort of).

I’ve managed to add a User ID of email address to visitor profiles and I have some records with emails. Now I’d like to use this email address to add a Gravatar to the profile and replace the default image.

As a first step to making this plugin I’m just adding the same Gravatar image to each profile to see if I can at least replace the existing image with a new one that I’ve defined. This is working well.

However, now I’d like to capture the email address from the User ID field from the profile and feed it into my function addGravatar and assign it to the $email variable below. I can’t figure out how to look up the User ID for the record from within the plugin. Can anyone help me out with this? My code is below.


class MyPlugin extends \Piwik\Plugin
public function getListHooksRegistered()
return array(
‘Live.getExtraVisitorDetails’ => ‘addGravatar’

public function addGravatar(&$result)
    $email = '';
    $hash = md5( strtolower( $email ) );
    $base = '';
    $url = $base . $hash . '?s=120';
    $result['visitorAvatar'] = $url;



I actually answered my own question. Turns out you can just use $result[‘userId’] to get the value stored there. In my case it was email address.



I’ve tried this, but it seems it does not work in my case - i’m using the “Tracker.recordAction” Hook.
Would you please have a look here?:,126410