Kolab - How to integrate Piwik Web Analytics

Quite lengthy but very straightforward description of the Kolab Groupware integration with Piwik Web Analytics. Integration process is simpler than you think as the additional application (Piwik) is hosted externally, and doesn't use single sign-on.

This process can be used to quickly integrate any other web based application as it only requires simple modifications to the already existing code.

Preparations

Create kolab_plugins directory and enter it.

# cd
# mkdir kolab_plugins
# cd kolab_plugins

Download 8297464 commit of the roundcubemail-plugins-kolab.

I have chosen this version because it uses only simple iframe object.
# wget https://git.kolab.org/roundcubemail-plugins-kolab/snapshot/roundcubemail-plugins-kolab-8297464ab4273f5662f1ce47a0c75bf602494e8a.tar.gz

Extract downloaded archive, move and rename owncloud plugin to piwik, remove archive and extracted directory.

# tar xfz roundcubemail-plugins-kolab-8297464ab4273f5662f1ce47a0c75bf602494e8a.tar.gz
# mv roundcubemail-plugins-kolab-8297464ab4273f5662f1ce47a0c75bf602494e8a/plugins/owncloud piwik
# rm roundcubemail-plugins-kolab-8297464ab4273f5662f1ce47a0c75bf602494e8a.tar.gz
# rm -r roundcubemail-plugins-kolab-8297464ab4273f5662f1ce47a0c75bf602494e8a

Change working directory.

# cd piwik

Configuration file

Look at the config.inc.php.dist file.

# cat config.inc.php.dist 
<?php

// ownCloud URL
$rcmail_config['owncloud_url'] = 'https://owncloud.webmail.tld';

Rename config.inc.php.dist to config.inc.php, remove comment, modify parameter name, and provide desired URL address. I will use http://blog.sleeplessbeastie.eu as an example.

# mv config.inc.php.dist config.inc.php
# sed -i -e "/^\//d" config.inc.php
# sed -i -e "s|owncloud_url|piwik_url|" config.inc.php
# sed -i -e "s|https://owncloud.webmail.tld|http://blog.sleeplessbeastie.eu|" config.inc.php

Verify applied modifications.

# cat config.inc.php
<?php

$rcmail_config['piwik_url'] = 'http://blog.sleeplessbeastie.eu';

Localization

List localization files.

# find localization  -name *.inc | grep -v en_US
localization/ru_RU.inc
localization/fr_FR.inc
localization/es_ES.inc
localization/pl_PL.inc
localization/en_US.inc
localization/et_EE.inc
localization/nl_NL.inc
localization/ja_JP.inc
localization/de_DE.inc
localization/de_CH.inc

Remove unnecessary localization files (everything except en_US).

# find localization  -name *.inc | grep -v en_US | xargs rm

Look at the localization file.

# find localization  -name *.inc -exec cat {} \;
<?php

$labels = array();
$labels['owncloud'] = 'Files';

?>

Modify this file accordingly.

# sed -i -e "s|owncloud|piwik|" localization/en_US.inc
# sed -i -e "s|Files|Piwik|"    localization/en_US.inc 

Verify applied modifications.

# cat localization/en_US.inc 
<?php

$labels = array();
$labels['piwik'] = 'Piwik';

?>

Plugin

Rename owncloud PHP script.

# mv owncloud.php piwik.php

Replace every owncloud occurence with piwik.

# sed -i -e "s|owncloud|piwik|g" piwik.php 

Remove lines from 69 to 73 as you do not want to pass username and password.

$user = $_SESSION['kolab_uid']; // requires kolab_auth plugin
$pass = $rcmail->decrypt($_SESSION['password']);

$src = preg_replace('/^(https?:\/\/)/',
                    '\\1' . urlencode($user) . ':' . urlencode($pass) . '@', $src);
# sed -i -e "69,73d" piwik.php
Do not forget to remove these lines as this is was very important.

Skin

Remove classic skin.

# rm -r skins/classic
I removed classic theme but you should keep and modify it.

Rename image displayed before text link.

# mv skins/larry/{cloud.png,piwik.png}

Look at the style sheet.

# cat skins/larry/owncloud.css 
/***** ownCloud plugin styles *****/

#taskbar a.button-owncloud span.button-inner
{
  background: url(cloud.png) 5px 5px no-repeat;
  height: 14px;
}

#taskbar a.button-owncloud:hover span.button-inner,
#taskbar a.button-owncloud.button-selected span.button-inner
{
  background: url(cloud.png) 5px -16px no-repeat;
  height: 14px;
}

Rename and modify style sheet.

# mv skins/larry/{owncloud.css,piwik.css}
# sed -i -e "s|owncloud|piwik|g"      skins/larry/piwik.css
# sed -i -e "s|ownCloud|Piwik|g"      skins/larry/piwik.css
# sed -i -e "s|cloud.png|piwik.png|g" skins/larry/piwik.css

Verify style modifications.

# cat skins/larry/piwik.css 
/***** Piwik plugin styles *****/

#taskbar a.button-piwik span.button-inner
{
  background: url(piwik.png) 5px 5px no-repeat;
  height: 14px;
}

#taskbar a.button-piwik:hover span.button-inner,
#taskbar a.button-piwik.button-selected span.button-inner
{
  background: url(piwik.png) 5px -16px no-repeat;
  height: 14px;
}

Look at the template.

<roundcube:object name="doctype" value="html5" />
<html>
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
<link rel="stylesheet" type="text/css" href="/this/owncloud.css" />
<link rel="stylesheet" type="text/css" href="/settings.css" />
</head>
<body class="owncloud noscroll">

<roundcube:include file="/includes/header.html" />

<div id="mainscreen" class="uibox" style="overflow: hidden">
    <roundcube:object name="owncloudframe" />
</div>

<roundcube:include file="/includes/footer.html" />

</body>
</html>

Rename and modify template in the same way as before.

# mv skins/larry/templates/{owncloud.html,piwik.html}
# sed -i -e "s|owncloud|piwik|g" skins/larry/templates/piwik.html 

Verify template modifications.

# cat skins/larry/templates/piwik.html 
<roundcube:object name="doctype" value="html5" />
<html>
<head>
<title><roundcube:object name="pagetitle" /></title>
<roundcube:include file="/includes/links.html" />
<link rel="stylesheet" type="text/css" href="/this/piwik.css" />
<link rel="stylesheet" type="text/css" href="/settings.css" />
</head>
<body class="piwik noscroll">

<roundcube:include file="/includes/header.html" />

<div id="mainscreen" class="uibox" style="overflow: hidden">
    <roundcube:object name="piwikframe" />
</div>

<roundcube:include file="/includes/footer.html" />

</body>
</html>

Installation

Change working directory and copy piwik plugin to the following directory.

/usr/share/roundcubemail/plugins/
# cd ..
# cp -r piwik /usr/share/roundcubemail/plugins/

Edit /usr/share/roundcubemail/config/main.inc.php file and add plugin to the $rcmail_config['plugins'] array to enable it.

You can do it by hand or use the following command.

# sed -e "/'contextmenu',/a \\\t\t\t'piwik'," /usr/share/roundcubemail/config/main.inc.php
Read Piwik FAQ if you get empty response (white page).

Download the source code

roundcubemail_piwik.tgz

Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland https://sleeplessbeastie.eu