Hooks in Piwik

List of hooks

This hook is called when computing the archiving for a day. Useful for plugins that want to archive data.

Argument: object ArchiveProcessing_Day

This hook is called when computing the archiving for a period. Useful for plugins that want to archive data.

Argument: object ArchiveProcessing_Period

At every page view, this hook will be called. Useful for plugins that want to not count access for certain people (ie. IP excluding, Cookie excluding)

Argument: boolean $excluded if set to false, no statistics will be logged for this page

When a new visitor is being logged by Piwik, this hook is called. Useful for plugins that want to register new information about the visitor, or filter the existing information.

Argument: array $informationToSave containing pairs of name,value to be recorded in the log_visit table

Called a user visiting the Piwik interface or calling the API does not have the requested access.

Argument: The exception Piwik_Access_NoAccessException

Called when the configuration file couldn't be found, usually when Piwik was not installed yet.

Argument: The exception thrown

The plugin listening to this event must set an 'auth' entry in the Zend_Registry, that has the same interface as Piwik_Auth.

Argument: None

Called at the end of the InstallationController constructor. Useful for plugins that want to modify the installation process (adding steps, removing steps, etc.).

Argument: The object InstallationController

Useful for plugins that want to change the Installation controller using setControllerToLoad(). See the example of the OpenAds plugin to see how to customize the installation process.

Argument: The object InstallationController

Register an action for a given hook

If you want to listen to a specific event, and trigger your own function when this event is posted, you have to define a method getListHooksRegistered() in your plugin class, that will return an array containing pair of (hook name, method to call).

For example if you want to execute your function AddCityInformation() when a new visitor is recorded by Piwik (hook 'LogStats.newVisitorInformation'), in your class Piwik_MyPlugin you would define a method:

function getListHooksRegistered() 
{
    return array( 'LogStats.newVisitorInformation' => 'AddCityInformation' );
}

The hook LogStats.newVisitorInformation has an argument: an array containing the visitor's information. You can add new elements to this array. Example:

function AddCityInformation( $notification ) 
{
     // we get the argument by reference associated with the hook
     $visitorInfo =& $notification->getNotificationObject();
     // we modify the variable, adding the new city field
     $visitorInfo['city'] = 'Paris, France';
}

You can have a look at the provider plugin to see an example of a plugins registering actions for multiple hooks.

Add a new hook

Plugins can themselves post new events, the same way Piwik posts events.

 Piwik_PostEvent( $eventName,  [ $object , [ $info ]])