Google Analytics for WordPress by MonsterInsights - Version 6.0.11

Version Description

= 6.0.0 =

This is a major release. Please back up your site before upgrading.

Download this release

Release Info

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

Code changes from version 6.0.4 to 6.0.11

README.md CHANGED
@@ -198,7 +198,7 @@ We declare these for code that relies on old constants. Please upgrade your code
198
  These rules dictate which Google Analytics UA code is used.
199
  The order of priority is as follows (top of list has most priority):
200
 
201
- - `monsterinsights_ga_ua` filter
202
  - MonsterInsights per site settings for manual UA or oAuth retrieved UA
203
  - Note, these settings are hidden when MONSTERINSIGHTS_GA_UA is defined
204
  - `MONSTERINSIGHTS_GA_UA` constant
@@ -207,7 +207,7 @@ The order of priority is as follows (top of list has most priority):
207
 
208
  As a result of this order of priority, on MS installs you can use the `MONSTERINSIGHTS_MS_GA_UA` constant to
209
  set the default UA for all of the subsites of an MS install, and then override that on a subsite basis using either
210
- the UI in the settings panel, the `MONSTERINSIGHTS_GA_UA` constant or the `monsterinsights_ga_ua` filter.
211
 
212
  Let's say you run a really large MS install, like for a university, and all of your sites are {sitename}.mysite.com or
213
  mysite.com/{example}/. In this case, you can quickly deploy MI for your entire network by network activating MonsterInsights
198
  These rules dictate which Google Analytics UA code is used.
199
  The order of priority is as follows (top of list has most priority):
200
 
201
+ - `monsterinsights_get_ua` filter
202
  - MonsterInsights per site settings for manual UA or oAuth retrieved UA
203
  - Note, these settings are hidden when MONSTERINSIGHTS_GA_UA is defined
204
  - `MONSTERINSIGHTS_GA_UA` constant
207
 
208
  As a result of this order of priority, on MS installs you can use the `MONSTERINSIGHTS_MS_GA_UA` constant to
209
  set the default UA for all of the subsites of an MS install, and then override that on a subsite basis using either
210
+ the UI in the settings panel, the `MONSTERINSIGHTS_GA_UA` constant or the `monsterinsights_get_ua` filter.
211
 
212
  Let's say you run a really large MS install, like for a university, and all of your sites are {sitename}.mysite.com or
213
  mysite.com/{example}/. In this case, you can quickly deploy MI for your entire network by network activating MonsterInsights
assets/lib/google/class-ga-client.php CHANGED
@@ -55,16 +55,6 @@ class MonsterInsights_GA_Client extends MonsterInsights_GA_Lib_Client {
55
 
56
  // Let's get an access token if we've got a refresh token.
57
  $this->refresh_tokens();
58
- $token = $this->get_access_token();
59
- if ( ! empty( $token ) ) {
60
- $token = json_encode( $token );
61
-
62
- try {
63
- $this->client->setAccessToken( $token );
64
- } catch ( MonsterInsights_GA_Lib_Auth_Exception $exception ) {
65
-
66
- }
67
- }
68
  }
69
 
70
  /**
@@ -118,11 +108,14 @@ class MonsterInsights_GA_Client extends MonsterInsights_GA_Lib_Client {
118
  *
119
  * @return array
120
  */
121
- public function do_request( $target_request_url, $decode_response = false, $request_method = 'GET' ) {
122
  // Get response.
123
- $response = $this->getAuth()->authenticatedRequest(
124
- new MonsterInsights_GA_Lib_Http_Request( $target_request_url, $request_method )
125
- );
 
 
 
126
 
127
  // Storing the response code.
128
  $this->http_response_code = $response->getResponseHttpCode();
@@ -338,8 +331,9 @@ class MonsterInsights_GA_Client extends MonsterInsights_GA_Lib_Client {
338
  try {
339
  $this->setAccessToken( json_encode( $access_token ) );
340
  } catch ( MonsterInsights_GA_Lib_Auth_Exception $exception ) {
341
-
342
  }
 
343
  }
344
 
345
  /**
@@ -347,7 +341,7 @@ class MonsterInsights_GA_Client extends MonsterInsights_GA_Lib_Client {
347
  *
348
  * @return mixed
349
  */
350
- private function get_access_token() {
351
  return get_option( $this->option_access_token, array( 'access_token' => false, 'expires' => 0 ) );
352
  }
353
 
55
 
56
  // Let's get an access token if we've got a refresh token.
57
  $this->refresh_tokens();
 
 
 
 
 
 
 
 
 
 
58
  }
59
 
60
  /**
108
  *
109
  * @return array
110
  */
111
+ public function do_request( $target_request_url, $decode_response = false, $request_method = 'GET', $body = array() ) {
112
  // Get response.
113
+ $request = new MonsterInsights_GA_Lib_Http_Request( $target_request_url, $request_method );
114
+ if ( ! empty( $body ) ) {
115
+ $request->setPostBody( $body ); // used exclusively for auth profiles
116
+ }
117
+
118
+ $response = $this->getAuth()->authenticatedRequest( $request );
119
 
120
  // Storing the response code.
121
  $this->http_response_code = $response->getResponseHttpCode();
331
  try {
332
  $this->setAccessToken( json_encode( $access_token ) );
333
  } catch ( MonsterInsights_GA_Lib_Auth_Exception $exception ) {
334
+ return true;
335
  }
336
+ return false;
337
  }
338
 
339
  /**
341
  *
342
  * @return mixed
343
  */
344
+ public function get_access_token() {
345
  return get_option( $this->option_access_token, array( 'access_token' => false, 'expires' => 0 ) );
346
  }
347
 
googleanalytics.php CHANGED
@@ -6,7 +6,7 @@
6
  * Author: MonsterInsights
7
  * Author URI: https://www.monsterinsights.com/
8
  *
9
- * Version: 6.0.4
10
  * Requires at least: 3.9.0
11
  * Tested up to: 4.7.2
12
  *
@@ -69,7 +69,7 @@ final class MonsterInsights_Lite {
69
  * @access public
70
  * @var string $version Plugin version.
71
  */
72
- public $version = '6.0.4';
73
 
74
  /**
75
  * Plugin file.
@@ -177,15 +177,17 @@ final class MonsterInsights_Lite {
177
 
178
  // This does the version to version background upgrade routines and initial install
179
  $mi_version = get_option( 'monsterinsights_current_version', '5.5.3' );
180
- if ( version_compare( $mi_version, '6.0.2', '<' ) ) {
181
  monsterinsights_lite_call_install_and_upgrade();
182
  }
183
 
184
  // Load the plugin textdomain.
185
  add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ) );
186
 
187
- // Load global components
188
- self::$instance->ga = new MonsterInsights_GA();
 
 
189
 
190
  // Load admin only components.
191
  if ( is_admin() ) {
@@ -232,6 +234,31 @@ final class MonsterInsights_Lite {
232
  _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-for-wordpress' ), '6.0.0' );
233
  }
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  /**
236
  * Define MonsterInsights constants.
237
  *
@@ -459,9 +486,14 @@ final class MonsterInsights_Lite {
459
  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/abstract-report.php';
460
  }
461
 
462
- require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/google.php';
463
  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/google.php';
464
 
 
 
 
 
 
465
  if ( is_admin() ) {
466
  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/googleauth.php';
467
  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/addons.php';
6
  * Author: MonsterInsights
7
  * Author URI: https://www.monsterinsights.com/
8
  *
9
+ * Version: 6.0.11
10
  * Requires at least: 3.9.0
11
  * Tested up to: 4.7.2
12
  *
69
  * @access public
70
  * @var string $version Plugin version.
71
  */
72
+ public $version = '6.0.11';
73
 
74
  /**
75
  * Plugin file.
177
 
178
  // This does the version to version background upgrade routines and initial install
179
  $mi_version = get_option( 'monsterinsights_current_version', '5.5.3' );
180
+ if ( version_compare( $mi_version, '6.0.11', '<' ) ) {
181
  monsterinsights_lite_call_install_and_upgrade();
182
  }
183
 
184
  // Load the plugin textdomain.
185
  add_action( 'plugins_loaded', array( self::$instance, 'load_plugin_textdomain' ) );
186
 
187
+ // Load GA for admin, lazyload for frontend
188
+ if ( is_admin() ) {
189
+ self::$instance->ga = new MonsterInsights_GA();
190
+ }
191
 
192
  // Load admin only components.
193
  if ( is_admin() ) {
234
  _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin&#8217; huh?', 'google-analytics-for-wordpress' ), '6.0.0' );
235
  }
236
 
237
+ /**
238
+ * Magic get function.
239
+ *
240
+ * We use this to lazy load certain functionality. Right now used to lazyload
241
+ * the Google Object for frontend, so it's only loaded if user is using a plugin
242
+ * that requires it.
243
+ *
244
+ * @since 6.0.10
245
+ * @access public
246
+ *
247
+ * @return void
248
+ */
249
+ public function __get( $key ) {
250
+ if ( $key === 'ga' ) {
251
+ if ( empty( self::$instance->ga ) ) {
252
+ // LazyLoad GA for Frontend
253
+ self::$instance->ga = new MonsterInsights_GA();
254
+ require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/google.php';
255
+ }
256
+ return $key;
257
+ } else {
258
+ return $key;
259
+ }
260
+ }
261
+
262
  /**
263
  * Define MonsterInsights constants.
264
  *
486
  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/abstract-report.php';
487
  }
488
 
489
+ // Load Google Config
490
  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/google.php';
491
 
492
+ // Lazy Load for Frontend. Load for Admin.
493
+ if ( is_admin() ) {
494
+ require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/google.php';
495
+ }
496
+
497
  if ( is_admin() ) {
498
  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'includes/admin/googleauth.php';
499
  require_once MONSTERINSIGHTS_PLUGIN_DIR . 'lite/includes/admin/addons.php';
includes/admin/common.php CHANGED
@@ -187,6 +187,17 @@ function monsterinsights_remove_conflicting_asset_files() {
187
 
188
  $styles = array(
189
  'kt_admin_css', // Pinnacle theme
 
 
 
 
 
 
 
 
 
 
 
190
  );
191
 
192
  $scripts = array(
187
 
188
  $styles = array(
189
  'kt_admin_css', // Pinnacle theme
190
+ 'select2-css', // Schema theme
191
+ 'tweetshare_style', // TweetShare - Click To Tweet
192
+ 'tweetshare_custom_style', // TweetShare - Click To Tweet
193
+ 'tweeetshare_font_script', // TweetShare - Click To Tweet
194
+ 'tweeetshare_jquery_script', // TweetShare - Click To Tweet
195
+ 'tweeetshare_jqueryui_script', // TweetShare - Click To Tweet
196
+ 'tweeetshare_custom_script', // TweetShare - Click To Tweet
197
+ 'tweeetshare_custome_style', // TweetShare - Click To Tweet
198
+ 'tweeetshare_notice_style', // TweetShare - Click To Tweet
199
+ 'tweeetshare_theme_style', // TweetShare - Click To Tweet
200
+ 'tweeetshare_tweet_box_style', // TweetShare - Click To Tweet
201
  );
202
 
203
  $scripts = array(
includes/admin/google.php CHANGED
@@ -98,6 +98,7 @@ final class MonsterInsights_GA {
98
  $this->status = $this->get_status();
99
  $this->base = MonsterInsights();
100
 
 
101
  // Show any info/error notices
102
  $this->get_notices();
103
 
@@ -108,7 +109,7 @@ final class MonsterInsights_GA {
108
  add_action( 'admin_init', array( $this, 'deactivate_google' ) ); // Deactivate
109
  }
110
 
111
- private function get_client() {
112
  return ! empty( $this->client ) ? $this->client : monsterinsights_create_client();
113
  }
114
 
@@ -150,24 +151,17 @@ final class MonsterInsights_GA {
150
  $failed = monsterinsights_get_option( 'cron_failed', false );
151
  $dash_dis = monsterinsights_get_option( 'dashboards_disabled', false );
152
 
153
- if ( $this->is_wp_blocking_google() || $this->is_google_on_blacklist() ) {
154
- $status = 'blocked';
155
- return $status;
156
- }
157
-
158
  // See if issue connecting or expired
159
  if ( ! $dash_dis && $failed && ( $last_run === false || monsterinsights_hours_between( $last_run ) >= 48 ) ) {
160
  $status = 'blocked';
161
-
162
- if ( ! $this->client->getAccessToken() ) {
163
- $status = 'expired';
164
- }
165
- return $status;
166
  }
167
 
168
- // Check to make sure access token is there
169
- if ( ! $this->client->getAccessToken() ) {
 
 
170
  $status = 'expired';
 
171
  }
172
 
173
  // See if needs permissions
@@ -251,10 +245,8 @@ final class MonsterInsights_GA {
251
  *
252
  * @return array
253
  */
254
- public function get_profiles() { // @todo: this needs exception handling for a 401 login required
255
- $accounts = $this->format_profile_call(
256
- $this->do_request( 'https://www.googleapis.com/analytics/v3/management/accountSummaries' )
257
- );
258
  if ( is_array( $accounts ) ) {
259
  return $accounts;
260
  } else {
@@ -298,53 +290,72 @@ final class MonsterInsights_GA {
298
  *
299
  * @return mixed
300
  */
301
- private function format_profile_call( $response ) {
302
-
303
- if ( isset( $response['response']['code'] ) && $response['response']['code'] == 200 ) {
304
- if ( ! empty( $response['body']['items'] ) && is_array( $response['body']['items'] ) ) {
305
- $accounts = array();
306
-
307
- foreach ( $response['body']['items'] as $item ) {
308
- // Check if webProperties is set
309
- if ( isset( $item['webProperties'] ) ) {
310
- $profiles = array();
311
-
312
- foreach ( $item['webProperties'] as $property_key => $property ) {
313
- $profiles[ $property_key ] = array(
314
- 'id' => $property['id'],
315
- 'name' => $property['name'],
316
- 'items' => array(),
317
- );
 
 
 
 
 
 
 
 
 
318
 
319
- // Check if profiles is set
320
- if ( isset( $property['profiles'] ) ) {
321
- foreach ( $property['profiles'] as $key => $profile ) {
322
- $profiles[ $property_key ]['items'][ $key ] = array_merge(
323
- $profile,
324
- array(
325
- 'name' => $profile['name'] . ' (' . $property['id'] . ')',
326
- 'ua_code' => $property['id'],
327
- )
328
- );
329
- }
330
- }
331
  }
332
 
333
- $accounts[ $item['id'] ] = array(
334
- 'id' => $item['id'],
335
- 'ua_code' => $property['id'],
336
- 'parent_name' => $item['name'],
337
- 'items' => $profiles,
338
- );
 
339
 
 
 
 
 
 
 
 
340
  }
341
  }
342
-
343
- return $accounts;
 
 
 
344
  }
345
  }
346
-
347
- return false;
348
  }
349
 
350
  private function clear_oauth_data() {
@@ -706,7 +717,7 @@ final class MonsterInsights_GA {
706
  public function monsterinsights_show_admin_config_expired_notice() {
707
  echo '<div class="error"><p>' .
708
  sprintf(
709
- esc_html__( 'It seems the authentication for the plugin has expired, please %1$sre-authenticate%2$s with Google Analytics to allow the plugin to fetch data.', 'google-analytics-for-wordpress' ),
710
  '<a href="' . admin_url( 'admin.php?page=monsterinsights_settings' ) . '">',
711
  '</a>'
712
  )
@@ -738,5 +749,4 @@ final class MonsterInsights_GA {
738
  )
739
  . '</p></div>';
740
  }
741
-
742
  }
98
  $this->status = $this->get_status();
99
  $this->base = MonsterInsights();
100
 
101
+
102
  // Show any info/error notices
103
  $this->get_notices();
104
 
109
  add_action( 'admin_init', array( $this, 'deactivate_google' ) ); // Deactivate
110
  }
111
 
112
+ private function get_client() {
113
  return ! empty( $this->client ) ? $this->client : monsterinsights_create_client();
114
  }
115
 
151
  $failed = monsterinsights_get_option( 'cron_failed', false );
152
  $dash_dis = monsterinsights_get_option( 'dashboards_disabled', false );
153
 
 
 
 
 
 
154
  // See if issue connecting or expired
155
  if ( ! $dash_dis && $failed && ( $last_run === false || monsterinsights_hours_between( $last_run ) >= 48 ) ) {
156
  $status = 'blocked';
 
 
 
 
 
157
  }
158
 
159
+ $access_token = $this->client->get_access_token();
160
+
161
+ // Check to make sure access token is there and not expired
162
+ if ( empty( $access_token ) || empty( $access_token['expires'] ) || current_time( 'timestamp' ) >= $access_token['expires'] ) {
163
  $status = 'expired';
164
+ return $status;
165
  }
166
 
167
  // See if needs permissions
245
  *
246
  * @return array
247
  */
248
+ public function get_profiles() { // @todo: this needs exception handling for a 401 login required
249
+ $accounts = $this->format_profile_call();
 
 
250
  if ( is_array( $accounts ) ) {
251
  return $accounts;
252
  } else {
290
  *
291
  * @return mixed
292
  */
293
+ private function format_profile_call() {
294
+ $accounts = array();
295
+ $start_index = 1;
296
+ $paginate = false;
297
+ $continue = true;
298
+ while ( $continue ) {
299
+ $body = array(
300
+ 'max-results' => 1000,
301
+ 'start-index' => $paginate ? $start_index + 1000 : $start_index,
302
+ );
303
+ if ( $paginate ) {
304
+ $start_index = $start_index + 1000;
305
+ }
306
+ $response = $this->client->do_request( 'https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties/~all/profiles', false, 'GET', $body );
307
+ if ( ! empty( $response ) ) {
308
+ $response = array(
309
+ 'response' => array( 'code' => $this->client->get_http_response_code() ),
310
+ 'body' => json_decode( $response->getResponseBody(), true ),
311
+ );
312
+ } else {
313
+ break;
314
+ }
315
+
316
+ if ( isset( $response['response']['code'] ) && $response['response']['code'] == 200 ) {
317
+ if ( ! empty( $response['body']['items'] ) && is_array( $response['body']['items'] ) ) {
318
+ foreach ( $response['body']['items'] as $item ) {
319
 
320
+ // Only deal with web properties, not apps.
321
+ if ( isset( $item['type'] ) && 'WEB' != $item['type'] ) {
322
+ continue;
323
+ }
324
+
325
+ if ( empty( $accounts[ $item['accountId'] ] ) ) {
326
+ $accounts[ $item['accountId'] ] = array(
327
+ 'id' => $item['accountId'],
328
+ 'ua_code' => $item['webPropertyId'],
329
+ 'parent_name' => $item['websiteUrl'],
330
+ 'items' => array(),
331
+ );
332
  }
333
 
334
+ if ( empty( $accounts[ $item['accountId'] ]['items'][ $item['internalWebPropertyId'] ] ) ) {
335
+ $accounts[ $item['accountId'] ]['items'][ $item['internalWebPropertyId'] ]= array(
336
+ 'id' => $item['webPropertyId'],
337
+ 'name' => $item['websiteUrl'],
338
+ 'items' => array(),
339
+ );
340
+ }
341
 
342
+ if ( empty( $accounts[ $item['accountId'] ]['items'][ $item['internalWebPropertyId'] ]['items'][ $item['id'] ] ) ) {
343
+ $accounts[ $item['accountId'] ]['items'][ $item['internalWebPropertyId'] ]['items'][ $item['id'] ] = array(
344
+ 'name' => $item['name'] . ' (' . $item['webPropertyId'] . ')',
345
+ 'ua_code' => $item['webPropertyId'],
346
+ 'id' => $item['id'],
347
+ );
348
+ }
349
  }
350
  }
351
+ }
352
+ if ( isset( $response['body']['totalResults'] ) && $start_index < $response['body']['totalResults'] && ! empty( $response['body']['nextLink'] ) ) {
353
+ $paginate = true;
354
+ } else {
355
+ $continue = false;
356
  }
357
  }
358
+ return $accounts;
 
359
  }
360
 
361
  private function clear_oauth_data() {
717
  public function monsterinsights_show_admin_config_expired_notice() {
718
  echo '<div class="error"><p>' .
719
  sprintf(
720
+ esc_html__( 'It seems the authentication for the plugin has expired or the connection to Google Analytics is blocked, please try %1$sre-authenticating%2$s with Google Analytics to allow the plugin to fetch data.', 'google-analytics-for-wordpress' ),
721
  '<a href="' . admin_url( 'admin.php?page=monsterinsights_settings' ) . '">',
722
  '</a>'
723
  )
749
  )
750
  . '</p></div>';
751
  }
 
752
  }
includes/admin/pages/settings.php CHANGED
@@ -150,6 +150,18 @@ function monsterinsights_updated_settings() {
150
  echo monsterinsights_get_message( 'success', esc_html__( 'Settings saved successfully.', 'google-analytics-for-wordpress' ) );
151
  }
152
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  /**
154
  * Outputs a checkbox for settings.
155
  *
150
  echo monsterinsights_get_message( 'success', esc_html__( 'Settings saved successfully.', 'google-analytics-for-wordpress' ) );
151
  }
152
 
153
+ /**
154
+ * Outputs a WordPress style notification to tell the user their UA code was bad.
155
+ *
156
+ * @since 6.0.3
157
+ * @access public
158
+ *
159
+ * @return void
160
+ */
161
+ function monsterinsights_invalid_ua_code() {
162
+ echo monsterinsights_get_message( 'error', esc_html__( 'Invalid UA code.', 'google-analytics-for-wordpress' ) );
163
+ }
164
+
165
  /**
166
  * Outputs a checkbox for settings.
167
  *
includes/admin/settings/tab-general.php CHANGED
@@ -221,6 +221,7 @@ add_action( 'monsterinsights_tab_settings_general', 'monsterinsights_settings_ge
221
  * @return void
222
  */
223
  function monsterinsights_settings_save_general() {
 
224
  $manual_ua_code = isset( $_POST['manual_ua_code'] ) ? $_POST['manual_ua_code'] : '';
225
  $manual_ua_code = monsterinsights_is_valid_ua( $manual_ua_code ); // also sanitizes the string
226
 
@@ -228,7 +229,7 @@ function monsterinsights_settings_save_general() {
228
  monsterinsights_update_option( 'manual_ua_code', $manual_ua_code );
229
  } else {
230
  if ( empty ( $_POST['manual_ua_code'] ) ) {
231
- // @todo: throw alert?
232
  }
233
  monsterinsights_update_option( 'manual_ua_code', '' );
234
  }
@@ -278,7 +279,11 @@ function monsterinsights_settings_save_general() {
278
  do_action( 'monsterinsights_settings_save_general_end' );
279
 
280
  // Output an admin notice so the user knows what happened
281
- add_action( 'monsterinsights_settings_general_tab_notice', 'monsterinsights_updated_settings' );
 
 
 
 
282
  }
283
  add_action( 'monsterinsights_settings_save_general', 'monsterinsights_settings_save_general', 11 );
284
 
221
  * @return void
222
  */
223
  function monsterinsights_settings_save_general() {
224
+ $thow_notice = false;
225
  $manual_ua_code = isset( $_POST['manual_ua_code'] ) ? $_POST['manual_ua_code'] : '';
226
  $manual_ua_code = monsterinsights_is_valid_ua( $manual_ua_code ); // also sanitizes the string
227
 
229
  monsterinsights_update_option( 'manual_ua_code', $manual_ua_code );
230
  } else {
231
  if ( empty ( $_POST['manual_ua_code'] ) ) {
232
+ $throw_notice = true;
233
  }
234
  monsterinsights_update_option( 'manual_ua_code', '' );
235
  }
279
  do_action( 'monsterinsights_settings_save_general_end' );
280
 
281
  // Output an admin notice so the user knows what happened
282
+ if ( $throw_notice ) {
283
+ add_action( 'monsterinsights_settings_general_tab_notice', 'monsterinsights_invalid_ua_code' );
284
+ } else {
285
+ add_action( 'monsterinsights_settings_general_tab_notice', 'monsterinsights_updated_settings' );
286
+ }
287
  }
288
  add_action( 'monsterinsights_settings_save_general', 'monsterinsights_settings_save_general', 11 );
289
 
includes/admin/tracking.php CHANGED
@@ -42,7 +42,7 @@ class MonsterInsights_Tracking {
42
  add_action( 'admin_head', array( $this, 'check_for_optout' ) );
43
  add_action( 'admin_notices', array( $this, 'monsterinsights_admin_notice' ) );
44
  add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
45
- add_action( 'monsterinsights_send_tracking_checkin', array( $this, 'send_checkin' ) );
46
  }
47
 
48
  /**
@@ -68,7 +68,7 @@ class MonsterInsights_Tracking {
68
  $theme_data = wp_get_theme();
69
  $theme = $theme_data->Name . ' ' . $theme_data->Version;
70
  $tracking_mode = monsterinsights_get_option( 'tracking_mode', 'analytics' );
71
- $events_mode = monsterinsights_get_option( 'events_mode', false );
72
 
73
  if ( $tracking_mode === false ) {
74
  $tracking_mode = 'analytics';
@@ -240,10 +240,10 @@ class MonsterInsights_Tracking {
240
  * @return void
241
  */
242
  public function schedule_send() {
243
- // We send once a week (while tracking is allowed) to check in, which can be used to determine active sites
244
- if ( ! wp_next_scheduled( 'monsterinsights_weekly_cron' ) ) {
245
  // Set the next event of fetching data
246
- wp_schedule_event( strtotime( date( 'Y-m-d', strtotime( 'tomorrow' ) ) . ' 00:01:30 ' ), 'weekly', 'monsterinsights_send_tracking_checkin' );
247
  }
248
  }
249
 
42
  add_action( 'admin_head', array( $this, 'check_for_optout' ) );
43
  add_action( 'admin_notices', array( $this, 'monsterinsights_admin_notice' ) );
44
  add_filter( 'cron_schedules', array( $this, 'add_schedules' ) );
45
+ add_action( 'monsterinsights_daily_cron', array( $this, 'send_checkin' ) );
46
  }
47
 
48
  /**
68
  $theme_data = wp_get_theme();
69
  $theme = $theme_data->Name . ' ' . $theme_data->Version;
70
  $tracking_mode = monsterinsights_get_option( 'tracking_mode', 'analytics' );
71
+ $events_mode = monsterinsights_get_option( 'events_mode', 'none' );
72
 
73
  if ( $tracking_mode === false ) {
74
  $tracking_mode = 'analytics';
240
  * @return void
241
  */
242
  public function schedule_send() {
243
+ // We send once a day (while tracking is allowed) to check in, which can be used to determine active sites
244
+ if ( ! wp_next_scheduled( 'monsterinsights_daily_cron' ) ) {
245
  // Set the next event of fetching data
246
+ wp_schedule_event( strtotime( date( 'Y-m-d', strtotime( 'tomorrow' ) ) . ' 00:01:00 ' ), 'daily', 'monsterinsights_daily_cron' );
247
  }
248
  }
249
 
includes/frontend/events/class-events-js.php CHANGED
@@ -58,6 +58,7 @@ class MonsterInsights_Events_JS {
58
  $events = monsterinsights_get_option( 'events_mode', false );
59
  if ( $events === 'js' && $tracking === 'analytics' ) {
60
  add_action( 'wp_head', array( $this, 'output_javascript' ), 9 );
 
61
  }
62
  }
63
 
@@ -312,6 +313,10 @@ class MonsterInsights_Events_JS {
312
  };
313
  }
314
 
 
 
 
 
315
  if ( is_debug_mode ) {
316
  console.log( "Link: " + link);
317
  console.log( "Extension: " + extension );
@@ -322,7 +327,7 @@ class MonsterInsights_Events_JS {
322
  }
323
 
324
  /* Let's get the type of click event this is */
325
- if ( el.protocol == 'mailto' ) { /* If it's an email */
326
  type = "mailto";
327
  } else if ( download_extensions.length > 0 && extension.length > 0 && download_extensions.includes(extension) ) { /* If it's a download */
328
  type = "download";
@@ -505,8 +510,8 @@ class MonsterInsights_Events_JS {
505
  <!-- MonsterInsights JS Event Tracking -->
506
  <script type="text/javascript" data-cfasync="false">
507
  (function(){
508
- function __gaTrackerClickEventPHP() {var phpvalues = { 'is_debug_mode': <?php echo $is_debug_mode; ?>,'download_extensions': <?php echo $download_extensions; ?>,'inbound_paths': <?php echo $inbound_paths; ?>,'home_url': "<?php echo home_url(); ?>",'track_download_as': "<?php echo $track_download_as; ?>",'internal_label': "outbound-link-<?php echo $internal_label; ?>"};return phpvalues;}
509
- function __gaTrackerClickEvent(e){var t=__gaTrackerClickEventPHP(),n=t.is_debug_mode||window.monsterinsights_debug_mode,o=e.srcElement||e.target;if(n&&(console.log("__gaTracker.hasOwnProperty(loaded)"),console.log(__gaTracker.hasOwnProperty("loaded")),console.log("__gaTracker.loaded"),console.log(__gaTracker.loaded),console.log("Event.which: "+e.which),console.log("El: "),console.log(o),console.log("Will track: "+!__gaTracker.hasOwnProperty("loaded")||1!=__gaTracker.loaded||1!=e.which&&2!=e.which&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey)),__gaTracker.hasOwnProperty("loaded")&&1==__gaTracker.loaded&&(1==e.which||2==e.which||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)){for(;o&&("undefined"==typeof o.tagName||"a"!=o.tagName.toLowerCase()||!o.href);)o=o.parentNode;if(o&&o.href){var a=o.href,r=o.href,l="internal",i=t.download_extensions,c=t.inbound_paths,d=(t.home_url,t.track_download_as),s="outbound-link-"+t.internal_label;r=r.substring(0,-1==r.indexOf("#")?r.length:r.indexOf("#")),r=r.substring(0,-1==r.indexOf("?")?r.length:r.indexOf("?")),r=r.substring(r.lastIndexOf("/")+1,r.length),r=r.substring(r.indexOf(".")+1);var g=function(){for(var e=0,t=document.domain,n=t.split("."),o="_gd"+(new Date).getTime();e<n.length-1&&-1==document.cookie.indexOf(o+"="+o);)t=n.slice(-1-++e).join("."),document.cookie=o+"="+o+";domain="+t+";";return document.cookie=o+"=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain="+t+";",t}();if("function"!=typeof String.prototype.endsWith&&(String.prototype.endsWith=function(e){return-1!==this.indexOf(e,this.length-e.length)}),"function"!=typeof String.prototype.startsWith&&(String.prototype.startsWith=function(e){return 0===this.indexOf(e)}),"function"!=typeof Array.prototype.includes&&Object.defineProperty(Array.prototype,"includes",{value:function(e,t){if(null==this)throw new TypeError('"this" is null or not defined');var n=Object(this),o=n.length>>>0;if(0===o)return!1;for(var a=0|t,r=Math.max(a>=0?a:o-Math.abs(a),0);o>r;){if(n[r]===e)return!0;r++}return!1}}),"function"!=typeof Array.prototype.lastIndexOf&&(Array.prototype.lastIndexOf=function(e){"use strict";if(void 0===this||null===this)throw new TypeError;var t,n,o=Object(this),a=o.length>>>0;if(0===a)return-1;for(t=a-1,arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),n=t>=0?Math.min(t,a-1):a-Math.abs(t);n>=0;n--)if(n in o&&o[n]===e)return n;return-1}),n&&(console.log("Link: "+a),console.log("Extension: "+r),console.log("Protocol: "+o.protocol),console.log("External: "+(o.hostname.length>0&&g.length>0&&!o.hostname.endsWith(g))),console.log("Current domain: "+g),console.log("Link domain: "+o.hostname)),"mailto"==o.protocol)l="mailto";else if(i.length>0&&r.length>0&&i.includes(r))l="download";else if(o.hostname.length>0&&g.length>0&&!o.hostname.endsWith(g))l="external";else{var h,u,_=o.pathname;for(h=0,u=c.length;u>h;++h)if(_.startsWith(c[h])){l="internal-as-outbound";break}}if(n&&console.log("Type: "+l),"internal"!==l&&!a.match(/^javascript\:/i)){var f=o.target&&!o.target.match(/^_(self|parent|top)$/i)?o.target:!1;(e.ctrlKey||e.shiftKey||e.metaKey||2==e.which)&&(f="_blank"),n&&(console.log("Control Key: "+e.ctrlKey),console.log("Shift Key: "+e.shiftKey),console.log("Meta Key: "+e.metaKey),console.log("Which Key: "+e.which),console.log("Target: "+f));var k=!1,v=function(){k||(k=!0,window.location.href=a)};if(f){if("download"==l?"pageview"==d?n?console.log("Target | Download | Send | Pageview | "+a):__gaTracker("send","pageview",a):n?console.log("Target | Download | Send | Event | "+a):__gaTracker("send","event","download",a):"mailto"==l?n?console.log("Target | Mailto | Send | Event | Mailto | "+a):__gaTracker("send","event","mailto",a):"internal-as-outbound"==l?n?console.log("Target | Internal-As-Outbound | Send | event | "+s+" | "+a+" | "+o.title):__gaTracker("send","event",s,a,o.title):"external"==l?n?console.log("Target | External | Send | 'outbound-link' | "+a+" | "+o.title):__gaTracker("send","event","outbound-link",a,o.title):n&&console.log("Target | "+l+" | "+a+" is not a tracked click."),n)return!1}else{if(e.defaultPrevented||(e.preventDefault?e.preventDefault():e.returnValue=!1),"download"==l?"pageview"==d?n?console.log("Not Target | Download | Send | Pageview | "+a):__gaTracker("send","pageview",a,{hitCallback:v}):n?console.log("Not Target | Download | Send | Event | "+a):__gaTracker("send","event","download",{hitCallback:v}):"mailto"==l?n?console.log("Not Target | Mailto | Send | Event | Mailto | "+a):__gaTracker("send","event","mailto",a,{hitCallback:v}):"internal-as-outbound"==l?window.onbeforeunload=function(){n?console.log("Not Target | Internal-As-Outbound | Send | event | "+s+" | "+a+" | "+o.title):navigator.sendBeacon?__gaTracker("send","event",s,a,o.title,{transport:"beacon"}):__gaTracker("send","event",s,a,o.title,{hitCallback:v})}:"external"==l?window.onbeforeunload=function(){n?console.log("Not Target | External | Send | 'outbound-link' | "+a+" | "+o.title):navigator.sendBeacon?__gaTracker("send","event","outbound-link",a,o.title,{transport:"beacon"}):__gaTracker("send","event","outbound-link",a,o.title,{hitCallback:v})}:n&&console.log("Not Target | "+l+" | "+a+" is not a tracked click."),n)return!1;setTimeout(v,1e3)}}}}}var __gaTrackerWindow=window,__gaTrackerEventType="click";__gaTrackerWindow.addEventListener?__gaTrackerWindow.addEventListener("load",function(){document.body.addEventListener(__gaTrackerEventType,__gaTrackerClickEvent,!1)},!1):__gaTrackerWindow.attachEvent&&__gaTrackerWindow.attachEvent("onload",function(){document.body.attachEvent("on"+__gaTrackerEventType,__gaTrackerClickEvent)});
510
  })();
511
  </script>
512
  <!-- End MonsterInsights JS Event Tracking -->
58
  $events = monsterinsights_get_option( 'events_mode', false );
59
  if ( $events === 'js' && $tracking === 'analytics' ) {
60
  add_action( 'wp_head', array( $this, 'output_javascript' ), 9 );
61
+ add_action( 'login_head', array( $this, 'output_javascript' ), 9 );
62
  }
63
  }
64
 
313
  };
314
  }
315
 
316
+ function monsterinsightsStringTrim(x) {
317
+ return x.replace(/^\s+|\s+$/gm,'');
318
+ }
319
+
320
  if ( is_debug_mode ) {
321
  console.log( "Link: " + link);
322
  console.log( "Extension: " + extension );
327
  }
328
 
329
  /* Let's get the type of click event this is */
330
+ if ( monsterinsightsStringTrim( el.protocol ) == 'mailto' || monsterinsightsStringTrim( el.protocol ) == 'mailto:' ) { /* If it's an email */
331
  type = "mailto";
332
  } else if ( download_extensions.length > 0 && extension.length > 0 && download_extensions.includes(extension) ) { /* If it's a download */
333
  type = "download";
510
  <!-- MonsterInsights JS Event Tracking -->
511
  <script type="text/javascript" data-cfasync="false">
512
  (function(){
513
+ function __gaTrackerClickEventPHP() {var phpvalues = { 'is_debug_mode': <?php echo $is_debug_mode; ?>,'download_extensions': <?php echo $download_extensions; ?>,'inbound_paths': <?php echo $inbound_paths; ?>,'home_url': "<?php echo home_url(); ?>",'track_download_as': "<?php echo $track_download_as; ?>",'internal_label': "<?php echo $internal_label; ?>"};return phpvalues;}
514
+ function __gaTrackerClickEvent(e){function t(e){return e.replace(/^\s+|\s+$/gm,"")}var n=__gaTrackerClickEventPHP(),o=n.is_debug_mode||window.monsterinsights_debug_mode,a=e.srcElement||e.target;if(o&&(console.log("__gaTracker.hasOwnProperty(loaded)"),console.log(__gaTracker.hasOwnProperty("loaded")),console.log("__gaTracker.loaded"),console.log(__gaTracker.loaded),console.log("Event.which: "+e.which),console.log("El: "),console.log(a),console.log("Will track: "+!__gaTracker.hasOwnProperty("loaded")||1!=__gaTracker.loaded||1!=e.which&&2!=e.which&&!e.metaKey&&!e.ctrlKey&&!e.shiftKey&&!e.altKey)),__gaTracker.hasOwnProperty("loaded")&&1==__gaTracker.loaded&&(1==e.which||2==e.which||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey)){for(;a&&("undefined"==typeof a.tagName||"a"!=a.tagName.toLowerCase()||!a.href);)a=a.parentNode;if(a&&a.href){var r=a.href,l=a.href,i="internal",c=n.download_extensions,d=n.inbound_paths,s=(n.home_url,n.track_download_as),g="outbound-link-"+n.internal_label;l=l.substring(0,-1==l.indexOf("#")?l.length:l.indexOf("#")),l=l.substring(0,-1==l.indexOf("?")?l.length:l.indexOf("?")),l=l.substring(l.lastIndexOf("/")+1,l.length),l=l.substring(l.indexOf(".")+1);var h=function(){for(var e=0,t=document.domain,n=t.split("."),o="_gd"+(new Date).getTime();e<n.length-1&&-1==document.cookie.indexOf(o+"="+o);)t=n.slice(-1-++e).join("."),document.cookie=o+"="+o+";domain="+t+";";return document.cookie=o+"=;expires=Thu, 01 Jan 1970 00:00:01 GMT;domain="+t+";",t}();if("function"!=typeof String.prototype.endsWith&&(String.prototype.endsWith=function(e){return-1!==this.indexOf(e,this.length-e.length)}),"function"!=typeof String.prototype.startsWith&&(String.prototype.startsWith=function(e){return 0===this.indexOf(e)}),"function"!=typeof Array.prototype.includes&&Object.defineProperty(Array.prototype,"includes",{value:function(e,t){if(null==this)throw new TypeError('"this" is null or not defined');var n=Object(this),o=n.length>>>0;if(0===o)return!1;for(var a=0|t,r=Math.max(a>=0?a:o-Math.abs(a),0);o>r;){if(n[r]===e)return!0;r++}return!1}}),"function"!=typeof Array.prototype.lastIndexOf&&(Array.prototype.lastIndexOf=function(e){"use strict";if(void 0===this||null===this)throw new TypeError;var t,n,o=Object(this),a=o.length>>>0;if(0===a)return-1;for(t=a-1,arguments.length>1&&(t=Number(arguments[1]),t!=t?t=0:0!=t&&t!=1/0&&t!=-(1/0)&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),n=t>=0?Math.min(t,a-1):a-Math.abs(t);n>=0;n--)if(n in o&&o[n]===e)return n;return-1}),o&&(console.log("Link: "+r),console.log("Extension: "+l),console.log("Protocol: "+a.protocol),console.log("External: "+(a.hostname.length>0&&h.length>0&&!a.hostname.endsWith(h))),console.log("Current domain: "+h),console.log("Link domain: "+a.hostname)),"mailto"==t(a.protocol)||"mailto:"==t(a.protocol))i="mailto";else if(c.length>0&&l.length>0&&c.includes(l))i="download";else if(a.hostname.length>0&&h.length>0&&!a.hostname.endsWith(h))i="external";else{var u,_,f=a.pathname;for(u=0,_=d.length;_>u;++u)if(f.startsWith(d[u])){i="internal-as-outbound";break}}if(o&&console.log("Type: "+i),"internal"!==i&&!r.match(/^javascript\:/i)){var k=a.target&&!a.target.match(/^_(self|parent|top)$/i)?a.target:!1;(e.ctrlKey||e.shiftKey||e.metaKey||2==e.which)&&(k="_blank"),o&&(console.log("Control Key: "+e.ctrlKey),console.log("Shift Key: "+e.shiftKey),console.log("Meta Key: "+e.metaKey),console.log("Which Key: "+e.which),console.log("Target: "+k));var v=!1,T=function(){v||(v=!0,window.location.href=r)};if(k){if("download"==i?"pageview"==s?o?console.log("Target | Download | Send | Pageview | "+r):__gaTracker("send","pageview",r):o?console.log("Target | Download | Send | Event | "+r):__gaTracker("send","event","download",r):"mailto"==i?o?console.log("Target | Mailto | Send | Event | Mailto | "+r):__gaTracker("send","event","mailto",r):"internal-as-outbound"==i?o?console.log("Target | Internal-As-Outbound | Send | event | "+g+" | "+r+" | "+a.title):__gaTracker("send","event",g,r,a.title):"external"==i?o?console.log("Target | External | Send | 'outbound-link' | "+r+" | "+a.title):__gaTracker("send","event","outbound-link",r,a.title):o&&console.log("Target | "+i+" | "+r+" is not a tracked click."),o)return!1}else{if(e.defaultPrevented||(e.preventDefault?e.preventDefault():e.returnValue=!1),"download"==i?"pageview"==s?o?console.log("Not Target | Download | Send | Pageview | "+r):__gaTracker("send","pageview",r,{hitCallback:T}):o?console.log("Not Target | Download | Send | Event | "+r):__gaTracker("send","event","download",{hitCallback:T}):"mailto"==i?o?console.log("Not Target | Mailto | Send | Event | Mailto | "+r):__gaTracker("send","event","mailto",r,{hitCallback:T}):"internal-as-outbound"==i?window.onbeforeunload=function(){o?console.log("Not Target | Internal-As-Outbound | Send | event | "+g+" | "+r+" | "+a.title):navigator.sendBeacon?__gaTracker("send","event",g,r,a.title,{transport:"beacon"}):__gaTracker("send","event",g,r,a.title,{hitCallback:T})}:"external"==i?window.onbeforeunload=function(){o?console.log("Not Target | External | Send | 'outbound-link' | "+r+" | "+a.title):navigator.sendBeacon?__gaTracker("send","event","outbound-link",r,a.title,{transport:"beacon"}):__gaTracker("send","event","outbound-link",r,a.title,{hitCallback:T})}:o&&console.log("Not Target | "+i+" | "+r+" is not a tracked click."),o)return!1;setTimeout(T,1e3)}}}}}var __gaTrackerWindow=window,__gaTrackerEventType="click";__gaTrackerWindow.addEventListener?__gaTrackerWindow.addEventListener("load",function(){document.body.addEventListener(__gaTrackerEventType,__gaTrackerClickEvent,!1)},!1):__gaTrackerWindow.attachEvent&&__gaTrackerWindow.attachEvent("onload",function(){document.body.attachEvent("on"+__gaTrackerEventType,__gaTrackerClickEvent)});
515
  })();
516
  </script>
517
  <!-- End MonsterInsights JS Event Tracking -->
includes/frontend/frontend.php CHANGED
@@ -26,7 +26,8 @@ if ( ! defined( 'ABSPATH' ) ) {
26
  *
27
  * @return array Array of the options to use.
28
  */
29
- function monsterinsights_tracking_script( ) {
 
30
  $tracking_mode = monsterinsights_get_option( 'tracking_mode', 'analytics' );
31
  require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/class-tracking-abstract.php';
32
  $mode = '';
@@ -80,6 +81,7 @@ function monsterinsights_tracking_script( ) {
80
  do_action( 'monsterinsights_tracking_after', $mode );
81
  }
82
  add_action( 'wp_head', 'monsterinsights_tracking_script', 8 );
 
83
 
84
  /**
85
  * Get frontend tracking options.
@@ -96,18 +98,20 @@ add_action( 'wp_head', 'monsterinsights_tracking_script', 8 );
96
  function monsterinsights_events_tracking( ) {
97
  $events_mode = monsterinsights_get_option( 'events_mode', false );
98
  $tracking_mode = monsterinsights_get_option( 'tracking_mode', false );
 
99
 
100
- if ( ! monsterinsights_disabled_user_group() && $events_mode === 'php' && ( $tracking_mode === 'ga' || $tracking_mode === 'analytics' ) ) {
101
  require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/events/class-events-php.php';
102
  new MonsterInsights_Events_PHP();
103
- } else if ( ! monsterinsights_disabled_user_group() && $events_mode === 'js' && $tracking_mode === 'analytics' ) {
104
  require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/events/class-events-js.php';
105
  new MonsterInsights_Events_JS();
106
  } else {
107
  // User is in the disabled group or events mode is off
108
  }
109
  }
110
- add_action( 'template_redirect', 'monsterinsights_events_tracking' );
 
111
 
112
  function monsterinsights_disabled_user_group( ) {
113
  $user = wp_get_current_user();
26
  *
27
  * @return array Array of the options to use.
28
  */
29
+ function monsterinsights_tracking_script( ) {
30
+
31
  $tracking_mode = monsterinsights_get_option( 'tracking_mode', 'analytics' );
32
  require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/class-tracking-abstract.php';
33
  $mode = '';
81
  do_action( 'monsterinsights_tracking_after', $mode );
82
  }
83
  add_action( 'wp_head', 'monsterinsights_tracking_script', 8 );
84
+ add_action( 'login_head', 'monsterinsights_tracking_script', 8 );
85
 
86
  /**
87
  * Get frontend tracking options.
98
  function monsterinsights_events_tracking( ) {
99
  $events_mode = monsterinsights_get_option( 'events_mode', false );
100
  $tracking_mode = monsterinsights_get_option( 'tracking_mode', false );
101
+ $disabled_user = monsterinsights_disabled_user_group();
102
 
103
+ if ( ! $disabled_user && $events_mode === 'php' && ( $tracking_mode === 'ga' || $tracking_mode === 'analytics' ) ) {
104
  require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/events/class-events-php.php';
105
  new MonsterInsights_Events_PHP();
106
+ } else if ( ! $disabled_user && $events_mode === 'js' && $tracking_mode === 'analytics' ) {
107
  require_once plugin_dir_path( MONSTERINSIGHTS_PLUGIN_FILE ) . 'includes/frontend/events/class-events-js.php';
108
  new MonsterInsights_Events_JS();
109
  } else {
110
  // User is in the disabled group or events mode is off
111
  }
112
  }
113
+ add_action( 'template_redirect', 'monsterinsights_events_tracking', 9 );
114
+ add_action( 'login_head', 'monsterinsights_events_tracking', 8 );
115
 
116
  function monsterinsights_disabled_user_group( ) {
117
  $user = wp_get_current_user();
includes/frontend/tracking/class-tracking-analytics.php CHANGED
@@ -182,27 +182,26 @@ class MonsterInsights_Tracking_Analytics extends MonsterInsights_Tracking_Abstra
182
  <!-- This site uses the Google Analytics by MonsterInsights plugin v<?php echo MONSTERINSIGHTS_VERSION; ?> - Using Analytics tracking - https://www.monsterinsights.com/ -->
183
  <?php if ( monsterinsights_get_ua() ) { ?>
184
  <script type="text/javascript" data-cfasync="false">
185
- (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
186
- (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
187
- m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
188
- })(window,document,'script','<?php echo $src; ?>','__gaTracker');
189
-
190
- <?php
191
- if ( current_user_can( 'manage_options' ) && $is_debug_mode ) {
192
- echo 'window.ga_debug = {trace: true};';
193
- }
194
- echo $compat;
195
- if ( count( $options ) >= 1 ) {
196
- foreach ( $options as $item ) {
197
- if ( ! is_array( $item ) ) {
198
- echo ' __gaTracker(' . $item . ");\n";
199
- } else if ( ! empty ( $item['value'] ) ) {
200
- echo ' ' . $item['value'] . "\n";
201
- }
202
  }
203
  }
204
- ?>
205
-
206
  </script>
207
  <?php } else { ?>
208
  <!-- No UA code set -->
182
  <!-- This site uses the Google Analytics by MonsterInsights plugin v<?php echo MONSTERINSIGHTS_VERSION; ?> - Using Analytics tracking - https://www.monsterinsights.com/ -->
183
  <?php if ( monsterinsights_get_ua() ) { ?>
184
  <script type="text/javascript" data-cfasync="false">
185
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
186
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
187
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
188
+ })(window,document,'script','<?php echo $src; ?>','__gaTracker');
189
+
190
+ <?php
191
+ if ( current_user_can( 'manage_options' ) && $is_debug_mode ) {
192
+ echo 'window.ga_debug = {trace: true};';
193
+ }
194
+ echo $compat;
195
+ if ( count( $options ) >= 1 ) {
196
+ foreach ( $options as $item ) {
197
+ if ( ! is_array( $item ) ) {
198
+ echo ' __gaTracker(' . $item . ");\n";
199
+ } else if ( ! empty ( $item['value'] ) ) {
200
+ echo ' ' . $item['value'] . "\n";
 
201
  }
202
  }
203
+ }
204
+ ?>
205
  </script>
206
  <?php } else { ?>
207
  <!-- No UA code set -->
includes/install.php CHANGED
@@ -63,6 +63,7 @@ class MonsterInsights_Install {
63
 
64
  $version = get_option( 'monsterinsights_current_version', false );
65
  $yoast = get_option( 'yst_ga', false );
 
66
 
67
  // if new install and have not used Yoast previously
68
  if ( ! $version && ! $yoast ) {
@@ -76,11 +77,24 @@ class MonsterInsights_Install {
76
  $this->upgrade_from_yoast();
77
  // This is the version used for MI upgrade routines.
78
  update_option( 'monsterinsights_db_version', '6.0.0' );
 
 
 
 
 
79
 
80
  } else { // if existing install
81
  if ( version_compare( $version, '6.0.2', '<' ) ) {
82
  $this->v602_upgrades();
83
  }
 
 
 
 
 
 
 
 
84
  // @todo: doc as nonpublic
85
 
86
  update_option( 'monsterinsights_version_upgraded_from', $version );
@@ -631,6 +645,33 @@ class MonsterInsights_Install {
631
  }
632
  }
633
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
634
  /**
635
  * MonsterInsights Version 6.1 upgrades.
636
  *
@@ -649,9 +690,8 @@ class MonsterInsights_Install {
649
  * Running List of Things To Do In 6.1.0's Upgrade Routine
650
  *
651
  * 1. Drop Yoast yst_ga options if the upgraded from option === 6.0 or higher
652
- * 2. Remove the Yoast scheduled cron event if the upgraded from option === 6.0 or higher
653
- * 3. Remove yst_ga support from helper options
654
- * 4. Remove track_full_url
655
  */
656
  }
657
  }
63
 
64
  $version = get_option( 'monsterinsights_current_version', false );
65
  $yoast = get_option( 'yst_ga', false );
66
+ $cachec = false; // have we forced an object cache to be cleared already (so we don't clear it unnecessarily)
67
 
68
  // if new install and have not used Yoast previously
69
  if ( ! $version && ! $yoast ) {
77
  $this->upgrade_from_yoast();
78
  // This is the version used for MI upgrade routines.
79
  update_option( 'monsterinsights_db_version', '6.0.0' );
80
+
81
+ if ( ! $cachec ) {
82
+ wp_cache_flush();
83
+ $cachec = true;
84
+ }
85
 
86
  } else { // if existing install
87
  if ( version_compare( $version, '6.0.2', '<' ) ) {
88
  $this->v602_upgrades();
89
  }
90
+ if ( version_compare( $version, '6.0.11', '<' ) ) {
91
+ $this->v6011_upgrades();
92
+
93
+ if ( ! $cachec ) {
94
+ wp_cache_flush();
95
+ $cachec = true;
96
+ }
97
+ }
98
  // @todo: doc as nonpublic
99
 
100
  update_option( 'monsterinsights_version_upgraded_from', $version );
645
  }
646
  }
647
 
648
+ /**
649
+ * MonsterInsights Version 6.0.11 upgrades.
650
+ *
651
+ * This upgrade routine finds and removes the old crons if they exist.
652
+ *
653
+ * @since 6.0.11
654
+ * @access public
655
+ *
656
+ * @return void
657
+ */
658
+ public function v6011_upgrades() {
659
+ // If old tracking checkin exists, remove it
660
+ if ( wp_next_scheduled( 'monsterinsights_send_tracking_checkin' ) ) {
661
+ wp_clear_scheduled_hook( 'monsterinsights_send_tracking_checkin' );
662
+ }
663
+
664
+ // Remove Weekly cron
665
+ if ( wp_next_scheduled( 'monsterinsights_weekly_cron' ) ) {
666
+ wp_clear_scheduled_hook( 'monsterinsights_weekly_cron' );
667
+ }
668
+
669
+ // Remove Yoast cron
670
+ if ( wp_next_scheduled( 'yst_ga_aggregate_data' ) ) {
671
+ wp_clear_scheduled_hook( 'yst_ga_aggregate_data' );
672
+ }
673
+ }
674
+
675
  /**
676
  * MonsterInsights Version 6.1 upgrades.
677
  *
690
  * Running List of Things To Do In 6.1.0's Upgrade Routine
691
  *
692
  * 1. Drop Yoast yst_ga options if the upgraded from option === 6.0 or higher
693
+ * 2. Remove yst_ga support from helper options
694
+ * 3. Remove track_full_url
 
695
  */
696
  }
697
  }
includes/options.php CHANGED
@@ -150,7 +150,6 @@ function monsterinsights_update_option( $key = '', $value = false ) {
150
  // $did_update = update_site_option( $option_name, $settings );
151
  //} else {
152
  $did_update = update_option( $option_name, $settings );
153
- update_option( 'yst_ga', $settings ); // Will remove at some point. Please use the helper function instead of calling this option directly.
154
  //}
155
 
156
  // If it updated, let's update the global variable
@@ -201,7 +200,6 @@ function monsterinsights_delete_option( $key = '' ) {
201
  // $did_update = update_site_option( 'monsterinsights_settings', $settings );
202
  //} else {
203
  $did_update = update_option( $option_name, $settings );
204
- update_option( 'yst_ga', $settings ); // Will remove at some point. Please use the helper function instead of calling this option directly.
205
  //}
206
 
207
  // If it updated, let's update the global variable
@@ -254,7 +252,6 @@ function monsterinsights_delete_options( $keys = array() ) {
254
  // $did_update = update_site_option( 'monsterinsights_settings', $settings );
255
  //} else {
256
  $did_update = update_option( $option_name, $settings );
257
- update_option( 'yst_ga', $settings ); // Will remove at some point. Please use the helper function instead of calling this option directly.
258
  //}
259
 
260
  // If it updated, let's update the global variable
150
  // $did_update = update_site_option( $option_name, $settings );
151
  //} else {
152
  $did_update = update_option( $option_name, $settings );
 
153
  //}
154
 
155
  // If it updated, let's update the global variable
200
  // $did_update = update_site_option( 'monsterinsights_settings', $settings );
201
  //} else {
202
  $did_update = update_option( $option_name, $settings );
 
203
  //}
204
 
205
  // If it updated, let's update the global variable
252
  // $did_update = update_site_option( 'monsterinsights_settings', $settings );
253
  //} else {
254
  $did_update = update_option( $option_name, $settings );
 
255
  //}
256
 
257
  // If it updated, let's update the global variable
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://www.wpbeginner.com/wpbeginner-needs-your-help/
4
  Tags: analytics, analytics dashboard, google analytics, google analytics dashboard, google analytics widget, universal google analytics, statistics, tracking, stats, google, yoast, google analytics by yoast, ga, monster insights, monsterinsights, universal analytics, web stats, ecommerce, ecommerce tracking
5
  Requires at least: 3.9
6
  Tested up to: 4.7.2
7
- Stable tag: 6.0.4
8
  License: GPL v3
9
 
10
  The best Google Analytics plugin for WordPress. See how visitors find and use your website, so you can keep them coming back.
@@ -137,6 +137,29 @@ You can also learn about other <a href="http://www.wpbeginner.com/category/plugi
137
 
138
  == Changelog ==
139
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  = 6.0.4, February 20, 2017 =
141
  * Tweak: monsterinsights_delete_options now checks to ensure an array is passed in
142
  * Tweak: The reporting class now has many more object property checks.
4
  Tags: analytics, analytics dashboard, google analytics, google analytics dashboard, google analytics widget, universal google analytics, statistics, tracking, stats, google, yoast, google analytics by yoast, ga, monster insights, monsterinsights, universal analytics, web stats, ecommerce, ecommerce tracking
5
  Requires at least: 3.9
6
  Tested up to: 4.7.2
7
+ Stable tag: 6.0.11
8
  License: GPL v3
9
 
10
  The best Google Analytics plugin for WordPress. See how visitors find and use your website, so you can keep them coming back.
137
 
138
  == Changelog ==
139
 
140
+ = 6.0.11, February 24, 2017 =
141
+ * Notice: Version numbers 6.0.5 - 6.0.10 were not used, as we're synching the version numbers of the Lite and Pro versions of our plugin. You didn't miss any updates.
142
+ * Notice: As of this release, we no longer backport changes to the old `yst_ga` option. If you need to access MonsterInsights's settings programically, please use our helper functions. Do not directly access a option.
143
+ * New: Redesigned authentication dropdown that shows the site urls to make it easier to find a profile when the users have many accounts.
144
+ * New: Tracking is now enabled for the WordPress admin login page (wp-login.php).
145
+ * Tweak: The Google class in the admin now only checks for blocking when the reauth is attempted. Expect to save a ton of external calls in the admin, and maybe a performance boost.
146
+ * Tweak: The GA client object is now lazyloaded on the frontend, so it's loaded only when something (like another plugin) attempts to use it. In plain English, this will make a alot of sites load times significantly improve.
147
+ * Tweak: The analytics.js output has been tweaked to be slightly more asthetically pleasing (its aligned correctly). We realize no one probably cares but we look at this code for every user we support, so it help us.
148
+ * Tweak: The config expired notice has been updated to reflect that it can also be shown if the server is blocking MonsterInsights's ability to connect to Google Analytics.
149
+ * Tweak: The cron jobs for opt-in tracking and statistics have been combined into a single cron.
150
+ * Tweak: Various performance improvements in the frontend output class.
151
+ * Tweak: A notice is now shown when MonsterInsights rejects a manual UA code from being saved for being an invalid format.
152
+ * Fixed: Issue where the plugin TweetShare would prevent users from being able to see their properties in the authentication dropdown.
153
+ * Fixed: Issue where the manual UA code might not be ported as we were backporting changes to the monsterinsights_settings option to the yst_ga option for backwards compatibility. This lead to a situation where the new settings would override the old ones before the routine to fix the manual UA code issue had run.
154
+ * Fixed: Issue where a fatal error from a reference to a class called "Yoast_Frontend_GA" which our plugin doesn't have or use, would be shown caused by the previous Yoast usage of object caching via an autoloader. This is solved by doing a 1 time object cache flush on upgrade.
155
+ * Fixed: Issue where if you had more than 1000 profiles on your Google account, not all would be shown.
156
+ * Fixed: App analytics properties are now excluded from the dropdown of properties you can authenticate to.
157
+ * Fixed: The readme suggested a filter to use for filtering the UA to use, but the filter name was typo'd. This has been fixed.
158
+ * Fixed: Issue where the tracking cron would add a new unique cron each day.
159
+ * Fixed: We implemented a routine to cleanup those extra crons as well as the old yoast one we no longer use.
160
+ * Fixed: Issue where the .org theme Schema would prevent users from being able to see their properties in the authentication dropdown.
161
+ * Fixed: Issue where JS based events tracking might not correctly track a mailto: link.
162
+
163
  = 6.0.4, February 20, 2017 =
164
  * Tweak: monsterinsights_delete_options now checks to ensure an array is passed in
165
  * Tweak: The reporting class now has many more object property checks.