Google Analyticator - Version 2.0

Version Description

Download this release

Release Info

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

Code changes from version 1.54 to 2.0

Files changed (3) hide show
  1. ga_external-links.js +0 -49
  2. google-analyticator.php +141 -41
  3. readme.txt +2 -1
ga_external-links.js DELETED
@@ -1,49 +0,0 @@
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+")$", "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
- addHandler(a[i], 'click', function(){ urchinTracker('/download/'+this.href.replace(/^(http|https):\/\/([a-z-.0-9]+)\//i, '').split('/').join('--')); }, false);
16
- }
17
- else {
18
- addHandler(a[i], 'click', function() { urchinTracker('/outgoing/'+this.href.replace(/^http:\/\/|https:\/\//i, '').split('/').join('--')); }, false);
19
- }
20
- };
21
- };
22
- };
23
-
24
- function onContent(f){//(C)webreflection.blogspot.com
25
- var a,b=navigator.userAgent,d=document,w=window,
26
- c="__onContent__",e="addEventListener",o="opera",r="readyState",
27
- s="<scr".concat("ipt defer src='//:' on",r,"change='if(this.",r,"==\"complete\"){this.parentNode.removeChild(this);",c,"()}'></scr","ipt>");
28
- w[c]=(function(o){return function(){w[c]=function(){};for(a=arguments.callee;!a.done;a.done=1)f(o?o():o)}})(w[c]);
29
- if(d[e])d[e]("DOMContentLoaded",w[c],false);
30
- if(/WebKit|Khtml/i.test(b)||(w[o]&&parseInt(w[o].version())<9))
31
- (function(){/loaded|complete/.test(d[r])?w[c]():setTimeout(arguments.callee,1)})();
32
- else if(/MSIE/i.test(b))d.write(s);
33
- };
34
-
35
- function addHandler(obj, evt, newhandler, captures)
36
- {
37
- if (obj.attachEvent)
38
- obj.attachEvent('on' + evt, newhandler);
39
- else if (obj.addEventListener)
40
- obj.addEventListener(evt, newhandler, captures);
41
- else
42
- {
43
- var oldhandler;
44
- if (oldhandler = obj['on' + evt])
45
- obj['on' + evt] = function() { oldhandler(); newhandler(); }
46
- else obj['on' + evt] = newhandler;
47
- }
48
- }
49
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
google-analyticator.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  * Plugin Name: Google Analyticator
4
- * Version: 1.54
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.
@@ -17,6 +17,7 @@ define("key_ga_uid", "ga_uid", true);
17
  define("key_ga_status", "ga_status", true);
18
  define("key_ga_admin", "ga_admin_status", true);
19
  define("key_ga_extra", "ga_extra", true);
 
20
  define("key_ga_outbound", "ga_outbound", true);
21
  define("key_ga_downloads", "ga_downloads", true);
22
  define("key_ga_footer", "ga_footer", true);
@@ -25,6 +26,7 @@ define("ga_uid_default", "XX-XXXXX-X", true);
25
  define("ga_status_default", ga_disabled, true);
26
  define("ga_admin_default", ga_enabled, true);
27
  define("ga_extra_default", "", true);
 
28
  define("ga_outbound_default", ga_enabled, true);
29
  define("ga_downloads_default", "", true);
30
  define("ga_footer_default", ga_disabled, true);
@@ -34,6 +36,7 @@ add_option(key_ga_status, ga_status_default, 'If Google Analytics logging in tur
34
  add_option(key_ga_uid, ga_uid_default, 'Your Google Analytics UID.');
35
  add_option(key_ga_admin, ga_admin_default, 'If WordPress admins are counted in Google Analytics.');
36
  add_option(key_ga_extra, ga_extra_default, 'Addition Google Analytics tracking options');
 
37
  add_option(key_ga_outbound, ga_outbound_default, 'Add tracking of outbound links');
38
  add_option(key_ga_downloads, ga_downloads_default, 'Download extensions to track with Google Analyticator');
39
  add_option(key_ga_footer, ga_footer_default, 'If Google Analyticator is outputting in the footer');
@@ -41,6 +44,9 @@ add_option(key_ga_footer, ga_footer_default, 'If Google Analyticator is outputti
41
  // Create a option page for settings
42
  add_action('admin_menu', 'add_ga_option_page');
43
 
 
 
 
44
  // Hook in the options page function
45
  function add_ga_option_page() {
46
  global $wpdb;
@@ -78,10 +84,14 @@ function ga_options_page() {
78
  if (($ga_admin != ga_enabled) && ($ga_admin != ga_disabled))
79
  $ga_admin = ga_admin_default;
80
  update_option(key_ga_admin, $ga_admin);
81
-
82
  // Update the extra tracking code
83
  $ga_extra = $_POST[key_ga_extra];
84
  update_option(key_ga_extra, $ga_extra);
 
 
 
 
85
 
86
  // Update the outbound tracking
87
  $ga_outbound = $_POST[key_ga_outbound];
@@ -189,76 +199,90 @@ function ga_options_page() {
189
  </tr>
190
  <tr>
191
  <th width="30%" valign="top" style="padding-top: 10px;">
192
- <label for="<?php echo key_ga_outbound ?>">Outbound link tracking:</label>
193
  </th>
194
  <td>
195
  <?php
196
- echo "<select name='".key_ga_outbound."' id='".key_ga_outbound."'>\n";
197
 
198
  echo "<option value='".ga_enabled."'";
199
- if(get_option(key_ga_outbound) == ga_enabled)
200
  echo " selected='selected'";
201
  echo ">Enabled</option>\n";
202
 
203
  echo "<option value='".ga_disabled."'";
204
- if(get_option(key_ga_outbound) == ga_disabled)
205
  echo" selected='selected'";
206
  echo ">Disabled</option>\n";
207
 
208
  echo "</select>\n";
209
  ?>
210
- <p style="margin: 5px 10px;">Disabling this option will turn off the tracking of outbound links. It's recommended not to disable this option unless you're a privacy advocate (now why would you be using Google Analytics in the first place?) or it's causing some kind of weird issue.</p>
211
  </td>
212
  </tr>
213
  <tr>
214
  <th width="30%" valign="top" style="padding-top: 10px;">
215
- <label for="<?php echo key_ga_footer ?>">Footer tracking code:</label>
216
  </th>
217
  <td>
218
  <?php
219
- echo "<select name='".key_ga_footer."' id='".key_ga_footer."'>\n";
220
 
221
  echo "<option value='".ga_enabled."'";
222
- if(get_option(key_ga_footer) == ga_enabled)
223
  echo " selected='selected'";
224
  echo ">Enabled</option>\n";
225
 
226
  echo "<option value='".ga_disabled."'";
227
- if(get_option(key_ga_footer) == ga_disabled)
228
  echo" selected='selected'";
229
  echo ">Disabled</option>\n";
230
 
231
  echo "</select>\n";
232
  ?>
233
- <p style="margin: 5px 10px;">Enabling this option will insert the Google Analytics tracking code in your site's footer instead of your header. This will speed up your page loading if turned on. Not all themes support code in the footer, so if you turn this option on, be sure to check the Analytics code is still displayed on your site.</p>
234
  </td>
235
  </tr>
236
  <tr>
237
  <th valign="top" style="padding-top: 10px;">
238
- <label for="<?php echo key_ga_extra; ?>">Additional tracking code:</label>
239
  </th>
240
  <td>
241
  <?php
242
  echo "<input type='text' size='50' ";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
  echo "name='".key_ga_extra."' ";
244
- echo "id='".key_ga_extra."' ";
245
- echo "value='".stripslashes(get_option(key_ga_extra))."' />\n";
246
  ?>
247
- <p style="margin: 5px 10px;">Enter any additional bits of tracking code that you would like to include in the script. For example to track a subdomain in your main domain's profile you would add <strong>_udn="example.com";</strong>. Addition tracking code information can be found in <a href="http://www.google.com/support/analytics/">Google Analytic's FAQ</a>.</p>
248
  </td>
249
  </tr>
250
  <tr>
251
  <th valign="top" style="padding-top: 10px;">
252
- <label for="<?php echo key_ga_downloads; ?>">Download extensions to track:</label>
253
  </th>
254
  <td>
255
  <?php
256
- echo "<input type='text' size='50' ";
257
- echo "name='".key_ga_downloads."' ";
258
- echo "id='".key_ga_downloads."' ";
259
- echo "value='".stripslashes(get_option(key_ga_downloads))."' />\n";
260
  ?>
261
- <p style="margin: 5px 10px;">Enter any extensions of files you would like to be tracked as a download. For example to track all MP3s and PDFs enter <strong>mp3,pdf</strong>. <em>Outbound link tracking must be enabled for downloads to be tracked.</em></p>
262
  </td>
263
  </tr>
264
  </table>
@@ -281,8 +305,9 @@ if (get_option(key_ga_footer) == ga_enabled) {
281
 
282
  // The guts of the Google Analytics script
283
  function add_google_analytics() {
284
- $uid = get_option(key_ga_uid);
285
  $extra = stripslashes(get_option(key_ga_extra));
 
286
  $extensions = str_replace (",", "|", get_option(key_ga_downloads));
287
 
288
  // If GA is enabled and has a valid key
@@ -292,26 +317,101 @@ function add_google_analytics() {
292
  if ((get_option(key_ga_admin) == ga_enabled) || ((get_option(key_ga_admin) == ga_disabled) && ( !current_user_can('level_8') ))) {
293
 
294
  echo "<!-- Google Analytics Tracking by Google Analyticator: http://cavemonkey50.com/code/google-analyticator/ -->\n";
295
- echo " <script src=\"http://www.google-analytics.com/urchin.js\" type=\"text/javascript\"></script>\n";
296
- // If outbound tracking is enabled
297
- if ( get_option (key_ga_outbound) == ga_enabled )
298
- echo " <script src=\"" . get_option('siteurl') . "/wp-content/plugins/google-analyticator/ga_external-links.js\" type=\"text/javascript\"></script>\n";
299
  echo " <script type=\"text/javascript\">\n";
300
- // If outbound tracking is enabled
301
- if ( get_option (key_ga_outbound) == ga_enabled ) {
302
- // If in the header
303
- if ( get_option (key_ga_footer) != ga_enabled )
304
- echo " onContent(function() {\n";
305
- echo " urchin = new urchin();\n";
306
- echo " urchin.trackDownload = \"$extensions\";\n";
307
- echo " urchin.trackLinks();\n";
308
- // If in the header
309
- if ( get_option (key_ga_footer) != ga_enabled )
310
- echo " } );\n";
311
- }
312
- echo " _uacct=\"$uid\"; $extra urchinTracker();\n";
 
 
 
 
 
 
313
  echo " </script>\n";
314
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  }
316
  }
317
  }
1
  <?php
2
  /*
3
  * Plugin Name: Google Analyticator
4
+ * Version: 2.0
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.
17
  define("key_ga_status", "ga_status", true);
18
  define("key_ga_admin", "ga_admin_status", true);
19
  define("key_ga_extra", "ga_extra", true);
20
+ define("key_ga_extra_after", "ga_extra_after", true);
21
  define("key_ga_outbound", "ga_outbound", true);
22
  define("key_ga_downloads", "ga_downloads", true);
23
  define("key_ga_footer", "ga_footer", true);
26
  define("ga_status_default", ga_disabled, true);
27
  define("ga_admin_default", ga_enabled, true);
28
  define("ga_extra_default", "", true);
29
+ define("ga_extra_after_default", "", true);
30
  define("ga_outbound_default", ga_enabled, true);
31
  define("ga_downloads_default", "", true);
32
  define("ga_footer_default", ga_disabled, true);
36
  add_option(key_ga_uid, ga_uid_default, 'Your Google Analytics UID.');
37
  add_option(key_ga_admin, ga_admin_default, 'If WordPress admins are counted in Google Analytics.');
38
  add_option(key_ga_extra, ga_extra_default, 'Addition Google Analytics tracking options');
39
+ add_option(key_ga_extra_after, ga_extra_after_default, 'Addition Google Analytics tracking options');
40
  add_option(key_ga_outbound, ga_outbound_default, 'Add tracking of outbound links');
41
  add_option(key_ga_downloads, ga_downloads_default, 'Download extensions to track with Google Analyticator');
42
  add_option(key_ga_footer, ga_footer_default, 'If Google Analyticator is outputting in the footer');
44
  // Create a option page for settings
45
  add_action('admin_menu', 'add_ga_option_page');
46
 
47
+ // Initialize outbound link tracking
48
+ add_action('init', 'ga_outgoing_links');
49
+
50
  // Hook in the options page function
51
  function add_ga_option_page() {
52
  global $wpdb;
84
  if (($ga_admin != ga_enabled) && ($ga_admin != ga_disabled))
85
  $ga_admin = ga_admin_default;
86
  update_option(key_ga_admin, $ga_admin);
87
+
88
  // Update the extra tracking code
89
  $ga_extra = $_POST[key_ga_extra];
90
  update_option(key_ga_extra, $ga_extra);
91
+
92
+ // Update the extra after tracking code
93
+ $ga_extra_after = $_POST[key_ga_extra_after];
94
+ update_option(key_ga_extra_after, $ga_extra_after);
95
 
96
  // Update the outbound tracking
97
  $ga_outbound = $_POST[key_ga_outbound];
199
  </tr>
200
  <tr>
201
  <th width="30%" valign="top" style="padding-top: 10px;">
202
+ <label for="<?php echo key_ga_footer ?>">Footer tracking code:</label>
203
  </th>
204
  <td>
205
  <?php
206
+ echo "<select name='".key_ga_footer."' id='".key_ga_footer."'>\n";
207
 
208
  echo "<option value='".ga_enabled."'";
209
+ if(get_option(key_ga_footer) == ga_enabled)
210
  echo " selected='selected'";
211
  echo ">Enabled</option>\n";
212
 
213
  echo "<option value='".ga_disabled."'";
214
+ if(get_option(key_ga_footer) == ga_disabled)
215
  echo" selected='selected'";
216
  echo ">Disabled</option>\n";
217
 
218
  echo "</select>\n";
219
  ?>
220
+ <p style="margin: 5px 10px;">Enabling this option will insert the Google Analytics tracking code in your site's footer instead of your header. This will speed up your page loading if turned on. Not all themes support code in the footer, so if you turn this option on, be sure to check the Analytics code is still displayed on your site.</p>
221
  </td>
222
  </tr>
223
  <tr>
224
  <th width="30%" valign="top" style="padding-top: 10px;">
225
+ <label for="<?php echo key_ga_outbound ?>">Outbound link tracking:</label>
226
  </th>
227
  <td>
228
  <?php
229
+ echo "<select name='".key_ga_outbound."' id='".key_ga_outbound."'>\n";
230
 
231
  echo "<option value='".ga_enabled."'";
232
+ if(get_option(key_ga_outbound) == ga_enabled)
233
  echo " selected='selected'";
234
  echo ">Enabled</option>\n";
235
 
236
  echo "<option value='".ga_disabled."'";
237
+ if(get_option(key_ga_outbound) == ga_disabled)
238
  echo" selected='selected'";
239
  echo ">Disabled</option>\n";
240
 
241
  echo "</select>\n";
242
  ?>
243
+ <p style="margin: 5px 10px;">Disabling this option will turn off the tracking of outbound links. It's recommended not to disable this option unless you're a privacy advocate (now why would you be using Google Analytics in the first place?) or it's causing some kind of weird issue.</p>
244
  </td>
245
  </tr>
246
  <tr>
247
  <th valign="top" style="padding-top: 10px;">
248
+ <label for="<?php echo key_ga_downloads; ?>">Download extensions to track:</label>
249
  </th>
250
  <td>
251
  <?php
252
  echo "<input type='text' size='50' ";
253
+ echo "name='".key_ga_downloads."' ";
254
+ echo "id='".key_ga_downloads."' ";
255
+ echo "value='".stripslashes(get_option(key_ga_downloads))."' />\n";
256
+ ?>
257
+ <p style="margin: 5px 10px;">Enter any extensions of files you would like to be tracked as a download. For example to track all MP3s and PDFs enter <strong>mp3,pdf</strong>. <em>Outbound link tracking must be enabled for downloads to be tracked.</em></p>
258
+ </td>
259
+ </tr>
260
+ <tr>
261
+ <th valign="top" style="padding-top: 10px;">
262
+ <label for="<?php echo key_ga_extra; ?>">Additional tracking code<br />(before tracker initialization):</label>
263
+ </th>
264
+ <td>
265
+ <?php
266
+ echo "<textarea cols='50' rows='8' ";
267
  echo "name='".key_ga_extra."' ";
268
+ echo "id='".key_ga_extra."'>";
269
+ echo stripslashes(get_option(key_ga_extra))."</textarea>\n";
270
  ?>
271
+ <p style="margin: 5px 10px;">Enter any additional lines of tracking code that you would like to include in the Google Anayltics tracking script. The code in this section will be displayed <strong>before</strong> the Google Analytics tracker is initialized. Read <a href="http://www.google.com/analytics/InstallingGATrackingCode.pdf">Google Analytics tracker manual</a> to learn what code goes here and how to use it.</p>
272
  </td>
273
  </tr>
274
  <tr>
275
  <th valign="top" style="padding-top: 10px;">
276
+ <label for="<?php echo key_ga_extra_after; ?>">Additional tracking code<br />(after tracker initialization):</label>
277
  </th>
278
  <td>
279
  <?php
280
+ echo "<textarea cols='50' rows='8' ";
281
+ echo "name='".key_ga_extra_after."' ";
282
+ echo "id='".key_ga_extra_after."'>";
283
+ echo stripslashes(get_option(key_ga_extra_after))."</textarea>\n";
284
  ?>
285
+ <p style="margin: 5px 10px;">Enter any additional lines of tracking code that you would like to include in the Google Anayltics tracking script. The code in this section will be displayed <strong>after</strong> the Google Analytics tracker is initialized. Read <a href="http://www.google.com/analytics/InstallingGATrackingCode.pdf">Google Analytics tracker manual</a> to learn what code goes here and how to use it.</p>
286
  </td>
287
  </tr>
288
  </table>
305
 
306
  // The guts of the Google Analytics script
307
  function add_google_analytics() {
308
+ $uid = stripslashes(get_option(key_ga_uid));
309
  $extra = stripslashes(get_option(key_ga_extra));
310
+ $extra_after = stripslashes(get_option(key_ga_extra_after));
311
  $extensions = str_replace (",", "|", get_option(key_ga_downloads));
312
 
313
  // If GA is enabled and has a valid key
317
  if ((get_option(key_ga_admin) == ga_enabled) || ((get_option(key_ga_admin) == ga_disabled) && ( !current_user_can('level_8') ))) {
318
 
319
  echo "<!-- Google Analytics Tracking by Google Analyticator: http://cavemonkey50.com/code/google-analyticator/ -->\n";
 
 
 
 
320
  echo " <script type=\"text/javascript\">\n";
321
+ echo " var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n";
322
+ echo " document.write(\"\<script src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'>\<\/script>\" );\n";
323
+ echo " </script>\n\n";
324
+
325
+ echo " <script type=\"text/javascript\">\n";
326
+ echo " var pageTracker = _gat._getTracker(\"$uid\");\n";
327
+
328
+ // Insert extra before tracker code
329
+ if ( '' != $extra )
330
+ echo " " . $extra . "\n";
331
+
332
+ // Initialize the tracker
333
+ echo " pageTracker._initData();\n";
334
+ echo " pageTracker._trackPageview();\n";
335
+
336
+ // Insert extra after tracker code
337
+ if ( '' != $extra_after )
338
+ echo " " . $extra_after . "\n";
339
+
340
  echo " </script>\n";
341
+ }
342
+ }
343
+ }
344
+
345
+ // Add the ougoing links script
346
+ function ga_outgoing_links() {
347
+ if (get_option(key_ga_outbound) == ga_enabled) {
348
+ if ((get_option(key_ga_admin) == ga_enabled) || ((get_option(key_ga_admin) == ga_disabled) && ( !current_user_can('level_8') ))) {
349
+ add_filter('comment_text', 'ga_outgoing');
350
+ add_filter('get_comment_author_link', 'ga_outgoing_comment_author');
351
+ add_filter('the_content', 'ga_outgoing');
352
+ add_filter('the_excerpt', 'ga_outgoing');
353
+ }
354
+ }
355
+ }
356
+
357
+ // Finds all the links contained in a post or comment
358
+ function ga_outgoing($input) {
359
+ static $link_pattern = '/<a (.*?)href="(.*?)\/\/(.*?)"(.*?)>(.*?)<\/a>/i';
360
+ static $link_pattern_2 = '/<a (.*?)href=\'(.*?)\/\/(.*?)\'(.*?)>(.*?)<\/a>/i';
361
+ $input = preg_replace_callback($link_pattern, ga_parse_link, $input);
362
+ $input = preg_replace_callback($link_pattern_2, ga_parse_link, $input);
363
+ return $input;
364
+ }
365
+
366
+ // Takes the comment author link and adds the Google outgoing tracking code
367
+ function ga_outgoing_comment_author($input) {
368
+ static $link_pattern = '(.*href\s*=\s*)[\"\']*(.*)[\"\'] (.*)';
369
+ ereg($link_pattern, $input, $matches);
370
+ if ($matches[2] == "") return $input;
371
+
372
+ $target = ga_find_domain($matches[2]);
373
+ $local_host = ga_find_domain($_SERVER["HTTP_HOST"]);
374
+ if ( $target["domain"] != $local_host["domain"] ){
375
+ $tracker_code .= " onclick=\"javascript:pageTracker._trackPageview ('/outbound/".$target["host"]."');\" ";
376
+ }
377
+ return $matches[1] . "\"" . $matches[2] . "\"" . $tracker_code . $matches[3];
378
+ }
379
+
380
+ // Takes a link and adds the Google outgoing tracking code
381
+ function ga_parse_link($matches){
382
+ $local_host = ga_find_domain($_SERVER["HTTP_HOST"]);
383
+ $target = ga_find_domain($matches[3]);
384
+ $url = $matches[3];
385
+ $file_extension = strtolower(substr(strrchr($url,"."),1));
386
+ if ( $target["domain"] != $local_host["domain"] ){
387
+ $tracker_code .= " onclick=\"javascript:pageTracker._trackPageview ('/outbound/".$target["host"]."');\"";
388
+ }
389
+ if ( ($target["domain"] == $local_host["domain"]) && (ga_check_download($file_extension)) ){
390
+ $url = strtolower(substr(strrchr($url,"/"),1));
391
+ $tracker_code .= " onclick=\"javascript:pageTracker._trackPageview ('/downloads/".$file_extension."/".$url."');\"";
392
+ }
393
+ return '<a href="' . $matches[2] . '//' . $matches[3] . '"' . $matches[1] . $matches[4].$tracker_code.'>' . $matches[5] . '</a>';
394
+ }
395
+
396
+ // Checks to see if the link is on your site
397
+ function ga_find_domain($url){
398
+ $host_pattern = "/^(http:\/\/)?([^\/]+)/i";
399
+ $domain_pattern = "/[^\.\/]+\.[^\.\/]+$/";
400
+
401
+ preg_match($host_pattern, $url, $matches);
402
+ $host = $matches[2];
403
+ preg_match($domain_pattern, $host, $matches);
404
+ return array("domain"=>$matches[0],"host"=>$host);
405
+ }
406
+
407
+ // Checks to see if the requested URL is a download
408
+ function ga_check_download($file_extension){
409
+ if (get_option(key_ga_downloads)){
410
+ $extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
411
+
412
+ foreach ($extensions as $extension) {
413
+ if ($extension == $file_extension)
414
+ return true;
415
  }
416
  }
417
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://cavemonkey50.com/code/
4
  Tags: stats, google, analytics, tracking
5
  Requires at least: 2.0
6
  Tested up to: 2.3
7
- Stable tag: 1.54
8
 
9
  Adds the necessary JavaScript code to enable Google Analytics.
10
 
@@ -16,6 +16,7 @@ Google Analyticator adds the necessary JavaScript code to enable Google Analytic
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.
4
  Tags: stats, google, analytics, tracking
5
  Requires at least: 2.0
6
  Tested up to: 2.3
7
+ Stable tag: 2.0
8
 
9
  Adds the necessary JavaScript code to enable Google Analytics.
10
 
16
 
17
  Google Analyticator Has the Following Features:
18
 
19
+ - Full support for the latest version of Google Analytics tracking code (ga.js).
20
  - Inserts tracking code on all pages WordPress manages.
21
  - Automatically tracks outbound links.
22
  - Provides support for download link tracking.