[Piwik-hackers] geoip plugin developement guidelines

Matthieu Aubry matthieu.aubry at gmail.com
Sun Jan 13 22:06:25 CET 2008



mikael letang wrote:
> Here under the main steps I understand to be followed for the geoip 
> plugin (or any plugin)
>
> 1) register data (log)
> 2) archive
> 3) display data
>
> 1) register data
> I understand that for performance matters, all data must be registered 
> during the loging process. That means that in our case, we need to add 
> localisation field such as "location_city" in the log table, and 
> populate it during the logging process. Besides the city, i think it 
> is also interesting to store the GPS coordinates, which are also 
> provided by the geoip library. (for later mapping for exemple).
> So there are two things to do:
> a) create the field(s) in the log_visit table.
> This must be done in the Plugin class (Geoip.php), in the function 
> install()
> b) populating the added fields during logging (i.e., when the user 
> visit a page).
> This logging logic is achieved in the Plugin class (Geoip.php), with 
> the help of a hook (which is a notification system). For exemple, in 
> Provider.php, the function "logProviderInfo" is registered as hook 
> function, and do the job of extracting the provider (from the ip, 
> provided by the notification object).
exactly
>
> 2) archive
> During the archiving process, the same system of hook allow to handle 
> the archiving of the data of our plugin. For exemple in Provider.php, 
> archiveMonth() and archiveDay() are registered to be called during the 
> archive process, and do the record creation (I think: data extraction 
> from log_visit table, in archiveDay(), and data extraction from daily 
> archive, in archiveMonth().
yes computing the statistics for a given field of the table log_visit is 
automatically handled with the helper function 
Piwik_ArchiveProcessing_Day::getDataTableInterestForLabel()
in your case it will compute the statistics (nb of visits, nb of 
actions, bounce rate, etc.) for any distinct value of the  location_city 
field automatically.

>
> 3) display data
> the Plugin/API.php (in our case, Geoip/API.php) is in charge of 
> reading the archives to be finally displayed. A lot of options in the 
> returned datatable object allows for modifications (in which i did not 
> dig yet)
yes.
currently the APIs are called withing the "Home" controller which 
displays all the reports in one page. You can see the calling code in 
/trunk/plugins/Home/Controller.php
But it will change very soon as we are working on a widget architecture 
for displaying all the data.

You've understood the global process perfectly. good luck with the plugin!


More information about the Piwik-hackers mailing list