How to build a very simple Piwik plugin

For a simple Plugin example, you can have a look at the ExamplePlugin. The file contains two classes:

  • Piwik_ExamplePlugin which is the main Plugin file

It contains the global information about the plugin, and some generic methods such as getInformation(), install(), uninstall(), etc. View the Piwik_Plugin abstract class for more information about the methods you can implement in your main plugin file.

View the Piwik_ExamplePlugin class for a simple Plugin example.

  • Piwik_ExamplePlugin_Controller which is the Plugin Controller

The controller is the entry point when you go to ?module=YourPluginName&action=TheControllerMethodName. For example going to ?module=YourPlugin&action=printTest will execute the method printTest() of your class Piwik_YourPlugin_Controller.

View the Piwik_ExamplePlugin_Controller class for a Plugin Controller Example.

  • An optional Piwik_ExamplePlugin_API that your plugin can publish in a file API.php

This API can be used to request data from within other Piwik plugins or from outside, in other softwares, using the Piwik Web Services Architecture.

View the Piwik_ExamplePlugin_API class for an example of a Plugin publishing an API.

You call this API using the link in the page API reference: look for the Module ExamplePlugin section and click the links on the right.