Google Analytics for WordPress by MonsterInsights - Version 4.2.5

Version Description

  • Fixed a couple notices.
  • Added tracking to better understand configurations to test the plugin with.
Download this release

Release Info

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

Code changes from version 4.2.4 to 4.2.5

Files changed (6) hide show
  1. class-pointer.php +122 -0
  2. class-tracking.php +164 -0
  3. googleanalytics.php +1106 -1044
  4. license.txt +621 -0
  5. readme.txt +7 -2
  6. yst_plugin_tools.css +16 -20
class-pointer.php ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Admin
4
+ */
5
+
6
+ /**
7
+ * This class handles the pointers for the GA for WP plugin.
8
+ */
9
+ class GA_Pointer {
10
+
11
+ /**
12
+ * Class constructor.
13
+ */
14
+ function __construct() {
15
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ) );
16
+ }
17
+
18
+ /**
19
+ * Enqueue styles and scripts needed for the pointers.
20
+ */
21
+ function enqueue() {
22
+ $options = get_option( 'Yoast_Google_Analytics' );
23
+ if ( !isset( $options['tracking_popup'] ) && !isset( $_GET['allow_tracking'] ) ) {
24
+ wp_enqueue_style( 'wp-pointer' );
25
+ wp_enqueue_script( 'jquery-ui' );
26
+ wp_enqueue_script( 'wp-pointer' );
27
+ wp_enqueue_script( 'utils' );
28
+ add_action( 'admin_print_footer_scripts', array( $this, 'tracking_request' ) );
29
+ }
30
+ }
31
+
32
+ /**
33
+ * Shows a popup that asks for permission to allow tracking.
34
+ */
35
+ function tracking_request() {
36
+ $id = '#wpadminbar';
37
+ $content = '<h3>' . __( 'Help improve Google Analytics for WordPress', 'gawp' ) . '</h3>';
38
+ $content .= '<p>' . __( 'You\'ve just installed Google Analytics for WordPress by Yoast. Please helps us improve it by allowing us to gather anonymous usage stats so we know which configurations, plugins and themes to test with.', 'gawp' ) . '</p>';
39
+ $opt_arr = array(
40
+ 'content' => $content,
41
+ 'position' => array( 'edge' => 'top', 'align' => 'center' )
42
+ );
43
+ $button2 = __( 'Allow tracking', 'gawp' );
44
+ $nonce = wp_create_nonce( 'wpga_activate_presstrends' );
45
+
46
+ $function2 = 'document.location="' . admin_url( 'options-general.php?page=google-analytics-for-wordpress&allow_tracking=yes&nonce=' . $nonce ) . '";';
47
+ $function1 = 'document.location="' . admin_url( 'options-general.php?page=google-analytics-for-wordpress&allow_tracking=no&nonce=' . $nonce ) . '";';
48
+
49
+ $this->print_scripts( $id, $opt_arr, __( 'Do not allow tracking', 'gawp' ), $button2, $function2, $function1 );
50
+ }
51
+
52
+ /**
53
+ * Load a tiny bit of CSS in the head
54
+ */
55
+ function admin_head() {
56
+ ?>
57
+ <style type="text/css" media="screen">
58
+ #pointer-primary {
59
+ margin: 0 5px 0 0;
60
+ }
61
+ </style>
62
+ <?php
63
+ }
64
+
65
+ /**
66
+ * Prints the pointer script
67
+ *
68
+ * @param string $selector The CSS selector the pointer is attached to.
69
+ * @param array $options The options for the pointer.
70
+ * @param string $button1 Text for button 1
71
+ * @param string|bool $button2 Text for button 2 (or false to not show it, defaults to false)
72
+ * @param string $button2_function The JavaScript function to attach to button 2
73
+ * @param string $button1_function The JavaScript function to attach to button 1
74
+ */
75
+ function print_scripts( $selector, $options, $button1, $button2 = false, $button2_function = '', $button1_function = '' ) {
76
+ ?>
77
+ <script type="text/javascript">
78
+ //<![CDATA[
79
+ (function ($) {
80
+ var gawp_pointer_options = <?php echo json_encode( $options ); ?>, setup;
81
+
82
+ gawp_pointer_options = $.extend(gawp_pointer_options, {
83
+ buttons:function (event, t) {
84
+ button = jQuery('<a id="pointer-close" style="margin-left:5px" class="button-secondary">' + '<?php echo $button1; ?>' + '</a>');
85
+ button.bind('click.pointer', function () {
86
+ t.element.pointer('close');
87
+ });
88
+ return button;
89
+ },
90
+ close:function () {
91
+ }
92
+ });
93
+
94
+ setup = function () {
95
+ $('<?php echo $selector; ?>').pointer(gawp_pointer_options).pointer('open');
96
+ <?php if ( $button2 ) { ?>
97
+ jQuery('#pointer-close').after('<a id="pointer-primary" class="button-primary">' + '<?php echo $button2; ?>' + '</a>');
98
+ jQuery('#pointer-primary').click(function () {
99
+ <?php echo $button2_function; ?>
100
+ });
101
+ jQuery('#pointer-close').click(function () {
102
+ <?php if ( $button1_function == '' ) { ?>
103
+ wpseo_setIgnore("tour", "wp-pointer-0", "<?php echo wp_create_nonce( 'wpseo-ignore' ); ?>");
104
+ <?php } else { ?>
105
+ <?php echo $button1_function; ?>
106
+ <?php } ?>
107
+ });
108
+ <?php } ?>
109
+ };
110
+
111
+ if (gawp_pointer_options.position && gawp_pointer_options.position.defer_loading)
112
+ $(window).bind('load.wp-pointers', setup);
113
+ else
114
+ $(document).ready(setup);
115
+ })(jQuery);
116
+ //]]>
117
+ </script>
118
+ <?php
119
+ }
120
+ }
121
+
122
+ $ga_pointer = new GA_Pointer;
class-tracking.php ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * @package Admin
4
+ */
5
+
6
+ /**
7
+ * Class that creates the tracking functionality for WP SEO, as the core class might be used in more plugins, it's checked for existence first.
8
+ */
9
+ if ( !class_exists( 'Yoast_Tracking' ) ) {
10
+ class Yoast_Tracking {
11
+
12
+ /**
13
+ * Class constructor
14
+ */
15
+ function __construct() {
16
+ add_action( 'admin_footer', array( $this, 'tracking' ), 99 );
17
+
18
+ // Invalidate the cache when changes are being made.
19
+ add_action( 'switch_theme', array( $this, 'delete_cache' ) );
20
+
21
+ add_action( 'admin_init', array( $this, 'check_active_plugins' ) );
22
+ }
23
+
24
+ /**
25
+ * This is the only current way of doing something when a plugin is activated or updated...
26
+ */
27
+ function check_active_plugins() {
28
+ $hash = md5( serialize( get_option( 'active_plugins' ) ) );
29
+ $old_hash = get_transient( 'yoast_tracking_active_plugins_hash' );
30
+ if ( $hash != $old_hash ) {
31
+ add_action( 'admin_footer', array( $this, 'delete_cache' ) );
32
+ set_transient( 'yoast_tracking_active_plugins_hash', $hash, 7 * 60 * 60 * 24 );
33
+ }
34
+ }
35
+
36
+ /**
37
+ * This deletes the tracking cache, effectively meaning the tracking will be done again.
38
+ */
39
+ function delete_cache() {
40
+ delete_transient( 'yoast_tracking_cache' );
41
+ }
42
+
43
+ /**
44
+ * Main tracking function.
45
+ */
46
+ function tracking() {
47
+ // Start of Metrics
48
+ global $wpdb;
49
+
50
+ $options = get_option( 'wpseo' );
51
+
52
+ if ( !isset( $options['hash'] ) || empty( $options['hash'] ) ) {
53
+ $options['hash'] = md5( site_url() );
54
+ update_option( 'wpseo', $options );
55
+ }
56
+
57
+ $data = get_transient( 'yoast_tracking_cache' );
58
+ if ( ( defined( 'DEBUG_YOAST_TRACKING' ) && DEBUG_YOAST_TRACKING ) || !$data || $data == '' ) {
59
+
60
+ $pts = array();
61
+ foreach ( get_post_types( array( 'public' => true ) ) as $pt ) {
62
+ $count = wp_count_posts( $pt );
63
+ $pts[$pt] = $count->publish;
64
+ }
65
+
66
+ $comments_count = wp_count_comments();
67
+
68
+ // wp_get_theme was introduced in 3.4, for compatibility with older versions, let's do a workaround for now.
69
+ if ( function_exists( 'wp_get_theme' ) ) {
70
+ $theme_data = wp_get_theme();
71
+ $theme = array(
72
+ 'name' => $theme_data->display( 'Name', false, false ),
73
+ 'theme_uri' => $theme_data->display( 'ThemeURI', false, false ),
74
+ 'version' => $theme_data->display( 'Version', false, false ),
75
+ 'author' => $theme_data->display( 'Author', false, false ),
76
+ 'author_uri'=> $theme_data->display( 'AuthorURI', false, false ),
77
+ );
78
+ if ( isset( $theme_data->template ) && !empty( $theme_data->template ) && $theme_data->parent() ) {
79
+ $theme['template'] = array(
80
+ 'version' => $theme_data->parent()->display( 'Version', false, false ),
81
+ 'name' => $theme_data->parent()->display( 'Name', false, false ),
82
+ 'theme_uri' => $theme_data->parent()->display( 'ThemeURI', false, false ),
83
+ 'author' => $theme_data->parent()->display( 'Author', false, false ),
84
+ 'author_uri'=> $theme_data->parent()->display( 'AuthorURI', false, false ),
85
+ );
86
+ } else {
87
+ $theme['template'] = '';
88
+ }
89
+ } else {
90
+ $theme_data = (object) get_theme_data( get_stylesheet_directory() . '/style.css' );
91
+ $theme = array(
92
+ 'version' => $theme_data->Version,
93
+ 'name' => $theme_data->Name,
94
+ 'author' => $theme_data->Author,
95
+ 'template' => $theme_data->Template,
96
+ );
97
+ }
98
+
99
+ $plugins = array();
100
+ foreach ( get_option( 'active_plugins' ) as $plugin_path ) {
101
+ $plugin_info = get_plugin_data( WP_PLUGIN_DIR . '/' . $plugin_path );
102
+
103
+ $slug = str_replace( '/' . basename( $plugin_path ), '', $plugin_path );
104
+ $plugins[$slug] = array(
105
+ 'version' => $plugin_info['Version'],
106
+ 'name' => $plugin_info['Name'],
107
+ 'plugin_uri' => $plugin_info['PluginURI'],
108
+ 'author' => $plugin_info['AuthorName'],
109
+ 'author_uri' => $plugin_info['AuthorURI'],
110
+ );
111
+ }
112
+
113
+ $data = array(
114
+ 'site' => array(
115
+ 'hash' => $options['hash'],
116
+ 'url' => site_url(),
117
+ 'name' => get_bloginfo( 'name' ),
118
+ 'version' => get_bloginfo( 'version' ),
119
+ 'multisite' => is_multisite(),
120
+ 'users' => count( get_users() ),
121
+ 'lang' => get_locale(),
122
+ ),
123
+ 'pts' => $pts,
124
+ 'comments' => array(
125
+ 'total' => $comments_count->total_comments,
126
+ 'approved' => $comments_count->approved,
127
+ 'spam' => $comments_count->spam,
128
+ 'pings' => $wpdb->get_var( "SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_type = 'pingback'" ),
129
+ ),
130
+ 'options' => apply_filters( 'yoast_tracking_filters', array() ),
131
+ 'theme' => $theme,
132
+ 'plugins' => $plugins,
133
+ );
134
+
135
+ $args = array(
136
+ 'body' => $data
137
+ );
138
+ wp_remote_post( 'https://tracking.yoast.com/', $args );
139
+
140
+ // Store for a week, then push data again.
141
+ set_transient( 'yoast_tracking_cache', $data, 7 * 60 * 60 * 24 );
142
+ }
143
+ }
144
+ }
145
+
146
+ $yoast_tracking = new Yoast_Tracking;
147
+ }
148
+
149
+ /**
150
+ * Adds tracking parameters for Google Analytics settings. Outside of the main class as the class could also be in use in other plugins.
151
+ *
152
+ * @param array $options
153
+ * @return array
154
+ */
155
+ function ystga_tracking_additions( $options ) {
156
+ $opt = get_option('Yoast_Google_Analytics');
157
+
158
+ $options['gawp'] = array(
159
+ 'advanced_settigns' => isset( $opt['advancedsettings'] ) ? 1 : 0,
160
+ );
161
+ return $options;
162
+ }
163
+
164
+ add_filter( 'yoast_tracking_filters', 'ystga_tracking_additions' );
googleanalytics.php CHANGED
@@ -4,35 +4,60 @@ Plugin Name: Google Analytics for WordPress
4
  Plugin URI: http://yoast.com/wordpress/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v420
5
  Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. custom variables and automatic clickout and download tracking.
6
  Author: Joost de Valk
7
- Version: 4.2.4
8
  Requires at least: 3.0
9
  Author URI: http://yoast.com/
10
- License: GPL
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  */
12
 
13
  // This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics
14
 
15
- define('GAWP_VERSION', '4.2.3');
16
 
17
  /*
18
  * Admin User Interface
19
  */
20
 
21
- if ( is_admin() && ( !defined('DOING_AJAX') || !DOING_AJAX ) && !class_exists( 'GA_Admin' ) ) {
 
 
22
 
23
  require_once plugin_dir_path( __FILE__ ) . 'yst_plugin_tools.php';
24
  require_once plugin_dir_path( __FILE__ ) . '/wp-gdata/wp-gdata.php';
25
-
 
 
 
 
 
 
 
26
  class GA_Admin extends Yoast_GA_Plugin_Admin {
27
 
28
- var $hook = 'google-analytics-for-wordpress';
29
- var $filename = 'google-analytics-for-wordpress/googleanalytics.php';
30
- var $longname = 'Google Analytics Configuration';
31
- var $shortname = 'Google Analytics';
32
- var $ozhicon = 'images/chart_curve.png';
33
  var $optionname = 'Yoast_Google_Analytics';
34
- var $homepage = 'http://yoast.com/wordpress/google-analytics/';
35
- var $toc = '';
36
 
37
  /**
38
  * PHP4 Constructor
@@ -40,783 +65,811 @@ if ( is_admin() && ( !defined('DOING_AJAX') || !DOING_AJAX ) && !class_exists( '
40
  function GA_Admin() {
41
  $this->__construct();
42
  }
43
-
44
  /**
45
  * Constructur, load all required stuff.
46
  */
47
  function __construct() {
48
  $this->upgrade();
49
-
50
- $this->plugin_url = plugins_url( '', __FILE__ ).'/';
51
-
52
  // Register the settings page
53
- add_action( 'admin_menu', array(&$this, 'register_settings_page') );
54
 
55
  // Register the contextual help for the settings page
56
  // add_action( 'contextual_help', array(&$this, 'plugin_help'), 10, 3 );
57
-
58
  // Give the settings page a nice icon in Ozh's menu
59
- add_filter( 'ozh_adminmenu_icon', array(&$this, 'add_ozh_adminmenu_icon' ) );
60
 
61
  // Give the plugin a settings link in the plugin overview
62
- add_filter( 'plugin_action_links', array(&$this, 'add_action_link'), 10, 2 );
63
-
64
  // Print Scripts and Styles
65
- add_action('admin_print_scripts', array(&$this, 'config_page_scripts') );
66
- add_action('admin_print_styles', array(&$this, 'config_page_styles') );
67
-
68
  // Print stuff in the settings page's head
69
- add_action('admin_head', array(&$this, 'config_page_head') );
70
 
71
  // Drop a warning on each page of the admin when Google Analytics hasn't been configured
72
- add_action('admin_footer', array(&$this, 'warning') );
73
-
74
  // Save settings
75
  // TODO: replace with Options API
76
- add_action('admin_init', array(&$this, 'save_settings') );
77
 
78
- // Authenticate
79
- add_action('admin_init', array(&$this, 'authenticate') );
80
  }
81
-
82
  function config_page_head() {
 
 
 
 
 
 
 
 
 
 
 
 
83
  global $current_screen;
84
- if ( 'settings_page_'.$this->hook == $current_screen->id ) {
85
  $options = get_option( $this->optionname );
86
- if (!empty($options['uastring'])) {
87
  $uastring = $options['uastring'];
88
- } else {
89
- $uastring = '';
90
  }
91
-
92
- ?>
93
- <script type="text/javascript">
94
- function makeSublist(parent,child,childVal) {
95
- jQuery("body").append("<select style='display:none' id='"+parent+child+"'></select>");
96
- jQuery('#'+parent+child).html(jQuery("#"+child+" option"));
97
-
98
- var parentValue = jQuery('#'+parent).val();
99
- jQuery('#'+child).html(jQuery("#"+parent+child+" .sub_"+parentValue).clone());
100
-
101
- childVal = (typeof childVal == "undefined")? "" : childVal ;
102
- jQuery("#"+child).val(childVal).attr('selected','selected');
103
-
104
- jQuery('#'+parent).change(function(){
105
- var parentValue = jQuery('#'+parent).val();
106
- jQuery('#'+child).html(jQuery("#"+parent+child+" .sub_"+parentValue).clone());
107
- jQuery('#'+child).trigger("change");
108
- jQuery('#'+child).focus();
109
- });
110
- }
111
- jQuery(document).ready(function(){
112
- makeSublist('ga_account', 'uastring_sel', '<?php echo $uastring; ?>');
113
- jQuery('#position').change(function(){
114
- if (jQuery('#position').val() == 'header') {
115
- jQuery('#position_header').css("display","block");
116
- jQuery('#position_manual').css("display","none");
117
- } else {
118
- jQuery('#position_header').css("display","none");
119
- jQuery('#position_manual').css("display","block");
120
- }
121
- }).change();
122
- jQuery('#switchtomanual').change(function() {
123
- if ( jQuery('#switchtomanual').is(':checked') ) {
124
- jQuery('#uastring_manual').css('display','block');
125
- jQuery('#uastring_automatic').css('display','none');
126
- } else {
127
- jQuery('#uastring_manual').css('display','none');
128
- jQuery('#uastring_automatic').css('display','block');
129
- }
130
- }).change();
131
- jQuery('#trackoutbound').change(function(){
132
- if ( jQuery('#trackoutbound').is(':checked') ) {
133
- jQuery('#internallinktracking').css("display","block");
134
- jQuery('.internallinktracking').css("display","list-item");
135
- } else {
136
- jQuery('#internallinktracking').css("display","none");
137
- jQuery('.internallinktracking').css("display","none");
138
- }
139
- }).change();
140
- jQuery('#advancedsettings').change(function(){
141
- if ( jQuery('#advancedsettings').is(':checked') ) {
142
- jQuery('#advancedgasettings').css("display","block");
143
- jQuery('#customvarsettings').css("display","block");
144
- jQuery('.advancedgasettings').css("display","list-item");
145
- jQuery('.customvarsettings').css("display","list-item");
146
- } else {
147
- jQuery('#advancedgasettings').css("display","none");
148
- jQuery('#customvarsettings').css("display","none");
149
- jQuery('.advancedgasettings').css("display","none");
150
- jQuery('.customvarsettings').css("display","none");
151
- }
152
- }).change();
153
- jQuery('#extrase').change(function(){
154
- if ( jQuery('#extrase').is(':checked') ) {
155
- jQuery('#extrasebox').css("display","block");
156
- } else {
157
- jQuery('#extrasebox').css("display","none");
158
- }
159
- }).change();
160
- jQuery('#gajslocalhosting').change(function(){
161
- if ( jQuery('#gajslocalhosting').is(':checked') ) {
162
- jQuery('#localhostingbox').css("display","block");
163
- } else {
164
- jQuery('#localhostingbox').css("display","none");
165
- }
166
- }).change();
167
- jQuery('#customvarsettings :input').change(function() {
168
- if (jQuery("#customvarsettings :input:checked").size() > 5) {
169
- alert("<?php _e('The maximum number of allowed custom variables in Google Analytics is 5, please unselect one of the other custom variables before selecting this one.'); ?>");
170
- jQuery(this).attr('checked', false);
171
- };
172
- });
173
- jQuery('#uastring').change(function(){
174
- if ( jQuery('#switchtomanual').is(':checked') ) {
175
- if (!jQuery(this).val().match(/^UA-[\d-]+$/)) {
176
- alert("<?php _e('That\'s not a valid UA ID, please make sure it matches the expected pattern of: UA-XXXXXX-X, and that there are no spaces or other characters in the input field.'); ?>");
177
- jQuery(this).focus();
178
- }
179
  }
180
- });
181
  });
182
- </script>
183
- <link rel="shortcut icon" href="<?php echo $this->plugin_url; ?>images/favicon.ico" />
 
184
  <?php
185
  }
186
  }
187
-
188
- function plugin_help($contextual_help, $screen_id, $screen) {
189
- if ( $screen_id == 'settings_page_'.$this->hook ) {
190
 
191
- $contextual_help = '<h2>'.__('Having problems?').'</h2>'.
192
- '<p>'.sprintf( __("If you're having problems with this plugin, please refer to its <a href='%s'>FAQ page</a>."), 'http://yoast.com/wordpress/google-analytics/ga-wp-faq/' ).'</p>';
 
 
 
193
  }
194
  return $contextual_help;
195
  }
196
-
197
  function toc( $modules ) {
198
  $output = '<ul>';
199
- foreach ($modules as $module => $key) {
200
- $output .= '<li class="'.$key.'"><a href="#'.$key.'">'.$module.'</a></li>';
201
  }
202
  $output .= '</ul>';
203
  return $output;
204
  }
205
-
206
  function save_settings() {
207
  $options = get_option( $this->optionname );
208
-
209
- if ( isset($_REQUEST['reset']) && $_REQUEST['reset'] == "true" && isset($_REQUEST['plugin']) && $_REQUEST['plugin'] == 'google-analytics-for-wordpress') {
210
- $options = $this->set_defaults();
211
- $options['msg'] = "<div class=\"updated\"><p>".__('Google Analytics settings reset.')."</p></div>\n";
212
- } elseif ( isset($_POST['submit']) && isset($_POST['plugin']) && $_POST['plugin'] == 'google-analytics-for-wordpress') {
213
-
214
- if (!current_user_can('manage_options')) die(__('You cannot edit the Google Analytics for WordPress options.'));
215
- check_admin_referer('analyticspp-config');
216
-
217
- foreach (array('uastring', 'dlextensions', 'domainorurl','position','domain', 'customcode', 'ga_token', 'extraseurl', 'gajsurl', 'gfsubmiteventpv', 'trackprefix', 'ignore_userlevel', 'internallink', 'internallinklabel', 'primarycrossdomain', 'othercrossdomains') as $option_name) {
218
- if (isset($_POST[$option_name]))
219
  $options[$option_name] = $_POST[$option_name];
220
  else
221
  $options[$option_name] = '';
222
  }
223
-
224
- foreach (array('extrase', 'trackoutbound', 'admintracking', 'trackadsense', 'allowanchor', 'allowlinker', 'allowhash', 'rsslinktagging', 'advancedsettings', 'trackregistration', 'theme_updated', 'cv_loggedin', 'cv_authorname', 'cv_category', 'cv_all_categories', 'cv_tags', 'cv_year', 'cv_post_type', 'outboundpageview', 'downloadspageview', 'trackcrossdomain','gajslocalhosting', 'manual_uastring', 'taggfsubmit', 'wpec_tracking', 'shopp_tracking', 'anonymizeip', 'trackcommentform', 'debug','firebuglite') as $option_name) {
225
- if (isset($_POST[$option_name]) && $_POST[$option_name] == 'on')
226
  $options[$option_name] = true;
227
  else
228
  $options[$option_name] = false;
229
  }
230
 
231
- if (isset($_POST['manual_uastring']) && isset($_POST['uastring_man'])) {
232
  $options['uastring'] = $_POST['uastring_man'];
233
  }
234
-
235
  if ( $options['trackcrossdomain'] ) {
236
  if ( !$options['allowlinker'] )
237
  $options['allowlinker'] = true;
238
 
239
- if ( empty($options['primarycrossdomain']) ) {
240
- $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
241
  $options['primarycrossdomain'] = $origin["domain"];
242
  }
243
  }
244
-
245
- if ( function_exists('w3tc_pgcache_flush') )
246
- w3tc_pgcache_flush();
247
-
248
- if ( function_exists('w3tc_dbcache_flush') )
249
- w3tc_dbcache_flush();
250
-
251
- if ( function_exists('w3tc_minify_flush') )
252
- w3tc_minify_flush();
253
-
254
- if ( function_exists('w3tc_objectcache_flush') )
255
  w3tc_objectcache_flush();
256
-
257
- if ( function_exists('wp_cache_clear_cache') )
258
  wp_cache_clear_cache();
259
-
260
  $options['msg'] = "<div id=\"updatemessage\" class=\"updated fade\"><p>Google Analytics <strong>settings updated</strong>.</p></div>\n";
261
  $options['msg'] .= "<script type=\"text/javascript\">setTimeout(function(){jQuery('#updatemessage').hide('slow');}, 3000);</script>";
262
  }
263
- update_option($this->optionname, $options);
264
  }
265
-
266
  function save_button() {
267
- return '<div class="alignright"><input type="submit" class="button-primary" name="submit" value="'.__('Update Google Analytics Settings &raquo;').'" /></div><br class="clear"/>';
268
  }
269
-
270
  function upgrade() {
271
- $options = get_option($this->optionname);
272
- if ( isset($options['version']) && $options['version'] < '4.04' ) {
273
- if ( !isset($options['ignore_userlevel']) || $options['ignore_userlevel'] == '')
274
  $options['ignore_userlevel'] = 11;
275
  }
276
- if ( !isset($options['version']) || $options['version'] != GAWP_VERSION ) {
277
  $options['version'] = GAWP_VERSION;
278
  }
279
- update_option($this->optionname, $options);
280
  }
281
-
282
  function config_page() {
283
- $options = get_option($this->optionname);
284
- if ( isset($options['msg']) )
285
  echo $options['msg'];
286
  $options['msg'] = '';
287
- update_option($this->optionname, $options);
288
-
289
- if ( !isset($options['uastring']) )
290
  $options = $this->set_defaults();
291
  $modules = array();
292
-
 
 
293
  ?>
294
- <div class="wrap">
295
- <a href="http://yoast.com/"><div id="yoast-icon" style="background: url(<?php echo $this->plugin_url; ?>images/ga-icon-32x32.png) no-repeat;" class="icon32"><br /></div></a>
296
- <h2><?php _e("Google Analytics for WordPress Configuration") ?></h2>
297
- <div class="postbox-container" style="width:65%;">
298
- <div class="metabox-holder">
299
- <div class="meta-box-sortables">
300
- <form action="<?php echo $this->plugin_options_url(); ?>" method="post" id="analytics-conf">
301
- <input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>
302
- <?php
303
- wp_nonce_field('analyticspp-config');
304
-
305
- if ( empty($options['uastring']) && empty($options['ga_token']) ) {
306
- $query = $this->plugin_options_url().'&reauth=true';
307
- $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.';
308
- } else if(isset($options['ga_token']) && !empty($options['ga_token'])) {
309
- $token = $options['ga_token'];
310
-
311
- require_once plugin_dir_path(__FILE__).'xmlparser.php';
312
- if (file_exists(ABSPATH.'wp-includes/class-http.php'))
313
- require_once(ABSPATH.'wp-includes/class-http.php');
314
-
315
- if (!isset($options['ga_api_responses'][$token])) {
316
- $options['ga_api_responses'] = array();
317
-
318
- if ( $oauth = $options['gawp_oauth'] ) {
319
- if ( isset( $oauth['params']['oauth_token'], $oauth['params']['oauth_token_secret'] ) ) {
320
- $options['gawp_oauth']['access_token'] = array(
321
- 'oauth_token' => base64_decode( $oauth['params']['oauth_token'] ),
322
- 'oauth_token_secret' => base64_decode( $oauth['params']['oauth_token_secret'] )
323
- );
324
- unset( $options['gawp_oauth']['params'] );
325
- update_option( $this->optionname, $options );
326
- }
327
- }
328
-
329
- $args = array(
330
- 'scope' => 'https://www.google.com/analytics/feeds/',
331
- 'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'
332
- );
333
- $access_token = $options['gawp_oauth']['access_token'];
334
- $gdata = new WP_Gdata( $args, $access_token['oauth_token'], $access_token['oauth_token_secret'] );
335
-
336
-
337
- $response = $gdata->get( 'https://www.google.com/analytics/feeds/accounts/default' );
338
- $http_code = wp_remote_retrieve_response_code( $response );
339
- $response = wp_remote_retrieve_body( $response );
340
-
341
-
342
- if($http_code==200)
343
- {
344
- $options['ga_api_responses'][$token] = array(
345
- 'response'=>array('code'=>$http_code),
346
- 'body'=>$response
347
- );
348
- $options['ga_token'] = $token;
349
- update_option('Yoast_Google_Analytics', $options);
350
- }
351
- }
352
-
353
- if (is_array($options['ga_api_responses'][$token]) && $options['ga_api_responses'][$token]['response']['code'] == 200) {
354
- $arr = yoast_xml2array($options['ga_api_responses'][$token]['body']);
355
-
356
- $ga_accounts = array();
357
- if (isset($arr['feed']['entry'][0])) {
358
- foreach ($arr['feed']['entry'] as $site) {
359
- $ua = $site['dxp:property']['3_attr']['value'];
360
- $account = $site['dxp:property']['1_attr']['value'];
361
- if (!isset($ga_accounts[$account]) || !is_array($ga_accounts[$account]))
362
- $ga_accounts[$account] = array();
363
- $ga_accounts[$account][$site['title']] = $ua;
364
- }
365
- } else {
366
- $ua = $arr['feed']['entry']['dxp:property']['3_attr']['value'];
367
- $account = $arr['feed']['entry']['dxp:property']['1_attr']['value'];
368
- $title = $arr['feed']['entry']['title'];
369
- if (!isset($ga_accounts[$account]) || !is_array($ga_accounts[$account]))
370
- $ga_accounts[$account] = array();
371
- $ga_accounts[$account][$title] = $ua;
372
- }
373
-
374
- $select1 = '<select style="width:150px;" name="ga_account" id="ga_account">';
375
- $select1 .= "\t<option></option>\n";
376
- $select2 = '<select style="width:150px;" name="uastring" id="uastring_sel">';
377
- $i = 1;
378
- $currentua = '';
379
- if (!empty($options['uastring']))
380
- $currentua = $options['uastring'];
381
-
382
- foreach($ga_accounts as $account => $val) {
383
- $accountsel = false;
384
- foreach ($val as $title => $ua) {
385
- $sel = selected($ua, $currentua, false);
386
- if (!empty($sel)) {
387
- $accountsel = true;
388
- }
389
- $select2 .= "\t".'<option class="sub_'.$i.'" '.$sel.' value="'.$ua.'">'.$title.' - '.$ua.'</option>'."\n";
390
- }
391
- $select1 .= "\t".'<option '.selected($accountsel,true,false).' value="'.$i.'">'.$account.'</option>'."\n";
392
- $i++;
393
- }
394
- $select1 .= '</select>';
395
- $select2 .= '</select>';
396
-
397
- $line = '<input type="hidden" name="ga_token" value="'.$token.'"/>';
398
- $line .= 'Please select the correct Analytics profile to track:<br/>';
399
- $line .= '<table class="form_table">';
400
- $line .= '<tr><th width="15%">Account:</th><td width="85%">'.$select1.'</td></tr>';
401
- $line .= '<tr><th>Profile:</th><td>'.$select2.'</td></tr>';
402
- $line .= '</table>';
403
-
404
- $try = 1;
405
- if (isset($_GET['try']))
406
- $try = $_GET['try'] + 1;
407
-
408
- if ($i == 1 && $try < 4 && isset($_GET['token'])) {
409
- $line .= '<script type="text/javascript">
410
- window.location="'.$this->plugin_options_url().'&switchua=1&token='.$token.'&try='.$try.'";
 
 
 
 
 
411
  </script>';
412
- }
413
- $line .= 'Please note that if you have several profiles of the same website, it doesn\'t matter which profile you select, and in fact another profile might show as selected later. You can check whether they\'re profiles for the same site by checking if they have the same UA code. If that\'s true, tracking will be correct.<br/>';
414
- $line .= '<br/>Refresh this listing or switch to another account: ';
415
- } else {
416
- $line = 'Unfortunately, an error occurred while connecting to Google, please try again:';
417
- }
418
-
419
- $query = $this->plugin_options_url().'&reauth=true';
420
- $line .= '<a class="button" href="'.$query.'">Re-authenticate with Google</a>';
421
- } else {
422
- $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>';
423
- }
424
- $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>';
425
- $rows = array();
426
- $content = '';
427
- $rows[] = array(
428
- 'id' => 'uastring',
429
- 'label' => 'Analytics Profile',
430
- 'desc' => '<input type="checkbox" name="manual_uastring" '.checked($options['manual_uastring'], true, false).' id="switchtomanual"/> <label for="switchtomanual">Manually enter your UA code</label>',
431
- 'content' => $line
432
- );
433
- $temp_content = $this->select('position', array('header' => 'In the header (default)', 'manual' => 'Insert manually'));
434
- if ($options['theme_updated'] && $options['position'] == 'manual') {
435
- $temp_content .= '<input type="hidden" name="theme_updated" value="off"/>';
436
- 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>';
437
- remove_action('admin_footer', array(&$this,'theme_switch_warning'));
438
- }
439
- $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>';
440
- $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>';
441
-
442
- $rows[] = array(
443
- 'id' => 'position',
444
- 'label' => 'Where should the tracking code be placed',
445
- 'desc' => $desc,
446
- 'content' => $temp_content,
447
- );
448
- $rows[] = array(
449
- 'id' => 'trackoutbound',
450
- 'label' => 'Track outbound clicks &amp; downloads',
451
- 'desc' => 'Clicks &amp; downloads will be tracked as events, you can find these under Content &raquo; Event Tracking in your Google Analytics reports.',
452
- 'content' => $this->checkbox('trackoutbound'),
453
- );
454
- $rows[] = array(
455
- 'id' => 'advancedsettings',
456
- 'label' => 'Show advanced settings',
457
- 'desc' => 'Only adviced for advanced users who know their way around Google Analytics',
458
- 'content' => $this->checkbox('advancedsettings'),
459
- );
460
- $this->postbox('gasettings','Google Analytics Settings',$this->form_table($rows).$this->save_button());
461
-
462
- $rows = array();
463
- $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>';
464
- $rows[] = array(
465
- 'id' => 'cv_loggedin',
466
- 'label' => 'Logged in Users',
467
- '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.',
468
- 'content' => $this->checkbox('cv_loggedin'),
469
- );
470
- $rows[] = array(
471
- 'id' => 'cv_post_type',
472
- 'label' => 'Post type',
473
- 'desc' => 'Allows you to see pageviews per post type, especially useful if you use multiple custom post types.',
474
- 'content' => $this->checkbox('cv_post_type'),
475
- );
476
- $rows[] = array(
477
- 'id' => 'cv_authorname',
478
- 'label' => 'Author Name',
479
- 'desc' => 'Allows you to see pageviews per author.',
480
- 'content' => $this->checkbox('cv_authorname'),
481
- );
482
- $rows[] = array(
483
- 'id' => 'cv_tags',
484
- 'label' => 'Tags',
485
- 'desc' => 'Allows you to see pageviews per tags using advanced segments.',
486
- 'content' => $this->checkbox('cv_tags'),
487
- );
488
- $rows[] = array(
489
- 'id' => 'cv_year',
490
- 'label' => 'Publication year',
491
- 'desc' => 'Allows you to see pageviews per year of publication, showing you if your old posts still get traffic.',
492
- 'content' => $this->checkbox('cv_year'),
493
- );
494
- $rows[] = array(
495
- 'id' => 'cv_category',
496
- 'label' => 'Single Category',
497
- 'desc' => 'Allows you to see pageviews per category, works best when each post is in only one category.',
498
- 'content' => $this->checkbox('cv_category'),
499
- );
500
- $rows[] = array(
501
- 'id' => 'cv_all_categories',
502
- 'label' => 'All Categories',
503
- 'desc' => 'Allows you to see pageviews per category using advanced segments, should be used when you use multiple categories per post.',
504
- 'content' => $this->checkbox('cv_all_categories'),
505
- );
506
-
507
- $modules['Custom Variables'] = 'customvarsettings';
508
- $this->postbox('customvarsettings','Custom Variables Settings',$pre_content.$this->form_table($rows).$this->save_button());
509
-
510
- $rows = array();
511
- $rows[] = array(
512
- 'id' => 'ignore_userlevel',
513
- 'label' => 'Ignore users',
514
- 'desc' => 'Users of the role you select and higher will be ignored, so if you select Editor, all Editors and Administrators will be ignored.',
515
- 'content' => $this->select('ignore_userlevel', array(
516
- '11' => 'Ignore no-one',
517
- '8' => 'Administrator',
518
- '5' => 'Editor',
519
- '2' => 'Author',
520
- '1' => 'Contributor',
521
- '0' => 'Subscriber (ignores all logged in users)',
522
- )),
523
- );
524
- $rows[] = array(
525
- 'id' => 'outboundpageview',
526
- 'label' => 'Track outbound clicks as pageviews',
527
- '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 skew your statistics, but <em>is</em> sometimes necessary when you need to set outbound clicks as goals.',
528
- 'content' => $this->checkbox('outboundpageview'),
529
- );
530
- $rows[] = array(
531
- 'id' => 'downloadspageview',
532
- 'label' => 'Track downloads as pageviews',
533
- 'desc' => 'Not recommended, as this would skew your statistics, but it does make it possible to track downloads as goals.',
534
- 'content' => $this->checkbox('downloadspageview'),
535
- );
536
- $rows[] = array(
537
- 'id' => 'dlextensions',
538
- 'label' => 'Extensions of files to track as downloads',
539
- 'content' => $this->textinput('dlextensions'),
540
- );
541
- if ( $options['outboundpageview'] ) {
542
- $rows[] = array(
543
- 'id' => 'trackprefix',
544
- 'label' => 'Prefix to use in Analytics before the tracked pageviews',
545
- '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.',
546
- 'content' => $this->textinput('trackprefix'),
547
- );
548
- }
549
- $rows[] = array(
550
- 'id' => 'domainorurl',
551
- 'label' => 'Track full URL of outbound clicks or just the domain',
552
- 'content' => $this->select('domainorurl', array(
553
- 'domain' => 'Just the domain',
554
- 'url' => 'Track the complete URL',
555
- )
556
- ),
557
- );
558
- $rows[] = array(
559
- 'id' => 'domain',
560
- 'label' => 'Subdomain Tracking',
561
- 'desc' => 'This allows you to set the domain that\'s set by <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setDomainName"><code>setDomainName</code></a> for tracking subdomains, if empty this will not be set.',
562
- 'content' => $this->textinput('domain'),
563
- );
564
- $rows[] = array(
565
- 'id' => 'trackcrossdomain',
566
- 'label' => 'Enable Cross Domain Tracking',
567
- 'desc' => 'This allows you to enable <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html">Cross-Domain Tracking</a> for this site. When endabled <code>_setAllowLinker:</code> will be enabled if it is not already.',
568
- 'content' => $this->checkbox('trackcrossdomain'),
569
- );
570
- $rows[] = array(
571
- 'id' => 'primarycrossdomain',
572
- 'label' => 'Cross-Domain Tracking, Primary Domain',
573
- 'desc' => 'Set the primary domain used in <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setDomainName"><code>setDomainName</code></a> for cross domain tracking (eg. <code>example-petstore.com</code> ), if empty this will default to your configured Home URL.',
574
- 'content' => $this->textinput('primarycrossdomain'),
575
- );
576
- $rows[] = array(
577
- 'id' => 'othercrossdomains',
578
- 'label' => 'Cross-Domain Tracking, Other Domains',
579
- 'desc' => 'All links to these domains will have the <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#multipleDomains"><code>_link</code></a> code automatically attached. Separate domains/sub-domains with commas (eg. <code>dogs.example-petstore.com, cats.example-petstore.com</code>)',
580
- 'content' => $this->textinput('othercrossdomains'),
581
- );
582
- $rows[] = array(
583
- 'id' => 'customcode',
584
- 'label' => 'Custom Code',
585
- 'desc' => 'Not for the average user: this allows you to add a line of code, to be added before the <code>trackPageview</code> call.',
586
- 'content' => $this->textinput('customcode'),
587
- );
588
- $rows[] = array(
589
- 'id' => 'trackadsense',
590
- 'label' => 'Track AdSense',
591
- '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>.',
592
- 'content' => $this->checkbox('trackadsense'),
593
- );
594
- $rows[] = array(
595
- 'id' => 'gajslocalhosting',
596
- 'label' => 'Host ga.js locally',
597
- 'content' => $this->checkbox('gajslocalhosting').'<div id="localhostingbox">
 
 
 
 
 
 
598
  You have to provide a URL to your ga.js file:
599
- <input type="text" name="gajsurl" size="30" value="'.$options['gajsurl'].'"/>
600
  </div>',
601
- 'desc' => 'For some reasons you might want to use a locally hosted ga.js file, or another ga.js file, check the box and then please enter the full URL including http here.'
602
- );
603
- $rows[] = array(
604
- 'id' => 'extrase',
605
- 'label' => 'Track extra Search Engines',
606
- 'content' => $this->checkbox('extrase').'<div id="extrasebox">
607
  You can provide a custom URL to the extra search engines file if you want:
608
- <input type="text" name="extraseurl" size="30" value="'.$options['extraseurl'].'"/>
609
  </div>',
610
- );
611
- $rows[] = array(
612
- 'id' => 'rsslinktagging',
613
- 'label' => 'Tag links in RSS feed with campaign variables',
614
- '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.',
615
- 'content' => $this->checkbox('rsslinktagging'),
616
- );
617
- $rows[] = array(
618
- 'id' => 'trackregistration',
619
- 'label' => 'Add tracking to the login and registration forms',
620
- 'content' => $this->checkbox('trackregistration'),
621
- );
622
- $rows[] = array(
623
- 'id' => 'trackcommentform',
624
- 'label' => 'Add tracking to the comment forms',
625
- 'content' => $this->checkbox('trackcommentform'),
626
- );
627
- $rows[] = array(
628
- 'id' => 'allowanchor',
629
- 'label' => 'Use # instead of ? for Campaign tracking',
630
- 'desc' => 'This adds a <code><a href="http://code.google.com/apis/analytics/docs/gaJSApiCampaignTracking.html#_gat.GA_Tracker_._setAllowAnchor">_setAllowAnchor</a></code> call to your tracking code, and makes RSS link tagging use a # as well.',
631
- 'content' => $this->checkbox('allowanchor'),
632
- );
633
- $rows[] = array(
634
- 'id' => 'allowlinker',
635
- 'label' => 'Add <code>_setAllowLinker</code>',
636
- 'desc' => 'This adds a <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowLinker">_setAllowLinker</a></code> call to your tracking code, allowing you to use <code>_link</code> and related functions.',
637
- 'content' => $this->checkbox('allowlinker'),
638
- );
639
- $rows[] = array(
640
- 'id' => 'allowhash',
641
- 'label' => 'Set <code>_setAllowHash</code> to false',
642
- 'desc' => 'This sets <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowHash">_setAllowHash</a></code> to false, allowing you to track subdomains etc.',
643
- 'content' => $this->checkbox('allowhash'),
644
- );
645
- $rows[] = array(
646
- 'id' => 'anonymizeip',
647
- 'label' => 'Anonymize IP\'s',
648
- 'desc' => 'This adds <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApi_gat.html#_gat._anonymizeIp">_anonymizeIp</a></code>, telling Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage.',
649
- 'content' => $this->checkbox('anonymizeip'),
650
- );
651
- $modules['Advanced Settings'] = 'advancedgasettings';
652
- $this->postbox('advancedgasettings','Advanced Settings',$this->form_table($rows).$this->save_button());
653
-
654
- $rows = array();
655
- $rows[] = array(
656
- 'id' => 'internallink',
657
- 'label' => 'Internal links to track as outbound',
658
- 'desc' => 'If you want to track all internal links that begin with <code>/out/</code>, enter <code>/out/</code> in the box above. If you have multiple prefixes you can separate them with comma\'s: <code>/out/,/recommends/</code>',
659
- 'content' => $this->textinput('internallink'),
660
- );
661
- $rows[] = array(
662
- 'id' => 'internallinklabel',
663
- 'label' => 'Label to use',
664
- 'desc' => 'The label to use for these links, this will be added to where the click came from, so if the label is "aff", the label for a click from the content of an article becomes "outbound-article-aff".',
665
- 'content' => $this->textinput('internallinklabel'),
666
- );
667
- $modules['Internal Link Tracking'] = 'internallinktracking';
668
- $this->postbox('internallinktracking','Internal Links to Track as Outbound',$this->form_table($rows).$this->save_button());
669
-
670
- /* if (class_exists('RGForms') && GFCommon::$version >= '1.3.11') {
671
- $pre_content = 'This plugin can automatically tag your Gravity Forms to track form submissions as either events or pageviews';
672
- $rows = array();
673
- $rows[] = array(
674
- 'id' => 'taggfsubmit',
675
- 'label' => 'Tag Gravity Forms',
676
- 'content' => $this->checkbox('taggfsubmit'),
677
- );
678
- $rows[] = array(
679
- 'id' => 'gfsubmiteventpv',
680
- 'label' => 'Tag Gravity Forms as',
681
- 'content' => '<select name="gfsubmiteventpv">
682
- <option value="events" '.selected($options['gfsubmiteventpv'],'events',false).'>Events</option>
683
- <option value="pageviews" '.selected($options['gfsubmiteventpv'],'pageviews',false).'>Pageviews</option>
684
- </select>',
685
- );
686
- $this->postbox('gravityforms','Gravity Forms Settings',$pre_content.$this->form_table($rows).$this->save_button());
687
- $modules['Gravity Forms'] = 'gravityforms';
688
- }
689
- */
690
- if ( defined('WPSC_VERSION') ) {
691
- $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.';
692
- $rows = array();
693
- $rows[] = array(
694
- 'id' => 'wpec_tracking',
695
- 'label' => 'Enable transaction tracking',
696
- 'content' => $this->checkbox('wpec_tracking'),
697
- );
698
- $this->postbox('wpecommerce','WordPress e-Commerce Settings',$pre_content.$this->form_table($rows).$this->save_button());
699
- $modules['WordPress e-Commerce'] = 'wpecommerce';
700
- }
701
-
702
- global $Shopp;
703
- if ( isset($Shopp) ) {
704
- $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.';
705
- $rows = array();
706
- $rows[] = array(
707
- 'id' => 'shopp_tracking',
708
- 'label' => 'Enable transaction tracking',
709
- 'content' => $this->checkbox('shopp_tracking'),
710
- );
711
- $this->postbox('shoppecommerce','Shopp e-Commerce Settings',$pre_content.$this->form_table($rows).$this->save_button());
712
- $modules['Shopp'] = 'shoppecommerce';
713
- }
714
- $pre_content = '<p>If you want to confirm that tracking on your blog is working as it should, enable this option and check the console in <a href="http://getfirebug.com/">Firebug</a> (for Firefox), <a href="http://getfirebug.com/firebuglite">Firebug Lite</a> (for other browsers) or Chrome &amp; Safari\'s Web Inspector. Be absolutely sure to disable debugging afterwards, as it is slower than normal tracking.</p><p><strong>Note</strong>: the debugging and firebug scripts are only loaded for admins.</p>';
715
- $rows = array();
716
- $rows[] = array(
717
- 'id' => 'debug',
718
- 'label' => 'Enable debug mode',
719
- 'content' => $this->checkbox('debug'),
720
- );
721
- $rows[] = array(
722
- 'id' => 'firebuglite',
723
- 'label' => 'Enable Firebug Lite',
724
- 'content' => $this->checkbox('firebuglite'),
725
- );
726
- $this->postbox('debugmode','Debug Mode',$pre_content.$this->form_table($rows).$this->save_button());
727
- $modules['Debug Mode'] = 'debugmode';
728
- ?>
729
- </form>
730
- <form action="<?php echo $this->plugin_options_url(); ?>" method="post" onsubmit="javascript:return(confirm('Do you really want to reset all settings?'));">
731
- <input type="hidden" name="reset" value="true"/>
732
- <input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>
733
- <div class="submit"><input type="submit" value="Reset All Settings &raquo;" /></div>
734
- </form>
735
- </div>
736
- </div>
 
 
737
  </div>
738
  <div class="postbox-container side" style="width:20%;">
739
- <div class="metabox-holder">
740
  <div class="meta-box-sortables">
741
  <?php
742
- if ( count($modules) > 0 )
743
- $this->postbox('toc','List of Available Modules',$this->toc($modules));
744
- $this->postbox('donate','<strong class="red">'.__( 'Help Spread the Word!' ).'</strong>','<p><strong>'.__( 'Want to help make this plugin even better? All donations are used to improve this plugin, so donate $20, $50 or $100 now!' ).'</strong></p><form style="width:160px;margin:0 auto;" action="https://www.paypal.com/cgi-bin/webscr" method="post">
745
- <input type="hidden" name="cmd" value="_s-xclick">
746
- <input type="hidden" name="hosted_button_id" value="FW9FK4EBZ9FVJ">
747
- <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit">
748
- <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
749
- </form>'
750
- .'<p>'.__('Or you could:').'</p>'
751
- .'<ul>'
752
- .'<li><a href="http://wordpress.org/extend/plugins/google-analytics-for-wordpress/">'.__('Rate the plugin 5★ on WordPress.org').'</a></li>'
753
- .'<li><a href="http://wordpress.org/tags/google-analytics-for-wordpress">'.__('Help out other users in the forums').'</a></li>'
754
- .'<li>'.sprintf( __('Blog about it & link to the %1$splugin page%2$s'), '<a href="http://yoast.com/wordpress/google-analytics/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=link&utm_campaign=wpgaplugin">', '</a>').'</li>');
755
- $this->postbox('sitereview','<strong>'.__('Want to Improve your Site?').'</strong>','<p>'.sprintf( __('If you want to improve your site, but don\'t know where to start, you should order a %1$swebsite review%2$s from Yoast!'), '<a href="http://yoast.com/hire-me/website-review/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=link&utm_campaign=wpgaplugin">', '</a>').'</p>'.'<p>'.__('The results of this review contain a full report of improvements for your site, encompassing my findings for improvements in different key areas such as SEO to Usability to Site Speed & more.').'</p>'.'<p><a class="button-secondary" href="http://yoast.com/hire-me/website-review/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=button&utm_campaign=wpgaplugin">'.__('Click here to read more &raquo;').'</a></p>');
756
-
757
- $this->plugin_support();
758
- $this->news();
759
  ?>
760
  </div>
761
  <br/><br/><br/>
762
  </div>
763
  </div>
764
- </div>
765
- <?php
766
- }
767
-
768
  function set_defaults() {
769
  $options = array(
770
- 'advancedsettings' => false,
771
- 'allowanchor' => false,
772
- 'allowhash' => false,
773
- 'allowlinker' => false,
774
- 'anonymizeip' => false,
775
- 'customcode' => '',
776
- 'cv_loggedin' => false,
777
- 'cv_authorname' => false,
778
- 'cv_category' => false,
779
- 'cv_all_categories' => false,
780
- 'cv_tags' => false,
781
- 'cv_year' => false,
782
- 'cv_post_type' => false,
783
- 'debug' => false,
784
- 'dlextensions' => 'doc,exe,js,pdf,ppt,tgz,zip,xls',
785
- 'domain' => '',
786
- 'domainorurl' => 'domain',
787
- 'extrase' => false,
788
- 'extraseurl' => '',
789
- 'firebuglite' => false,
790
- 'ga_token' => '',
791
- 'ga_api_responses' => array(),
792
- 'gajslocalhosting' => false,
793
- 'gajsurl' => '',
794
- 'ignore_userlevel' => '11',
795
- 'internallink' => false,
796
- 'internallinklabel' => '',
797
- 'outboundpageview' => false,
798
- 'downloadspageview' => false,
799
- 'othercrossdomains' => '',
800
- 'position' => 'footer',
801
- 'primarycrossdomain' => '',
802
- 'theme_updated' => false,
803
- 'trackcommentform' => true,
804
- 'trackcrossdomain' => false,
805
- 'trackadsense' => false,
806
- 'trackoutbound' => true,
807
- 'trackregistration' => false,
808
- 'rsslinktagging' => true,
809
- 'uastring' => '',
810
- 'version' => GAWP_VERSION,
811
  );
812
- update_option($this->optionname,$options);
813
  return $options;
814
  }
815
-
816
  function warning() {
817
- $options = get_option($this->optionname);
818
- if (!isset($options['uastring']) || empty($options['uastring'])) {
819
- 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>";
820
  }
821
  } // end warning()
822
 
@@ -825,9 +878,9 @@ if ( is_admin() && ( !defined('DOING_AJAX') || !DOING_AJAX ) && !class_exists( '
825
  if ( isset( $_REQUEST['oauth_token'] ) ) {
826
  $o = get_option( $this->optionname );
827
  if ( isset( $o['gawp_oauth']['oauth_token'] ) && $o['gawp_oauth']['oauth_token'] == $_REQUEST['oauth_token'] ) {
828
- $gdata = new WP_GData(
829
- array(
830
- 'scope' => 'https://www.google.com/analytics/feeds/',
831
  'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'
832
  ),
833
  $o['gawp_oauth']['oauth_token'],
@@ -846,10 +899,10 @@ if ( is_admin() && ( !defined('DOING_AJAX') || !DOING_AJAX ) && !class_exists( '
846
  exit;
847
  }
848
 
849
- if ( ! empty( $_GET['reauth'] ) ) {
850
- $gdata = new WP_GData(
851
- array(
852
- 'scope' => 'https://www.google.com/analytics/feeds/',
853
  'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'
854
  )
855
  );
@@ -859,7 +912,7 @@ if ( is_admin() && ( !defined('DOING_AJAX') || !DOING_AJAX ) && !class_exists( '
859
  $options = get_option( $this->optionname );
860
  unset( $options['ga_token'] );
861
  unset( $options['gawp_oauth']['access_token'] );
862
- $options['gawp_oauth']['oauth_token'] = $request_token['oauth_token'];
863
  $options['gawp_oauth']['oauth_token_secret'] = $request_token['oauth_token_secret'];
864
  update_option( $this->optionname, $options );
865
 
@@ -877,35 +930,36 @@ if ( is_admin() && ( !defined('DOING_AJAX') || !DOING_AJAX ) && !class_exists( '
877
  /**
878
  * Code that actually inserts stuff into pages.
879
  */
880
- if ( ! class_exists( 'GA_Filter' ) ) {
881
  class GA_Filter {
882
 
883
  /**
884
  * Cleans the variable to make it ready for storing in Google Analytics
885
  */
886
- function ga_str_clean($val) {
887
- return remove_accents(str_replace('---','-',str_replace(' ','-',strtolower(html_entity_decode($val)))));
888
  }
 
889
  /*
890
- * Insert the tracking code into the page
891
- */
892
- function spool_analytics() {
893
  global $wp_query;
894
  // echo '<!--'.print_r($wp_query,1).'-->';
895
 
896
- $options = get_option('Yoast_Google_Analytics');
897
 
898
- if ( !isset($options['uastring']) || $options['uastring'] == '' ) {
899
- if ( current_user_can('manage_options') )
900
  echo "<!-- Google Analytics tracking code not shown because yo haven't chosen a Google Analytics account yet. -->\n";
901
  return;
902
  }
903
-
904
  /**
905
  * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
906
  */
907
  $customvarslot = 1;
908
- if ( yoast_ga_do_tracking() && !is_preview() ) {
909
  $push = array();
910
 
911
  if ( $options['allowanchor'] )
@@ -913,45 +967,45 @@ if ( ! class_exists( 'GA_Filter' ) ) {
913
 
914
  if ( $options['allowlinker'] )
915
  $push[] = "'_setAllowLinker',true";
916
-
917
  if ( $options['anonymizeip'] )
918
  $push[] = "'_gat._anonymizeIp'";
919
-
920
- if ( isset($options['domain']) && $options['domain'] != "" )
921
- $push[] = "'_setDomainName','".$options['domain']."'";
922
 
923
- if ( isset($options['trackcrossdomain']) && $options['trackcrossdomain'] )
924
- $push[] = "'_setDomainName','".$options['primarycrossdomain']."'";
 
 
 
925
 
926
- if ( isset($options['allowhash']) && $options['allowhash'] )
927
  $push[] = "'_setAllowHash',false";
928
 
929
  if ( $options['cv_loggedin'] ) {
930
  $current_user = wp_get_current_user();
931
  if ( $current_user && $current_user->ID != 0 )
932
- $push[] = "'_setCustomVar',$customvarslot,'logged-in','".$current_user->roles[0]."',1";
933
  // 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.
934
  $customvarslot++;
935
- }
936
 
937
- if ( function_exists('is_post_type_archive') && is_post_type_archive() ) {
938
  if ( $options['cv_post_type'] ) {
939
  $post_type = get_post_type();
940
  if ( $post_type ) {
941
- $push[] = "'_setCustomVar',".$customvarslot.",'post_type','".$post_type."',3";
942
- $customvarslot++;
943
  }
944
  }
945
  } else if ( is_singular() && !is_home() ) {
946
  if ( $options['cv_post_type'] ) {
947
  $post_type = get_post_type();
948
  if ( $post_type ) {
949
- $push[] = "'_setCustomVar',".$customvarslot.",'post_type','".$post_type."',3";
950
- $customvarslot++;
951
  }
952
  }
953
  if ( $options['cv_authorname'] ) {
954
- $push[] = "'_setCustomVar',$customvarslot,'author','".GA_Filter::ga_str_clean(get_the_author_meta('display_name',$wp_query->post->post_author))."',3";
955
  $customvarslot++;
956
  }
957
  if ( $options['cv_tags'] ) {
@@ -959,323 +1013,326 @@ if ( ! class_exists( 'GA_Filter' ) ) {
959
  if ( get_the_tags() ) {
960
  $tagsstr = '';
961
  foreach ( get_the_tags() as $tag ) {
962
- if ($i > 0)
963
  $tagsstr .= ' ';
964
  $tagsstr .= $tag->slug;
965
  $i++;
966
  }
967
  // Max 64 chars for value and label combined, hence 64 - 4
968
- $tagsstr = substr($tagsstr, 0, 60);
969
- $push[] = "'_setCustomVar',$customvarslot,'tags','".$tagsstr."',3";
970
  }
971
  $customvarslot++;
972
  }
973
  if ( is_singular() ) {
974
  if ( $options['cv_year'] ) {
975
- $push[] = "'_setCustomVar',$customvarslot,'year','".get_the_time('Y')."',3";
976
  $customvarslot++;
977
  }
978
  if ( $options['cv_category'] && is_single() ) {
979
  $cats = get_the_category();
980
  if ( is_array( $cats ) && isset( $cats[0] ) )
981
- $push[] = "'_setCustomVar',$customvarslot,'category','".$cats[0]->slug."',3";
982
  $customvarslot++;
983
  }
984
  if ( $options['cv_all_categories'] && is_single() ) {
985
- $i = 0;
986
  $catsstr = '';
987
  foreach ( (array) get_the_category() as $cat ) {
988
- if ($i > 0)
989
  $catsstr .= ' ';
990
  $catsstr .= $cat->slug;
991
  $i++;
992
  }
993
  // Max 64 chars for value and label combined, hence 64 - 10
994
- $catsstr = substr($catsstr, 0, 54);
995
- $push[] = "'_setCustomVar',$customvarslot,'categories','".$catsstr."',3";
996
  $customvarslot++;
997
  }
998
  }
999
- }
1000
 
1001
- $push = apply_filters('yoast-ga-custom-vars',$push, $customvarslot);
 
 
1002
 
1003
- $push = apply_filters('yoast-ga-push-before-pageview',$push);
1004
-
1005
  if ( is_404() ) {
1006
  $push[] = "'_trackPageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
1007
- } else if ($wp_query->is_search) {
1008
- $pushstr = "'_trackPageview','".get_bloginfo('url')."/?s=";
1009
- if ($wp_query->found_posts == 0) {
1010
- $push[] = $pushstr."no-results:".rawurlencode($wp_query->query_vars['s'])."&cat=no-results'";
1011
- } else if ($wp_query->found_posts == 1) {
1012
- $push[] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=1-result'";
1013
- } else if ($wp_query->found_posts > 1 && $wp_query->found_posts < 6) {
1014
- $push[] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=2-5-results'";
1015
  } else {
1016
- $push[] = $pushstr.rawurlencode($wp_query->query_vars['s'])."&cat=plus-5-results'";
1017
  }
1018
  } else {
1019
  $push[] = "'_trackPageview'";
1020
  }
1021
-
1022
- $push = apply_filters('yoast-ga-push-after-pageview',$push);
1023
 
1024
- if ( defined('WPSC_VERSION') && $options['wpec_tracking'] )
1025
- $push = GA_Filter::wpec_transaction_tracking($push);
1026
-
1027
- if ($options['shopp_tracking']) {
 
 
1028
  global $Shopp;
1029
- if ( isset($Shopp) )
1030
- $push = GA_Filter::shopp_transaction_tracking($push);
1031
  }
1032
-
1033
  $pushstr = "";
1034
- foreach ($push as $key) {
1035
- if (!empty($pushstr))
1036
  $pushstr .= ",";
1037
 
1038
- $pushstr .= "[".$key."]";
1039
  }
1040
 
1041
- if ( current_user_can('manage_options') && $options['firebuglite'] && $options['debug'] )
1042
  echo '<script src="https://getfirebug.com/firebug-lite.js" type="text/javascript"></script>';
1043
  ?>
1044
-
1045
- <script type="text/javascript">//<![CDATA[
1046
- // Google Analytics for WordPress by Yoast v<?php echo GAWP_VERSION; ?> | http://yoast.com/wordpress/google-analytics/
1047
- var _gaq = _gaq || [];
1048
- _gaq.push(['_setAccount','<?php echo trim($options["uastring"]); ?>']);
1049
- <?php
1050
- if ( $options["extrase"] ) {
1051
- if ( !empty($options["extraseurl"]) ) {
1052
- $url = $options["extraseurl"];
1053
- } else {
1054
- $url = plugins_url( 'custom_se_async.js', __FILE__ );
1055
- }
1056
- echo '</script><script src="'.$url.'" type="text/javascript"></script>'."\n".'<script type="text/javascript">';
1057
- }
1058
 
1059
- if ( $options['customcode'] && trim( $options['customcode'] ) != '' )
1060
- echo "\t". stripslashes( $options['customcode'] ) ."\n";
1061
- ?>
1062
- _gaq.push(<?php echo $pushstr; ?>);
1063
- (function() {
1064
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
1065
- ga.src = <?php
1066
- if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1067
- echo "'".$options['gajsurl']."';";
1068
- } else {
1069
- $script = 'ga.js';
1070
- if ( current_user_can('manage_options') && $options['debug'] )
1071
- $script = 'u/ga_debug.js';
1072
- echo "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/".$script."';";
1073
- }
1074
- ?>
1075
 
1076
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
1077
- })();
1078
- //]]></script>
1079
- <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1080
  } else if ( $options["uastring"] != "" ) {
1081
- echo "<!-- Google Analytics tracking code not shown because users over level ".$options["ignore_userlevel"]." are ignored -->\n";
1082
- }
1083
  }
1084
 
1085
  /*
1086
  * Insert the AdSense parameter code into the page. This'll go into the header per Google's instructions.
1087
  */
1088
  function spool_adsense() {
1089
- $options = get_option('Yoast_Google_Analytics');
1090
  if ( $options["uastring"] != "" && yoast_ga_do_tracking() && !is_preview() ) {
1091
- echo '<script type="text/javascript">'."\n";
1092
- echo "\t".'window.google_analytics_uacct = "'.$options["uastring"].'";'."\n";
1093
- echo '</script>'."\n";
1094
  }
1095
- }
1096
 
1097
  function ga_get_tracking_prefix() {
1098
- $options = get_option('Yoast_Google_Analytics');
1099
- return (empty($options['trackprefix'])) ? '/yoast-ga/' : $options['trackprefix'];
1100
  }
1101
-
1102
- function ga_get_tracking_link($prefix, $target, $jsprefix = 'javascript:') {
1103
- $options = get_option('Yoast_Google_Analytics');
1104
- if (
1105
- ( $prefix != 'download' && $options['outboundpageview'] ) ||
1106
- ( $prefix == 'download' && $options['downloadspageview'] ) )
1107
- {
1108
- $prefix = GA_Filter::ga_get_tracking_prefix().$prefix;
1109
- $pushstr = "['_trackPageview','".$prefix."/". esc_js( esc_url( $target ) )."']";
1110
  } else {
1111
- $pushstr = "['_trackEvent','".$prefix."','".esc_js( esc_url( $target ) )."']";
1112
  }
1113
- return $jsprefix."_gaq.push(".$pushstr.");";
1114
  }
1115
-
1116
- function ga_get_domain($uri){
1117
- $hostPattern = "/^(http:\/\/)?([^\/]+)/i";
1118
  $domainPatternUS = "/[^\.\/]+\.[^\.\/]+$/";
1119
  $domainPatternUK = "/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/";
1120
 
1121
- preg_match($hostPattern, $uri, $matches);
1122
  $host = $matches[2];
1123
- if (preg_match("/.*\..*\..*\..*$/",$host))
1124
- preg_match($domainPatternUK, $host, $matches);
1125
  else
1126
- preg_match($domainPatternUS, $host, $matches);
1127
 
1128
- return array("domain"=>$matches[0],"host"=>$host);
1129
  }
1130
 
1131
- function ga_parse_link($category, $matches){
1132
- $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
1133
- $options = get_option('Yoast_Google_Analytics');
1134
-
1135
  // Break out immediately if the link is not an http or https link.
1136
- if (strpos($matches[2],"http") !== 0) {
1137
  $target = false;
1138
- } else if ((strpos($matches[2],"mailto") === 0)) {
1139
  $target = 'email';
1140
  } else {
1141
- $target = GA_Filter::ga_get_domain($matches[3]);
1142
  }
1143
- $trackBit = "";
1144
- $extension = substr(strrchr($matches[3], '.'), 1);
1145
- $dlextensions = explode(",",str_replace('.','',$options['dlextensions']));
1146
  if ( $target ) {
1147
  if ( $target == 'email' ) {
1148
- $trackBit = GA_Filter::ga_get_tracking_link('mailto', str_replace('mailto:','',$matches[3]),'');
1149
- } else if ( in_array($extension, $dlextensions) ) {
1150
- $trackBit = GA_Filter::ga_get_tracking_link('download', $matches[3],'');
1151
- } else if ( $target["domain"] != $origin["domain"] ){
1152
- $crossdomains = array();
1153
- if (isset($options['othercrossdomains']))
1154
- $crossdomains = explode(',',str_replace(' ','',$options['othercrossdomains']));
1155
- if ( isset($options['trackcrossdomain']) && $options['trackcrossdomain'] && in_array($target["host"],$crossdomains) ) {
1156
  $trackBit = '_gaq.push([\'_link\', \'' . $matches[2] . '//' . $matches[3] . '\']); return false;"';
1157
- } else if ( $options['trackoutbound'] && in_array($options['domainorurl'], array('domain','url')) ) {
1158
- $url = $options['domainorurl'] == 'domain' ? $target["host"] : $matches[3];
1159
- $trackBit = GA_Filter::ga_get_tracking_link($category, $url,'');
1160
  }
1161
- $trackBit = GA_Filter::ga_get_tracking_link($category, $url,'');
1162
- } else if ( $target["domain"] == $origin["domain"] && isset($options['internallink']) && $options['internallink'] != '') {
1163
- $url = preg_replace('|'.$origin["host"].'|','',$matches[3]);
1164
- $extintlinks = explode(',',$options['internallink']);
1165
- foreach ($extintlinks as $link) {
1166
- if (preg_match('|^'.trim($link).'|', $url, $match)) {
1167
  $label = $options['internallinklabel'];
1168
- if ($label == '')
1169
  $label = 'int';
1170
- $trackBit = GA_Filter::ga_get_tracking_link($category.'-'.$label, $url,'');
1171
- }
1172
  }
1173
  }
1174
- }
1175
- if ($trackBit != "") {
1176
- if (preg_match('/onclick=[\'\"](.*?)[\'\"]/i', $matches[4]) > 0) {
1177
  // Check for manually tagged outbound clicks, and replace them with the tracking of choice.
1178
- if (preg_match('/.*_track(Pageview|Event).*/i', $matches[4]) > 0) {
1179
- $matches[4] = preg_replace('/onclick=[\'\"](javascript:)?(.*;)?[a-zA-Z0-9]+\._track(Pageview|Event)\([^\)]+\)(;)?(.*)?[\'\"]/i', 'onclick="javascript:' . $trackBit .'$2$5"', $matches[4]);
1180
  } else {
1181
- $matches[4] = preg_replace('/onclick=[\'\"](javascript:)?(.*?)[\'\"]/i', 'onclick="javascript:' . $trackBit .'$2"', $matches[4]);
1182
  }
1183
  } else {
1184
  $matches[4] = 'onclick="javascript:' . $trackBit . '"' . $matches[4];
1185
- }
1186
  }
1187
  return '<a ' . $matches[1] . 'href="' . $matches[2] . '//' . $matches[3] . '"' . ' ' . $matches[4] . '>' . $matches[5] . '</a>';
1188
  }
1189
 
1190
- function ga_parse_article_link($matches){
1191
- return GA_Filter::ga_parse_link('outbound-article',$matches);
1192
  }
1193
 
1194
- function ga_parse_comment_link($matches){
1195
- return GA_Filter::ga_parse_link('outbound-comment',$matches);
1196
  }
1197
 
1198
- function ga_parse_widget_link($matches){
1199
- return GA_Filter::ga_parse_link('outbound-widget',$matches);
1200
  }
1201
 
1202
- function ga_parse_nav_menu($matches){
1203
- return GA_Filter::ga_parse_link('outbound-menu',$matches);
1204
  }
1205
-
1206
- function widget_content($text) {
1207
  if ( !yoast_ga_do_tracking() )
1208
  return $text;
1209
  static $anchorPattern = '/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
1210
- $text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_widget_link'),$text);
1211
  return $text;
1212
  }
1213
-
1214
- function the_content($text) {
1215
  if ( !yoast_ga_do_tracking() )
1216
  return $text;
1217
 
1218
- if (!is_feed()) {
1219
  static $anchorPattern = '/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
1220
- $text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_article_link'),$text);
1221
  }
1222
  return $text;
1223
  }
1224
 
1225
- function nav_menu($text) {
1226
  if ( !yoast_ga_do_tracking() )
1227
  return $text;
1228
 
1229
- if (!is_feed()) {
1230
  static $anchorPattern = '/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
1231
- $text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_nav_menu'),$text);
1232
  }
1233
  return $text;
1234
  }
1235
-
1236
- function comment_text($text) {
1237
  if ( !yoast_ga_do_tracking() )
1238
  return $text;
1239
 
1240
- if (!is_feed()) {
1241
  static $anchorPattern = '/<a (.*?)href="(.*?)\/\/(.*?)"(.*?)>(.*?)<\/a>/i';
1242
- $text = preg_replace_callback($anchorPattern,array('GA_Filter','ga_parse_comment_link'),$text);
1243
  }
1244
  return $text;
1245
  }
1246
 
1247
- function comment_author_link($text) {
1248
- $options = get_option('Yoast_Google_Analytics');
1249
 
1250
  if ( !yoast_ga_do_tracking() )
1251
  return $text;
1252
 
1253
- static $anchorPattern = '/(.*\s+.*?href\s*=\s*)["\'](.*?)["\'](.*)/';
1254
- preg_match($anchorPattern, $text, $matches);
1255
- if (!isset($matches[2]) || $matches[2] == "") return $text;
1256
 
1257
  $trackBit = '';
1258
- $target = GA_Filter::ga_get_domain($matches[2]);
1259
- $origin = GA_Filter::ga_get_domain($_SERVER["HTTP_HOST"]);
1260
- if ( $target["domain"] != $origin["domain"] ){
1261
  if ( isset( $options['domainorurl'] ) && $options['domainorurl'] == "domain" )
1262
  $url = $target["host"];
1263
  else
1264
  $url = $matches[2];
1265
- $trackBit = 'onclick="'.GA_Filter::ga_get_tracking_link('outbound-commentauthor', $url).'"';
1266
- }
1267
- return $matches[1] . "\"" . $matches[2] . "\" " . $trackBit ." ". $matches[3];
1268
  }
1269
-
1270
- function bookmarks($bookmarks) {
1271
  if ( !yoast_ga_do_tracking() )
1272
  return $bookmarks;
1273
-
1274
  $i = 0;
1275
- while ( $i < count($bookmarks) ) {
1276
- $target = GA_Filter::ga_get_domain($bookmarks[$i]->link_url);
1277
- $sitedomain = GA_Filter::ga_get_domain(get_bloginfo('url'));
1278
- if ($target['host'] == $sitedomain['host']) {
1279
  $i++;
1280
  continue;
1281
  }
@@ -1283,150 +1340,150 @@ if ( $options['gajslocalhosting'] && !empty($options['gajsurl']) ) {
1283
  $url = $target["host"];
1284
  else
1285
  $url = $bookmarks[$i]->link_url;
1286
- $trackBit = '" onclick="'.GA_Filter::ga_get_tracking_link('outbound-blogroll', $url);
1287
  $bookmarks[$i]->link_target .= $trackBit;
1288
  $i++;
1289
  }
1290
  return $bookmarks;
1291
  }
1292
-
1293
- function rsslinktagger($guid) {
1294
- $options = get_option('Yoast_Google_Analytics');
1295
  global $wp, $post;
1296
  if ( is_feed() ) {
1297
  if ( $options['allowanchor'] ) {
1298
  $delimiter = '#';
1299
  } else {
1300
  $delimiter = '?';
1301
- if (strpos ( $guid, $delimiter ) > 0)
1302
  $delimiter = '&amp;';
1303
  }
1304
- return $guid . $delimiter . 'utm_source=rss&amp;utm_medium=rss&amp;utm_campaign='.urlencode($post->post_name);
1305
  }
1306
  return $guid;
1307
  }
1308
-
1309
  function wpec_transaction_tracking( $push ) {
1310
  global $wpdb, $purchlogs, $cart_log_id;
1311
- if( !isset( $cart_log_id ) || empty($cart_log_id) )
1312
  return $push;
1313
 
1314
- $city = $wpdb->get_var ("SELECT tf.value
1315
- FROM ".WPSC_TABLE_SUBMITED_FORM_DATA." tf
1316
- LEFT JOIN ".WPSC_TABLE_CHECKOUT_FORMS." cf
1317
  ON cf.id = tf.form_id
1318
  WHERE cf.type = 'city'
1319
- AND log_id = ".$cart_log_id );
1320
 
1321
- $country = $wpdb->get_var ("SELECT tf.value
1322
- FROM ".WPSC_TABLE_SUBMITED_FORM_DATA." tf
1323
- LEFT JOIN ".WPSC_TABLE_CHECKOUT_FORMS." cf
1324
  ON cf.id = tf.form_id
1325
  WHERE cf.type = 'country'
1326
- AND log_id = ".$cart_log_id );
1327
 
1328
- $cart_items = $wpdb->get_results ("SELECT * FROM ".WPSC_TABLE_CART_CONTENTS." WHERE purchaseid = ".$cart_log_id, ARRAY_A);
1329
 
1330
- $total_shipping = $purchlogs->allpurchaselogs[0]->base_shipping;
1331
- $total_tax = 0;
1332
  foreach ( $cart_items as $item ) {
1333
  $total_shipping += $item['pnp'];
1334
- $total_tax += $item['tax_charged'];
1335
  }
1336
 
1337
- $push[] = "'_addTrans','".$cart_log_id."'," // Order ID
1338
- ."'".GA_Filter::ga_str_clean(get_bloginfo('name'))."'," // Store name
1339
- ."'".nzshpcrt_currency_display($purchlogs->allpurchaselogs[0]->totalprice,1,true,false,true)."'," // Total price
1340
- ."'".nzshpcrt_currency_display($total_tax,1,true,false,true)."'," // Tax
1341
- ."'".nzshpcrt_currency_display($total_shipping,1,true,false,true)."'," // Shipping
1342
- ."'".$city."'," // City
1343
- ."''," // State
1344
- ."'".$country."'"; // Country
1345
-
1346
- foreach( $cart_items as $item ) {
1347
- $item['sku'] = $wpdb->get_var( "SELECT meta_value FROM ".WPSC_TABLE_PRODUCTMETA." WHERE meta_key = 'sku' AND product_id = '".$item['prodid']."' LIMIT 1" );
1348
 
1349
- $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']."'" );
1350
- $push[] = "'_addItem',"
1351
- ."'".$cart_log_id."'," // Order ID
1352
- ."'".$item['sku']."'," // Item SKU
1353
- ."'". str_replace( "'", "", $item['name'] ) ."'," // Item Name
1354
- ."'".$item['category']."'," // Item Category
1355
- ."'".$item['price']."'," // Item Price
1356
- ."'".$item['quantity']."'"; // Item Quantity
 
 
 
1357
  }
1358
  $push[] = "'_trackTrans'";
1359
 
1360
  return $push;
1361
  }
1362
-
1363
  function shopp_transaction_tracking( $push ) {
1364
  global $Shopp;
1365
 
1366
  // Only process if we're in the checkout process (receipt page)
1367
- if (version_compare(substr(SHOPP_VERSION,0,3),'1.1') >= 0) {
1368
  // Only process if we're in the checkout process (receipt page)
1369
- if (function_exists('is_shopp_page') && !is_shopp_page('checkout')) return $push;
1370
- if (empty($Shopp->Order->purchase)) return $push;
1371
 
1372
- $Purchase = new Purchase($Shopp->Order->purchase);
1373
  $Purchase->load_purchased();
1374
  } else {
1375
  // For 1.0.x
1376
  // Only process if we're in the checkout process (receipt page)
1377
- if (function_exists('is_shopp_page') && !is_shopp_page('checkout')) return $push;
1378
  // Only process if we have valid order data
1379
- if (!isset($Shopp->Cart->data->Purchase)) return $push;
1380
- if (empty($Shopp->Cart->data->Purchase->id)) return $push;
1381
 
1382
  $Purchase = $Shopp->Cart->data->Purchase;
1383
  }
1384
 
1385
  $push[] = "'_addTrans',"
1386
- ."'".$Purchase->id."'," // Order ID
1387
- ."'".GA_Filter::ga_str_clean(get_bloginfo('name'))."'," // Store
1388
- ."'".number_format($Purchase->total,2)."'," // Total price
1389
- ."'".number_format($Purchase->tax,2)."'," // Tax
1390
- ."'".number_format($Purchase->shipping,2)."'," // Shipping
1391
- ."'".$Purchase->city."'," // City
1392
- ."'".$Purchase->state."'," // State
1393
- ."'.$Purchase->country.'"; // Country
1394
-
1395
- foreach ($Purchase->purchased as $item) {
1396
- $sku = empty($item->sku) ? 'PID-'.$item->product.str_pad($item->price,4,'0',STR_PAD_LEFT) : $item->sku;
1397
- $push[] = "'_addItem',"
1398
- ."'".$Purchase->id."',"
1399
- ."'".$sku."',"
1400
- ."'". str_replace( "'", "", $item->name ) ."',"
1401
- ."'".$item->optionlabel."',"
1402
- ."'".number_format($item->unitprice,2)."',"
1403
- ."'".$item->quantity."'";
1404
  }
1405
  $push[] = "'_trackTrans'";
1406
  return $push;
1407
  }
1408
-
1409
  } // class GA_Filter
1410
  } // endif
1411
 
1412
  /**
1413
  * If setAllowAnchor is set to true, GA ignores all links tagged "normally", so we redirect all "normally" tagged URL's
1414
- * to one tagged with a hash.
1415
  */
1416
  function ga_utm_hashtag_redirect() {
1417
- if (isset($_SERVER['REQUEST_URI'])) {
1418
- if (strpos($_SERVER['REQUEST_URI'], "utm_") !== false) {
1419
  $url = 'http://';
1420
- if ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "") {
1421
  $url = 'https://';
1422
  }
1423
  $url .= $_SERVER['SERVER_NAME'];
1424
- if ( strpos($_SERVER['REQUEST_URI'], "?utm_") !== false ) {
1425
- $url .= str_replace("?utm_","#utm_",$_SERVER['REQUEST_URI']);
1426
- } else if ( strpos($_SERVER['REQUEST_URI'], "&utm_") !== false ) {
1427
- $url .= substr_replace($_SERVER['REQUEST_URI'], "#utm_", strpos($_SERVER['REQUEST_URI'], "&utm_"), 5);
1428
  }
1429
- wp_redirect($url, 301);
1430
  exit;
1431
  }
1432
  }
@@ -1434,133 +1491,138 @@ function ga_utm_hashtag_redirect() {
1434
 
1435
  function yoast_ga_do_tracking() {
1436
  $current_user = wp_get_current_user();
1437
-
1438
- if (0 == $current_user->ID)
1439
  return true;
1440
-
1441
- $yoast_ga_options = get_option('Yoast_Google_Analytics');
1442
-
1443
- if ( ($current_user->user_level >= $yoast_ga_options["ignore_userlevel"]) )
1444
  return false;
1445
  else
1446
  return true;
1447
  }
1448
 
1449
  function track_comment_form_head() {
1450
- if (is_singular()) {
1451
- global $post;
1452
- $yoast_ga_options = get_option('Yoast_Google_Analytics');
1453
- if ( yoast_ga_do_tracking()
1454
- && isset( $yoast_ga_options["trackcommentform"] )
1455
- && $yoast_ga_options["trackcommentform"]
1456
- && ( 'open' == $post->comment_status ) )
1457
- wp_enqueue_script('jquery');
1458
- }
 
1459
  }
1460
- add_action('wp_print_scripts','track_comment_form_head');
 
1461
 
1462
  $comment_form_id = 'commentform';
1463
- function yoast_get_comment_form_id($args) {
1464
  global $comment_form_id;
1465
  $comment_form_id = $args['id_form'];
1466
  return $args;
1467
  }
1468
- add_filter('comment_form_defaults', 'yoast_get_comment_form_id',99,1);
 
1469
 
1470
  function yoast_track_comment_form() {
1471
- global $comment_form_id, $post;
1472
- $yoast_ga_options = get_option('Yoast_Google_Analytics');
1473
- if ( yoast_ga_do_tracking() && $yoast_ga_options["trackcommentform"] ) {
1474
- ?>
1475
- <script type="text/javascript">
1476
- jQuery(document).ready(function() {
1477
- jQuery('#<?php echo $comment_form_id; ?>').submit(function() {
1478
- _gaq.push(
1479
- ['_setAccount','<?php echo $yoast_ga_options["uastring"]; ?>'],
1480
- ['_trackEvent','comment','submit']
1481
- );
1482
- });
1483
- });
1484
- </script>
1485
- <?php
1486
- }
1487
  }
1488
- add_action('comment_form_after','yoast_track_comment_form');
1489
 
1490
- function yoast_sanitize_relative_links($content) {
1491
- preg_match("|^http(s)?://([^/]+)|i", get_bloginfo('url'), $match);
1492
- $content = preg_replace("/<a([^>]*) href=('|\")\/([^\"']*)('|\")/", "<a\${1} href=\"" .$match[0] ."/" ."\${3}\"", $content);
 
 
1493
 
1494
- if (is_singular()) {
1495
- $content = preg_replace("/<a([^>]*) href=('|\")#([^\"']*)('|\")/", "<a\${1} href=\"" .get_permalink()."#" ."\${3}\"", $content);
1496
- }
1497
- return $content;
1498
  }
1499
- add_filter('the_content', 'yoast_sanitize_relative_links', 98);
1500
- add_filter('widget_text', 'yoast_sanitize_relative_links', 98);
 
1501
 
1502
  function yoast_analytics() {
1503
- $options = get_option('Yoast_Google_Analytics');
1504
- if ($options['position'] == 'manual')
1505
  GA_Filter::spool_analytics();
1506
  else
1507
  echo '<!-- Please set Google Analytics position to "manual" in the settings, or remove this call to yoast_analytics(); -->';
1508
  }
1509
 
1510
- $gaf = new GA_Filter();
1511
- $options = get_option('Yoast_Google_Analytics');
1512
 
1513
- if (!is_array($options)) {
1514
- $options = get_option('GoogleAnalyticsPP');
1515
- if (!is_array($options)) {
1516
  $ga_admin->set_defaults();
1517
  } else {
1518
- delete_option('GoogleAnalyticsPP');
1519
- if ($options['admintracking']) {
1520
  $options["ignore_userlevel"] = '8';
1521
- unset($options['admintracking']);
1522
  } else {
1523
  $options["ignore_userlevel"] = '11';
1524
  }
1525
- update_option('Yoast_Google_Analytics', $options);
1526
  }
1527
  } else {
1528
  if ( isset( $options['allowanchor'] ) && $options['allowanchor'] ) {
1529
- add_action('init','ga_utm_hashtag_redirect',1);
1530
  }
1531
 
1532
- if ( (isset( $options['trackoutbound'] ) && $options['trackoutbound'] ) ||
1533
- (isset( $options['trackcrossdomain'] ) && $options['trackcrossdomain'] ) ) {
 
1534
  // filters alter the existing content
1535
- add_filter('the_content', array('GA_Filter','the_content'), 99);
1536
- add_filter('widget_text', array('GA_Filter','widget_content'), 99);
1537
- add_filter('the_excerpt', array('GA_Filter','the_content'), 99);
1538
- add_filter('comment_text', array('GA_Filter','comment_text'), 99);
1539
- add_filter('get_bookmarks', array('GA_Filter','bookmarks'), 99);
1540
- add_filter('get_comment_author_link', array('GA_Filter','comment_author_link'), 99);
1541
- add_filter('wp_nav_menu', array('GA_Filter','nav_menu'), 99);
1542
  }
1543
 
1544
  if ( isset( $options['trackadsense'] ) && $options['trackadsense'] )
1545
- add_action('wp_head', array('GA_Filter','spool_adsense'),1);
1546
 
1547
  if ( !isset( $options['position'] ) )
1548
  $options['position'] = 'header';
1549
-
1550
- switch ($options['position']) {
1551
  case 'manual':
1552
  // No need to insert here, bail NOW.
1553
  break;
1554
  case 'header':
1555
  default:
1556
- add_action('wp_head', array('GA_Filter','spool_analytics'),2);
1557
  break;
1558
  }
1559
 
1560
  if ( isset( $options['trackregistration'] ) && $options['trackregistration'] )
1561
- add_action('login_head', array('GA_Filter','spool_analytics'),20);
1562
 
1563
  if ( isset( $options['rsslinktagging'] ) && $options['rsslinktagging'] )
1564
- add_filter ( 'the_permalink_rss', array('GA_Filter','rsslinktagger'), 99 );
1565
-
1566
  }
4
  Plugin URI: http://yoast.com/wordpress/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v420
5
  Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. custom variables and automatic clickout and download tracking.
6
  Author: Joost de Valk
7
+ Version: 4.2.5
8
  Requires at least: 3.0
9
  Author URI: http://yoast.com/
10
+ License: GPL v3
11
+
12
+ Google Analytics for WordPress
13
+ Copyright (C) 2008-2012, Joost de Valk - joost@yoast.com
14
+
15
+ This program is free software: you can redistribute it and/or modify
16
+ it under the terms of the GNU General Public License as published by
17
+ the Free Software Foundation, either version 3 of the License, or
18
+ (at your option) any later version.
19
+
20
+ This program is distributed in the hope that it will be useful,
21
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ GNU General Public License for more details.
24
+
25
+ You should have received a copy of the GNU General Public License
26
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
27
  */
28
 
29
  // This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics
30
 
31
+ define( 'GAWP_VERSION', '4.2.5' );
32
 
33
  /*
34
  * Admin User Interface
35
  */
36
 
37
+ $options = get_option( 'Yoast_Google_Analytics' );
38
+
39
+ if ( is_admin() && ( !defined( 'DOING_AJAX' ) || !DOING_AJAX ) && !class_exists( 'GA_Admin' ) ) {
40
 
41
  require_once plugin_dir_path( __FILE__ ) . 'yst_plugin_tools.php';
42
  require_once plugin_dir_path( __FILE__ ) . '/wp-gdata/wp-gdata.php';
43
+
44
+ global $wp_version;
45
+ if ( version_compare( $wp_version, '3.3', '>=' ) && !isset( $options['tracking_popup'] ) )
46
+ require_once plugin_dir_path( __FILE__ ) . 'class-pointer.php';
47
+
48
+ if ( isset( $options['yoast_tracking'] ) && ( 'on' == $options['yoast_tracking'] || true === $options['yoast_tracking'] ) )
49
+ require_once plugin_dir_path( __FILE__ ) . 'class-tracking.php';
50
+
51
  class GA_Admin extends Yoast_GA_Plugin_Admin {
52
 
53
+ var $hook = 'google-analytics-for-wordpress';
54
+ var $filename = 'google-analytics-for-wordpress/googleanalytics.php';
55
+ var $longname = 'Google Analytics Configuration';
56
+ var $shortname = 'Google Analytics';
57
+ var $ozhicon = 'images/chart_curve.png';
58
  var $optionname = 'Yoast_Google_Analytics';
59
+ var $homepage = 'http://yoast.com/wordpress/google-analytics/';
60
+ var $toc = '';
61
 
62
  /**
63
  * PHP4 Constructor
65
  function GA_Admin() {
66
  $this->__construct();
67
  }
68
+
69
  /**
70
  * Constructur, load all required stuff.
71
  */
72
  function __construct() {
73
  $this->upgrade();
74
+
75
+ $this->plugin_url = plugins_url( '', __FILE__ ) . '/';
76
+
77
  // Register the settings page
78
+ add_action( 'admin_menu', array( &$this, 'register_settings_page' ) );
79
 
80
  // Register the contextual help for the settings page
81
  // add_action( 'contextual_help', array(&$this, 'plugin_help'), 10, 3 );
82
+
83
  // Give the settings page a nice icon in Ozh's menu
84
+ add_filter( 'ozh_adminmenu_icon', array( &$this, 'add_ozh_adminmenu_icon' ) );
85
 
86
  // Give the plugin a settings link in the plugin overview
87
+ add_filter( 'plugin_action_links', array( &$this, 'add_action_link' ), 10, 2 );
88
+
89
  // Print Scripts and Styles
90
+ add_action( 'admin_print_scripts', array( &$this, 'config_page_scripts' ) );
91
+ add_action( 'admin_print_styles', array( &$this, 'config_page_styles' ) );
92
+
93
  // Print stuff in the settings page's head
94
+ add_action( 'admin_head', array( &$this, 'config_page_head' ) );
95
 
96
  // Drop a warning on each page of the admin when Google Analytics hasn't been configured
97
+ add_action( 'admin_footer', array( &$this, 'warning' ) );
98
+
99
  // Save settings
100
  // TODO: replace with Options API
101
+ add_action( 'admin_init', array( &$this, 'save_settings' ) );
102
 
103
+ // Authenticate
104
+ add_action( 'admin_init', array( &$this, 'authenticate' ) );
105
  }
106
+
107
  function config_page_head() {
108
+
109
+ if ( isset( $_GET['allow_tracking'] ) ) {
110
+ $options = get_option( 'Yoast_Google_Analytics' );
111
+
112
+ $options['tracking_popup'] = 'done';
113
+ if ( $_GET['allow_tracking'] == 'yes' )
114
+ $options['yoast_tracking'] = true;
115
+ else
116
+ $options['yoast_tracking'] = false;
117
+ update_option( 'Yoast_Google_Analytics', $options );
118
+ }
119
+
120
  global $current_screen;
121
+ if ( 'settings_page_' . $this->hook == $current_screen->id ) {
122
  $options = get_option( $this->optionname );
123
+ if ( !empty( $options['uastring'] ) ) {
124
  $uastring = $options['uastring'];
125
+ } else {
126
+ $uastring = '';
127
  }
128
+
129
+ ?>
130
+ <script type="text/javascript">
131
+ function makeSublist(parent, child, childVal) {
132
+ jQuery("body").append("<select style='display:none' id='" + parent + child + "'></select>");
133
+ jQuery('#' + parent + child).html(jQuery("#" + child + " option"));
134
+
135
+ var parentValue = jQuery('#' + parent).val();
136
+ jQuery('#' + child).html(jQuery("#" + parent + child + " .sub_" + parentValue).clone());
137
+
138
+ childVal = (typeof childVal == "undefined") ? "" : childVal;
139
+ jQuery("#" + child).val(childVal).attr('selected', 'selected');
140
+
141
+ jQuery('#' + parent).change(function () {
142
+ var parentValue = jQuery('#' + parent).val();
143
+ jQuery('#' + child).html(jQuery("#" + parent + child + " .sub_" + parentValue).clone());
144
+ jQuery('#' + child).trigger("change");
145
+ jQuery('#' + child).focus();
146
+ });
147
+ }
148
+ jQuery(document).ready(function () {
149
+ makeSublist('ga_account', 'uastring_sel', '<?php echo $uastring; ?>');
150
+ jQuery('#position').change(function () {
151
+ if (jQuery('#position').val() == 'header') {
152
+ jQuery('#position_header').css("display", "block");
153
+ jQuery('#position_manual').css("display", "none");
154
+ } else {
155
+ jQuery('#position_header').css("display", "none");
156
+ jQuery('#position_manual').css("display", "block");
157
+ }
158
+ }).change();
159
+ jQuery('#switchtomanual').change(function () {
160
+ if (jQuery('#switchtomanual').is(':checked')) {
161
+ jQuery('#uastring_manual').css('display', 'block');
162
+ jQuery('#uastring_automatic').css('display', 'none');
163
+ } else {
164
+ jQuery('#uastring_manual').css('display', 'none');
165
+ jQuery('#uastring_automatic').css('display', 'block');
166
+ }
167
+ }).change();
168
+ jQuery('#trackoutbound').change(function () {
169
+ if (jQuery('#trackoutbound').is(':checked')) {
170
+ jQuery('#internallinktracking').css("display", "block");
171
+ jQuery('.internallinktracking').css("display", "list-item");
172
+ } else {
173
+ jQuery('#internallinktracking').css("display", "none");
174
+ jQuery('.internallinktracking').css("display", "none");
175
+ }
176
+ }).change();
177
+ jQuery('#advancedsettings').change(function () {
178
+ if (jQuery('#advancedsettings').is(':checked')) {
179
+ jQuery('#advancedgasettings').css("display", "block");
180
+ jQuery('#customvarsettings').css("display", "block");
181
+ jQuery('.advancedgasettings').css("display", "list-item");
182
+ jQuery('.customvarsettings').css("display", "list-item");
183
+ } else {
184
+ jQuery('#advancedgasettings').css("display", "none");
185
+ jQuery('#customvarsettings').css("display", "none");
186
+ jQuery('.advancedgasettings').css("display", "none");
187
+ jQuery('.customvarsettings').css("display", "none");
188
+ }
189
+ }).change();
190
+ jQuery('#extrase').change(function () {
191
+ if (jQuery('#extrase').is(':checked')) {
192
+ jQuery('#extrasebox').css("display", "block");
193
+ } else {
194
+ jQuery('#extrasebox').css("display", "none");
195
+ }
196
+ }).change();
197
+ jQuery('#gajslocalhosting').change(function () {
198
+ if (jQuery('#gajslocalhosting').is(':checked')) {
199
+ jQuery('#localhostingbox').css("display", "block");
200
+ } else {
201
+ jQuery('#localhostingbox').css("display", "none");
202
+ }
203
+ }).change();
204
+ jQuery('#customvarsettings :input').change(function () {
205
+ if (jQuery("#customvarsettings :input:checked").size() > 5) {
206
+ alert("<?php _e( 'The maximum number of allowed custom variables in Google Analytics is 5, please unselect one of the other custom variables before selecting this one.' ); ?>");
207
+ jQuery(this).attr('checked', false);
208
+ }
209
+ ;
210
+ });
211
+ jQuery('#uastring').change(function () {
212
+ if (jQuery('#switchtomanual').is(':checked')) {
213
+ if (!jQuery(this).val().match(/^UA-[\d-]+$/)) {
214
+ alert("<?php _e( 'That\'s not a valid UA ID, please make sure it matches the expected pattern of: UA-XXXXXX-X, and that there are no spaces or other characters in the input field.' ); ?>");
215
+ jQuery(this).focus();
216
  }
217
+ }
218
  });
219
+ });
220
+ </script>
221
+ <link rel="shortcut icon" href="<?php echo $this->plugin_url; ?>images/favicon.ico"/>
222
  <?php
223
  }
224
  }
 
 
 
225
 
226
+ function plugin_help( $contextual_help, $screen_id, $screen ) {
227
+ if ( $screen_id == 'settings_page_' . $this->hook ) {
228
+
229
+ $contextual_help = '<h2>' . __( 'Having problems?' ) . '</h2>' .
230
+ '<p>' . sprintf( __( "If you're having problems with this plugin, please refer to its <a href='%s'>FAQ page</a>." ), 'http://yoast.com/wordpress/google-analytics/ga-wp-faq/' ) . '</p>';
231
  }
232
  return $contextual_help;
233
  }
234
+
235
  function toc( $modules ) {
236
  $output = '<ul>';
237
+ foreach ( $modules as $module => $key ) {
238
+ $output .= '<li class="' . $key . '"><a href="#' . $key . '">' . $module . '</a></li>';
239
  }
240
  $output .= '</ul>';
241
  return $output;
242
  }
243
+
244
  function save_settings() {
245
  $options = get_option( $this->optionname );
246
+
247
+ if ( isset( $_REQUEST['reset'] ) && $_REQUEST['reset'] == "true" && isset( $_REQUEST['plugin'] ) && $_REQUEST['plugin'] == 'google-analytics-for-wordpress' ) {
248
+ $options = $this->set_defaults();
249
+ $options['msg'] = "<div class=\"updated\"><p>" . __( 'Google Analytics settings reset.' ) . "</p></div>\n";
250
+ } elseif ( isset( $_POST['submit'] ) && isset( $_POST['plugin'] ) && $_POST['plugin'] == 'google-analytics-for-wordpress' ) {
251
+
252
+ if ( !current_user_can( 'manage_options' ) ) die( __( 'You cannot edit the Google Analytics for WordPress options.' ) );
253
+ check_admin_referer( 'analyticspp-config' );
254
+
255
+ foreach ( array( 'uastring', 'dlextensions', 'domainorurl', 'position', 'domain', 'customcode', 'ga_token', 'extraseurl', 'gajsurl', 'gfsubmiteventpv', 'trackprefix', 'ignore_userlevel', 'internallink', 'internallinklabel', 'primarycrossdomain', 'othercrossdomains' ) as $option_name ) {
256
+ if ( isset( $_POST[$option_name] ) )
257
  $options[$option_name] = $_POST[$option_name];
258
  else
259
  $options[$option_name] = '';
260
  }
261
+
262
+ foreach ( array( 'extrase', 'trackoutbound', 'admintracking', 'trackadsense', 'allowanchor', 'allowlinker', 'allowhash', 'rsslinktagging', 'advancedsettings', 'trackregistration', 'theme_updated', 'cv_loggedin', 'cv_authorname', 'cv_category', 'cv_all_categories', 'cv_tags', 'cv_year', 'cv_post_type', 'outboundpageview', 'downloadspageview', 'trackcrossdomain', 'gajslocalhosting', 'manual_uastring', 'taggfsubmit', 'wpec_tracking', 'shopp_tracking', 'anonymizeip', 'trackcommentform', 'debug', 'firebuglite', 'yoast_tracking' ) as $option_name ) {
263
+ if ( isset( $_POST[$option_name] ) && $_POST[$option_name] == 'on' )
264
  $options[$option_name] = true;
265
  else
266
  $options[$option_name] = false;
267
  }
268
 
269
+ if ( isset( $_POST['manual_uastring'] ) && isset( $_POST['uastring_man'] ) ) {
270
  $options['uastring'] = $_POST['uastring_man'];
271
  }
272
+
273
  if ( $options['trackcrossdomain'] ) {
274
  if ( !$options['allowlinker'] )
275
  $options['allowlinker'] = true;
276
 
277
+ if ( empty( $options['primarycrossdomain'] ) ) {
278
+ $origin = GA_Filter::ga_get_domain( $_SERVER["HTTP_HOST"] );
279
  $options['primarycrossdomain'] = $origin["domain"];
280
  }
281
  }
282
+
283
+ if ( function_exists( 'w3tc_pgcache_flush' ) )
284
+ w3tc_pgcache_flush();
285
+
286
+ if ( function_exists( 'w3tc_dbcache_flush' ) )
287
+ w3tc_dbcache_flush();
288
+
289
+ if ( function_exists( 'w3tc_minify_flush' ) )
290
+ w3tc_minify_flush();
291
+
292
+ if ( function_exists( 'w3tc_objectcache_flush' ) )
293
  w3tc_objectcache_flush();
294
+
295
+ if ( function_exists( 'wp_cache_clear_cache' ) )
296
  wp_cache_clear_cache();
297
+
298
  $options['msg'] = "<div id=\"updatemessage\" class=\"updated fade\"><p>Google Analytics <strong>settings updated</strong>.</p></div>\n";
299
  $options['msg'] .= "<script type=\"text/javascript\">setTimeout(function(){jQuery('#updatemessage').hide('slow');}, 3000);</script>";
300
  }
301
+ update_option( $this->optionname, $options );
302
  }
303
+
304
  function save_button() {
305
+ return '<div class="alignright"><input type="submit" class="button-primary" name="submit" value="' . __( 'Update Google Analytics Settings &raquo;' ) . '" /></div><br class="clear"/>';
306
  }
307
+
308
  function upgrade() {
309
+ $options = get_option( $this->optionname );
310
+ if ( isset( $options['version'] ) && $options['version'] < '4.04' ) {
311
+ if ( !isset( $options['ignore_userlevel'] ) || $options['ignore_userlevel'] == '' )
312
  $options['ignore_userlevel'] = 11;
313
  }
314
+ if ( !isset( $options['version'] ) || $options['version'] != GAWP_VERSION ) {
315
  $options['version'] = GAWP_VERSION;
316
  }
317
+ update_option( $this->optionname, $options );
318
  }
319
+
320
  function config_page() {
321
+ $options = get_option( $this->optionname );
322
+ if ( isset( $options['msg'] ) )
323
  echo $options['msg'];
324
  $options['msg'] = '';
325
+ update_option( $this->optionname, $options );
326
+
327
+ if ( !isset( $options['uastring'] ) )
328
  $options = $this->set_defaults();
329
  $modules = array();
330
+
331
+ if ( !isset( $options['manual_uastring'] ) )
332
+ $options['manual_uastring'] = '';
333
  ?>
334
+ <div class="wrap">
335
+ <a href="http://yoast.com/">
336
+ <div id="yoast-icon"
337
+ style="background: url(<?php echo $this->plugin_url; ?>images/ga-icon-32x32.png) no-repeat;"
338
+ class="icon32"><br/></div>
339
+ </a>
340
+
341
+ <h2><?php _e( "Google Analytics for WordPress Configuration" ) ?></h2>
342
+
343
+ <div class="postbox-container" style="width:65%;">
344
+ <div class="metabox-holder">
345
+ <div class="meta-box-sortables">
346
+ <form action="<?php echo $this->plugin_options_url(); ?>" method="post" id="analytics-conf">
347
+ <input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>
348
+ <?php
349
+ wp_nonce_field( 'analyticspp-config' );
350
+
351
+ if ( empty( $options['uastring'] ) && empty( $options['ga_token'] ) ) {
352
+ $query = $this->plugin_options_url() . '&reauth=true';
353
+ $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.';
354
+ } else if ( isset( $options['ga_token'] ) && !empty( $options['ga_token'] ) ) {
355
+ $token = $options['ga_token'];
356
+
357
+ require_once plugin_dir_path( __FILE__ ) . 'xmlparser.php';
358
+ if ( file_exists( ABSPATH . 'wp-includes/class-http.php' ) )
359
+ require_once( ABSPATH . 'wp-includes/class-http.php' );
360
+
361
+ if ( !isset( $options['ga_api_responses'][$token] ) ) {
362
+ $options['ga_api_responses'] = array();
363
+
364
+ if ( $oauth = $options['gawp_oauth'] ) {
365
+ if ( isset( $oauth['params']['oauth_token'], $oauth['params']['oauth_token_secret'] ) ) {
366
+ $options['gawp_oauth']['access_token'] = array(
367
+ 'oauth_token' => base64_decode( $oauth['params']['oauth_token'] ),
368
+ 'oauth_token_secret' => base64_decode( $oauth['params']['oauth_token_secret'] )
369
+ );
370
+ unset( $options['gawp_oauth']['params'] );
371
+ update_option( $this->optionname, $options );
372
+ }
373
+ }
374
+
375
+ $args = array(
376
+ 'scope' => 'https://www.google.com/analytics/feeds/',
377
+ 'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'
378
+ );
379
+ $access_token = $options['gawp_oauth']['access_token'];
380
+ $gdata = new WP_Gdata( $args, $access_token['oauth_token'], $access_token['oauth_token_secret'] );
381
+
382
+
383
+ $response = $gdata->get( 'https://www.google.com/analytics/feeds/accounts/default' );
384
+ $http_code = wp_remote_retrieve_response_code( $response );
385
+ $response = wp_remote_retrieve_body( $response );
386
+
387
+
388
+ if ( $http_code == 200 ) {
389
+ $options['ga_api_responses'][$token] = array(
390
+ 'response'=> array( 'code'=> $http_code ),
391
+ 'body' => $response
392
+ );
393
+ $options['ga_token'] = $token;
394
+ update_option( 'Yoast_Google_Analytics', $options );
395
+ }
396
+ }
397
+
398
+ if ( isset( $options['ga_api_responses'][$token] ) && is_array( $options['ga_api_responses'][$token] ) && $options['ga_api_responses'][$token]['response']['code'] == 200 ) {
399
+ $arr = yoast_xml2array( $options['ga_api_responses'][$token]['body'] );
400
+
401
+ $ga_accounts = array();
402
+ if ( isset( $arr['feed']['entry'][0] ) ) {
403
+ foreach ( $arr['feed']['entry'] as $site ) {
404
+ $ua = $site['dxp:property']['3_attr']['value'];
405
+ $account = $site['dxp:property']['1_attr']['value'];
406
+ if ( !isset( $ga_accounts[$account] ) || !is_array( $ga_accounts[$account] ) )
407
+ $ga_accounts[$account] = array();
408
+ $ga_accounts[$account][$site['title']] = $ua;
409
+ }
410
+ } else {
411
+ $ua = $arr['feed']['entry']['dxp:property']['3_attr']['value'];
412
+ $account = $arr['feed']['entry']['dxp:property']['1_attr']['value'];
413
+ $title = $arr['feed']['entry']['title'];
414
+ if ( !isset( $ga_accounts[$account] ) || !is_array( $ga_accounts[$account] ) )
415
+ $ga_accounts[$account] = array();
416
+ $ga_accounts[$account][$title] = $ua;
417
+ }
418
+
419
+ $select1 = '<select style="width:150px;" name="ga_account" id="ga_account">';
420
+ $select1 .= "\t<option></option>\n";
421
+ $select2 = '<select style="width:150px;" name="uastring" id="uastring_sel">';
422
+ $i = 1;
423
+ $currentua = '';
424
+ if ( !empty( $options['uastring'] ) )
425
+ $currentua = $options['uastring'];
426
+
427
+ foreach ( $ga_accounts as $account => $val ) {
428
+ $accountsel = false;
429
+ foreach ( $val as $title => $ua ) {
430
+ $sel = selected( $ua, $currentua, false );
431
+ if ( !empty( $sel ) ) {
432
+ $accountsel = true;
433
+ }
434
+ $select2 .= "\t" . '<option class="sub_' . $i . '" ' . $sel . ' value="' . $ua . '">' . $title . ' - ' . $ua . '</option>' . "\n";
435
+ }
436
+ $select1 .= "\t" . '<option ' . selected( $accountsel, true, false ) . ' value="' . $i . '">' . $account . '</option>' . "\n";
437
+ $i++;
438
+ }
439
+ $select1 .= '</select>';
440
+ $select2 .= '</select>';
441
+
442
+ $line = '<input type="hidden" name="ga_token" value="' . $token . '"/>';
443
+ $line .= 'Please select the correct Analytics profile to track:<br/>';
444
+ $line .= '<table class="form_table">';
445
+ $line .= '<tr><th width="15%">Account:</th><td width="85%">' . $select1 . '</td></tr>';
446
+ $line .= '<tr><th>Profile:</th><td>' . $select2 . '</td></tr>';
447
+ $line .= '</table>';
448
+
449
+ $try = 1;
450
+ if ( isset( $_GET['try'] ) )
451
+ $try = $_GET['try'] + 1;
452
+
453
+ if ( $i == 1 && $try < 4 && isset( $_GET['token'] ) ) {
454
+ $line .= '<script type="text/javascript">
455
+ window.location="' . $this->plugin_options_url() . '&switchua=1&token=' . $token . '&try=' . $try . '";
456
  </script>';
457
+ }
458
+ $line .= 'Please note that if you have several profiles of the same website, it doesn\'t matter which profile you select, and in fact another profile might show as selected later. You can check whether they\'re profiles for the same site by checking if they have the same UA code. If that\'s true, tracking will be correct.<br/>';
459
+ $line .= '<br/>Refresh this listing or switch to another account: ';
460
+ } else {
461
+ $line = 'Unfortunately, an error occurred while connecting to Google, please try again:';
462
+ }
463
+
464
+ $query = $this->plugin_options_url() . '&reauth=true';
465
+ $line .= '<a class="button" href="' . $query . '">Re-authenticate with Google</a>';
466
+ } else {
467
+ $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>';
468
+ }
469
+ $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>';
470
+ $rows = array();
471
+ $content = '';
472
+ $rows[] = array(
473
+ 'id' => 'uastring',
474
+ 'label' => 'Analytics Profile',
475
+ 'desc' => '<input type="checkbox" name="manual_uastring" ' . checked( $options['manual_uastring'], true, false ) . ' id="switchtomanual"/> <label for="switchtomanual">Manually enter your UA code</label>',
476
+ 'content' => $line
477
+ );
478
+ $temp_content = $this->select( 'position', array( 'header' => 'In the header (default)', 'manual' => 'Insert manually' ) );
479
+ if ( $options['theme_updated'] && $options['position'] == 'manual' ) {
480
+ $temp_content .= '<input type="hidden" name="theme_updated" value="off"/>';
481
+ 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>';
482
+ remove_action( 'admin_footer', array( &$this, 'theme_switch_warning' ) );
483
+ }
484
+ $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>';
485
+ $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>';
486
+
487
+ $rows[] = array(
488
+ 'id' => 'position',
489
+ 'label' => 'Where should the tracking code be placed',
490
+ 'desc' => $desc,
491
+ 'content' => $temp_content,
492
+ );
493
+ $rows[] = array(
494
+ 'id' => 'trackoutbound',
495
+ 'label' => 'Track outbound clicks &amp; downloads',
496
+ 'desc' => 'Clicks &amp; downloads will be tracked as events, you can find these under Content &raquo; Event Tracking in your Google Analytics reports.',
497
+ 'content' => $this->checkbox( 'trackoutbound' ),
498
+ );
499
+ $rows[] = array(
500
+ 'id' => 'advancedsettings',
501
+ 'label' => 'Show advanced settings',
502
+ 'desc' => 'Only adviced for advanced users who know their way around Google Analytics',
503
+ 'content' => $this->checkbox( 'advancedsettings' ),
504
+ );
505
+ $rows[] = array(
506
+ 'id' => 'yoast_tracking',
507
+ 'label' => 'Allow tracking of anonymous data',
508
+ 'desc' => 'By allowing us to track anonymous data we can better help you, because we know with which WordPress configurations, themes and plugins we should test. No personal data will be submitted.',
509
+ 'content' => $this->checkbox( 'yoast_tracking' ),
510
+ );
511
+ $this->postbox( 'gasettings', 'Google Analytics Settings', $this->form_table( $rows ) . $this->save_button() );
512
+
513
+ $rows = array();
514
+ $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>';
515
+ $rows[] = array(
516
+ 'id' => 'cv_loggedin',
517
+ 'label' => 'Logged in Users',
518
+ '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.',
519
+ 'content' => $this->checkbox( 'cv_loggedin' ),
520
+ );
521
+ $rows[] = array(
522
+ 'id' => 'cv_post_type',
523
+ 'label' => 'Post type',
524
+ 'desc' => 'Allows you to see pageviews per post type, especially useful if you use multiple custom post types.',
525
+ 'content' => $this->checkbox( 'cv_post_type' ),
526
+ );
527
+ $rows[] = array(
528
+ 'id' => 'cv_authorname',
529
+ 'label' => 'Author Name',
530
+ 'desc' => 'Allows you to see pageviews per author.',
531
+ 'content' => $this->checkbox( 'cv_authorname' ),
532
+ );
533
+ $rows[] = array(
534
+ 'id' => 'cv_tags',
535
+ 'label' => 'Tags',
536
+ 'desc' => 'Allows you to see pageviews per tags using advanced segments.',
537
+ 'content' => $this->checkbox( 'cv_tags' ),
538
+ );
539
+ $rows[] = array(
540
+ 'id' => 'cv_year',
541
+ 'label' => 'Publication year',
542
+ 'desc' => 'Allows you to see pageviews per year of publication, showing you if your old posts still get traffic.',
543
+ 'content' => $this->checkbox( 'cv_year' ),
544
+ );
545
+ $rows[] = array(
546
+ 'id' => 'cv_category',
547
+ 'label' => 'Single Category',
548
+ 'desc' => 'Allows you to see pageviews per category, works best when each post is in only one category.',
549
+ 'content' => $this->checkbox( 'cv_category' ),
550
+ );
551
+ $rows[] = array(
552
+ 'id' => 'cv_all_categories',
553
+ 'label' => 'All Categories',
554
+ 'desc' => 'Allows you to see pageviews per category using advanced segments, should be used when you use multiple categories per post.',
555
+ 'content' => $this->checkbox( 'cv_all_categories' ),
556
+ );
557
+
558
+ $modules['Custom Variables'] = 'customvarsettings';
559
+ $this->postbox( 'customvarsettings', 'Custom Variables Settings', $pre_content . $this->form_table( $rows ) . $this->save_button() );
560
+
561
+ $rows = array();
562
+ $rows[] = array(
563
+ 'id' => 'ignore_userlevel',
564
+ 'label' => 'Ignore users',
565
+ 'desc' => 'Users of the role you select and higher will be ignored, so if you select Editor, all Editors and Administrators will be ignored.',
566
+ 'content' => $this->select( 'ignore_userlevel', array(
567
+ '11' => 'Ignore no-one',
568
+ '8' => 'Administrator',
569
+ '5' => 'Editor',
570
+ '2' => 'Author',
571
+ '1' => 'Contributor',
572
+ '0' => 'Subscriber (ignores all logged in users)',
573
+ ) ),
574
+ );
575
+ $rows[] = array(
576
+ 'id' => 'outboundpageview',
577
+ 'label' => 'Track outbound clicks as pageviews',
578
+ '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 skew your statistics, but <em>is</em> sometimes necessary when you need to set outbound clicks as goals.',
579
+ 'content' => $this->checkbox( 'outboundpageview' ),
580
+ );
581
+ $rows[] = array(
582
+ 'id' => 'downloadspageview',
583
+ 'label' => 'Track downloads as pageviews',
584
+ 'desc' => 'Not recommended, as this would skew your statistics, but it does make it possible to track downloads as goals.',
585
+ 'content' => $this->checkbox( 'downloadspageview' ),
586
+ );
587
+ $rows[] = array(
588
+ 'id' => 'dlextensions',
589
+ 'label' => 'Extensions of files to track as downloads',
590
+ 'content' => $this->textinput( 'dlextensions' ),
591
+ );
592
+ if ( $options['outboundpageview'] ) {
593
+ $rows[] = array(
594
+ 'id' => 'trackprefix',
595
+ 'label' => 'Prefix to use in Analytics before the tracked pageviews',
596
+ '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.',
597
+ 'content' => $this->textinput( 'trackprefix' ),
598
+ );
599
+ }
600
+ $rows[] = array(
601
+ 'id' => 'domainorurl',
602
+ 'label' => 'Track full URL of outbound clicks or just the domain',
603
+ 'content' => $this->select( 'domainorurl', array(
604
+ 'domain' => 'Just the domain',
605
+ 'url' => 'Track the complete URL',
606
+ )
607
+ ),
608
+ );
609
+ $rows[] = array(
610
+ 'id' => 'domain',
611
+ 'label' => 'Subdomain Tracking',
612
+ 'desc' => 'This allows you to set the domain that\'s set by <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setDomainName"><code>setDomainName</code></a> for tracking subdomains, if empty this will not be set.',
613
+ 'content' => $this->textinput( 'domain' ),
614
+ );
615
+ $rows[] = array(
616
+ 'id' => 'trackcrossdomain',
617
+ 'label' => 'Enable Cross Domain Tracking',
618
+ 'desc' => 'This allows you to enable <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html">Cross-Domain Tracking</a> for this site. When endabled <code>_setAllowLinker:</code> will be enabled if it is not already.',
619
+ 'content' => $this->checkbox( 'trackcrossdomain' ),
620
+ );
621
+ $rows[] = array(
622
+ 'id' => 'primarycrossdomain',
623
+ 'label' => 'Cross-Domain Tracking, Primary Domain',
624
+ 'desc' => 'Set the primary domain used in <a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setDomainName"><code>setDomainName</code></a> for cross domain tracking (eg. <code>example-petstore.com</code> ), if empty this will default to your configured Home URL.',
625
+ 'content' => $this->textinput( 'primarycrossdomain' ),
626
+ );
627
+ $rows[] = array(
628
+ 'id' => 'othercrossdomains',
629
+ 'label' => 'Cross-Domain Tracking, Other Domains',
630
+ 'desc' => 'All links to these domains will have the <a href="http://code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#multipleDomains"><code>_link</code></a> code automatically attached. Separate domains/sub-domains with commas (eg. <code>dogs.example-petstore.com, cats.example-petstore.com</code>)',
631
+ 'content' => $this->textinput( 'othercrossdomains' ),
632
+ );
633
+ $rows[] = array(
634
+ 'id' => 'customcode',
635
+ 'label' => 'Custom Code',
636
+ 'desc' => 'Not for the average user: this allows you to add a line of code, to be added before the <code>trackPageview</code> call.',
637
+ 'content' => $this->textinput( 'customcode' ),
638
+ );
639
+ $rows[] = array(
640
+ 'id' => 'trackadsense',
641
+ 'label' => 'Track AdSense',
642
+ '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>.',
643
+ 'content' => $this->checkbox( 'trackadsense' ),
644
+ );
645
+ $rows[] = array(
646
+ 'id' => 'gajslocalhosting',
647
+ 'label' => 'Host ga.js locally',
648
+ 'content' => $this->checkbox( 'gajslocalhosting' ) . '<div id="localhostingbox">
649
  You have to provide a URL to your ga.js file:
650
+ <input type="text" name="gajsurl" size="30" value="' . $options['gajsurl'] . '"/>
651
  </div>',
652
+ 'desc' => 'For some reasons you might want to use a locally hosted ga.js file, or another ga.js file, check the box and then please enter the full URL including http here.'
653
+ );
654
+ $rows[] = array(
655
+ 'id' => 'extrase',
656
+ 'label' => 'Track extra Search Engines',
657
+ 'content' => $this->checkbox( 'extrase' ) . '<div id="extrasebox">
658
  You can provide a custom URL to the extra search engines file if you want:
659
+ <input type="text" name="extraseurl" size="30" value="' . $options['extraseurl'] . '"/>
660
  </div>',
661
+ );
662
+ $rows[] = array(
663
+ 'id' => 'rsslinktagging',
664
+ 'label' => 'Tag links in RSS feed with campaign variables',
665
+ '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.',
666
+ 'content' => $this->checkbox( 'rsslinktagging' ),
667
+ );
668
+ $rows[] = array(
669
+ 'id' => 'trackregistration',
670
+ 'label' => 'Add tracking to the login and registration forms',
671
+ 'content' => $this->checkbox( 'trackregistration' ),
672
+ );
673
+ $rows[] = array(
674
+ 'id' => 'trackcommentform',
675
+ 'label' => 'Add tracking to the comment forms',
676
+ 'content' => $this->checkbox( 'trackcommentform' ),
677
+ );
678
+ $rows[] = array(
679
+ 'id' => 'allowanchor',
680
+ 'label' => 'Use # instead of ? for Campaign tracking',
681
+ 'desc' => 'This adds a <code><a href="http://code.google.com/apis/analytics/docs/gaJSApiCampaignTracking.html#_gat.GA_Tracker_._setAllowAnchor">_setAllowAnchor</a></code> call to your tracking code, and makes RSS link tagging use a # as well.',
682
+ 'content' => $this->checkbox( 'allowanchor' ),
683
+ );
684
+ $rows[] = array(
685
+ 'id' => 'allowlinker',
686
+ 'label' => 'Add <code>_setAllowLinker</code>',
687
+ 'desc' => 'This adds a <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowLinker">_setAllowLinker</a></code> call to your tracking code, allowing you to use <code>_link</code> and related functions.',
688
+ 'content' => $this->checkbox( 'allowlinker' ),
689
+ );
690
+ $rows[] = array(
691
+ 'id' => 'allowhash',
692
+ 'label' => 'Set <code>_setAllowHash</code> to false',
693
+ 'desc' => 'This sets <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowHash">_setAllowHash</a></code> to false, allowing you to track subdomains etc.',
694
+ 'content' => $this->checkbox( 'allowhash' ),
695
+ );
696
+ $rows[] = array(
697
+ 'id' => 'anonymizeip',
698
+ 'label' => 'Anonymize IP\'s',
699
+ 'desc' => 'This adds <code><a href="http://code.google.com/apis/analytics/docs/gaJS/gaJSApi_gat.html#_gat._anonymizeIp">_anonymizeIp</a></code>, telling Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage.',
700
+ 'content' => $this->checkbox( 'anonymizeip' ),
701
+ );
702
+ $modules['Advanced Settings'] = 'advancedgasettings';
703
+ $this->postbox( 'advancedgasettings', 'Advanced Settings', $this->form_table( $rows ) . $this->save_button() );
704
+
705
+ $rows = array();
706
+ $rows[] = array(
707
+ 'id' => 'internallink',
708
+ 'label' => 'Internal links to track as outbound',
709
+ 'desc' => 'If you want to track all internal links that begin with <code>/out/</code>, enter <code>/out/</code> in the box above. If you have multiple prefixes you can separate them with comma\'s: <code>/out/,/recommends/</code>',
710
+ 'content' => $this->textinput( 'internallink' ),
711
+ );
712
+ $rows[] = array(
713
+ 'id' => 'internallinklabel',
714
+ 'label' => 'Label to use',
715
+ 'desc' => 'The label to use for these links, this will be added to where the click came from, so if the label is "aff", the label for a click from the content of an article becomes "outbound-article-aff".',
716
+ 'content' => $this->textinput( 'internallinklabel' ),
717
+ );
718
+ $modules['Internal Link Tracking'] = 'internallinktracking';
719
+ $this->postbox( 'internallinktracking', 'Internal Links to Track as Outbound', $this->form_table( $rows ) . $this->save_button() );
720
+
721
+ /* if (class_exists('RGForms') && GFCommon::$version >= '1.3.11') {
722
+ $pre_content = 'This plugin can automatically tag your Gravity Forms to track form submissions as either events or pageviews';
723
+ $rows = array();
724
+ $rows[] = array(
725
+ 'id' => 'taggfsubmit',
726
+ 'label' => 'Tag Gravity Forms',
727
+ 'content' => $this->checkbox('taggfsubmit'),
728
+ );
729
+ $rows[] = array(
730
+ 'id' => 'gfsubmiteventpv',
731
+ 'label' => 'Tag Gravity Forms as',
732
+ 'content' => '<select name="gfsubmiteventpv">
733
+ <option value="events" '.selected($options['gfsubmiteventpv'],'events',false).'>Events</option>
734
+ <option value="pageviews" '.selected($options['gfsubmiteventpv'],'pageviews',false).'>Pageviews</option>
735
+ </select>',
736
+ );
737
+ $this->postbox('gravityforms','Gravity Forms Settings',$pre_content.$this->form_table($rows).$this->save_button());
738
+ $modules['Gravity Forms'] = 'gravityforms';
739
+ }
740
+ */
741
+ if ( defined( 'WPSC_VERSION' ) ) {
742
+ $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.';
743
+ $rows = array();
744
+ $rows[] = array(
745
+ 'id' => 'wpec_tracking',
746
+ 'label' => 'Enable transaction tracking',
747
+ 'content' => $this->checkbox( 'wpec_tracking' ),
748
+ );
749
+ $this->postbox( 'wpecommerce', 'WordPress e-Commerce Settings', $pre_content . $this->form_table( $rows ) . $this->save_button() );
750
+ $modules['WordPress e-Commerce'] = 'wpecommerce';
751
+ }
752
+
753
+ global $Shopp;
754
+ if ( isset( $Shopp ) ) {
755
+ $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.';
756
+ $rows = array();
757
+ $rows[] = array(
758
+ 'id' => 'shopp_tracking',
759
+ 'label' => 'Enable transaction tracking',
760
+ 'content' => $this->checkbox( 'shopp_tracking' ),
761
+ );
762
+ $this->postbox( 'shoppecommerce', 'Shopp e-Commerce Settings', $pre_content . $this->form_table( $rows ) . $this->save_button() );
763
+ $modules['Shopp'] = 'shoppecommerce';
764
+ }
765
+ $pre_content = '<p>If you want to confirm that tracking on your blog is working as it should, enable this option and check the console in <a href="http://getfirebug.com/">Firebug</a> (for Firefox), <a href="http://getfirebug.com/firebuglite">Firebug Lite</a> (for other browsers) or Chrome &amp; Safari\'s Web Inspector. Be absolutely sure to disable debugging afterwards, as it is slower than normal tracking.</p><p><strong>Note</strong>: the debugging and firebug scripts are only loaded for admins.</p>';
766
+ $rows = array();
767
+ $rows[] = array(
768
+ 'id' => 'debug',
769
+ 'label' => 'Enable debug mode',
770
+ 'content' => $this->checkbox( 'debug' ),
771
+ );
772
+ $rows[] = array(
773
+ 'id' => 'firebuglite',
774
+ 'label' => 'Enable Firebug Lite',
775
+ 'content' => $this->checkbox( 'firebuglite' ),
776
+ );
777
+ $this->postbox( 'debugmode', 'Debug Mode', $pre_content . $this->form_table( $rows ) . $this->save_button() );
778
+ $modules['Debug Mode'] = 'debugmode';
779
+ ?>
780
+ </form>
781
+ <form action="<?php echo $this->plugin_options_url(); ?>" method="post"
782
+ onsubmit="javascript:return(confirm('Do you really want to reset all settings?'));">
783
+ <input type="hidden" name="reset" value="true"/>
784
+ <input type="hidden" name="plugin" value="google-analytics-for-wordpress"/>
785
+
786
+ <div class="submit"><input type="submit" value="Reset All Settings &raquo;"/></div>
787
+ </form>
788
+ </div>
789
+ </div>
790
  </div>
791
  <div class="postbox-container side" style="width:20%;">
792
+ <div class="metabox-holder">
793
  <div class="meta-box-sortables">
794
  <?php
795
+ if ( count( $modules ) > 0 )
796
+ $this->postbox( 'toc', 'List of Available Modules', $this->toc( $modules ) );
797
+ $this->postbox( 'donate', '<strong class="red">' . __( 'Help Spread the Word!' ) . '</strong>', '<p><strong>' . __( 'Want to help make this plugin even better? All donations are used to improve this plugin, so donate $20, $50 or $100 now!' ) . '</strong></p><form style="width:160px;margin:0 auto;" action="https://www.paypal.com/cgi-bin/webscr" method="post">
798
+ <input type="hidden" name="cmd" value="_s-xclick">
799
+ <input type="hidden" name="hosted_button_id" value="FW9FK4EBZ9FVJ">
800
+ <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" border="0" name="submit">
801
+ <img alt="" border="0" src="https://www.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
802
+ </form>'
803
+ . '<p>' . __( 'Or you could:' ) . '</p>'
804
+ . '<ul>'
805
+ . '<li><a href="http://wordpress.org/extend/plugins/google-analytics-for-wordpress/">' . __( 'Rate the plugin 5★ on WordPress.org' ) . '</a></li>'
806
+ . '<li><a href="http://wordpress.org/tags/google-analytics-for-wordpress">' . __( 'Help out other users in the forums' ) . '</a></li>'
807
+ . '<li>' . sprintf( __( 'Blog about it & link to the %1$splugin page%2$s' ), '<a href="http://yoast.com/wordpress/google-analytics/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=link&utm_campaign=wpgaplugin">', '</a>' ) . '</li>' );
808
+ $this->postbox( 'sitereview', '<strong>' . __( 'Want to Improve your Site?' ) . '</strong>', '<p>' . sprintf( __( 'If you want to improve your site, but don\'t know where to start, you should order a %1$swebsite review%2$s from Yoast!' ), '<a href="http://yoast.com/hire-me/website-review/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=link&utm_campaign=wpgaplugin">', '</a>' ) . '</p>' . '<p>' . __( 'The results of this review contain a full report of improvements for your site, encompassing my findings for improvements in different key areas such as SEO to Usability to Site Speed & more.' ) . '</p>' . '<p><a class="button-secondary" href="http://yoast.com/hire-me/website-review/#utm_source=wpadmin&utm_medium=sidebanner&utm_term=button&utm_campaign=wpgaplugin">' . __( 'Click here to read more &raquo;' ) . '</a></p>' );
809
+
810
+ $this->plugin_support();
811
+ $this->news();
812
  ?>
813
  </div>
814
  <br/><br/><br/>
815
  </div>
816
  </div>
817
+ </div>
818
+ <?php
819
+ }
820
+
821
  function set_defaults() {
822
  $options = array(
823
+ 'advancedsettings' => false,
824
+ 'allowanchor' => false,
825
+ 'allowhash' => false,
826
+ 'allowlinker' => false,
827
+ 'anonymizeip' => false,
828
+ 'customcode' => '',
829
+ 'cv_loggedin' => false,
830
+ 'cv_authorname' => false,
831
+ 'cv_category' => false,
832
+ 'cv_all_categories' => false,
833
+ 'cv_tags' => false,
834
+ 'cv_year' => false,
835
+ 'cv_post_type' => false,
836
+ 'debug' => false,
837
+ 'dlextensions' => 'doc,exe,js,pdf,ppt,tgz,zip,xls',
838
+ 'domain' => '',
839
+ 'domainorurl' => 'domain',
840
+ 'extrase' => false,
841
+ 'extraseurl' => '',
842
+ 'firebuglite' => false,
843
+ 'ga_token' => '',
844
+ 'ga_api_responses' => array(),
845
+ 'gajslocalhosting' => false,
846
+ 'gajsurl' => '',
847
+ 'ignore_userlevel' => '11',
848
+ 'internallink' => false,
849
+ 'internallinklabel' => '',
850
+ 'outboundpageview' => false,
851
+ 'downloadspageview' => false,
852
+ 'othercrossdomains' => '',
853
+ 'position' => 'footer',
854
+ 'primarycrossdomain' => '',
855
+ 'theme_updated' => false,
856
+ 'trackcommentform' => true,
857
+ 'trackcrossdomain' => false,
858
+ 'trackadsense' => false,
859
+ 'trackoutbound' => true,
860
+ 'trackregistration' => false,
861
+ 'rsslinktagging' => true,
862
+ 'uastring' => '',
863
+ 'version' => GAWP_VERSION,
864
  );
865
+ update_option( $this->optionname, $options );
866
  return $options;
867
  }
868
+
869
  function warning() {
870
+ $options = get_option( $this->optionname );
871
+ if ( !isset( $options['uastring'] ) || empty( $options['uastring'] ) ) {
872
+ 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>";
873
  }
874
  } // end warning()
875
 
878
  if ( isset( $_REQUEST['oauth_token'] ) ) {
879
  $o = get_option( $this->optionname );
880
  if ( isset( $o['gawp_oauth']['oauth_token'] ) && $o['gawp_oauth']['oauth_token'] == $_REQUEST['oauth_token'] ) {
881
+ $gdata = new WP_GData(
882
+ array(
883
+ 'scope' => 'https://www.google.com/analytics/feeds/',
884
  'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'
885
  ),
886
  $o['gawp_oauth']['oauth_token'],
899
  exit;
900
  }
901
 
902
+ if ( !empty( $_GET['reauth'] ) ) {
903
+ $gdata = new WP_GData(
904
+ array(
905
+ 'scope' => 'https://www.google.com/analytics/feeds/',
906
  'xoauth_displayname' => 'Google Analytics for WordPress by Yoast'
907
  )
908
  );
912
  $options = get_option( $this->optionname );
913
  unset( $options['ga_token'] );
914
  unset( $options['gawp_oauth']['access_token'] );
915
+ $options['gawp_oauth']['oauth_token'] = $request_token['oauth_token'];
916
  $options['gawp_oauth']['oauth_token_secret'] = $request_token['oauth_token_secret'];
917
  update_option( $this->optionname, $options );
918
 
930
  /**
931
  * Code that actually inserts stuff into pages.
932
  */
933
+ if ( !class_exists( 'GA_Filter' ) ) {
934
  class GA_Filter {
935
 
936
  /**
937
  * Cleans the variable to make it ready for storing in Google Analytics
938
  */
939
+ function ga_str_clean( $val ) {
940
+ return remove_accents( str_replace( '---', '-', str_replace( ' ', '-', strtolower( html_entity_decode( $val ) ) ) ) );
941
  }
942
+
943
  /*
944
+ * Insert the tracking code into the page
945
+ */
946
+ function spool_analytics() {
947
  global $wp_query;
948
  // echo '<!--'.print_r($wp_query,1).'-->';
949
 
950
+ $options = get_option( 'Yoast_Google_Analytics' );
951
 
952
+ if ( !isset( $options['uastring'] ) || $options['uastring'] == '' ) {
953
+ if ( current_user_can( 'manage_options' ) )
954
  echo "<!-- Google Analytics tracking code not shown because yo haven't chosen a Google Analytics account yet. -->\n";
955
  return;
956
  }
957
+
958
  /**
959
  * The order of custom variables is very, very important: custom vars should always take up the same slot to make analysis easy.
960
  */
961
  $customvarslot = 1;
962
+ if ( yoast_ga_do_tracking() && !is_preview() ) {
963
  $push = array();
964
 
965
  if ( $options['allowanchor'] )
967
 
968
  if ( $options['allowlinker'] )
969
  $push[] = "'_setAllowLinker',true";
970
+
971
  if ( $options['anonymizeip'] )
972
  $push[] = "'_gat._anonymizeIp'";
 
 
 
973
 
974
+ if ( isset( $options['domain'] ) && $options['domain'] != "" )
975
+ $push[] = "'_setDomainName','" . $options['domain'] . "'";
976
+
977
+ if ( isset( $options['trackcrossdomain'] ) && $options['trackcrossdomain'] )
978
+ $push[] = "'_setDomainName','" . $options['primarycrossdomain'] . "'";
979
 
980
+ if ( isset( $options['allowhash'] ) && $options['allowhash'] )
981
  $push[] = "'_setAllowHash',false";
982
 
983
  if ( $options['cv_loggedin'] ) {
984
  $current_user = wp_get_current_user();
985
  if ( $current_user && $current_user->ID != 0 )
986
+ $push[] = "'_setCustomVar',$customvarslot,'logged-in','" . $current_user->roles[0] . "',1";
987
  // 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.
988
  $customvarslot++;
989
+ }
990
 
991
+ if ( function_exists( 'is_post_type_archive' ) && is_post_type_archive() ) {
992
  if ( $options['cv_post_type'] ) {
993
  $post_type = get_post_type();
994
  if ( $post_type ) {
995
+ $push[] = "'_setCustomVar'," . $customvarslot . ",'post_type','" . $post_type . "',3";
996
+ $customvarslot++;
997
  }
998
  }
999
  } else if ( is_singular() && !is_home() ) {
1000
  if ( $options['cv_post_type'] ) {
1001
  $post_type = get_post_type();
1002
  if ( $post_type ) {
1003
+ $push[] = "'_setCustomVar'," . $customvarslot . ",'post_type','" . $post_type . "',3";
1004
+ $customvarslot++;
1005
  }
1006
  }
1007
  if ( $options['cv_authorname'] ) {
1008
+ $push[] = "'_setCustomVar',$customvarslot,'author','" . GA_Filter::ga_str_clean( get_the_author_meta( 'display_name', $wp_query->post->post_author ) ) . "',3";
1009
  $customvarslot++;
1010
  }
1011
  if ( $options['cv_tags'] ) {
1013
  if ( get_the_tags() ) {
1014
  $tagsstr = '';
1015
  foreach ( get_the_tags() as $tag ) {
1016
+ if ( $i > 0 )
1017
  $tagsstr .= ' ';
1018
  $tagsstr .= $tag->slug;
1019
  $i++;
1020
  }
1021
  // Max 64 chars for value and label combined, hence 64 - 4
1022
+ $tagsstr = substr( $tagsstr, 0, 60 );
1023
+ $push[] = "'_setCustomVar',$customvarslot,'tags','" . $tagsstr . "',3";
1024
  }
1025
  $customvarslot++;
1026
  }
1027
  if ( is_singular() ) {
1028
  if ( $options['cv_year'] ) {
1029
+ $push[] = "'_setCustomVar',$customvarslot,'year','" . get_the_time( 'Y' ) . "',3";
1030
  $customvarslot++;
1031
  }
1032
  if ( $options['cv_category'] && is_single() ) {
1033
  $cats = get_the_category();
1034
  if ( is_array( $cats ) && isset( $cats[0] ) )
1035
+ $push[] = "'_setCustomVar',$customvarslot,'category','" . $cats[0]->slug . "',3";
1036
  $customvarslot++;
1037
  }
1038
  if ( $options['cv_all_categories'] && is_single() ) {
1039
+ $i = 0;
1040
  $catsstr = '';
1041
  foreach ( (array) get_the_category() as $cat ) {
1042
+ if ( $i > 0 )
1043
  $catsstr .= ' ';
1044
  $catsstr .= $cat->slug;
1045
  $i++;
1046
  }
1047
  // Max 64 chars for value and label combined, hence 64 - 10
1048
+ $catsstr = substr( $catsstr, 0, 54 );
1049
+ $push[] = "'_setCustomVar',$customvarslot,'categories','" . $catsstr . "',3";
1050
  $customvarslot++;
1051
  }
1052
  }
1053
+ }
1054
 
1055
+ $push = apply_filters( 'yoast-ga-custom-vars', $push, $customvarslot );
1056
+
1057
+ $push = apply_filters( 'yoast-ga-push-before-pageview', $push );
1058
 
 
 
1059
  if ( is_404() ) {
1060
  $push[] = "'_trackPageview','/404.html?page=' + document.location.pathname + document.location.search + '&from=' + document.referrer";
1061
+ } else if ( $wp_query->is_search ) {
1062
+ $pushstr = "'_trackPageview','" . get_bloginfo( 'url' ) . "/?s=";
1063
+ if ( $wp_query->found_posts == 0 ) {
1064
+ $push[] = $pushstr . "no-results:" . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=no-results'";
1065
+ } else if ( $wp_query->found_posts == 1 ) {
1066
+ $push[] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=1-result'";
1067
+ } else if ( $wp_query->found_posts > 1 && $wp_query->found_posts < 6 ) {
1068
+ $push[] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=2-5-results'";
1069
  } else {
1070
+ $push[] = $pushstr . rawurlencode( $wp_query->query_vars['s'] ) . "&cat=plus-5-results'";
1071
  }
1072
  } else {
1073
  $push[] = "'_trackPageview'";
1074
  }
 
 
1075
 
1076
+ $push = apply_filters( 'yoast-ga-push-after-pageview', $push );
1077
+
1078
+ if ( defined( 'WPSC_VERSION' ) && $options['wpec_tracking'] )
1079
+ $push = GA_Filter::wpec_transaction_tracking( $push );
1080
+
1081
+ if ( $options['shopp_tracking'] ) {
1082
  global $Shopp;
1083
+ if ( isset( $Shopp ) )
1084
+ $push = GA_Filter::shopp_transaction_tracking( $push );
1085
  }
1086
+
1087
  $pushstr = "";
1088
+ foreach ( $push as $key ) {
1089
+ if ( !empty( $pushstr ) )
1090
  $pushstr .= ",";
1091
 
1092
+ $pushstr .= "[" . $key . "]";
1093
  }
1094
 
1095
+ if ( current_user_can( 'manage_options' ) && $options['firebuglite'] && $options['debug'] )
1096
  echo '<script src="https://getfirebug.com/firebug-lite.js" type="text/javascript"></script>';
1097
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1098
 
1099
+ <script type="text/javascript">//<![CDATA[
1100
+ // Google Analytics for WordPress by Yoast v<?php echo GAWP_VERSION; ?> | http://yoast.com/wordpress/google-analytics/
1101
+ var _gaq = _gaq || [];
1102
+ _gaq.push(['_setAccount', '<?php echo trim( $options["uastring"] ); ?>']);
1103
+ <?php
1104
+ if ( $options["extrase"] ) {
1105
+ if ( !empty( $options["extraseurl"] ) ) {
1106
+ $url = $options["extraseurl"];
1107
+ } else {
1108
+ $url = plugins_url( 'custom_se_async.js', __FILE__ );
1109
+ }
1110
+ echo '</script><script src="' . $url . '" type="text/javascript"></script>' . "\n" . '<script type="text/javascript">';
1111
+ }
 
 
 
1112
 
1113
+ if ( $options['customcode'] && trim( $options['customcode'] ) != '' )
1114
+ echo "\t" . stripslashes( $options['customcode'] ) . "\n";
1115
+ ?>
1116
+ _gaq.push(<?php echo $pushstr; ?>);
1117
+ (function () {
1118
+ var ga = document.createElement('script');
1119
+ ga.type = 'text/javascript';
1120
+ ga.async = true;
1121
+ ga.src = <?php
1122
+ if ( $options['gajslocalhosting'] && !empty( $options['gajsurl'] ) ) {
1123
+ echo "'" . $options['gajsurl'] . "';";
1124
+ } else {
1125
+ $script = 'ga.js';
1126
+ if ( current_user_can( 'manage_options' ) && $options['debug'] )
1127
+ $script = 'u/ga_debug.js';
1128
+ echo "('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/" . $script . "';";
1129
+ }
1130
+ ?>
1131
+
1132
+ var s = document.getElementsByTagName('script')[0];
1133
+ s.parentNode.insertBefore(ga, s);
1134
+ })();
1135
+ //]]></script>
1136
+ <?php
1137
  } else if ( $options["uastring"] != "" ) {
1138
+ echo "<!-- Google Analytics tracking code not shown because users over level " . $options["ignore_userlevel"] . " are ignored -->\n";
1139
+ }
1140
  }
1141
 
1142
  /*
1143
  * Insert the AdSense parameter code into the page. This'll go into the header per Google's instructions.
1144
  */
1145
  function spool_adsense() {
1146
+ $options = get_option( 'Yoast_Google_Analytics' );
1147
  if ( $options["uastring"] != "" && yoast_ga_do_tracking() && !is_preview() ) {
1148
+ echo '<script type="text/javascript">' . "\n";
1149
+ echo "\t" . 'window.google_analytics_uacct = "' . $options["uastring"] . '";' . "\n";
1150
+ echo '</script>' . "\n";
1151
  }
1152
+ }
1153
 
1154
  function ga_get_tracking_prefix() {
1155
+ $options = get_option( 'Yoast_Google_Analytics' );
1156
+ return ( empty( $options['trackprefix'] ) ) ? '/yoast-ga/' : $options['trackprefix'];
1157
  }
1158
+
1159
+ function ga_get_tracking_link( $prefix, $target, $jsprefix = 'javascript:' ) {
1160
+ $options = get_option( 'Yoast_Google_Analytics' );
1161
+ if (
1162
+ ( $prefix != 'download' && $options['outboundpageview'] ) ||
1163
+ ( $prefix == 'download' && $options['downloadspageview'] )
1164
+ ) {
1165
+ $prefix = GA_Filter::ga_get_tracking_prefix() . $prefix;
1166
+ $pushstr = "['_trackPageview','" . $prefix . "/" . esc_js( esc_url( $target ) ) . "']";
1167
  } else {
1168
+ $pushstr = "['_trackEvent','" . $prefix . "','" . esc_js( esc_url( $target ) ) . "']";
1169
  }
1170
+ return $jsprefix . "_gaq.push(" . $pushstr . ");";
1171
  }
1172
+
1173
+ function ga_get_domain( $uri ) {
1174
+ $hostPattern = "/^(http:\/\/)?([^\/]+)/i";
1175
  $domainPatternUS = "/[^\.\/]+\.[^\.\/]+$/";
1176
  $domainPatternUK = "/[^\.\/]+\.[^\.\/]+\.[^\.\/]+$/";
1177
 
1178
+ preg_match( $hostPattern, $uri, $matches );
1179
  $host = $matches[2];
1180
+ if ( preg_match( "/.*\..*\..*\..*$/", $host ) )
1181
+ preg_match( $domainPatternUK, $host, $matches );
1182
  else
1183
+ preg_match( $domainPatternUS, $host, $matches );
1184
 
1185
+ return array( "domain"=> $matches[0], "host"=> $host );
1186
  }
1187
 
1188
+ function ga_parse_link( $category, $matches ) {
1189
+ $origin = GA_Filter::ga_get_domain( $_SERVER["HTTP_HOST"] );
1190
+ $options = get_option( 'Yoast_Google_Analytics' );
1191
+
1192
  // Break out immediately if the link is not an http or https link.
1193
+ if ( strpos( $matches[2], "http" ) !== 0 ) {
1194
  $target = false;
1195
+ } else if ( ( strpos( $matches[2], "mailto" ) === 0 ) ) {
1196
  $target = 'email';
1197
  } else {
1198
+ $target = GA_Filter::ga_get_domain( $matches[3] );
1199
  }
1200
+ $trackBit = "";
1201
+ $extension = substr( strrchr( $matches[3], '.' ), 1 );
1202
+ $dlextensions = explode( ",", str_replace( '.', '', $options['dlextensions'] ) );
1203
  if ( $target ) {
1204
  if ( $target == 'email' ) {
1205
+ $trackBit = GA_Filter::ga_get_tracking_link( 'mailto', str_replace( 'mailto:', '', $matches[3] ), '' );
1206
+ } else if ( in_array( $extension, $dlextensions ) ) {
1207
+ $trackBit = GA_Filter::ga_get_tracking_link( 'download', $matches[3], '' );
1208
+ } else if ( $target["domain"] != $origin["domain"] ) {
1209
+ $crossdomains = array();
1210
+ if ( isset( $options['othercrossdomains'] ) )
1211
+ $crossdomains = explode( ',', str_replace( ' ', '', $options['othercrossdomains'] ) );
1212
+ if ( isset( $options['trackcrossdomain'] ) && $options['trackcrossdomain'] && in_array( $target["host"], $crossdomains ) ) {
1213
  $trackBit = '_gaq.push([\'_link\', \'' . $matches[2] . '//' . $matches[3] . '\']); return false;"';
1214
+ } else if ( $options['trackoutbound'] && in_array( $options['domainorurl'], array( 'domain', 'url' ) ) ) {
1215
+ $url = $options['domainorurl'] == 'domain' ? $target["host"] : $matches[3];
1216
+ $trackBit = GA_Filter::ga_get_tracking_link( $category, $url, '' );
1217
  }
1218
+ $trackBit = GA_Filter::ga_get_tracking_link( $category, $url, '' );
1219
+ } else if ( $target["domain"] == $origin["domain"] && isset( $options['internallink'] ) && $options['internallink'] != '' ) {
1220
+ $url = preg_replace( '|' . $origin["host"] . '|', '', $matches[3] );
1221
+ $extintlinks = explode( ',', $options['internallink'] );
1222
+ foreach ( $extintlinks as $link ) {
1223
+ if ( preg_match( '|^' . trim( $link ) . '|', $url, $match ) ) {
1224
  $label = $options['internallinklabel'];
1225
+ if ( $label == '' )
1226
  $label = 'int';
1227
+ $trackBit = GA_Filter::ga_get_tracking_link( $category . '-' . $label, $url, '' );
1228
+ }
1229
  }
1230
  }
1231
+ }
1232
+ if ( $trackBit != "" ) {
1233
+ if ( preg_match( '/onclick=[\'\"](.*?)[\'\"]/i', $matches[4] ) > 0 ) {
1234
  // Check for manually tagged outbound clicks, and replace them with the tracking of choice.
1235
+ if ( preg_match( '/.*_track(Pageview|Event).*/i', $matches[4] ) > 0 ) {
1236
+ $matches[4] = preg_replace( '/onclick=[\'\"](javascript:)?(.*;)?[a-zA-Z0-9]+\._track(Pageview|Event)\([^\)]+\)(;)?(.*)?[\'\"]/i', 'onclick="javascript:' . $trackBit . '$2$5"', $matches[4] );
1237
  } else {
1238
+ $matches[4] = preg_replace( '/onclick=[\'\"](javascript:)?(.*?)[\'\"]/i', 'onclick="javascript:' . $trackBit . '$2"', $matches[4] );
1239
  }
1240
  } else {
1241
  $matches[4] = 'onclick="javascript:' . $trackBit . '"' . $matches[4];
1242
+ }
1243
  }
1244
  return '<a ' . $matches[1] . 'href="' . $matches[2] . '//' . $matches[3] . '"' . ' ' . $matches[4] . '>' . $matches[5] . '</a>';
1245
  }
1246
 
1247
+ function ga_parse_article_link( $matches ) {
1248
+ return GA_Filter::ga_parse_link( 'outbound-article', $matches );
1249
  }
1250
 
1251
+ function ga_parse_comment_link( $matches ) {
1252
+ return GA_Filter::ga_parse_link( 'outbound-comment', $matches );
1253
  }
1254
 
1255
+ function ga_parse_widget_link( $matches ) {
1256
+ return GA_Filter::ga_parse_link( 'outbound-widget', $matches );
1257
  }
1258
 
1259
+ function ga_parse_nav_menu( $matches ) {
1260
+ return GA_Filter::ga_parse_link( 'outbound-menu', $matches );
1261
  }
1262
+
1263
+ function widget_content( $text ) {
1264
  if ( !yoast_ga_do_tracking() )
1265
  return $text;
1266
  static $anchorPattern = '/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
1267
+ $text = preg_replace_callback( $anchorPattern, array( 'GA_Filter', 'ga_parse_widget_link' ), $text );
1268
  return $text;
1269
  }
1270
+
1271
+ function the_content( $text ) {
1272
  if ( !yoast_ga_do_tracking() )
1273
  return $text;
1274
 
1275
+ if ( !is_feed() ) {
1276
  static $anchorPattern = '/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
1277
+ $text = preg_replace_callback( $anchorPattern, array( 'GA_Filter', 'ga_parse_article_link' ), $text );
1278
  }
1279
  return $text;
1280
  }
1281
 
1282
+ function nav_menu( $text ) {
1283
  if ( !yoast_ga_do_tracking() )
1284
  return $text;
1285
 
1286
+ if ( !is_feed() ) {
1287
  static $anchorPattern = '/<a (.*?)href=[\'\"](.*?)\/\/([^\'\"]+?)[\'\"](.*?)>(.*?)<\/a>/i';
1288
+ $text = preg_replace_callback( $anchorPattern, array( 'GA_Filter', 'ga_parse_nav_menu' ), $text );
1289
  }
1290
  return $text;
1291
  }
1292
+
1293
+ function comment_text( $text ) {
1294
  if ( !yoast_ga_do_tracking() )
1295
  return $text;
1296
 
1297
+ if ( !is_feed() ) {
1298
  static $anchorPattern = '/<a (.*?)href="(.*?)\/\/(.*?)"(.*?)>(.*?)<\/a>/i';
1299
+ $text = preg_replace_callback( $anchorPattern, array( 'GA_Filter', 'ga_parse_comment_link' ), $text );
1300
  }
1301
  return $text;
1302
  }
1303
 
1304
+ function comment_author_link( $text ) {
1305
+ $options = get_option( 'Yoast_Google_Analytics' );
1306
 
1307
  if ( !yoast_ga_do_tracking() )
1308
  return $text;
1309
 
1310
+ static $anchorPattern = '/(.*\s+.*?href\s*=\s*)["\'](.*?)["\'](.*)/';
1311
+ preg_match( $anchorPattern, $text, $matches );
1312
+ if ( !isset( $matches[2] ) || $matches[2] == "" ) return $text;
1313
 
1314
  $trackBit = '';
1315
+ $target = GA_Filter::ga_get_domain( $matches[2] );
1316
+ $origin = GA_Filter::ga_get_domain( $_SERVER["HTTP_HOST"] );
1317
+ if ( $target["domain"] != $origin["domain"] ) {
1318
  if ( isset( $options['domainorurl'] ) && $options['domainorurl'] == "domain" )
1319
  $url = $target["host"];
1320
  else
1321
  $url = $matches[2];
1322
+ $trackBit = 'onclick="' . GA_Filter::ga_get_tracking_link( 'outbound-commentauthor', $url ) . '"';
1323
+ }
1324
+ return $matches[1] . "\"" . $matches[2] . "\" " . $trackBit . " " . $matches[3];
1325
  }
1326
+
1327
+ function bookmarks( $bookmarks ) {
1328
  if ( !yoast_ga_do_tracking() )
1329
  return $bookmarks;
1330
+
1331
  $i = 0;
1332
+ while ( $i < count( $bookmarks ) ) {
1333
+ $target = GA_Filter::ga_get_domain( $bookmarks[$i]->link_url );
1334
+ $sitedomain = GA_Filter::ga_get_domain( get_bloginfo( 'url' ) );
1335
+ if ( $target['host'] == $sitedomain['host'] ) {
1336
  $i++;
1337
  continue;
1338
  }
1340
  $url = $target["host"];
1341
  else
1342
  $url = $bookmarks[$i]->link_url;
1343
+ $trackBit = '" onclick="' . GA_Filter::ga_get_tracking_link( 'outbound-blogroll', $url );
1344
  $bookmarks[$i]->link_target .= $trackBit;
1345
  $i++;
1346
  }
1347
  return $bookmarks;
1348
  }
1349
+
1350
+ function rsslinktagger( $guid ) {
1351
+ $options = get_option( 'Yoast_Google_Analytics' );
1352
  global $wp, $post;
1353
  if ( is_feed() ) {
1354
  if ( $options['allowanchor'] ) {
1355
  $delimiter = '#';
1356
  } else {
1357
  $delimiter = '?';
1358
+ if ( strpos( $guid, $delimiter ) > 0 )
1359
  $delimiter = '&amp;';
1360
  }
1361
+ return $guid . $delimiter . 'utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=' . urlencode( $post->post_name );
1362
  }
1363
  return $guid;
1364
  }
1365
+
1366
  function wpec_transaction_tracking( $push ) {
1367
  global $wpdb, $purchlogs, $cart_log_id;
1368
+ if ( !isset( $cart_log_id ) || empty( $cart_log_id ) )
1369
  return $push;
1370
 
1371
+ $city = $wpdb->get_var( "SELECT tf.value
1372
+ FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " tf
1373
+ LEFT JOIN " . WPSC_TABLE_CHECKOUT_FORMS . " cf
1374
  ON cf.id = tf.form_id
1375
  WHERE cf.type = 'city'
1376
+ AND log_id = " . $cart_log_id );
1377
 
1378
+ $country = $wpdb->get_var( "SELECT tf.value
1379
+ FROM " . WPSC_TABLE_SUBMITED_FORM_DATA . " tf
1380
+ LEFT JOIN " . WPSC_TABLE_CHECKOUT_FORMS . " cf
1381
  ON cf.id = tf.form_id
1382
  WHERE cf.type = 'country'
1383
+ AND log_id = " . $cart_log_id );
1384
 
1385
+ $cart_items = $wpdb->get_results( "SELECT * FROM " . WPSC_TABLE_CART_CONTENTS . " WHERE purchaseid = " . $cart_log_id, ARRAY_A );
1386
 
1387
+ $total_shipping = $purchlogs->allpurchaselogs[0]->base_shipping;
1388
+ $total_tax = 0;
1389
  foreach ( $cart_items as $item ) {
1390
  $total_shipping += $item['pnp'];
1391
+ $total_tax += $item['tax_charged'];
1392
  }
1393
 
1394
+ $push[] = "'_addTrans','" . $cart_log_id . "'," // Order ID
1395
+ . "'" . GA_Filter::ga_str_clean( get_bloginfo( 'name' ) ) . "'," // Store name
1396
+ . "'" . nzshpcrt_currency_display( $purchlogs->allpurchaselogs[0]->totalprice, 1, true, false, true ) . "'," // Total price
1397
+ . "'" . nzshpcrt_currency_display( $total_tax, 1, true, false, true ) . "'," // Tax
1398
+ . "'" . nzshpcrt_currency_display( $total_shipping, 1, true, false, true ) . "'," // Shipping
1399
+ . "'" . $city . "'," // City
1400
+ . "''," // State
1401
+ . "'" . $country . "'"; // Country
 
 
 
1402
 
1403
+ foreach ( $cart_items as $item ) {
1404
+ $item['sku'] = $wpdb->get_var( "SELECT meta_value FROM " . WPSC_TABLE_PRODUCTMETA . " WHERE meta_key = 'sku' AND product_id = '" . $item['prodid'] . "' LIMIT 1" );
1405
+
1406
+ $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'] . "'" );
1407
+ $push[] = "'_addItem',"
1408
+ . "'" . $cart_log_id . "'," // Order ID
1409
+ . "'" . $item['sku'] . "'," // Item SKU
1410
+ . "'" . str_replace( "'", "", $item['name'] ) . "'," // Item Name
1411
+ . "'" . $item['category'] . "'," // Item Category
1412
+ . "'" . $item['price'] . "'," // Item Price
1413
+ . "'" . $item['quantity'] . "'"; // Item Quantity
1414
  }
1415
  $push[] = "'_trackTrans'";
1416
 
1417
  return $push;
1418
  }
1419
+
1420
  function shopp_transaction_tracking( $push ) {
1421
  global $Shopp;
1422
 
1423
  // Only process if we're in the checkout process (receipt page)
1424
+ if ( version_compare( substr( SHOPP_VERSION, 0, 3 ), '1.1' ) >= 0 ) {
1425
  // Only process if we're in the checkout process (receipt page)
1426
+ if ( function_exists( 'is_shopp_page' ) && !is_shopp_page( 'checkout' ) ) return $push;
1427
+ if ( empty( $Shopp->Order->purchase ) ) return $push;
1428
 
1429
+ $Purchase = new Purchase( $Shopp->Order->purchase );
1430
  $Purchase->load_purchased();
1431
  } else {
1432
  // For 1.0.x
1433
  // Only process if we're in the checkout process (receipt page)
1434
+ if ( function_exists( 'is_shopp_page' ) && !is_shopp_page( 'checkout' ) ) return $push;
1435
  // Only process if we have valid order data
1436
+ if ( !isset( $Shopp->Cart->data->Purchase ) ) return $push;
1437
+ if ( empty( $Shopp->Cart->data->Purchase->id ) ) return $push;
1438
 
1439
  $Purchase = $Shopp->Cart->data->Purchase;
1440
  }
1441
 
1442
  $push[] = "'_addTrans',"
1443
+ . "'" . $Purchase->id . "'," // Order ID
1444
+ . "'" . GA_Filter::ga_str_clean( get_bloginfo( 'name' ) ) . "'," // Store
1445
+ . "'" . number_format( $Purchase->total, 2 ) . "'," // Total price
1446
+ . "'" . number_format( $Purchase->tax, 2 ) . "'," // Tax
1447
+ . "'" . number_format( $Purchase->shipping, 2 ) . "'," // Shipping
1448
+ . "'" . $Purchase->city . "'," // City
1449
+ . "'" . $Purchase->state . "'," // State
1450
+ . "'.$Purchase->country.'"; // Country
1451
+
1452
+ foreach ( $Purchase->purchased as $item ) {
1453
+ $sku = empty( $item->sku ) ? 'PID-' . $item->product . str_pad( $item->price, 4, '0', STR_PAD_LEFT ) : $item->sku;
1454
+ $push[] = "'_addItem',"
1455
+ . "'" . $Purchase->id . "',"
1456
+ . "'" . $sku . "',"
1457
+ . "'" . str_replace( "'", "", $item->name ) . "',"
1458
+ . "'" . $item->optionlabel . "',"
1459
+ . "'" . number_format( $item->unitprice, 2 ) . "',"
1460
+ . "'" . $item->quantity . "'";
1461
  }
1462
  $push[] = "'_trackTrans'";
1463
  return $push;
1464
  }
1465
+
1466
  } // class GA_Filter
1467
  } // endif
1468
 
1469
  /**
1470
  * If setAllowAnchor is set to true, GA ignores all links tagged "normally", so we redirect all "normally" tagged URL's
1471
+ * to one tagged with a hash.
1472
  */
1473
  function ga_utm_hashtag_redirect() {
1474
+ if ( isset( $_SERVER['REQUEST_URI'] ) ) {
1475
+ if ( strpos( $_SERVER['REQUEST_URI'], "utm_" ) !== false ) {
1476
  $url = 'http://';
1477
+ if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] != "" ) {
1478
  $url = 'https://';
1479
  }
1480
  $url .= $_SERVER['SERVER_NAME'];
1481
+ if ( strpos( $_SERVER['REQUEST_URI'], "?utm_" ) !== false ) {
1482
+ $url .= str_replace( "?utm_", "#utm_", $_SERVER['REQUEST_URI'] );
1483
+ } else if ( strpos( $_SERVER['REQUEST_URI'], "&utm_" ) !== false ) {
1484
+ $url .= substr_replace( $_SERVER['REQUEST_URI'], "#utm_", strpos( $_SERVER['REQUEST_URI'], "&utm_" ), 5 );
1485
  }
1486
+ wp_redirect( $url, 301 );
1487
  exit;
1488
  }
1489
  }
1491
 
1492
  function yoast_ga_do_tracking() {
1493
  $current_user = wp_get_current_user();
1494
+
1495
+ if ( 0 == $current_user->ID )
1496
  return true;
1497
+
1498
+ $yoast_ga_options = get_option( 'Yoast_Google_Analytics' );
1499
+
1500
+ if ( ( $current_user->user_level >= $yoast_ga_options["ignore_userlevel"] ) )
1501
  return false;
1502
  else
1503
  return true;
1504
  }
1505
 
1506
  function track_comment_form_head() {
1507
+ if ( is_singular() ) {
1508
+ global $post;
1509
+ $yoast_ga_options = get_option( 'Yoast_Google_Analytics' );
1510
+ if ( yoast_ga_do_tracking()
1511
+ && isset( $yoast_ga_options["trackcommentform"] )
1512
+ && $yoast_ga_options["trackcommentform"]
1513
+ && ( 'open' == $post->comment_status )
1514
+ )
1515
+ wp_enqueue_script( 'jquery' );
1516
+ }
1517
  }
1518
+
1519
+ add_action( 'wp_print_scripts', 'track_comment_form_head' );
1520
 
1521
  $comment_form_id = 'commentform';
1522
+ function yoast_get_comment_form_id( $args ) {
1523
  global $comment_form_id;
1524
  $comment_form_id = $args['id_form'];
1525
  return $args;
1526
  }
1527
+
1528
+ add_filter( 'comment_form_defaults', 'yoast_get_comment_form_id', 99, 1 );
1529
 
1530
  function yoast_track_comment_form() {
1531
+ global $comment_form_id, $post;
1532
+ $yoast_ga_options = get_option( 'Yoast_Google_Analytics' );
1533
+ if ( yoast_ga_do_tracking() && $yoast_ga_options["trackcommentform"] ) {
1534
+ ?>
1535
+ <script type="text/javascript">
1536
+ jQuery(document).ready(function () {
1537
+ jQuery('#<?php echo $comment_form_id; ?>').submit(function () {
1538
+ _gaq.push(
1539
+ ['_setAccount', '<?php echo $yoast_ga_options["uastring"]; ?>'],
1540
+ ['_trackEvent', 'comment', 'submit']
1541
+ );
1542
+ });
1543
+ });
1544
+ </script>
1545
+ <?php
1546
+ }
1547
  }
 
1548
 
1549
+ add_action( 'comment_form_after', 'yoast_track_comment_form' );
1550
+
1551
+ function yoast_sanitize_relative_links( $content ) {
1552
+ preg_match( "|^http(s)?://([^/]+)|i", get_bloginfo( 'url' ), $match );
1553
+ $content = preg_replace( "/<a([^>]*) href=('|\")\/([^\"']*)('|\")/", "<a\${1} href=\"" . $match[0] . "/" . "\${3}\"", $content );
1554
 
1555
+ if ( is_singular() ) {
1556
+ $content = preg_replace( "/<a([^>]*) href=('|\")#([^\"']*)('|\")/", "<a\${1} href=\"" . get_permalink() . "#" . "\${3}\"", $content );
1557
+ }
1558
+ return $content;
1559
  }
1560
+
1561
+ add_filter( 'the_content', 'yoast_sanitize_relative_links', 98 );
1562
+ add_filter( 'widget_text', 'yoast_sanitize_relative_links', 98 );
1563
 
1564
  function yoast_analytics() {
1565
+ $options = get_option( 'Yoast_Google_Analytics' );
1566
+ if ( $options['position'] == 'manual' )
1567
  GA_Filter::spool_analytics();
1568
  else
1569
  echo '<!-- Please set Google Analytics position to "manual" in the settings, or remove this call to yoast_analytics(); -->';
1570
  }
1571
 
1572
+ $gaf = new GA_Filter();
 
1573
 
1574
+ if ( !is_array( $options ) ) {
1575
+ $options = get_option( 'GoogleAnalyticsPP' );
1576
+ if ( !is_array( $options ) ) {
1577
  $ga_admin->set_defaults();
1578
  } else {
1579
+ delete_option( 'GoogleAnalyticsPP' );
1580
+ if ( $options['admintracking'] ) {
1581
  $options["ignore_userlevel"] = '8';
1582
+ unset( $options['admintracking'] );
1583
  } else {
1584
  $options["ignore_userlevel"] = '11';
1585
  }
1586
+ update_option( 'Yoast_Google_Analytics', $options );
1587
  }
1588
  } else {
1589
  if ( isset( $options['allowanchor'] ) && $options['allowanchor'] ) {
1590
+ add_action( 'init', 'ga_utm_hashtag_redirect', 1 );
1591
  }
1592
 
1593
+ if ( ( isset( $options['trackoutbound'] ) && $options['trackoutbound'] ) ||
1594
+ ( isset( $options['trackcrossdomain'] ) && $options['trackcrossdomain'] )
1595
+ ) {
1596
  // filters alter the existing content
1597
+ add_filter( 'the_content', array( 'GA_Filter', 'the_content' ), 99 );
1598
+ add_filter( 'widget_text', array( 'GA_Filter', 'widget_content' ), 99 );
1599
+ add_filter( 'the_excerpt', array( 'GA_Filter', 'the_content' ), 99 );
1600
+ add_filter( 'comment_text', array( 'GA_Filter', 'comment_text' ), 99 );
1601
+ add_filter( 'get_bookmarks', array( 'GA_Filter', 'bookmarks' ), 99 );
1602
+ add_filter( 'get_comment_author_link', array( 'GA_Filter', 'comment_author_link' ), 99 );
1603
+ add_filter( 'wp_nav_menu', array( 'GA_Filter', 'nav_menu' ), 99 );
1604
  }
1605
 
1606
  if ( isset( $options['trackadsense'] ) && $options['trackadsense'] )
1607
+ add_action( 'wp_head', array( 'GA_Filter', 'spool_adsense' ), 1 );
1608
 
1609
  if ( !isset( $options['position'] ) )
1610
  $options['position'] = 'header';
1611
+
1612
+ switch ( $options['position'] ) {
1613
  case 'manual':
1614
  // No need to insert here, bail NOW.
1615
  break;
1616
  case 'header':
1617
  default:
1618
+ add_action( 'wp_head', array( 'GA_Filter', 'spool_analytics' ), 2 );
1619
  break;
1620
  }
1621
 
1622
  if ( isset( $options['trackregistration'] ) && $options['trackregistration'] )
1623
+ add_action( 'login_head', array( 'GA_Filter', 'spool_analytics' ), 20 );
1624
 
1625
  if ( isset( $options['rsslinktagging'] ) && $options['rsslinktagging'] )
1626
+ add_filter( 'the_permalink_rss', array( 'GA_Filter', 'rsslinktagger' ), 99 );
1627
+
1628
  }
license.txt ADDED
@@ -0,0 +1,621 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+ Preamble
9
+
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
12
+
13
+ The licenses for most software and other practical works are designed
14
+ to take away your freedom to share and change the works. By contrast,
15
+ the GNU General Public License is intended to guarantee your freedom to
16
+ share and change all versions of a program--to make sure it remains free
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
21
+
22
+ When we speak of free software, we are referring to freedom, not
23
+ price. Our General Public Licenses are designed to make sure that you
24
+ have the freedom to distribute copies of free software (and charge for
25
+ them if you wish), that you receive source code or can get it if you
26
+ want it, that you can change the software or use pieces of it in new
27
+ free programs, and that you know you can do these things.
28
+
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
67
+
68
+ The precise terms and conditions for copying, distribution and
69
+ modification follow.
70
+
71
+ TERMS AND CONDITIONS
72
+
73
+ 0. Definitions.
74
+
75
+ "This License" refers to version 3 of the GNU General Public License.
76
+
77
+ "Copyright" also means copyright-like laws that apply to other kinds of
78
+ works, such as semiconductor masks.
79
+
80
+ "The Program" refers to any copyrightable work licensed under this
81
+ License. Each licensee is addressed as "you". "Licensees" and
82
+ "recipients" may be individuals or organizations.
83
+
84
+ To "modify" a work means to copy from or adapt all or part of the work
85
+ in a fashion requiring copyright permission, other than the making of an
86
+ exact copy. The resulting work is called a "modified version" of the
87
+ earlier work or a work "based on" the earlier work.
88
+
89
+ A "covered work" means either the unmodified Program or a work based
90
+ on the Program.
91
+
92
+ To "propagate" a work means to do anything with it that, without
93
+ permission, would make you directly or secondarily liable for
94
+ infringement under applicable copyright law, except executing it on a
95
+ computer or modifying a private copy. Propagation includes copying,
96
+ distribution (with or without modification), making available to the
97
+ public, and in some countries other activities as well.
98
+
99
+ To "convey" a work means any kind of propagation that enables other
100
+ parties to make or receive copies. Mere interaction with a user through
101
+ a computer network, with no transfer of a copy, is not conveying.
102
+
103
+ An interactive user interface displays "Appropriate Legal Notices"
104
+ to the extent that it includes a convenient and prominently visible
105
+ feature that (1) displays an appropriate copyright notice, and (2)
106
+ tells the user that there is no warranty for the work (except to the
107
+ extent that warranties are provided), that licensees may convey the
108
+ work under this License, and how to view a copy of this License. If
109
+ the interface presents a list of user commands or options, such as a
110
+ menu, a prominent item in the list meets this criterion.
111
+
112
+ 1. Source Code.
113
+
114
+ The "source code" for a work means the preferred form of the work
115
+ for making modifications to it. "Object code" means any non-source
116
+ form of a work.
117
+
118
+ A "Standard Interface" means an interface that either is an official
119
+ standard defined by a recognized standards body, or, in the case of
120
+ interfaces specified for a particular programming language, one that
121
+ is widely used among developers working in that language.
122
+
123
+ The "System Libraries" of an executable work include anything, other
124
+ than the work as a whole, that (a) is included in the normal form of
125
+ packaging a Major Component, but which is not part of that Major
126
+ Component, and (b) serves only to enable use of the work with that
127
+ Major Component, or to implement a Standard Interface for which an
128
+ implementation is available to the public in source code form. A
129
+ "Major Component", in this context, means a major essential component
130
+ (kernel, window system, and so on) of the specific operating system
131
+ (if any) on which the executable work runs, or a compiler used to
132
+ produce the work, or an object code interpreter used to run it.
133
+
134
+ The "Corresponding Source" for a work in object code form means all
135
+ the source code needed to generate, install, and (for an executable
136
+ work) run the object code and to modify the work, including scripts to
137
+ control those activities. However, it does not include the work's
138
+ System Libraries, or general-purpose tools or generally available free
139
+ programs which are used unmodified in performing those activities but
140
+ which are not part of the work. For example, Corresponding Source
141
+ includes interface definition files associated with source files for
142
+ the work, and the source code for shared libraries and dynamically
143
+ linked subprograms that the work is specifically designed to require,
144
+ such as by intimate data communication or control flow between those
145
+ subprograms and other parts of the work.
146
+
147
+ The Corresponding Source need not include anything that users
148
+ can regenerate automatically from other parts of the Corresponding
149
+ Source.
150
+
151
+ The Corresponding Source for a work in source code form is that
152
+ same work.
153
+
154
+ 2. Basic Permissions.
155
+
156
+ All rights granted under this License are granted for the term of
157
+ copyright on the Program, and are irrevocable provided the stated
158
+ conditions are met. This License explicitly affirms your unlimited
159
+ permission to run the unmodified Program. The output from running a
160
+ covered work is covered by this License only if the output, given its
161
+ content, constitutes a covered work. This License acknowledges your
162
+ rights of fair use or other equivalent, as provided by copyright law.
163
+
164
+ You may make, run and propagate covered works that you do not
165
+ convey, without conditions so long as your license otherwise remains
166
+ in force. You may convey covered works to others for the sole purpose
167
+ of having them make modifications exclusively for you, or provide you
168
+ with facilities for running those works, provided that you comply with
169
+ the terms of this License in conveying all material for which you do
170
+ not control copyright. Those thus making or running the covered works
171
+ for you must do so exclusively on your behalf, under your direction
172
+ and control, on terms that prohibit them from making any copies of
173
+ your copyrighted material outside their relationship with you.
174
+
175
+ Conveying under any other circumstances is permitted solely under
176
+ the conditions stated below. Sublicensing is not allowed; section 10
177
+ makes it unnecessary.
178
+
179
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180
+
181
+ No covered work shall be deemed part of an effective technological
182
+ measure under any applicable law fulfilling obligations under article
183
+ 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184
+ similar laws prohibiting or restricting circumvention of such
185
+ measures.
186
+
187
+ When you convey a covered work, you waive any legal power to forbid
188
+ circumvention of technological measures to the extent such circumvention
189
+ is effected by exercising rights under this License with respect to
190
+ the covered work, and you disclaim any intention to limit operation or
191
+ modification of the work as a means of enforcing, against the work's
192
+ users, your or third parties' legal rights to forbid circumvention of
193
+ technological measures.
194
+
195
+ 4. Conveying Verbatim Copies.
196
+
197
+ You may convey verbatim copies of the Program's source code as you
198
+ receive it, in any medium, provided that you conspicuously and
199
+ appropriately publish on each copy an appropriate copyright notice;
200
+ keep intact all notices stating that this License and any
201
+ non-permissive terms added in accord with section 7 apply to the code;
202
+ keep intact all notices of the absence of any warranty; and give all
203
+ recipients a copy of this License along with the Program.
204
+
205
+ You may charge any price or no price for each copy that you convey,
206
+ and you may offer support or warranty protection for a fee.
207
+
208
+ 5. Conveying Modified Source Versions.
209
+
210
+ You may convey a work based on the Program, or the modifications to
211
+ produce it from the Program, in the form of source code under the
212
+ terms of section 4, provided that you also meet all of these conditions:
213
+
214
+ a) The work must carry prominent notices stating that you modified
215
+ it, and giving a relevant date.
216
+
217
+ b) The work must carry prominent notices stating that it is
218
+ released under this License and any conditions added under section
219
+ 7. This requirement modifies the requirement in section 4 to
220
+ "keep intact all notices".
221
+
222
+ c) You must license the entire work, as a whole, under this
223
+ License to anyone who comes into possession of a copy. This
224
+ License will therefore apply, along with any applicable section 7
225
+ additional terms, to the whole of the work, and all its parts,
226
+ regardless of how they are packaged. This License gives no
227
+ permission to license the work in any other way, but it does not
228
+ invalidate such permission if you have separately received it.
229
+
230
+ d) If the work has interactive user interfaces, each must display
231
+ Appropriate Legal Notices; however, if the Program has interactive
232
+ interfaces that do not display Appropriate Legal Notices, your
233
+ work need not make them do so.
234
+
235
+ A compilation of a covered work with other separate and independent
236
+ works, which are not by their nature extensions of the covered work,
237
+ and which are not combined with it such as to form a larger program,
238
+ in or on a volume of a storage or distribution medium, is called an
239
+ "aggregate" if the compilation and its resulting copyright are not
240
+ used to limit the access or legal rights of the compilation's users
241
+ beyond what the individual works permit. Inclusion of a covered work
242
+ in an aggregate does not cause this License to apply to the other
243
+ parts of the aggregate.
244
+
245
+ 6. Conveying Non-Source Forms.
246
+
247
+ You may convey a covered work in object code form under the terms
248
+ of sections 4 and 5, provided that you also convey the
249
+ machine-readable Corresponding Source under the terms of this License,
250
+ in one of these ways:
251
+
252
+ a) Convey the object code in, or embodied in, a physical product
253
+ (including a physical distribution medium), accompanied by the
254
+ Corresponding Source fixed on a durable physical medium
255
+ customarily used for software interchange.
256
+
257
+ b) Convey the object code in, or embodied in, a physical product
258
+ (including a physical distribution medium), accompanied by a
259
+ written offer, valid for at least three years and valid for as
260
+ long as you offer spare parts or customer support for that product
261
+ model, to give anyone who possesses the object code either (1) a
262
+ copy of the Corresponding Source for all the software in the
263
+ product that is covered by this License, on a durable physical
264
+ medium customarily used for software interchange, for a price no
265
+ more than your reasonable cost of physically performing this
266
+ conveying of source, or (2) access to copy the
267
+ Corresponding Source from a network server at no charge.
268
+
269
+ c) Convey individual copies of the object code with a copy of the
270
+ written offer to provide the Corresponding Source. This
271
+ alternative is allowed only occasionally and noncommercially, and
272
+ only if you received the object code with such an offer, in accord
273
+ with subsection 6b.
274
+
275
+ d) Convey the object code by offering access from a designated
276
+ place (gratis or for a charge), and offer equivalent access to the
277
+ Corresponding Source in the same way through the same place at no
278
+ further charge. You need not require recipients to copy the
279
+ Corresponding Source along with the object code. If the place to
280
+ copy the object code is a network server, the Corresponding Source
281
+ may be on a different server (operated by you or a third party)
282
+ that supports equivalent copying facilities, provided you maintain
283
+ clear directions next to the object code saying where to find the
284
+ Corresponding Source. Regardless of what server hosts the
285
+ Corresponding Source, you remain obligated to ensure that it is
286
+ available for as long as needed to satisfy these requirements.
287
+
288
+ e) Convey the object code using peer-to-peer transmission, provided
289
+ you inform other peers where the object code and Corresponding
290
+ Source of the work are being offered to the general public at no
291
+ charge under subsection 6d.
292
+
293
+ A separable portion of the object code, whose source code is excluded
294
+ from the Corresponding Source as a System Library, need not be
295
+ included in conveying the object code work.
296
+
297
+ A "User Product" is either (1) a "consumer product", which means any
298
+ tangible personal property which is normally used for personal, family,
299
+ or household purposes, or (2) anything designed or sold for incorporation
300
+ into a dwelling. In determining whether a product is a consumer product,
301
+ doubtful cases shall be resolved in favor of coverage. For a particular
302
+ product received by a particular user, "normally used" refers to a
303
+ typical or common use of that class of product, regardless of the status
304
+ of the particular user or of the way in which the particular user
305
+ actually uses, or expects or is expected to use, the product. A product
306
+ is a consumer product regardless of whether the product has substantial
307
+ commercial, industrial or non-consumer uses, unless such uses represent
308
+ the only significant mode of use of the product.
309
+
310
+ "Installation Information" for a User Product means any methods,
311
+ procedures, authorization keys, or other information required to install
312
+ and execute modified versions of a covered work in that User Product from
313
+ a modified version of its Corresponding Source. The information must
314
+ suffice to ensure that the continued functioning of the modified object
315
+ code is in no case prevented or interfered with solely because
316
+ modification has been made.
317
+
318
+ If you convey an object code work under this section in, or with, or
319
+ specifically for use in, a User Product, and the conveying occurs as
320
+ part of a transaction in which the right of possession and use of the
321
+ User Product is transferred to the recipient in perpetuity or for a
322
+ fixed term (regardless of how the transaction is characterized), the
323
+ Corresponding Source conveyed under this section must be accompanied
324
+ by the Installation Information. But this requirement does not apply
325
+ if neither you nor any third party retains the ability to install
326
+ modified object code on the User Product (for example, the work has
327
+ been installed in ROM).
328
+
329
+ The requirement to provide Installation Information does not include a
330
+ requirement to continue to provide support service, warranty, or updates
331
+ for a work that has been modified or installed by the recipient, or for
332
+ the User Product in which it has been modified or installed. Access to a
333
+ network may be denied when the modification itself materially and
334
+ adversely affects the operation of the network or violates the rules and
335
+ protocols for communication across the network.
336
+
337
+ Corresponding Source conveyed, and Installation Information provided,
338
+ in accord with this section must be in a format that is publicly
339
+ documented (and with an implementation available to the public in
340
+ source code form), and must require no special password or key for
341
+ unpacking, reading or copying.
342
+
343
+ 7. Additional Terms.
344
+
345
+ "Additional permissions" are terms that supplement the terms of this
346
+ License by making exceptions from one or more of its conditions.
347
+ Additional permissions that are applicable to the entire Program shall
348
+ be treated as though they were included in this License, to the extent
349
+ that they are valid under applicable law. If additional permissions
350
+ apply only to part of the Program, that part may be used separately
351
+ under those permissions, but the entire Program remains governed by
352
+ this License without regard to the additional permissions.
353
+
354
+ When you convey a copy of a covered work, you may at your option
355
+ remove any additional permissions from that copy, or from any part of
356
+ it. (Additional permissions may be written to require their own
357
+ removal in certain cases when you modify the work.) You may place
358
+ additional permissions on material, added by you to a covered work,
359
+ for which you have or can give appropriate copyright permission.
360
+
361
+ Notwithstanding any other provision of this License, for material you
362
+ add to a covered work, you may (if authorized by the copyright holders of
363
+ that material) supplement the terms of this License with terms:
364
+
365
+ a) Disclaiming warranty or limiting liability differently from the
366
+ terms of sections 15 and 16 of this License; or
367
+
368
+ b) Requiring preservation of specified reasonable legal notices or
369
+ author attributions in that material or in the Appropriate Legal
370
+ Notices displayed by works containing it; or
371
+
372
+ c) Prohibiting misrepresentation of the origin of that material, or
373
+ requiring that modified versions of such material be marked in
374
+ reasonable ways as different from the original version; or
375
+
376
+ d) Limiting the use for publicity purposes of names of licensors or
377
+ authors of the material; or
378
+
379
+ e) Declining to grant rights under trademark law for use of some
380
+ trade names, trademarks, or service marks; or
381
+
382
+ f) Requiring indemnification of licensors and authors of that
383
+ material by anyone who conveys the material (or modified versions of
384
+ it) with contractual assumptions of liability to the recipient, for
385
+ any liability that these contractual assumptions directly impose on
386
+ those licensors and authors.
387
+
388
+ All other non-permissive additional terms are considered "further
389
+ restrictions" within the meaning of section 10. If the Program as you
390
+ received it, or any part of it, contains a notice stating that it is
391
+ governed by this License along with a term that is a further
392
+ restriction, you may remove that term. If a license document contains
393
+ a further restriction but permits relicensing or conveying under this
394
+ License, you may add to a covered work material governed by the terms
395
+ of that license document, provided that the further restriction does
396
+ not survive such relicensing or conveying.
397
+
398
+ If you add terms to a covered work in accord with this section, you
399
+ must place, in the relevant source files, a statement of the
400
+ additional terms that apply to those files, or a notice indicating
401
+ where to find the applicable terms.
402
+
403
+ Additional terms, permissive or non-permissive, may be stated in the
404
+ form of a separately written license, or stated as exceptions;
405
+ the above requirements apply either way.
406
+
407
+ 8. Termination.
408
+
409
+ You may not propagate or modify a covered work except as expressly
410
+ provided under this License. Any attempt otherwise to propagate or
411
+ modify it is void, and will automatically terminate your rights under
412
+ this License (including any patent licenses granted under the third
413
+ paragraph of section 11).
414
+
415
+ However, if you cease all violation of this License, then your
416
+ license from a particular copyright holder is reinstated (a)
417
+ provisionally, unless and until the copyright holder explicitly and
418
+ finally terminates your license, and (b) permanently, if the copyright
419
+ holder fails to notify you of the violation by some reasonable means
420
+ prior to 60 days after the cessation.
421
+
422
+ Moreover, your license from a particular copyright holder is
423
+ reinstated permanently if the copyright holder notifies you of the
424
+ violation by some reasonable means, this is the first time you have
425
+ received notice of violation of this License (for any work) from that
426
+ copyright holder, and you cure the violation prior to 30 days after
427
+ your receipt of the notice.
428
+
429
+ Termination of your rights under this section does not terminate the
430
+ licenses of parties who have received copies or rights from you under
431
+ this License. If your rights have been terminated and not permanently
432
+ reinstated, you do not qualify to receive new licenses for the same
433
+ material under section 10.
434
+
435
+ 9. Acceptance Not Required for Having Copies.
436
+
437
+ You are not required to accept this License in order to receive or
438
+ run a copy of the Program. Ancillary propagation of a covered work
439
+ occurring solely as a consequence of using peer-to-peer transmission
440
+ to receive a copy likewise does not require acceptance. However,
441
+ nothing other than this License grants you permission to propagate or
442
+ modify any covered work. These actions infringe copyright if you do
443
+ not accept this License. Therefore, by modifying or propagating a
444
+ covered work, you indicate your acceptance of this License to do so.
445
+
446
+ 10. Automatic Licensing of Downstream Recipients.
447
+
448
+ Each time you convey a covered work, the recipient automatically
449
+ receives a license from the original licensors, to run, modify and
450
+ propagate that work, subject to this License. You are not responsible
451
+ for enforcing compliance by third parties with this License.
452
+
453
+ An "entity transaction" is a transaction transferring control of an
454
+ organization, or substantially all assets of one, or subdividing an
455
+ organization, or merging organizations. If propagation of a covered
456
+ work results from an entity transaction, each party to that
457
+ transaction who receives a copy of the work also receives whatever
458
+ licenses to the work the party's predecessor in interest had or could
459
+ give under the previous paragraph, plus a right to possession of the
460
+ Corresponding Source of the work from the predecessor in interest, if
461
+ the predecessor has it or can get it with reasonable efforts.
462
+
463
+ You may not impose any further restrictions on the exercise of the
464
+ rights granted or affirmed under this License. For example, you may
465
+ not impose a license fee, royalty, or other charge for exercise of
466
+ rights granted under this License, and you may not initiate litigation
467
+ (including a cross-claim or counterclaim in a lawsuit) alleging that
468
+ any patent claim is infringed by making, using, selling, offering for
469
+ sale, or importing the Program or any portion of it.
470
+
471
+ 11. Patents.
472
+
473
+ A "contributor" is a copyright holder who authorizes use under this
474
+ License of the Program or a work on which the Program is based. The
475
+ work thus licensed is called the contributor's "contributor version".
476
+
477
+ A contributor's "essential patent claims" are all patent claims
478
+ owned or controlled by the contributor, whether already acquired or
479
+ hereafter acquired, that would be infringed by some manner, permitted
480
+ by this License, of making, using, or selling its contributor version,
481
+ but do not include claims that would be infringed only as a
482
+ consequence of further modification of the contributor version. For
483
+ purposes of this definition, "control" includes the right to grant
484
+ patent sublicenses in a manner consistent with the requirements of
485
+ this License.
486
+
487
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488
+ patent license under the contributor's essential patent claims, to
489
+ make, use, sell, offer for sale, import and otherwise run, modify and
490
+ propagate the contents of its contributor version.
491
+
492
+ In the following three paragraphs, a "patent license" is any express
493
+ agreement or commitment, however denominated, not to enforce a patent
494
+ (such as an express permission to practice a patent or covenant not to
495
+ sue for patent infringement). To "grant" such a patent license to a
496
+ party means to make such an agreement or commitment not to enforce a
497
+ patent against the party.
498
+
499
+ If you convey a covered work, knowingly relying on a patent license,
500
+ and the Corresponding Source of the work is not available for anyone
501
+ to copy, free of charge and under the terms of this License, through a
502
+ publicly available network server or other readily accessible means,
503
+ then you must either (1) cause the Corresponding Source to be so
504
+ available, or (2) arrange to deprive yourself of the benefit of the
505
+ patent license for this particular work, or (3) arrange, in a manner
506
+ consistent with the requirements of this License, to extend the patent
507
+ license to downstream recipients. "Knowingly relying" means you have
508
+ actual knowledge that, but for the patent license, your conveying the
509
+ covered work in a country, or your recipient's use of the covered work
510
+ in a country, would infringe one or more identifiable patents in that
511
+ country that you have reason to believe are valid.
512
+
513
+ If, pursuant to or in connection with a single transaction or
514
+ arrangement, you convey, or propagate by procuring conveyance of, a
515
+ covered work, and grant a patent license to some of the parties
516
+ receiving the covered work authorizing them to use, propagate, modify
517
+ or convey a specific copy of the covered work, then the patent license
518
+ you grant is automatically extended to all recipients of the covered
519
+ work and works based on it.
520
+
521
+ A patent license is "discriminatory" if it does not include within
522
+ the scope of its coverage, prohibits the exercise of, or is
523
+ conditioned on the non-exercise of one or more of the rights that are
524
+ specifically granted under this License. You may not convey a covered
525
+ work if you are a party to an arrangement with a third party that is
526
+ in the business of distributing software, under which you make payment
527
+ to the third party based on the extent of your activity of conveying
528
+ the work, and under which the third party grants, to any of the
529
+ parties who would receive the covered work from you, a discriminatory
530
+ patent license (a) in connection with copies of the covered work
531
+ conveyed by you (or copies made from those copies), or (b) primarily
532
+ for and in connection with specific products or compilations that
533
+ contain the covered work, unless you entered into that arrangement,
534
+ or that patent license was granted, prior to 28 March 2007.
535
+
536
+ Nothing in this License shall be construed as excluding or limiting
537
+ any implied license or other defenses to infringement that may
538
+ otherwise be available to you under applicable patent law.
539
+
540
+ 12. No Surrender of Others' Freedom.
541
+
542
+ If conditions are imposed on you (whether by court order, agreement or
543
+ otherwise) that contradict the conditions of this License, they do not
544
+ excuse you from the conditions of this License. If you cannot convey a
545
+ covered work so as to satisfy simultaneously your obligations under this
546
+ License and any other pertinent obligations, then as a consequence you may
547
+ not convey it at all. For example, if you agree to terms that obligate you
548
+ to collect a royalty for further conveying from those to whom you convey
549
+ the Program, the only way you could satisfy both those terms and this
550
+ License would be to refrain entirely from conveying the Program.
551
+
552
+ 13. Use with the GNU Affero General Public License.
553
+
554
+ Notwithstanding any other provision of this License, you have
555
+ permission to link or combine any covered work with a work licensed
556
+ under version 3 of the GNU Affero General Public License into a single
557
+ combined work, and to convey the resulting work. The terms of this
558
+ License will continue to apply to the part which is the covered work,
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
562
+
563
+ 14. Revised Versions of this License.
564
+
565
+ The Free Software Foundation may publish revised and/or new versions of
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
568
+ address new problems or concerns.
569
+
570
+ Each version is given a distinguishing version number. If the
571
+ Program specifies that a certain numbered version of the GNU General
572
+ Public License "or any later version" applies to it, you have the
573
+ option of following the terms and conditions either of that numbered
574
+ version or of any later version published by the Free Software
575
+ Foundation. If the Program does not specify a version number of the
576
+ GNU General Public License, you may choose any version ever published
577
+ by the Free Software Foundation.
578
+
579
+ If the Program specifies that a proxy can decide which future
580
+ versions of the GNU General Public License can be used, that proxy's
581
+ public statement of acceptance of a version permanently authorizes you
582
+ to choose that version for the Program.
583
+
584
+ Later license versions may give you additional or different
585
+ permissions. However, no additional obligations are imposed on any
586
+ author or copyright holder as a result of your choosing to follow a
587
+ later version.
588
+
589
+ 15. Disclaimer of Warranty.
590
+
591
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592
+ APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593
+ HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594
+ OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596
+ PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597
+ IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598
+ ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599
+
600
+ 16. Limitation of Liability.
601
+
602
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603
+ WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604
+ THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605
+ GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606
+ USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607
+ DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608
+ PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609
+ EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610
+ SUCH DAMAGES.
611
+
612
+ 17. Interpretation of Sections 15 and 16.
613
+
614
+ If the disclaimer of warranty and limitation of liability provided
615
+ above cannot be given local legal effect according to their terms,
616
+ reviewing courts shall apply local law that most closely approximates
617
+ an absolute waiver of all civil liability in connection with the
618
+ Program, unless a warranty or assumption of liability accompanies a
619
+ copy of the Program in return for a fee.
620
+
621
+ END OF TERMS AND CONDITIONS
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.3
7
- Stable tag: 4.2.4
8
 
9
  Track your WordPress site easily and with lots of metadata: views per author & category, automatic tracking of outbound clicks and pageviews.
10
 
@@ -58,6 +58,11 @@ This section describes how to install the plugin and get it working.
58
 
59
  == Changelog ==
60
 
 
 
 
 
 
61
  = 4.2.4 =
62
 
63
  * Fixed bug introduced with 4.2.3 that wouldn't allow saving settings.
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.4
7
+ Stable tag: 4.2.5
8
 
9
  Track your WordPress site easily and with lots of metadata: views per author & category, automatic tracking of outbound clicks and pageviews.
10
 
58
 
59
  == Changelog ==
60
 
61
+ = 4.2.5 =
62
+
63
+ * Fixed a couple notices.
64
+ * Added tracking to better understand configurations to test the plugin with.
65
+
66
  = 4.2.4 =
67
 
68
  * Fixed bug introduced with 4.2.3 that wouldn't allow saving settings.
yst_plugin_tools.css CHANGED
@@ -32,18 +32,18 @@ div.inside a:hover, div.inside a.rsswidget:hover {
32
  div.inside ul li.rss {
33
  list-style-image: url(images/rss.png);
34
  }
35
-
36
- div.inside ul li.twitter {
37
- list-style-image: url(images/twitter-icon.png);
38
- }
39
-
40
- div.inside ul li.facebook {
41
- list-style-image: url(images/facebook-icon.png);
42
- }
43
-
44
- div.inside ul li.googleplus {
45
- list-style-image: url(images/google-plus-icon.png);
46
- }
47
 
48
  div.inside ul li.email {
49
  list-style-image: url(images/email_sub.png);
@@ -78,10 +78,6 @@ div.inside .button:hover, div.inside .button-primary:hover {
78
  text-decoration: none;
79
  }
80
 
81
- .button, .button-primary {
82
- margin-top: 10px;
83
- }
84
-
85
  .postbox#donate {
86
  border-color: green;
87
  border-width: 2px;
@@ -90,7 +86,7 @@ strong.red {
90
  color: green;
91
  font-weight: bold;
92
  font-size: 105%;
93
- }
94
- .postbox {
95
- margin: 0 10px 10px 0;
96
- }
32
  div.inside ul li.rss {
33
  list-style-image: url(images/rss.png);
34
  }
35
+
36
+ div.inside ul li.twitter {
37
+ list-style-image: url(images/twitter-icon.png);
38
+ }
39
+
40
+ div.inside ul li.facebook {
41
+ list-style-image: url(images/facebook-icon.png);
42
+ }
43
+
44
+ div.inside ul li.googleplus {
45
+ list-style-image: url(images/google-plus-icon.png);
46
+ }
47
 
48
  div.inside ul li.email {
49
  list-style-image: url(images/email_sub.png);
78
  text-decoration: none;
79
  }
80
 
 
 
 
 
81
  .postbox#donate {
82
  border-color: green;
83
  border-width: 2px;
86
  color: green;
87
  font-weight: bold;
88
  font-size: 105%;
89
+ }
90
+ .postbox {
91
+ margin: 0 10px 10px 0;
92
+ }