Google Analytics for WordPress by MonsterInsights - Version 5.2.7

Version Description

Release Date: December 18th, 2014

  • Bugfixes:

    • Increase timeout limit for request to Google API to prevent quickly session time-outs.
    • Setting SSL verifier to FALSE, to prevent checking SSL-chain.
    • Checking for cURL version 7.19, it this version is used the plugin switches to http streams.
  • Enhancements:

    • Using webproperties instead of account names in the select box for choosing the Google Analytics profile.
Download this release

Release Info

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

Code changes from version 5.2.6 to 5.2.7

admin/api-libs/google/io/Google_WPIO.php CHANGED
@@ -19,12 +19,11 @@
19
  * WP based implementation of apiIO.
20
  *
21
  */
22
-
23
  class Yoast_Google_WPIO extends Yoast_Google_IO {
24
- private static $ENTITY_HTTP_METHODS = array("POST" => null, "PUT" => null);
25
  private static $HOP_BY_HOP = array(
26
  'connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization',
27
- 'te', 'trailers', 'transfer-encoding', 'upgrade');
28
 
29
  /**
30
  * Perform an authenticated / signed apiHttpRequest.
@@ -33,51 +32,63 @@ class Yoast_Google_WPIO extends Yoast_Google_IO {
33
  * and then calls apiWPIO::makeRequest on the signed request
34
  *
35
  * @param Yoast_Google_HttpRequest $request
 
36
  * @return Yoast_Google_HttpRequest The resulting HTTP response including the
37
  * responseHttpCode, responseHeaders and responseBody.
38
  */
39
- public function authenticatedRequest(Yoast_Google_HttpRequest $request) {
40
- $request = Yoast_Google_Client::$auth->sign($request);
41
- return $this->makeRequest($request);
 
42
  }
43
 
44
  /**
45
  * Execute a apiHttpRequest
46
  *
47
  * @param Yoast_Google_HttpRequest $request the http request to be executed
 
48
  * @return Yoast_Google_HttpRequest http request with the response http code, response
49
  * headers and response body filled in
50
  */
51
- public function makeRequest(Yoast_Google_HttpRequest $request) {
52
 
53
  // First, check to see if we have a valid cached version.
54
- $cached = $this->getCachedRequest($request);
55
- if ($cached !== false) {
56
- if (!$this->checkMustRevaliadateCachedRequest($cached, $request)) {
57
  return $cached;
58
  }
59
  }
60
 
61
- if (array_key_exists($request->getRequestMethod(),
62
- self::$ENTITY_HTTP_METHODS)) {
63
- $request = $this->processEntityRequest($request);
64
  }
65
 
66
  $params = array(
67
- 'user-agent' => $request->getUserAgent()
 
 
68
  );
69
 
70
- if ($request->getPostBody()) {
 
 
 
 
 
 
 
71
  $params['body'] = $request->getPostBody();
72
  }
73
 
74
  $requestHeaders = $request->getRequestHeaders();
75
- if ($requestHeaders && is_array($requestHeaders)) {
76
  $params['headers'] = $requestHeaders;
77
  }
78
 
79
 
80
- switch( $request->getRequestMethod() ) {
81
  case 'POST' :
82
  $response = wp_remote_post( $request->getUrl(), $params );
83
  break;
@@ -91,32 +102,64 @@ class Yoast_Google_WPIO extends Yoast_Google_IO {
91
  $respHttpCode = wp_remote_retrieve_response_code( $response );
92
  $responseHeaders = wp_remote_retrieve_headers( $response );
93
 
94
- if ($respHttpCode == 304 && $cached) {
95
  // If the server responded NOT_MODIFIED, return the cached request.
96
- $this->updateCachedRequest($cached, $responseHeaders);
 
97
  return $cached;
98
  }
99
 
100
  // Fill in the apiHttpRequest with the response values
101
- $request->setResponseHttpCode($respHttpCode);
102
- $request->setResponseHeaders($responseHeaders);
103
 
104
- $request->setResponseBody($responseBody);
105
  // Store the request in cache (the function checks to see if the request
106
  // can actually be cached)
107
- $this->setCachedRequest($request);
 
108
  // And finally return it
109
 
110
  return $request;
111
  }
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
  /**
114
  * Set options that update default behavior.
115
  *
116
  * @param array $optParams Multiple options used by a session.
117
  */
118
- public function setOptions($optParams) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
 
120
  }
121
 
122
  }
19
  * WP based implementation of apiIO.
20
  *
21
  */
 
22
  class Yoast_Google_WPIO extends Yoast_Google_IO {
23
+ private static $ENTITY_HTTP_METHODS = array( "POST" => null, "PUT" => null );
24
  private static $HOP_BY_HOP = array(
25
  'connection', 'keep-alive', 'proxy-authenticate', 'proxy-authorization',
26
+ 'te', 'trailers', 'transfer-encoding', 'upgrade' );
27
 
28
  /**
29
  * Perform an authenticated / signed apiHttpRequest.
32
  * and then calls apiWPIO::makeRequest on the signed request
33
  *
34
  * @param Yoast_Google_HttpRequest $request
35
+ *
36
  * @return Yoast_Google_HttpRequest The resulting HTTP response including the
37
  * responseHttpCode, responseHeaders and responseBody.
38
  */
39
+ public function authenticatedRequest( Yoast_Google_HttpRequest $request ) {
40
+ $request = Yoast_Google_Client::$auth->sign( $request );
41
+
42
+ return $this->makeRequest( $request );
43
  }
44
 
45
  /**
46
  * Execute a apiHttpRequest
47
  *
48
  * @param Yoast_Google_HttpRequest $request the http request to be executed
49
+ *
50
  * @return Yoast_Google_HttpRequest http request with the response http code, response
51
  * headers and response body filled in
52
  */
53
+ public function makeRequest( Yoast_Google_HttpRequest $request ) {
54
 
55
  // First, check to see if we have a valid cached version.
56
+ $cached = $this->getCachedRequest( $request );
57
+ if ( $cached !== false ) {
58
+ if ( ! $this->checkMustRevaliadateCachedRequest( $cached, $request ) ) {
59
  return $cached;
60
  }
61
  }
62
 
63
+ if ( array_key_exists( $request->getRequestMethod(),
64
+ self::$ENTITY_HTTP_METHODS ) ) {
65
+ $request = $this->processEntityRequest( $request );
66
  }
67
 
68
  $params = array(
69
+ 'user-agent' => $request->getUserAgent(),
70
+ 'timeout' => 30,
71
+ 'sslverify' => false,
72
  );
73
 
74
+ $curl_version = $this->get_curl_version();
75
+ if( $curl_version !== false ) {
76
+ if ( version_compare( $curl_version, '7.19.0', '<=' ) && version_compare( $curl_version, '7.19.8', '>' ) ) {
77
+ add_filter( 'http_api_transports', array( $this, 'filter_curl_from_transports' ) );
78
+ }
79
+ }
80
+
81
+ if ( $request->getPostBody() ) {
82
  $params['body'] = $request->getPostBody();
83
  }
84
 
85
  $requestHeaders = $request->getRequestHeaders();
86
+ if ( $requestHeaders && is_array( $requestHeaders ) ) {
87
  $params['headers'] = $requestHeaders;
88
  }
89
 
90
 
91
+ switch ( $request->getRequestMethod() ) {
92
  case 'POST' :
93
  $response = wp_remote_post( $request->getUrl(), $params );
94
  break;
102
  $respHttpCode = wp_remote_retrieve_response_code( $response );
103
  $responseHeaders = wp_remote_retrieve_headers( $response );
104
 
105
+ if ( $respHttpCode == 304 && $cached ) {
106
  // If the server responded NOT_MODIFIED, return the cached request.
107
+ $this->updateCachedRequest( $cached, $responseHeaders );
108
+
109
  return $cached;
110
  }
111
 
112
  // Fill in the apiHttpRequest with the response values
113
+ $request->setResponseHttpCode( $respHttpCode );
114
+ $request->setResponseHeaders( $responseHeaders );
115
 
116
+ $request->setResponseBody( $responseBody );
117
  // Store the request in cache (the function checks to see if the request
118
  // can actually be cached)
119
+ $this->setCachedRequest( $request );
120
+
121
  // And finally return it
122
 
123
  return $request;
124
  }
125
 
126
+ /**
127
+ * Remove Curl from the transport
128
+ *
129
+ * @param $transports
130
+ *
131
+ * @return mixed
132
+ */
133
+ public function filter_curl_from_transports( $transports ) {
134
+ unset( $transports['curl'] );
135
+
136
+ return $transports;
137
+ }
138
+
139
  /**
140
  * Set options that update default behavior.
141
  *
142
  * @param array $optParams Multiple options used by a session.
143
  */
144
+ public function setOptions( $optParams ) {
145
+
146
+ }
147
+
148
+ /**
149
+ * Get the current curl verison if curl is installed
150
+ *
151
+ * @return bool|string
152
+ */
153
+ public function get_curl_version() {
154
+ if ( function_exists( 'curl_version' ) ) {
155
+ $curl = curl_version();
156
+
157
+ if ( isset( $curl['version'] ) ) {
158
+ return $curl['version'];
159
+ }
160
+ }
161
 
162
+ return false;
163
  }
164
 
165
  }
admin/api-libs/googleanalytics/class-google-analytics-client.php CHANGED
@@ -13,6 +13,7 @@ class Yoast_Google_Analytics_Client extends Yoast_Google_Client {
13
 
14
  /**
15
  * Initialize the config and refresh the token
 
16
  * @param array $config
17
  */
18
  public function __construct( $config ) {
@@ -58,7 +59,7 @@ class Yoast_Google_Analytics_Client extends Yoast_Google_Client {
58
  // Set our settings
59
  $this->setRedirectUri( $config['redirect_uri'] );
60
  $this->setScopes( $config['scopes'] );
61
- $this->setAccessType('offline');
62
  }
63
 
64
  /**
@@ -83,8 +84,8 @@ class Yoast_Google_Analytics_Client extends Yoast_Google_Client {
83
  $this->setAccessToken( $response->access_token );
84
  }
85
  }
86
- } catch(Exception $e) {
87
- $this->save_refresh_token('');
88
  }
89
  }
90
  }
@@ -98,6 +99,7 @@ class Yoast_Google_Analytics_Client extends Yoast_Google_Client {
98
  * @return bool
99
  */
100
  public function authenticate_client( $authorization_code = null ) {
 
101
 
102
  // Authenticate client
103
  try {
@@ -107,7 +109,7 @@ class Yoast_Google_Analytics_Client extends Yoast_Google_Client {
107
  $response = $this->getAccessToken();
108
 
109
  // Check if there is a response body
110
- if ( !empty( $response ) ) {
111
  $response = json_decode( $response );
112
 
113
  if ( is_object( $response ) ) {
@@ -119,8 +121,15 @@ class Yoast_Google_Analytics_Client extends Yoast_Google_Client {
119
 
120
  }
121
  } catch ( Yoast_Google_AuthException $exception ) {
122
- return false;
 
 
 
 
 
123
  }
 
 
124
  }
125
 
126
  /**
@@ -158,7 +167,7 @@ class Yoast_Google_Analytics_Client extends Yoast_Google_Client {
158
  * @param $refresh_token
159
  */
160
  public function save_refresh_token( $refresh_token ) {
161
- update_option( self::OPTION_REFRESH_TOKEN, $refresh_token );
162
  }
163
 
164
  /**
13
 
14
  /**
15
  * Initialize the config and refresh the token
16
+ *
17
  * @param array $config
18
  */
19
  public function __construct( $config ) {
59
  // Set our settings
60
  $this->setRedirectUri( $config['redirect_uri'] );
61
  $this->setScopes( $config['scopes'] );
62
+ $this->setAccessType( 'offline' );
63
  }
64
 
65
  /**
84
  $this->setAccessToken( $response->access_token );
85
  }
86
  }
87
+ } catch ( Exception $e ) {
88
+
89
  }
90
  }
91
  }
99
  * @return bool
100
  */
101
  public function authenticate_client( $authorization_code = null ) {
102
+ static $has_retried;
103
 
104
  // Authenticate client
105
  try {
109
  $response = $this->getAccessToken();
110
 
111
  // Check if there is a response body
112
+ if ( ! empty( $response ) ) {
113
  $response = json_decode( $response );
114
 
115
  if ( is_object( $response ) ) {
121
 
122
  }
123
  } catch ( Yoast_Google_AuthException $exception ) {
124
+ // If there aren't any attempts before, try again and set attempts on true, to prevent further attempts
125
+ if ( empty( $has_retried ) ) {
126
+ $has_retried = true;
127
+
128
+ return $this->authenticate_client( $authorization_code );
129
+ }
130
  }
131
+
132
+ return false;
133
  }
134
 
135
  /**
167
  * @param $refresh_token
168
  */
169
  public function save_refresh_token( $refresh_token ) {
170
+ update_option( self::OPTION_REFRESH_TOKEN, trim( $refresh_token ) );
171
  }
172
 
173
  /**
admin/class-admin-assets.php CHANGED
@@ -11,7 +11,9 @@ if ( ! class_exists( 'Yoast_GA_Admin_Assets' ) ) {
11
  * Add the scripts to the admin head
12
  */
13
  public static function enqueue_scripts() {
14
- wp_enqueue_script( 'yoast_ga_admin', self::get_asset_path( 'assets/js/yoast_ga_admin' ) . self::file_ext( '.js' ), array( 'jquery' ), GAWP_VERSION );
 
 
15
 
16
  // Enqueue the qtip js file
17
  wp_enqueue_script( 'jquery-qtip', self::get_asset_path( 'assets/dependencies/qtip/jquery.qtip.min.js' ) , array( 'jquery' ), '1.0.0-RC3', true );
11
  * Add the scripts to the admin head
12
  */
13
  public static function enqueue_scripts() {
14
+ wp_enqueue_script( 'yoast_focusable', self::get_asset_path( 'assets/dependencies/focusable/focus-element-overlay.min.js' ), array( 'jquery' ), false );
15
+
16
+ wp_enqueue_script( 'yoast_ga_admin', self::get_asset_path( 'assets/js/yoast_ga_admin' ) . self::file_ext( '.js' ), array( 'jquery', 'yoast_focusable' ), GAWP_VERSION );
17
 
18
  // Enqueue the qtip js file
19
  wp_enqueue_script( 'jquery-qtip', self::get_asset_path( 'assets/dependencies/qtip/jquery.qtip.min.js' ) , array( 'jquery' ), '1.0.0-RC3', true );
admin/class-admin-form.php CHANGED
@@ -136,18 +136,12 @@ if ( ! class_exists( 'Yoast_GA_Admin_Form' ) ) {
136
  $select_value = self::get_formfield_from_options( $name );
137
 
138
  foreach ( $values as $optgroup => $value ) {
139
- if ( ! empty( $value['options'] ) ) {
140
- $select .= '<optgroup label="' . $optgroup . '">';
141
-
142
- foreach ( $value['options'] as $option ) {
143
- $select .= self::option( $select_value, $option );
144
- }
145
-
146
- $select .= '</optgroup>';
147
-
148
  } else {
149
  $select .= self::option( $select_value, $value );
150
  }
 
151
  }
152
  }
153
  $select .= '</select>';
@@ -241,7 +235,10 @@ if ( ! class_exists( 'Yoast_GA_Admin_Form' ) ) {
241
  public static function parse_optgroups( $values ) {
242
  $optgroups = array();
243
  foreach ( $values as $key => $value ) {
244
- $optgroups[$value['parent_name']]['options'] = $value['profiles'];
 
 
 
245
  }
246
 
247
  return $optgroups;
@@ -260,6 +257,33 @@ if ( ! class_exists( 'Yoast_GA_Admin_Form' ) ) {
260
  return '<label class="ga-form ga-form-' . $type . '-label ga-form-label-left" id="yoast-ga-form-label-' . $type . '-' . self::$form_namespace . '-' . $id . '" />' . $title . ':</label>';
261
  }
262
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
263
  /**
264
  * Getting the value from the option, if it doesn't exist return empty string
265
  *
136
  $select_value = self::get_formfield_from_options( $name );
137
 
138
  foreach ( $values as $optgroup => $value ) {
139
+ if ( ! empty( $value['items'] ) ) {
140
+ $select .= self::create_optgroup( $optgroup, $value, $select_value );
 
 
 
 
 
 
 
141
  } else {
142
  $select .= self::option( $select_value, $value );
143
  }
144
+
145
  }
146
  }
147
  $select .= '</select>';
235
  public static function parse_optgroups( $values ) {
236
  $optgroups = array();
237
  foreach ( $values as $key => $value ) {
238
+ foreach ( $value['items'] AS $subitem ) {
239
+ $optgroups[$subitem['name']]['items'] = $subitem['items'];
240
+ }
241
+
242
  }
243
 
244
  return $optgroups;
257
  return '<label class="ga-form ga-form-' . $type . '-label ga-form-label-left" id="yoast-ga-form-label-' . $type . '-' . self::$form_namespace . '-' . $id . '" />' . $title . ':</label>';
258
  }
259
 
260
+ /**
261
+ * Creates a optgroup with the items. If items contain items it will create a nested optgroup
262
+ *
263
+ * @param string $optgroup
264
+ * @param array $value
265
+ * @param array $select_value
266
+ *
267
+ * @return string
268
+ */
269
+ private static function create_optgroup( $optgroup, $value, $select_value ) {
270
+ $optgroup = '<optgroup label="' . $optgroup . '">';
271
+
272
+ foreach ( $value['items'] as $option ) {
273
+ if ( ! empty( $option['items'] ) ) {
274
+
275
+ $optgroup .= self::create_optgroup( $option['name'], $option, $select_value );
276
+ } else {
277
+ $optgroup .= self::option( $select_value, $option );
278
+ }
279
+ }
280
+
281
+ $optgroup .= '</optgroup>';
282
+
283
+ return $optgroup;
284
+ }
285
+
286
+
287
  /**
288
  * Getting the value from the option, if it doesn't exist return empty string
289
  *
admin/class-admin.php CHANGED
@@ -43,17 +43,15 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
43
  // Listener for reconnecting with google analytics
44
  $this->google_analytics_listener();
45
 
46
- if ( is_null( $this->get_tracking_code() ) ) {
47
  add_action( 'admin_notices', array( $this, 'config_warning' ) );
48
  }
49
 
50
- $last_run = get_transient( 'yst_ga_last_wp_run' );
51
  if ( $last_run === false || Yoast_GA_Utils::hours_between( strtotime( $last_run ), time() ) >= 48 ) {
52
  // Show error, something went wrong
53
- if ( ! is_null( $this->get_tracking_code() ) ) {
54
- if ( ! isset( $_GET['page'] ) || ( isset( $_GET['page'] ) && $_GET['page'] !== 'yst_ga_settings' ) ) {
55
- add_action( 'admin_notices', array( $this, 'warning_fetching_data' ) );
56
- }
57
  }
58
  }
59
 
@@ -138,7 +136,7 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
138
  // Fail, add a new notification
139
  $this->add_notification( 'ga_notifications', array(
140
  'type' => 'error',
141
- 'description' => __( 'There where no changes to save, please try again.', 'google-analytics-for-wordpress' ),
142
  ) );
143
  }
144
 
@@ -161,6 +159,21 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
161
 
162
  }
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
  /**
165
  * Transform the Profile ID into an helpful UA code
166
  *
@@ -172,10 +185,12 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
172
  $profiles = $this->get_profiles();
173
  $ua_code = null;
174
 
175
- foreach ( $profiles as $profile ) {
176
- foreach ( $profile['profiles'] as $subprofile ) {
177
- if ( isset( $subprofile['id'] ) && $subprofile['id'] == $profile_id ) {
178
- $ua_code = $subprofile['ua_code'];
 
 
179
  }
180
  }
181
  }
@@ -270,6 +285,7 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
270
  }
271
  }
272
 
 
273
  /**
274
  * Get the Google Analytics profiles which are in this google account
275
  *
@@ -281,14 +297,13 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
281
  return $return;
282
  }
283
 
284
-
285
  /**
286
  * Checks if there is a callback or reauth to get token from Google Analytics api
287
  */
288
  private function google_analytics_listener() {
289
 
290
  if ( ! empty( $_POST['google_auth_code'] ) ) {
291
- Yoast_Google_Analytics::get_instance()->authenticate( $_POST['google_auth_code'] );
292
  }
293
 
294
 
43
  // Listener for reconnecting with google analytics
44
  $this->google_analytics_listener();
45
 
46
+ if ( is_null( $this->get_tracking_code() ) && $this->show_admin_warning() ) {
47
  add_action( 'admin_notices', array( $this, 'config_warning' ) );
48
  }
49
 
50
+ $last_run = get_option( 'yst_ga_last_wp_run' );
51
  if ( $last_run === false || Yoast_GA_Utils::hours_between( strtotime( $last_run ), time() ) >= 48 ) {
52
  // Show error, something went wrong
53
+ if ( ! is_null( $this->get_tracking_code() ) && empty( $this->options['manual_ua_code_field'] ) && $this->show_admin_warning() ) {
54
+ add_action( 'admin_notices', array( $this, 'warning_fetching_data' ) );
 
 
55
  }
56
  }
57
 
136
  // Fail, add a new notification
137
  $this->add_notification( 'ga_notifications', array(
138
  'type' => 'error',
139
+ 'description' => __( 'There were no changes to save, please try again.', 'google-analytics-for-wordpress' ),
140
  ) );
141
  }
142
 
159
 
160
  }
161
 
162
+ /**
163
+ * Are we allowed to show an warning message? returns true if it's allowed
164
+ *
165
+ * @return bool
166
+ */
167
+ private function show_admin_warning() {
168
+ if ( current_user_can( 'manage_options' ) ) {
169
+ if ( ! isset( $_GET['page'] ) || ( isset( $_GET['page'] ) && $_GET['page'] !== 'yst_ga_settings' ) ) {
170
+ return true;
171
+ }
172
+ }
173
+
174
+ return false;
175
+ }
176
+
177
  /**
178
  * Transform the Profile ID into an helpful UA code
179
  *
185
  $profiles = $this->get_profiles();
186
  $ua_code = null;
187
 
188
+ foreach ( $profiles as $account ) {
189
+ foreach ( $account['items'] as $profile ) {
190
+ foreach ( $profile['items'] as $subprofile ) {
191
+ if ( isset( $subprofile['id'] ) && $subprofile['id'] === $profile_id ) {
192
+ return $subprofile['ua_code'];
193
+ }
194
  }
195
  }
196
  }
285
  }
286
  }
287
 
288
+
289
  /**
290
  * Get the Google Analytics profiles which are in this google account
291
  *
297
  return $return;
298
  }
299
 
 
300
  /**
301
  * Checks if there is a callback or reauth to get token from Google Analytics api
302
  */
303
  private function google_analytics_listener() {
304
 
305
  if ( ! empty( $_POST['google_auth_code'] ) ) {
306
+ Yoast_Google_Analytics::get_instance()->authenticate( trim( $_POST['google_auth_code'] ) );
307
  }
308
 
309
 
admin/class-google-analytics.php CHANGED
@@ -116,7 +116,7 @@ if ( ! class_exists( 'Yoast_Google_Analytics', false ) ) {
116
  * @return bool
117
  */
118
  public function has_refresh_token() {
119
- return ($this->client->get_refresh_token() != '');
120
  }
121
 
122
  /**
@@ -128,6 +128,31 @@ if ( ! class_exists( 'Yoast_Google_Analytics', false ) ) {
128
  return get_option( $this->option_name );
129
  }
130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  /**
132
  * Updating the options based on $this->option_name and the internal property $this->options
133
  */
@@ -152,6 +177,15 @@ if ( ! class_exists( 'Yoast_Google_Analytics', false ) ) {
152
  $this->client = new Yoast_Google_Analytics_Client( $config );
153
  }
154
 
 
 
 
 
 
 
 
 
 
155
  /**
156
  * Saving profile response in options
157
  *
@@ -163,6 +197,20 @@ if ( ! class_exists( 'Yoast_Google_Analytics', false ) ) {
163
  $this->update_options();
164
  }
165
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
166
  /**
167
  * Format the accounts request
168
  *
@@ -177,24 +225,39 @@ if ( ! class_exists( 'Yoast_Google_Analytics', false ) ) {
177
  $accounts = array();
178
 
179
  foreach ( $response['body']['items'] as $item ) {
180
-
181
- $profiles = array();
182
- foreach ( $item['webProperties'] AS $property ) {
183
- foreach ( $property['profiles'] AS $key => $profile ) {
184
- $property['profiles'][$key]['name'] = $profile['name'] . ' (' . $property['id'] . ')';
185
- $property['profiles'][$key]['ua_code'] = $property['id'];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
186
  }
187
 
188
- $profiles = array_merge( $profiles, $property['profiles'] );
189
- }
190
-
191
- $accounts[$item['id']] = array(
192
- 'id' => $item['id'],
193
- 'ua_code' => $property['id'],
194
- 'parent_name' => $item['name'],
195
- 'profiles' => $profiles,
196
- );
197
 
 
198
  }
199
 
200
  return $accounts;
116
  * @return bool
117
  */
118
  public function has_refresh_token() {
119
+ return ( $this->client->get_refresh_token() != '' );
120
  }
121
 
122
  /**
128
  return get_option( $this->option_name );
129
  }
130
 
131
+ /**
132
+ * Checks whether we'll ever be able to reach Google.
133
+ *
134
+ * @return bool
135
+ */
136
+ public function check_google_access_from_wp() {
137
+ $can_access_google = true;
138
+ if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && WP_HTTP_BLOCK_EXTERNAL ) {
139
+ $can_access_google = false;
140
+ if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) {
141
+ // Better to use the internal WP logic from this point forward.
142
+ $can_access_google = $this->test_connection_to_google();
143
+ }
144
+ }
145
+
146
+ return $can_access_google;
147
+ }
148
+
149
+ /**
150
+ * Check if we can access Google Apis from this server by making a dummy connection
151
+ */
152
+ public function check_google_access() {
153
+ return $this->test_connection_to_google();
154
+ }
155
+
156
  /**
157
  * Updating the options based on $this->option_name and the internal property $this->options
158
  */
177
  $this->client = new Yoast_Google_Analytics_Client( $config );
178
  }
179
 
180
+ /**
181
+ * Gets an authentication URL
182
+ *
183
+ * @return mixed
184
+ */
185
+ public function create_auth_url() {
186
+ return $this->client->createAuthUrl();
187
+ }
188
+
189
  /**
190
  * Saving profile response in options
191
  *
197
  $this->update_options();
198
  }
199
 
200
+ /**
201
+ * Test a connection to Google
202
+ *
203
+ * @return bool
204
+ */
205
+ private function test_connection_to_google(){
206
+ $wp_http = new WP_Http();
207
+ if ( $wp_http->block_request( 'https://www.googleapis.com/analytics/v3/management/accountSummaries' ) === false ) {
208
+ return true;
209
+ }
210
+
211
+ return false;
212
+ }
213
+
214
  /**
215
  * Format the accounts request
216
  *
225
  $accounts = array();
226
 
227
  foreach ( $response['body']['items'] as $item ) {
228
+ // Check if webProperties is set
229
+ if ( isset( $item['webProperties'] ) ) {
230
+ $profiles = array();
231
+
232
+ foreach ( $item['webProperties'] as $property_key => $property ) {
233
+ $profiles[$property_key] = array(
234
+ 'id' => $property['id'],
235
+ 'name' => $property['name'],
236
+ 'items' => array(),
237
+ );
238
+
239
+ // Check if profiles is set
240
+ if ( isset( $property['profiles'] ) ) {
241
+ foreach ( $property['profiles'] as $key => $profile ) {
242
+ $profiles[$property_key]['items'][$key] = array_merge(
243
+ $profile,
244
+ array(
245
+ 'name' => $profile['name'] . ' (' . $property['id'] . ')',
246
+ 'ua_code' => $property['id'],
247
+ )
248
+ );
249
+ }
250
+ }
251
  }
252
 
253
+ $accounts[$item['id']] = array(
254
+ 'id' => $item['id'],
255
+ 'ua_code' => $property['id'],
256
+ 'parent_name' => $item['name'],
257
+ 'items' => $profiles,
258
+ );
 
 
 
259
 
260
+ }
261
  }
262
 
263
  return $accounts;
admin/dashboards/class-admin-dashboards-collector.php CHANGED
@@ -141,7 +141,7 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
141
  * @return datetime
142
  */
143
  private function get_last_aggregate_run() {
144
- return get_transient( 'yst_ga_last_wp_run' );
145
  }
146
 
147
  /**
@@ -399,7 +399,7 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
399
  * Success, set a transient which stores the latest runtime
400
  */
401
  if ( ! empty( $response ) ) {
402
- set_transient( 'yst_ga_last_wp_run', date( 'Y-m-d' ), 48 * HOUR_IN_SECONDS );
403
  }
404
 
405
  return Yoast_GA_Dashboards_Data::set( $name, $response, strtotime( $start_date ), strtotime( $end_date ), $store_as );
141
  * @return datetime
142
  */
143
  private function get_last_aggregate_run() {
144
+ return get_option( 'yst_ga_last_wp_run' );
145
  }
146
 
147
  /**
399
  * Success, set a transient which stores the latest runtime
400
  */
401
  if ( ! empty( $response ) ) {
402
+ update_option( 'yst_ga_last_wp_run', date( 'Y-m-d' ) );
403
  }
404
 
405
  return Yoast_GA_Dashboards_Data::set( $name, $response, strtotime( $start_date ), strtotime( $end_date ), $store_as );
admin/dashboards/class-admin-dashboards-data.php CHANGED
@@ -12,13 +12,6 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Data' ) ) {
12
 
13
  class Yoast_GA_Dashboards_Data {
14
 
15
- /**
16
- * The time to store a transient (in seconds)
17
- *
18
- * @var int
19
- */
20
- private static $store_transient_time = DAY_IN_SECONDS;
21
-
22
  /**
23
  * Get a data object
24
  *
@@ -27,16 +20,16 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Data' ) ) {
27
  * @return array
28
  */
29
  public static function get( $type ) {
30
- $transient = get_transient( 'yst_ga_' . $type );
31
 
32
- if ( false === $transient ) {
33
- // Transient does not exist, abort
34
  return array();
35
  }
36
 
37
  // @TODO loop through transient to get the correct date range
38
 
39
- return $transient;
40
  }
41
 
42
  /**
@@ -59,7 +52,7 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Data' ) ) {
59
  'value' => $value,
60
  );
61
 
62
- return set_transient( 'yst_ga_' . $type, $store, self::$store_transient_time );
63
  }
64
  }
65
 
12
 
13
  class Yoast_GA_Dashboards_Data {
14
 
 
 
 
 
 
 
 
15
  /**
16
  * Get a data object
17
  *
20
  * @return array
21
  */
22
  public static function get( $type ) {
23
+ $option = get_option( 'yst_ga_' . $type );
24
 
25
+ if ( false === $option ) {
26
+ // Option does not exist, abort
27
  return array();
28
  }
29
 
30
  // @TODO loop through transient to get the correct date range
31
 
32
+ return $option;
33
  }
34
 
35
  /**
52
  'value' => $value,
53
  );
54
 
55
+ return update_option( 'yst_ga_' . $type, $store );
56
  }
57
  }
58
 
admin/pages/settings.php CHANGED
@@ -26,48 +26,63 @@ echo Yoast_GA_Admin_Form::create_form( 'settings' );
26
  <div id="general" class="gatab">
27
  <?php
28
  echo '<h2>' . __( 'General settings', 'google-analytics-for-wordpress' ) . '</h2>';
 
29
  echo '<div id="ga-promote">';
30
 
31
- $profiles = Yoast_GA_Admin_Form::parse_optgroups( $yoast_ga_admin->get_profiles() );
32
- $ga_url = $_SERVER['PHP_SELF'];
33
- if ( isset( $_GET['page'] ) ) {
34
- $ga_url .= '?page=' . $_GET['page'];
35
- }
36
- $ga_url .= '&reauth=true';
37
 
38
- echo "<div id='google_ua_code_field'>";
39
- if ( count( $profiles ) == 0 ) {
40
- echo '<div class="ga-form ga-form-input">';
41
- echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle" />' . __( 'Google profile', 'google-analytics-for-wordpress' ) . ':</label>';
42
- echo '<a id="yst_ga_authenticate" class="button" href="' . $ga_url . '" target="_blank">' . __( 'Authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
43
- echo '</div>';
44
- echo '<div class="ga-form ga-form-input">';
45
- echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle" />' . __( 'Current UA-profile', 'google-analytics-for-wordpress' ) . '</label>';
46
- echo $yoast_ga_admin->get_tracking_code();
47
- echo '</div>';
48
- } else {
49
- echo Yoast_GA_Admin_Form::select( __('Analytics profile', 'google-analytics-for-wordpress' ), 'analytics_profile', $profiles, null, false, __( 'Select a profile', 'google-analytics-for-wordpress' ) );
 
 
 
 
 
 
50
 
51
- echo '<div class="ga-form ga-form-input">';
52
- echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle" />&nbsp;</label>';
53
- echo '<a id="yst_ga_authenticate" class="button" href="' . $ga_url . '" target="_blank">' . __( 'Re-authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
 
 
54
  echo '</div>';
55
- }
56
 
57
- echo '<div id="oauth_code" class="ga-form ga-form-input">';
58
- echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle" />' . __( 'Paste your Google code here', 'google-analytics-for-wordpress' ) . ':</label>';
59
- echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, __('Please leave this field empty if everything is all right for you', 'google-analytics-for-wordpress') );
60
- echo '</label>';
61
 
62
- echo '</div>';
63
- echo '</div>';
 
 
 
 
 
 
 
 
64
 
65
  echo '<label class="ga-form ga-form-checkbox-label ga-form-label-left">';
66
  echo Yoast_GA_Admin_Form::input( 'checkbox', null, 'manual_ua_code', __( 'Manually enter your UA code', 'google-analytics-for-wordpress' ) );
67
  echo '</label>';
68
  echo '<div id="enter_ua">';
69
  echo Yoast_GA_Admin_Form::input( 'text', null, 'manual_ua_code_field' );
70
- echo '<p><strong>' . __('Warning: If you use a manual UA code, you won\'t be able to use the dashboards.', 'google-analytics-for-wordpress') . '</strong></p>';
71
  echo '</div>';
72
  echo '<div class="clear"></div></div>';
73
  ?>
@@ -82,7 +97,7 @@ echo Yoast_GA_Admin_Form::create_form( 'settings' );
82
  <div id="universal" class="gatab">
83
  <?php
84
  echo '<h2>' . __( 'Universal settings', 'google-analytics-for-wordpress' ) . '</h2>';
85
- echo Yoast_GA_Admin_Form::input( 'checkbox', __( 'Enable Universal tracking', 'google-analytics-for-wordpress' ), 'enable_universal', null, sprintf( __( 'First enable Universal tracking in your Google Analytics account. How to do that, please read %1$sthis guide%2$s to learn how to do that.', 'google-analytics-for-wordpress' ), '<a href="http://kb.yoast.com/article/125-universal-analytics#utm_medium=kb-link&utm_source=gawp-config&utm_campaign=wpgaplugin" target="_blank">', '</a>' ) );
86
  echo Yoast_GA_Admin_Form::input( 'checkbox', __( 'Enable Demographics and Interest Reports', 'google-analytics-for-wordpress' ), 'demographics', null, sprintf( __( 'You have to enable the Demographics in Google Analytics before you can see the tracking data. We have a doc in our %1$sknowlegde base%2$s about this feature.', 'google-analytics-for-wordpress' ), '<a href="http://kb.yoast.com/article/154-enable-demographics-and-interests-report-in-google-analytics/#utm_medium=kb-link&utm_source=gawp-config&utm_campaign=wpgaplugin" target="_blank">', '</a>' ) );
87
  ?>
88
  </div>
@@ -132,7 +147,7 @@ echo $yoast_ga_admin->content_footer();
132
  jQuery(document).ready(
133
  function () {
134
  jQuery('#yoast-ga-form-select-settings-analytics_profile').chosen({
135
- group_search : true
136
  });
137
  jQuery('#yoast-ga-form-select-settings-ignore_users').chosen({placeholder_text_multiple: '<?php echo __( 'Select the users to ignore', 'google-analytics-for-wordpress' ); ?>'});
138
  }
26
  <div id="general" class="gatab">
27
  <?php
28
  echo '<h2>' . __( 'General settings', 'google-analytics-for-wordpress' ) . '</h2>';
29
+
30
  echo '<div id="ga-promote">';
31
 
32
+ $ga_class = Yoast_Google_Analytics::get_instance();
33
+ $wp_block_google = $ga_class->check_google_access_from_wp();
34
+ $check_google_access = $ga_class->check_google_access();
35
+
36
+ if ( $wp_block_google && $check_google_access ) {
 
37
 
38
+ $profiles = Yoast_GA_Admin_Form::parse_optgroups( $yoast_ga_admin->get_profiles() );
39
+
40
+ $auth_url = Yoast_Google_Analytics::get_instance()->create_auth_url();
41
+ add_thickbox();
42
+ echo '<script>yst_thickbox_heading = "' . __( 'Paste your Google authentication code', 'google-analytics-for-wordpress' ) . '";</script>';
43
+
44
+ echo "<div id='google_ua_code_field'>";
45
+ if ( count( $profiles ) == 0 ) {
46
+ echo '<div class="ga-form ga-form-input">';
47
+ echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle" />' . __( 'Google profile', 'google-analytics-for-wordpress' ) . ':</label>';
48
+ echo '<a id="yst_ga_authenticate" class="button" onclick="yst_popupwindow(\'' . $auth_url . '\',500,500);">' . __( 'Authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
49
+ echo '</div>';
50
+ echo '<div class="ga-form ga-form-input">';
51
+ echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle" />' . __( 'Current UA-profile', 'google-analytics-for-wordpress' ) . '</label>';
52
+ echo $yoast_ga_admin->get_tracking_code();
53
+ echo '</div>';
54
+ } else {
55
+ echo Yoast_GA_Admin_Form::select( __('Analytics profile', 'google-analytics-for-wordpress' ), 'analytics_profile', $profiles, null, false, __( 'Select a profile', 'google-analytics-for-wordpress' ) );
56
 
57
+ echo '<div class="ga-form ga-form-input">';
58
+ echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle" />&nbsp;</label>';
59
+ echo '<a id="yst_ga_authenticate" class="button" onclick="yst_popupwindow(\'' . $auth_url . '\',500,500);">' . __( 'Re-authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
60
+ echo '</div>';
61
+ }
62
  echo '</div>';
 
63
 
64
+ echo '<div id="oauth_code" class="ga-form ga-form-input">';
65
+ echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle" />' . __( 'Paste your Google code and press return', 'google-analytics-for-wordpress' ) . ':</label>';
66
+ echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, null );
67
+ echo '</label>';
68
 
69
+ echo '</div>';
70
+ } else {
71
+ echo '<h3>' . __( 'Cannot connect to Google', 'google-analytics-for-wordpress' ) . '</h3>';
72
+ if ( $wp_block_google == false && $check_google_access == false ) {
73
+ echo '<p>' . __( 'Your server is blocking requests to Google, to fix this, add <code>*.googleapis.com</code> to the <code>WP_ACCESSIBLE_HOSTS</code> constant in your <em>wp-config.php</em> or ask your webhost to do this.', 'google-analytics-for-wordpress' ) . '</p>';
74
+ } else {
75
+ echo '<p>' . __( 'Your firewall or webhost is blocking requests to Google, please ask your webhost company to fix this.', 'google-analytics-for-wordpress' ) . '</p>';
76
+ }
77
+ echo '<p>' . __( 'Until this is fixed, you can only use the manual authentication method and cannot use the dashboards feature.', 'google-analytics-for-wordpress' ) . '</p>';
78
+ }
79
 
80
  echo '<label class="ga-form ga-form-checkbox-label ga-form-label-left">';
81
  echo Yoast_GA_Admin_Form::input( 'checkbox', null, 'manual_ua_code', __( 'Manually enter your UA code', 'google-analytics-for-wordpress' ) );
82
  echo '</label>';
83
  echo '<div id="enter_ua">';
84
  echo Yoast_GA_Admin_Form::input( 'text', null, 'manual_ua_code_field' );
85
+ echo '<p><strong>' . __( 'Warning: If you use a manual UA code, you won\'t be able to use the dashboards.', 'google-analytics-for-wordpress' ) . '</strong></p>';
86
  echo '</div>';
87
  echo '<div class="clear"></div></div>';
88
  ?>
97
  <div id="universal" class="gatab">
98
  <?php
99
  echo '<h2>' . __( 'Universal settings', 'google-analytics-for-wordpress' ) . '</h2>';
100
+ echo Yoast_GA_Admin_Form::input( 'checkbox', __( 'Enable Universal tracking', 'google-analytics-for-wordpress' ), 'enable_universal', null, sprintf( __( 'First enable Universal tracking in your Google Analytics account. How to do that, please read %1$sthis guide%2$s to learn how to do that.', 'google-analytics-for-wordpress' ), '<a href="http://kb.yoast.com/article/125-universal-analytics#utm_medium=kb-link&utm_source=gawp-config&utm_campaign=wpgaplugin" target="_blank">', '</a>' ) );
101
  echo Yoast_GA_Admin_Form::input( 'checkbox', __( 'Enable Demographics and Interest Reports', 'google-analytics-for-wordpress' ), 'demographics', null, sprintf( __( 'You have to enable the Demographics in Google Analytics before you can see the tracking data. We have a doc in our %1$sknowlegde base%2$s about this feature.', 'google-analytics-for-wordpress' ), '<a href="http://kb.yoast.com/article/154-enable-demographics-and-interests-report-in-google-analytics/#utm_medium=kb-link&utm_source=gawp-config&utm_campaign=wpgaplugin" target="_blank">', '</a>' ) );
102
  ?>
103
  </div>
147
  jQuery(document).ready(
148
  function () {
149
  jQuery('#yoast-ga-form-select-settings-analytics_profile').chosen({
150
+ group_search: true
151
  });
152
  jQuery('#yoast-ga-form-select-settings-ignore_users').chosen({placeholder_text_multiple: '<?php echo __( 'Select the users to ignore', 'google-analytics-for-wordpress' ); ?>'});
153
  }
assets/css/yoast_ga_styles.css CHANGED
@@ -118,6 +118,10 @@ p.ga-topdescription {
118
  width: 325px;
119
  }
120
 
 
 
 
 
121
  #yoast-ga-form-settings #oauth_code div {
122
  margin: 0 0 0 5px;
123
  }
118
  width: 325px;
119
  }
120
 
121
+ #yoast-ga-form-settings #oauth_code {
122
+ padding: 20px;
123
+ }
124
+
125
  #yoast-ga-form-settings #oauth_code div {
126
  margin: 0 0 0 5px;
127
  }
assets/css/yoast_ga_styles.min.css CHANGED
@@ -1 +1 @@
1
- h2#yoast_ga_title{padding:9px 15px 4px 0;font-size:23px;font-weight:400;line-height:29px}.nav-tab-wrapper{margin-bottom:20px}.gatab{display:none}.gatab.active{display:block;padding:.5em .9em;border:1px solid #ddd;border-radius:0 3px 3px;background-color:#fff}.tabwrapper .gatab{padding:0;border:none;background:0 0}.tabwrapper .gatab h2{padding:9px 15px 4px 0;font-size:23px;font-weight:400}.ga-form-submit{margin-top:20px}.ga-form-label-left{float:left;width:250px;margin:0 0 0 5px;font-size:14px;font-weight:700;cursor:default}.ga-form-input{margin-top:10px}#yoast-ga-wrapper{display:table;width:auto;max-width:1150px}.yoast-ga-content{display:table-cell;min-width:850px;height:500px;margin:0;padding:0;vertical-align:top}.yoast-ga-banners{display:table-cell;width:261px;height:500px;margin:0;padding:20px;vertical-align:top}.ga-form-input{display:table;margin-bottom:20px}.ga-form-table{display:table-cell}.ga-form-description{display:block;float:right;max-width:325px;color:#999}p.ga-topdescription{max-width:600px}#ga-promote,.ga-promote{max-width:600px;padding-left:10px;border:1px solid #ccc;background-color:#fff}.ga-promote{margin-bottom:10px}#ga-promote p,.ga-promote p{margin:0;padding:1em 1em 1em 0}#yoast-ga-form-settings input[type=text]{width:325px}#yoast-ga-form-settings #oauth_code div{margin:0 0 0 5px}#yoast-ga-form-settings #oauth_code input[type=text]{width:275px}.ga-form .chosen-search input[type=text]{width:100%!important}.yoast-ga-content .chosen-container{width:325px!important}#enter_ua{display:none;margin-top:10px;padding-top:10px}#yoast-ga-form-text-settings-ga_general-manual_ua_code_field{margin-top:-30px}select.ga-multiple{width:300px;height:150px!important}.wpseotab .extension{float:left;box-sizing:border-box;width:350px;height:230px;margin:10px 20px 10px 0;border:1px solid #ccc}.wpseotab .extension p{margin:0;padding:10px}.wpseotab .extension h3{box-sizing:border-box;height:110px;margin:0;padding:20px 10px 0 120px;border-bottom:1px solid #ccc;background:left 10px/130px 100px no-repeat #fff}.wpseotab .extension button.installed{border-color:#00a000;background-color:#00a000;cursor:default}.wpseotab .extension .button-primary.activate-link{border-color:#f06000;background-color:#f18500}.extension a{text-decoration:none}.ecommerce h3{background-image:url(../img/eComm_130x100.png)!important}.ga_premium h3{background-image:url(../img/ga-premium-banner.png)!important}#ga-debug-info h3{height:30px;margin-top:10px;padding-left:16px;font-size:14px}.yoast_help{margin:2px 5px 0}#enter_ua div{display:inline-block;margin:0}
1
+ h2#yoast_ga_title{padding:9px 15px 4px 0;font-size:23px;font-weight:400;line-height:29px}.nav-tab-wrapper{margin-bottom:20px}.gatab{display:none}.gatab.active{display:block;padding:.5em .9em;border:1px solid #ddd;border-radius:0 3px 3px;background-color:#fff}.tabwrapper .gatab{padding:0;border:none;background:0 0}.tabwrapper .gatab h2{padding:9px 15px 4px 0;font-size:23px;font-weight:400}.ga-form-submit{margin-top:20px}.ga-form-label-left{float:left;width:250px;margin:0 0 0 5px;font-size:14px;font-weight:700;cursor:default}.ga-form-input{margin-top:10px}#yoast-ga-wrapper{display:table;width:auto;max-width:1150px}.yoast-ga-content{display:table-cell;min-width:850px;height:500px;margin:0;padding:0;vertical-align:top}.yoast-ga-banners{display:table-cell;width:261px;height:500px;margin:0;padding:20px;vertical-align:top}.ga-form-input{display:table;margin-bottom:20px}.ga-form-table{display:table-cell}.ga-form-description{display:block;float:right;max-width:325px;color:#999}p.ga-topdescription{max-width:600px}#ga-promote,.ga-promote{max-width:600px;padding-left:10px;border:1px solid #ccc;background-color:#fff}.ga-promote{margin-bottom:10px}#ga-promote p,.ga-promote p{margin:0;padding:1em 1em 1em 0}#yoast-ga-form-settings input[type=text]{width:325px}#yoast-ga-form-settings #oauth_code{padding:20px}#yoast-ga-form-settings #oauth_code div{margin:0 0 0 5px}#yoast-ga-form-settings #oauth_code input[type=text]{width:275px}.ga-form .chosen-search input[type=text]{width:100%!important}.yoast-ga-content .chosen-container{width:325px!important}#enter_ua{display:none;margin-top:10px;padding-top:10px}#yoast-ga-form-text-settings-ga_general-manual_ua_code_field{margin-top:-30px}select.ga-multiple{width:300px;height:150px!important}.wpseotab .extension{float:left;box-sizing:border-box;width:350px;height:230px;margin:10px 20px 10px 0;border:1px solid #ccc}.wpseotab .extension p{margin:0;padding:10px}.wpseotab .extension h3{box-sizing:border-box;height:110px;margin:0;padding:20px 10px 0 120px;border-bottom:1px solid #ccc;background:left 10px/130px 100px no-repeat #fff}.wpseotab .extension button.installed{border-color:#00a000;background-color:#00a000;cursor:default}.wpseotab .extension .button-primary.activate-link{border-color:#f06000;background-color:#f18500}.extension a{text-decoration:none}.ecommerce h3{background-image:url(../img/eComm_130x100.png)!important}.ga_premium h3{background-image:url(../img/ga-premium-banner.png)!important}#ga-debug-info h3{height:30px;margin-top:10px;padding-left:16px;font-size:14px}.yoast_help{margin:2px 5px 0}#enter_ua div{display:inline-block;margin:0}
assets/dependencies/focusable/focus-element-overlay.min.js ADDED
@@ -0,0 +1 @@
 
1
+ !function(e){function n(){o(),jQuery("body").prepend('<div id="overlay-layer"></div>'),p=jQuery("#overlay-layer"),h(),t()}function o(){jQuery.fn.focusable=function(e){return Focusable.setFocus(this,e),this}}function t(){p.on("click",".column",u),jQuery(window).on("resize",i),jQuery(window).on("keyup",d)}function i(){v&&(v=b.findOnResize?jQuery(v.selector):v,c())}function d(e){b.hideOnESC&&27===e.keyCode&&y&&a()}function u(){b.hideOnClick&&a()}function l(e,n){jQuery("body").css("overflow","hidden"),b=jQuery.extend(b,n),v=e,c(),p.fadeIn(b.fadeDuration)}function r(){p.find(".column").remove()}function a(){y=!1,v=null,jQuery("body").css("overflow",""),p.fadeOut(b.fadeDuration,r)}function c(){if(v){var e=0;for(y=!0,r();4>e;)f(e),e++}}function f(e){var n=v.offset(),o=0,t=0,i=s(v.outerWidth()),d="100%",u="";switch(e){case 0:i=s(n.left);break;case 1:t=s(n.left),d=s(n.top);break;case 2:t=s(n.left),o=s(v.outerHeight()+n.top);break;case 3:i="100%",t=s(v.outerWidth()+n.left)}u="top:"+o+";left:"+t+";width:"+i+";height:"+d,p.append('<div class="column" style="'+u+'"></div>')}function s(e){return e+"px"}function h(){var e=function(){var e=document.createElement("style");return e.appendChild(document.createTextNode("")),document.head.appendChild(e),e.sheet}();e.insertRule("#overlay-layer{ display:none; position: absolute; top: 0; left: 0; width: 100%; height: 100%; z-index: 9999; overflow: hidden; pointer-events: none; }",0),e.insertRule("#overlay-layer .column{ position: absolute; background: rgba(0,0,0,0.8); pointer-events: all; }",1)}var p=null,v=null,y=!1,b={fadeDuration:700,hideOnClick:!1,hideOnESC:!1,findOnResize:!1};jQuery(document).ready(n),e.Focusable={setFocus:l,hide:a,refresh:c}}(window);
assets/js/yoast_ga_admin.js CHANGED
@@ -1,3 +1,9 @@
 
 
 
 
 
 
1
  jQuery(document).ready(function() {
2
  jQuery('#ga-tabs').find('a').click(function() {
3
  jQuery('#ga-tabs').find('a').removeClass('nav-tab-active');
@@ -27,7 +33,7 @@ jQuery(document).ready(function() {
27
  jQuery('#' + activeTab).addClass('active');
28
  jQuery('#' + activeTab + '-tab').addClass('nav-tab-active');
29
 
30
- function yst_ga_switch_manual() {
31
  if ( jQuery('#yoast-ga-form-checkbox-settings-manual_ua_code').is(':checked') ) {
32
  jQuery('#enter_ua').show();
33
  jQuery("#yoast-ga-form-select-settings-analytics_profile").prop('disabled', true).trigger("chosen:updated");
@@ -48,7 +54,9 @@ jQuery(document).ready(function() {
48
 
49
  jQuery('#oauth_code').hide();
50
  jQuery("#yst_ga_authenticate").click( function() {
51
- jQuery('#oauth_code').show().focus();
 
 
52
  });
53
 
54
  jQuery('.nav-tab-active').click();
1
+ function yst_popupwindow(url, w, h) {
2
+ var left = (screen.width/2)-(w/2);
3
+ var top = (screen.height/8);
4
+ return window.open(url, '', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
5
+ }
6
+
7
  jQuery(document).ready(function() {
8
  jQuery('#ga-tabs').find('a').click(function() {
9
  jQuery('#ga-tabs').find('a').removeClass('nav-tab-active');
33
  jQuery('#' + activeTab).addClass('active');
34
  jQuery('#' + activeTab + '-tab').addClass('nav-tab-active');
35
 
36
+ function yst_ga_switch_manual() {
37
  if ( jQuery('#yoast-ga-form-checkbox-settings-manual_ua_code').is(':checked') ) {
38
  jQuery('#enter_ua').show();
39
  jQuery("#yoast-ga-form-select-settings-analytics_profile").prop('disabled', true).trigger("chosen:updated");
54
 
55
  jQuery('#oauth_code').hide();
56
  jQuery("#yst_ga_authenticate").click( function() {
57
+ jQuery('#oauth_code').show();
58
+ Focusable.setFocus(jQuery('#oauth_code'), {hideOnESC:true});
59
+ jQuery('#oauth_code input').focus();
60
  });
61
 
62
  jQuery('.nav-tab-active').click();
assets/js/yoast_ga_admin.min.js CHANGED
@@ -1 +1 @@
1
- jQuery(document).ready(function(){function a(){jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").is(":checked")?(jQuery("#enter_ua").show(),jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",!0).trigger("chosen:updated"),jQuery("#yst_ga_authenticate").attr("disabled",!0),jQuery("#oauth_code").hide()):(jQuery("#enter_ua").hide(),jQuery("#yoast-ga-form-text-settings-manual_ua_code_field").attr("value",""),jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",!1).trigger("chosen:updated"),jQuery("#yst_ga_authenticate").attr("disabled",!1),jQuery("#oauth_code").show())}jQuery("#ga-tabs").find("a").click(function(){jQuery("#ga-tabs").find("a").removeClass("nav-tab-active"),jQuery(".gatab").removeClass("active");var a=jQuery(this).attr("id").replace("-tab","");jQuery("#"+a).addClass("active"),jQuery(this).addClass("nav-tab-active"),jQuery("#return_tab").val(a)}),jQuery("a.activate-link").click(function(){jQuery("#extensions.wpseotab").removeClass("active"),jQuery("#extensions-tab").removeClass("nav-tab-active"),jQuery("#licenses.wpseotab").addClass("active"),jQuery("#licenses-tab").addClass("nav-tab-active")});var b=window.location.hash.replace("#top#","");(""===b||"#_=_"===b)&&(b=jQuery(".gatab").attr("id")),jQuery("#"+b).addClass("active"),jQuery("#"+b+"-tab").addClass("nav-tab-active"),jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").click(function(){a()}),a(),jQuery("#oauth_code").hide(),jQuery("#yst_ga_authenticate").click(function(){jQuery("#oauth_code").show().focus()}),jQuery(".nav-tab-active").click(),jQuery(".yoast_help").qtip({position:{corner:{target:"topMiddle",tooltip:"bottomLeft"}},show:{when:{event:"mouseover"}},hide:{fixed:!0,when:{event:"mouseout"}},style:{tip:"bottomLeft",name:"blue"}})});
1
+ function yst_popupwindow(a,b,c){var d=screen.width/2-b/2,e=screen.height/8;return window.open(a,"","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+b+", height="+c+", top="+e+", left="+d)}jQuery(document).ready(function(){function a(){jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").is(":checked")?(jQuery("#enter_ua").show(),jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",!0).trigger("chosen:updated"),jQuery("#yst_ga_authenticate").attr("disabled",!0),jQuery("#oauth_code").hide()):(jQuery("#enter_ua").hide(),jQuery("#yoast-ga-form-text-settings-manual_ua_code_field").attr("value",""),jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",!1).trigger("chosen:updated"),jQuery("#yst_ga_authenticate").attr("disabled",!1),jQuery("#oauth_code").show())}jQuery("#ga-tabs").find("a").click(function(){jQuery("#ga-tabs").find("a").removeClass("nav-tab-active"),jQuery(".gatab").removeClass("active");var a=jQuery(this).attr("id").replace("-tab","");jQuery("#"+a).addClass("active"),jQuery(this).addClass("nav-tab-active"),jQuery("#return_tab").val(a)}),jQuery("a.activate-link").click(function(){jQuery("#extensions.wpseotab").removeClass("active"),jQuery("#extensions-tab").removeClass("nav-tab-active"),jQuery("#licenses.wpseotab").addClass("active"),jQuery("#licenses-tab").addClass("nav-tab-active")});var b=window.location.hash.replace("#top#","");(""===b||"#_=_"===b)&&(b=jQuery(".gatab").attr("id")),jQuery("#"+b).addClass("active"),jQuery("#"+b+"-tab").addClass("nav-tab-active"),jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").click(function(){a()}),a(),jQuery("#oauth_code").hide(),jQuery("#yst_ga_authenticate").click(function(){jQuery("#oauth_code").show(),Focusable.setFocus(jQuery("#oauth_code"),{hideOnESC:!0}),jQuery("#oauth_code input").focus()}),jQuery(".nav-tab-active").click(),jQuery(".yoast_help").qtip({position:{corner:{target:"topMiddle",tooltip:"bottomLeft"}},show:{when:{event:"mouseover"}},hide:{fixed:!0,when:{event:"mouseout"}},style:{tip:"bottomLeft",name:"blue"}})});
googleanalytics.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Google Analytics by Yoast
4
  Plugin URI: https://yoast.com/wordpress/plugins/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v504
5
  Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. error page, search result and automatic clickout and download tracking.
6
  Author: Team Yoast
7
- Version: 5.2.6
8
  Requires at least: 3.8
9
  Author URI: https://yoast.com/
10
  License: GPL v3
@@ -30,7 +30,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
30
 
31
  // This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics, but has since been rewritten and refactored multiple times.
32
 
33
- define( 'GAWP_VERSION', '5.2.6' );
34
 
35
  define( 'GAWP_FILE', __FILE__ );
36
 
4
  Plugin URI: https://yoast.com/wordpress/plugins/google-analytics/#utm_source=wordpress&utm_medium=plugin&utm_campaign=wpgaplugin&utm_content=v504
5
  Description: This plugin makes it simple to add Google Analytics to your WordPress blog, adding lots of features, eg. error page, search result and automatic clickout and download tracking.
6
  Author: Team Yoast
7
+ Version: 5.2.7
8
  Requires at least: 3.8
9
  Author URI: https://yoast.com/
10
  License: GPL v3
30
 
31
  // This plugin was originally based on Rich Boakes' Analytics plugin: http://boakes.org/analytics, but has since been rewritten and refactored multiple times.
32
 
33
+ define( 'GAWP_VERSION', '5.2.7' );
34
 
35
  define( 'GAWP_FILE', __FILE__ );
36
 
includes/class-utils.php CHANGED
@@ -14,9 +14,10 @@ if ( ! class_exists( 'Yoast_GA_Utils' ) ) {
14
 
15
  //Makes sure is_plugin_active is available when called from front end
16
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
17
- if (is_plugin_active( 'wordpress-seo/wp-seo.php' ) || is_plugin_active( 'wordpress-seo-premium/wp-seo-premium.php' ) ) {
18
  $wp_seo_active = true;
19
  }
 
20
  return $wp_seo_active;
21
  }
22
 
@@ -34,5 +35,6 @@ if ( ! class_exists( 'Yoast_GA_Utils' ) ) {
34
 
35
  return floor( $hours );
36
  }
 
37
  }
38
  }
14
 
15
  //Makes sure is_plugin_active is available when called from front end
16
  include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
17
+ if ( is_plugin_active( 'wordpress-seo/wp-seo.php' ) || is_plugin_active( 'wordpress-seo-premium/wp-seo-premium.php' ) ) {
18
  $wp_seo_active = true;
19
  }
20
+
21
  return $wp_seo_active;
22
  }
23
 
35
 
36
  return floor( $hours );
37
  }
38
+
39
  }
40
  }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://yoast.com/donate/
4
  Tags: analytics, google analytics, statistics, tracking, stats, google, yoast
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
- Stable tag: 5.2.6
8
 
9
  Track your WordPress site easily with the latest tracking codes and lots added data for search result pages and error pages.
10
 
@@ -49,6 +49,18 @@ This section describes how to install the plugin and get it working.
49
 
50
  == Changelog ==
51
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  = 5.2.6 =
53
 
54
  Release Date: December 16th, 2014
4
  Tags: analytics, google analytics, statistics, tracking, stats, google, yoast
5
  Requires at least: 3.8
6
  Tested up to: 4.1
7
+ Stable tag: 5.2.7
8
 
9
  Track your WordPress site easily with the latest tracking codes and lots added data for search result pages and error pages.
10
 
49
 
50
  == Changelog ==
51
 
52
+ = 5.2.7 =
53
+
54
+ Release Date: December 18th, 2014
55
+
56
+ * Bugfixes:
57
+ * Increase timeout limit for request to Google API to prevent quickly session time-outs.
58
+ * Setting SSL verifier to FALSE, to prevent checking SSL-chain.
59
+ * Checking for cURL version 7.19, it this version is used the plugin switches to http streams.
60
+
61
+ * Enhancements:
62
+ * Using webproperties instead of account names in the select box for choosing the Google Analytics profile.
63
+
64
  = 5.2.6 =
65
 
66
  Release Date: December 16th, 2014