Cielito Lindo Productions

Discovering the beauty of God's creation | And it was very good

Koken and Piwik - tips on how to improve your setup

There are quite a few tutorials out there about how to integrate the open source analytics tool Piwik (which is in my opinion a pretty good alternative to Google analytics) into Koken and they are working fine.

Unfortunately they have the disadvantage that you can't see how much time a user spends on your site unless he moves between different pages. Instead of the specific time in your Piwik statistics you can only see a visiting time of 0 seconds in these casepleases.

But there's a trick on how to improve this. Just add the following line to your Piwik tracking code:


This line sends a heartbeat to Piwik so that Piwik knows that the visitor is still viewing the site. Per default the heartbeat is sent every 15 seconds.

In order to change this time just add instead the following line:

_paq.push(['enableHeartBeatTimer', 30]);

So as a summary the whole setup would be the following:

1. Open the admin panel of your koken installation

2. Go to the Store tab and install the HTML Injector plugin

3. Go to Settings -> Plugins page and click on the Edit button of the newly installed plugin

4. In the bottom area paste the code that you can find on your Piwik administration page under "Tracking code"

5. Add the above mentioned heartbeat-code under the line that includes the word "trackPageView" Please click here for a complete code sample or check the following screenshot.

6. (optionally) Open the developers view of your browser (or eg. Firebug on Firefox). Now on the network tab you should see that the Piwik code is reloading every eg. 15 seconds

8. Go to your Piwik installation page and check that your own visit now shows the real time

Please see this link if you wish more information about the Piwik heartbeat funtion.