Google Analytics for WordPress by MonsterInsights - Version 5.0.5

Version Description

Release Date: September 4th, 2014

  • Bugfixes:
    • Fixes error in link parsing that would cause all sorts of display errors.
Download this release

Release Info

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

Code changes from version 5.0.4 to 5.0.5

frontend/class-frontend.php CHANGED
@@ -72,16 +72,20 @@ if ( ! class_exists( 'Yoast_GA_Frontend' ) ) {
72
  $domainPatternUS = "/[^\.\/]+\.[^\.\/]+$/";
73
  $domainPatternUK = "/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/";
74
 
75
- preg_match( $hostPattern, $uri, $matches );
76
- $host = $matches[2];
77
- if ( preg_match( "/.*\..*\..*\..*$/", $host ) ) {
78
- preg_match( $domainPatternUK, $host, $matches );
79
- } else {
80
- preg_match( $domainPatternUS, $host, $matches );
81
- }
 
82
 
83
- if ( isset( $matches[0] ) ) {
84
- return array( "domain" => $matches[0], "host" => $host );
 
 
 
85
  } else {
86
  return false;
87
  }
@@ -130,7 +134,7 @@ if ( ! class_exists( 'Yoast_GA_Frontend' ) ) {
130
  $extension = substr( strrchr( $original_url, '.' ), 1 );
131
 
132
  // Break out immediately if the link is not an http or https link.
133
- if ( $protocol != 'http' && $protocol != 'https' && $protocol != 'mailto' ) {
134
  $type = null;
135
  } else {
136
  if ( ( $protocol == 'mailto' ) ) {
72
  $domainPatternUS = "/[^\.\/]+\.[^\.\/]+$/";
73
  $domainPatternUK = "/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/";
74
 
75
+ $matching = preg_match( $hostPattern, $uri, $matches );
76
+ if ( $matching ) {
77
+ $host = $matches[2];
78
+ if ( preg_match( "/.*\..*\..*\..*$/", $host ) ) {
79
+ preg_match( $domainPatternUK, $host, $matches );
80
+ } else {
81
+ preg_match( $domainPatternUS, $host, $matches );
82
+ }
83
 
84
+ if ( isset( $matches[0] ) ) {
85
+ return array( "domain" => $matches[0], "host" => $host );
86
+ } else {
87
+ return false;
88
+ }
89
  } else {
90
  return false;
91
  }
134
  $extension = substr( strrchr( $original_url, '.' ), 1 );
135
 
136
  // Break out immediately if the link is not an http or https link.
137
+ if ( $protocol !== 'http' && $protocol !== 'https' && $protocol !== 'mailto' ) {
138
  $type = null;
139
  } else {
140
  if ( ( $protocol == 'mailto' ) ) {
frontend/class-ga-js.php CHANGED
@@ -13,11 +13,14 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
13
 
14
  add_action( 'wp_head', array( $this, 'tracking' ), 8 );
15
 
16
- // Check for outbound
17
- add_filter( 'the_content', array( $this, 'the_content' ), 99 );
18
- add_filter( 'widget_text', array( $this, 'widget_content' ), 99 );
19
- add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 );
20
- add_filter( 'comment_text', array( $this, 'comment_text' ), 99 );
 
 
 
21
  }
22
 
23
  /**
@@ -26,18 +29,10 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
26
  * @todo, add the tracking code and remove this test output
27
  */
28
  public function tracking() {
29
- global $wp_query, $current_user;
30
-
31
- // Make sure $current_user is filled.
32
- get_currentuserinfo();
33
 
34
  $options = parent::$options['ga_general'];
35
- $gaq_push = array();
36
 
37
- /**
38
- * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
39
- */
40
- $customvarslot = 1;
41
  if ( parent::do_tracking() && ! is_preview() ) {
42
  $gaq_push = array();
43
 
@@ -131,11 +126,19 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
131
  /**
132
  * Ouput tracking link
133
  *
134
- * @param $link
 
135
  *
136
  * @return mixed
137
  */
138
- private function output_parse_link( $link ) {
 
 
 
 
 
 
 
139
  $onclick = NULL;
140
  $options = $this->get_options();
141
  $options = $options['ga_general'];
@@ -163,15 +166,9 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
163
 
164
  $onclick = "_gaq.push(['_trackEvent', '" . esc_attr ( $link['category'] ) . "-" . esc_attr ( $label ) . "', '" . esc_attr ( $full_url ) . "', '" . esc_attr ( strip_tags( $link['link_text'] ) ) . "']);";
165
 
166
- break;
167
- case 'internal':
168
- $onclick = NULL;
169
-
170
  break;
171
  case 'outbound':
172
- if ( $options['track_outbound'] == 1 ) {
173
- $onclick = "_gaq.push(['_trackEvent', '" . esc_attr ( $link['category'] ) . "', '" . esc_attr ( $full_url ) . "', '" . esc_attr ( strip_tags( $link['link_text'] ) ) . "']);";
174
- }
175
 
176
  break;
177
  }
@@ -189,7 +186,7 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
189
  * @return mixed
190
  */
191
  public function parse_article_link( $matches ) {
192
- return $this->output_parse_link( $this->get_target( 'outbound-article', $matches ) );
193
  }
194
 
195
  /**
@@ -200,7 +197,7 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
200
  * @return mixed
201
  */
202
  public function parse_comment_link( $matches ) {
203
- return $this->output_parse_link( $this->get_target( 'outbound-comment', $matches ) );
204
  }
205
 
206
  /**
@@ -211,7 +208,7 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
211
  * @return mixed
212
  */
213
  public function parse_widget_link( $matches ) {
214
- return $this->output_parse_link( $this->get_target( 'outbound-widget', $matches ) );
215
  }
216
 
217
  /**
@@ -222,7 +219,7 @@ if ( ! class_exists( 'Yoast_GA_JS' ) ) {
222
  * @return mixed
223
  */
224
  public function parse_nav_menu( $matches ) {
225
- return $this->output_parse_link( $this->get_target( 'outbound-menu', $matches ) );
226
  }
227
 
228
  /**
13
 
14
  add_action( 'wp_head', array( $this, 'tracking' ), 8 );
15
 
16
+ $options = parent::$options['ga_general'];
17
+ if ( $options['track_outbound'] == 1 ) {
18
+ // Check for outbound
19
+ add_filter( 'the_content', array( $this, 'the_content' ), 99 );
20
+ add_filter( 'widget_text', array( $this, 'widget_content' ), 99 );
21
+ add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 );
22
+ add_filter( 'comment_text', array( $this, 'comment_text' ), 99 );
23
+ }
24
  }
25
 
26
  /**
29
  * @todo, add the tracking code and remove this test output
30
  */
31
  public function tracking() {
32
+ global $wp_query;
 
 
 
33
 
34
  $options = parent::$options['ga_general'];
 
35
 
 
 
 
 
36
  if ( parent::do_tracking() && ! is_preview() ) {
37
  $gaq_push = array();
38
 
126
  /**
127
  * Ouput tracking link
128
  *
129
+ * @param string $label
130
+ * @param array $matches
131
  *
132
  * @return mixed
133
  */
134
+ private function output_parse_link( $label, $matches ) {
135
+ $link = $this->get_target( $label, $matches );
136
+
137
+ // bail early for links that we can't handle
138
+ if ( is_null( $link['type'] ) || 'internal' === $link['type'] ) {
139
+ return $matches[0];
140
+ }
141
+
142
  $onclick = NULL;
143
  $options = $this->get_options();
144
  $options = $options['ga_general'];
166
 
167
  $onclick = "_gaq.push(['_trackEvent', '" . esc_attr ( $link['category'] ) . "-" . esc_attr ( $label ) . "', '" . esc_attr ( $full_url ) . "', '" . esc_attr ( strip_tags( $link['link_text'] ) ) . "']);";
168
 
 
 
 
 
169
  break;
170
  case 'outbound':
171
+ $onclick = "_gaq.push(['_trackEvent', '" . esc_attr ( $link['category'] ) . "', '" . esc_attr ( $full_url ) . "', '" . esc_attr ( strip_tags( $link['link_text'] ) ) . "']);";
 
 
172
 
173
  break;
174
  }
186
  * @return mixed
187
  */
188
  public function parse_article_link( $matches ) {
189
+ return $this->output_parse_link( 'outbound-article', $matches );
190
  }
191
 
192
  /**
197
  * @return mixed
198
  */
199
  public function parse_comment_link( $matches ) {
200
+ return $this->output_parse_link( 'outbound-comment', $matches );
201
  }
202
 
203
  /**
208
  * @return mixed
209
  */
210
  public function parse_widget_link( $matches ) {
211
+ return $this->output_parse_link( 'outbound-widget', $matches );
212
  }
213
 
214
  /**
219
  * @return mixed
220
  */
221
  public function parse_nav_menu( $matches ) {
222
+ return $this->output_parse_link( 'outbound-menu', $matches );
223
  }
224
 
225
  /**
frontend/class-universal.php CHANGED
@@ -9,15 +9,18 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
9
  public $link_regex;
10
 
11
  public function __construct() {
12
- $this->link_regex = '/<a (.*?)href=[\'\"](.*?):\/*([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
13
 
14
  add_action( 'wp_head', array( $this, 'tracking' ), 8 );
15
 
16
- // Check for outbound option
17
- add_filter( 'the_content', array( $this, 'the_content' ), 99 );
18
- add_filter( 'widget_text', array( $this, 'widget_content' ), 99 );
19
- add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 );
20
- add_filter( 'comment_text', array( $this, 'comment_text' ), 99 );
 
 
 
21
  }
22
 
23
  /**
@@ -26,18 +29,10 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
26
  * @todo, add the tracking code and remove this test output
27
  */
28
  public function tracking() {
29
- global $wp_query, $current_user;
30
-
31
- // Make sure $current_user is filled.
32
- get_currentuserinfo();
33
 
34
  $options = parent::$options['ga_general'];
35
- $gaq_push = array();
36
 
37
- /**
38
- * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
39
- */
40
- $customvarslot = 1;
41
  if ( $this->do_tracking() && ! is_preview() ) {
42
  $gaq_push = array();
43
 
@@ -123,8 +118,7 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
123
  } else {
124
  require( GAWP_PATH . 'frontend/views/tracking_universal.php' );
125
  }
126
- }
127
- else{
128
  require( GAWP_PATH . 'frontend/views/tracking_usergroup.php' );
129
  }
130
  }
@@ -132,12 +126,20 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
132
  /**
133
  * Ouput tracking link
134
  *
135
- * @param $link
 
136
  *
137
  * @return mixed
138
  */
139
- private function output_parse_link( $link ) {
140
- $onclick = NULL;
 
 
 
 
 
 
 
141
  $options = $this->get_options();
142
  $options = $options['ga_general'];
143
  $full_url = $this->make_full_url( $link );
@@ -162,22 +164,19 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
162
  $label = 'int';
163
  }
164
 
165
- $onclick = "ga('send', 'event', '" . esc_attr( $link['category'] ) . "-" .esc_attr ( $label ) . "', '" . esc_attr( $full_url ) . "', '" . esc_attr ( strip_tags( $link['link_text'] ) ) . "');";
166
-
167
- break;
168
- case 'internal':
169
- $onclick = NULL;
170
 
171
  break;
172
  case 'outbound':
173
  if ( $options['track_outbound'] == 1 ) {
174
- $onclick = "ga('send', 'event', '" . esc_attr ( $link['category'] ) . "', '" . esc_attr( $full_url ) . "', '" . esc_attr( strip_tags( $link['link_text'] ) ) . "');";
175
  }
176
 
177
  break;
178
  }
179
 
180
  $link['link_attributes'] = $this->output_add_onclick( $link['link_attributes'], $onclick );
 
181
  return '<a href="' . $full_url . '" ' . $link['link_attributes'] . '>' . $link['link_text'] . '</a>';
182
 
183
  }
@@ -190,7 +189,7 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
190
  * @return mixed
191
  */
192
  public function parse_article_link( $matches ) {
193
- return $this->output_parse_link( $this->get_target( 'outbound-article', $matches ) );
194
  }
195
 
196
  /**
@@ -201,7 +200,7 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
201
  * @return mixed
202
  */
203
  public function parse_comment_link( $matches ) {
204
- return $this->output_parse_link( $this->get_target( 'outbound-comment', $matches ) );
205
  }
206
 
207
  /**
@@ -212,7 +211,7 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
212
  * @return mixed
213
  */
214
  public function parse_widget_link( $matches ) {
215
- return $this->output_parse_link( $this->get_target( 'outbound-widget', $matches ) );
216
  }
217
 
218
  /**
@@ -223,7 +222,7 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
223
  * @return mixed
224
  */
225
  public function parse_nav_menu( $matches ) {
226
- return $this->output_parse_link( $this->get_target( 'outbound-menu', $matches ) );
227
  }
228
 
229
  /**
@@ -269,8 +268,9 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
269
  * @return mixed
270
  */
271
  public function nav_menu( $text ) {
272
- if ( ! $this->do_tracking() )
273
  return $text;
 
274
 
275
  if ( ! is_feed() ) {
276
  $text = preg_replace_callback( $this->link_regex, array( $this, 'parse_nav_menu' ), $text );
@@ -287,8 +287,9 @@ if ( ! class_exists( 'Yoast_GA_Universal' ) ) {
287
  * @return mixed
288
  */
289
  public function comment_text( $text ) {
290
- if ( ! $this->do_tracking() )
291
  return $text;
 
292
 
293
  if ( ! is_feed() ) {
294
  $text = preg_replace_callback( $this->link_regex, array( $this, 'parse_comment_link' ), $text );
9
  public $link_regex;
10
 
11
  public function __construct() {
12
+ $this->link_regex = '`<a (.*?)href=[\'\"](.*?):/*([^\'\"]+)[\'\"](.*?)>(.*?)</a>`i';
13
 
14
  add_action( 'wp_head', array( $this, 'tracking' ), 8 );
15
 
16
+ $options = parent::$options['ga_general'];
17
+ if ( $options['track_outbound'] == 1 ) {
18
+ // Check for outbound option
19
+ add_filter( 'the_content', array( $this, 'the_content' ), 99 );
20
+ add_filter( 'widget_text', array( $this, 'widget_content' ), 99 );
21
+ add_filter( 'the_excerpt', array( $this, 'the_content' ), 99 );
22
+ add_filter( 'comment_text', array( $this, 'comment_text' ), 99 );
23
+ }
24
  }
25
 
26
  /**
29
  * @todo, add the tracking code and remove this test output
30
  */
31
  public function tracking() {
32
+ global $wp_query;
 
 
 
33
 
34
  $options = parent::$options['ga_general'];
 
35
 
 
 
 
 
36
  if ( $this->do_tracking() && ! is_preview() ) {
37
  $gaq_push = array();
38
 
118
  } else {
119
  require( GAWP_PATH . 'frontend/views/tracking_universal.php' );
120
  }
121
+ } else {
 
122
  require( GAWP_PATH . 'frontend/views/tracking_usergroup.php' );
123
  }
124
  }
126
  /**
127
  * Ouput tracking link
128
  *
129
+ * @param string $label
130
+ * @param array $matches
131
  *
132
  * @return mixed
133
  */
134
+ private function output_parse_link( $label, $matches ) {
135
+ $link = $this->get_target( $label, $matches );
136
+
137
+ // bail early for links that we can't handle
138
+ if ( is_null( $link['type'] ) || 'internal' === $link['type'] ) {
139
+ return $matches[0];
140
+ }
141
+
142
+ $onclick = null;
143
  $options = $this->get_options();
144
  $options = $options['ga_general'];
145
  $full_url = $this->make_full_url( $link );
164
  $label = 'int';
165
  }
166
 
167
+ $onclick = "ga('send', 'event', '" . esc_attr( $link['category'] ) . "-" . esc_attr( $label ) . "', '" . esc_attr( $full_url ) . "', '" . esc_attr( strip_tags( $link['link_text'] ) ) . "');";
 
 
 
 
168
 
169
  break;
170
  case 'outbound':
171
  if ( $options['track_outbound'] == 1 ) {
172
+ $onclick = "ga('send', 'event', '" . esc_attr( $link['category'] ) . "', '" . esc_attr( $full_url ) . "', '" . esc_attr( strip_tags( $link['link_text'] ) ) . "');";
173
  }
174
 
175
  break;
176
  }
177
 
178
  $link['link_attributes'] = $this->output_add_onclick( $link['link_attributes'], $onclick );
179
+
180
  return '<a href="' . $full_url . '" ' . $link['link_attributes'] . '>' . $link['link_text'] . '</a>';
181
 
182
  }
189
  * @return mixed
190
  */
191
  public function parse_article_link( $matches ) {
192
+ return $this->output_parse_link( 'outbound-article', $matches );
193
  }
194
 
195
  /**
200
  * @return mixed
201
  */
202
  public function parse_comment_link( $matches ) {
203
+ return $this->output_parse_link( 'outbound-comment', $matches );
204
  }
205
 
206
  /**
211
  * @return mixed
212
  */
213
  public function parse_widget_link( $matches ) {
214
+ return $this->output_parse_link( 'outbound-widget', $matches );
215
  }
216
 
217
  /**
222
  * @return mixed
223
  */
224
  public function parse_nav_menu( $matches ) {
225
+ return $this->output_parse_link( 'outbound-menu', $matches );
226
  }
227
 
228
  /**
268
  * @return mixed
269
  */
270
  public function nav_menu( $text ) {
271
+ if ( ! $this->do_tracking() ) {
272
  return $text;
273
+ }
274
 
275
  if ( ! is_feed() ) {
276
  $text = preg_replace_callback( $this->link_regex, array( $this, 'parse_nav_menu' ), $text );
287
  * @return mixed
288
  */
289
  public function comment_text( $text ) {
290
+ if ( ! $this->do_tracking() ) {
291
  return $text;
292
+ }
293
 
294
  if ( ! is_feed() ) {
295
  $text = preg_replace_callback( $this->link_regex, array( $this, 'parse_comment_link' ), $text );
googleanalytics.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Google Analytics by Yoast
4
  Plugin URI: https://yoast.com/wordpress/plugins/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v504
5
  Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. error page, search result and automatic clickout and download tracking.
6
  Author: Team Yoast
7
- Version: 5.0.4
8
  Requires at least: 3.8
9
  Author URI: https://yoast.com/
10
  License: GPL v3
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30
 
31
  // This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics, but has since been rewritten and refactored multiple times.
32
 
33
- define( "GAWP_VERSION", '5.0.4' );
34
 
35
  define( "GAWP_FILE", __FILE__ );
36
 
4
  Plugin URI: https://yoast.com/wordpress/plugins/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v504
5
  Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. error page, search result and automatic clickout and download tracking.
6
  Author: Team Yoast
7
+ Version: 5.0.5
8
  Requires at least: 3.8
9
  Author URI: https://yoast.com/
10
  License: GPL v3
30
 
31
  // This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics, but has since been rewritten and refactored multiple times.
32
 
33
+ define( "GAWP_VERSION", '5.0.5' );
34
 
35
  define( "GAWP_FILE", __FILE__ );
36
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://yoast.com/donate/
4
  Tags: analytics, google analytics, statistics, tracking, stats, google, yoast
5
  Requires at least: 3.8
6
  Tested up to: 4.0
7
- Stable tag: 5.0.4
8
 
9
  Track your WordPress site easily with the latest tracking codes and lots added data for search result pages and error pages.
10
 
@@ -49,6 +49,12 @@ This section describes how to install the plugin and get it working.
49
 
50
  == Changelog ==
51
 
 
 
 
 
 
 
52
  = 5.0.4 =
53
  Release Date: September 4th, 2014
54
 
4
  Tags: analytics, google analytics, statistics, tracking, stats, google, yoast
5
  Requires at least: 3.8
6
  Tested up to: 4.0
7
+ Stable tag: 5.0.5
8
 
9
  Track your WordPress site easily with the latest tracking codes and lots added data for search result pages and error pages.
10
 
49
 
50
  == Changelog ==
51
 
52
+ = 5.0.5 =
53
+ Release Date: September 4th, 2014
54
+
55
+ * Bugfixes:
56
+ * Fixes error in link parsing that would cause all sorts of display errors.
57
+
58
  = 5.0.4 =
59
  Release Date: September 4th, 2014
60