@sgiehl opened this Issue on June 20th 2010 Member

I've developed a plugin (based on current trunk [2319]), which allows to track additional information about community users. It generates reports about:

  • usertype (user/guest) including evolution
  • users age-group
  • evolution of average age
  • gender (male, female, unknown) including evolution
  • user activity (list of the most active user)

It uses the setCustomData of the JS Tracker and takes currently three parameters:

  • userid - Unique identifier of an user (might be id or nickname) up to 100 chars
  • gender - Gender of user (might be 'F', 'M' or empty for unknown)
  • birthdate - Birthdate of user (in format YYYY-MM-DD)

Tracking the users information would work like this:

<script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", {$IDSITE});
var user = { 
      'userid' : 'ID-or-Nickname',
      'gender' : 'F',
      'birthdate': '1985-05-13'
piwikTracker.setCustomData( user );
} catch( err ) {}

If one of those parameters is tracked it will be saved or even updated in an later request within the same visit. For that the plugin extends the 'log_visit'-table within installation. Its adds three columns at the end of the table.

The plugin uses the translations and is available in english and german.

I'll attach some screenshots and the sourcecode.

Feel free to test, review and comment.
Suggestions for improvements or additional features are welcome ;)

Keywords: plugin, community

@sgiehl commented on June 20th 2010 Member

Attachment: plugin source code

@sgiehl commented on June 20th 2010 Member

Attachment: screenshot of age report

@sgiehl commented on June 20th 2010 Member

Attachment: screenshot of age report

@sgiehl commented on June 20th 2010 Member

Attachment: screenshot of gender report

@sgiehl commented on June 20th 2010 Member

Attachment: screenshot of gender report

@sgiehl commented on June 20th 2010 Member

Attachment: screenshot of useractivity report

@sgiehl commented on June 20th 2010 Member

Attachment: screenshot of usertype report

@sgiehl commented on July 26th 2010 Member

Attachment: new version using the hookable update function

@sgiehl commented on August 1st 2010 Member

Attachment: v 0.3 - fixed problem with averge age

@sgiehl commented on August 19th 2010 Member

Attachment: v 0.3 - fixed fatal occuring since 0.6.4; implemented getReportMetadata to make reports available for pdf plugin

@mattab commented on June 21st 2010 Member

This looks very interesting! This is a very interesting third party plugin.

The code is great, I have nothing to say (which is rare ;-))

One performance improvement could be to have the UPDATE done by the main piwik UPDATE (on log_visit table). If you want to submit a patch to have a hookable UPDATE please do so, I'll commit it to trunk.

If you are interested in contribute more to Piwik, you are very welcome! Great developers are not easy to find ;)

@sgiehl commented on June 21st 2010 Member

Thanks ;-)
If you want you can also integrate the plugin to core.

I will have a look at the mentioned improvement.

@sgiehl commented on June 22nd 2010 Member

I created a patch to make update hookable (see #1440). Already changed my plugin. Will upload changes here as soon as the patch is commited to trunk.

@mattab commented on June 29th 2010 Member

Patch #1440 is now committed to trunk.

@sgiehl commented on June 29th 2010 Member

Just added the new version. It now uses the hookable update and includes some small fixes.
Known "Bug":

  • Displaying the average age in a period other than day doesn't work.
    I'm looking for a way to calculate the average value for a given period. There isn't such a feature in the archive processing at the moment.
@anonymous-matomo-user commented on July 28th 2010

Vers. Piwik 6.4 / Community 0.2

Ich habe einige Websites und nur 1x ist der Code fr das Plugin im Trackingcode enthalten.
Wenn das Plugin aktiv ist wird nur noch die Seite in Piwik ausgewertet
die den var(user) code enthlt.
Gewertet wird aber auch erst ab dem Moment in dem dort in den enthaltenen Variablen
Daten drin stehen.
Ist das ein Fehler bei mir, oder allgemein so?

I have some websides and only 1x the code is included for the Plugin in the Trackingcode.
If the Plugin is active only the side is evaluated in Piwik
var (user) code includes.
But it is evaluated only from the moment in the contained variable
Data are in it.
Is this normaly?

Normaly Trackingcode

try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
} catch( err ) 

Community Trackingcode

try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 10);
var user = {  'userid' : '{$this->user->username}',  'gender' : ge,  'birthdate': '{$this->user->userOption12}' };
piwikTracker.setCustomData( user );
} catch( err ) { }
@sgiehl commented on July 28th 2010 Member

Dass die Community Daten nur ab dem Zeitpunkt ausgewertet werden knnen, ab dem der entsprechende Trackingcode eingebunden ist, ist nicht anders mglich, da zuvor ja auch keine Daten dafr gespeichert werden konnten. Was genau meinst du damit dass die Seiten auf denen noch der normale Trackingcode eingebunden ist nicht mehr ausgewertet werden? Zeigt nur das Community-Plugin keine Daten an, oder funktioniert die komplette Auswertung aller Daten bei dir nicht mehr?

It is only possible to display values after the extended tracking code has been included. Before no additional data has been saved. What do you mean with only the site where the extended tracking code is included evaluates? Does only the community plugin show no data for the rest, or is even the hole tracking not working?

@anonymous-matomo-user commented on July 28th 2010

Entschuldigung, war nicht ganz klar ausgedrckt
Sobald das Plugin aktiv ist werden die anderen
Seiten von PIWIK nicht mehr ausgewertet
Das das Plugin erst auswerten kann sobald Daten
vorhanden sind ist klar

Sorry, was not expressed clearly
As soon as the Plugin is active the others
Sides of PIWIK no more evaluated
The Plugin can only evaluate as soon as data are available is clear

@sgiehl commented on July 28th 2010 Member

Do you have access to the error logs. Are there any errors occuring?

@anonymous-matomo-user commented on July 28th 2010

There are no entries in the errorlog

@sgiehl commented on July 28th 2010 Member

hm... are the visitors still tracked? eg. are there new entries generated in the vistor_log table?

@anonymous-matomo-user commented on July 28th 2010

No, I have in log_visit no new entry with aktiv Community Plugin.
Because my Goals don't work any more since 6.4 it can be also a Piwikproblem what can be repaired in 6.5.
(With aktiv Goals the Rest of Piwik is working)

Unfortunately, I have installed your Plugin only with 6.4 and have no possibilities of comparison

I forgot to tell you: Great Plugin

@anonymous-matomo-user commented on August 16th 2010

Now the Plugin works (Piwik 0.9 / 0.3)

At first I had a installerror, DB-Fields without Null by userid and gender, and than I found
as soon as I have an entry in birtdate Piwik stops Tracking.
I have in my Community Mysqlfields with char(10) and date, both with yyyy-mm-dd at least
I tested your example code.
Do you have an idea what I'm doing wrong?

Could it bee that Action and Max Action has twisted data?

@anonymous-matomo-user commented on August 18th 2010

Now I have tested the Plugin with new installed older Piwikversions (without other Third Party Piwik Plugins).
With version 6.4 the Plugin working fine and from version 7 the mistake appears.

@sgiehl commented on August 19th 2010 Member

@bastelix: would you please try this new version, it should fix the problems.

@anonymous-matomo-user commented on December 23rd 2010

I have a problem...

If I have xampp unsecure, this plugin works perfectly, but.... If I have xampp secure all tracking doesnt work... :(

Anyone can help me????

@robocoder commented on December 23rd 2010 Contributor

What is "xampp secure"?

@sgiehl commented on December 23rd 2010 Member

Do you mean xampp running on https?

Well, could you please give some detailed information?
Which operating system are you running? And which version of xampp and piwik do you use?
Are any errors occuring in the error log?

@sgiehl commented on January 4th 2012 Member

Plugin might not work with newer versions of piwik. As custom variables are now implemented in piwik, plugin is no longer needed...

@anonymous-matomo-user commented on January 5th 2012

I have created workround in my piwik server , so we can "support" the Community plugin graphic Api :

1) Add the "old" 3 fields (userid,gender,birthdate) to the piwik_log_visit table , by installing the community plugin .

2) 3 custom variables were used to store the value of this plugin :

custom_var_k1 ='userid'

request example will look something like that :

3)To display the graphic presentation of the previous plugin (use the community folder) , i'm copying the date into the "OLD" data columns , using the following trigger :

create trigger Community_trigger
before insert on piwik_log_visit
for each row
IF NEW.custom_var_k1='userid' THEN SET NEW.userid = NEW.custom_var_v1 ;
IF NEW.custom_var_k2='gender' THEN SET NEW.gender = NEW.custom_var_v2 ;
IF NEW.custom_var_k3='birthdate' THEN SET NEW.birthdate = NEW.custom_var_v3 ;

So , we can use the grapgic API as before .

This Issue was closed on October 26th 2012
Powered by GitHub Issue Mirror