A quite lengthy but very straightforward description of the Kolab Groupware integration with Piwik Web Analytics.
The integration process is simpler than you think as the additional application (Piwik) is hosted externally and doesn’t use a 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.


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 a 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 the working directory.

# cd piwik

Configuration file

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

# cat config.inc.php.dist
// ownCloud URL
$rcmail_config['owncloud_url'] = 'https://owncloud.webmail.tld';

Rename config.inc.php.dist to config.inc.php, remove comments, modify the parameter name, and provide the desired URL address. I will use <a href="https://sleeplessbeastie.eu" rel="nofollow">https://sleeplessbeastie.eu</a> 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|https://sleeplessbeastie.eu|" config.inc.php

Verify applied modifications.

# cat config.inc.php
$rcmail_config['piwik_url'] = 'https://sleeplessbeastie.eu';


List localization files.

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

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 {} \;
$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
$labels = array();
$labels['piwik'] = 'Piwik';


Rename owncloud PHP script.

# mv owncloud.php piwik.php

Replace every owncloud occurrence 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.


Remove classic skin.

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

Rename the image displayed before the 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" />
<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" />
<body class="owncloud noscroll">
<roundcube:include file="/includes/header.html" />
<div id="mainscreen" class="uibox" style="overflow: hidden">
    <roundcube:object name="owncloudframe" />
<roundcube:include file="/includes/footer.html" />

Rename and modify the 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" />
<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" />
<body class="piwik noscroll">
<roundcube:include file="/includes/header.html" />
<div id="mainscreen" class="uibox" style="overflow: hidden">
    <roundcube:object name="piwikframe" />
<roundcube:include file="/includes/footer.html" />


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

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

Edit /usr/share/roundcubemail/config/main.inc.php file and add a 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 an empty response (white page).

Download the source code