This repository has been archived by the owner on Feb 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
piwik_tracking.php
56 lines (48 loc) · 1.81 KB
/
piwik_tracking.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<?php
/**
*
* piwik_tracking
*
* Bind piwik analytics script - based on: http://github.com/igloonet/roundcube_google_analytics
*
* @version 1.0 - 01.05.2014
* @author Martin Winter
*
**/
class piwik_tracking extends rcube_plugin {
function init () {
$this->load_config('config/config.inc.php');
$this->add_hook('render_page', array($this, 'add_script'));
}
function add_script ($args) {
$rcmail = rcmail::get_instance();
$exclude = array_flip($rcmail->config->get('piwik_tracking_exclude'));
if (isset($exclude[$args['template']]))
return $args;
if ($rcmail->config->get('piwik_tracking_privacy') and !empty($_SESSION['user_id']))
return $args;
if(!$rcmail->config->get('piwik_tracking_domain'))
return $args;
$script = '
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push([\'trackPageView\']);
_paq.push([\'enableLinkTracking\']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://' . $rcmail->config->get('piwik_tracking_domain') . '/";
_paq.push([\'setTrackerUrl\', u+\'piwik.php\']);
_paq.push([\'setSiteId\', ' . $rcmail->config->get('piwik_tracking_id') . ']);
var d=document, g=d.createElement(\'script\'), s=d.getElementsByTagName(\'script\')[0]; g.type=\'text/javascript\';
g.defer=true; g.async=true; g.src=u+\'piwik.js\'; s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img src="http://' . $rcmail->config->get('piwik_tracking_domain') . '/piwik.php?idsite=' . $rcmail->config->get('piwik_tracking_id') . '" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
';
// add script to end of page
$rcmail->output->add_footer($script);
return $args;
}
}
?>