Version Description
Download this release
Release Info
Developer | joostdevalk |
Plugin | Google Analytics for WordPress by MonsterInsights |
Version | 2.5.3 |
Comparing to | |
See all releases |
Code changes from version 2.5.1 to 2.5.3
- googleanalytics.php +530 -538
- readme.txt +1 -1
googleanalytics.php
CHANGED
@@ -1,538 +1,530 @@
|
|
1 |
-
<?php
|
2 |
-
/*
|
3 |
-
Plugin Name: Google Analytics for WordPress
|
4 |
-
Plugin URI: http://www.joostdevalk.nl/wordpress/analytics/
|
5 |
-
Description: This plugin makes it simple to add Google Analytics with extra search engines and automatic clickout and download tracking to your WordPress blog.
|
6 |
-
Author: Joost de Valk
|
7 |
-
Version: 2.5.
|
8 |
-
Author URI: http://www.joostdevalk.nl/
|
9 |
-
License: GPL
|
10 |
-
|
11 |
-
Based on Rich Boakes' Analytics plugin: http://boakes.org/analytics
|
12 |
-
|
13 |
-
*/
|
14 |
-
|
15 |
-
$pluginpath = str_replace(str_replace('\\', '/', ABSPATH), get_settings('siteurl').'/', str_replace('\\', '/', dirname(__FILE__))).'/';
|
16 |
-
$uastring = "UA-00000-0";
|
17 |
-
|
18 |
-
/*
|
19 |
-
* Admin User Interface
|
20 |
-
*/
|
21 |
-
|
22 |
-
if ( ! class_exists( 'GA_Admin' ) ) {
|
23 |
-
|
24 |
-
class GA_Admin {
|
25 |
-
|
26 |
-
function add_config_page() {
|
27 |
-
global $wpdb;
|
28 |
-
if ( function_exists('add_submenu_page') ) {
|
29 |
-
add_submenu_page('plugins.php', 'Google Analytics for WordPress Configuration', 'Google Analytics', 9, basename(__FILE__), array('GA_Admin','config_page'));
|
30 |
-
}
|
31 |
-
} // end add_GA_config_page()
|
32 |
-
|
33 |
-
function config_page() {
|
34 |
-
global $dlextensions;
|
35 |
-
if ( isset($_POST['submit']) ) {
|
36 |
-
if (!current_user_can('manage_options')) die(__('You cannot edit the Google Analytics for WordPress options.'));
|
37 |
-
check_admin_referer('analyticspp-config');
|
38 |
-
$options['uastring'] = $_POST['uastring'];
|
39 |
-
|
40 |
-
if (isset($_POST['dlextensions']) && $_POST['dlextensions'] != "")
|
41 |
-
$options['dlextensions'] = strtolower($_POST['dlextensions']);
|
42 |
-
if (isset($_POST['dlprefix']) && $_POST['dlprefix'] != "")
|
43 |
-
$options['dlprefix'] = strtolower($_POST['dlprefix']);
|
44 |
-
|
45 |
-
if (isset($_POST['artprefix']) && $_POST['artprefix'] != "")
|
46 |
-
$options['artprefix'] = strtolower($_POST['artprefix']);
|
47 |
-
if (isset($_POST['comprefix']) && $_POST['comprefix'] != "")
|
48 |
-
$options['comprefix'] = strtolower($_POST['comprefix']);
|
49 |
-
if (isset($_POST['comautprefix']) && $_POST['comautprefix'] != "")
|
50 |
-
$options['comautprefix'] = strtolower($_POST['comautprefix']);
|
51 |
-
if (isset($_POST['blogrollprefix']) && $_POST['blogrollprefix'] != "")
|
52 |
-
$options['blogrollprefix'] = strtolower($_POST['blogrollprefix']);
|
53 |
-
if (isset($_POST['domainorurl']) && $_POST['domainorurl'] != "")
|
54 |
-
$options['domainorurl'] = $_POST['domainorurl'];
|
55 |
-
|
56 |
-
if (isset($_POST['extrase'])) {
|
57 |
-
$options['extrase'] = true;
|
58 |
-
} else {
|
59 |
-
$options['extrase'] = false;
|
60 |
-
}
|
61 |
-
|
62 |
-
if (isset($_POST['imagese'])) {
|
63 |
-
$options['imagese'] = true;
|
64 |
-
$options['extrase'] = true;
|
65 |
-
} else {
|
66 |
-
$options['imagese'] = false;
|
67 |
-
}
|
68 |
-
|
69 |
-
if (isset($_POST['trackoutbound'])) {
|
70 |
-
$options['trackoutbound'] = true;
|
71 |
-
} else {
|
72 |
-
$options['trackoutbound'] = false;
|
73 |
-
}
|
74 |
-
|
75 |
-
if (isset($_POST['admintracking'])) {
|
76 |
-
$options['admintracking'] = true;
|
77 |
-
} else {
|
78 |
-
$options['admintracking'] = false;
|
79 |
-
}
|
80 |
-
|
81 |
-
if (isset($_POST['trackadsense'])) {
|
82 |
-
$options['trackadsense'] = true;
|
83 |
-
} else {
|
84 |
-
$options['trackadsense'] = false;
|
85 |
-
}
|
86 |
-
|
87 |
-
if (isset($_POST['userv2'])) {
|
88 |
-
$options['userv2'] = true;
|
89 |
-
} else {
|
90 |
-
$options['userv2'] = false;
|
91 |
-
}
|
92 |
-
|
93 |
-
$opt = serialize($options);
|
94 |
-
update_option('GoogleAnalyticsPP', $opt);
|
95 |
-
}
|
96 |
-
$mulch = ($uastring=""?"##-#####-#":$uastring);
|
97 |
-
|
98 |
-
$opt = get_option('GoogleAnalyticsPP');
|
99 |
-
$options = unserialize($opt);
|
100 |
-
?>
|
101 |
-
<div class="wrap">
|
102 |
-
<script type="text/javascript">
|
103 |
-
function toggle_help(ele, ele2) {
|
104 |
-
var expl = document.getElementById(ele2);
|
105 |
-
if (expl.style.display == "block") {
|
106 |
-
expl.style.display = "none";
|
107 |
-
ele.innerHTML = "What's this?";
|
108 |
-
} else {
|
109 |
-
expl.style.display = "block";
|
110 |
-
ele.innerHTML = "Hide explanation";
|
111 |
-
}
|
112 |
-
}
|
113 |
-
</script>
|
114 |
-
<h2>Google Analytics for WordPress Configuration</h2>
|
115 |
-
<form action="" method="post" id="analytics-conf">
|
116 |
-
<table class="form-table" style="width:100%;">
|
117 |
-
<?php
|
118 |
-
if ( function_exists('wp_nonce_field') )
|
119 |
-
wp_nonce_field('analyticspp-config');
|
120 |
-
?>
|
121 |
-
<tr>
|
122 |
-
<th scope="row" style="width:400px;" valign="top">
|
123 |
-
<label for="uastring">Analytics User Account</label> <small><a href="#" onclick="javascript:toggle_help(this, 'expl');">What's this?</a></small>
|
124 |
-
</th>
|
125 |
-
<td>
|
126 |
-
<input id="uastring" name="uastring" type="text" size="20" maxlength="40" value="<?php echo $options['uastring']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;" /><br/>
|
127 |
-
<div id="expl" style="display:none;">
|
128 |
-
<h3>Explanation</h3>
|
129 |
-
<p>Google Analytics is a statistics service provided
|
130 |
-
free of charge by Google. This plugin simplifies
|
131 |
-
the process of including the <em>basic</em> Google
|
132 |
-
Analytics code in your blog, so you don't have to
|
133 |
-
edit any PHP. If you don't have a Google Analytics
|
134 |
-
account yet, you can get one at
|
135 |
-
<a href="https://www.google.com/analytics/home/">analytics.google.com</a>.</p>
|
136 |
-
|
137 |
-
<p>In the Google interface, when you "Add Website
|
138 |
-
Profile" you are shown a piece of JavaScript that
|
139 |
-
you are told to insert into the page, in that script is a
|
140 |
-
unique string that identifies the website you
|
141 |
-
just defined, that is your User Account string
|
142 |
-
(it's shown in <strong>bold</strong> in the example below).</p>
|
143 |
-
<tt><script type="text/javascript"><br/>
|
144 |
-
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
145 |
-
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
146 |
-
</script><br/>
|
147 |
-
<script type="text/javascript"><br/>
|
148 |
-
var pageTracker = _gat._getTracker("<strong><?php echo($mulch);?></strong>");<br/>
|
149 |
-
pageTracker._initData();<br/>
|
150 |
-
pageTracker._trackPageview();<br/>
|
151 |
-
</script></tt>
|
152 |
-
<p>Once you have entered your User Account String in
|
153 |
-
the box above your pages will be trackable by
|
154 |
-
Google Analytics.</p>
|
155 |
-
</div>
|
156 |
-
</td>
|
157 |
-
</tr>
|
158 |
-
<?php if ($options['trackoutbound']) { ?>
|
159 |
-
<tr>
|
160 |
-
<th scope="row" valign="top">
|
161 |
-
<label for="dlextensions">Extensions of files to track as downloads</label><br/>
|
162 |
-
<small>(If the extension is only two chars, prefix it with a dot, like '.js')</small>
|
163 |
-
</th>
|
164 |
-
<td>
|
165 |
-
<input type="text" name="dlextensions" size="40" value="<?php echo $options['dlextensions']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
166 |
-
</td>
|
167 |
-
</tr>
|
168 |
-
<tr>
|
169 |
-
<th scope="row" valign="top">
|
170 |
-
<label for="dlprefix">Prefix for tracked downloads</label>
|
171 |
-
</th>
|
172 |
-
<td>
|
173 |
-
<input type="text" id="dlprefix" name="dlprefix" size="40" value="<?php echo $options['dlprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
174 |
-
</td>
|
175 |
-
</tr>
|
176 |
-
<tr>
|
177 |
-
<th scope="row" valign="top">
|
178 |
-
<label for="artprefix">Prefix for outbound clicks from articles</label>
|
179 |
-
</th>
|
180 |
-
<td>
|
181 |
-
<input type="text" id="artprefix" name="artprefix" size="40" value="<?php echo $options['artprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
182 |
-
</td>
|
183 |
-
</tr>
|
184 |
-
<tr>
|
185 |
-
<th scope="row" valign="top">
|
186 |
-
<label for="comprefix">Prefix for outbound clicks from within comments</label>
|
187 |
-
</th>
|
188 |
-
<td>
|
189 |
-
<input type="text" id="comprefix" name="comprefix" size="40" value="<?php echo $options['comprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
190 |
-
</td>
|
191 |
-
</tr>
|
192 |
-
<tr>
|
193 |
-
<th scope="row" valign="top">
|
194 |
-
<label for="comautprefix">Prefix for outbound clicks from comment author links</label>
|
195 |
-
</th>
|
196 |
-
<td>
|
197 |
-
<input type="text" id="comautprefix" name="comautprefix" size="40" value="<?php echo $options['comautprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
198 |
-
</td>
|
199 |
-
</tr>
|
200 |
-
<tr>
|
201 |
-
<th scope="row" valign="top">
|
202 |
-
<label for="blogrollprefix">Prefix for outbound clicks from blogroll links</label>
|
203 |
-
</th>
|
204 |
-
<td>
|
205 |
-
<input type="text" id="blogrollprefix" name="blogrollprefix" size="40" value="<?php echo $options['blogrollprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
206 |
-
</td>
|
207 |
-
</tr>
|
208 |
-
<tr>
|
209 |
-
<th scope="row" valign="top">
|
210 |
-
<label for="domainorurl">Track full URL of outbound clicks or just the domain?</label>
|
211 |
-
</th>
|
212 |
-
<td>
|
213 |
-
<select name="domainorurl" id="domainorurl">
|
214 |
-
<option value="domain"<?php if ($options['domainorurl'] == 'domain') { echo ' selected="selected"';} ?>>Just the domain</option>
|
215 |
-
<option value="url"<?php if ($options['domainorurl'] == 'url') { echo ' selected="selected"';} ?>>Track the complete URL</option>
|
216 |
-
</select>
|
217 |
-
</td>
|
218 |
-
</tr>
|
219 |
-
<?php } ?>
|
220 |
-
<tr>
|
221 |
-
<th scope="row" valign="top">
|
222 |
-
<label for="trackoutbound">Track outbound clicks<br/>
|
223 |
-
& downloads</label>
|
224 |
-
</th>
|
225 |
-
<td>
|
226 |
-
<input type="checkbox" id="trackoutbound" name="trackoutbound" <?php if ($options['trackoutbound']) echo ' checked="checked" '; ?>/>
|
227 |
-
</td>
|
228 |
-
</tr>
|
229 |
-
<tr>
|
230 |
-
<th scope="row" valign="top">
|
231 |
-
<label for="trackadsense">Track AdSense clicks</label>
|
232 |
-
</th>
|
233 |
-
<td>
|
234 |
-
<input type="checkbox" id="trackadsense" name="trackadsense" <?php if ($options['trackadsense']) echo ' checked="checked" '; ?>/>
|
235 |
-
</td>
|
236 |
-
</tr>
|
237 |
-
<tr>
|
238 |
-
<th scope="row" valign="top">
|
239 |
-
<label for="extrase">Track extra Search Engines</label>
|
240 |
-
</th>
|
241 |
-
<td>
|
242 |
-
<input type="checkbox" id="extrase" name="extrase" <?php if ($options['extrase']) echo ' checked="checked" '; ?>/>
|
243 |
-
</td>
|
244 |
-
</tr>
|
245 |
-
<tr>
|
246 |
-
<th scope="row" valign="top">
|
247 |
-
<label for="admintracking">Track the administrator too</label><br/>
|
248 |
-
<small>(default is not to)</small>
|
249 |
-
</th>
|
250 |
-
<td>
|
251 |
-
<input type="checkbox" id="admintracking" name="admintracking" <?php if ($options['admintracking']) echo ' checked="checked" '; ?>/>
|
252 |
-
</td>
|
253 |
-
</tr>
|
254 |
-
<tr>
|
255 |
-
<th scope="row" valign="top">
|
256 |
-
<label for="userv2">I use Urchin too.</label>
|
257 |
-
</th>
|
258 |
-
<td>
|
259 |
-
<input type="checkbox" id="userv2" name="userv2" <?php if ($options['userv2']) echo ' checked="checked" '; ?>/>
|
260 |
-
</td>
|
261 |
-
</tr>
|
262 |
-
</table>
|
263 |
-
<p style="border:0;" class="submit"><input type="submit" name="submit" value="Update Settings »" /></p>
|
264 |
-
</form>
|
265 |
-
</div>
|
266 |
-
<?php
|
267 |
-
if (isset($options['uastring'])) {
|
268 |
-
if ($options['uastring'] == "") {
|
269 |
-
add_action('admin_footer', array('GA_Admin','warning'));
|
270 |
-
} else {
|
271 |
-
if (isset($_POST['submit'])) {
|
272 |
-
if ($_POST['uastring'] != $options['uastring'] ) {
|
273 |
-
add_action('admin_footer', array('GA_Admin','success'));
|
274 |
-
}
|
275 |
-
}
|
276 |
-
}
|
277 |
-
} else {
|
278 |
-
add_action('admin_footer', array('GA_Admin','warning'));
|
279 |
-
}
|
280 |
-
|
281 |
-
} // end config_page()
|
282 |
-
|
283 |
-
function restore_defaults() {
|
284 |
-
$options['dlextensions'] = 'doc,exe,.js,pdf,ppt,tgz,zip,xls';
|
285 |
-
$options['dlprefix'] = '/downloads';
|
286 |
-
$options['artprefix'] = '/outbound/article';
|
287 |
-
$options['comprefix'] = '/outbound/comment';
|
288 |
-
$options['comautprefix'] = '/outbound/commentauthor';
|
289 |
-
$options['blogrollprefix'] = '/outbound/blogroll';
|
290 |
-
$options['domainorurl'] = 'domain';
|
291 |
-
$options['userv2'] = false;
|
292 |
-
$options['extrase'] = false;
|
293 |
-
$options['imagese'] = false;
|
294 |
-
$options['trackoutbound'] = true;
|
295 |
-
$opt = serialize($options);
|
296 |
-
update_option('GoogleAnalyticsPP',$opt);
|
297 |
-
}
|
298 |
-
|
299 |
-
function success() {
|
300 |
-
echo "
|
301 |
-
<div id='analytics-warning' class='updated fade-ff0000'><p><strong>Congratulations! You have just activated Google Analytics.</p></div>
|
302 |
-
<style type='text/css'>
|
303 |
-
#adminmenu { margin-bottom: 7em; }
|
304 |
-
#analytics-warning { position: absolute; top: 7em; }
|
305 |
-
</style>";
|
306 |
-
} // end success()
|
307 |
-
|
308 |
-
function warning() {
|
309 |
-
echo "
|
310 |
-
<div id='analytics-warning' class='updated fade-ff0000'><p><strong>Google Analytics is not active.</strong> You must <a href='plugins.php?page=googleanalytics.php'>enter your UA String</a> for it to work.</p></div>
|
311 |
-
<style type='text/css'>
|
312 |
-
#adminmenu { margin-bottom: 6em; }
|
313 |
-
#analytics-warning { position: absolute; top: 7em; }
|
314 |
-
</style>";
|
315 |
-
} // end warning()
|
316 |
-
|
317 |
-
} // end class GA_Admin
|
318 |
-
|
319 |
-
} //endif
|
320 |
-
|
321 |
-
|
322 |
-
/**
|
323 |
-
* Code that actually inserts stuff into pages.
|
324 |
-
*/
|
325 |
-
if ( ! class_exists( 'GA_Filter' ) ) {
|
326 |
-
class GA_Filter {
|
327 |
-
|
328 |
-
/*
|
329 |
-
* Insert the tracking code into the page
|
330 |
-
*/
|
331 |
-
function spool_analytics() {
|
332 |
-
global $pluginpath;
|
333 |
-
|
334 |
-
$opt = get_option('GoogleAnalyticsPP');
|
335 |
-
$options = unserialize($opt);
|
336 |
-
|
337 |
-
if ($options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ) { ?>
|
338 |
-
<!-- Google Analytics for WordPress | http://www.joostdevalk.nl/wordpress/google-analytics/ -->
|
339 |
-
<script type="text/javascript">
|
340 |
-
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
341 |
-
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
342 |
-
</script>
|
343 |
-
<script type="text/javascript">
|
344 |
-
var pageTracker = _gat._getTracker("<?php echo $options["uastring"]; ?>");
|
345 |
-
</script>
|
346 |
-
<?php if ( $options["extrase"] == true ) {
|
347 |
-
echo("\t<script src=\"".$pluginpath."custom_se.js\" type=\"text/javascript\"></script>\n");
|
348 |
-
} ?>
|
349 |
-
<script type="text/javascript">
|
350 |
-
<?php if ( $options['userv2'] ) {
|
351 |
-
echo("\tpageTracker._setLocalRemoteServerMode();");
|
352 |
-
} ?>
|
353 |
-
pageTracker._initData();
|
354 |
-
<?php if (strpos($_SERVER['HTTP_REFERER'],"images.google") && strpos($_SERVER['HTTP_REFERER'],"&prev") && $options["imagese"]) { ?>
|
355 |
-
regex = new RegExp("images.google.([^\/]+).*&prev=([^&]+)");
|
356 |
-
var match = regex.exec(pageTracker.qa);
|
357 |
-
pageTracker.qa = "http://images.google." + match[1] + unescape(match[2]);
|
358 |
-
<?php } ?>
|
359 |
-
pageTracker._trackPageview();
|
360 |
-
</script>
|
361 |
-
<!-- End of Google Analytics code -->
|
362 |
-
<?php
|
363 |
-
}
|
364 |
-
}
|
365 |
-
|
366 |
-
function track_adsense() {
|
367 |
-
echo("\t<script src=\"".$pluginpath."adsense-track.js\" type=\"text/javascript\"></script>\n");
|
368 |
-
}
|
369 |
-
/* Create an array which contians:
|
370 |
-
* "domain" e.g. boakes.org
|
371 |
-
* "host" e.g. store.boakes.org
|
372 |
-
*/
|
373 |
-
function ga_get_domain($uri){
|
374 |
-
|
375 |
-
$hostPattern = "/^(http:\/\/)?([^\/]+)/i";
|
376 |
-
$domainPattern = "/[^\.\/]+\.[^\.\/]+$/";
|
377 |
-
|
378 |
-
preg_match($hostPattern, $uri, $matches);
|
379 |
-
$host = $matches[2];
|
380 |
-
preg_match($domainPattern, $host, $matches);
|
381 |
-
return array("domain"=>$matches[0],"host"=>$host);
|
382 |
-
|
383 |
-
}
|
384 |
-
|
385 |
-
function ga_parse_link($leaf, $matches){
|
386 |
-
global $origin ;
|
387 |
-
|
388 |
-
$opt = get_option('GoogleAnalyticsPP');
|
389 |
-
$options = unserialize($opt);
|
390 |
-
|
391 |
-
$target = GA_Filter::ga_get_domain($matches[3]);
|
392 |
-
$coolbit = "";
|
393 |
-
$extension = substr($matches[3],-3);
|
394 |
-
$dlextensions = split(",",$options['dlextensions']);
|
395 |
-
if ( $target["domain"] != $origin["domain"] ){
|
396 |
-
if ($options['domainorurl'] == "domain") {
|
397 |
-
$coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$leaf."/".$target["host"]."');\"";
|
398 |
-
} else if ($options['domainorurl'] == "url") {
|
399 |
-
$coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$leaf."/".$matches[2]."//".$matches[3]."');\"";
|
400 |
-
}
|
401 |
-
} else if ( in_array($extension, $dlextensions) && $target["domain"] == $origin["domain"] ) {
|
402 |
-
$file = str_replace($origin["domain"],"",$matches[3]);
|
403 |
-
$file = str_replace('www.',"",$file);
|
404 |
-
$coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$options['dlprefix'].$file."');\"";
|
405 |
-
}
|
406 |
-
return '<a href="' . $matches[2] . '//' . $matches[3] . '"' .
|
407 |
-
}
|
408 |
-
|
409 |
-
function ga_parse_article_link($matches){
|
410 |
-
$opt = get_option('GoogleAnalyticsPP');
|
411 |
-
$options = unserialize($opt);
|
412 |
-
return GA_Filter::ga_parse_link($options['artprefix'],$matches);
|
413 |
-
}
|
414 |
-
|
415 |
-
function ga_parse_comment_link($matches){
|
416 |
-
$opt = get_option('GoogleAnalyticsPP');
|
417 |
-
$options = unserialize($opt);
|
418 |
-
return GA_Filter::ga_parse_link($options['comprefix'],$matches);
|
419 |
-
}
|
420 |
-
|
421 |
-
function the_content($text) {
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
$
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
$
|
493 |
-
$
|
494 |
-
$
|
495 |
-
|
496 |
-
$
|
497 |
-
|
498 |
-
|
499 |
-
$options['
|
500 |
-
$options['
|
501 |
-
$options['
|
502 |
-
$options['
|
503 |
-
$
|
504 |
-
|
505 |
-
|
506 |
-
$options
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
if ($options['
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
// adds the footer so the javascript is loaded
|
533 |
-
add_action('wp_head', array('GA_Filter','spool_analytics'));
|
534 |
-
|
535 |
-
if ($options['trackadsense']) {
|
536 |
-
add_action('wp_footer', array('GA_Filter','track_adsense'));
|
537 |
-
}
|
538 |
-
?>
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: Google Analytics for WordPress
|
4 |
+
Plugin URI: http://www.joostdevalk.nl/wordpress/analytics/
|
5 |
+
Description: This plugin makes it simple to add Google Analytics with extra search engines and automatic clickout and download tracking to your WordPress blog.
|
6 |
+
Author: Joost de Valk
|
7 |
+
Version: 2.5.3
|
8 |
+
Author URI: http://www.joostdevalk.nl/
|
9 |
+
License: GPL
|
10 |
+
|
11 |
+
Based on Rich Boakes' Analytics plugin: http://boakes.org/analytics
|
12 |
+
|
13 |
+
*/
|
14 |
+
|
15 |
+
$pluginpath = str_replace(str_replace('\\', '/', ABSPATH), get_settings('siteurl').'/', str_replace('\\', '/', dirname(__FILE__))).'/';
|
16 |
+
$uastring = "UA-00000-0";
|
17 |
+
|
18 |
+
/*
|
19 |
+
* Admin User Interface
|
20 |
+
*/
|
21 |
+
|
22 |
+
if ( ! class_exists( 'GA_Admin' ) ) {
|
23 |
+
|
24 |
+
class GA_Admin {
|
25 |
+
|
26 |
+
function add_config_page() {
|
27 |
+
global $wpdb;
|
28 |
+
if ( function_exists('add_submenu_page') ) {
|
29 |
+
add_submenu_page('plugins.php', 'Google Analytics for WordPress Configuration', 'Google Analytics', 9, basename(__FILE__), array('GA_Admin','config_page'));
|
30 |
+
}
|
31 |
+
} // end add_GA_config_page()
|
32 |
+
|
33 |
+
function config_page() {
|
34 |
+
global $dlextensions;
|
35 |
+
if ( isset($_POST['submit']) ) {
|
36 |
+
if (!current_user_can('manage_options')) die(__('You cannot edit the Google Analytics for WordPress options.'));
|
37 |
+
check_admin_referer('analyticspp-config');
|
38 |
+
$options['uastring'] = $_POST['uastring'];
|
39 |
+
|
40 |
+
if (isset($_POST['dlextensions']) && $_POST['dlextensions'] != "")
|
41 |
+
$options['dlextensions'] = strtolower($_POST['dlextensions']);
|
42 |
+
if (isset($_POST['dlprefix']) && $_POST['dlprefix'] != "")
|
43 |
+
$options['dlprefix'] = strtolower($_POST['dlprefix']);
|
44 |
+
|
45 |
+
if (isset($_POST['artprefix']) && $_POST['artprefix'] != "")
|
46 |
+
$options['artprefix'] = strtolower($_POST['artprefix']);
|
47 |
+
if (isset($_POST['comprefix']) && $_POST['comprefix'] != "")
|
48 |
+
$options['comprefix'] = strtolower($_POST['comprefix']);
|
49 |
+
if (isset($_POST['comautprefix']) && $_POST['comautprefix'] != "")
|
50 |
+
$options['comautprefix'] = strtolower($_POST['comautprefix']);
|
51 |
+
if (isset($_POST['blogrollprefix']) && $_POST['blogrollprefix'] != "")
|
52 |
+
$options['blogrollprefix'] = strtolower($_POST['blogrollprefix']);
|
53 |
+
if (isset($_POST['domainorurl']) && $_POST['domainorurl'] != "")
|
54 |
+
$options['domainorurl'] = $_POST['domainorurl'];
|
55 |
+
|
56 |
+
if (isset($_POST['extrase'])) {
|
57 |
+
$options['extrase'] = true;
|
58 |
+
} else {
|
59 |
+
$options['extrase'] = false;
|
60 |
+
}
|
61 |
+
|
62 |
+
if (isset($_POST['imagese'])) {
|
63 |
+
$options['imagese'] = true;
|
64 |
+
$options['extrase'] = true;
|
65 |
+
} else {
|
66 |
+
$options['imagese'] = false;
|
67 |
+
}
|
68 |
+
|
69 |
+
if (isset($_POST['trackoutbound'])) {
|
70 |
+
$options['trackoutbound'] = true;
|
71 |
+
} else {
|
72 |
+
$options['trackoutbound'] = false;
|
73 |
+
}
|
74 |
+
|
75 |
+
if (isset($_POST['admintracking'])) {
|
76 |
+
$options['admintracking'] = true;
|
77 |
+
} else {
|
78 |
+
$options['admintracking'] = false;
|
79 |
+
}
|
80 |
+
|
81 |
+
if (isset($_POST['trackadsense'])) {
|
82 |
+
$options['trackadsense'] = true;
|
83 |
+
} else {
|
84 |
+
$options['trackadsense'] = false;
|
85 |
+
}
|
86 |
+
|
87 |
+
if (isset($_POST['userv2'])) {
|
88 |
+
$options['userv2'] = true;
|
89 |
+
} else {
|
90 |
+
$options['userv2'] = false;
|
91 |
+
}
|
92 |
+
|
93 |
+
$opt = serialize($options);
|
94 |
+
update_option('GoogleAnalyticsPP', $opt);
|
95 |
+
}
|
96 |
+
$mulch = ($uastring=""?"##-#####-#":$uastring);
|
97 |
+
|
98 |
+
$opt = get_option('GoogleAnalyticsPP');
|
99 |
+
$options = unserialize($opt);
|
100 |
+
?>
|
101 |
+
<div class="wrap">
|
102 |
+
<script type="text/javascript">
|
103 |
+
function toggle_help(ele, ele2) {
|
104 |
+
var expl = document.getElementById(ele2);
|
105 |
+
if (expl.style.display == "block") {
|
106 |
+
expl.style.display = "none";
|
107 |
+
ele.innerHTML = "What's this?";
|
108 |
+
} else {
|
109 |
+
expl.style.display = "block";
|
110 |
+
ele.innerHTML = "Hide explanation";
|
111 |
+
}
|
112 |
+
}
|
113 |
+
</script>
|
114 |
+
<h2>Google Analytics for WordPress Configuration</h2>
|
115 |
+
<form action="" method="post" id="analytics-conf">
|
116 |
+
<table class="form-table" style="width:100%;">
|
117 |
+
<?php
|
118 |
+
if ( function_exists('wp_nonce_field') )
|
119 |
+
wp_nonce_field('analyticspp-config');
|
120 |
+
?>
|
121 |
+
<tr>
|
122 |
+
<th scope="row" style="width:400px;" valign="top">
|
123 |
+
<label for="uastring">Analytics User Account</label> <small><a href="#" onclick="javascript:toggle_help(this, 'expl');">What's this?</a></small>
|
124 |
+
</th>
|
125 |
+
<td>
|
126 |
+
<input id="uastring" name="uastring" type="text" size="20" maxlength="40" value="<?php echo $options['uastring']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;" /><br/>
|
127 |
+
<div id="expl" style="display:none;">
|
128 |
+
<h3>Explanation</h3>
|
129 |
+
<p>Google Analytics is a statistics service provided
|
130 |
+
free of charge by Google. This plugin simplifies
|
131 |
+
the process of including the <em>basic</em> Google
|
132 |
+
Analytics code in your blog, so you don't have to
|
133 |
+
edit any PHP. If you don't have a Google Analytics
|
134 |
+
account yet, you can get one at
|
135 |
+
<a href="https://www.google.com/analytics/home/">analytics.google.com</a>.</p>
|
136 |
+
|
137 |
+
<p>In the Google interface, when you "Add Website
|
138 |
+
Profile" you are shown a piece of JavaScript that
|
139 |
+
you are told to insert into the page, in that script is a
|
140 |
+
unique string that identifies the website you
|
141 |
+
just defined, that is your User Account string
|
142 |
+
(it's shown in <strong>bold</strong> in the example below).</p>
|
143 |
+
<tt><script type="text/javascript"><br/>
|
144 |
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
145 |
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
146 |
+
</script><br/>
|
147 |
+
<script type="text/javascript"><br/>
|
148 |
+
var pageTracker = _gat._getTracker("<strong><?php echo($mulch);?></strong>");<br/>
|
149 |
+
pageTracker._initData();<br/>
|
150 |
+
pageTracker._trackPageview();<br/>
|
151 |
+
</script></tt>
|
152 |
+
<p>Once you have entered your User Account String in
|
153 |
+
the box above your pages will be trackable by
|
154 |
+
Google Analytics.</p>
|
155 |
+
</div>
|
156 |
+
</td>
|
157 |
+
</tr>
|
158 |
+
<?php if ($options['trackoutbound']) { ?>
|
159 |
+
<tr>
|
160 |
+
<th scope="row" valign="top">
|
161 |
+
<label for="dlextensions">Extensions of files to track as downloads</label><br/>
|
162 |
+
<small>(If the extension is only two chars, prefix it with a dot, like '.js')</small>
|
163 |
+
</th>
|
164 |
+
<td>
|
165 |
+
<input type="text" name="dlextensions" size="40" value="<?php echo $options['dlextensions']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
166 |
+
</td>
|
167 |
+
</tr>
|
168 |
+
<tr>
|
169 |
+
<th scope="row" valign="top">
|
170 |
+
<label for="dlprefix">Prefix for tracked downloads</label>
|
171 |
+
</th>
|
172 |
+
<td>
|
173 |
+
<input type="text" id="dlprefix" name="dlprefix" size="40" value="<?php echo $options['dlprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
174 |
+
</td>
|
175 |
+
</tr>
|
176 |
+
<tr>
|
177 |
+
<th scope="row" valign="top">
|
178 |
+
<label for="artprefix">Prefix for outbound clicks from articles</label>
|
179 |
+
</th>
|
180 |
+
<td>
|
181 |
+
<input type="text" id="artprefix" name="artprefix" size="40" value="<?php echo $options['artprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
182 |
+
</td>
|
183 |
+
</tr>
|
184 |
+
<tr>
|
185 |
+
<th scope="row" valign="top">
|
186 |
+
<label for="comprefix">Prefix for outbound clicks from within comments</label>
|
187 |
+
</th>
|
188 |
+
<td>
|
189 |
+
<input type="text" id="comprefix" name="comprefix" size="40" value="<?php echo $options['comprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
190 |
+
</td>
|
191 |
+
</tr>
|
192 |
+
<tr>
|
193 |
+
<th scope="row" valign="top">
|
194 |
+
<label for="comautprefix">Prefix for outbound clicks from comment author links</label>
|
195 |
+
</th>
|
196 |
+
<td>
|
197 |
+
<input type="text" id="comautprefix" name="comautprefix" size="40" value="<?php echo $options['comautprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
198 |
+
</td>
|
199 |
+
</tr>
|
200 |
+
<tr>
|
201 |
+
<th scope="row" valign="top">
|
202 |
+
<label for="blogrollprefix">Prefix for outbound clicks from blogroll links</label>
|
203 |
+
</th>
|
204 |
+
<td>
|
205 |
+
<input type="text" id="blogrollprefix" name="blogrollprefix" size="40" value="<?php echo $options['blogrollprefix']; ?>" style="font-family: 'Courier New', Courier, mono; font-size: 1.5em;"/>
|
206 |
+
</td>
|
207 |
+
</tr>
|
208 |
+
<tr>
|
209 |
+
<th scope="row" valign="top">
|
210 |
+
<label for="domainorurl">Track full URL of outbound clicks or just the domain?</label>
|
211 |
+
</th>
|
212 |
+
<td>
|
213 |
+
<select name="domainorurl" id="domainorurl">
|
214 |
+
<option value="domain"<?php if ($options['domainorurl'] == 'domain') { echo ' selected="selected"';} ?>>Just the domain</option>
|
215 |
+
<option value="url"<?php if ($options['domainorurl'] == 'url') { echo ' selected="selected"';} ?>>Track the complete URL</option>
|
216 |
+
</select>
|
217 |
+
</td>
|
218 |
+
</tr>
|
219 |
+
<?php } ?>
|
220 |
+
<tr>
|
221 |
+
<th scope="row" valign="top">
|
222 |
+
<label for="trackoutbound">Track outbound clicks<br/>
|
223 |
+
& downloads</label>
|
224 |
+
</th>
|
225 |
+
<td>
|
226 |
+
<input type="checkbox" id="trackoutbound" name="trackoutbound" <?php if ($options['trackoutbound']) echo ' checked="checked" '; ?>/>
|
227 |
+
</td>
|
228 |
+
</tr>
|
229 |
+
<tr>
|
230 |
+
<th scope="row" valign="top">
|
231 |
+
<label for="trackadsense">Track AdSense clicks</label>
|
232 |
+
</th>
|
233 |
+
<td>
|
234 |
+
<input type="checkbox" id="trackadsense" name="trackadsense" <?php if ($options['trackadsense']) echo ' checked="checked" '; ?>/>
|
235 |
+
</td>
|
236 |
+
</tr>
|
237 |
+
<tr>
|
238 |
+
<th scope="row" valign="top">
|
239 |
+
<label for="extrase">Track extra Search Engines</label>
|
240 |
+
</th>
|
241 |
+
<td>
|
242 |
+
<input type="checkbox" id="extrase" name="extrase" <?php if ($options['extrase']) echo ' checked="checked" '; ?>/>
|
243 |
+
</td>
|
244 |
+
</tr>
|
245 |
+
<tr>
|
246 |
+
<th scope="row" valign="top">
|
247 |
+
<label for="admintracking">Track the administrator too</label><br/>
|
248 |
+
<small>(default is not to)</small>
|
249 |
+
</th>
|
250 |
+
<td>
|
251 |
+
<input type="checkbox" id="admintracking" name="admintracking" <?php if ($options['admintracking']) echo ' checked="checked" '; ?>/>
|
252 |
+
</td>
|
253 |
+
</tr>
|
254 |
+
<tr>
|
255 |
+
<th scope="row" valign="top">
|
256 |
+
<label for="userv2">I use Urchin too.</label>
|
257 |
+
</th>
|
258 |
+
<td>
|
259 |
+
<input type="checkbox" id="userv2" name="userv2" <?php if ($options['userv2']) echo ' checked="checked" '; ?>/>
|
260 |
+
</td>
|
261 |
+
</tr>
|
262 |
+
</table>
|
263 |
+
<p style="border:0;" class="submit"><input type="submit" name="submit" value="Update Settings »" /></p>
|
264 |
+
</form>
|
265 |
+
</div>
|
266 |
+
<?php
|
267 |
+
if (isset($options['uastring'])) {
|
268 |
+
if ($options['uastring'] == "") {
|
269 |
+
add_action('admin_footer', array('GA_Admin','warning'));
|
270 |
+
} else {
|
271 |
+
if (isset($_POST['submit'])) {
|
272 |
+
if ($_POST['uastring'] != $options['uastring'] ) {
|
273 |
+
add_action('admin_footer', array('GA_Admin','success'));
|
274 |
+
}
|
275 |
+
}
|
276 |
+
}
|
277 |
+
} else {
|
278 |
+
add_action('admin_footer', array('GA_Admin','warning'));
|
279 |
+
}
|
280 |
+
|
281 |
+
} // end config_page()
|
282 |
+
|
283 |
+
function restore_defaults() {
|
284 |
+
$options['dlextensions'] = 'doc,exe,.js,pdf,ppt,tgz,zip,xls';
|
285 |
+
$options['dlprefix'] = '/downloads';
|
286 |
+
$options['artprefix'] = '/outbound/article';
|
287 |
+
$options['comprefix'] = '/outbound/comment';
|
288 |
+
$options['comautprefix'] = '/outbound/commentauthor';
|
289 |
+
$options['blogrollprefix'] = '/outbound/blogroll';
|
290 |
+
$options['domainorurl'] = 'domain';
|
291 |
+
$options['userv2'] = false;
|
292 |
+
$options['extrase'] = false;
|
293 |
+
$options['imagese'] = false;
|
294 |
+
$options['trackoutbound'] = true;
|
295 |
+
$opt = serialize($options);
|
296 |
+
update_option('GoogleAnalyticsPP',$opt);
|
297 |
+
}
|
298 |
+
|
299 |
+
function success() {
|
300 |
+
echo "
|
301 |
+
<div id='analytics-warning' class='updated fade-ff0000'><p><strong>Congratulations! You have just activated Google Analytics.</p></div>
|
302 |
+
<style type='text/css'>
|
303 |
+
#adminmenu { margin-bottom: 7em; }
|
304 |
+
#analytics-warning { position: absolute; top: 7em; }
|
305 |
+
</style>";
|
306 |
+
} // end success()
|
307 |
+
|
308 |
+
function warning() {
|
309 |
+
echo "
|
310 |
+
<div id='analytics-warning' class='updated fade-ff0000'><p><strong>Google Analytics is not active.</strong> You must <a href='plugins.php?page=googleanalytics.php'>enter your UA String</a> for it to work.</p></div>
|
311 |
+
<style type='text/css'>
|
312 |
+
#adminmenu { margin-bottom: 6em; }
|
313 |
+
#analytics-warning { position: absolute; top: 7em; }
|
314 |
+
</style>";
|
315 |
+
} // end warning()
|
316 |
+
|
317 |
+
} // end class GA_Admin
|
318 |
+
|
319 |
+
} //endif
|
320 |
+
|
321 |
+
|
322 |
+
/**
|
323 |
+
* Code that actually inserts stuff into pages.
|
324 |
+
*/
|
325 |
+
if ( ! class_exists( 'GA_Filter' ) ) {
|
326 |
+
class GA_Filter {
|
327 |
+
|
328 |
+
/*
|
329 |
+
* Insert the tracking code into the page
|
330 |
+
*/
|
331 |
+
function spool_analytics() {
|
332 |
+
global $pluginpath;
|
333 |
+
|
334 |
+
$opt = get_option('GoogleAnalyticsPP');
|
335 |
+
$options = unserialize($opt);
|
336 |
+
|
337 |
+
if ($options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ) { ?>
|
338 |
+
<!-- Google Analytics for WordPress | http://www.joostdevalk.nl/wordpress/google-analytics/ -->
|
339 |
+
<script type="text/javascript">
|
340 |
+
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
|
341 |
+
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
|
342 |
+
</script>
|
343 |
+
<script type="text/javascript">
|
344 |
+
var pageTracker = _gat._getTracker("<?php echo $options["uastring"]; ?>");
|
345 |
+
</script>
|
346 |
+
<?php if ( $options["extrase"] == true ) {
|
347 |
+
echo("\t<script src=\"".$pluginpath."custom_se.js\" type=\"text/javascript\"></script>\n");
|
348 |
+
} ?>
|
349 |
+
<script type="text/javascript">
|
350 |
+
<?php if ( $options['userv2'] ) {
|
351 |
+
echo("\tpageTracker._setLocalRemoteServerMode();");
|
352 |
+
} ?>
|
353 |
+
pageTracker._initData();
|
354 |
+
<?php if (strpos($_SERVER['HTTP_REFERER'],"images.google") && strpos($_SERVER['HTTP_REFERER'],"&prev") && $options["imagese"]) { ?>
|
355 |
+
regex = new RegExp("images.google.([^\/]+).*&prev=([^&]+)");
|
356 |
+
var match = regex.exec(pageTracker.qa);
|
357 |
+
pageTracker.qa = "http://images.google." + match[1] + unescape(match[2]);
|
358 |
+
<?php } ?>
|
359 |
+
pageTracker._trackPageview();
|
360 |
+
</script>
|
361 |
+
<!-- End of Google Analytics code -->
|
362 |
+
<?php
|
363 |
+
}
|
364 |
+
}
|
365 |
+
|
366 |
+
function track_adsense() {
|
367 |
+
echo("\t<script src=\"".$pluginpath."adsense-track.js\" type=\"text/javascript\"></script>\n");
|
368 |
+
}
|
369 |
+
/* Create an array which contians:
|
370 |
+
* "domain" e.g. boakes.org
|
371 |
+
* "host" e.g. store.boakes.org
|
372 |
+
*/
|
373 |
+
function ga_get_domain($uri){
|
374 |
+
|
375 |
+
$hostPattern = "/^(http:\/\/)?([^\/]+)/i";
|
376 |
+
$domainPattern = "/[^\.\/]+\.[^\.\/]+$/";
|
377 |
+
|
378 |
+
preg_match($hostPattern, $uri, $matches);
|
379 |
+
$host = $matches[2];
|
380 |
+
preg_match($domainPattern, $host, $matches);
|
381 |
+
return array("domain"=>$matches[0],"host"=>$host);
|
382 |
+
|
383 |
+
}
|
384 |
+
|
385 |
+
function ga_parse_link($leaf, $matches){
|
386 |
+
global $origin ;
|
387 |
+
|
388 |
+
$opt = get_option('GoogleAnalyticsPP');
|
389 |
+
$options = unserialize($opt);
|
390 |
+
|
391 |
+
$target = GA_Filter::ga_get_domain($matches[3]);
|
392 |
+
$coolbit = "";
|
393 |
+
$extension = substr($matches[3],-3);
|
394 |
+
$dlextensions = split(",",$options['dlextensions']);
|
395 |
+
if ( $target["domain"] != $origin["domain"] ){
|
396 |
+
if ($options['domainorurl'] == "domain") {
|
397 |
+
$coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$leaf."/".$target["host"]."');\"";
|
398 |
+
} else if ($options['domainorurl'] == "url") {
|
399 |
+
$coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$leaf."/".$matches[2]."//".$matches[3]."');\"";
|
400 |
+
}
|
401 |
+
} else if ( in_array($extension, $dlextensions) && $target["domain"] == $origin["domain"] ) {
|
402 |
+
$file = str_replace($origin["domain"],"",$matches[3]);
|
403 |
+
$file = str_replace('www.',"",$file);
|
404 |
+
$coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$options['dlprefix'].$file."');\"";
|
405 |
+
}
|
406 |
+
return '<a ' . $matches[1] . 'href="' . $matches[2] . '//' . $matches[3] . '"' . ' ' .$coolBit . $matches[4] . '>' . $matches[5] . '</a>';
|
407 |
+
}
|
408 |
+
|
409 |
+
function ga_parse_article_link($matches){
|
410 |
+
$opt = get_option('GoogleAnalyticsPP');
|
411 |
+
$options = unserialize($opt);
|
412 |
+
return GA_Filter::ga_parse_link($options['artprefix'],$matches);
|
413 |
+
}
|
414 |
+
|
415 |
+
function ga_parse_comment_link($matches){
|
416 |
+
$opt = get_option('GoogleAnalyticsPP');
|
417 |
+
$options = unserialize($opt);
|
418 |
+
return GA_Filter::ga_parse_link($options['comprefix'],$matches);
|
419 |
+
}
|
420 |
+
|
421 |
+
function the_content($text) {
|
422 |
+
static $anchorPattern = '/<a (.*?)href="(.*?)\/\/(.*?)"(.*?)>(.*?)<\/a>/i';
|
423 |
+
$text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_article_link'),$text);
|
424 |
+
return $text;
|
425 |
+
}
|
426 |
+
|
427 |
+
function comment_text($text) {
|
428 |
+
static $anchorPattern = '/<a (.*?)href="(.*?)\/\/(.*?)"(.*?)>(.*?)<\/a>/i';
|
429 |
+
$text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_comment_link'),$text);
|
430 |
+
return $text;
|
431 |
+
}
|
432 |
+
|
433 |
+
function comment_author_link($text) {
|
434 |
+
$opt = get_option('GoogleAnalyticsPP');
|
435 |
+
$options = unserialize($opt);
|
436 |
+
|
437 |
+
static $anchorPattern = '/(.*\s+.*?href\s*=\s*)["\'](.*?)["\'](.*)/';
|
438 |
+
preg_match($anchorPattern, $text, $matches);
|
439 |
+
if ($matches[2] == "") return $text;
|
440 |
+
|
441 |
+
$target = GA_Filter::ga_get_domain($matches[2]);
|
442 |
+
$coolbit = "";
|
443 |
+
$origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
|
444 |
+
if ( $target["domain"] != $origin["domain"] ){
|
445 |
+
if ($options['domainorurl'] == "domain") {
|
446 |
+
$coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$options['comautprefix']."/".$target["host"]."');\"";
|
447 |
+
} else if ($options['domainorurl'] == "url") {
|
448 |
+
$coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$options['comautprefix']."/".$matches[2]."');\"";
|
449 |
+
}
|
450 |
+
}
|
451 |
+
return $matches[1] . "\"" . $matches[2] . "\" " . $coolBit ." ". $matches[3];
|
452 |
+
}
|
453 |
+
|
454 |
+
function bookmarks($bookmarks) {
|
455 |
+
if (!is_admin() && (!current_user_can('edit_users') || $options['admintracking'] ) ) {
|
456 |
+
$opt = get_option('GoogleAnalyticsPP');
|
457 |
+
$options = unserialize($opt);
|
458 |
+
|
459 |
+
foreach ( (array) $bookmarks as $bookmark ) {
|
460 |
+
if ($options['domainorurl'] == "domain") {
|
461 |
+
$target = GA_Filter::ga_get_domain($bookmark->link_url);
|
462 |
+
$bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$target["host"]."');";
|
463 |
+
} else if ($options['domainorurl'] == "url") {
|
464 |
+
$bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$bookmark->link_url."');";
|
465 |
+
}
|
466 |
+
}
|
467 |
+
}
|
468 |
+
return $bookmarks;
|
469 |
+
}
|
470 |
+
} // class GA_Filter
|
471 |
+
} // endif
|
472 |
+
|
473 |
+
$version = "0.61";
|
474 |
+
$uakey = "analytics";
|
475 |
+
|
476 |
+
if (function_exists("get_option")) {
|
477 |
+
if ($wp_uastring_takes_precedence) {
|
478 |
+
$opt = get_option('GoogleAnalyticsPP');
|
479 |
+
$options = unserialize($opt);
|
480 |
+
$uastring = $options['uastring'];
|
481 |
+
}
|
482 |
+
}
|
483 |
+
|
484 |
+
$mulch = ($uastring=""?"##-#####-#":$uastring);
|
485 |
+
$gaf = new GA_Filter();
|
486 |
+
$origin = $gaf->ga_get_domain($_SERVER["HTTP_HOST"]);
|
487 |
+
|
488 |
+
$opt = get_option('GoogleAnalyticsPP',"");
|
489 |
+
|
490 |
+
if ($opt == "") {
|
491 |
+
$options['dlextensions'] = 'doc,exe,.js,pdf,ppt,tgz,zip,xls';
|
492 |
+
$options['dlprefix'] = '/downloads';
|
493 |
+
$options['artprefix'] = '/outbound/article';
|
494 |
+
$options['comprefix'] = '/outbound/comment';
|
495 |
+
$options['comautprefix'] = '/outbound/commentauthor';
|
496 |
+
$options['blogrollprefix'] = '/outbound/blogroll';
|
497 |
+
$options['domainorurl'] = 'domain';
|
498 |
+
$options['position'] = 'header';
|
499 |
+
$options['userv2'] = false;
|
500 |
+
$options['extrase'] = false;
|
501 |
+
$options['imagese'] = false;
|
502 |
+
$options['trackoutbound'] = true;
|
503 |
+
$opt = serialize($options);
|
504 |
+
update_option('GoogleAnalyticsPP',$opt);
|
505 |
+
} else {
|
506 |
+
$options = unserialize($opt);
|
507 |
+
}
|
508 |
+
|
509 |
+
// adds the menu item to the admin interface
|
510 |
+
add_action('admin_menu', array('GA_Admin','add_config_page'));
|
511 |
+
|
512 |
+
if ($options['trackoutbound']) {
|
513 |
+
// filters alter the existing content
|
514 |
+
add_filter('the_content', array('GA_Filter','the_content'), 99);
|
515 |
+
add_filter('the_excerpt', array('GA_Filter','the_content'), 99);
|
516 |
+
add_filter('comment_text', array('GA_Filter','comment_text'), 99);
|
517 |
+
add_filter('get_bookmarks', array('GA_Filter','bookmarks'), 99);
|
518 |
+
add_filter('get_comment_author_link', array('GA_Filter','comment_author_link'), 99);
|
519 |
+
}
|
520 |
+
if ($options['trackadsense']) {
|
521 |
+
add_action('wp_footer', array('GA_Filter','track_adsense'));
|
522 |
+
}
|
523 |
+
|
524 |
+
// adds the footer so the javascript is loaded
|
525 |
+
add_action('wp_head', array('GA_Filter','spool_analytics'));
|
526 |
+
|
527 |
+
if ($options['trackadsense']) {
|
528 |
+
add_action('wp_footer', array('GA_Filter','track_adsense'));
|
529 |
+
}
|
530 |
+
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.joostdevalk.nl/donate/
|
|
4 |
Tags: analytics, google analytics, statistics
|
5 |
Requires at least: 2.2
|
6 |
Tested up to: 2.5
|
7 |
-
Stable tag: 2.5.
|
8 |
|
9 |
The Google Analytics for WordPress plugina automatically tracks and segments all outbound links from within posts, comment author links, links within comments, blogroll links and downloads. It also allows you to track AdSense clicks, add extra search engines, track image search queries and it will even work together with Urchin.
|
10 |
|
4 |
Tags: analytics, google analytics, statistics
|
5 |
Requires at least: 2.2
|
6 |
Tested up to: 2.5
|
7 |
+
Stable tag: 2.5.3
|
8 |
|
9 |
The Google Analytics for WordPress plugina automatically tracks and segments all outbound links from within posts, comment author links, links within comments, blogroll links and downloads. It also allows you to track AdSense clicks, add extra search engines, track image search queries and it will even work together with Urchin.
|
10 |
|