Google Analyticator - Version 6.2

Version Description

  • Adds a new option for site speed tracking (enabled by default).
  • Replaces deprecated tracking code _setVar with _setCustomVar.
  • Improves the account select dropdown by organizing the accounts. Props bluntly.
  • Prevents post preview pages from being tracked and skewing stats.
Download this release

Release Info

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

Code changes from version 6.1.3 to 6.2

Files changed (2) hide show
  1. google-analyticator.php +96 -39
  2. readme.txt +9 -2
google-analyticator.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
  /*
3
  * Plugin Name: Google Analyticator
4
- * Version: 6.1.3
5
  * Plugin URI: http://ronaldheft.com/code/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 settings page</a> and enter your Google Analytics' UID and enable logging.
7
  * Author: Ronald Heft
@@ -9,7 +9,7 @@
9
  * Text Domain: google-analyticator
10
  */
11
 
12
- define('GOOGLE_ANALYTICATOR_VERSION', '6.1.3');
13
 
14
  // Constants for enabled/disabled state
15
  define("ga_enabled", "enabled", true);
@@ -31,6 +31,7 @@ define("key_ga_outbound_prefix", "ga_outbound_prefix", true);
31
  define("key_ga_downloads", "ga_downloads", true);
32
  define("key_ga_downloads_prefix", "ga_downloads_prefix", true);
33
  define("key_ga_widgets", "ga_widgets", true);
 
34
 
35
  define("ga_uid_default", "XX-XXXXX-X", true);
36
  define("ga_status_default", ga_disabled, true);
@@ -45,6 +46,7 @@ define("ga_outbound_prefix_default", 'outgoing', true);
45
  define("ga_downloads_default", "", true);
46
  define("ga_downloads_prefix_default", "download", true);
47
  define("ga_widgets_default", ga_enabled, true);
 
48
 
49
  // Create the default key and status
50
  add_option(key_ga_status, ga_status_default, '');
@@ -65,6 +67,7 @@ add_option('ga_profileid', '', '');
65
  add_option(key_ga_widgets, ga_widgets_default, '');
66
  add_option('ga_google_token', '', '');
67
  add_option('ga_compatibility', 'off', '');
 
68
 
69
  # Check if we have a version of WordPress greater than 2.8
70
  if ( function_exists('register_widget') ) {
@@ -235,6 +238,12 @@ function ga_options_page() {
235
  if ( $ga_compatibility == '' )
236
  $ga_compatibility = 'off';
237
  update_option('ga_compatibility', $ga_compatibility);
 
 
 
 
 
 
238
 
239
  // Give an updated message
240
  echo "<div class='updated fade'><p><strong>" . __('Google Analyticator settings saved.', 'google-analyticator') . "</strong></p></div>";
@@ -403,6 +412,29 @@ function ga_options_page() {
403
  <p style="margin: 5px 10px;" class="setting-description"><?php _e('Selecting the "Remove" option will physically remove the tracking code from logged in users. Selecting the "Use \'admin\' variable" option will assign a variable called \'admin\' to logged in users. This option will allow Google Analytics\' site overlay feature to work, but you will have to manually configure Google Analytics to exclude tracking from pageviews with the \'admin\' variable.', 'google-analyticator'); ?></p>
404
  </td>
405
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
  <tr>
407
  <th width="30%" valign="top" style="padding-top: 10px;">
408
  <label for="<?php echo key_ga_outbound ?>"><?php _e('Outbound link tracking', 'google-analyticator'); ?>:</label>
@@ -699,14 +731,27 @@ function ga_ajax_accounts()
699
  </th>
700
  <td>
701
  <?php
 
 
 
 
 
 
 
 
 
702
  # Create a select box
703
  echo '<select name="' . key_ga_uid . '" id="' . key_ga_uid . '">';
704
  echo '<option value="XX-XXXXX-X">' . __('Select an Account', 'google-analyticator') . '</option>';
705
 
706
  # The list of accounts
707
- foreach ( $ga_accounts AS $account ) {
708
- $select = ( get_option(key_ga_uid) == $account['ga:webPropertyId'] ) ? ' selected="selected"' : '';
709
- echo '<option value="' . $account['ga:webPropertyId'] . '"' . $select . '>' . $account['title'] . '</option>';
 
 
 
 
710
  }
711
 
712
  # Close the select box
@@ -720,6 +765,10 @@ function ga_ajax_accounts()
720
  die();
721
  }
722
 
 
 
 
 
723
  /**
724
  * Checks if the WordPress API is a valid method for selecting an account
725
  *
@@ -795,26 +844,29 @@ function add_google_analytics()
795
  # Determine if the user is an admin, and should see the tracking code
796
  if ( ( get_option(key_ga_admin) == ga_enabled || !ga_current_user_is(get_option(key_ga_admin_role)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
797
  {
798
- # Add the notice that Google Analyticator tracking is enabled
799
- echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
 
 
 
800
 
801
- # Add the Adsense data if specified
802
- if ( get_option(key_ga_adsense) != '' )
803
- echo '<script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n";
804
 
805
- # Include the file types to track
806
- $extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
807
- $ext = "";
808
- foreach ( $extensions AS $extension )
809
- $ext .= "'$extension',";
810
- $ext = substr($ext, 0, -1);
811
-
812
- # Include the link tracking prefixes
813
- $outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
814
- $downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
815
- $event_tracking = get_option(key_ga_event);
816
 
817
- ?>
 
 
 
 
 
818
  <script type="text/javascript">
819
  var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
820
  <?php if ( $event_tracking != 'enabled' ) { ?>
@@ -824,32 +876,36 @@ function add_google_analytics()
824
  var analyticsEventTracking = '<?php echo $event_tracking; ?>';
825
  </script>
826
  <?php
827
- # Add the first part of the core tracking code
828
- ?>
829
  <script type="text/javascript">
830
  var _gaq = _gaq || [];
831
  _gaq.push(['_setAccount', '<?php echo $uid; ?>']);
832
  <?php
833
 
834
- # Add any tracking code before the trackPageview
835
- do_action('google_analyticator_extra_js_before');
836
- if ( '' != $extra )
837
- echo " $extra\n";
838
 
839
- # Add the track pageview function
840
- echo " _gaq.push(['_trackPageview']);\n";
 
 
 
 
841
 
842
- # Disable page tracking if admin is logged in
843
- if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(key_ga_admin_role)) ) )
844
- echo " _gaq.push(['_setVar', 'admin']);\n";
845
 
846
- # Add any tracking code after the trackPageview
847
- do_action('google_analyticator_extra_js_after');
848
- if ( '' != $extra_after )
849
- echo " $extra_after\n";
850
 
851
- # Add the final section of the tracking code
852
- ?>
853
 
854
  (function() {
855
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
@@ -858,6 +914,7 @@ function add_google_analytics()
858
  })();
859
  </script>
860
  <?php
 
861
  } else {
862
  # Add the notice that Google Analyticator tracking is enabled
863
  echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
1
  <?php
2
  /*
3
  * Plugin Name: Google Analyticator
4
+ * Version: 6.2
5
  * Plugin URI: http://ronaldheft.com/code/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 settings page</a> and enter your Google Analytics' UID and enable logging.
7
  * Author: Ronald Heft
9
  * Text Domain: google-analyticator
10
  */
11
 
12
+ define('GOOGLE_ANALYTICATOR_VERSION', '6.2');
13
 
14
  // Constants for enabled/disabled state
15
  define("ga_enabled", "enabled", true);
31
  define("key_ga_downloads", "ga_downloads", true);
32
  define("key_ga_downloads_prefix", "ga_downloads_prefix", true);
33
  define("key_ga_widgets", "ga_widgets", true);
34
+ define("key_ga_sitespeed", "ga_sitespeed", true);
35
 
36
  define("ga_uid_default", "XX-XXXXX-X", true);
37
  define("ga_status_default", ga_disabled, true);
46
  define("ga_downloads_default", "", true);
47
  define("ga_downloads_prefix_default", "download", true);
48
  define("ga_widgets_default", ga_enabled, true);
49
+ define("ga_sitespeed_default", ga_enabled, true);
50
 
51
  // Create the default key and status
52
  add_option(key_ga_status, ga_status_default, '');
67
  add_option(key_ga_widgets, ga_widgets_default, '');
68
  add_option('ga_google_token', '', '');
69
  add_option('ga_compatibility', 'off', '');
70
+ add_option(key_ga_sitespeed, ga_sitespeed_default, '');
71
 
72
  # Check if we have a version of WordPress greater than 2.8
73
  if ( function_exists('register_widget') ) {
238
  if ( $ga_compatibility == '' )
239
  $ga_compatibility = 'off';
240
  update_option('ga_compatibility', $ga_compatibility);
241
+
242
+ // Update the sitespeed option
243
+ $ga_sitespeed = $_POST[key_ga_sitespeed];
244
+ if (($ga_sitespeed != ga_enabled) && ($ga_sitespeed != ga_disabled))
245
+ $ga_sitespeed = ga_widgets_default;
246
+ update_option(key_ga_sitespeed, $ga_sitespeed);
247
 
248
  // Give an updated message
249
  echo "<div class='updated fade'><p><strong>" . __('Google Analyticator settings saved.', 'google-analyticator') . "</strong></p></div>";
412
  <p style="margin: 5px 10px;" class="setting-description"><?php _e('Selecting the "Remove" option will physically remove the tracking code from logged in users. Selecting the "Use \'admin\' variable" option will assign a variable called \'admin\' to logged in users. This option will allow Google Analytics\' site overlay feature to work, but you will have to manually configure Google Analytics to exclude tracking from pageviews with the \'admin\' variable.', 'google-analyticator'); ?></p>
413
  </td>
414
  </tr>
415
+ <tr>
416
+ <th width="30%" valign="top" style="padding-top: 10px;">
417
+ <label for="<?php echo key_ga_sitespeed ?>"><?php _e('Site speed tracking', 'google-analyticator'); ?>:</label>
418
+ </th>
419
+ <td>
420
+ <?php
421
+ echo "<select name='".key_ga_sitespeed."' id='".key_ga_sitespeed."'>\n";
422
+
423
+ echo "<option value='".ga_enabled."'";
424
+ if(get_option(key_ga_sitespeed) == ga_enabled)
425
+ echo " selected='selected'";
426
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
427
+
428
+ echo "<option value='".ga_disabled."'";
429
+ if(get_option(key_ga_sitespeed) == ga_disabled)
430
+ echo" selected='selected'";
431
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
432
+
433
+ echo "</select>\n";
434
+ ?>
435
+ <p style="margin: 5px 10px;" class="setting-description"><?php _e('Disabling this option will turn off the tracking required for <a href="http://www.google.com/support/analyticshelp/bin/answer.py?hl=en&answer=1205784&topic=1120718&utm_source=gablog&utm_medium=blog&utm_campaign=newga-blog&utm_content=sitespeed">Google Analytics\' Site Speed tracking report</a>.', 'google-analyticator'); ?></p>
436
+ </td>
437
+ </tr>
438
  <tr>
439
  <th width="30%" valign="top" style="padding-top: 10px;">
440
  <label for="<?php echo key_ga_outbound ?>"><?php _e('Outbound link tracking', 'google-analyticator'); ?>:</label>
731
  </th>
732
  <td>
733
  <?php
734
+ // sort the $ga_accounts array by ga:accountName and then title
735
+ $sorted_ga_accounts = array();
736
+ foreach ($ga_accounts as $ga_account) {
737
+ $sorted_ga_accounts[$ga_account['ga:accountName']][] = $ga_account;
738
+ }
739
+ foreach( $sorted_ga_accounts as $id => $sorted_ga_account) {
740
+ usort($sorted_ga_accounts[$id], 'ga_sort_account_list');
741
+ }
742
+
743
  # Create a select box
744
  echo '<select name="' . key_ga_uid . '" id="' . key_ga_uid . '">';
745
  echo '<option value="XX-XXXXX-X">' . __('Select an Account', 'google-analyticator') . '</option>';
746
 
747
  # The list of accounts
748
+ foreach ( $sorted_ga_accounts AS $account_name => $account_list ) {
749
+ echo "<optgroup label='".htmlentities($account_name)."'>\n";
750
+ foreach( $account_list as $account) {
751
+ $select = ( get_option(key_ga_uid) == $account['ga:webPropertyId'] ) ? ' selected="selected"' : '';
752
+ echo '<option value="' . $account['ga:webPropertyId'] . '"' . $select . '>' . $account['title'] . '</option>';
753
+ }
754
+ echo "</optgroup>\n";
755
  }
756
 
757
  # Close the select box
765
  die();
766
  }
767
 
768
+ function ga_sort_account_list($a, $b) {
769
+ return strcmp($a['title'],$b['title']);
770
+ }
771
+
772
  /**
773
  * Checks if the WordPress API is a valid method for selecting an account
774
  *
844
  # Determine if the user is an admin, and should see the tracking code
845
  if ( ( get_option(key_ga_admin) == ga_enabled || !ga_current_user_is(get_option(key_ga_admin_role)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
846
  {
847
+ # Disable the tracking code on the post preview page
848
+ if ( !function_exists("is_preview") || ( function_exists("is_preview") && !is_preview() ) )
849
+ {
850
+ # Add the notice that Google Analyticator tracking is enabled
851
+ echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
852
 
853
+ # Add the Adsense data if specified
854
+ if ( get_option(key_ga_adsense) != '' )
855
+ echo '<script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n";
856
 
857
+ # Include the file types to track
858
+ $extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
859
+ $ext = "";
860
+ foreach ( $extensions AS $extension )
861
+ $ext .= "'$extension',";
862
+ $ext = substr($ext, 0, -1);
 
 
 
 
 
863
 
864
+ # Include the link tracking prefixes
865
+ $outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
866
+ $downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
867
+ $event_tracking = get_option(key_ga_event);
868
+
869
+ ?>
870
  <script type="text/javascript">
871
  var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
872
  <?php if ( $event_tracking != 'enabled' ) { ?>
876
  var analyticsEventTracking = '<?php echo $event_tracking; ?>';
877
  </script>
878
  <?php
879
+ # Add the first part of the core tracking code
880
+ ?>
881
  <script type="text/javascript">
882
  var _gaq = _gaq || [];
883
  _gaq.push(['_setAccount', '<?php echo $uid; ?>']);
884
  <?php
885
 
886
+ # Add any tracking code before the trackPageview
887
+ do_action('google_analyticator_extra_js_before');
888
+ if ( '' != $extra )
889
+ echo " $extra\n";
890
 
891
+ # Add the track pageview function
892
+ echo " _gaq.push(['_trackPageview']);\n";
893
+
894
+ # Add the site speed tracking
895
+ if ( get_option(key_ga_sitespeed) == ga_enabled )
896
+ echo " _gaq.push(['_trackPageLoadTime']);\n";
897
 
898
+ # Disable page tracking if admin is logged in
899
+ if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(key_ga_admin_role)) ) )
900
+ echo " _gaq.push(['_setCustomVar', 'admin']);\n";
901
 
902
+ # Add any tracking code after the trackPageview
903
+ do_action('google_analyticator_extra_js_after');
904
+ if ( '' != $extra_after )
905
+ echo " $extra_after\n";
906
 
907
+ # Add the final section of the tracking code
908
+ ?>
909
 
910
  (function() {
911
  var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
914
  })();
915
  </script>
916
  <?php
917
+ }
918
  } else {
919
  # Add the notice that Google Analyticator tracking is enabled
920
  echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://ronaldheft.com/code/donate/
4
  Tags: stats, statistics, google, analytics, google analytics, tracking, widget
5
  Requires at least: 2.7
6
  Tested up to: 3.2
7
- Stable tag: 6.1.3
8
 
9
  Adds the necessary JavaScript code to enable Google Analytics. Includes widgets for Analytics data display.
10
 
@@ -16,12 +16,13 @@ Google Analyticator adds the necessary JavaScript code to enable Google Analytic
16
 
17
  Google Analyticator Has the Following Features:
18
 
19
- - **NEW!** Supports standard Google Analytics tracking via the latest async tracking methods (faster and more reliable than the older ga.js tracking method)
20
  - Includes an admin dashboard widget that displays a graph of the last 30 days of visitors, a summary of site usage, the top pages, the top referrers, and the top searches
21
  - Includes a widget that can be used to display visitor stat information on the front-end
22
  - Supports outbound link tracking of all links on the page, including links not managed by WordPress
23
  - Supports download link tracking
24
  - Supports event tracking with outbound links / downloads instead of the old pageview tracking method
 
25
  - Allows hiding of Administrator visits without affecting Google Analytics' site overlay feature
26
  - Supports any advanced tracking code Google provides
27
  - Installs easily - unlike other plugins, the user doesn't even have to know their Analytics UID
@@ -49,6 +50,12 @@ Please visit [Google Analyticator's support forum](http://forums.ronaldheft.com/
49
 
50
  == Changelog ==
51
 
 
 
 
 
 
 
52
  = 6.1.3 =
53
  * Fixes a Javascript error on the WordPress login page.
54
  * Improves profile id logic to hopefully fix dashboard errors for the people that experience them.
4
  Tags: stats, statistics, google, analytics, google analytics, tracking, widget
5
  Requires at least: 2.7
6
  Tested up to: 3.2
7
+ Stable tag: 6.2
8
 
9
  Adds the necessary JavaScript code to enable Google Analytics. Includes widgets for Analytics data display.
10
 
16
 
17
  Google Analyticator Has the Following Features:
18
 
19
+ - Supports standard Google Analytics tracking via the latest async tracking methods (faster and more reliable than the older ga.js tracking method)
20
  - Includes an admin dashboard widget that displays a graph of the last 30 days of visitors, a summary of site usage, the top pages, the top referrers, and the top searches
21
  - Includes a widget that can be used to display visitor stat information on the front-end
22
  - Supports outbound link tracking of all links on the page, including links not managed by WordPress
23
  - Supports download link tracking
24
  - Supports event tracking with outbound links / downloads instead of the old pageview tracking method
25
+ - **NEW!** Support site speed tracking
26
  - Allows hiding of Administrator visits without affecting Google Analytics' site overlay feature
27
  - Supports any advanced tracking code Google provides
28
  - Installs easily - unlike other plugins, the user doesn't even have to know their Analytics UID
50
 
51
  == Changelog ==
52
 
53
+ = 6.2 =
54
+ * Adds a new option for site speed tracking (enabled by default).
55
+ * Replaces deprecated tracking code _setVar with _setCustomVar.
56
+ * Improves the account select dropdown by organizing the accounts. Props bluntly.
57
+ * Prevents post preview pages from being tracked and skewing stats.
58
+
59
  = 6.1.3 =
60
  * Fixes a Javascript error on the WordPress login page.
61
  * Improves profile id logic to hopefully fix dashboard errors for the people that experience them.