Add an improved version of piwik_analytics.
This commit is contained in:
parent
d3d3a6e323
commit
c5fd4cd4a3
2 changed files with 127 additions and 0 deletions
44
plugins/piwik_analytics/config.inc.php.dist
Normal file
44
plugins/piwik_analytics/config.inc.php.dist
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
<?php
|
||||||
|
/* piwik site id */
|
||||||
|
$rcmail_config['piwik_analytics_id'] = 4;
|
||||||
|
|
||||||
|
/* domain of your piwik installation */
|
||||||
|
$rcmail_config['piwik_analytics_url'] = 'noc.kolabsys.com/piwik/';
|
||||||
|
|
||||||
|
/* exclude private pages - analytics will works only for non-logged users */
|
||||||
|
$rcmail_config['piwik_analytics_privacy'] = false;
|
||||||
|
|
||||||
|
/* exclude the following templates */
|
||||||
|
$rcmail_config['piwik_analytics_exclude'] = Array(
|
||||||
|
);
|
||||||
|
|
||||||
|
// Possible templates:
|
||||||
|
|
||||||
|
// "message",
|
||||||
|
// "messagepreview",
|
||||||
|
// "compose",
|
||||||
|
// "editidentity",
|
||||||
|
// "editcontact",
|
||||||
|
// "showcontact"
|
||||||
|
|
||||||
|
// "message",
|
||||||
|
// "messagepart",
|
||||||
|
// "messagepreview",
|
||||||
|
// "messageerror",
|
||||||
|
// "showcontact",
|
||||||
|
// "addcontact",
|
||||||
|
// "editcontact",
|
||||||
|
// "importcontacts",
|
||||||
|
// "addressbook",
|
||||||
|
// "compose",
|
||||||
|
// "editidentity",
|
||||||
|
// "error",
|
||||||
|
// "identities",
|
||||||
|
// "login",
|
||||||
|
// "mail",
|
||||||
|
// "managefolders",
|
||||||
|
// "plugin",
|
||||||
|
// "settingsedit",
|
||||||
|
// "settings"
|
||||||
|
|
||||||
|
?>
|
83
plugins/piwik_analytics/piwik_analytics.php
Normal file
83
plugins/piwik_analytics/piwik_analytics.php
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* piwik_analytics
|
||||||
|
*
|
||||||
|
* Bind piwik analytics script - based on: http://github.com/igloonet/roundcube_google_analytics
|
||||||
|
*
|
||||||
|
* @version 1.0 - 28. 11. 2010
|
||||||
|
* @author Florian Beer
|
||||||
|
* @modified_by Florian Beer
|
||||||
|
* @website http://blog.no-panic.at
|
||||||
|
* @licence GNU GPL
|
||||||
|
*
|
||||||
|
* Updated by Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
|
class piwik_analytics extends rcube_plugin
|
||||||
|
{
|
||||||
|
function init()
|
||||||
|
{
|
||||||
|
if (file_exists(dirname(__FILE__) . "/config.inc.php")) {
|
||||||
|
$this->load_config('config.inc.php');
|
||||||
|
} elseif (file_exists(dirname(__FILE__) . "/config.inc.php.dist")) {
|
||||||
|
$this->load_config('config.inc.php.dist');
|
||||||
|
} elseif (file_exists(dirname(__FILE__) . "/config/config.inc.php")) {
|
||||||
|
$this->load_config('config/config.inc.php');
|
||||||
|
} elseif (file_exists(dirname(__FILE__) . "/config/config.inc.php.dist")) {
|
||||||
|
$this->load_config('config/config.inc.php.dist');
|
||||||
|
/* } else {
|
||||||
|
error_log("Cannot find / load configuration for plugin piwik_analytics"); */
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->add_hook('render_page', array($this, 'add_script'));
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_script($args) {
|
||||||
|
$rcmail = rcmail::get_instance();
|
||||||
|
|
||||||
|
$exclude = $rcmail->config->get('piwik_analytics_exclude');
|
||||||
|
|
||||||
|
if (empty($exclude) || !is_array($exclude)) {
|
||||||
|
$exclude = Array();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($exclude[$args['template']])) {
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($rcmail->config->get('piwik_analytics_privacy', true)) {
|
||||||
|
if (!empty($_SESSION['user_id'])) {
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$rcmail->config->get('piwik_analytics_url', false)) {
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
|
||||||
|
$script = '
|
||||||
|
<!-- Piwik -->
|
||||||
|
<script type="text/javascript">
|
||||||
|
var pkBaseURL = (("https:" == document.location.protocol) ? "https://' . $rcmail->config->get('piwik_analytics_url') . '" : "http://' . $rcmail->config->get('piwik_analytics_url') . '");
|
||||||
|
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", ' . $rcmail->config->get('piwik_analytics_id') . ');
|
||||||
|
piwikTracker.trackPageView();
|
||||||
|
piwikTracker.enableLinkTracking();
|
||||||
|
} catch( err ) {}
|
||||||
|
</script><noscript><p><img src="http://' . $rcmail->config->get('piwik_analytics_url') . '/piwik.php?idsite=' . $rcmail->config->get('piwik_analytics_id') . '" style="border:0" alt="" /></p></noscript>
|
||||||
|
<!-- End Piwik Tag -->';
|
||||||
|
|
||||||
|
// add script to end of page
|
||||||
|
$rcmail->output->add_footer($script);
|
||||||
|
|
||||||
|
return $args;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
Loading…
Add table
Reference in a new issue