WP Google Analytics - Version 1.2.0

Version Description

Download this release

Release Info

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

Code changes from version 1.1.0 to 1.2.0

Files changed (2) hide show
  1. readme.txt +1 -1
  2. wp-google-analytics.php +144 -45
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.1.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.2.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,20 @@
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
  *
@@ -68,33 +75,6 @@ class wpGoogleAnalytics {
68
  */
69
  global $wp_roles;
70
 
71
- //Deal with the data when submitted
72
- if (isset($_POST['wga_submit'])) {
73
- //Google Analytics Code
74
- $_POST['wga']['code'] = stripslashes($_POST['wga']['code']);
75
- //Special logging of 404s
76
- $_POST['wga']['log_404s'] = (!isset($_POST['wga']['log_404s']) || strtolower($_POST['wga']['log_404s']) != 'true')? 'false':'true';
77
- //Special logging of searches
78
- $_POST['wga']['log_searches'] = (!isset($_POST['wga']['log_searches']) || strtolower($_POST['wga']['log_searches']) != 'true')? 'false':'true';
79
- //Special logging of outgoing link
80
- $_POST['wga']['log_outgoing'] = (!isset($_POST['wga']['log_outgoing']) || strtolower($_POST['wga']['log_outgoing']) != 'true')? 'false':'true';
81
- //Ignore admin area
82
- $_POST['wga']['ignore_admin_area'] = (!isset($_POST['wga']['ignore_admin_area']) || strtolower($_POST['wga']['ignore_admin_area']) != 'true')? 'false':'true';
83
- //Add/remove wga_no_track capability for each role
84
- foreach ($wp_roles->roles as $role=>$role_info) {
85
- if (isset($_POST['wga']['role'][$role]) && $_POST['wga']['role'][$role] == 'true') {
86
- $wp_roles->add_cap($role, 'wga_no_track', true);
87
- } else {
88
- $wp_roles->add_cap($role, 'wga_no_track', false);
89
- }
90
- }
91
- //We don't need to store this in our setting
92
- unset($_POST['wga']['role']);
93
- //update our option
94
- update_option('wga', $_POST['wga']);
95
- echo '<div class="updated fade"><p>'.__('Options Updated.').'</p></div>';
96
- }
97
-
98
  //Get our options
99
  $wga = wpGoogleAnalytics::get_options();
100
  //Echo debug info if needed
@@ -106,30 +86,66 @@ class wpGoogleAnalytics {
106
  foreach ($wp_roles->roles as $role=>$role_info) {
107
  $checked = (isset($role_info['capabilities']['wga_no_track']) && $role_info['capabilities']['wga_no_track'])? ' checked="checked"':'';
108
  $role_info['name'] .= (strtolower(substr($role_info['name'], -1)) != 's')? 's':'';
109
- $roles .= " <label for='wga_role_{$role}'><input type='checkbox' name='wga[role][{$role}]' value='true' id='wga_role_{$role}'{$checked} /> ".__("Do not log {$role_info['name']} when logged in")."</label><br />";
110
  }
111
  ?>
112
  <div class="wrap">
113
  <h2><?php _e('Google Analytics Options') ?></h2>
114
- <form action="" method="post" id="wp_google_analytics">
115
- <fieldset class="options">
116
- <legend><?php _e('Google Analytics Code'); ?></legend>
117
- <label for="wga_code">
118
- <?php _e('Paste your <a href="http://analytics.google.com">Google Analytics</a> code into the textarea:'); ?><br /><br />
119
- <textarea name="wga[code]" id="wga_code" style="width:400px; height:150px;"><?php echo htmlentities($wga['code']); ?></textarea><br /><br />
120
- </label>
121
- <label for="wga_ignore_admin_area"><input type="checkbox" name="wga[ignore_admin_area]" value="true" id="wga_ignore_admin_area" <?php if ($wga['ignore_admin_area'] == 'true') { echo ' checked="checked"';} ?> /> <?php _e('Do not log anything in the admin area'); ?></label><br />
122
- <label for="wga_log_404s"><input type="checkbox" name="wga[log_404s]" value="true" id="wga_log_404s" <?php if ($wga['log_404s'] == 'true') { echo ' checked="checked"';} ?> /> <?php _e('Log 404 errors as /404/{url}?referrer={referrer}'); ?></label><br />
123
- <label for="wga_log_searches"><input type="checkbox" name="wga[log_searches]" value="true" id="wga_log_searches" <?php if ($wga['log_searches'] == 'true') { echo ' checked="checked"';} ?> /> <?php _e('Log searches as /search/{search}?referrer={referrer}'); ?></label><br />
124
- <label for="wga_log_outgoing"><input type="checkbox" name="wga[log_outgoing]" value="true" id="wga_log_outgoing" <?php if ($wga['log_outgoing'] == 'true') { echo ' checked="checked"';} ?> /> <?php _e('Log outgoing links as /outgoing/{url}?referrer={referrer}'); ?></label><br />
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  <?php echo $roles; ?>
126
- </fieldset>
 
 
127
  <p class="submit">
128
- <input type="submit" name="wga_submit" value="Update Options &raquo;" />
129
  </p>
 
 
130
  </form>
131
  </div>
132
  <?php
 
133
  }
134
 
135
  /**
@@ -260,8 +276,8 @@ class wpGoogleAnalytics {
260
  */
261
  function start_ob() {
262
  $log_outgoing = wpGoogleAnalytics::get_options('log_outgoing');
263
- //Only start the output buffering if we care, and if it's NOT an XMLRPC REQUEST
264
- if (($log_outgoing == 'true' || $log_outgoing === false) && (!defined('XMLRPC_REQUEST') || !XMLRPC_REQUEST)) {
265
  ob_start(array('wpGoogleAnalytics', 'get_links'));
266
  }
267
  }
@@ -348,12 +364,95 @@ class wpGoogleAnalytics {
348
  }
349
  return $static;
350
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  }
352
 
353
  /**
354
  * Add the necessary hooks
355
  */
356
  add_action('admin_menu', array('wpGoogleAnalytics','admin_menu'));
357
- add_action('wp_footer', array('wpGoogleAnalytics', 'insert_code'));
358
  add_action('init', array('wpGoogleAnalytics', 'start_ob'));
 
 
359
  ?>
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.2.0
7
  * Author: Aaron D. Campbell
8
  * Author URI: http://xavisys.com/
9
  */
10
 
11
+ define('WGA_VERSION', '1.2.0');
12
  /**
13
  * Changelog:
14
+ * 05/18/2008: 1.2.0
15
+ * - No longer parses outgoing links in the admin section.
16
+ * - Uses get_footer instead of wp_footer. Too many themes aren't adding the wp_footer call.
17
+ * - Options page updated
18
+ * - Added optional anonymous statistics collection
19
+ *
20
  * 04/26/2008: 1.1.0
21
  * - Major revamp to work better with the new Google Tracking Code. It seems that outgoing links weren't being tracked properly.
22
  *
75
  */
76
  global $wp_roles;
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  //Get our options
79
  $wga = wpGoogleAnalytics::get_options();
80
  //Echo debug info if needed
86
  foreach ($wp_roles->roles as $role=>$role_info) {
87
  $checked = (isset($role_info['capabilities']['wga_no_track']) && $role_info['capabilities']['wga_no_track'])? ' checked="checked"':'';
88
  $role_info['name'] .= (strtolower(substr($role_info['name'], -1)) != 's')? 's':'';
89
+ $roles .= " <label for='wga_role_{$role}'><input type='checkbox' name='wga-roles[{$role}]' value='true' id='wga_role_{$role}'{$checked} /> ".__("Do not log {$role_info['name']} when logged in")."</label><br />";
90
  }
91
  ?>
92
  <div class="wrap">
93
  <h2><?php _e('Google Analytics Options') ?></h2>
94
+ <form action="options.php" method="post" id="wp_google_analytics">
95
+ <?php wp_nonce_field('update-options'); ?>
96
+ <p>Google Maps for WordPress will allow you to easily add maps to your posts or pages.</p>
97
+ <table class="form-table">
98
+ <tr valign="top">
99
+ <th scope="row">
100
+ <label for="wga_code"><?php _e('Paste your <a href="http://analytics.google.com">Google Analytics</a> code into the textarea:'); ?></label>
101
+ </th>
102
+ <td>
103
+ <textarea name="wga[code]" id="wga_code" style="width:95%;" rows="10"><?php echo htmlentities($wga['code']); ?></textarea>
104
+ </td>
105
+ </tr>
106
+ <tr valign="top">
107
+ <th scope="row">
108
+ <a title="<?php _e('Click for Help!'); ?>" href="#" onclick="jQuery('#wga_user_agreed_to_send_system_information_help').toggle(); return false;">
109
+ <?php _e('System Information:') ?>
110
+ </a>
111
+ </th>
112
+ <td>
113
+ <label for="wga_user_agreed_to_send_system_information"><input type="checkbox" name="wga[user_agreed_to_send_system_information]" value="true" id="wga_user_agreed_to_send_system_information"<?php checked('true', $wga['user_agreed_to_send_system_information']); ?> /> <?php _e('I agree to send anonymous system information'); ?></label><br />
114
+ <small id="wga_user_agreed_to_send_system_information_help" style="display:none;">
115
+ <?php _e('You can help by sending anonymous system information that will help Xavisys make better decisions about new features.'); ?><br />
116
+ <?php _e('The information will be sent anonymously, but a unique identifier will be sent to prevent duplicate entries from the same installation.'); ?>
117
+ </small>
118
+ </td>
119
+ </tr>
120
+ <tr valign="top">
121
+ <th scope="row">
122
+ <?php _e('Additional items to log:') ?>
123
+ </th>
124
+ <td>
125
+ <label for="wga_log_404s"><input type="checkbox" name="wga[log_404s]" value="true" id="wga_log_404s"<?php checked('true', $wga['log_404s']); ?> /> <?php _e('Log 404 errors as /404/{url}?referrer={referrer}'); ?></label><br />
126
+ <label for="wga_log_searches"><input type="checkbox" name="wga[log_searches]" value="true" id="wga_log_searches"<?php checked('true', $wga['log_searches']); ?> /> <?php _e('Log searches as /search/{search}?referrer={referrer}'); ?></label><br />
127
+ <label for="wga_log_outgoing"><input type="checkbox" name="wga[log_outgoing]" value="true" id="wga_log_outgoing"<?php checked('true', $wga['log_outgoing']); ?> /> <?php _e('Log outgoing links as /outgoing/{url}?referrer={referrer}'); ?></label><br />
128
+ </td>
129
+ </tr>
130
+ <tr valign="top">
131
+ <th scope="row">
132
+ <?php _e('Visits to ignore:') ?>
133
+ </th>
134
+ <td>
135
+ <label for="wga_ignore_admin_area"><input type="checkbox" name="wga[ignore_admin_area]" value="true" id="wga_ignore_admin_area"<?php checked('true', $wga['ignore_admin_area']); ?> /> <?php _e('Do not log anything in the admin area'); ?></label><br />
136
  <?php echo $roles; ?>
137
+ </td>
138
+ </tr>
139
+ </table>
140
  <p class="submit">
141
+ <input type="submit" name="Submit" value="<?php _e('Update Options &raquo;'); ?>" />
142
  </p>
143
+ <input type="hidden" name="action" value="update" />
144
+ <input type="hidden" name="page_options" value="wga,wga-roles" />
145
  </form>
146
  </div>
147
  <?php
148
+ wpGoogleAnalytics::outputSendInfoForm();
149
  }
150
 
151
  /**
276
  */
277
  function start_ob() {
278
  $log_outgoing = wpGoogleAnalytics::get_options('log_outgoing');
279
+ // Only start the output buffering if we care, and if it's NOT an XMLRPC REQUEST
280
+ if (($log_outgoing == 'true' || $log_outgoing === false) && (!defined('XMLRPC_REQUEST') || !XMLRPC_REQUEST) && !is_admin()) {
281
  ob_start(array('wpGoogleAnalytics', 'get_links'));
282
  }
283
  }
364
  }
365
  return $static;
366
  }
367
+
368
+ function updateOption($oldValue, $newValue) {
369
+ /**
370
+ * @var WP_Roles
371
+ */
372
+ global $wp_roles;
373
+
374
+ //Add/remove wga_no_track capability for each role
375
+ foreach ($wp_roles->roles as $role=>$role_info) {
376
+ if (isset($newValue[$role]) && $newValue[$role] == 'true') {
377
+ $wp_roles->add_cap($role, 'wga_no_track', true);
378
+ } else {
379
+ $wp_roles->add_cap($role, 'wga_no_track', false);
380
+ }
381
+ }
382
+ }
383
+
384
+ function activatePlugin() {
385
+ // If the wga-id has not been generated, generate one and store it.
386
+ $o = get_option('wga');
387
+ $wgaId = wpGoogleAnalytics::get_wgaId();
388
+ if (!isset($o['user_agreed_to_send_system_information'])) {
389
+ $o['user_agreed_to_send_system_information'] = 'true';
390
+ update_option('wga', $o);
391
+ }
392
+ }
393
+
394
+ function get_wgaId() {
395
+ $wgaId = get_option('wga-id');
396
+ if ($wgaId === false) {
397
+ $wgaId = sha1( get_bloginfo('url') . mt_rand() );
398
+ update_option('wga-id', $wgaId);
399
+ }
400
+ return $wgaId;
401
+ }
402
+ /**
403
+ * if user agrees to send system information and the last sent info is outdated outputs a bunch of stuff that sends sysinfo without interrupting
404
+ */
405
+ function outputSendInfoForm()
406
+ {
407
+ $o = get_option('wga');
408
+ if ($o['user_agreed_to_send_system_information'] == 'true') {
409
+ $lastSent = get_option('wga-sysinfo');
410
+ $sysinfo = wpGoogleAnalytics::get_sysinfo();
411
+ if (serialize($lastSent) != serialize($sysinfo)) {
412
+ ?>
413
+ <iframe id="hidden_frame" name="hidden_frame" style="width:0px; height:0px; border: 0px" src="about:blank"></iframe>
414
+ <form id="wga_send_info_form" target="hidden_frame" method="post" action="http://xavisys.com/plugin-info.php">
415
+ <?php
416
+ foreach($sysinfo as $k=>$v)
417
+ {
418
+ ?>
419
+ <input type="hidden" name="<?php echo attribute_escape($k); ?>" value="<?php echo attribute_escape($v);?>"></input>
420
+ <?php
421
+ }
422
+ ?>
423
+ </form>
424
+ <script type='text/javascript'>
425
+ jQuery('#wga_send_info_form').submit();
426
+ </script>
427
+ <?php
428
+ update_option('wga-sysinfo', $sysinfo);
429
+ }
430
+ }
431
+ }
432
+ function get_sysinfo()
433
+ {
434
+ global $wpdb;
435
+ $s = array();
436
+ $s['plugin'] = 'WP Google Analytics';
437
+ $s['id'] = wpGoogleAnalytics::get_wgaId();
438
+ $s['version'] = WGA_VERSION;
439
+
440
+ $s['php_version'] = phpversion();
441
+ $s['mysql_version'] = @mysql_get_server_info($wpdb->dbh);
442
+ $s['server_software'] = $_SERVER["SERVER_SOFTWARE"];
443
+ $s['memory_limit'] = ini_get('memory_limit');
444
+
445
+ return $s;
446
+ }
447
+
448
  }
449
 
450
  /**
451
  * Add the necessary hooks
452
  */
453
  add_action('admin_menu', array('wpGoogleAnalytics','admin_menu'));
454
+ add_action('get_footer', array('wpGoogleAnalytics', 'insert_code'));
455
  add_action('init', array('wpGoogleAnalytics', 'start_ob'));
456
+ add_action('update_option_wga-roles', array('wpGoogleAnalytics', 'updateOption'), null, 2);
457
+ add_action('activate_wp-google-analytics/wp-google-analytics.php', array('wpGoogleAnalytics', 'updateOption'));
458
  ?>