Google Analytics for WordPress by MonsterInsights - Version 4.0

Version Description

  • NOTE WHEN UPGRADING: you'll have to reconfigure the plugin so it can fully support all the new features!
  • Complete rewrite of the codebase
  • Switched to the new asynchronous event tracking model
  • Switched link tracking to an event tracking model, because of this change removed 5 settings from the settings panel that were no longer needed
  • Implemented custom variable tracking to track:
    • On the session level: whether the user is logged in or not.
    • On the page level: the current posts's author, category, tags, year of publication and post type.
  • Added Google Analytics API integration, so you can easily select a site to track.
  • E-Commerce integration, tracking transactions, support for WP E-Commerce and Shopp.
  • Much much more: check out the release post.
Download this release

Release Info

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

Code changes from version 3.2.5 to 4.0

account-id.png DELETED
Binary file
custom_se.js DELETED
@@ -1,125 +0,0 @@
1
- // This JavaScript was developed by GA-Experts (http://www.ga-experts.co.uk) for Google Analytics
2
- // Please use this code to overwrite the default set of Search Engines in the GA tracking code
3
- // Use this code at your own risk. GA Experts takes no responsibility for errors, loss of data or any other complications arising from the use of this code
4
- // Version 2.0 (Mar 2007) - many thanks to Brian Clifton and Tomas Remotigue for help with this
5
- // For enquiries please contact mail@ga-experts.co.uk
6
-
7
- // Dutch Search Engines added by Joost de Valk (http://www.joostdevalk.nl)
8
- // For enquiries specifically about the Dutch SE's please contact joost@joostdevalk.nl
9
-
10
- // Google EMEA Image domains
11
- pageTracker._addOrganic("images.google.co.uk","q");
12
- pageTracker._addOrganic("images.google.es","q");
13
- pageTracker._addOrganic("images.google.pt","q");
14
- pageTracker._addOrganic("images.google.it","q");
15
- pageTracker._addOrganic("images.google.fr","q");
16
- pageTracker._addOrganic("images.google.nl","q");
17
- pageTracker._addOrganic("images.google.be","q");
18
- pageTracker._addOrganic("images.google.de","q");
19
- pageTracker._addOrganic("images.google.no","q");
20
- pageTracker._addOrganic("images.google.se","q");
21
- pageTracker._addOrganic("images.google.dk","q");
22
- pageTracker._addOrganic("images.google.fi","q");
23
- pageTracker._addOrganic("images.google.ch","q");
24
- pageTracker._addOrganic("images.google.at","q");
25
- pageTracker._addOrganic("images.google.ie","q");
26
- pageTracker._addOrganic("images.google.ru","q");
27
- pageTracker._addOrganic("images.google.pl","q");
28
-
29
- // Other Google Image search
30
- pageTracker._addOrganic("images.google.com","q");
31
- pageTracker._addOrganic("images.google.ca","q");
32
- pageTracker._addOrganic("images.google.com.au","q");
33
- pageTracker._addOrganic("images.google","q");
34
-
35
- // Blogsearch
36
- pageTracker._addOrganic("blogsearch.google","q");
37
-
38
- // Google EMEA Domains
39
- pageTracker._addOrganic("google.co.uk","q");
40
- pageTracker._addOrganic("google.es","q");
41
- pageTracker._addOrganic("google.pt","q");
42
- pageTracker._addOrganic("google.it","q");
43
- pageTracker._addOrganic("google.fr","q");
44
- pageTracker._addOrganic("google.nl","q");
45
- pageTracker._addOrganic("google.be","q");
46
- pageTracker._addOrganic("google.de","q");
47
- pageTracker._addOrganic("google.no","q");
48
- pageTracker._addOrganic("google.se","q");
49
- pageTracker._addOrganic("google.dk","q");
50
- pageTracker._addOrganic("google.fi","q");
51
- pageTracker._addOrganic("google.ch","q");
52
- pageTracker._addOrganic("google.at","q");
53
- pageTracker._addOrganic("google.ie","q");
54
- pageTracker._addOrganic("google.ru","q");
55
- pageTracker._addOrganic("google.pl","q");
56
-
57
- // Yahoo EMEA Domains
58
- pageTracker._addOrganic("uk.yahoo.com","p");
59
- pageTracker._addOrganic("es.yahoo.com","p");
60
- pageTracker._addOrganic("pt.yahoo.com","p");
61
- pageTracker._addOrganic("it.yahoo.com","p");
62
- pageTracker._addOrganic("fr.yahoo.com","p");
63
- pageTracker._addOrganic("nl.yahoo.com","p");
64
- pageTracker._addOrganic("be.yahoo.com","p");
65
- pageTracker._addOrganic("de.yahoo.com","p");
66
- pageTracker._addOrganic("no.yahoo.com","p");
67
- pageTracker._addOrganic("se.yahoo.com","p");
68
- pageTracker._addOrganic("dk.yahoo.com","p");
69
- pageTracker._addOrganic("fi.yahoo.com","p");
70
- pageTracker._addOrganic("ch.yahoo.com","p");
71
- pageTracker._addOrganic("at.yahoo.com","p");
72
- pageTracker._addOrganic("ie.yahoo.com","p");
73
- pageTracker._addOrganic("ru.yahoo.com","p");
74
- pageTracker._addOrganic("pl.yahoo.com","p");
75
-
76
- // UK specific
77
- pageTracker._addOrganic("hotbot.co.uk","query");
78
- pageTracker._addOrganic("excite.co.uk","q");
79
- pageTracker._addOrganic("bbc","q");
80
- pageTracker._addOrganic("tiscali","query");
81
- pageTracker._addOrganic("uk.ask.com","q");
82
- pageTracker._addOrganic("blueyonder","q");
83
- pageTracker._addOrganic("search.aol.co.uk","query");
84
- pageTracker._addOrganic("ntlworld","q");
85
- pageTracker._addOrganic("tesco.net","q");
86
- pageTracker._addOrganic("orange.co.uk","q");
87
- pageTracker._addOrganic("mywebsearch.com","searchfor");
88
- pageTracker._addOrganic("uk.myway.com","searchfor");
89
- pageTracker._addOrganic("searchy.co.uk","search_term");
90
- pageTracker._addOrganic("msn.co.uk","q");
91
- pageTracker._addOrganic("uk.altavista.com","q");
92
- pageTracker._addOrganic("lycos.co.uk","query");
93
-
94
- // NL specific
95
- pageTracker._addOrganic("chello.nl","q1");
96
- pageTracker._addOrganic("home.nl","q");
97
- pageTracker._addOrganic("planet.nl","googleq=q");
98
- pageTracker._addOrganic("search.ilse.nl","search_for");
99
- pageTracker._addOrganic("search-dyn.tiscali.nl","key");
100
- pageTracker._addOrganic("startgoogle.startpagina.nl","q");
101
- pageTracker._addOrganic("vinden.nl","q");
102
- pageTracker._addOrganic("vindex.nl","search_for");
103
- pageTracker._addOrganic("zoeken.nl","query");
104
- pageTracker._addOrganic("zoeken.track.nl","qr");
105
- pageTracker._addOrganic("zoeknu.nl","Keywords");
106
-
107
- // Extras
108
- pageTracker._addOrganic("alltheweb","q");
109
- pageTracker._addOrganic("ananzi","qt");
110
- pageTracker._addOrganic("anzwers","search");
111
- pageTracker._addOrganic("araby.com","q");
112
- pageTracker._addOrganic("dogpile","q");
113
- pageTracker._addOrganic("elmundo.es","q");
114
- pageTracker._addOrganic("ezilon.com","q");
115
- pageTracker._addOrganic("hotbot","query");
116
- pageTracker._addOrganic("indiatimes.com","query");
117
- pageTracker._addOrganic("iafrica.funnel.co.za","q");
118
- pageTracker._addOrganic("mywebsearch.com","searchfor");
119
- pageTracker._addOrganic("rambler.ru","words");
120
- pageTracker._addOrganic("search.aol.com","encquery");
121
- pageTracker._addOrganic("search.indiatimes.com","query");
122
- pageTracker._addOrganic("searcheurope.com","query");
123
- pageTracker._addOrganic("suche.web.de","su");
124
- pageTracker._addOrganic("terra.es","query");
125
- pageTracker._addOrganic("voila.fr","kw");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
custom_se_async.js ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // This JavaScript was developed by GA-Experts (http://www.ga-experts.co.uk) for Google Analytics
2
+ // Please use this code to overwrite the default set of Search Engines in the GA tracking code
3
+ // Use this code at your own risk. GA Experts takes no responsibility for errors, loss of data or any other complications arising from the use of this code
4
+ // Version 2.0 (Mar 2007) - many thanks to Brian Clifton and Tomas Remotigue for help with this
5
+ // For enquiries please contact mail@ga-experts.co.uk
6
+
7
+ // Dutch Search Engines added by Joost de Valk (http://www.joostdevalk.nl)
8
+ // For enquiries specifically about the Dutch SE's please contact joost@joostdevalk.nl
9
+
10
+ // Google EMEA Image domains
11
+ _gaq.push(
12
+ ['_addOrganic','images.google.co.uk','q'],
13
+ ['_addOrganic','images.google.es','q'],
14
+ ['_addOrganic','images.google.pt','q'],
15
+ ['_addOrganic','images.google.it','q'],
16
+ ['_addOrganic','images.google.fr','q'],
17
+ ['_addOrganic','images.google.nl','q'],
18
+ ['_addOrganic','images.google.be','q'],
19
+ ['_addOrganic','images.google.de','q'],
20
+ ['_addOrganic','images.google.no','q'],
21
+ ['_addOrganic','images.google.se','q'],
22
+ ['_addOrganic','images.google.dk','q'],
23
+ ['_addOrganic','images.google.fi','q'],
24
+ ['_addOrganic','images.google.ch','q'],
25
+ ['_addOrganic','images.google.at','q'],
26
+ ['_addOrganic','images.google.ie','q'],
27
+ ['_addOrganic','images.google.ru','q'],
28
+ ['_addOrganic','images.google.pl','q']
29
+ );
30
+
31
+ // Other Google Image search
32
+ _gaq.push(
33
+ ['_addOrganic','images.google.com','q'],
34
+ ['_addOrganic','images.google.ca','q'],
35
+ ['_addOrganic','images.google.com.au','q'],
36
+ ['_addOrganic','images.google','q']
37
+ );
38
+
39
+ // Blogsearch
40
+ _gaq.push(
41
+ ['_addOrganic','blogsearch.google','q']
42
+ );
43
+
44
+ // Google EMEA Domains
45
+ _gaq.push(
46
+ ['_addOrganic','google.co.uk','q'],
47
+ ['_addOrganic','google.es','q'],
48
+ ['_addOrganic','google.pt','q'],
49
+ ['_addOrganic','google.it','q'],
50
+ ['_addOrganic','google.fr','q'],
51
+ ['_addOrganic','google.nl','q'],
52
+ ['_addOrganic','google.be','q'],
53
+ ['_addOrganic','google.de','q'],
54
+ ['_addOrganic','google.no','q'],
55
+ ['_addOrganic','google.se','q'],
56
+ ['_addOrganic','google.dk','q'],
57
+ ['_addOrganic','google.fi','q'],
58
+ ['_addOrganic','google.ch','q'],
59
+ ['_addOrganic','google.at','q'],
60
+ ['_addOrganic','google.ie','q'],
61
+ ['_addOrganic','google.ru','q'],
62
+ ['_addOrganic','google.pl','q']
63
+ );
64
+
65
+ // Yahoo EMEA Domains
66
+ _gaq.push(
67
+ ['_addOrganic','uk.yahoo.com','p'],
68
+ ['_addOrganic','es.yahoo.com','p'],
69
+ ['_addOrganic','pt.yahoo.com','p'],
70
+ ['_addOrganic','it.yahoo.com','p'],
71
+ ['_addOrganic','fr.yahoo.com','p'],
72
+ ['_addOrganic','nl.yahoo.com','p'],
73
+ ['_addOrganic','be.yahoo.com','p'],
74
+ ['_addOrganic','de.yahoo.com','p'],
75
+ ['_addOrganic','no.yahoo.com','p'],
76
+ ['_addOrganic','se.yahoo.com','p'],
77
+ ['_addOrganic','dk.yahoo.com','p'],
78
+ ['_addOrganic','fi.yahoo.com','p'],
79
+ ['_addOrganic','ch.yahoo.com','p'],
80
+ ['_addOrganic','at.yahoo.com','p'],
81
+ ['_addOrganic','ie.yahoo.com','p'],
82
+ ['_addOrganic','ru.yahoo.com','p'],
83
+ ['_addOrganic','pl.yahoo.com','p']
84
+ );
85
+
86
+ // UK specific
87
+ _gaq.push(
88
+ ['_addOrganic','hotbot.co.uk','query'],
89
+ ['_addOrganic','excite.co.uk','q'],
90
+ ['_addOrganic','bbc','q'],
91
+ ['_addOrganic','tiscali','query'],
92
+ ['_addOrganic','uk.ask.com','q'],
93
+ ['_addOrganic','blueyonder','q'],
94
+ ['_addOrganic','search.aol.co.uk','query'],
95
+ ['_addOrganic','ntlworld','q'],
96
+ ['_addOrganic','tesco.net','q'],
97
+ ['_addOrganic','orange.co.uk','q'],
98
+ ['_addOrganic','mywebsearch.com','searchfor'],
99
+ ['_addOrganic','uk.myway.com','searchfor'],
100
+ ['_addOrganic','searchy.co.uk','search_term'],
101
+ ['_addOrganic','msn.co.uk','q'],
102
+ ['_addOrganic','uk.altavista.com','q'],
103
+ ['_addOrganic','lycos.co.uk','query']
104
+ );
105
+
106
+ // NL specific
107
+ _gaq.push(
108
+ ['_addOrganic','chello.nl','q1'],
109
+ ['_addOrganic','home.nl','q'],
110
+ ['_addOrganic','planet.nl','googleq=q'],
111
+ ['_addOrganic','search.ilse.nl','search_for'],
112
+ ['_addOrganic','search-dyn.tiscali.nl','key'],
113
+ ['_addOrganic','startgoogle.startpagina.nl','q'],
114
+ ['_addOrganic','vinden.nl','q'],
115
+ ['_addOrganic','vindex.nl','search_for'],
116
+ ['_addOrganic','zoeken.nl','query'],
117
+ ['_addOrganic','zoeken.track.nl','qr'],
118
+ ['_addOrganic','zoeknu.nl','Keywords']
119
+ );
120
+
121
+ // Extras
122
+ _gaq.push(
123
+ ['_addOrganic','alltheweb','q'],
124
+ ['_addOrganic','ananzi','qt'],
125
+ ['_addOrganic','anzwers','search'],
126
+ ['_addOrganic','araby.com','q'],
127
+ ['_addOrganic','dogpile','q'],
128
+ ['_addOrganic','elmundo.es','q'],
129
+ ['_addOrganic','ezilon.com','q'],
130
+ ['_addOrganic','hotbot','query'],
131
+ ['_addOrganic','indiatimes.com','query'],
132
+ ['_addOrganic','iafrica.funnel.co.za','q'],
133
+ ['_addOrganic','mywebsearch.com','searchfor'],
134
+ ['_addOrganic','rambler.ru','words'],
135
+ ['_addOrganic','search.aol.com','encquery'],
136
+ ['_addOrganic','search.indiatimes.com','query'],
137
+ ['_addOrganic','searcheurope.com','query'],
138
+ ['_addOrganic','suche.web.de','su'],
139
+ ['_addOrganic','terra.es','query'],
140
+ ['_addOrganic','voila.fr','kw']
141
+ );
googleanalytics.php CHANGED
@@ -1,16 +1,16 @@
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.5
8
- Requires at least: 2.7
9
  Author URI: http://yoast.com/
10
  License: GPL
11
 
12
  */
13
-
14
  // Determine the location
15
  function gapp_plugin_path() {
16
  return plugins_url('', __FILE__).'/';
@@ -24,16 +24,16 @@ if ( ! class_exists( 'GA_Admin' ) ) {
24
 
25
  require_once('yst_plugin_tools.php');
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';
33
- var $ozhicon = 'chart_curve.png';
34
- var $optionname = 'GoogleAnalyticsPP';
35
  var $homepage = 'http://yoast.com/wordpress/google-analytics/';
36
-
37
 
38
  function GA_Admin() {
39
  add_action( 'admin_menu', array(&$this, 'register_settings_page') );
@@ -44,29 +44,89 @@ if ( ! class_exists( 'GA_Admin' ) ) {
44
  add_action('admin_print_styles', array(&$this,'config_page_styles'));
45
 
46
  add_action('wp_dashboard_setup', array(&$this,'widget_setup'));
 
47
  add_action('admin_head', array(&$this,'config_page_head'));
 
 
 
 
 
 
 
48
  }
49
 
50
  function config_page_head() {
51
- if ($_GET['page'] == $this->hook) {
 
 
 
 
 
 
52
  wp_enqueue_script('jquery');
53
  ?>
54
- <script type="text/javascript" charset="utf-8">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  jQuery(document).ready(function(){
56
- jQuery('#explanation td').css("display","none");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  jQuery('#advancedsettings').change(function(){
58
  if ((jQuery('#advancedsettings').attr('checked')) == true) {
59
  jQuery('#advancedgasettings').css("display","block");
 
 
60
  } else {
61
  jQuery('#advancedgasettings').css("display","none");
 
 
62
  }
63
  }).change();
64
- jQuery('#explain').click(function(){
65
- if ((jQuery('#explanation').css("display")) == "block") {
66
- jQuery('#explanation').css("display","none");
67
  } else {
68
- jQuery('#explanation').css("display","block");
69
  }
 
 
 
 
 
 
70
  });
71
  });
72
  </script>
@@ -74,85 +134,232 @@ if ( ! class_exists( 'GA_Admin' ) ) {
74
  }
75
  }
76
 
77
- function checkbox($id) {
78
- $options = get_option($this->optionname);
79
- return '<input type="checkbox" id="'.$id.'" name="'.$id.'"'. checked($options[$id],true,false).'/>';
80
- }
 
 
81
 
82
- function textinput($id) {
83
- $options = get_option($this->optionname);
84
- return '<input type="text" id="'.$id.'" name="'.$id.'" size="30" value="'.$options[$id].'"/>';
 
 
85
  }
86
 
87
- function config_page() {
88
- $options = get_option('GoogleAnalyticsPP');
89
-
90
- if ( (isset($_POST['reset']) && $_POST['reset'] == "true") || !is_array($options) ) {
91
- $this->set_defaults();
92
- echo "<div class=\"updated\"><p>Google Analytics settings reset to default.</p></div>\n";
93
  }
94
-
95
- if ( isset($_POST['submit']) ) {
 
 
 
 
 
 
 
 
 
96
  if (!current_user_can('manage_options')) die(__('You cannot edit the Google Analytics for WordPress options.'));
97
  check_admin_referer('analyticspp-config');
98
 
99
- foreach (array('uastring', 'dlextensions', 'dlprefix', 'artprefix', 'comprefix', 'comautprefix', 'blogrollprefix', 'domainorurl','position','domain') as $option_name) {
100
  if (isset($_POST[$option_name]))
101
  $options[$option_name] = $_POST[$option_name];
102
  else
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>";
 
 
 
116
  }
117
-
118
-
 
 
 
 
 
 
 
 
 
 
119
  ?>
120
  <div class="wrap">
121
- <a href="http://yoast.com/"><div id="yoast-icon" style="background: url(http://cdn.yoast.com/theme/yoast-32x32.png) no-repeat;" class="icon32"><br /></div></a>
122
  <h2>Google Analytics for WordPress Configuration</h2>
123
- <div class="postbox-container" style="width:70%;">
124
  <div class="metabox-holder">
125
  <div class="meta-box-sortables">
126
- <form action="" method="post" id="analytics-conf">
 
127
  <?php
128
  wp_nonce_field('analyticspp-config');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  $rows = array();
 
130
  $rows[] = array(
131
  'id' => 'uastring',
132
- 'label' => 'Analytics Account ID',
133
- 'desc' => '<a href="#" id="explain">What\'s this?</a>',
134
- 'content' => '<input id="uastring" name="uastring" type="text" size="20" maxlength="40" value="'.$options['uastring'].'"/><br/><div id="explanation" style="background: #fff; border: 1px solid #ccc; padding: 5px; display:none;">
135
- <strong>Explanation</strong><br/>
136
- Find the Account ID, starting with UA- in your account overview, as marked below:<br/>
137
- <br/>
138
- <img src="'.gapp_plugin_path().'/account-id.png" alt="Account ID"/><br/>
139
- <br/>
140
- Once you have entered your Account ID in the box above your pages will be trackable by Google Analytics.<br/>
141
- Still can\'t find it? Watch <a href="http://yoast.com/wordpress/google-analytics/#accountid">this video</a>!
142
- </div>'
143
  );
 
 
 
 
 
 
 
 
 
144
  $rows[] = array(
145
  'id' => 'position',
146
- 'label' => 'Where should the tracking script be placed?',
147
- 'content' => '<select name="position" id="position">
148
- <option value="footer" '.checked($options['position'],true,false).'>In the footer (default)</option>
149
- <option value="header" '.checked($options['position'],true,false).'>In the header</option>
150
- </select>'
151
  );
152
  $rows[] = array(
153
  'id' => 'trackoutbound',
154
  'label' => 'Track outbound clicks &amp; downloads',
155
- 'desc' => '',
156
  'content' => $this->checkbox('trackoutbound'),
157
  );
158
  $rows[] = array(
@@ -161,57 +368,99 @@ if ( ! class_exists( 'GA_Admin' ) ) {
161
  'desc' => 'Only adviced for advanced users who know their way around Google Analytics',
162
  'content' => $this->checkbox('advancedsettings'),
163
  );
164
- $this->postbox('gasettings','Google Analytics Settings',$this->form_table($rows));
165
 
166
  $rows = array();
 
167
  $rows[] = array(
168
- 'id' => 'admintracking',
169
- 'label' => 'Track the administrator too',
170
- 'desc' => 'Not recommended, as this would schew your statistics.',
171
- 'content' => $this->checkbox('admintracking'),
172
  );
173
  $rows[] = array(
174
- 'id' => 'trackloggedin',
175
- 'label' => 'Segment logged in users',
176
- 'content' => $this->checkbox('trackloggedin'),
 
177
  );
178
  $rows[] = array(
179
- 'id' => 'dlextensions',
180
- 'label' => 'Extensions of files to track as downloads',
181
- 'content' => $this->textinput('dlextensions'),
 
 
 
 
 
 
 
 
 
 
 
 
 
182
  );
183
  $rows[] = array(
184
- 'id' => 'dlprefix',
185
- 'label' => 'Prefix for tracked downloads',
186
- 'content' => $this->textinput('dlprefix'),
 
187
  );
188
  $rows[] = array(
189
- 'id' => 'artprefix',
190
- 'label' => 'Prefix for outbound clicks from articles',
191
- 'content' => $this->textinput('artprefix'),
 
192
  );
 
 
 
193
  $rows[] = array(
194
- 'id' => 'comprefix',
195
- 'label' => 'Prefix for outbound clicks from links in comments',
196
- 'content' => $this->textinput('comprefix'),
 
 
 
 
 
 
 
 
197
  );
198
  $rows[] = array(
199
- 'id' => 'comautprefix',
200
- 'label' => 'Prefix for outbound clicks from comment author links',
201
- 'content' => $this->textinput('comautprefix'),
 
202
  );
203
  $rows[] = array(
204
- 'id' => 'blogrollprefix',
205
- 'label' => 'Prefix for outbound clicks from blogroll links',
206
- 'content' => $this->textinput('blogrollprefix'),
 
 
 
 
 
 
 
 
 
 
 
 
207
  );
208
  $rows[] = array(
209
  'id' => 'domainorurl',
210
  'label' => 'Track full URL of outbound clicks or just the domain',
211
- 'content' => '<select name="domainorurl" id="domainorurl">
212
- <option value="domain"'.selected($options['domainorurl'],'domain',false).'>Just the domain</option>
213
- <option value="url"'.selected($options['domainorurl'],'url',false).'>Track the complete URL</option>
214
- </select>',
 
215
  );
216
  $rows[] = array(
217
  'id' => 'domain',
@@ -222,28 +471,21 @@ if ( ! class_exists( 'GA_Admin' ) ) {
222
  $rows[] = array(
223
  'id' => 'trackadsense',
224
  'label' => 'Track AdSense',
225
- 'desc' => 'This requires integration of your Analytics and AdSense account, for help, <a href="https://www.google.com/adsense/support/bin/topic.py?topic=15007">look here</a>.',
226
  'content' => $this->checkbox('trackadsense'),
227
  );
228
  $rows[] = array(
229
  'id' => 'extrase',
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',
242
- 'content' => $this->checkbox('userv2'),
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(
@@ -253,27 +495,87 @@ if ( ! class_exists( 'GA_Admin' ) ) {
253
  );
254
  $rows[] = array(
255
  'id' => 'allowanchor',
256
- 'label' => 'Use # instead of ? for Campaign tracking?',
257
- 'desc' => 'This adds a <a href="http://code.google.com/apis/analytics/docs/gaJSApiCampaignTracking.html#_gat.GA_Tracker_._setAllowAnchor">setAllowAnchor</a> call to your tracking script, and makes RSS link tagging use a # as well.',
258
  'content' => $this->checkbox('allowanchor'),
259
  );
260
- $this->postbox('advancedgasettings','Advanced Settings',$this->form_table($rows));
261
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  ?>
263
- <div class="submit"><input type="submit" class="button-primary" name="submit" value="Update Google Analytics Settings &raquo;" /></div>
264
  </form>
265
- <form action="" method="post">
266
  <input type="hidden" name="reset" value="true"/>
267
- <div class="submit"><input type="submit" value="Reset Default Settings &raquo;" /></div>
 
268
  </form>
269
  </div>
270
  </div>
271
  </div>
272
- <div class="postbox-container" style="width:20%;">
273
  <div class="metabox-holder">
274
  <div class="meta-box-sortables">
275
  <?php
 
 
276
  $this->plugin_like();
 
 
 
 
 
 
277
  $this->plugin_support();
278
  $this->news();
279
  ?>
@@ -283,42 +585,45 @@ if ( ! class_exists( 'GA_Admin' ) ) {
283
  </div>
284
  </div>
285
  <?php
286
- if (isset($options['uastring'])) {
287
- if ($options['uastring'] == "") {
288
- add_action('admin_footer', array(&$this,'warning'));
289
- } else {
290
- if (isset($_POST['submit'])) {
291
- if ($_POST['uastring'] != $options['uastring'] ) {
292
- add_action('admin_footer', array(&$this,'success'));
293
- }
294
- }
295
- }
296
- } else {
297
- add_action('admin_footer', array(&$this,'warning'));
298
- }
299
  }
300
 
301
  function set_defaults() {
302
- $options = get_option('GoogleAnalyticsPP');
303
- $options['dlextensions'] = 'doc,exe,.js,pdf,ppt,tgz,zip,xls';
304
- $options['dlprefix'] = '/downloads';
305
- $options['artprefix'] = '/outbound/article';
306
- $options['comprefix'] = '/outbound/comment';
307
- $options['comautprefix'] = '/outbound/commentauthor';
308
- $options['blogrollprefix'] = '/outbound/blogroll';
309
- $options['domainorurl'] = 'domain';
310
- $options['userv2'] = false;
311
- $options['extrase'] = false;
312
- $options['imagese'] = false;
313
- $options['admintracking'] = true;
314
- $options['trackoutbound'] = true;
315
- $options['advancedsettings'] = false;
316
- $options['allowanchor'] = false;
317
- update_option('GoogleAnalyticsPP',$options);
 
 
 
 
 
 
 
 
 
 
 
 
 
318
  }
319
 
320
  function warning() {
321
- echo "<div id='message' class='error'><p><strong>Google Analytics is not active.</strong> You must <a href='plugins.php?page=googleanalytics.php'>enter your UA String</a> for it to work.</p></div>";
 
 
 
322
  } // end warning()
323
 
324
  } // end class GA_Admin
@@ -333,79 +638,171 @@ if ( ! class_exists( 'GA_Admin' ) ) {
333
  if ( ! class_exists( 'GA_Filter' ) ) {
334
  class GA_Filter {
335
 
 
 
 
 
 
 
336
  /*
337
  * Insert the tracking code into the page
338
  */
339
  function spool_analytics() {
340
- global $wp_query;
341
- $options = get_option('GoogleAnalyticsPP');
 
 
 
342
 
343
- if ( $options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ) {
344
- echo "\n".'<!-- Google Analytics for WordPress | http://yoast.com/wordpress/google-analytics/ -->'."\n";
345
- echo '<script type="text/javascript">'."\n";
346
- echo "\t".'var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");'."\n";
347
- echo "\t".'document.write(unescape("%3Cscript src=\'" + gaJsHost + "google-analytics.com/ga.js\' type=\'text/javascript\'%3E%3C/script%3E"));'."\n";
348
- echo '</script>'."\n";
349
- echo '<script type="text/javascript">'."\n";
350
- echo "\t".'try {'."\n";
351
- echo "\t\t".'var pageTracker = _gat._getTracker("'.$options["uastring"].'");'."\n";
352
 
353
- /**
354
- * If this is a 404 page, track the 404 and prevent all other stuff as it's not needed.
355
- */
356
- if ( is_404() ) {
357
- echo "\t\t".'pageTracker._trackPageview("/404.html?page=" + document.location.pathname + document.location.search + "&from=" + document.referrer);'."\n";
358
- echo "\t".'} catch(err) {}'."\n";
359
- echo '</script>'."\n";
360
- } else if ($wp_query->is_search && $wp_query->found_posts == 0) {
361
- echo "\t\t".'pageTracker._trackPageview("'.get_bloginfo('url').'/?s=no-results: '.rawurlencode($wp_query->query_vars['s']).'&cat=no-results");'."\n";
362
- echo "\t".'} catch(err) {}'."\n";
363
- echo '</script>'."\n";
364
- } else {
365
- if ( $options["extrase"] ) {
366
- /**
367
- * We need to load another script, so we need to close the try / catch, load the script, and open it again.
368
- */
369
- echo "\t".'} catch(err) {}'."\n";
370
- echo '</script>'."\n";
371
- echo '<script src="'.gapp_plugin_path().'custom_se.js" type="text/javascript"></script>'."\n";
372
- echo '<script type="text/javascript">'."\n";
373
- echo "\t".'try {'."\n";
374
- }
375
-
376
- if ( $options['userv2'] )
377
- echo "\t\t".'pageTracker._setLocalRemoteServerMode();'."\n";
378
-
379
- if ( $options['allowanchor'] )
380
- echo "\t\t".'pageTracker._setAllowAnchor(true);'."\n";
381
-
382
- if ( $options['trackloggedin'] && !isset($_COOKIE['__utmv']) && is_user_logged_in() )
383
- echo "\t\tpageTracker._setVar('logged-in');\n";
384
- else
385
- echo "\t\t// Cookied already: ".$_COOKIE['__utmv']."\n";
386
 
387
- if ( isset($options['domain']) && $options['domain'] != "" ) {
388
- if (substr($options['domain'],0,1) != ".")
389
- $options['domain'] = ".".$options['domain'];
390
- echo "\t\t".'pageTracker._setDomainName("'.$options['domain'].'");'."\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
392
 
393
- if ( strpos($_SERVER['HTTP_REFERER'],"images.google") && strpos($_SERVER['HTTP_REFERER'],"&prev") && $options["imagese"] ) {
394
- echo "\t\t".'pageTracker._addOrganic("images.google","prev");'."\n";
395
- // echo "\t\t".'regex = new RegExp("images.google.([^\/]+).*&prev=([^&]+)");'."\n";
396
- // echo "\t\t".'var match = regex.exec(pageTracker.qa);'."\n";
397
- // echo "\t\t".'pageTracker.qa = "http://images.google." + match[1] + unescape(match[2]);'."\n";
 
 
 
 
 
 
 
398
  }
 
 
 
 
 
399
 
400
- echo "\t\t".'pageTracker._trackPageview();'."\n";
401
- echo "\t".'} catch(err) {}'."\n";
402
- echo '</script>'."\n";
 
 
 
 
403
  }
404
- echo '<!-- End of Google Analytics code -->'."\n";
405
- } else if ( $options["uastring"] != "" && current_user_can('edit_users') && !$options["admintracking"] ) {
406
- echo "<!-- Google Analytics tracking code not shown because admin tracking is disabled -->";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
407
  } else if ( $options["uastring"] == "" && current_user_can('edit_users') ) {
408
- echo "<!-- Google Analytics tracking code not shown because yo haven't entered your UA string yet. -->";
409
  }
410
  }
411
 
@@ -413,7 +810,7 @@ if ( ! class_exists( 'GA_Filter' ) ) {
413
  * Insert the AdSense parameter code into the page. This'll go into the header per Google's instructions.
414
  */
415
  function spool_adsense() {
416
- $options = get_option('GoogleAnalyticsPP');
417
  if ( $options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ) {
418
  echo '<script type="text/javascript">'."\n";
419
  echo "\t".'window.google_analytics_uacct = "'.$options["uastring"].'";'."\n";
@@ -421,6 +818,24 @@ if ( ! class_exists( 'GA_Filter' ) ) {
421
  }
422
  }
423
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
424
  /* Create an array which contians:
425
  * "domain" e.g. boakes.org
426
  * "host" e.g. store.boakes.org
@@ -432,18 +847,17 @@ if ( ! class_exists( 'GA_Filter' ) ) {
432
 
433
  preg_match($hostPattern, $uri, $matches);
434
  $host = $matches[2];
435
- if (preg_match("/.*\..*\..*\..*$/",$host)) {
436
- preg_match($domainPatternUK, $host, $matches);
437
- } else {
438
- preg_match($domainPatternUS, $host, $matches);
439
- }
440
 
441
  return array("domain"=>$matches[0],"host"=>$host);
442
  }
443
 
444
- function ga_parse_link($leaf, $matches){
445
  $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
446
- $options = get_option('GoogleAnalyticsPP');
447
 
448
  // Break out immediately if the link is not an http or https link.
449
  if (strpos($matches[2],"http") !== 0)
@@ -451,40 +865,43 @@ if ( ! class_exists( 'GA_Filter' ) ) {
451
  else
452
  $target = GA_Filter::ga_get_domain($matches[3]);
453
 
454
- $coolBit = "";
455
- $extension = substr($matches[3],-3);
456
- $dlextensions = split(",",$options['dlextensions']);
457
  if ( $target ) {
458
- if ( $target["domain"] != $origin["domain"] ){
 
 
 
459
  if ($options['domainorurl'] == "domain") {
460
- $coolBit .= "javascript:pageTracker._trackPageview('".$leaf."/".$target["host"]."');";
461
  } else if ($options['domainorurl'] == "url") {
462
- $coolBit .= "javascript:pageTracker._trackPageview('".$leaf."/".$matches[2]."//".$matches[3]."');";
463
  }
464
- } else if ( in_array($extension, $dlextensions) && $target["domain"] == $origin["domain"] ) {
465
- $file = str_replace($origin["domain"],"",$matches[3]);
466
- $file = str_replace('www.',"",$file);
467
- $coolBit .= "javascript:pageTracker._trackPageview('".$options['dlprefix'].$file."');";
468
- }
469
  }
470
- if ($coolBit != "") {
471
  if (preg_match('/onclick=[\'\"](.*?)[\'\"]/i', $matches[4]) > 0) {
472
- $matches[4] = preg_replace('/onclick=[\'\"](.*?)[\'\"]/i', 'onclick="' . $coolBit .' $1"', $matches[4]);
 
 
 
 
 
473
  } else {
474
- $matches[4] = 'onclick="' . $coolBit . '"' . $matches[4];
475
  }
476
  }
477
  return '<a ' . $matches[1] . 'href="' . $matches[2] . '//' . $matches[3] . '"' . ' ' . $matches[4] . '>' . $matches[5] . '</a>';
478
  }
479
 
480
  function ga_parse_article_link($matches){
481
- $options = get_option('GoogleAnalyticsPP');
482
- return GA_Filter::ga_parse_link($options['artprefix'],$matches);
483
  }
484
 
485
  function ga_parse_comment_link($matches){
486
- $options = get_option('GoogleAnalyticsPP');
487
- return GA_Filter::ga_parse_link($options['comprefix'],$matches);
488
  }
489
 
490
  function the_content($text) {
@@ -504,8 +921,8 @@ if ( ! class_exists( 'GA_Filter' ) ) {
504
  }
505
 
506
  function comment_author_link($text) {
507
- $options = get_option('GoogleAnalyticsPP');
508
-
509
  if (current_user_can('edit_users') && !$options["admintracking"]) {
510
  return $text;
511
  }
@@ -514,39 +931,43 @@ if ( ! class_exists( 'GA_Filter' ) ) {
514
  if ($matches[2] == "") return $text;
515
 
516
  $target = GA_Filter::ga_get_domain($matches[2]);
517
- $coolBit = "";
518
  $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
519
  if ( $target["domain"] != $origin["domain"] ){
520
- if ($options['domainorurl'] == "domain") {
521
- $coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$options['comautprefix']."/".$target["host"]."');\"";
522
- } else if ($options['domainorurl'] == "url") {
523
- $coolBit .= "onclick=\"javascript:pageTracker._trackPageview('".$options['comautprefix']."/".$matches[2]."');\"";
524
- }
525
  }
526
- return $matches[1] . "\"" . $matches[2] . "\" " . $coolBit ." ". $matches[3];
527
  }
528
 
529
  function bookmarks($bookmarks) {
530
- $options = get_option('GoogleAnalyticsPP');
531
 
532
  if (!is_admin() && (!current_user_can('edit_users') || $options['admintracking'] ) ) {
533
- foreach ( (array) $bookmarks as $bookmark ) {
534
- $target = GA_Filter::ga_get_domain($bookmark->link_url);
 
535
  $sitedomain = GA_Filter::ga_get_domain(get_bloginfo('url'));
536
- if ($target['host'] == $sitedomain['host'])
537
- continue;
538
- if ($options['domainorurl'] == "domain") {
539
- $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$target["host"]."');";
540
- } else if ($options['domainorurl'] == "url") {
541
- $bookmark->link_rel = $bookmark->link_rel."\" onclick=\"javascript:pageTracker._trackPageview('".$options['blogrollprefix']."/".$bookmark->link_url."');";
542
  }
 
 
 
 
 
 
 
543
  }
544
  }
545
  return $bookmarks;
546
  }
547
 
548
  function rsslinktagger($guid) {
549
- $options = get_option('GoogleAnalyticsPP');
550
  global $wp, $post;
551
  if ( is_feed() ) {
552
  if ( $options['allowanchor'] ) {
@@ -560,13 +981,100 @@ if ( ! class_exists( 'GA_Filter' ) ) {
560
  }
561
  }
562
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
563
  } // class GA_Filter
564
  } // endif
565
 
566
  /**
567
  * If setAllowAnchor is set to true, GA ignores all links tagged "normally", so we redirect all "normally" tagged URL's
568
- * to one tagged with a hash. Needs some work as it also needs to do that when the first utm_ var is actually not the
569
- * first GET variable in the URL.
570
  */
571
  function ga_utm_hashtag_redirect() {
572
  if (isset($_SERVER['REQUEST_URI'])) {
@@ -587,8 +1095,75 @@ function ga_utm_hashtag_redirect() {
587
  }
588
  }
589
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
590
  $gaf = new GA_Filter();
591
- $options = get_option('GoogleAnalyticsPP');
592
 
593
  if (!is_array($options))
594
  $ga_admin->set_defaults();
@@ -607,12 +1182,17 @@ if ($options['trackoutbound']) {
607
  }
608
 
609
  if ($options['trackadsense'])
610
- add_action('wp_head', array('GA_Filter','spool_adsense'),10);
611
 
612
- if ($options['position'] == 'footer' || $options['position'] == "")
613
- add_action('wp_footer', array('GA_Filter','spool_analytics'));
614
- else
615
- add_action('wp_head', array('GA_Filter','spool_analytics'),20);
 
 
 
 
 
616
 
617
  if ($options['trackregistration'])
618
  add_action('login_head', array('GA_Filter','spool_analytics'),20);
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=v40
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: 4.0
8
+ Requires at least: 2.8
9
  Author URI: http://yoast.com/
10
  License: GPL
11
 
12
  */
13
+
14
  // Determine the location
15
  function gapp_plugin_path() {
16
  return plugins_url('', __FILE__).'/';
24
 
25
  require_once('yst_plugin_tools.php');
26
 
27
+ class GA_Admin extends Yoast_GA_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';
33
+ var $ozhicon = 'images/chart_curve.png';
34
+ var $optionname = 'Yoast_Google_Analytics';
35
  var $homepage = 'http://yoast.com/wordpress/google-analytics/';
36
+ var $toc = '';
37
 
38
  function GA_Admin() {
39
  add_action( 'admin_menu', array(&$this, 'register_settings_page') );
44
  add_action('admin_print_styles', array(&$this,'config_page_styles'));
45
 
46
  add_action('wp_dashboard_setup', array(&$this,'widget_setup'));
47
+
48
  add_action('admin_head', array(&$this,'config_page_head'));
49
+
50
+ add_action('admin_footer', array(&$this,'warning'));
51
+ add_action('admin_footer', array(&$this,'theme_switch_warning'));
52
+
53
+ add_action('admin_init', array(&$this,'save_settings'));
54
+
55
+ add_action('switch_theme', array(&$this,'switch_theme'));
56
  }
57
 
58
  function config_page_head() {
59
+ if (isset($_GET['page']) && $_GET['page'] == $this->hook) {
60
+ $options = get_option($this->optionname);
61
+ if (!empty($options['uastring'])) {
62
+ $uastring = $options['uastring'];
63
+ } else {
64
+ $uastring = '';
65
+ }
66
  wp_enqueue_script('jquery');
67
  ?>
68
+ <script type="text/javascript" charset="utf-8">
69
+ function makeSublist(parent,child,childVal)
70
+ {
71
+ jQuery("body").append("<select style='display:none' id='"+parent+child+"'></select>");
72
+ jQuery('#'+parent+child).html(jQuery("#"+child+" option"));
73
+
74
+ var parentValue = jQuery('#'+parent).attr('value');
75
+ jQuery('#'+child).html(jQuery("#"+parent+child+" .sub_"+parentValue).clone());
76
+
77
+ childVal = (typeof childVal == "undefined")? "" : childVal ;
78
+ jQuery("#"+child).val(childVal).attr('selected','selected');
79
+
80
+ jQuery('#'+parent).change(function(){
81
+ var parentValue = jQuery('#'+parent).attr('value');
82
+ jQuery('#'+child).html(jQuery("#"+parent+child+" .sub_"+parentValue).clone());
83
+ jQuery('#'+child).trigger("change");
84
+ jQuery('#'+child).focus();
85
+ });
86
+ }
87
  jQuery(document).ready(function(){
88
+ makeSublist('ga_account', 'uastring_sel', '<?php echo $uastring; ?>');
89
+ jQuery('#position').change(function(){
90
+ if (jQuery('#position').val() == 'header') {
91
+ jQuery('#position_header').css("display","block");
92
+ jQuery('#position_manual').css("display","none");
93
+ } else {
94
+ jQuery('#position_header').css("display","none");
95
+ jQuery('#position_manual').css("display","block");
96
+ }
97
+ }).change();
98
+ jQuery('#switchtomanual').change(function() {
99
+ if ((jQuery('#switchtomanual').attr('checked')) == true) {
100
+ jQuery('#uastring_manual').css('display','block');
101
+ jQuery('#uastring_automatic').css('display','none');
102
+ } else {
103
+ jQuery('#uastring_manual').css('display','none');
104
+ jQuery('#uastring_automatic').css('display','block');
105
+ }
106
+ }).change();
107
  jQuery('#advancedsettings').change(function(){
108
  if ((jQuery('#advancedsettings').attr('checked')) == true) {
109
  jQuery('#advancedgasettings').css("display","block");
110
+ jQuery('#customvarsettings').css("display","block");
111
+ jQuery('#toc').css("display","block");
112
  } else {
113
  jQuery('#advancedgasettings').css("display","none");
114
+ jQuery('#customvarsettings').css("display","none");
115
+ jQuery('#toc').css("display","none");
116
  }
117
  }).change();
118
+ jQuery('#extrase').change(function(){
119
+ if ((jQuery('#extrase').attr('checked')) == true) {
120
+ jQuery('#extrasebox').css("display","block");
121
  } else {
122
+ jQuery('#extrasebox').css("display","none");
123
  }
124
+ }).change();
125
+ jQuery('#customvarsettings :input').change(function() {
126
+ if (jQuery("#customvarsettings :input:checked").size() > 5) {
127
+ alert('The maximum number of allowed custom variables in Google Analytics is 5, please unselect one of the other custom variables before selecting this one.')
128
+ jQuery(this).attr('checked', false);
129
+ };
130
  });
131
  });
132
  </script>
134
  }
135
  }
136
 
137
+ function theme_switch_warning() {
138
+ $options = get_option( $this->optionname );
139
+ if ($options['theme_updated']) {
140
+ echo "<div id='message' class='error'><p>You have updated your theme, please check your <a href='".$this->plugin_options_url()."'><strong>Google Analytics settings</strong></a> to make sure Google Analytics can still function correctly.</p></div>";
141
+ }
142
+ }
143
 
144
+ function switch_theme( $theme ) {
145
+ $options = get_option( $this->optionname );
146
+ $options['theme_updated'] = 1;
147
+ $options['position'] = 'header';
148
+ update_option( $this->optionname, $options );
149
  }
150
 
151
+ function toc( $modules ) {
152
+ $output = '<ul>';
153
+ foreach ($modules as $module => $key) {
154
+ $output .= '<li><a href="#'.$key.'">'.$module.'</a></li>';
 
 
155
  }
156
+ $output .= '</ul>';
157
+ return $output;
158
+ }
159
+
160
+ function save_settings() {
161
+ $options = get_option( $this->optionname );
162
+
163
+ if ( isset($_REQUEST['reset']) && $_REQUEST['reset'] == "true" && isset($_REQUEST['plugin']) && $_REQUEST['plugin'] == 'google-analytics-for-wordpress') {
164
+ $options = $this->set_defaults();
165
+ $options['msg'] = "<div class=\"updated\"><p>Google Analytics settings reset.</p></div>\n";
166
+ } elseif ( isset($_POST['submit']) && isset($_POST['plugin']) && $_POST['plugin'] == 'google-analytics-for-wordpress') {
167
  if (!current_user_can('manage_options')) die(__('You cannot edit the Google Analytics for WordPress options.'));
168
  check_admin_referer('analyticspp-config');
169
 
170
+ foreach (array('uastring', 'dlextensions', 'domainorurl','position','domain', 'ga_token', 'extraseurl', 'gfsubmiteventpv', 'trackprefix', 'ignore_userlevel') as $option_name) {
171
  if (isset($_POST[$option_name]))
172
  $options[$option_name] = $_POST[$option_name];
173
  else
174
  $options[$option_name] = '';
175
  }
176
 
177
+ foreach (array('extrase', 'trackoutbound', 'admintracking', 'trackadsense', 'allowanchor', 'allowlinker', 'rsslinktagging', 'advancedsettings', 'trackregistration', 'theme_updated', 'cv_loggedin', 'cv_authorname', 'cv_category', 'cv_all_categories', 'cv_tags', 'cv_year', 'cv_post_type', 'outboundpageview', 'downloadspageview', 'manual_uastring', 'taggfsubmit', 'wpec_tracking', 'shopp_tracking') as $option_name) {
178
+ if (isset($_POST[$option_name]) && $_POST[$option_name] != 'off')
179
  $options[$option_name] = true;
180
  else
181
  $options[$option_name] = false;
182
  }
183
 
184
+ if (isset($_POST['manual_uastring']) && isset($_POST['uastring_man'])) {
185
+ $options['uastring'] = $_POST['uastring_man'];
186
+ }
187
+
188
+ $options['msg'] = "<div id=\"updatemessage\" class=\"updated fade\"><p>Google Analytics settings updated.</p></div>\n";
189
+ $options['msg'] .= "<script type=\"text/javascript\">setTimeout(function(){jQuery('#updatemessage').hide('slow');}, 3000);</script>";
190
  }
191
+ update_option($this->optionname, $options);
192
+ }
193
+
194
+ function save_button() {
195
+ return '<div class="alignright"><input type="submit" class="button-primary" name="submit" value="Update Google Analytics Settings &raquo;" /></div><br class="clear"/>';
196
+ }
197
+
198
+ function config_page() {
199
+ $options = get_option($this->optionname);
200
+ echo $options['msg'];
201
+ $options['msg'] = '';
202
+ update_option($this->optionname, $options);
203
  ?>
204
  <div class="wrap">
205
+ <a href="http://yoast.com/"><div id="yoast-icon" style="background: url(http://cdn.yoast.com/wp-content/themes/yoast-v2/images/yoast-32x32.png) no-repeat;" class="icon32"><br /></div></a>
206
  <h2>Google Analytics for WordPress Configuration</h2>
207
+ <div class="postbox-container" style="width:65%;">
208
  <div class="metabox-holder">
209
  <div class="meta-box-sortables">
210
+ <form action="<?php echo $this->plugin_options_url(); ?>" method="post" id="analytics-conf">
211
+ <input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>
212
  <?php
213
  wp_nonce_field('analyticspp-config');
214
+ if ( empty($options['uastring']) && empty($options['ga_token']) && !isset($_GET['token']) ) {
215
+ $url = $this->plugin_options_url();
216
+ if (isset($_GET['switchua']))
217
+ $url .= '&switchua=1';
218
+ $query = 'https://www.google.com/accounts/AuthSubRequest?';
219
+ $query .= http_build_query(
220
+ array(
221
+ 'next' => $url,
222
+ 'scope' => 'https://www.google.com/analytics/feeds/',
223
+ 'secure' => 0,
224
+ 'session' => 1,
225
+ 'hd' => 'default'
226
+ )
227
+ );
228
+ $line = 'Please authenticate with Google Analytics to retrieve your tracking code:<br/><br/> <a class="button-primary" href="'.$query.'">Click here to authenticate with Google</a><br/><br/><strong>Note</strong>: if you have multiple Google accounts, you\'ll want to switch to the right account first, since Google doesn\'t let you switch accounts on the authentication screen.';
229
+ } else if(isset($_GET['token']) || (isset($options['ga_token']) && !empty($options['ga_token']))) {
230
+ if (isset($_GET['token']))
231
+ $token = $_GET['token'];
232
+ else
233
+ $token = $options['ga_token'];
234
+
235
+ require_once('xmlparser.php');
236
+ if (file_exists(ABSPATH.'wp-includes/class-http.php'))
237
+ require_once(ABSPATH.'wp-includes/class-http.php');
238
+
239
+ if (!isset($options['ga_api_responses'][$token])) {
240
+ $options['ga_api_responses'] = array();
241
+ $request = new WP_Http;
242
+ $api_url = 'https://www.google.com/analytics/feeds/accounts/default';
243
+ $headers = array(
244
+ 'Content-Type' => 'application/x-www-form-urlencoded',
245
+ 'Authorization' => 'AuthSub token="'.$token.'"',
246
+ );
247
+ $args = array(
248
+ 'method' => 'GET',
249
+ 'body' => '',
250
+ 'headers' => $headers,
251
+ 'timeout' => 10,
252
+ );
253
+ $result = $request->request( $api_url , $args );
254
+ if (is_array($result) && $result['response']['code'] == 200) {
255
+ $options['ga_api_responses'][$token] = $result;
256
+ $options['ga_token'] = $token;
257
+ update_option('Yoast_Google_Analytics', $options);
258
+ }
259
+ }
260
+
261
+ if (is_array($options['ga_api_responses'][$token]) && $options['ga_api_responses'][$token]['response']['code'] == 200) {
262
+ $arr = yoast_xml2array($options['ga_api_responses'][$token]['body']);
263
+
264
+ $ga_accounts = array();
265
+ foreach ($arr['feed']['entry'] as $site) {
266
+ $ua = $site['dxp:property']['3_attr']['value'];
267
+ $account = $site['dxp:property']['1_attr']['value'];
268
+ if (!isset($ga_accounts[$account]) || !is_array($ga_accounts[$account]))
269
+ $ga_accounts[$account] = array();
270
+ $ga_accounts[$account][$site['title']] = $ua;
271
+ }
272
+
273
+ $select1 = '<select style="width:150px;" name="ga_account" id="ga_account">';
274
+ $select1 .= "\t<option></option>\n";
275
+ $select2 = '<select style="width:150px;" name="uastring" id="uastring_sel">';
276
+ $i = 1;
277
+ $currentua = '';
278
+ if (!empty($options['uastring']))
279
+ $currentua = $options['uastring'];
280
+
281
+ foreach($ga_accounts as $account => $val) {
282
+ $accountsel = false;
283
+ foreach ($val as $title => $ua) {
284
+ $sel = selected($ua, $currentua, false);
285
+ if (!empty($sel)) {
286
+ $accountsel = true;
287
+ }
288
+ $select2 .= "\t".'<option class="sub_'.$i.'" '.$sel.' value="'.$ua.'">'.$title.'</option>'."\n";
289
+ }
290
+ $select1 .= "\t".'<option '.selected($accountsel,true,false).' value="'.$i.'">'.$account.'</option>'."\n";
291
+ $i++;
292
+ }
293
+ $select1 .= '</select>';
294
+ $select2 .= '</select>';
295
+
296
+ $line = '<input type="hidden" name="ga_token" value="'.$token.'"/>';
297
+ $line .= 'Please select the correct Analytics profile to track:<br/>';
298
+ $line .= '<table class="form_table">';
299
+ $line .= '<tr><th width="15%">Account:</th><td width="85%">'.$select1.'</td></tr>';
300
+ $line .= '<tr><th>Profile:</th><td>'.$select2.'</td></tr>';
301
+ $line .= '</table>';
302
+
303
+ $try = 1;
304
+ if (isset($_GET['try']))
305
+ $try = $_GET['try'] + 1;
306
+
307
+ if ($i == 1 && $try < 4 && isset($_GET['token'])) {
308
+ $line .= '<script type="text/javascript" charset="utf-8">
309
+ window.location="'.$this->plugin_options_url().'&switchua=1&token='.$token.'&try='.$try.'";
310
+ </script>';
311
+ }
312
+
313
+ $line .= '<br/>Refresh this listing or switch to another account: ';
314
+ } else {
315
+ $line = 'Unfortunately, an error occurred while connecting to Google, please try again:';
316
+ }
317
+
318
+ $url = $this->plugin_options_url();
319
+ if (isset($_GET['switchua']))
320
+ $url .= '&switchua=1';
321
+ $query = 'https://www.google.com/accounts/AuthSubRequest?';
322
+ $query .= http_build_query(
323
+ array(
324
+ 'next' => $url,
325
+ 'scope' => 'https://www.google.com/analytics/feeds/',
326
+ 'secure' => 0,
327
+ 'session' => 1,
328
+ 'hd' => 'default'
329
+ )
330
+ );
331
+ $line .= '<a class="button" href="'.$query.'">Re-authenticate with Google</a>';
332
+ } else {
333
+ $line = '<input id="uastring" name="uastring" type="text" size="20" maxlength="40" value="'.$options['uastring'].'"/><br/><a href="'.$this->plugin_options_url().'&amp;switchua=1">Select another Analytics Profile &raquo;</a>';
334
+ }
335
+ $line = '<div id="uastring_automatic">'.$line.'</div><div style="display:none;" id="uastring_manual">Manually enter your UA code: <input id="uastring" name="uastring_man" type="text" size="20" maxlength="40" value="'.$options['uastring'].'"/></div>';
336
  $rows = array();
337
+ $content = '';
338
  $rows[] = array(
339
  'id' => 'uastring',
340
+ 'label' => 'Analytics Profile',
341
+ 'desc' => '<input type="checkbox" name="manual_uastring" '.checked($options['manual_uastring'], true, false).' id="switchtomanual"/> <label for="switchtomanual">Manually enter your UA code</label>',
342
+ 'content' => $line
 
 
 
 
 
 
 
 
343
  );
344
+ $temp_content = $this->select('position', array('header' => 'In the header (default)', 'manual' => 'Insert manually'));
345
+ if ($options['theme_updated'] && $options['position'] == 'manual') {
346
+ $temp_content .= '<input type="hidden" name="theme_updated" value="off"/>';
347
+ echo '<div id="message" class="updated" style="background-color:lightgreen;border-color:green;"><p><strong>Notice:</strong> You switched your theme, please make sure your Google Analytics tracking is still ok. Save your settings to make sure Google Analytics gets loaded properly.</p></div>';
348
+ remove_action('admin_footer', array(&$this,'theme_switch_warning'));
349
+ }
350
+ $desc = '<div id="position_header">The header is by far the best spot to place the tracking code. If you\'d rather place the code manually, switch to manual placement. For more info <a href="http://yoast.com/wordpress/google-analytics/manual-placement/">read this page</a>.</div>';
351
+ $desc .= '<div id="position_manual"><a href="http://yoast.com/wordpress/google-analytics/manual-placement/">Follow the instructions here</a> to choose the location for your tracking code manually.</div>';
352
+
353
  $rows[] = array(
354
  'id' => 'position',
355
+ 'label' => 'Where should the tracking code be placed',
356
+ 'desc' => $desc,
357
+ 'content' => $temp_content,
 
 
358
  );
359
  $rows[] = array(
360
  'id' => 'trackoutbound',
361
  'label' => 'Track outbound clicks &amp; downloads',
362
+ 'desc' => 'Clicks &amp; downloads will be tracked as events, you can find these under Content &raquo; Event Tracking in your Google Analytics reports.',
363
  'content' => $this->checkbox('trackoutbound'),
364
  );
365
  $rows[] = array(
368
  'desc' => 'Only adviced for advanced users who know their way around Google Analytics',
369
  'content' => $this->checkbox('advancedsettings'),
370
  );
371
+ $this->postbox('gasettings','Google Analytics Settings',$this->form_table($rows).$this->save_button());
372
 
373
  $rows = array();
374
+ $pre_content = '<p>Google Analytics allows you to save up to 5 custom variables on each page, and this plugin helps you make the most use of these! Check which custom variables you\'d like the plugin to save for you below. Please note that these will only be saved when they are actually available.</p><p>If you want to start using these custom variables, go to Visitors &raquo; Custom Variables in your Analytics reports.</p>';
375
  $rows[] = array(
376
+ 'id' => 'cv_loggedin',
377
+ 'label' => 'Logged in Users',
378
+ '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.',
379
+ 'content' => $this->checkbox('cv_loggedin'),
380
  );
381
  $rows[] = array(
382
+ 'id' => 'cv_authorname',
383
+ 'label' => 'Author Name',
384
+ 'desc' => 'Allows you to see pageviews per author.',
385
+ 'content' => $this->checkbox('cv_authorname'),
386
  );
387
  $rows[] = array(
388
+ 'id' => 'cv_category',
389
+ 'label' => 'Single Category',
390
+ 'desc' => 'Allows you to see pageviews per category, works best when each post is in only one category.',
391
+ 'content' => $this->checkbox('cv_category'),
392
+ );
393
+ $rows[] = array(
394
+ 'id' => 'cv_all_categories',
395
+ 'label' => 'All Categories',
396
+ 'desc' => 'Allows you to see pageviews per category using advanced segments, should be used when you use multiple categories per post.',
397
+ 'content' => $this->checkbox('cv_all_categories'),
398
+ );
399
+ $rows[] = array(
400
+ 'id' => 'cv_tags',
401
+ 'label' => 'Tags',
402
+ 'desc' => 'Allows you to see pageviews per tags using advanced segments.',
403
+ 'content' => $this->checkbox('cv_tags'),
404
  );
405
  $rows[] = array(
406
+ 'id' => 'cv_year',
407
+ 'label' => 'Publication year',
408
+ 'desc' => 'Allows you to see pageviews per year of publication, showing you if your old posts still get traffic.',
409
+ 'content' => $this->checkbox('cv_year'),
410
  );
411
  $rows[] = array(
412
+ 'id' => 'cv_post_type',
413
+ 'label' => 'Post type',
414
+ 'desc' => 'Allows you to see pageviews per post type, especially useful if you use multiple custom post types.',
415
+ 'content' => $this->checkbox('cv_post_type'),
416
  );
417
+ $this->postbox('customvarsettings','Custom Variables Settings',$pre_content.$this->form_table($rows).$this->save_button());
418
+
419
+ $rows = array();
420
  $rows[] = array(
421
+ 'id' => 'ignore_userlevel',
422
+ 'label' => 'Ignore users',
423
+ 'desc' => 'Users of the role you select and higher will be ignored, so if you select Editor, all Editors and Administrators will be ignored.',
424
+ 'content' => $this->select('ignore_userlevel', array(
425
+ '11' => 'Ignore no-one',
426
+ '8' => 'Administrator',
427
+ '5' => 'Editor',
428
+ '2' => 'Author',
429
+ '1' => 'Contributor',
430
+ '0' => 'Subscriber',
431
+ )),
432
  );
433
  $rows[] = array(
434
+ 'id' => 'outboundpageview',
435
+ 'label' => 'Track outbound clicks as pageviews',
436
+ 'desc' => 'You do not need to enable this to enable outbound click tracking, this changes the default behavior of tracking clicks as events to tracking them as pageviews. This is therefore not recommended, as this would schew your statistics, but <em>is</em> sometimes necessary when you need to set outbound clicks as goals.',
437
+ 'content' => $this->checkbox('outboundpageview'),
438
  );
439
  $rows[] = array(
440
+ 'id' => 'downloadspageview',
441
+ 'label' => 'Track downloads as pageviews',
442
+ 'desc' => 'Not recommended, as this would schew your statistics, but it does make it possible to track downloads as goals.',
443
+ 'content' => $this->checkbox('downloadspageview'),
444
+ );
445
+ $rows[] = array(
446
+ 'id' => 'dlextensions',
447
+ 'label' => 'Extensions of files to track as downloads',
448
+ 'content' => $this->textinput('dlextensions'),
449
+ );
450
+ $rows[] = array(
451
+ 'id' => 'trackprefix',
452
+ 'label' => 'Prefix to use in Analytics before the tracked pageviews',
453
+ 'desc' => 'This prefix is used before all pageviews, they are then segmented automatically after that. If nothing is entered here, <code>/yoast-ga/</code> is used.',
454
+ 'content' => $this->textinput('trackprefix'),
455
  );
456
  $rows[] = array(
457
  'id' => 'domainorurl',
458
  'label' => 'Track full URL of outbound clicks or just the domain',
459
+ 'content' => $this->select('domainorurl', array(
460
+ 'domain' => 'Just the domain',
461
+ 'url' => 'Track the complete URL',
462
+ )
463
+ ),
464
  );
465
  $rows[] = array(
466
  'id' => 'domain',
471
  $rows[] = array(
472
  'id' => 'trackadsense',
473
  'label' => 'Track AdSense',
474
+ 'desc' => 'This requires integration of your Analytics and AdSense account, for help, <a href="http://google.com/support/analytics/bin/answer.py?answer=92625">look here</a>.',
475
  'content' => $this->checkbox('trackadsense'),
476
  );
477
  $rows[] = array(
478
  'id' => 'extrase',
479
  'label' => 'Track extra Search Engines',
480
+ 'content' => $this->checkbox('extrase').'<div id="extrasebox">
481
+ You can provide a custom URL to the extra search engines file if you want:
482
+ <input type="text" name="extraseurl" size="30" value="'.$options['extraseurl'].'"/>
483
+ </div>',
 
 
 
 
 
 
 
 
484
  );
485
  $rows[] = array(
486
  'id' => 'rsslinktagging',
487
  'label' => 'Tag links in RSS feed with campaign variables',
488
+ 'desc' => 'Do not use this feature if you use FeedBurner, as FeedBurner can do this automatically, and better than this plugin can. Check <a href="http://www.google.com/support/feedburner/bin/answer.py?hl=en&amp;answer=165769">this help page</a> for info on how to enable this feature in FeedBurner.',
489
  'content' => $this->checkbox('rsslinktagging'),
490
  );
491
  $rows[] = array(
495
  );
496
  $rows[] = array(
497
  'id' => 'allowanchor',
498
+ 'label' => 'Use # instead of ? for Campaign tracking',
499
+ 'desc' => 'This adds a <a href="http://code.google.com/apis/analytics/docs/gaJSApiCampaignTracking.html#_gat.GA_Tracker_._setAllowAnchor">setAllowAnchor</a> call to your tracking code, and makes RSS link tagging use a # as well.',
500
  'content' => $this->checkbox('allowanchor'),
501
  );
502
+ $rows[] = array(
503
+ 'id' => 'allowlinker',
504
+ 'label' => 'Add <code>_setAllowLinker</code>',
505
+ 'desc' => 'This adds a <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowLinker">setAllowLinker</a> call to your tracking code, allowing you to use <code>_link</code> and related functions.',
506
+ 'content' => $this->checkbox('allowlinker'),
507
+ );
508
+ $this->postbox('advancedgasettings','Advanced Settings',$this->form_table($rows).$this->save_button());
509
+
510
+ $modules = array();
511
+
512
+ /* if (class_exists('RGForms') && GFCommon::$version >= '1.3.11') {
513
+ $pre_content = 'This plugin can automatically tag your Gravity Forms to track form submissions as either events or pageviews';
514
+ $rows = array();
515
+ $rows[] = array(
516
+ 'id' => 'taggfsubmit',
517
+ 'label' => 'Tag Gravity Forms',
518
+ 'content' => $this->checkbox('taggfsubmit'),
519
+ );
520
+ $rows[] = array(
521
+ 'id' => 'gfsubmiteventpv',
522
+ 'label' => 'Tag Gravity Forms as',
523
+ 'content' => '<select name="gfsubmiteventpv">
524
+ <option value="events" '.selected($options['gfsubmiteventpv'],'events',false).'>Events</option>
525
+ <option value="pageviews" '.selected($options['gfsubmiteventpv'],'pageviews',false).'>Pageviews</option>
526
+ </select>',
527
+ );
528
+ $this->postbox('gravityforms','Gravity Forms Settings',$pre_content.$this->form_table($rows).$this->save_button());
529
+ $modules['Gravity Forms'] = 'gravityforms';
530
+ }
531
+ */
532
+ if ( defined('WPSC_VERSION') ) {
533
+ $pre_content = 'The WordPress e-Commerce plugin has been detected. This plugin can automatically add transaction tracking for you. To do that, <a href="http://yoast.com/wordpress/google-analytics/enable-ecommerce/">enable e-commerce for your reports in Google Analytics</a> and then check the box below.';
534
+ $rows = array();
535
+ $rows[] = array(
536
+ 'id' => 'wpec_tracking',
537
+ 'label' => 'Enable transaction tracking',
538
+ 'content' => $this->checkbox('wpec_tracking'),
539
+ );
540
+ $this->postbox('wpecommerce','WordPress e-Commerce Settings',$pre_content.$this->form_table($rows).$this->save_button());
541
+ $modules['WordPress e-Commerce'] = 'wpecommerce';
542
+ }
543
+
544
+ global $Shopp;
545
+ if ( isset($Shopp) ) {
546
+ $pre_content = 'The Shopp e-Commerce plugin has been detected. This plugin can automatically add transaction tracking for you. To do that, <a href="http://www.google.com/support/googleanalytics/bin/answer.py?hl=en&amp;answer=55528">enable e-commerce for your reports in Google Analytics</a> and then check the box below.';
547
+ $rows = array();
548
+ $rows[] = array(
549
+ 'id' => 'shopp_tracking',
550
+ 'label' => 'Enable transaction tracking',
551
+ 'content' => $this->checkbox('shopp_tracking'),
552
+ );
553
+ $this->postbox('shoppecommerce','Shopp e-Commerce Settings',$pre_content.$this->form_table($rows).$this->save_button());
554
+ $modules['Shopp'] = 'shoppecommerce';
555
+ }
556
  ?>
 
557
  </form>
558
+ <form action="<?php echo $this->plugin_options_url(); ?>" method="post" onsubmit="javascript:return(confirm('Do you really want to reset all settings?'));">
559
  <input type="hidden" name="reset" value="true"/>
560
+ <input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>
561
+ <div class="submit"><input type="submit" value="Reset All Settings &raquo;" /></div>
562
  </form>
563
  </div>
564
  </div>
565
  </div>
566
+ <div class="postbox-container side" style="width:20%;">
567
  <div class="metabox-holder">
568
  <div class="meta-box-sortables">
569
  <?php
570
+ if ( count($modules) > 0 )
571
+ $this->postbox('toc','List of Available Modules',$this->toc($modules));
572
  $this->plugin_like();
573
+ $this->postbox('donate','Donate $5, $10 or $20 now!','<form style="margin-left:50px;" action="https://www.paypal.com/cgi-bin/webscr" method="post">
574
+ <input type="hidden" name="cmd" value="_s-xclick">
575
+ <input type="hidden" name="hosted_button_id" value="FW9FK4EBZ9FVJ">
576
+ <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!">
577
+ <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
578
+ </form>');
579
  $this->plugin_support();
580
  $this->news();
581
  ?>
585
  </div>
586
  </div>
587
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
588
  }
589
 
590
  function set_defaults() {
591
+ $options = array(
592
+ 'advancedsettings' => false,
593
+ 'allowanchor' => false,
594
+ 'allowlinker' => false,
595
+ 'cv_loggedin' => false,
596
+ 'cv_authorname' => false,
597
+ 'cv_category' => false,
598
+ 'cv_all_categories' => false,
599
+ 'cv_tags' => false,
600
+ 'cv_year' => false,
601
+ 'cv_post_type' => false,
602
+ 'dlextensions' => 'doc,exe,js,pdf,ppt,tgz,zip,xls',
603
+ 'domainorurl' => 'domain',
604
+ 'ga_token' => '',
605
+ 'ga_api_responses' => array(),
606
+ 'extrase' => false,
607
+ 'extraseurl' => '',
608
+ 'ignore_userlevel' => '11',
609
+ 'outboundpageview' => false,
610
+ 'downloadspageview' => false,
611
+ 'position' => 'footer',
612
+ 'trackadsense' => false,
613
+ 'trackoutbound' => true,
614
+ 'trackregistration' => false,
615
+ 'rsslinktagging' => true,
616
+ 'domain' => '',
617
+ );
618
+ update_option($this->optionname,$options);
619
+ return $options;
620
  }
621
 
622
  function warning() {
623
+ $options = get_option($this->optionname);
624
+ if (!isset($options['uastring']) || empty($options['uastring'])) {
625
+ echo "<div id='message' class='error'><p><strong>Google Analytics is not active.</strong> You must <a href='".$this->plugin_options_url()."'>select which Analytics Profile to track</a> before it can work.</p></div>";
626
+ }
627
  } // end warning()
628
 
629
  } // end class GA_Admin
638
  if ( ! class_exists( 'GA_Filter' ) ) {
639
  class GA_Filter {
640
 
641
+ /**
642
+ * Cleans the variable to make it ready for storing in Google Analytics
643
+ */
644
+ function ga_str_clean($val) {
645
+ return remove_accents(str_replace('---','-',str_replace(' ','-',strtolower(html_entity_decode($val)))));
646
+ }
647
  /*
648
  * Insert the tracking code into the page
649
  */
650
  function spool_analytics() {
651
+ global $wp_query, $current_user;
652
+ // echo '<!--'.print_r($wp_query,1).'-->';
653
+ // echo '<!--'.print_r($current_user,1).'-->';
654
+
655
+ $options = get_option('Yoast_Google_Analytics');
656
 
657
+ /**
658
+ * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
659
+ */
660
+ $customvarslot = 1;
661
+ if ( $options["uastring"] != "" && !($current_user->user_level >= $options["ignore_userlevel"]) && !is_preview() ) {
662
+ $push = array();
 
 
 
663
 
664
+ if ( $options['allowanchor'] )
665
+ $push[] = "'_setAllowAnchor',true";
666
+
667
+ if ( $options['allowlinker'] )
668
+ $push[] = "'_setAllowLinker',true";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
669
 
670
+ if ( isset($options['domain']) && $options['domain'] != "" ) {
671
+ // should allow for a 'none' domain too!
672
+ if (substr($options['domain'],0,1) != "." && $options['domain'] != 'none')
673
+ $options['domain'] = ".".$options['domain'];
674
+ $push[] = "'_setDomainName','".$options['domain']."'";
675
+ }
676
+
677
+ if ( $options['cv_loggedin'] ) {
678
+ if ( $current_user->ID != 0 )
679
+ $push[] = "'_setCustomVar',".$customvarslot.",'logged-in','".$current_user->roles[0]."',1";
680
+ // 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.
681
+ $customvarslot++;
682
+ }
683
+
684
+ if ( is_singular() && !is_home() ) {
685
+ if ( $options['cv_post_type'] ) {
686
+ $post_type = get_post_type();
687
+ if ( $post_type ) {
688
+ $push[] = "'_setCustomVar',".$customvarslot.",'post_type','".$post_type."'";
689
+ $customvarslot++;
690
+ }
691
  }
692
+ if ( $options['cv_authorname'] ) {
693
+ $push[] = "'_setCustomVar',".$customvarslot.",'author','".GA_Filter::ga_str_clean(get_the_author_meta('display_name',$wp_query->post->post_author))."'";
694
+ $customvarslot++;
695
+ }
696
+ if ( $options['cv_tags'] ) {
697
+ $i = 0;
698
+ $tagsstr = '';
699
+ foreach ( (array) get_the_tags() as $tag ) {
700
+ if ($i > 0)
701
+ $tagsstr .= ' ';
702
+ $tagsstr .= $tag->slug;
703
+ $i++;
704
+ }
705
+ // Max 64 chars for value and label combined, hence 64 - 4
706
+ $tagsstr = substr($tagsstr, 0, 60);
707
+ $push[] = "'_setCustomVar',".$customvarslot.",'tags','".$tagsstr."'";
708
+ $customvarslot++;
709
+ }
710
+ if ( is_single() ) {
711
+ if ( $options['cv_year'] ) {
712
+ $push[] = "'_setCustomVar',".$customvarslot.",'year','".get_the_time('Y')."'";
713
+ $customvarslot++;
714
+ }
715
+ if ( $options['cv_category'] ) {
716
+ $cats = get_the_category();
717
+ $push[] = "'_setCustomVar',".$customvarslot.",'category','".$cats[0]->slug."'";
718
+ $customvarslot++;
719
+ }
720
+ if ( $options['cv_all_categories'] ) {
721
+ $i = 0;
722
+ $catsstr = '';
723
+ foreach ( (array) get_the_category() as $cat ) {
724
+ if ($i > 0)
725
+ $catsstr .= ' ';
726
+ $catsstr .= $cat->slug;
727
+ $i++;
728
+ }
729
+ // Max 64 chars for value and label combined, hence 64 - 10
730
+ $catsstr = substr($catsstr, 0, 54);
731
+ $push[] = "'_setCustomVar',".$customvarslot.",'categories','".$catsstr."'";
732
+ $customvarslot++;
733
+ }
734
+ }
735
+ }
736
+
737
+ $push = apply_filters('yoast-ga-custom-vars',$push, $customvarslot);
738
+
739
+ $push = apply_filters('yoast-ga-push-before-pageview',$push);
740
 
741
+ if ( is_404() ) {
742
+ $push[] = "'_trackPageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
743
+ } else if ($wp_query->is_search) {
744
+ $pushstr = "'_trackPageview','".get_bloginfo('url')."/?s=";
745
+ if ($wp_query->found_posts == 0) {
746
+ $push[] = $pushstr."no-results:".rawurlencode($wp_query->query_vars['s'])."&cat=no-results'";
747
+ } else if ($wp_query->found_posts == 1) {
748
+ $push[] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=1-result'";
749
+ } else if ($wp_query->found_posts > 1 && $wp_query->found_posts < 6) {
750
+ $push[] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=2-5-results'";
751
+ } else {
752
+ $push[] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=plus-5-results'";
753
  }
754
+ } else {
755
+ $push[] = "'_trackPageview'";
756
+ }
757
+
758
+ $push = apply_filters('yoast-ga-push-after-pageview',$push);
759
 
760
+ if ( defined('WPSC_VERSION') && $options['wpec_tracking'] )
761
+ $push = GA_Filter::wpec_transaction_tracking($push);
762
+
763
+ if ($options['shopp_tracking']) {
764
+ global $Shopp;
765
+ if ( isset($Shopp) )
766
+ $push = GA_Filter::shopp_transaction_tracking($push);
767
  }
768
+
769
+ $pushstr = "";
770
+ foreach ($push as $key) {
771
+ if (!empty($pushstr))
772
+ $pushstr .= ",";
773
+
774
+ $pushstr .= "[".$key."]";
775
+ }
776
+
777
+ ?>
778
+
779
+ <!-- Google Analytics for WordPress by Yoast v4.0 | http://yoast.com/wordpress/google-analytics/ -->
780
+ <script type="text/javascript">//<![CDATA[
781
+ var _gaq = _gaq || [];
782
+ _gaq.push(['_setAccount','<?php echo $options["uastring"]; ?>']);
783
+ _gaq.push(<?php echo $pushstr; ?>);
784
+ <?php
785
+ if ( $options["extrase"] ) {
786
+ if ( !empty($options["extraseurl"]) ) {
787
+ $url = $options["extraseurl"];
788
+ } else {
789
+ $url = gapp_plugin_path().'custom_se_async.js';
790
+ }
791
+ echo '</script><script src="'.$url.'" type="text/javascript"></script>'."\n".'<script type="text/javascript">';
792
+ }
793
+
794
+ ?> (function() {
795
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
796
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
797
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
798
+ })();
799
+ //]]></script>
800
+ <!-- End of Google Analytics for WordPress by Yoast v4.0 -->
801
+ <?php
802
+ } else if ( $options["uastring"] != "" ) {
803
+ echo "<!-- Google Analytics tracking code not shown because users over level ".$options["ignore_userlevel"]." are ignored -->\n";
804
  } else if ( $options["uastring"] == "" && current_user_can('edit_users') ) {
805
+ echo "<!-- Google Analytics tracking code not shown because yo haven't chosen a Google Analytics account yet. -->\n";
806
  }
807
  }
808
 
810
  * Insert the AdSense parameter code into the page. This'll go into the header per Google's instructions.
811
  */
812
  function spool_adsense() {
813
+ $options = get_option('Yoast_Google_Analytics');
814
  if ( $options["uastring"] != "" && (!current_user_can('edit_users') || $options["admintracking"]) && !is_preview() ) {
815
  echo '<script type="text/javascript">'."\n";
816
  echo "\t".'window.google_analytics_uacct = "'.$options["uastring"].'";'."\n";
818
  }
819
  }
820
 
821
+ function ga_get_tracking_prefix() {
822
+ $options = get_option('Yoast_Google_Analytics');
823
+ return (empty($options['trackprefix'])) ? '/yoast-ga/' : $options['trackprefix'];
824
+ }
825
+
826
+ function ga_get_tracking_link($prefix, $target, $jsprefix = 'javascript:') {
827
+ $options = get_option('Yoast_Google_Analytics');
828
+ if (
829
+ ( $prefix != 'download' && $options['outboundpageview'] ) ||
830
+ ( $prefix == 'download' && $options['downloadspageview'] ) )
831
+ {
832
+ $prefix = GA_Filter::ga_get_tracking_prefix().$prefix;
833
+ $pushstr = "['_trackPageview','".$prefix."/".$target."']";
834
+ } else {
835
+ $pushstr = "['_trackEvent','".$prefix."','".$target."']";
836
+ }
837
+ return $jsprefix."_gaq.push(".$pushstr.");";
838
+ }
839
  /* Create an array which contians:
840
  * "domain" e.g. boakes.org
841
  * "host" e.g. store.boakes.org
847
 
848
  preg_match($hostPattern, $uri, $matches);
849
  $host = $matches[2];
850
+ if (preg_match("/.*\..*\..*\..*$/",$host))
851
+ preg_match($domainPatternUK, $host, $matches);
852
+ else
853
+ preg_match($domainPatternUS, $host, $matches);
 
854
 
855
  return array("domain"=>$matches[0],"host"=>$host);
856
  }
857
 
858
+ function ga_parse_link($category, $matches){
859
  $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
860
+ $options = get_option('Yoast_Google_Analytics');
861
 
862
  // Break out immediately if the link is not an http or https link.
863
  if (strpos($matches[2],"http") !== 0)
865
  else
866
  $target = GA_Filter::ga_get_domain($matches[3]);
867
 
868
+ $trackBit = "";
869
+ $extension = substr(strrchr($matches[3], '.'), 1);
870
+ $dlextensions = split(",",str_replace('.','',$options['dlextensions']));
871
  if ( $target ) {
872
+ if ( in_array($extension, $dlextensions) ) {
873
+ $file = $matches[3];
874
+ $trackBit = GA_Filter::ga_get_tracking_link('download', $file,'');
875
+ } else if ( $target["domain"] != $origin["domain"] ){
876
  if ($options['domainorurl'] == "domain") {
877
+ $url = $target["host"];
878
  } else if ($options['domainorurl'] == "url") {
879
+ $url = $matches[3];
880
  }
881
+ $trackBit = GA_Filter::ga_get_tracking_link($category, $url,'');
882
+ }
 
 
 
883
  }
884
+ if ($trackBit != "") {
885
  if (preg_match('/onclick=[\'\"](.*?)[\'\"]/i', $matches[4]) > 0) {
886
+ // Check for manually tagged outbound clicks, and replace them with the tracking of choice.
887
+ if (preg_match('/.*_track(Pageview|Event).*/i', $matches[4]) > 0) {
888
+ $matches[4] = preg_replace('/onclick=[\'\"](javascript:)?(.*;)?[a-zA-Z0-9]+\._track(Pageview|Event)\([^\)]+\)(;)?(.*)?[\'\"]/i', 'onclick="javascript:' . $trackBit .'$2$5"', $matches[4]);
889
+ } else {
890
+ $matches[4] = preg_replace('/onclick=[\'\"](javascript:)?(.*?)[\'\"]/i', 'onclick="javascript:' . $trackBit .'$2"', $matches[4]);
891
+ }
892
  } else {
893
+ $matches[4] = 'onclick="javascript:' . $trackBit . '"' . $matches[4];
894
  }
895
  }
896
  return '<a ' . $matches[1] . 'href="' . $matches[2] . '//' . $matches[3] . '"' . ' ' . $matches[4] . '>' . $matches[5] . '</a>';
897
  }
898
 
899
  function ga_parse_article_link($matches){
900
+ return GA_Filter::ga_parse_link('outbound-article',$matches);
 
901
  }
902
 
903
  function ga_parse_comment_link($matches){
904
+ return GA_Filter::ga_parse_link('outbound-comment',$matches);
 
905
  }
906
 
907
  function the_content($text) {
921
  }
922
 
923
  function comment_author_link($text) {
924
+ $options = get_option('Yoast_Google_Analytics');
925
+
926
  if (current_user_can('edit_users') && !$options["admintracking"]) {
927
  return $text;
928
  }
931
  if ($matches[2] == "") return $text;
932
 
933
  $target = GA_Filter::ga_get_domain($matches[2]);
 
934
  $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
935
  if ( $target["domain"] != $origin["domain"] ){
936
+ if ($options['domainorurl'] == "domain")
937
+ $url = $target["host"];
938
+ else
939
+ $url = $matches[2];
940
+ $trackBit = 'onclick="'.GA_Filter::ga_get_tracking_link('outbound-commentauthor', $url).'"';
941
  }
942
+ return $matches[1] . "\"" . $matches[2] . "\" " . $trackBit ." ". $matches[3];
943
  }
944
 
945
  function bookmarks($bookmarks) {
946
+ $options = get_option('Yoast_Google_Analytics');
947
 
948
  if (!is_admin() && (!current_user_can('edit_users') || $options['admintracking'] ) ) {
949
+ $i = 0;
950
+ while ( $i < count($bookmarks) ) {
951
+ $target = GA_Filter::ga_get_domain($bookmarks[$i]->link_url);
952
  $sitedomain = GA_Filter::ga_get_domain(get_bloginfo('url'));
953
+ if ($target['host'] == $sitedomain['host']) {
954
+ $i++;
955
+ continue;
 
 
 
956
  }
957
+ if ($options['domainorurl'] == "domain")
958
+ $url = $target["host"];
959
+ else
960
+ $url = $bookmarks[$i]->link_url;
961
+ $trackBit = '" onclick="'.GA_Filter::ga_get_tracking_link('outbound-blogroll', $url);
962
+ $bookmarks[$i]->link_target .= $trackBit;
963
+ $i++;
964
  }
965
  }
966
  return $bookmarks;
967
  }
968
 
969
  function rsslinktagger($guid) {
970
+ $options = get_option('Yoast_Google_Analytics');
971
  global $wp, $post;
972
  if ( is_feed() ) {
973
  if ( $options['allowanchor'] ) {
981
  }
982
  }
983
 
984
+ function wpec_transaction_tracking( $push ) {
985
+ global $wpdb, $purchlogs, $cart_log_id;
986
+ if( !isset( $cart_log_id ) || empty($cart_log_id) )
987
+ return $push;
988
+
989
+ $city = $wpdb->get_var ("SELECT tf.value
990
+ FROM ".WPSC_TABLE_SUBMITED_FORM_DATA." tf
991
+ LEFT JOIN ".WPSC_TABLE_CHECKOUT_FORMS." cf
992
+ ON cf.id = tf.form_id
993
+ WHERE cf.type = 'city'
994
+ AND log_id = ".$cart_log_id );
995
+
996
+ $country = $wpdb->get_var ("SELECT tf.value
997
+ FROM ".WPSC_TABLE_SUBMITED_FORM_DATA." tf
998
+ LEFT JOIN ".WPSC_TABLE_CHECKOUT_FORMS." cf
999
+ ON cf.id = tf.form_id
1000
+ WHERE cf.type = 'country'
1001
+ AND log_id = ".$cart_log_id );
1002
+
1003
+ $cart_items = $wpdb->get_results ("SELECT * FROM ".WPSC_TABLE_CART_CONTENTS." WHERE purchaseid = ".$cart_log_id, ARRAY_A);
1004
+
1005
+ $total_shipping = $purchlogs->allpurchaselogs[0]->base_shipping;
1006
+ $total_tax = 0;
1007
+ foreach ( $cart_items as $item ) {
1008
+ $total_shipping += $item['pnp'];
1009
+ $total_tax += $item['tax_charged'];
1010
+ }
1011
+
1012
+ $push[] = "'_addTrans','".$cart_log_id."'," // Order ID
1013
+ ."'".GA_Filter::ga_str_clean(get_bloginfo('name'))."'," // Store name
1014
+ ."'".nzshpcrt_currency_display($purchlogs->allpurchaselogs[0]->totalprice,1,true,false,true)."'," // Total price
1015
+ ."'".nzshpcrt_currency_display($total_tax,1,true,false,true)."'," // Tax
1016
+ ."'".nzshpcrt_currency_display($total_shipping,1,true,false,true)."'," // Shipping
1017
+ ."'".$city."'," // City
1018
+ ."''," // State
1019
+ ."'".$country."'"; // Country
1020
+
1021
+ foreach( $cart_items as $item ) {
1022
+ $item['sku'] = $wpdb->get_var( "SELECT meta_value FROM ".WPSC_TABLE_PRODUCTMETA." WHERE meta_key = 'sku' AND product_id = '".$item['prodid']."' LIMIT 1" );
1023
+
1024
+ $item['category'] = $wpdb->get_var( "SELECT pc.name FROM ".WPSC_TABLE_PRODUCT_CATEGORIES." pc LEFT JOIN ".WPSC_TABLE_ITEM_CATEGORY_ASSOC." ca ON pc.id = ca.category_id WHERE pc.group_id = '1' AND ca.product_id = '".$item['prodid']."'" );
1025
+ $push[] = "'_addItem',"
1026
+ ."'".$cart_log_id."'," // Order ID
1027
+ ."'".$item['sku']."'," // Item SKU
1028
+ ."'".$item['name']."'," // Item Name
1029
+ ."'".$item['category']."'," // Item Category
1030
+ ."'".$item['price']."'," // Item Price
1031
+ ."'".$item['quantity']."'"; // Item Quantity
1032
+ }
1033
+ $push[] = "'_trackTrans'";
1034
+
1035
+ return $push;
1036
+ }
1037
+
1038
+ function shopp_transaction_tracking( $push ) {
1039
+ global $Shopp;
1040
+ // Only process if we're in the checkout process (receipt page)
1041
+ if (function_exists('is_shopp_page') && !is_shopp_page('checkout'))
1042
+ return $push;
1043
+ // Only process if we have valid order data
1044
+ if (!isset($Shopp->Cart->data->Purchase) || empty($Shopp->Cart->data->Purchase->id))
1045
+ return $push;
1046
+
1047
+ $Purchase = $Shopp->Cart->data->Purchase;
1048
+ $push[] = "'_addTrans',"
1049
+ ."'".$Purchase->id."'," // Order ID
1050
+ ."'".GA_Filter::ga_str_clean(get_bloginfo('name'))."'," // Store
1051
+ ."'".number_format($Purchase->total,2)."'," // Total price
1052
+ ."'".number_format($Purchase->tax,2)."'," // Tax
1053
+ ."'".number_format($Purchase->shipping,2)."'," // Shipping
1054
+ ."'".$Purchase->city."'," // City
1055
+ ."'".$Purchase->state."'," // State
1056
+ ."'.$Purchase->country.'"; // Country
1057
+
1058
+ foreach ($Purchase->purchased as $item) {
1059
+ $sku = empty($item->sku) ? 'PID-'.$item->product.str_pad($item->price,4,'0',STR_PAD_LEFT) : $item->sku;
1060
+ $push[] = "'_addItem',"
1061
+ ."'".$Purchase->id."',"
1062
+ ."'".$sku."',"
1063
+ ."'".$item->name."',"
1064
+ ."'".$item->optionlabel."',"
1065
+ ."'".number_format($item->unitprice,2)."',"
1066
+ ."'".$item->quantity."'";
1067
+ }
1068
+ $push[] = "'_trackTrans'";
1069
+ return $push;
1070
+ }
1071
+
1072
  } // class GA_Filter
1073
  } // endif
1074
 
1075
  /**
1076
  * If setAllowAnchor is set to true, GA ignores all links tagged "normally", so we redirect all "normally" tagged URL's
1077
+ * to one tagged with a hash.
 
1078
  */
1079
  function ga_utm_hashtag_redirect() {
1080
  if (isset($_SERVER['REQUEST_URI'])) {
1095
  }
1096
  }
1097
 
1098
+ function track_comment_form_head() {
1099
+ if (is_single()) {
1100
+ global $post;
1101
+ if ('open' == $post->comment_status)
1102
+ wp_enqueue_script('jquery');
1103
+ }
1104
+ }
1105
+ add_action('wp_print_scripts','track_comment_form_head');
1106
+
1107
+ $comment_form_id = '';
1108
+ function yoast_get_comment_form_id($args) {
1109
+ global $comment_form_id;
1110
+ $comment_form_id = $args['id_form'];
1111
+ return $args;
1112
+ }
1113
+ add_filter('comment_form_defaults', 'yoast_get_comment_form_id',99,1);
1114
+
1115
+ function yoast_track_comment_form() {
1116
+ global $comment_form_id, $post;
1117
+ $yoast_ga_options = get_option('Yoast_Google_Analytics');
1118
+ ?>
1119
+ <script type="text/javascript" charset="utf-8">
1120
+ jQuery(document).ready(function() {
1121
+ jQuery('#<?php echo $comment_form_id; ?>').submit(function() {
1122
+ _gaq.push(
1123
+ ['_setAccount','<?php echo $yoast_ga_options["uastring"]; ?>'],
1124
+ ['_trackEvent','comment']
1125
+ );
1126
+ });
1127
+ });
1128
+ </script>
1129
+ <?php
1130
+ }
1131
+ add_action('comment_form_after','yoast_track_comment_form');
1132
+ /*
1133
+ function gfform_tag() {
1134
+ $options = get_option('Yoast_Google_Analytics');
1135
+ if ( isset( $options['taggfsubmit'] ) && $options['taggfsubmit'] ) {
1136
+ $title = GA_Filter::ga_str_clean( $form['title'] );
1137
+ if ($options['gfsubmiteventpv'] == 'events') {
1138
+ $pv = "['_trackEvent','gf_form_submit','".$title."']";
1139
+ } else {
1140
+ $pv = "['_trackPageview','".GA_Filter::ga_get_tracking_prefix()."gf-form-submit/".$title."']";
1141
+ }
1142
+ }
1143
+ wp_enqueue_script('jquery');
1144
+ ?>
1145
+ <script type="text/javascript" charset="utf-8">
1146
+ jQuery(document).ready(function() {
1147
+ jQuery('.gform_wrapper form').submit(function() {
1148
+ _gaq.push(<?php echo $pv; ?>);
1149
+ });
1150
+ });
1151
+ </script>
1152
+ <?php
1153
+ }
1154
+ add_action('wp_footer','gfform_tag',10);
1155
+ */
1156
+
1157
+ function yoast_analytics() {
1158
+ $options = get_option('Yoast_Google_Analytics');
1159
+ if ($options['position'] == 'manual')
1160
+ GA_Filter::spool_analytics();
1161
+ else
1162
+ echo '<!-- Please set Google Analytics position to "manual" in the settings, or remove this call to yoast_analytics(); -->';
1163
+ }
1164
+
1165
  $gaf = new GA_Filter();
1166
+ $options = get_option('Yoast_Google_Analytics');
1167
 
1168
  if (!is_array($options))
1169
  $ga_admin->set_defaults();
1182
  }
1183
 
1184
  if ($options['trackadsense'])
1185
+ add_action('wp_head', array('GA_Filter','spool_adsense'),1);
1186
 
1187
+ switch ($options['position']) {
1188
+ case 'manual':
1189
+ // No need to insert here, bail NOW.
1190
+ break;
1191
+ case 'header':
1192
+ default:
1193
+ add_action('wp_head', array('GA_Filter','spool_analytics'),2);
1194
+ break;
1195
+ }
1196
 
1197
  if ($options['trackregistration'])
1198
  add_action('login_head', array('GA_Filter','spool_analytics'),20);
chart_curve.png → images/chart_curve.png RENAMED
File without changes
images/email_sub.png ADDED
Binary file
images/rss.png ADDED
Binary file
images/yoast-16x16.png ADDED
Binary file
readme.txt CHANGED
@@ -1,22 +1,24 @@
1
  === Google Analytics for WordPress ===
2
  Contributors: joostdevalk
3
  Donate link: http://yoast.com/donate/
4
- Tags: analytics, google analytics, statistics
5
- Requires at least: 2.7
6
- Tested up to: 2.9
7
- Stable tag: 3.2.5
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
 
11
  == Description ==
12
 
13
- 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.
14
 
15
- In the options panel for the plugin, you can determine the prefixes to use for the different kinds of outbound links and downloads it tracks.
 
 
16
 
17
- * [Google Analytics for WordPress](http://yoast.com/wordpress/google-analytics/).
18
  * Other [Wordpress plugins](http://yoast.com/wordpress/) by the same author.
19
- * Check out the authors [WordPress Hosting](http://yoast.com/wordpress-hosting/) experience. Good hosting is hard to come by, but it doesn't have to be expensive, Joost tells you why!
 
20
 
21
  == Installation ==
22
 
@@ -29,11 +31,17 @@ This section describes how to install the plugin and get it working.
29
 
30
  == Changelog ==
31
 
32
- = 3.2.5 =
33
- * Fix for XSS vulnerability as mentioned [here](http://www.securityfocus.com/archive/1/508211).
34
-
35
- = 3.2.4 =
36
- * Fixed a bug in search tracking introduced with previous version.
 
 
 
 
 
 
37
 
38
  = 3.2.3 =
39
  * Added 0 result search tracking inspired by [Justin Cutroni's post](http://www.epikone.com/blog/2009/09/08/tracking-ero-result-searches-in-google-analytics/).
@@ -166,4 +174,4 @@ Create a <a href="http://yoast.com/wordpress/google-analytics/creating-a-google-
166
  == Screenshots ==
167
 
168
  1. Screenshot of the configuration panel for this plugin.
169
- 2. Example of the exclude filter in Google Analytics.
1
  === Google Analytics for WordPress ===
2
  Contributors: joostdevalk
3
  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
8
 
9
+ The Google Analytics for WordPress plugin allows you to track your blog easily. 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 allows 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
 
11
  == Description ==
12
 
13
+ The Google Analytics for WordPress plugin allows you to track your blog easily. 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 allows 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!
14
 
15
+ For the full list of features, check out the [Google Analytics for WordPress](http://yoast.com/wordpress/google-analytics/) homepage.
16
+
17
+ NOTE WHEN UPGRADING TO VERSION 4.0: you'll have to reconfigure the plugin so it can fully support all the new features!
18
 
 
19
  * Other [Wordpress plugins](http://yoast.com/wordpress/) by the same author.
20
+ * Want to increase traffic to your WordPress blog? Check out the [WordPress SEO](http://yoast.com/articles/wordpress-seo/) Guide!
21
+ * Check out the authors [WordPress Hosting](http://yoast.com/articles/wordpress-hosting/) experience. Good hosting is hard to come by, but it doesn't have to be expensive, Joost tells you why!
22
 
23
  == Installation ==
24
 
31
 
32
  == Changelog ==
33
 
34
+ = 4.0 =
35
+ * NOTE WHEN UPGRADING: you'll have to reconfigure the plugin so it can fully support all the new features!
36
+ * Complete rewrite of the codebase
37
+ * Switched to the new asynchronous event tracking model
38
+ * Switched link tracking to an event tracking model, because of this change removed 5 settings from the settings panel that were no longer needed
39
+ * Implemented custom variable tracking to track:
40
+ * On the session level: whether the user is logged in or not.
41
+ * On the page level: the current posts's author, category, tags, year of publication and post type.
42
+ * Added Google Analytics API integration, so you can easily select a site to track.
43
+ * E-Commerce integration, tracking transactions, support for WP E-Commerce and Shopp.
44
+ * Much much more: check out [the release post](http://yoast.com/google-analytics-wordpress-v4/).
45
 
46
  = 3.2.3 =
47
  * Added 0 result search tracking inspired by [Justin Cutroni's post](http://www.epikone.com/blog/2009/09/08/tracking-ero-result-searches-in-google-analytics/).
174
  == Screenshots ==
175
 
176
  1. Screenshot of the configuration panel for this plugin.
177
+ 2. Example of the exclude filter in Google Analytics.
screenshot-1.jpg DELETED
Binary file
screenshot-1.png ADDED
Binary file
xmlparser.php ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ function yoast_xml2array($contents, $get_attributes = 1, $priority = 'tag') {
3
+ if (!function_exists('xml_parser_create'))
4
+ {
5
+ return "error";
6
+ }
7
+ $parser = xml_parser_create('');
8
+ xml_parser_set_option($parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
9
+ xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
10
+ xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
11
+ xml_parse_into_struct($parser, trim($contents), $xml_values);
12
+ xml_parser_free($parser);
13
+ if (!$xml_values)
14
+ return; //Hmm...
15
+ $xml_array = array ();
16
+ $parents = array ();
17
+ $opened_tags = array ();
18
+ $arr = array ();
19
+ $current = & $xml_array;
20
+ $repeated_tag_index = array ();
21
+ foreach ($xml_values as $data)
22
+ {
23
+ unset ($attributes, $value);
24
+ extract($data);
25
+ $result = array ();
26
+ $attributes_data = array ();
27
+ if (isset ($value))
28
+ {
29
+ if ($priority == 'tag')
30
+ $result = $value;
31
+ else
32
+ $result['value'] = $value;
33
+ }
34
+ if (isset ($attributes) and $get_attributes)
35
+ {
36
+ foreach ($attributes as $attr => $val)
37
+ {
38
+ if ($priority == 'tag')
39
+ $attributes_data[$attr] = $val;
40
+ else
41
+ $result['attr'][$attr] = $val; //Set all the attributes in a array called 'attr'
42
+ }
43
+ }
44
+ if ($type == "open")
45
+ {
46
+ $parent[$level -1] = & $current;
47
+ if (!is_array($current) or (!in_array($tag, array_keys($current))))
48
+ {
49
+ $current[$tag] = $result;
50
+ if ($attributes_data)
51
+ $current[$tag . '_attr'] = $attributes_data;
52
+ $repeated_tag_index[$tag . '_' . $level] = 1;
53
+ $current = & $current[$tag];
54
+ }
55
+ else
56
+ {
57
+ if (isset ($current[$tag][0]))
58
+ {
59
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
60
+ $repeated_tag_index[$tag . '_' . $level]++;
61
+ }
62
+ else
63
+ {
64
+ $current[$tag] = array (
65
+ $current[$tag],
66
+ $result
67
+ );
68
+ $repeated_tag_index[$tag . '_' . $level] = 2;
69
+ if (isset ($current[$tag . '_attr']))
70
+ {
71
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
72
+ unset ($current[$tag . '_attr']);
73
+ }
74
+ }
75
+ $last_item_index = $repeated_tag_index[$tag . '_' . $level] - 1;
76
+ $current = & $current[$tag][$last_item_index];
77
+ }
78
+ }
79
+ elseif ($type == "complete")
80
+ {
81
+ if (!isset ($current[$tag]))
82
+ {
83
+ $current[$tag] = $result;
84
+ $repeated_tag_index[$tag . '_' . $level] = 1;
85
+ if ($priority == 'tag' and $attributes_data)
86
+ $current[$tag . '_attr'] = $attributes_data;
87
+ }
88
+ else
89
+ {
90
+ if (isset ($current[$tag][0]) and is_array($current[$tag]))
91
+ {
92
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level]] = $result;
93
+ if ($priority == 'tag' and $get_attributes and $attributes_data)
94
+ {
95
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
96
+ }
97
+ $repeated_tag_index[$tag . '_' . $level]++;
98
+ }
99
+ else
100
+ {
101
+ $current[$tag] = array (
102
+ $current[$tag],
103
+ $result
104
+ );
105
+ $repeated_tag_index[$tag . '_' . $level] = 1;
106
+ if ($priority == 'tag' and $get_attributes)
107
+ {
108
+ if (isset ($current[$tag . '_attr']))
109
+ {
110
+ $current[$tag]['0_attr'] = $current[$tag . '_attr'];
111
+ unset ($current[$tag . '_attr']);
112
+ }
113
+ if ($attributes_data)
114
+ {
115
+ $current[$tag][$repeated_tag_index[$tag . '_' . $level] . '_attr'] = $attributes_data;
116
+ }
117
+ }
118
+ $repeated_tag_index[$tag . '_' . $level]++; //0 and 1 index is already taken
119
+ }
120
+ }
121
+ }
122
+ elseif ($type == 'close')
123
+ {
124
+ $current = & $parent[$level -1];
125
+ }
126
+ }
127
+ return ($xml_array);
128
+ }
129
+ ?>
yst_plugin_tools.css CHANGED
@@ -1,8 +1,18 @@
1
- small {
2
- font-weight:normal;
 
 
3
  color:#777;
4
  }
5
 
 
 
 
 
 
 
 
 
6
  div.inside ul {
7
  margin-left: 20px;
8
  }
@@ -12,18 +22,50 @@ div.inside ul li {
12
  line-height:16px;
13
  }
14
 
 
 
 
 
 
 
 
15
  div.inside ul li.rss {
16
- list-style-image: url(/wp-includes/images/rss.png);
17
  }
18
 
19
  div.inside ul li.email {
20
- list-style-image: url(http://cdn.yoast.com/email_sub.png);
21
  }
22
 
23
  div.inside ul li.yoast {
24
- list-style-image: url(http://cdn.yoast.com/theme/yoast-16x16.png);
25
  }
26
 
27
- .text {
28
  width: 250px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  }
1
+ td.yst_desc {
2
+ font-weight: normal;
3
+ font-size: 12px;
4
+ line-height: 12px;
5
  color:#777;
6
  }
7
 
8
+ tr.yst_row {
9
+ padding: 5px 0 0 0;
10
+ margin: 5px 0 0 0;
11
+ }
12
+ tr.yst_row.even {
13
+ background-color: #f6f6f6;
14
+ }
15
+
16
  div.inside ul {
17
  margin-left: 20px;
18
  }
22
  line-height:16px;
23
  }
24
 
25
+ div.inside a, div.inside a.rsswidget {
26
+ font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif;
27
+ text-decoration: none;
28
+ }
29
+ div.inside a:hover, div.inside a.rsswidget:hover {
30
+ text-decoration: underline;
31
+ }
32
  div.inside ul li.rss {
33
+ list-style-image: url(images/rss.png);
34
  }
35
 
36
  div.inside ul li.email {
37
+ list-style-image: url(images/email_sub.png);
38
  }
39
 
40
  div.inside ul li.yoast {
41
+ list-style-image: url(images/yoast-16x16.png);
42
  }
43
 
44
+ .text, .select {
45
  width: 250px;
46
+ }
47
+
48
+ .postbox p {
49
+ text-align:left;
50
+ margin: 0 10px 10px 10px;
51
+ font-size: 13px;
52
+ line-height: 150%;
53
+ }
54
+
55
+ .postbox pre {
56
+ margin: 5px 10px;
57
+ padding:4px;
58
+ background: lightyellow;
59
+ }
60
+
61
+ .side .postbox p, .side .postbox a, .side .postbox a.rsswidget {
62
+ font-size: 11px;
63
+ }
64
+
65
+ div.inside .button:hover, div.inside .button-primary:hover {
66
+ text-decoration: none;
67
+ }
68
+
69
+ .button, .button-primary {
70
+ margin-top: 10px;
71
  }
yst_plugin_tools.php CHANGED
@@ -5,8 +5,8 @@
5
  * Version 0.2
6
  */
7
 
8
- if (!class_exists('Yoast_Plugin_Admin')) {
9
- class Yoast_Plugin_Admin {
10
 
11
  var $hook = '';
12
  var $filename = '';
@@ -15,9 +15,9 @@ if (!class_exists('Yoast_Plugin_Admin')) {
15
  var $ozhicon = '';
16
  var $optionname = '';
17
  var $homepage = '';
18
- var $accesslvl = 'manage_options';
19
 
20
- function Yoast_Plugin_Admin() {
21
  add_action( 'admin_menu', array(&$this, 'register_settings_page') );
22
  add_filter( 'plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
23
  add_filter( 'ozh_adminmenu_icon', array(&$this, 'add_ozh_adminmenu_icon' ) );
@@ -81,19 +81,37 @@ if (!class_exists('Yoast_Plugin_Admin')) {
81
  /**
82
  * Create a Checkbox input field
83
  */
84
- function checkbox($id, $label) {
85
- $options = get_option($this->optionname);
86
- return '<input type="checkbox" id="'.$id.'" name="'.$id.'"'. checked($options[$id],true,false).'/> <label for="'.$id.'">'.$label.'</label><br/>';
87
  }
88
-
89
  /**
90
  * Create a Text input field
91
  */
92
- function textinput($id, $label) {
93
- $options = get_option($this->optionname);
94
- return '<label for="'.$id.'">'.$label.':</label><br/><input size="45" type="text" id="'.$id.'" name="'.$id.'" value="'.$options[$id].'"/><br/><br/>';
95
  }
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  /**
98
  * Create a potbox widget
99
  */
@@ -115,17 +133,28 @@ if (!class_exists('Yoast_Plugin_Admin')) {
115
  */
116
  function form_table($rows) {
117
  $content = '<table class="form-table">';
 
118
  foreach ($rows as $row) {
119
- $content .= '<tr><th valign="top" scrope="row">';
 
 
 
 
 
 
 
120
  if (isset($row['id']) && $row['id'] != '')
121
  $content .= '<label for="'.$row['id'].'">'.$row['label'].':</label>';
122
  else
123
  $content .= $row['label'];
124
- if (isset($row['desc']) && $row['desc'] != '')
125
- $content .= '<br/><small>'.$row['desc'].'</small>';
126
  $content .= '</th><td valign="top">';
127
  $content .= $row['content'];
128
  $content .= '</td></tr>';
 
 
 
 
 
129
  }
130
  $content .= '</table>';
131
  return $content;
@@ -134,43 +163,51 @@ if (!class_exists('Yoast_Plugin_Admin')) {
134
  /**
135
  * Create a "plugin like" box.
136
  */
137
- function plugin_like() {
 
 
 
138
  $content = '<p>'.__('Why not do any or all of the following:','ystplugin').'</p>';
139
  $content .= '<ul>';
140
  $content .= '<li><a href="'.$this->homepage.'">'.__('Link to it so other folks can find out about it.','ystplugin').'</a></li>';
141
- $content .= '<li><a href="http://wordpress.org/extend/plugins/'.$this->hook.'/">'.__('Give it a good rating on WordPress.org.','ystplugin').'</a></li>';
142
- $content .= '<li><a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&amp;hosted_button_id=2017947">'.__('Donate a token of your appreciation.','ystplugin').'</a></li>';
143
  $content .= '</ul>';
144
- $this->postbox($this->hook.'like', 'Like this plugin?', $content);
145
  }
146
 
147
  /**
148
- * Info box with link to the support forums.
149
  */
150
- function plugin_support() {
151
- $content = '<p>'.__('If you have any problems with this plugin or good ideas for improvements or new features, please talk about them in the','ystplugin').' <a href="http://wordpress.org/tags/'.$this->hook.'">'.__("Support forums",'ystplugin').'</a>.</p>';
152
- $this->postbox($this->hook.'support', 'Need support?', $content);
 
 
 
153
  }
154
 
155
  /**
156
  * Box with latest news from Yoast.com
157
  */
158
  function news() {
159
- require_once(ABSPATH.WPINC.'/rss.php');
160
- if ( $rss = fetch_rss( 'http://feeds2.feedburner.com/joostdevalk' ) ) {
161
- $content = '<ul>';
162
- $rss->items = array_slice( $rss->items, 0, 3 );
163
- foreach ( (array) $rss->items as $item ) {
 
 
 
164
  $content .= '<li class="yoast">';
165
- $content .= '<a class="rsswidget" href="'.clean_url( $item['link'], $protocolls=null, 'display' ).'">'. htmlentities($item['title']) .'</a> ';
166
  $content .= '</li>';
167
- }
168
- $content .= '<li class="rss"><a href="http://yoast.com/feed/">Subscribe with RSS</a></li>';
169
- $content .= '<li class="email"><a href="http://yoast.com/email-blog-updates/">Subscribe by email</a></li>';
170
- $this->postbox('yoastlatest', 'Latest news from Yoast', $content);
171
- } else {
172
- $this->postbox('yoastlatest', 'Latest news from Yoast', 'Nothing to say...');
173
- }
174
  }
175
 
176
  function text_limit( $text, $limit, $finish = ' [&hellip;]') {
5
  * Version 0.2
6
  */
7
 
8
+ if (!class_exists('Yoast_GA_Plugin_Admin')) {
9
+ class Yoast_GA_Plugin_Admin {
10
 
11
  var $hook = '';
12
  var $filename = '';
15
  var $ozhicon = '';
16
  var $optionname = '';
17
  var $homepage = '';
18
+ var $accesslvl = 'edit_users';
19
 
20
+ function Yoast_GA_Plugin_Admin() {
21
  add_action( 'admin_menu', array(&$this, 'register_settings_page') );
22
  add_filter( 'plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
23
  add_filter( 'ozh_adminmenu_icon', array(&$this, 'add_ozh_adminmenu_icon' ) );
81
  /**
82
  * Create a Checkbox input field
83
  */
84
+ function checkbox($id) {
85
+ $options = get_option( $this->optionname );
86
+ return '<input type="checkbox" id="'.$id.'" name="'.$id.'"'. checked($options[$id],true,false).'/>';
87
  }
88
+
89
  /**
90
  * Create a Text input field
91
  */
92
+ function textinput($id) {
93
+ $options = get_option( $this->optionname );
94
+ return '<input class="text" type="text" id="'.$id.'" name="'.$id.'" size="30" value="'.$options[$id].'"/>';
95
  }
96
 
97
+ /**
98
+ * Create a dropdown field
99
+ */
100
+ function select($id, $options, $multiple = false) {
101
+ $opt = get_option($this->optionname);
102
+ $output = '<select class="select" name="'.$id.'" id="'.$id.'">';
103
+ foreach ($options as $val => $name) {
104
+ $sel = '';
105
+ if ($opt[$id] == $val)
106
+ $sel = ' selected="selected"';
107
+ if ($name == '')
108
+ $name = $val;
109
+ $output .= '<option value="'.$val.'"'.$sel.'>'.$name.'</option>';
110
+ }
111
+ $output .= '</select>';
112
+ return $output;
113
+ }
114
+
115
  /**
116
  * Create a potbox widget
117
  */
133
  */
134
  function form_table($rows) {
135
  $content = '<table class="form-table">';
136
+ $i = 1;
137
  foreach ($rows as $row) {
138
+ $class = '';
139
+ if ($i > 1) {
140
+ $class .= 'yst_row';
141
+ }
142
+ if ($i % 2 == 0) {
143
+ $class .= ' even';
144
+ }
145
+ $content .= '<tr id="'.$row['id'].'_row" class="'.$class.'"><th valign="top" scrope="row">';
146
  if (isset($row['id']) && $row['id'] != '')
147
  $content .= '<label for="'.$row['id'].'">'.$row['label'].':</label>';
148
  else
149
  $content .= $row['label'];
 
 
150
  $content .= '</th><td valign="top">';
151
  $content .= $row['content'];
152
  $content .= '</td></tr>';
153
+ if ( isset($row['desc']) && !empty($row['desc']) ) {
154
+ $content .= '<tr class="'.$class.'"><td colspan="2" class="yst_desc"><small>'.$row['desc'].'</small></td></tr>';
155
+ }
156
+
157
+ $i++;
158
  }
159
  $content .= '</table>';
160
  return $content;
163
  /**
164
  * Create a "plugin like" box.
165
  */
166
+ function plugin_like($hook = '') {
167
+ if (empty($hook)) {
168
+ $hook = $this->hook;
169
+ }
170
  $content = '<p>'.__('Why not do any or all of the following:','ystplugin').'</p>';
171
  $content .= '<ul>';
172
  $content .= '<li><a href="'.$this->homepage.'">'.__('Link to it so other folks can find out about it.','ystplugin').'</a></li>';
173
+ $content .= '<li><a href="http://wordpress.org/extend/plugins/'.$hook.'/">'.__('Give it a good rating on WordPress.org.','ystplugin').'</a></li>';
174
+ $content .= '<li><a href="http://wordpress.org/extend/plugins/'.$hook.'/">'.__('Let other people know that it works with your WordPress setup.','ystplugin').'</a></li>';
175
  $content .= '</ul>';
176
+ $this->postbox($hook.'like', 'Like this plugin?', $content);
177
  }
178
 
179
  /**
180
+ * Info box with link to the bug tracker.
181
  */
182
+ function plugin_support($hook = '') {
183
+ if (empty($hook)) {
184
+ $hook = $this->hook;
185
+ }
186
+ $content = '<p>If you\'ve found a bug in this plugin, please submit it in the <a href="http://yoast.com/mantis/bug_report_page.php">Yoast Bug Tracker</a> with a clear description.</p>';
187
+ $this->postbox($this->hook.'support', __('Found a bug?','ystplugin'), $content);
188
  }
189
 
190
  /**
191
  * Box with latest news from Yoast.com
192
  */
193
  function news() {
194
+ include_once(ABSPATH . WPINC . '/feed.php');
195
+ $rss = fetch_feed('http://feeds.feedburner.com/joostdevalk');
196
+ $rss_items = $rss->get_items( 0, $rss->get_item_quantity(5) );
197
+ $content = '<ul>';
198
+ if ( !$rss_items ) {
199
+ $content .= '<li class="yoast">no news items, feed might be broken...</li>';
200
+ } else {
201
+ foreach ( $rss_items as $item ) {
202
  $content .= '<li class="yoast">';
203
+ $content .= '<a class="rsswidget" href="'.esc_url( $item->get_permalink(), $protocolls=null, 'display' ).'">'. htmlentities($item->get_title()) .'</a> ';
204
  $content .= '</li>';
205
+ }
206
+ }
207
+ $content .= '<li class="rss"><a href="http://yoast.com/feed/">Subscribe with RSS</a></li>';
208
+ $content .= '<li class="email"><a href="http://yoast.com/email-blog-updates/">Subscribe by email</a></li>';
209
+ $content .= '</ul>';
210
+ $this->postbox('yoastlatest', 'Latest news from Yoast', $content);
 
211
  }
212
 
213
  function text_limit( $text, $limit, $finish = ' [&hellip;]') {