Google Analyticator - Version 1.5

Version Description

Download this release

Release Info

Developer cavemonkey50
Plugin Icon 128x128 Google Analyticator
Version 1.5
Comparing to
See all releases

Code changes from version 1.41 to 1.5

google-analyticator/ga_external-links.js ADDED
@@ -0,0 +1,36 @@
1
+ /****** GA urchin.trackLinks 0.2
2
+ Docs: http://www.terenzani.it/54/urchintrack-utility-tracciare-link-esterni-e-download-con-google-analytics
3
+ Author: Francesco Terenzani http://www.terenzani.it/ ******/
4
+
5
+ function urchin(){
6
+ this.trackDownload = '';
7
+ this.trackLinks = function(){
8
+ var a = document.getElementsByTagName('a');
9
+ var domain = /^(http|https):\/\/([a-z-.0-9]+)[\/]{0,1}/i.exec(window.location);
10
+ var internalLink = new RegExp("^(http|https):\/\/"+domain[2], "i");
11
+ var isDownload = new RegExp("("+this.trackDownload+")quot;, "i");
12
+ for(var i = 0; i < a.length; i++){
13
+ if(internalLink.test(a[i].href)){
14
+ if(this.trackDownload && isDownload.test(a[i].href))
15
+ a[i].onclick = function(){
16
+ urchinTracker('/download/'+this.href.replace(/^(http|https):\/\/([a-z-.0-9]+)\//i, '').split('/').join('--'));
17
+ };
18
+ }
19
+ else
20
+ a[i].onclick = function(){
21
+ urchinTracker('/outgoing/'+this.href.replace(/^http:\/\/|https:\/\//i, '').split('/').join('--'));
22
+ };
23
+ };
24
+ };
25
+ };
26
+
27
+ function onContent(f){//(C)webreflection.blogspot.com
28
+ var a,b=navigator.userAgent,d=document,w=window,
29
+ c="__onContent__",e="addEventListener",o="opera",r="readyState",
30
+ s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,"()}'></scr","ipt>");
31
+ w[c]=(function(o){return function(){w[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(w[c]);
32
+ if(d[e])d[e]("DOMContentLoaded",w[c],false);
33
+ if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))
34
+ (function(){/loaded|complete/.test(d[r])?w[c]():setTimeout(arguments.callee,1)})();
35
+ else if(/MSIE/i.test(b))d.write(s);
36
+ };
google-analyticator.php → google-analyticator/google-analyticator.php RENAMED
@@ -1,7 +1,7 @@
1
<?php
2
/*
3
* Plugin Name: Google Analyticator
4
- * Version: 1.41
5
* Plugin URI: http://cavemonkey50.com/code/google-analyticator/
6
* Description: Adds the necessary JavaScript code to enable <a href="http://www.google.com/analytics/">Google's Analytics</a>. After enabling this plugin visit <a href="options-general.php?page=google-analyticator.php">the options page</a> and enter your Google Analytics' UID and enable logging.
7
* Author: Ronald Heft, Jr.
@@ -269,88 +269,40 @@ if (get_option(key_ga_footer) == ga_enabled) {
269
add_action('wp_head', 'add_google_analytics');
270
}
271
272
- // Add the ougoing links script
273
- function outgoing_links() {
274
- if (get_option(key_ga_outbound) == ga_enabled) {
275
- add_filter('comment_text', 'ga_outgoing');
276
- add_filter('get_comment_author_link', 'ga_outgoing_comment_author');
277
- add_filter('the_content', 'ga_outgoing');
278
- add_filter('the_excerpt', 'ga_outgoing');
279
- }
280
- }
281
-
282
// The guts of the Google Analytics script
283
function add_google_analytics() {
284
global $user_level;
285
$uid = get_option(key_ga_uid);
286
$extra = stripslashes(get_option(key_ga_extra));
287
if ((get_option(key_ga_status) != ga_disabled) && ($uid != "XX-XXXXX-X")) {
288
if ((get_option(key_ga_admin) == ga_enabled) || ((get_option(key_ga_admin) == ga_disabled) && ($user_level < 8))) {
289
echo "<!-- Google Analytics Tracking by Google Analyticator: http://cavemonkey50.com/code/google-analyticator/ -->\n";
290
- echo " <script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\"></script><script type=\"text/javascript\"> _uacct=\"$uid\"; $extra urchinTracker(); </script>\n";
291
- outgoing_links();
292
- }
293
- }
294
- }
295
-
296
- // Finds all the links contained in a post or comment
297
- function ga_outgoing($input) {
298
- static $link_pattern = '/<a (.*?)href="(.*?)\/\/(.*?)"(.*?)>(.*?)<\/a>/i';
299
- static $link_pattern_2 = '/<a (.*?)href=\'(.*?)\/\/(.*?)\'(.*?)>(.*?)<\/a>/i';
300
- $input = preg_replace_callback($link_pattern, ga_parse_link, $input);
301
- $input = preg_replace_callback($link_pattern_2, ga_parse_link, $input);
302
- return $input;
303
- }
304
-
305
- // Takes the comment author link and adds the Google outgoing tracking code
306
- function ga_outgoing_comment_author($input) {
307
- static $link_pattern = '(.*href\s*=\s*)[\"\']*(.*)[\"\'] (.*)';
308
- ereg($link_pattern, $input, $matches);
309
- if ($matches[2] == "") return $input;
310
-
311
- $target = ga_find_domain($matches[2]);
312
- $local_host = ga_find_domain($_SERVER["HTTP_HOST"]);
313
- if ( $target["domain"] != $local_host["domain"] ){
314
- $tracker_code .= " onclick=\"javascript:urchinTracker ('/outbound/".$target["host"]."');\" ";
315
- }
316
- return $matches[1] . "\"" . $matches[2] . "\"" . $tracker_code . $matches[3];
317
- }
318
-
319
- // Takes a link and adds the Google outgoing tracking code
320
- function ga_parse_link($matches){
321
- $local_host = ga_find_domain($_SERVER["HTTP_HOST"]);
322
- $target = ga_find_domain($matches[3]);
323
- $url = $matches[3];
324
- $file_extension = strtolower(substr(strrchr($url,"."),1));
325
- if ( $target["domain"] != $local_host["domain"] ){
326
- $tracker_code .= " onclick=\"javascript:urchinTracker ('/outbound/".$target["host"]."');\"";
327
- }
328
- if ( ($target["domain"] == $local_host["domain"]) && (ga_check_download($file_extension)) ){
329
- $url = strtolower(substr(strrchr($url,"/"),1));
330
- $tracker_code .= " onclick=\"javascript:urchinTracker ('/downloads/".$file_extension."/".$url."');\"";
331
- }
332
- return '<a href="' . $matches[2] . '//' . $matches[3] . '"' . $matches[1] . $matches[4].$tracker_code.'>' . $matches[5] . '</a>';
333
- }
334
-
335
- // Checks to see if the link is on your site
336
- function ga_find_domain($url){
337
- $host_pattern = "/^(http:\/\/)?([^\/]+)/i";
338
- $domain_pattern = "/[^\.\/]+\.[^\.\/]+#x2F;";
339
-
340
- preg_match($host_pattern, $url, $matches);
341
- $host = $matches[2];
342
- preg_match($domain_pattern, $host, $matches);
343
- return array("domain"=>$matches[0],"host"=>$host);
344
- }
345
-
346
- // Checks to see if the requested URL is a download
347
- function ga_check_download($file_extension){
348
- if (get_option(key_ga_downloads)){
349
- $extensions = explode(',', get_option(key_ga_downloads));
350
-
351
- foreach ($extensions as $extension) {
352
- if ($extension == $file_extension)
353
- return true;
354
}
355
}
356
}
1
<?php
2
/*
3
* Plugin Name: Google Analyticator
4
+ * Version: 1.5
5
* Plugin URI: http://cavemonkey50.com/code/google-analyticator/
6
* Description: Adds the necessary JavaScript code to enable <a href="http://www.google.com/analytics/">Google's Analytics</a>. After enabling this plugin visit <a href="options-general.php?page=google-analyticator.php">the options page</a> and enter your Google Analytics' UID and enable logging.
7
* Author: Ronald Heft, Jr.
269
add_action('wp_head', 'add_google_analytics');
270
}
271
272
// The guts of the Google Analytics script
273
function add_google_analytics() {
274
global $user_level;
275
$uid = get_option(key_ga_uid);
276
$extra = stripslashes(get_option(key_ga_extra));
277
+ $extensions = str_replace (",", "|", get_option(key_ga_downloads));
278
+
279
+ // If GA is enabled and has a valid key
280
if ((get_option(key_ga_status) != ga_disabled) && ($uid != "XX-XXXXX-X")) {
281
+
282
+ // Track if admin tracking is enabled or disabled and less than user level 8
283
if ((get_option(key_ga_admin) == ga_enabled) || ((get_option(key_ga_admin) == ga_disabled) && ($user_level < 8))) {
284
+
285
echo "<!-- Google Analytics Tracking by Google Analyticator: http://cavemonkey50.com/code/google-analyticator/ -->\n";
286
+ echo " <script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\"></script>\n";
287
+ // If outbound tracking is enabled
288
+ if ( get_option (key_ga_outbound) == ga_enabled )
289
+ echo " <script src=\"" . get_option('siteurl') . "/wp-content/plugins/google-analyticator/ga_external-links.js\" type=\"text/javascript\"></script>\n";
290
+ echo " <script type=\"text/javascript\">\n";
291
+ // If outbound tracking is enabled
292
+ if ( get_option (key_ga_outbound) == ga_enabled ) {
293
+ // If in the header
294
+ if ( get_option (key_ga_footer) != ga_enabled )
295
+ echo " onContent(function() {\n";
296
+ echo " urchin = new urchin();\n";
297
+ echo " urchin.trackDownload = \"$extensions\";\n";
298
+ echo " urchin.trackLinks();\n";
299
+ // If in the header
300
+ if ( get_option (key_ga_footer) != ga_enabled )
301
+ echo " } );\n";
302
+ }
303
+ echo " _uacct=\"$uid\"; $extra urchinTracker();\n";
304
+ echo " </script>\n";
305
+
306
}
307
}
308
}
readme.txt CHANGED
@@ -1,34 +1,50 @@
1
- == Google Analyticator ==
2
3
- Google Analyticator adds the necessary JavaScript code to enable Google Analytics (http://google.com/analytics) logging. This eliminates the need to edit your template code to begin logging.
4
5
- == Installation ==
6
- Drop the google-analyticator.php file into /wp-content/plugins/, and activate the plugin.
7
8
- == Usage ==
9
- In your WordPress administration page go to Options > Google Analytics. From there enter your UID and enable logging. Information on how to obtain your UID can be found on the options page.
10
11
- Once you save your settings, the JavaScript code should now be appearing on all of your WordPress pages.
12
13
- == Version History ==
14
- 1.41 - Adds the option to insert tracking code in the footer instead of the header.
15
16
- 1.4 - Adds download tracking.
17
18
- 1.31 - Fixes a small bug with backslashes in the additional tracking code box.
19
20
- 1.3 - WordPress 2.0 beta is now supported. Also, the missing options page bug should be fixed for good.
21
22
- 1.2 - Added support for outbound links.
23
24
- 1.12 - Try number two at fixing missing option page bug.
25
26
- 1.11 - Hopefully fixed a bug where options page would sometimes not display.
27
28
- 1.1 - Added an option to disable administrator logging, and added an option to add additional tracking code that Google has.
29
30
- 1.0 - Initial Release
31
32
- == Credits ==
33
- Copyright (c) 2006 Ronald Heft, Jr. (ron@cavemonkey50.com)
34
- Released under the terms of the GPL
1
+ === Plugin Name ===
2
+ Contributors: cavemonkey50
3
+ Donate link: http://cavemonkey50.com/code/
4
+ Tags: stats, google, analytics, tracking
5
+ Requires at least: 1.5
6
+ Tested up to: 2.1
7
+ Stable tag: 1.5
8
9
+ Adds the necessary JavaScript code to enable Google Analytics.
10
11
+ == Description ==
12
13
+ Google Analyticator adds the necessary JavaScript code to enable Google Analytics logging on any WordPress blog. This eliminates the need to edit your template code to begin logging.
14
+
15
+ **Features**
16
+
17
+ Google Analyticator Has the Following Features:
18
19
+ - Inserts tracking code on all pages WordPress manages.
20
+ - Automatically tracks outbound links.
21
+ - Provides support for download link tracking.
22
+ - Easy install: only need to know your tracking UID.
23
+ - Expandable: can insert additional tracking code if needed, while maintaining ease of use.
24
+ - Option to disable tracking of WordPress administrators.
25
+ - Can include tracking code in the footer, speeding up load times.
26
+ - Complete control over options; disable any feature if needed.
27
28
+ **Usage**
29
30
+ In your WordPress administration page go to Options > Google Analytics. From there enter your UID and enable logging. Information on how to obtain your UID can be found on the options page.
31
+
32
+ Once you save your settings the JavaScript code should now be appearing on all of your WordPress pages.
33
+
34
+ == Installation ==
35
36
+ Drop the google-analyticator folder into /wp-content/plugins/, and activate the plugin.
37
38
+ == Frequently Asked Questions ==
39
40
+ =Where is the Google Analytics code displayed?=
41
42
+ The Google Analytics code is added to the <head> section of your theme by default. It should be somewhere near the bottom of that section.
43
44
+ =Why don’t I see the Google Analytics code on my website?=
45
46
+ If you have switched off admin logging, you will not see the code. You can try enabling it temporarily or log out of your WordPress account to see if the code is displaying.
47
48
+ =Why is Google saying my tracking code isn’t installed?=
49
50
+ Google’s servers are slow at crawling for the tracking code. While the code may be visible on your site, it takes Google a number of days to realize it. The good news is hits are being recorded during this time; they just won’t be visible until Google acknowledges your tracking code.