WP Google Analytics - Version 1.1.0

Version Description

Download this release

Release Info

Developer aaroncampbell
Plugin Icon wp plugin WP Google Analytics
Version 1.1.0
Comparing to
See all releases

Code changes from version 1.0.0 to 1.1.0

Files changed (2) hide show
  1. readme.txt +1 -1
  2. wp-google-analytics.php +16 -7
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal%4
4
  Tags: analytics, google, google analytics
5
  Requires at least: 1.5
6
  Tested up to: 2.5.1
7
- Stable tag: 1.0.0
8
 
9
  Lets you use <a href="http://analytics.google.com">Google Analytics</a> to track your WordPress site statistics
10
 
4
  Tags: analytics, google, google analytics
5
  Requires at least: 1.5
6
  Tested up to: 2.5.1
7
+ Stable tag: 1.1.0
8
 
9
  Lets you use <a href="http://analytics.google.com">Google Analytics</a> to track your WordPress site statistics
10
 
wp-google-analytics.php CHANGED
@@ -3,13 +3,16 @@
3
  * Plugin Name: WP Google Analytics
4
  * Plugin URI: http://xavisys.com/wordpress-google-analytics-plugin/
5
  * Description: Lets you use <a href="http://analytics.google.com">Google Analytics</a> to track your WordPress site statistics
6
- * Version: 1.0.0
7
  * Author: Aaron D. Campbell
8
  * Author URI: http://xavisys.com/
9
  */
10
 
11
  /**
12
  * Changelog:
 
 
 
13
  * 04/17/2008: 1.0.0
14
  * - Added to wordpress.org repository
15
  *
@@ -159,7 +162,7 @@ class wpGoogleAnalytics {
159
  }
160
 
161
  /**
162
- * This injects the Google Analytics code into the head of the page.
163
  *
164
  * @param bool[optional] $output - defaults to true, false returns but does NOT echo the code
165
  */
@@ -206,8 +209,11 @@ class wpGoogleAnalytics {
206
  if (isset($track)) {
207
  //get the tracking URL
208
  $track['url'] = wpGoogleAnalytics::get_url($track);
209
- //adjust the code that we output
 
210
  $wga['code'] = str_replace("urchinTracker()","urchinTracker('{$track['url']}')", $wga['code']);
 
 
211
  //Echo debug info if needed
212
  if (WGA_DEBUG) {
213
  echo '<pre>',var_dump($track, $site_url),'</pre>';
@@ -290,13 +296,14 @@ class wpGoogleAnalytics {
290
  }
291
 
292
  /**
293
- * If a link is outgoing, add an onclick that runs urchinTracker with a
294
  * generated URL
295
  *
296
  * @param array $m - A match from the preg_replace_callback in self::get_links
297
  * @return string - modified andchor tag
298
  */
299
  function handle_link($m) {
 
300
  //get our site url...used to see if the link is outgoing. We can't use the wordpress setting, because wordpress might not be running at the document root.
301
  $site_url = (($_SERVER['HTTPS'] == 'on')? 'https://':'http://').$_SERVER['HTTP_HOST'];
302
  $link = array_pop($m);
@@ -307,13 +314,15 @@ class wpGoogleAnalytics {
307
  $track['code'] = 'outgoing';
308
  $track['url'] = wpGoogleAnalytics::get_url($track);
309
 
 
 
 
 
310
  //If there is already an onclick, add to the beginning of it (adding to the end will not work, because too many people leave off the ; from the last statement)
311
  if (preg_match("/onclick\s*=\s*(['\"])/iUx",$m[0],$match)) {
312
  //If the onclick uses single quotes, we use double...and vice versa
313
  if ($match[1] == "'" ) {
314
- $onclick = "urchinTracker(\"{$track['url']}\");";
315
- } else {
316
- $onclick = "urchinTracker('{$track['url']}');";
317
  }
318
  $m[0] = str_replace($match[0], $match[0].$onclick, $m[0]);
319
  } else {
3
  * Plugin Name: WP Google Analytics
4
  * Plugin URI: http://xavisys.com/wordpress-google-analytics-plugin/
5
  * Description: Lets you use <a href="http://analytics.google.com">Google Analytics</a> to track your WordPress site statistics
6
+ * Version: 1.1.0
7
  * Author: Aaron D. Campbell
8
  * Author URI: http://xavisys.com/
9
  */
10
 
11
  /**
12
  * Changelog:
13
+ * 04/26/2008: 1.1.0
14
+ * - Major revamp to work better with the new Google Tracking Code. It seems that outgoing links weren't being tracked properly.
15
+ *
16
  * 04/17/2008: 1.0.0
17
  * - Added to wordpress.org repository
18
  *
162
  }
163
 
164
  /**
165
+ * This injects the Google Analytics code into the footer of the page.
166
  *
167
  * @param bool[optional] $output - defaults to true, false returns but does NOT echo the code
168
  */
209
  if (isset($track)) {
210
  //get the tracking URL
211
  $track['url'] = wpGoogleAnalytics::get_url($track);
212
+
213
+ //adjust the code that we output, account for both types of tracking
214
  $wga['code'] = str_replace("urchinTracker()","urchinTracker('{$track['url']}')", $wga['code']);
215
+ $wga['code'] = str_replace("pageTracker._trackPageview()","pageTracker._trackPageview('{$track['url']}')", $wga['code']);
216
+
217
  //Echo debug info if needed
218
  if (WGA_DEBUG) {
219
  echo '<pre>',var_dump($track, $site_url),'</pre>';
296
  }
297
 
298
  /**
299
+ * If a link is outgoing, add an onclick that runs some Google JS with a
300
  * generated URL
301
  *
302
  * @param array $m - A match from the preg_replace_callback in self::get_links
303
  * @return string - modified andchor tag
304
  */
305
  function handle_link($m) {
306
+ $code = wpGoogleAnalytics::get_options('code');
307
  //get our site url...used to see if the link is outgoing. We can't use the wordpress setting, because wordpress might not be running at the document root.
308
  $site_url = (($_SERVER['HTTPS'] == 'on')? 'https://':'http://').$_SERVER['HTTP_HOST'];
309
  $link = array_pop($m);
314
  $track['code'] = 'outgoing';
315
  $track['url'] = wpGoogleAnalytics::get_url($track);
316
 
317
+ // Check which version of the code the user is using, and user proper function
318
+ $function = (strpos($code, 'ga.js') !== false)? 'pageTracker._trackPageview': 'urchinTracker';
319
+ $onclick = "{$function}('{$track['url']}');";
320
+
321
  //If there is already an onclick, add to the beginning of it (adding to the end will not work, because too many people leave off the ; from the last statement)
322
  if (preg_match("/onclick\s*=\s*(['\"])/iUx",$m[0],$match)) {
323
  //If the onclick uses single quotes, we use double...and vice versa
324
  if ($match[1] == "'" ) {
325
+ $onclick = str_replace("'", '"', $onclick);
 
 
326
  }
327
  $m[0] = str_replace($match[0], $match[0].$onclick, $m[0]);
328
  } else {