wiki:PiwikServer

Version 15 (modified by chris, 5 years ago) (diff)

--

Piwik Web Stats

This page is to document the Piwik server that is to be installed on the DevelopmentServer, the install was done on ticket:160

Install

Download

cd /web/
mkdir piwik.transitionnetwork.org
cd piwik.transitionnetwork.org/
wget http://piwik.org/latest.zip
unzip latest.zip

Apache

Then set up apache, see /etc/apache2/sites-available/piwik.transitionnetwork.org and run the web installer and:

cd /web/piwik.transitionnetwork.org/piwik/
chown -R www-data:www-data tmp/
chown -R www-data:www-data config/

MySQL

Then a MySQL user and database was added using phpMyAdmin which ran the following SQL:

CREATE USER 'piwik'@'localhost' IDENTIFIED BY '********';
GRANT USAGE ON * . * TO 'piwik'@'localhost' IDENTIFIED BY '********' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0 ;
CREATE DATABASE IF NOT EXISTS `piwik` ;
GRANT ALL PRIVILEGES ON `piwik` . * TO 'piwik'@'localhost';

Tracking code

The installer suggested this JS tracking code, see the docs at http://piwik.org/docs/javascript-tracking/ :

<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.transitionnetwork.org.webarch.net/" : "http://piwik.transitionnetwork.org.webarch.net/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://piwik.transitionnetwork.org.webarch.net/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->

And this image tracking code:

<!-- Piwik Image Tracker -->
<img src="https://piwik.transitionnetwork.org.webarch.net/piwik.php?idsite=1&rec=1" style="border:0" alt="" />
<!-- End Piwik -->

The following parameters can also be passed to the image URL:

  • rec - (required) The parameter &rec=1 is required to force the request to be recorded
  • idsite - (required) Defines the Website ID being tracked
  • action_name - Defines the custom Page Title for this page view
  • idgoal - The request will trigger the given Goal
  • urlref - The Referrer URL: must be set to the referrer URL used before landing on the page containing the Image tracker. For example, in PHP this value is accessible via

$_SERVER['HTTP_REFERER']

  • revenue - Used with idgoal, defines the custom revenue for this conversion

Customise the logo:

cd /web/piwik.transitionnetwork.org/piwik
chown -R www-data:www-data themes/

Cron

Set up the crontab to automatically archive the reports:

crontab -u www-data -e

5 * * * * /web/piwik.transitionnetwork.org/piwik/misc/cron/archive.sh > /dev/null

GA Import and Python

For the Google Analytics data import we need Python 2.6 and we are running with Python 2.5.2, so following this:

aptitude build-dep python2.5 
cd /usr/local/src
wget http://www.python.org/ftp/python/2.6.7/Python-2.6.7.tgz
tar -zxvf Python-2.6.7.tgz
cd Python-2.6.7
./configure --with-threads --enable-shared
make
make install 

Requirements

The requirements are:

  • PHP version 5.1.3 or greater, We highly recommend using at least PHP 5.3 as it is much more memory efficient than previous PHP versions, we have: PHP 5.2.6-1+lenny10 with Suhosin-Patch 0.9.6.2 (cli), when the server is migrated to squeeze we will get a new php, it can wait till then.
  • MySQL version 4.1 or greater, we have 5.0.51a-24+lenny5-log
  • (enabled by default) PHP extension pdo and pdo_mysql, weh have these already installed and they are configured via /etc/php5/apache2/conf.d/pdo.ini and /etc/php5/apache2/conf.d/pdo_mysql.ini
  • PHP GD extension, installed already
  • Increase your PHP memory_limit value in your php.ini config file to be at least memory_limit = 128M, we have 256M already in /etc/php5/apache2/php.ini