Google Analytics for WordPress by MonsterInsights - Version 4.0.6

Version Description

  • Bugs fixed in this release:
    • Sanitizing relative URL's could go wrong on some blogs installed in subdirectories.
    • Comment form tracking only worked for posts, not for pages, and would sometimes cause other issues. Patch by Milan Dini.
    • Settings page: now correctly hiding internal links to track as outbound block when outbound link tracking is disabled.
  • Code sanitization:
    • Hardcoded the scope for custom variables to prevent that from possibly going wrong.
    • Improved method of determining whether current user should be tracked or not.
    • Added plugin version number in script branding comment, and moved branding comment to within CDATA section to assist in debugging, even when people use W3TC or another form of code minification.
  • Documentation fixes:
    • Updated custom variable order in settings panel to reflect order of tracking. You can now determine their index key by counting down, first checked box is index 1, second 2, etc.
    • Ignored users dropdown now correctly reflects that ignoring subcribers and up means ignoring ALL logged in users.
Download this release

Release Info

Developer joostdevalk
Plugin Icon 128x128 Google Analytics for WordPress by MonsterInsights
Version 4.0.6
Comparing to
See all releases

Code changes from version 4.0.5 to 4.0.6

Files changed (3) hide show
  1. googleanalytics.php +88 -74
  2. readme.txt +14 -1
  3. yst_plugin_tools.css +10 -0
googleanalytics.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
  /*
3
  Plugin Name: Google Analytics for WordPress
4
- Plugin URI: http://yoast.com/wordpress/analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=google-analytics-for-wordpress&utm_content=v405
5
  Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. custom variables and automatic clickout and download tracking.
6
  Author: Joost de Valk
7
- Version: 4.0.5
8
  Requires at least: 2.8
9
  Author URI: http://yoast.com/
10
  License: GPL
@@ -106,16 +106,21 @@ if ( ! class_exists( 'GA_Admin' ) ) {
106
  jQuery('#uastring_automatic').css('display','block');
107
  }
108
  }).change();
 
 
 
 
 
 
 
109
  jQuery('#advancedsettings').change(function(){
110
  if ((jQuery('#advancedsettings').attr('checked')) == true) {
111
  jQuery('#advancedgasettings').css("display","block");
112
  jQuery('#customvarsettings').css("display","block");
113
- jQuery('#internallinktracking').css("display","block");
114
  jQuery('#toc').css("display","block");
115
  } else {
116
  jQuery('#advancedgasettings').css("display","none");
117
  jQuery('#customvarsettings').css("display","none");
118
- jQuery('#internallinktracking').css("display","none");
119
  jQuery('#toc').css("display","none");
120
  }
121
  }).change();
@@ -142,7 +147,7 @@ if ( ! class_exists( 'GA_Admin' ) ) {
142
  jQuery('#uastring').change(function(){
143
  if ((jQuery('#switchtomanual').attr('checked')) == true) {
144
  if (!jQuery(this).val().match(/^UA-[\d-]+$/)) {
145
- alert("That's not a valid UA ID, please make sure it looks something like this: UA-1234567-123, and that there are no spaces or other characters in the input field.");
146
  jQuery(this).focus();
147
  }
148
  }
@@ -225,13 +230,16 @@ if ( ! class_exists( 'GA_Admin' ) ) {
225
 
226
  function upgrade() {
227
  $options = get_option($this->optionname);
228
- if ($options['version'] != '4.0.4') {
229
  if ( !isset($options['trackcommentform']) || $options['trackcommentform'] == '')
230
  $options['trackcommentform'] = true;
231
  if ( !isset($options['ignore_userlevel']) || $options['ignore_userlevel'] == '')
232
  $options['ignore_userlevel'] = 11;
233
 
234
- $options['version'] = '4.0.4';
 
 
 
235
  }
236
  update_option($this->optionname, $options);
237
  }
@@ -429,24 +437,18 @@ if ( ! class_exists( 'GA_Admin' ) ) {
429
  'desc' => 'Allows you to easily remove logged in users from your reports, or to segment by different user roles. The users primary role will be logged.',
430
  'content' => $this->checkbox('cv_loggedin'),
431
  );
 
 
 
 
 
 
432
  $rows[] = array(
433
  'id' => 'cv_authorname',
434
  'label' => 'Author Name',
435
  'desc' => 'Allows you to see pageviews per author.',
436
  'content' => $this->checkbox('cv_authorname'),
437
  );
438
- $rows[] = array(
439
- 'id' => 'cv_category',
440
- 'label' => 'Single Category',
441
- 'desc' => 'Allows you to see pageviews per category, works best when each post is in only one category.',
442
- 'content' => $this->checkbox('cv_category'),
443
- );
444
- $rows[] = array(
445
- 'id' => 'cv_all_categories',
446
- 'label' => 'All Categories',
447
- 'desc' => 'Allows you to see pageviews per category using advanced segments, should be used when you use multiple categories per post.',
448
- 'content' => $this->checkbox('cv_all_categories'),
449
- );
450
  $rows[] = array(
451
  'id' => 'cv_tags',
452
  'label' => 'Tags',
@@ -460,11 +462,18 @@ if ( ! class_exists( 'GA_Admin' ) ) {
460
  'content' => $this->checkbox('cv_year'),
461
  );
462
  $rows[] = array(
463
- 'id' => 'cv_post_type',
464
- 'label' => 'Post type',
465
- 'desc' => 'Allows you to see pageviews per post type, especially useful if you use multiple custom post types.',
466
- 'content' => $this->checkbox('cv_post_type'),
467
  );
 
 
 
 
 
 
 
468
  $this->postbox('customvarsettings','Custom Variables Settings',$pre_content.$this->form_table($rows).$this->save_button());
469
 
470
  $rows = array();
@@ -478,7 +487,7 @@ if ( ! class_exists( 'GA_Admin' ) ) {
478
  '5' => 'Editor',
479
  '2' => 'Author',
480
  '1' => 'Contributor',
481
- '0' => 'Subscriber',
482
  )),
483
  );
484
  $rows[] = array(
@@ -658,7 +667,7 @@ if ( ! class_exists( 'GA_Admin' ) ) {
658
  if ( count($modules) > 0 )
659
  $this->postbox('toc','List of Available Modules',$this->toc($modules));
660
  $this->plugin_like();
661
- $this->postbox('donate','Donate $5, $10 or $20 now!','<p>This plugin has cost me countless hours of work, if you use it, please donate a token of your appreciation!</p><br/><form style="margin-left:50px;" action="https://www.paypal.com/cgi-bin/webscr" method="post">
662
  <input type="hidden" name="cmd" value="_s-xclick">
663
  <input type="hidden" name="hosted_button_id" value="FW9FK4EBZ9FVJ">
664
  <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
@@ -737,9 +746,8 @@ if ( ! class_exists( 'GA_Filter' ) ) {
737
  * Insert the tracking code into the page
738
  */
739
  function spool_analytics() {
740
- global $wp_query, $current_user;
741
  // echo '<!--'.print_r($wp_query,1).'-->';
742
- // echo '<!--'.print_r($current_user,1).'-->';
743
 
744
  $options = get_option('Yoast_Google_Analytics');
745
 
@@ -747,7 +755,7 @@ if ( ! class_exists( 'GA_Filter' ) ) {
747
  * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
748
  */
749
  $customvarslot = 1;
750
- if ( $options["uastring"] != "" && !($current_user->user_level >= $options["ignore_userlevel"]) && !is_preview() ) {
751
  $push = array();
752
 
753
  if ( $options['allowanchor'] )
@@ -767,8 +775,9 @@ if ( ! class_exists( 'GA_Filter' ) ) {
767
  }
768
 
769
  if ( $options['cv_loggedin'] ) {
770
- if ( $current_user->ID != 0 )
771
- $push[] = "'_setCustomVar',".$customvarslot.",'logged-in','".$current_user->roles[0]."',1";
 
772
  // Customvar slot needs to be upped even when the user is not logged in, to make sure the variables below are always in the same slot.
773
  $customvarslot++;
774
  }
@@ -777,12 +786,12 @@ if ( ! class_exists( 'GA_Filter' ) ) {
777
  if ( $options['cv_post_type'] ) {
778
  $post_type = get_post_type();
779
  if ( $post_type ) {
780
- $push[] = "'_setCustomVar',".$customvarslot.",'post_type','".$post_type."'";
781
  $customvarslot++;
782
  }
783
  }
784
  if ( $options['cv_authorname'] ) {
785
- $push[] = "'_setCustomVar',".$customvarslot.",'author','".GA_Filter::ga_str_clean(get_the_author_meta('display_name',$wp_query->post->post_author))."'";
786
  $customvarslot++;
787
  }
788
  if ( $options['cv_tags'] ) {
@@ -796,17 +805,17 @@ if ( ! class_exists( 'GA_Filter' ) ) {
796
  }
797
  // Max 64 chars for value and label combined, hence 64 - 4
798
  $tagsstr = substr($tagsstr, 0, 60);
799
- $push[] = "'_setCustomVar',".$customvarslot.",'tags','".$tagsstr."'";
800
  $customvarslot++;
801
  }
802
  if ( is_single() ) {
803
  if ( $options['cv_year'] ) {
804
- $push[] = "'_setCustomVar',".$customvarslot.",'year','".get_the_time('Y')."'";
805
  $customvarslot++;
806
  }
807
  if ( $options['cv_category'] ) {
808
  $cats = get_the_category();
809
- $push[] = "'_setCustomVar',".$customvarslot.",'category','".$cats[0]->slug."'";
810
  $customvarslot++;
811
  }
812
  if ( $options['cv_all_categories'] ) {
@@ -820,7 +829,7 @@ if ( ! class_exists( 'GA_Filter' ) ) {
820
  }
821
  // Max 64 chars for value and label combined, hence 64 - 10
822
  $catsstr = substr($catsstr, 0, 54);
823
- $push[] = "'_setCustomVar',".$customvarslot.",'categories','".$catsstr."'";
824
  $customvarslot++;
825
  }
826
  }
@@ -868,8 +877,8 @@ if ( ! class_exists( 'GA_Filter' ) ) {
868
 
869
  ?>
870
 
871
- <!-- Google Analytics for WordPress by Yoast v4.0 | http://yoast.com/wordpress/google-analytics/ -->
872
  <script type="text/javascript">//<![CDATA[
 
873
  var _gaq = _gaq || [];
874
  _gaq.push(['_setAccount','<?php echo $options["uastring"]; ?>']);
875
  <?php
@@ -896,8 +905,9 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
896
 
897
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
898
  })();
 
899
  //]]></script>
900
- <!-- End of Google Analytics for WordPress by Yoast v4.0 -->
901
  <?php
902
  } else if ( $options["uastring"] != "" ) {
903
  echo "<!-- Google Analytics tracking code not shown because users over level ".$options["ignore_userlevel"]." are ignored -->\n";
@@ -911,7 +921,7 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
911
  */
912
  function spool_adsense() {
913
  $options = get_option('Yoast_Google_Analytics');
914
- if ( $options["uastring"] != "" && !($current_user->user_level >= $options["ignore_userlevel"]) && !is_preview() ) {
915
  echo '<script type="text/javascript">'."\n";
916
  echo "\t".'window.google_analytics_uacct = "'.$options["uastring"].'";'."\n";
917
  echo '</script>'."\n";
@@ -1020,9 +1030,7 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1020
  }
1021
 
1022
  function widget_content($text) {
1023
- global $current_user;
1024
- $options = get_option('Yoast_Google_Analytics');
1025
- if ($current_user->user_level >= $options["ignore_userlevel"])
1026
  return $text;
1027
  static $anchorPattern = '/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
1028
  $text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_widget_link'),$text);
@@ -1030,9 +1038,7 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1030
  }
1031
 
1032
  function the_content($text) {
1033
- global $current_user;
1034
- $options = get_option('Yoast_Google_Analytics');
1035
- if ($current_user->user_level >= $options["ignore_userlevel"])
1036
  return $text;
1037
 
1038
  if (!is_feed()) {
@@ -1043,9 +1049,7 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1043
  }
1044
 
1045
  function comment_text($text) {
1046
- global $current_user;
1047
- $options = get_option('Yoast_Google_Analytics');
1048
- if ($current_user->user_level >= $options["ignore_userlevel"])
1049
  return $text;
1050
 
1051
  if (!is_feed()) {
@@ -1056,9 +1060,7 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1056
  }
1057
 
1058
  function comment_author_link($text) {
1059
- global $current_user;
1060
- $options = get_option('Yoast_Google_Analytics');
1061
- if ($current_user->user_level >= $options["ignore_userlevel"])
1062
  return $text;
1063
 
1064
  static $anchorPattern = '/(.*\s+.*?href\s*=\s*)["\'](.*?)["\'](.*)/';
@@ -1078,9 +1080,7 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1078
  }
1079
 
1080
  function bookmarks($bookmarks) {
1081
- global $current_user;
1082
- $options = get_option('Yoast_Google_Analytics');
1083
- if ($current_user->user_level >= $options["ignore_userlevel"])
1084
  return $bookmarks;
1085
 
1086
  $i = 0;
@@ -1231,12 +1231,27 @@ function ga_utm_hashtag_redirect() {
1231
  }
1232
  }
1233
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1234
  function track_comment_form_head() {
1235
- if (is_single()) {
1236
- global $post;
1237
- if ('open' == $post->comment_status)
1238
- wp_enqueue_script('jquery');
1239
- }
 
1240
  }
1241
  add_action('wp_print_scripts','track_comment_form_head');
1242
 
@@ -1249,20 +1264,22 @@ function yoast_get_comment_form_id($args) {
1249
  add_filter('comment_form_defaults', 'yoast_get_comment_form_id',99,1);
1250
 
1251
  function yoast_track_comment_form() {
1252
- global $comment_form_id, $post;
1253
- $yoast_ga_options = get_option('Yoast_Google_Analytics');
 
1254
  ?>
1255
  <script type="text/javascript" charset="utf-8">
1256
- jQuery(document).ready(function() {
1257
- jQuery('#<?php echo $comment_form_id; ?>').submit(function() {
1258
- _gaq.push(
1259
- ['_setAccount','<?php echo $yoast_ga_options["uastring"]; ?>'],
1260
- ['_trackEvent','comment']
1261
- );
1262
- });
1263
- });
1264
  </script>
1265
  <?php
 
1266
  }
1267
  add_action('comment_form_after','yoast_track_comment_form');
1268
  /*
@@ -1291,11 +1308,8 @@ add_action('wp_footer','gfform_tag',10);
1291
  */
1292
 
1293
  function yoast_sanitize_relative_links($content) {
1294
- $blogurl = get_bloginfo('url');
1295
- if (substr($blogurl, -1) == "/") {
1296
- $blogurl = substr($blogurl, 0, strlen($blogurl));
1297
- }
1298
- $content = preg_replace("/<a([^>]*) href=('|\")\/([^\"']*)('|\")/", "<a\${1} href=\"" .$blogurl ."/" ."\${3}\"", $content);
1299
 
1300
  if (is_singular()) {
1301
  $content = preg_replace("/<a([^>]*) href=('|\")#([^\"']*)('|\")/", "<a\${1} href=\"" .get_permalink()."#" ."\${3}\"", $content);
1
  <?php
2
  /*
3
  Plugin Name: Google Analytics for WordPress
4
+ Plugin URI: http://yoast.com/wordpress/analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=google-analytics-for-wordpress&utm_content=v406
5
  Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. custom variables and automatic clickout and download tracking.
6
  Author: Joost de Valk
7
+ Version: 4.0.6
8
  Requires at least: 2.8
9
  Author URI: http://yoast.com/
10
  License: GPL
106
  jQuery('#uastring_automatic').css('display','block');
107
  }
108
  }).change();
109
+ jQuery('#trackoutbound').change(function(){
110
+ if ((jQuery('#trackoutbound').attr('checked')) == true) {
111
+ jQuery('#internallinktracking').css("display","block");
112
+ } else {
113
+ jQuery('#internallinktracking').css("display","none");
114
+ }
115
+ }).change();
116
  jQuery('#advancedsettings').change(function(){
117
  if ((jQuery('#advancedsettings').attr('checked')) == true) {
118
  jQuery('#advancedgasettings').css("display","block");
119
  jQuery('#customvarsettings').css("display","block");
 
120
  jQuery('#toc').css("display","block");
121
  } else {
122
  jQuery('#advancedgasettings').css("display","none");
123
  jQuery('#customvarsettings').css("display","none");
 
124
  jQuery('#toc').css("display","none");
125
  }
126
  }).change();
147
  jQuery('#uastring').change(function(){
148
  if ((jQuery('#switchtomanual').attr('checked')) == true) {
149
  if (!jQuery(this).val().match(/^UA-[\d-]+$/)) {
150
+ alert("That's not a valid UA ID, please make sure it matches the expected pattern of: UA-XXXXXX-X, and that there are no spaces or other characters in the input field.");
151
  jQuery(this).focus();
152
  }
153
  }
230
 
231
  function upgrade() {
232
  $options = get_option($this->optionname);
233
+ if ($options['version'] < '4.04') {
234
  if ( !isset($options['trackcommentform']) || $options['trackcommentform'] == '')
235
  $options['trackcommentform'] = true;
236
  if ( !isset($options['ignore_userlevel']) || $options['ignore_userlevel'] == '')
237
  $options['ignore_userlevel'] = 11;
238
 
239
+ $options['version'] = '4.04';
240
+ }
241
+ if ($options['version'] < '4.06') {
242
+ $options['version'] = '4.06';
243
  }
244
  update_option($this->optionname, $options);
245
  }
437
  'desc' => 'Allows you to easily remove logged in users from your reports, or to segment by different user roles. The users primary role will be logged.',
438
  'content' => $this->checkbox('cv_loggedin'),
439
  );
440
+ $rows[] = array(
441
+ 'id' => 'cv_post_type',
442
+ 'label' => 'Post type',
443
+ 'desc' => 'Allows you to see pageviews per post type, especially useful if you use multiple custom post types.',
444
+ 'content' => $this->checkbox('cv_post_type'),
445
+ );
446
  $rows[] = array(
447
  'id' => 'cv_authorname',
448
  'label' => 'Author Name',
449
  'desc' => 'Allows you to see pageviews per author.',
450
  'content' => $this->checkbox('cv_authorname'),
451
  );
 
 
 
 
 
 
 
 
 
 
 
 
452
  $rows[] = array(
453
  'id' => 'cv_tags',
454
  'label' => 'Tags',
462
  'content' => $this->checkbox('cv_year'),
463
  );
464
  $rows[] = array(
465
+ 'id' => 'cv_category',
466
+ 'label' => 'Single Category',
467
+ 'desc' => 'Allows you to see pageviews per category, works best when each post is in only one category.',
468
+ 'content' => $this->checkbox('cv_category'),
469
  );
470
+ $rows[] = array(
471
+ 'id' => 'cv_all_categories',
472
+ 'label' => 'All Categories',
473
+ 'desc' => 'Allows you to see pageviews per category using advanced segments, should be used when you use multiple categories per post.',
474
+ 'content' => $this->checkbox('cv_all_categories'),
475
+ );
476
+
477
  $this->postbox('customvarsettings','Custom Variables Settings',$pre_content.$this->form_table($rows).$this->save_button());
478
 
479
  $rows = array();
487
  '5' => 'Editor',
488
  '2' => 'Author',
489
  '1' => 'Contributor',
490
+ '0' => 'Subscriber (ignores all logged in users)',
491
  )),
492
  );
493
  $rows[] = array(
667
  if ( count($modules) > 0 )
668
  $this->postbox('toc','List of Available Modules',$this->toc($modules));
669
  $this->plugin_like();
670
+ $this->postbox('donate','<strong class="red">Donate $5, $10, $20 or $50!</strong>','<p>This plugin has cost me countless hours of work, if you use it, please donate a token of your appreciation!</p><br/><form style="margin-left:50px;" action="https://www.paypal.com/cgi-bin/webscr" method="post">
671
  <input type="hidden" name="cmd" value="_s-xclick">
672
  <input type="hidden" name="hosted_button_id" value="FW9FK4EBZ9FVJ">
673
  <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
746
  * Insert the tracking code into the page
747
  */
748
  function spool_analytics() {
749
+ global $wp_query;
750
  // echo '<!--'.print_r($wp_query,1).'-->';
 
751
 
752
  $options = get_option('Yoast_Google_Analytics');
753
 
755
  * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
756
  */
757
  $customvarslot = 1;
758
+ if ( $options["uastring"] != "" && yoast_ga_do_tracking() && !is_preview() ) {
759
  $push = array();
760
 
761
  if ( $options['allowanchor'] )
775
  }
776
 
777
  if ( $options['cv_loggedin'] ) {
778
+ $current_user = wp_get_current_user();
779
+ if ( $current_user && $current_user->ID != 0 )
780
+ $push[] = "'_setCustomVar',$customvarslot,'logged-in','".$current_user->roles[0]."',1";
781
  // Customvar slot needs to be upped even when the user is not logged in, to make sure the variables below are always in the same slot.
782
  $customvarslot++;
783
  }
786
  if ( $options['cv_post_type'] ) {
787
  $post_type = get_post_type();
788
  if ( $post_type ) {
789
+ $push[] = "'_setCustomVar',".$customvarslot.",'post_type','".$post_type."',3";
790
  $customvarslot++;
791
  }
792
  }
793
  if ( $options['cv_authorname'] ) {
794
+ $push[] = "'_setCustomVar',$customvarslot,'author','".GA_Filter::ga_str_clean(get_the_author_meta('display_name',$wp_query->post->post_author))."',3";
795
  $customvarslot++;
796
  }
797
  if ( $options['cv_tags'] ) {
805
  }
806
  // Max 64 chars for value and label combined, hence 64 - 4
807
  $tagsstr = substr($tagsstr, 0, 60);
808
+ $push[] = "'_setCustomVar',$customvarslot,'tags','".$tagsstr."',3";
809
  $customvarslot++;
810
  }
811
  if ( is_single() ) {
812
  if ( $options['cv_year'] ) {
813
+ $push[] = "'_setCustomVar',$customvarslot,'year','".get_the_time('Y')."',3";
814
  $customvarslot++;
815
  }
816
  if ( $options['cv_category'] ) {
817
  $cats = get_the_category();
818
+ $push[] = "'_setCustomVar',$customvarslot,'category','".$cats[0]->slug."',3";
819
  $customvarslot++;
820
  }
821
  if ( $options['cv_all_categories'] ) {
829
  }
830
  // Max 64 chars for value and label combined, hence 64 - 10
831
  $catsstr = substr($catsstr, 0, 54);
832
+ $push[] = "'_setCustomVar',$customvarslot,'categories','".$catsstr."',3";
833
  $customvarslot++;
834
  }
835
  }
877
 
878
  ?>
879
 
 
880
  <script type="text/javascript">//<![CDATA[
881
+ // Google Analytics for WordPress by Yoast v<?php echo $options['version']; ?> | http://yoast.com/wordpress/google-analytics/
882
  var _gaq = _gaq || [];
883
  _gaq.push(['_setAccount','<?php echo $options["uastring"]; ?>']);
884
  <?php
905
 
906
  var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
907
  })();
908
+ // End of Google Analytics for WordPress by Yoast v4.0
909
  //]]></script>
910
+
911
  <?php
912
  } else if ( $options["uastring"] != "" ) {
913
  echo "<!-- Google Analytics tracking code not shown because users over level ".$options["ignore_userlevel"]." are ignored -->\n";
921
  */
922
  function spool_adsense() {
923
  $options = get_option('Yoast_Google_Analytics');
924
+ if ( $options["uastring"] != "" && yoast_ga_do_tracking() && !is_preview() ) {
925
  echo '<script type="text/javascript">'."\n";
926
  echo "\t".'window.google_analytics_uacct = "'.$options["uastring"].'";'."\n";
927
  echo '</script>'."\n";
1030
  }
1031
 
1032
  function widget_content($text) {
1033
+ if ( !yoast_ga_do_tracking() )
 
 
1034
  return $text;
1035
  static $anchorPattern = '/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
1036
  $text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_widget_link'),$text);
1038
  }
1039
 
1040
  function the_content($text) {
1041
+ if ( !yoast_ga_do_tracking() )
 
 
1042
  return $text;
1043
 
1044
  if (!is_feed()) {
1049
  }
1050
 
1051
  function comment_text($text) {
1052
+ if ( !yoast_ga_do_tracking() )
 
 
1053
  return $text;
1054
 
1055
  if (!is_feed()) {
1060
  }
1061
 
1062
  function comment_author_link($text) {
1063
+ if ( !yoast_ga_do_tracking() )
 
 
1064
  return $text;
1065
 
1066
  static $anchorPattern = '/(.*\s+.*?href\s*=\s*)["\'](.*?)["\'](.*)/';
1080
  }
1081
 
1082
  function bookmarks($bookmarks) {
1083
+ if ( !yoast_ga_do_tracking() )
 
 
1084
  return $bookmarks;
1085
 
1086
  $i = 0;
1231
  }
1232
  }
1233
 
1234
+ function yoast_ga_do_tracking() {
1235
+ $current_user = wp_get_current_user();
1236
+
1237
+ if (!$current_user)
1238
+ return true;
1239
+
1240
+ $yoast_ga_options = get_option('Yoast_Google_Analytics');
1241
+
1242
+ if ( ($current_user->user_level >= $yoast_ga_options["ignore_userlevel"]) )
1243
+ return false;
1244
+ else
1245
+ return true;
1246
+ }
1247
+
1248
  function track_comment_form_head() {
1249
+ if (is_singular()) {
1250
+ global $post;
1251
+ $yoast_ga_options = get_option('Yoast_Google_Analytics');
1252
+ if ( yoast_ga_do_tracking() && $yoast_ga_options["trackcommentform"] && ('open' == $post->comment_status) )
1253
+ wp_enqueue_script('jquery');
1254
+ }
1255
  }
1256
  add_action('wp_print_scripts','track_comment_form_head');
1257
 
1264
  add_filter('comment_form_defaults', 'yoast_get_comment_form_id',99,1);
1265
 
1266
  function yoast_track_comment_form() {
1267
+ global $comment_form_id, $post;
1268
+ $yoast_ga_options = get_option('Yoast_Google_Analytics');
1269
+ if ( yoast_ga_do_tracking() && $yoast_ga_options["trackcommentform"] ) {
1270
  ?>
1271
  <script type="text/javascript" charset="utf-8">
1272
+ jQuery(document).ready(function() {
1273
+ jQuery('#<?php echo $comment_form_id; ?>').submit(function() {
1274
+ _gaq.push(
1275
+ ['_setAccount','<?php echo $yoast_ga_options["uastring"]; ?>'],
1276
+ ['_trackEvent','comment']
1277
+ );
1278
+ });
1279
+ });
1280
  </script>
1281
  <?php
1282
+ }
1283
  }
1284
  add_action('comment_form_after','yoast_track_comment_form');
1285
  /*
1308
  */
1309
 
1310
  function yoast_sanitize_relative_links($content) {
1311
+ preg_match("|^http(s)?://([^/]+)|i", get_bloginfo('url'), $match);
1312
+ $content = preg_replace("/<a([^>]*) href=('|\")\/([^\"']*)('|\")/", "<a\${1} href=\"" .$match[0] ."/" ."\${3}\"", $content);
 
 
 
1313
 
1314
  if (is_singular()) {
1315
  $content = preg_replace("/<a([^>]*) href=('|\")#([^\"']*)('|\")/", "<a\${1} href=\"" .get_permalink()."#" ."\${3}\"", $content);
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://yoast.com/donate/
4
  Tags: analytics, google analytics, statistics, tracking, stats, google
5
  Requires at least: 2.8
6
  Tested up to: 3.0
7
- Stable tag: 4.0.5
8
 
9
  The Google Analytics for WordPress plugin allows you to track your blog easily and with lots of metadata. It adds the asynchronous tracking code for Google Analytics and automatically tracks and segments all outbound links from within posts, comment author links, links within comments, blogroll links and downloads. It'll add custom variables while tracking to show you pageviews per author, post type, category or publication year. It'll also allow you to track AdSense clicks, add extra search engines, ignore certain user levels, and much much more: this is simply the Ultimate Google Analytic solution for WP!
10
 
@@ -30,6 +30,19 @@ This section describes how to install the plugin and get it working.
30
 
31
  == Changelog ==
32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
  = 4.0.5 =
34
  * New features in this release:
35
  * Added a simple check to see if the UA code, when entered manually, matches a basic pattern of UA-1234567-12.
4
  Tags: analytics, google analytics, statistics, tracking, stats, google
5
  Requires at least: 2.8
6
  Tested up to: 3.0
7
+ Stable tag: 4.0.6
8
 
9
  The Google Analytics for WordPress plugin allows you to track your blog easily and with lots of metadata. It adds the asynchronous tracking code for Google Analytics and automatically tracks and segments all outbound links from within posts, comment author links, links within comments, blogroll links and downloads. It'll add custom variables while tracking to show you pageviews per author, post type, category or publication year. It'll also allow you to track AdSense clicks, add extra search engines, ignore certain user levels, and much much more: this is simply the Ultimate Google Analytic solution for WP!
10
 
30
 
31
  == Changelog ==
32
 
33
+ = 4.0.6 =
34
+ * Bugs fixed in this release:
35
+ * Sanitizing relative URL's could go wrong on some blogs installed in subdirectories.
36
+ * Comment form tracking only worked for posts, not for pages, and would sometimes cause other issues. Patch by [Milan Dinić](http://blog.milandinic.com/).
37
+ * Settings page: now correctly hiding internal links to track as outbound block when outbound link tracking is disabled.
38
+ * Code sanitization:
39
+ * Hardcoded the [scope for custom variables](http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._setCustomVar) to prevent that from possibly going wrong.
40
+ * Improved method of determining whether current user should be tracked or not.
41
+ * Added plugin version number in script branding comment, and moved branding comment to within CDATA section to assist in debugging, even when people use W3TC or another form of code minification.
42
+ * Documentation fixes:
43
+ * Updated custom variable order in settings panel to reflect order of tracking. You can now determine their index key by counting down, first checked box is index 1, second 2, etc.
44
+ * Ignored users dropdown now correctly reflects that ignoring subcribers and up means ignoring ALL logged in users.
45
+
46
  = 4.0.5 =
47
  * New features in this release:
48
  * Added a simple check to see if the UA code, when entered manually, matches a basic pattern of UA-1234567-12.
yst_plugin_tools.css CHANGED
@@ -68,4 +68,14 @@ div.inside .button:hover, div.inside .button-primary:hover {
68
 
69
  .button, .button-primary {
70
  margin-top: 10px;
 
 
 
 
 
 
 
 
 
 
71
  }
68
 
69
  .button, .button-primary {
70
  margin-top: 10px;
71
+ }
72
+
73
+ .postbox#donate {
74
+ border-color: #fa0913;
75
+ border-width: 2px;
76
+ }
77
+ strong.red {
78
+ color: #fa0913;
79
+ font-weight: bold;
80
+ font-size: 105%;
81
  }