forked from tatewake/dokuwiki-plugin-googleanalytics
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
41 lines (36 loc) · 1.54 KB
/
action.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
if(!defined('DOKU_INC')) die();
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'action.php');
class action_plugin_googleanalytics extends DokuWiki_Action_Plugin {
/**
* return some info
*/
function getInfo(){
return array(
'author' => 'Terence J. Grant',
'email' => '[email protected]',
'date' => '2014-06-14',
'name' => 'Google Analytics Plugin',
'desc' => 'Plugin to embed your google analytics code for your site. Now updated to support the new Google Universal Analytics.',
'url' => 'https://www.dokuwiki.org/plugin:googleanalytics',
);
}
/**
* Register its handlers with the DokuWiki's event controller
*/
function register(&$controller) {
$controller->register_hook('TPL_METAHEADER_OUTPUT', 'BEFORE', $this, '_addHeaders');
}
function _addHeaders (&$event, $param) {
global $INFO;
if(!$this->getConf('GAID')) return;
if($this->getConf('dont_count_admin') && $INFO['isadmin']) return;
if($this->getConf('dont_count_users') && $_SERVER['REMOTE_USER']) return;
$event->data["script"][] = array (
"type" => "text/javascript",
"_data" => "(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', '". $this->getConf('GAID') ."');ga('send', 'pageview');"
);
}
}
?>