This repository was archived by the owner on Jul 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathaction.php
131 lines (116 loc) · 3.45 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
if (!defined('DOKU_INC')) {
die();
}
if (!defined('DOKU_PLUGIN')) {
define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
}
/**
* Google Analytics for DokuWiki
*
* @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
* @author Terence J. Grant<tjgrant@tatewake.com>
*/
class action_plugin_googleanalytics extends DokuWiki_Action_Plugin
{
private $gaEnabled = true;
/**
* Register its handlers with the DokuWiki's event controller
*
* @param Doku_Event_Handler $controller
*/
public function register(Doku_Event_Handler $controller)
{
$controller->register_hook('DOKUWIKI_STARTED', 'AFTER', $this, 'gaConfig');
}
/**
* Initialize the Google Analytics config
*
* @param Doku_Event $event
* @param array $param
*/
public function gaConfig(Doku_Event $event, $param)
{
global $JSINFO;
global $INFO;
global $ACT;
if (!$this->gaEnabled) {
return;
}
$trackingId = $this->getConf('GAID');
$gtagId = $this->getConf('GTAGID');
if (!$trackingId && !$gtagId) {
return;
}
if ($this->getConf('dont_count_admin') && $INFO['isadmin']) {
return;
}
if ($this->getConf('dont_count_users') && $_SERVER['REMOTE_USER']) {
return;
}
act_clean($ACT);
$options = array();
if ($this->getConf('track_users') && $_SERVER['REMOTE_USER']) {
$options['userId'] = md5(auth_cookiesalt() . 'googleanalytics' . $_SERVER['REMOTE_USER']);
}
if ($this->getConf('domainName')) {
$options['cookieDomain'] = $this->getConf('domainName');
$options['legacyCookieDomain'] = $this->getConf('domainName');
}
global $conf;
$JSINFO['ga'] = array(
'trackingId' => $trackingId,
'gtagId' => $gtagId,
'anonymizeIp' => (bool) $this->getConf('anonymize'),
'action' => $ACT,
'trackOutboundLinks' => (bool) $this->getConf('track_links'),
'options' => $options,
'pageview' => $this->getPageView(),
'debug' => (bool) $conf['allowdebug']
);
}
/**
* normalize the pageview
*
* @return string
*/
protected function getPageView()
{
global $QUERY;
global $ID;
global $INPUT;
global $ACT;
// clean up parameters to log
$params = $_GET;
if (isset($params['do'])) {
unset($params['do']);
}
if (isset($params['id'])) {
unset($params['id']);
}
// decide on virtual views
if ($ACT == 'search') {
$view = '~search/';
$params['q'] = $QUERY;
} elseif ($ACT == 'admin') {
$page = $INPUT->str('page');
$view = '~admin';
if ($page) {
$view .= '/' . $page;
}
if (isset($params['page'])) {
unset($params['page']);
}
} else {
$view = str_replace(':', '/', $ID); // slashes needed for Content Drilldown
}
// prepend basedir, allows logging multiple dir based animals in one tracker
$view = DOKU_REL . $view;
// append query parameters
$query = http_build_query($params, '', '&');
if ($query) {
$view .= '?' . $query;
}
return $view;
}
}