Google Analytics for WordPress by MonsterInsights - Version 3.2.1

Version Description

  • Slight change to RSS URL tagging, now setting campaign to post name, and behaving better when not using rewritten URL's.
  • Two patches by Lee Willis:
    • Made some changes so the entire plugin works fine with .co.uk, .co.za etc domains.
    • Made sure internal blogroll links aren't tagged as external clicks.
Download this release

Release Info

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

Code changes from version 3.2 to 3.2.1

Files changed (2) hide show
  1. googleanalytics.php +48 -36
  2. readme.txt +7 -1
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/
5
  Description: This plugin makes it simple to add Google Analytics with extra search engines and automatic clickout and download tracking to your WordPress blog.
6
  Author: Joost de Valk
7
- Version: 3.2
8
  Requires at least: 2.7
9
  Author URI: http://yoast.com/
10
  License: GPL
@@ -26,7 +26,7 @@ if ( ! class_exists( 'GA_Admin' ) ) {
26
 
27
  class GA_Admin extends Yoast_Plugin_Admin {
28
 
29
- var $hook = 'google-analytics';
30
  var $filename = 'google-analytics-for-wordpress/googleanalytics.php';
31
  var $longname = 'Google Analytics Configuration';
32
  var $shortname = 'Google Analytics';
@@ -103,16 +103,13 @@ if ( ! class_exists( 'GA_Admin' ) ) {
103
  $options[$option_name] = '';
104
  }
105
 
106
- foreach (array('extrase', 'imagese', 'trackoutbound', 'trackloggedin', 'admintracking', 'trackadsense', 'userv2', 'allowanchor', 'rsslinktagging', 'advancedsettings') as $option_name) {
107
  if (isset($_POST[$option_name]))
108
  $options[$option_name] = true;
109
  else
110
  $options[$option_name] = false;
111
  }
112
 
113
- if ($options['imagese'])
114
- $options['extrase'] = true;
115
-
116
  update_option('GoogleAnalyticsPP', $options);
117
  echo "<div id=\"updatemessage\" class=\"updated fade\"><p>Google Analytics settings updated.</p></div>\n";
118
  echo "<script type=\"text/javascript\">setTimeout(function(){jQuery('#updatemessage').hide('slow');}, 3000);</script>";
@@ -233,6 +230,12 @@ if ( ! class_exists( 'GA_Admin' ) ) {
233
  'label' => 'Track extra Search Engines',
234
  'content' => $this->checkbox('extrase'),
235
  );
 
 
 
 
 
 
236
  $rows[] = array(
237
  'id' => 'userv2',
238
  'label' => 'I use Urchin',
@@ -240,9 +243,14 @@ if ( ! class_exists( 'GA_Admin' ) ) {
240
  );
241
  $rows[] = array(
242
  'id' => 'rsslinktagging',
243
- 'label' => 'Tag the links in your RSS feed with campaign variables.',
244
  'content' => $this->checkbox('rsslinktagging'),
245
  );
 
 
 
 
 
246
  $rows[] = array(
247
  'id' => 'allowanchor',
248
  'label' => 'Use # instead of ? for Campaign tracking?',
@@ -356,7 +364,7 @@ if ( ! class_exists( 'GA_Filter' ) ) {
356
  */
357
  echo "\t".'} catch(err) {}'."\n";
358
  echo '</script>'."\n";
359
- echo '<script src="'.gapp_plugin_path().'"custom_se.js" type="text/javascript"></script>'."\n";
360
  echo '<script type="text/javascript">'."\n";
361
  echo "\t".'try {'."\n";
362
  }
@@ -379,9 +387,10 @@ if ( ! class_exists( 'GA_Filter' ) ) {
379
  }
380
 
381
  if ( strpos($_SERVER['HTTP_REFERER'],"images.google") && strpos($_SERVER['HTTP_REFERER'],"&prev") && $options["imagese"] ) {
382
- echo "\t\t".'regex = new RegExp("images.google.([^\/]+).*&prev=([^&]+)");'."\n";
383
- echo "\t\t".'var match = regex.exec(pageTracker.qa);'."\n";
384
- echo "\t\t".'pageTracker.qa = "http://images.google." + match[1] + unescape(match[2]);'."\n";
 
385
  }
386
 
387
  echo "\t\t".'pageTracker._trackPageview();'."\n";
@@ -414,20 +423,22 @@ if ( ! class_exists( 'GA_Filter' ) ) {
414
  */
415
  function ga_get_domain($uri){
416
  $hostPattern = "/^(http:\/\/)?([^\/]+)/i";
417
- $domainPattern = "/[^\.\/]+\.[^\.\/]+$/";
 
418
 
419
  preg_match($hostPattern, $uri, $matches);
420
  $host = $matches[2];
421
- preg_match($domainPattern, $host, $matches);
422
- if (isset($matches[0]))
423
- return array("domain"=>$matches[0],"host"=>$host);
424
- else
425
- return array("domain"=>"","host"=>"");
 
 
426
  }
427
 
428
  function ga_parse_link($leaf, $matches){
429
  $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
430
-
431
  $options = get_option('GoogleAnalyticsPP');
432
 
433
  // Break out immediately if the link is not an http or https link.
@@ -515,11 +526,12 @@ if ( ! class_exists( 'GA_Filter' ) ) {
515
  $options = get_option('GoogleAnalyticsPP');
516
 
517
  if (!is_admin() && (!current_user_can('edit_users') || $options['admintracking'] ) ) {
518
- $options = get_option('GoogleAnalyticsPP');
519
-
520
  foreach ( (array) $bookmarks as $bookmark ) {
 
 
 
 
521
  if ($options['domainorurl'] == "domain") {
522
- $target = GA_Filter::ga_get_domain($bookmark->link_url);
523
  $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$target["host"]."');";
524
  } else if ($options['domainorurl'] == "url") {
525
  $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$bookmark->link_url."');";
@@ -531,16 +543,16 @@ if ( ! class_exists( 'GA_Filter' ) ) {
531
 
532
  function rsslinktagger($guid) {
533
  $options = get_option('GoogleAnalyticsPP');
534
- global $wp;
535
- if ($wp->request == 'feed') {
536
  if ( $options['allowanchor'] ) {
537
  $delimiter = '#';
538
  } else {
539
  $delimiter = '?';
 
 
540
  }
541
- if (strpos ( $guid, $delimiter ) > 0)
542
- $delimiter = '&amp;';
543
- return $guid . $delimiter . 'utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=rss';
544
  }
545
  }
546
 
@@ -578,9 +590,8 @@ if ( $options['allowanchor'] ) {
578
  $gaf = new GA_Filter();
579
  $options = get_option('GoogleAnalyticsPP');
580
 
581
- if (!is_array($options)) {
582
  $ga_admin->set_defaults();
583
- }
584
 
585
  if ($options['trackoutbound']) {
586
  // filters alter the existing content
@@ -591,17 +602,18 @@ if ($options['trackoutbound']) {
591
  add_filter('get_comment_author_link', array('GA_Filter','comment_author_link'), 99);
592
  }
593
 
594
- if ($options['trackadsense']) {
595
  add_action('wp_head', array('GA_Filter','spool_adsense'),10);
596
- }
597
 
598
- if ($options['position'] == 'footer' || $options['position'] == "") {
599
  add_action('wp_footer', array('GA_Filter','spool_analytics'));
600
- } else {
601
  add_action('wp_head', array('GA_Filter','spool_analytics'),20);
602
- }
603
 
604
- if ($options['rsslinktagging']) {
 
 
 
605
  add_filter ( 'the_permalink_rss', array('GA_Filter','rsslinktagger'), 99 );
606
- }
607
  ?>
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
5
  Description: This plugin makes it simple to add Google Analytics with extra search engines and automatic clickout and download tracking to your WordPress blog.
6
  Author: Joost de Valk
7
+ Version: 3.2.1
8
  Requires at least: 2.7
9
  Author URI: http://yoast.com/
10
  License: GPL
26
 
27
  class GA_Admin extends Yoast_Plugin_Admin {
28
 
29
+ var $hook = 'google-analytics-for-wordpress';
30
  var $filename = 'google-analytics-for-wordpress/googleanalytics.php';
31
  var $longname = 'Google Analytics Configuration';
32
  var $shortname = 'Google Analytics';
103
  $options[$option_name] = '';
104
  }
105
 
106
+ foreach (array('extrase', 'imagese', 'trackoutbound', 'trackloggedin', 'admintracking', 'trackadsense', 'userv2', 'allowanchor', 'rsslinktagging', 'advancedsettings', 'trackregistration') as $option_name) {
107
  if (isset($_POST[$option_name]))
108
  $options[$option_name] = true;
109
  else
110
  $options[$option_name] = false;
111
  }
112
 
 
 
 
113
  update_option('GoogleAnalyticsPP', $options);
114
  echo "<div id=\"updatemessage\" class=\"updated fade\"><p>Google Analytics settings updated.</p></div>\n";
115
  echo "<script type=\"text/javascript\">setTimeout(function(){jQuery('#updatemessage').hide('slow');}, 3000);</script>";
230
  'label' => 'Track extra Search Engines',
231
  'content' => $this->checkbox('extrase'),
232
  );
233
+ $rows[] = array(
234
+ 'id' => 'imagese',
235
+ 'label' => 'Track Google Image Search as a Search Engine',
236
+ 'desc' => 'This functionality is in beta, and not confirmed to work yet',
237
+ 'content' => $this->checkbox('imagese'),
238
+ );
239
  $rows[] = array(
240
  'id' => 'userv2',
241
  'label' => 'I use Urchin',
243
  );
244
  $rows[] = array(
245
  'id' => 'rsslinktagging',
246
+ 'label' => 'Tag links in RSS feed with campaign variables',
247
  'content' => $this->checkbox('rsslinktagging'),
248
  );
249
+ $rows[] = array(
250
+ 'id' => 'trackregistration',
251
+ 'label' => 'Add tracking to the login and registration forms',
252
+ 'content' => $this->checkbox('trackregistration'),
253
+ );
254
  $rows[] = array(
255
  'id' => 'allowanchor',
256
  'label' => 'Use # instead of ? for Campaign tracking?',
364
  */
365
  echo "\t".'} catch(err) {}'."\n";
366
  echo '</script>'."\n";
367
+ echo '<script src="'.gapp_plugin_path().'custom_se.js" type="text/javascript"></script>'."\n";
368
  echo '<script type="text/javascript">'."\n";
369
  echo "\t".'try {'."\n";
370
  }
387
  }
388
 
389
  if ( strpos($_SERVER['HTTP_REFERER'],"images.google") && strpos($_SERVER['HTTP_REFERER'],"&prev") && $options["imagese"] ) {
390
+ echo "\t\t".'pageTracker._addOrganic("images.google","prev");'."\n";
391
+ // echo "\t\t".'regex = new RegExp("images.google.([^\/]+).*&prev=([^&]+)");'."\n";
392
+ // echo "\t\t".'var match = regex.exec(pageTracker.qa);'."\n";
393
+ // echo "\t\t".'pageTracker.qa = "http://images.google." + match[1] + unescape(match[2]);'."\n";
394
  }
395
 
396
  echo "\t\t".'pageTracker._trackPageview();'."\n";
423
  */
424
  function ga_get_domain($uri){
425
  $hostPattern = "/^(http:\/\/)?([^\/]+)/i";
426
+ $domainPatternUS = "/[^\.\/]+\.[^\.\/]+$/";
427
+ $domainPatternUK = "/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/";
428
 
429
  preg_match($hostPattern, $uri, $matches);
430
  $host = $matches[2];
431
+ if (preg_match("/.*\..*\..*\..*$/",$host)) {
432
+ preg_match($domainPatternUK, $host, $matches);
433
+ } else {
434
+ preg_match($domainPatternUS, $host, $matches);
435
+ }
436
+
437
+ return array("domain"=>$matches[0],"host"=>$host);
438
  }
439
 
440
  function ga_parse_link($leaf, $matches){
441
  $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
 
442
  $options = get_option('GoogleAnalyticsPP');
443
 
444
  // Break out immediately if the link is not an http or https link.
526
  $options = get_option('GoogleAnalyticsPP');
527
 
528
  if (!is_admin() && (!current_user_can('edit_users') || $options['admintracking'] ) ) {
 
 
529
  foreach ( (array) $bookmarks as $bookmark ) {
530
+ $target = GA_Filter::ga_get_domain($bookmark->link_url);
531
+ $sitedomain = GA_Filter::ga_get_domain(get_bloginfo('url'));
532
+ if ($target['host'] == $sitedomain['host'])
533
+ continue;
534
  if ($options['domainorurl'] == "domain") {
 
535
  $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$target["host"]."');";
536
  } else if ($options['domainorurl'] == "url") {
537
  $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$bookmark->link_url."');";
543
 
544
  function rsslinktagger($guid) {
545
  $options = get_option('GoogleAnalyticsPP');
546
+ global $wp, $post;
547
+ if ( is_feed() ) {
548
  if ( $options['allowanchor'] ) {
549
  $delimiter = '#';
550
  } else {
551
  $delimiter = '?';
552
+ if (strpos ( $guid, $delimiter ) > 0)
553
+ $delimiter = '&amp;';
554
  }
555
+ return $guid . $delimiter . 'utm_source=rss&amp;utm_medium=rss&amp;utm_campaign='.urlencode($post->post_name);
 
 
556
  }
557
  }
558
 
590
  $gaf = new GA_Filter();
591
  $options = get_option('GoogleAnalyticsPP');
592
 
593
+ if (!is_array($options))
594
  $ga_admin->set_defaults();
 
595
 
596
  if ($options['trackoutbound']) {
597
  // filters alter the existing content
602
  add_filter('get_comment_author_link', array('GA_Filter','comment_author_link'), 99);
603
  }
604
 
605
+ if ($options['trackadsense'])
606
  add_action('wp_head', array('GA_Filter','spool_adsense'),10);
 
607
 
608
+ if ($options['position'] == 'footer' || $options['position'] == "")
609
  add_action('wp_footer', array('GA_Filter','spool_analytics'));
610
+ else
611
  add_action('wp_head', array('GA_Filter','spool_analytics'),20);
 
612
 
613
+ if ($options['trackregistration'])
614
+ add_action('login_head', array('GA_Filter','spool_analytics'),20);
615
+
616
+ if ($options['rsslinktagging'])
617
  add_filter ( 'the_permalink_rss', array('GA_Filter','rsslinktagger'), 99 );
618
+
619
  ?>
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://yoast.com/donate/
4
  Tags: analytics, google analytics, statistics
5
  Requires at least: 2.7
6
  Tested up to: 2.8.2
7
- Stable tag: 3.2
8
 
9
  The Google Analytics for WordPress plugin automatically tracks and segments all outbound links from within posts, comment author links, links within comments, blogroll links and downloads. It also allows you to track AdSense clicks, add extra search engines, track image search queries and it will even work together with Urchin.
10
 
@@ -29,6 +29,12 @@ This section describes how to install the plugin and get it working.
29
 
30
  == Changelog ==
31
 
 
 
 
 
 
 
32
  = 3.2 =
33
  * Added option to add tracking to add tracking to login / register pages, so you can track new signups (under Advanced settings).
34
  * Added beta option to track Google image search as a search engine, needs more testing to make sure it works.
4
  Tags: analytics, google analytics, statistics
5
  Requires at least: 2.7
6
  Tested up to: 2.8.2
7
+ Stable tag: 3.2.1
8
 
9
  The Google Analytics for WordPress plugin automatically tracks and segments all outbound links from within posts, comment author links, links within comments, blogroll links and downloads. It also allows you to track AdSense clicks, add extra search engines, track image search queries and it will even work together with Urchin.
10
 
29
 
30
  == Changelog ==
31
 
32
+ = 3.2.1 =
33
+ * Slight change to RSS URL tagging, now setting campaign to post name, and behaving better when not using rewritten URL's.
34
+ * Two patches by [Lee Willis](http://www.leewillis.co.uk):
35
+ * Made some changes so the entire plugin works fine with .co.uk, .co.za etc domains.
36
+ * Made sure internal blogroll links aren't tagged as external clicks.
37
+
38
  = 3.2 =
39
  * Added option to add tracking to add tracking to login / register pages, so you can track new signups (under Advanced settings).
40
  * Added beta option to track Google image search as a search engine, needs more testing to make sure it works.