-
Notifications
You must be signed in to change notification settings - Fork 6
/
plugin.php
41 lines (32 loc) · 1.15 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
<?php
class KokenGoogleAnalytics extends KokenPlugin {
function __construct()
{
$this->require_setup = true;
$this->register_hook('before_closing_head', 'render');
}
function render()
{
$gaSrcClassic = "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'";
$gaSrcWithDemographics = "('https:' == document.location.protocol ? 'https://' : 'http://') + 'stats.g.doubleclick.net/dc.js'";
$anonymize = $this->data->anonymize ? 'true' : 'false';
$gasrc = $this->data->demographics ? $gaSrcWithDemographics : $gaSrcClassic;
echo <<<OUT
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '{$this->data->tracking_id}']);
_gaq.push(['_trackPageview']);
_gaq.push(['_anonymizeIP', {$anonymize}]);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = {$gasrc};
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
// For themes that use pjax or turbolinks
$(window).on('page:change pjax:success', function() {
_gaq.push(['_trackPageview']);
});
</script>
OUT;
}
}