Google Analytics for WordPress by MonsterInsights - Version 4.0.12

Version Description

  • Fixed:
    • Tons of notices in backend and front end when no settings were saved yet.
    • Set proper defaults for all variables.
    • Notice for unset categories array on custom post types.
    • Notice for unset variable.
    • Error when user is not logged in in certain corner cases.
    • Bug where $options was used but never loaded for blogroll links.
Download this release

Release Info

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

Code changes from version 4.0.10 to 4.0.12

Files changed (2) hide show
  1. googleanalytics.php +84 -55
  2. readme.txt +27 -5
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=v407
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.10
8
  Requires at least: 2.8
9
  Author URI: http://yoast.com/
10
  License: GPL
@@ -12,6 +12,8 @@ License: GPL
12
 
13
  // This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics
14
 
 
 
15
  // Determine the location
16
  function gapp_plugin_path() {
17
  return plugins_url('', __FILE__).'/';
@@ -72,7 +74,7 @@ if ( ! class_exists( 'GA_Admin' ) ) {
72
  wp_enqueue_script('jquery');
73
 
74
  ?>
75
- <script type="text/javascript" charset="utf-8">
76
  function makeSublist(parent,child,childVal)
77
  {
78
  jQuery("body").append("<select style='display:none' id='"+parent+child+"'></select>");
@@ -254,23 +256,25 @@ if ( ! class_exists( 'GA_Admin' ) ) {
254
 
255
  function upgrade() {
256
  $options = get_option($this->optionname);
257
- if ($options['version'] < '4.04') {
258
- if ( !isset($options['trackcommentform']) || $options['trackcommentform'] == '')
259
- $options['trackcommentform'] = true;
260
  if ( !isset($options['ignore_userlevel']) || $options['ignore_userlevel'] == '')
261
  $options['ignore_userlevel'] = 11;
262
  }
263
- if ($options['version'] != '4.0.10') {
264
- $options['version'] = '4.0.10';
265
  }
266
  update_option($this->optionname, $options);
267
  }
268
 
269
  function config_page() {
270
  $options = get_option($this->optionname);
271
- echo $options['msg'];
 
272
  $options['msg'] = '';
273
  update_option($this->optionname, $options);
 
 
 
274
  $modules = array();
275
 
276
  ?>
@@ -387,7 +391,7 @@ if ( ! class_exists( 'GA_Admin' ) ) {
387
  $try = $_GET['try'] + 1;
388
 
389
  if ($i == 1 && $try < 4 && isset($_GET['token'])) {
390
- $line .= '<script type="text/javascript" charset="utf-8">
391
  window.location="'.$this->plugin_options_url().'&switchua=1&token='.$token.'&try='.$try.'";
392
  </script>';
393
  }
@@ -738,7 +742,10 @@ if ( ! class_exists( 'GA_Admin' ) ) {
738
  $options = array(
739
  'advancedsettings' => false,
740
  'allowanchor' => false,
 
741
  'allowlinker' => false,
 
 
742
  'cv_loggedin' => false,
743
  'cv_authorname' => false,
744
  'cv_category' => false,
@@ -746,22 +753,32 @@ if ( ! class_exists( 'GA_Admin' ) ) {
746
  'cv_tags' => false,
747
  'cv_year' => false,
748
  'cv_post_type' => false,
 
749
  'dlextensions' => 'doc,exe,js,pdf,ppt,tgz,zip,xls',
 
750
  'domainorurl' => 'domain',
751
- 'ga_token' => '',
752
- 'ga_api_responses' => array(),
753
  'extrase' => false,
754
  'extraseurl' => '',
 
 
 
 
 
755
  'ignore_userlevel' => '11',
 
 
756
  'outboundpageview' => false,
757
  'downloadspageview' => false,
 
758
  'position' => 'footer',
 
759
  'trackcommentform' => true,
760
  'trackadsense' => false,
761
  'trackoutbound' => true,
762
  'trackregistration' => false,
763
  'rsslinktagging' => true,
764
- 'domain' => '',
 
765
  );
766
  update_option($this->optionname,$options);
767
  return $options;
@@ -800,12 +817,18 @@ if ( ! class_exists( 'GA_Filter' ) ) {
800
  // echo '<!--'.print_r($wp_query,1).'-->';
801
 
802
  $options = get_option('Yoast_Google_Analytics');
 
 
 
 
 
 
803
 
804
  /**
805
  * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
806
  */
807
  $customvarslot = 1;
808
- if ( $options["uastring"] != "" && yoast_ga_do_tracking() && !is_preview() ) {
809
  $push = array();
810
 
811
  if ( $options['allowanchor'] )
@@ -868,7 +891,8 @@ if ( ! class_exists( 'GA_Filter' ) ) {
868
  }
869
  if ( $options['cv_category'] ) {
870
  $cats = get_the_category();
871
- $push[] = "'_setCustomVar',$customvarslot,'category','".$cats[0]->slug."',3";
 
872
  $customvarslot++;
873
  }
874
  if ( $options['cv_all_categories'] ) {
@@ -969,9 +993,7 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
969
  <?php
970
  } else if ( $options["uastring"] != "" ) {
971
  echo "<!-- Google Analytics tracking code not shown because users over level ".$options["ignore_userlevel"]." are ignored -->\n";
972
- } else if ( $options["uastring"] == "" && current_user_can('manage_options') ) {
973
- echo "<!-- Google Analytics tracking code not shown because yo haven't chosen a Google Analytics account yet. -->\n";
974
- }
975
  }
976
 
977
  /*
@@ -1118,6 +1140,8 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1118
  }
1119
 
1120
  function comment_author_link($text) {
 
 
1121
  if ( !yoast_ga_do_tracking() )
1122
  return $text;
1123
 
@@ -1128,7 +1152,7 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1128
  $target = GA_Filter::ga_get_domain($matches[2]);
1129
  $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
1130
  if ( $target["domain"] != $origin["domain"] ){
1131
- if ($options['domainorurl'] == "domain")
1132
  $url = $target["host"];
1133
  else
1134
  $url = $matches[2];
@@ -1149,7 +1173,7 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1149
  $i++;
1150
  continue;
1151
  }
1152
- if ($options['domainorurl'] == "domain")
1153
  $url = $target["host"];
1154
  else
1155
  $url = $bookmarks[$i]->link_url;
@@ -1304,7 +1328,7 @@ function ga_utm_hashtag_redirect() {
1304
  function yoast_ga_do_tracking() {
1305
  $current_user = wp_get_current_user();
1306
 
1307
- if (!$current_user)
1308
  return true;
1309
 
1310
  $yoast_ga_options = get_option('Yoast_Google_Analytics');
@@ -1319,7 +1343,10 @@ function track_comment_form_head() {
1319
  if (is_singular()) {
1320
  global $post;
1321
  $yoast_ga_options = get_option('Yoast_Google_Analytics');
1322
- if ( yoast_ga_do_tracking() && $yoast_ga_options["trackcommentform"] && ('open' == $post->comment_status) )
 
 
 
1323
  wp_enqueue_script('jquery');
1324
  }
1325
  }
@@ -1338,7 +1365,7 @@ function yoast_track_comment_form() {
1338
  $yoast_ga_options = get_option('Yoast_Google_Analytics');
1339
  if ( yoast_ga_do_tracking() && $yoast_ga_options["trackcommentform"] ) {
1340
  ?>
1341
- <script type="text/javascript" charset="utf-8">
1342
  jQuery(document).ready(function() {
1343
  jQuery('#<?php echo $comment_form_id; ?>').submit(function() {
1344
  _gaq.push(
@@ -1365,7 +1392,7 @@ function gfform_tag() {
1365
  }
1366
  wp_enqueue_script('jquery');
1367
  ?>
1368
- <script type="text/javascript" charset="utf-8">
1369
  jQuery(document).ready(function() {
1370
  jQuery('.gform_wrapper form').submit(function() {
1371
  _gaq.push(<?php echo $pv; ?>);
@@ -1414,39 +1441,41 @@ if (!is_array($options)) {
1414
  }
1415
  update_option('Yoast_Google_Analytics', $options);
1416
  }
1417
- }
 
 
 
1418
 
1419
- if ( $options['allowanchor'] ) {
1420
- add_action('init','ga_utm_hashtag_redirect',1);
1421
- }
 
 
 
 
 
 
1422
 
1423
- if ($options['trackoutbound']) {
1424
- // filters alter the existing content
1425
- add_filter('the_content', array('GA_Filter','the_content'), 99);
1426
- add_filter('widget_text', array('GA_Filter','widget_content'), 99);
1427
- add_filter('the_excerpt', array('GA_Filter','the_content'), 99);
1428
- add_filter('comment_text', array('GA_Filter','comment_text'), 99);
1429
- add_filter('get_bookmarks', array('GA_Filter','bookmarks'), 99);
1430
- add_filter('get_comment_author_link', array('GA_Filter','comment_author_link'), 99);
1431
- }
1432
 
1433
- if ($options['trackadsense'])
1434
- add_action('wp_head', array('GA_Filter','spool_adsense'),1);
1435
-
1436
- switch ($options['position']) {
1437
- case 'manual':
1438
- // No need to insert here, bail NOW.
1439
- break;
1440
- case 'header':
1441
- default:
1442
- add_action('wp_head', array('GA_Filter','spool_analytics'),2);
1443
- break;
1444
- }
1445
 
1446
- if ($options['trackregistration'])
1447
- add_action('login_head', array('GA_Filter','spool_analytics'),20);
1448
-
1449
- if ($options['rsslinktagging'])
1450
- add_filter ( 'the_permalink_rss', array('GA_Filter','rsslinktagger'), 99 );
1451
 
1452
- ?>
 
 
 
1
  <?php
2
  /*
3
  Plugin Name: Google Analytics for WordPress
4
+ Plugin URI: http://yoast.com/wordpress/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=google-analytics-for-wordpress&utm_content=v407
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.12
8
  Requires at least: 2.8
9
  Author URI: http://yoast.com/
10
  License: GPL
12
 
13
  // This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics
14
 
15
+ define('GAWP_VERSION', '4.0.12');
16
+
17
  // Determine the location
18
  function gapp_plugin_path() {
19
  return plugins_url('', __FILE__).'/';
74
  wp_enqueue_script('jquery');
75
 
76
  ?>
77
+ <script type="text/javascript">
78
  function makeSublist(parent,child,childVal)
79
  {
80
  jQuery("body").append("<select style='display:none' id='"+parent+child+"'></select>");
256
 
257
  function upgrade() {
258
  $options = get_option($this->optionname);
259
+ if ( isset($options['version']) && $options['version'] < '4.04' ) {
 
 
260
  if ( !isset($options['ignore_userlevel']) || $options['ignore_userlevel'] == '')
261
  $options['ignore_userlevel'] = 11;
262
  }
263
+ if ( !isset($options['version']) || $options['version'] != GAWP_VERSION ) {
264
+ $options['version'] = GAWP_VERSION;
265
  }
266
  update_option($this->optionname, $options);
267
  }
268
 
269
  function config_page() {
270
  $options = get_option($this->optionname);
271
+ if ( isset($options['msg']) )
272
+ echo $options['msg'];
273
  $options['msg'] = '';
274
  update_option($this->optionname, $options);
275
+
276
+ if ( !isset($options['uastring']) )
277
+ $options = $this->set_defaults();
278
  $modules = array();
279
 
280
  ?>
391
  $try = $_GET['try'] + 1;
392
 
393
  if ($i == 1 && $try < 4 && isset($_GET['token'])) {
394
+ $line .= '<script type="text/javascript">
395
  window.location="'.$this->plugin_options_url().'&switchua=1&token='.$token.'&try='.$try.'";
396
  </script>';
397
  }
742
  $options = array(
743
  'advancedsettings' => false,
744
  'allowanchor' => false,
745
+ 'allowhash' => false,
746
  'allowlinker' => false,
747
+ 'anonymizeip' => false,
748
+ 'customcode' => '',
749
  'cv_loggedin' => false,
750
  'cv_authorname' => false,
751
  'cv_category' => false,
753
  'cv_tags' => false,
754
  'cv_year' => false,
755
  'cv_post_type' => false,
756
+ 'debug' => false,
757
  'dlextensions' => 'doc,exe,js,pdf,ppt,tgz,zip,xls',
758
+ 'domain' => '',
759
  'domainorurl' => 'domain',
 
 
760
  'extrase' => false,
761
  'extraseurl' => '',
762
+ 'firebuglite' => false,
763
+ 'ga_token' => '',
764
+ 'ga_api_responses' => array(),
765
+ 'gajslocalhosting' => false,
766
+ 'gajsurl' => '',
767
  'ignore_userlevel' => '11',
768
+ 'internallink' => false,
769
+ 'internallinklabel' => '',
770
  'outboundpageview' => false,
771
  'downloadspageview' => false,
772
+ 'manual_uastring' => '',
773
  'position' => 'footer',
774
+ 'theme_updated' => false,
775
  'trackcommentform' => true,
776
  'trackadsense' => false,
777
  'trackoutbound' => true,
778
  'trackregistration' => false,
779
  'rsslinktagging' => true,
780
+ 'uastring' => '',
781
+ 'version' => GAWP_VERSION,
782
  );
783
  update_option($this->optionname,$options);
784
  return $options;
817
  // echo '<!--'.print_r($wp_query,1).'-->';
818
 
819
  $options = get_option('Yoast_Google_Analytics');
820
+
821
+ if ( !isset($options['uastring']) || $options['uastring'] == '' ) {
822
+ if ( current_user_can('manage_options') )
823
+ echo "<!-- Google Analytics tracking code not shown because yo haven't chosen a Google Analytics account yet. -->\n";
824
+ return;
825
+ }
826
 
827
  /**
828
  * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
829
  */
830
  $customvarslot = 1;
831
+ if ( yoast_ga_do_tracking() && !is_preview() ) {
832
  $push = array();
833
 
834
  if ( $options['allowanchor'] )
891
  }
892
  if ( $options['cv_category'] ) {
893
  $cats = get_the_category();
894
+ if ( is_array( $cats ) && isset( $cats[0] ) )
895
+ $push[] = "'_setCustomVar',$customvarslot,'category','".$cats[0]->slug."',3";
896
  $customvarslot++;
897
  }
898
  if ( $options['cv_all_categories'] ) {
993
  <?php
994
  } else if ( $options["uastring"] != "" ) {
995
  echo "<!-- Google Analytics tracking code not shown because users over level ".$options["ignore_userlevel"]." are ignored -->\n";
996
+ }
 
 
997
  }
998
 
999
  /*
1140
  }
1141
 
1142
  function comment_author_link($text) {
1143
+ $options = get_option('Yoast_Google_Analytics');
1144
+
1145
  if ( !yoast_ga_do_tracking() )
1146
  return $text;
1147
 
1152
  $target = GA_Filter::ga_get_domain($matches[2]);
1153
  $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
1154
  if ( $target["domain"] != $origin["domain"] ){
1155
+ if ( isset( $options['domainorurl'] ) && $options['domainorurl'] == "domain" )
1156
  $url = $target["host"];
1157
  else
1158
  $url = $matches[2];
1173
  $i++;
1174
  continue;
1175
  }
1176
+ if ( isset( $options['domainorurl'] ) && $options['domainorurl'] == "domain" )
1177
  $url = $target["host"];
1178
  else
1179
  $url = $bookmarks[$i]->link_url;
1328
  function yoast_ga_do_tracking() {
1329
  $current_user = wp_get_current_user();
1330
 
1331
+ if (0 == $current_user->ID)
1332
  return true;
1333
 
1334
  $yoast_ga_options = get_option('Yoast_Google_Analytics');
1343
  if (is_singular()) {
1344
  global $post;
1345
  $yoast_ga_options = get_option('Yoast_Google_Analytics');
1346
+ if ( yoast_ga_do_tracking()
1347
+ && isset( $yoast_ga_options["trackcommentform"] )
1348
+ && $yoast_ga_options["trackcommentform"]
1349
+ && ( 'open' == $post->comment_status ) )
1350
  wp_enqueue_script('jquery');
1351
  }
1352
  }
1365
  $yoast_ga_options = get_option('Yoast_Google_Analytics');
1366
  if ( yoast_ga_do_tracking() && $yoast_ga_options["trackcommentform"] ) {
1367
  ?>
1368
+ <script type="text/javascript">
1369
  jQuery(document).ready(function() {
1370
  jQuery('#<?php echo $comment_form_id; ?>').submit(function() {
1371
  _gaq.push(
1392
  }
1393
  wp_enqueue_script('jquery');
1394
  ?>
1395
+ <script type="text/javascript">
1396
  jQuery(document).ready(function() {
1397
  jQuery('.gform_wrapper form').submit(function() {
1398
  _gaq.push(<?php echo $pv; ?>);
1441
  }
1442
  update_option('Yoast_Google_Analytics', $options);
1443
  }
1444
+ } else {
1445
+ if ( isset( $options['allowanchor'] ) && $options['allowanchor'] ) {
1446
+ add_action('init','ga_utm_hashtag_redirect',1);
1447
+ }
1448
 
1449
+ if ( isset( $options['trackoutbound'] ) && $options['trackoutbound'] ) {
1450
+ // filters alter the existing content
1451
+ add_filter('the_content', array('GA_Filter','the_content'), 99);
1452
+ add_filter('widget_text', array('GA_Filter','widget_content'), 99);
1453
+ add_filter('the_excerpt', array('GA_Filter','the_content'), 99);
1454
+ add_filter('comment_text', array('GA_Filter','comment_text'), 99);
1455
+ add_filter('get_bookmarks', array('GA_Filter','bookmarks'), 99);
1456
+ add_filter('get_comment_author_link', array('GA_Filter','comment_author_link'), 99);
1457
+ }
1458
 
1459
+ if ( isset( $options['trackadsense'] ) && $options['trackadsense'] )
1460
+ add_action('wp_head', array('GA_Filter','spool_adsense'),1);
 
 
 
 
 
 
 
1461
 
1462
+ if ( !isset( $options['position'] ) )
1463
+ $options['position'] = 'header';
1464
+
1465
+ switch ($options['position']) {
1466
+ case 'manual':
1467
+ // No need to insert here, bail NOW.
1468
+ break;
1469
+ case 'header':
1470
+ default:
1471
+ add_action('wp_head', array('GA_Filter','spool_analytics'),2);
1472
+ break;
1473
+ }
1474
 
1475
+ if ( isset( $options['trackregistration'] ) && $options['trackregistration'] )
1476
+ add_action('login_head', array('GA_Filter','spool_analytics'),20);
 
 
 
1477
 
1478
+ if ( isset( $options['rsslinktagging'] ) && $options['rsslinktagging'] )
1479
+ add_filter ( 'the_permalink_rss', array('GA_Filter','rsslinktagger'), 99 );
1480
+
1481
+ }
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.1
7
- Stable tag: 4.0.10
8
 
9
  Track your WordPress site easily and with lots of metadata: views per author & category, automatic tracking of outbound clicks and pageviews.
10
 
@@ -23,8 +23,8 @@ Full list of features:
23
  * Option to manually place the tracking code in another location.
24
  * Outbound link & downloads tracking.
25
  * Configurable options to track outbound links either as pageviews.
26
- * Option to track just downloads as pageviews.
27
- * Allows usage of custom variables to track meta data on pages. Support for the following custom variables:
28
  * Author
29
  * Single category and / or multiple categories
30
  * Post type (especially useful if you use custom post types)
@@ -32,7 +32,7 @@ Full list of features:
32
  * Publication Year
33
  * Tags
34
  * Possibility to ignore any user level and up, so all editors and higher for instance.
35
- * Easily connect your AdSense and Analytics accounts.
36
  * Option to tag links with campaign tracking, with the option to use hashes (#).
37
  * Option anonymize IP's, for use in countries like Germany.
38
  * Full [debug mode](http://yoast.com/google-analytics-debug-mode/), including Firebug lite and ga_debug.js for debugging Analytics issues.
@@ -60,6 +60,22 @@ This section describes how to install the plugin and get it working.
60
 
61
  == Changelog ==
62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63
  = 4.0.10 =
64
 
65
  * Known issues:
@@ -281,4 +297,10 @@ Because that's where it belongs. It makes the page load faster (yes, faster, due
281
  2. Screenshot of the custom variable settings panel.
282
  3. Screenshot of the link tracking panel.
283
  4. Screenshot of the advanced settings panel.
284
- 5. Screenshot of the debugging mode in action.
 
 
 
 
 
 
4
  Tags: analytics, google analytics, statistics, tracking, stats, google
5
  Requires at least: 2.8
6
  Tested up to: 3.1
7
+ Stable tag: 4.0.12
8
 
9
  Track your WordPress site easily and with lots of metadata: views per author & category, automatic tracking of outbound clicks and pageviews.
10
 
23
  * Option to manually place the tracking code in another location.
24
  * Outbound link & downloads tracking.
25
  * Configurable options to track outbound links either as pageviews.
26
+ * Option to track just downloads as pageviews in Google Analytics.
27
+ * Allows usage of custom variables in Google Analytics to track meta data on pages. Support for the following custom variables:
28
  * Author
29
  * Single category and / or multiple categories
30
  * Post type (especially useful if you use custom post types)
32
  * Publication Year
33
  * Tags
34
  * Possibility to ignore any user level and up, so all editors and higher for instance.
35
+ * Easily connect your Google AdSense and Google Analytics accounts.
36
  * Option to tag links with campaign tracking, with the option to use hashes (#).
37
  * Option anonymize IP's, for use in countries like Germany.
38
  * Full [debug mode](http://yoast.com/google-analytics-debug-mode/), including Firebug lite and ga_debug.js for debugging Analytics issues.
60
 
61
  == Changelog ==
62
 
63
+ = 4.0.12 =
64
+
65
+ * Fixed:
66
+ * Tons of notices in backend and front end when no settings were saved yet.
67
+ * Set proper defaults for all variables.
68
+ * Notice for unset categories array on custom post types.
69
+ * Notice for unset variable.
70
+ * Error when user is not logged in in certain corner cases.
71
+ * Bug where $options was used but never loaded for blogroll links.
72
+
73
+ = 4.0.11 =
74
+
75
+ * Bugs fixed:
76
+ * You can now disable comment form tracking properly.
77
+ * Removed charset property from script tags to allow validation with HTML5 doctype.
78
+
79
  = 4.0.10 =
80
 
81
  * Known issues:
297
  2. Screenshot of the custom variable settings panel.
298
  3. Screenshot of the link tracking panel.
299
  4. Screenshot of the advanced settings panel.
300
+ 5. Screenshot of the debugging mode in action.
301
+
302
+ == Upgrade Notice ==
303
+
304
+ = 4.0.11 =
305
+
306
+ You can now properly disable the comment form tracking, and the charset attribute on script tags is gone so you can validate as HTML5 too.