forked from lgg42/piwikanalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
60 lines (51 loc) · 2.79 KB
/
plugin.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
57
58
59
60
<?php
class pluginMatomoAnalytics extends Plugin {
public function init()
{
$this->dbFields = [
'matomo-fqdn' => '',
'site-id' => '',
'token' => ''
];
}
public function form()
{
global $L;
$html = '<div>';
$html .= '<label for="jsmatomo-fqdn">'.$L->get('Matomo Server FQDN').'</label>';
$html .= '<input id="jsmatomo-fqdn" type="text" name="matomo-fqdn" value="'.$this->getValue('matomo-fqdn').'">';
$html .= '<div class="tip">'.$L->get('complete-this-field-with-the-matomo-server-fqdn').'</div>';
$html .= '</div>';
$html .= '<div>';
$html .= '<label for="jssite-id">'.$L->get('Matomo Site ID').'</label>';
$html .= '<input id="jssite-id" type="text" name="site-id" value="'.$this->getValue('site-id').'">';
$html .= '<div class="tip">'.$L->get('complete-this-field-with-the-matomo-site-id').'</div>';
$html .= '</div>';
return $html;
}
public function siteHead()
{
$html = PHP_EOL.'<!-- Matomo Analytics -->'.PHP_EOL;
$html .= '<script type="text/javascript">'.PHP_EOL;
$html .= 'var _paq = _paq || [];'.PHP_EOL;
$html .= '_paq.push([\'trackPageView\']);'.PHP_EOL;
$html .= '_paq.push([\'enableLinkTracking\']);'.PHP_EOL;
$html .= '(function() {'.PHP_EOL;
$html .= ' var u="//'.htmlentities($this->getValue('matomo-fqdn')).'/";'.PHP_EOL;
$html .= ' _paq.push([\'setTrackerUrl\', u+\'matomo.php\']);'.PHP_EOL;
$html .= ' _paq.push([\'setSiteId\', \''.htmlentities($this->getValue('site-id')).'\']);'.PHP_EOL;
$html .= ' var d=document, g=d.createElement(\'script\'), s=d.getElementsByTagName(\'script\')[0];'.PHP_EOL;
$html .= ' g.type=\'text/javascript\'; g.async=true; g.defer=true; g.src=u+\'matomo.js\'; s.parentNode.insertBefore(g,s);'.PHP_EOL;
$html .= '})();'.PHP_EOL.'</script>'.PHP_EOL;
$html .= '<!-- End Matomo Code -->'.PHP_EOL;
return $html;
}
public function siteBodyEnd()
{
$html = [];
$html[] = '<!-- Matomo Image Tracker-->';
$html[] = '<noscript><img referrerpolicy="no-referrer-when-downgrade" src="//'.htmlentities($this->getValue('matomo-fqdn')).'/matomo.php?idsite='.htmlentities($this->getValue('site-id')).'&rec=1" style="border:0" alt="" /></noscript>';
$html[] = '<!-- End Matomo -->';
return implode(PHP_EOL, $html);
}
}