Version Description
Release Date: December 11th, 2014
Enhancements: * improved visual look and data representation for dashboard graphs, props Andrey Savchenko * when manual UA-code is selected, the profile selection gets disabled to clarify that the user is choosing an alternative to regular profile selection.
Bugfixes: * Fixes a bug where GA profile was fetched with every admin request, resulting in a pile of unnecessary API requests. * Fixes a problem where GA started throttling API requests done by our plugin because there were too many. We now fetch the data only once a day from GA. For realtime data, users should go to Google Analytics.
Download this release
Release Info
Developer | omarreiss |
Plugin | Google Analytics for WordPress by MonsterInsights |
Version | 5.2.3 |
Comparing to | |
See all releases |
Code changes from version 5.2.2 to 5.2.3
- admin/class-admin.php +9 -2
- admin/class-google-analytics.php +53 -6
- admin/dashboards/class-admin-dashboards-collector.php +65 -46
- admin/dashboards/drivers/class-admin-dashboards-graph-generate.php +5 -1
- admin/pages/settings.php +3 -3
- assets/css/yoast_ga_admin_dashboard.css +2 -2
- assets/css/yoast_ga_admin_dashboard.min.css +1 -1
- assets/css/yoast_ga_styles.css +5 -0
- assets/js/yoast_ga_admin.js +15 -12
- assets/js/yoast_ga_admin.min.js +1 -1
- assets/js/yoast_ga_admin_dashboard.js +10 -7
- assets/js/yoast_ga_admin_dashboard.min.js +1 -1
- googleanalytics.php +2 -2
- readme.txt +13 -1
admin/class-admin.php
CHANGED
@@ -338,10 +338,11 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
338 |
* @param array $values
|
339 |
* @param null|string $description
|
340 |
* @param bool $multiple
|
|
|
341 |
*
|
342 |
* @return null|string
|
343 |
*/
|
344 |
-
public function select( $title, $name, $values, $description = null, $multiple = false ) {
|
345 |
$select = null;
|
346 |
$id = str_replace( '[', '-', $name );
|
347 |
$id = str_replace( ']', '', $id );
|
@@ -359,7 +360,10 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
359 |
if ( $multiple ) {
|
360 |
$select .= '<select multiple name="' . $name . '[]" id="yoast-ga-form-select-' . $this->form_namespace . '-' . $id . '" class="ga-multiple">';
|
361 |
} else {
|
362 |
-
$select .= '<select name="' . $name . '" id="yoast-ga-form-select-' . $this->form_namespace . '-' . $id . '">';
|
|
|
|
|
|
|
363 |
}
|
364 |
if ( count( $values ) >= 1 ) {
|
365 |
|
@@ -496,6 +500,9 @@ if ( ! class_exists( 'Yoast_GA_Admin' ) ) {
|
|
496 |
if ( ! empty ( $_GET['reauth'] ) ) {
|
497 |
$authorize_url = Yoast_Google_Analytics::instance()->authenticate();
|
498 |
|
|
|
|
|
|
|
499 |
wp_redirect( $authorize_url );
|
500 |
exit;
|
501 |
}
|
338 |
* @param array $values
|
339 |
* @param null|string $description
|
340 |
* @param bool $multiple
|
341 |
+
* @param string $empty_text
|
342 |
*
|
343 |
* @return null|string
|
344 |
*/
|
345 |
+
public function select( $title, $name, $values, $description = null, $multiple = false, $empty_text = null ) {
|
346 |
$select = null;
|
347 |
$id = str_replace( '[', '-', $name );
|
348 |
$id = str_replace( ']', '', $id );
|
360 |
if ( $multiple ) {
|
361 |
$select .= '<select multiple name="' . $name . '[]" id="yoast-ga-form-select-' . $this->form_namespace . '-' . $id . '" class="ga-multiple">';
|
362 |
} else {
|
363 |
+
$select .= '<select data-placeholder="' . $empty_text . '" name="' . $name . '" id="yoast-ga-form-select-' . $this->form_namespace . '-' . $id . '">';
|
364 |
+
if ( !is_null( $empty_text ) ) {
|
365 |
+
$select .= '<option></option>';
|
366 |
+
}
|
367 |
}
|
368 |
if ( count( $values ) >= 1 ) {
|
369 |
|
500 |
if ( ! empty ( $_GET['reauth'] ) ) {
|
501 |
$authorize_url = Yoast_Google_Analytics::instance()->authenticate();
|
502 |
|
503 |
+
delete_option( 'yst_ga_accounts' );
|
504 |
+
delete_option( 'yst_ga_response' );
|
505 |
+
|
506 |
wp_redirect( $authorize_url );
|
507 |
exit;
|
508 |
}
|
admin/class-google-analytics.php
CHANGED
@@ -85,20 +85,67 @@ if ( ! class_exists( 'Yoast_Google_Analytics', false ) ) {
|
|
85 |
* @return array
|
86 |
*/
|
87 |
public function get_profiles() {
|
88 |
-
$return
|
89 |
-
$
|
90 |
|
91 |
-
$
|
|
|
|
|
|
|
|
|
|
|
92 |
|
93 |
-
if ( $response ) {
|
94 |
-
$this->save_profile_response( $response, $accounts );
|
95 |
|
96 |
-
$return = $this->parse_profile_response( $response );
|
97 |
}
|
98 |
|
99 |
return $return;
|
100 |
}
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
/**
|
103 |
* Format the accounts request
|
104 |
*
|
85 |
* @return array
|
86 |
*/
|
87 |
public function get_profiles() {
|
88 |
+
$return = array();
|
89 |
+
$result = array();
|
90 |
|
91 |
+
$result['accounts'] = $this->get_option_api( 'yst_ga_accounts' );
|
92 |
+
$result['response'] = $this->get_option_api( 'yst_ga_response' );
|
93 |
+
|
94 |
+
if ( $result['accounts'] === false || $result['response'] === false ) {
|
95 |
+
$result = $this->fetch_api_profiles();
|
96 |
+
}
|
97 |
|
98 |
+
if ( $result['response'] ) {
|
99 |
+
$this->save_profile_response( $result['response'], $result['accounts'] );
|
100 |
|
101 |
+
$return = $this->parse_profile_response( $result['response'] );
|
102 |
}
|
103 |
|
104 |
return $return;
|
105 |
}
|
106 |
|
107 |
+
/**
|
108 |
+
* Get the transient of an API call
|
109 |
+
*
|
110 |
+
* @param $name
|
111 |
+
*
|
112 |
+
* @return string
|
113 |
+
*/
|
114 |
+
private function get_option_api( $name ) {
|
115 |
+
return get_option( $name );
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Save the option API
|
120 |
+
*
|
121 |
+
* @param $name
|
122 |
+
* @param $value
|
123 |
+
*
|
124 |
+
* @return string
|
125 |
+
*/
|
126 |
+
private function save_option_api( $name, $value ) {
|
127 |
+
return update_option( $name, $value );
|
128 |
+
}
|
129 |
+
|
130 |
+
/**
|
131 |
+
* Fetch the API profiles and store them
|
132 |
+
*
|
133 |
+
* @return array
|
134 |
+
*/
|
135 |
+
private function fetch_api_profiles() {
|
136 |
+
$accounts = $this->format_accounts_call( $this->do_request( 'https://www.googleapis.com/analytics/v3/management/accounts/~all/webproperties', 'https://www.googleapis.com/auth/analytics.readonly' ) );
|
137 |
+
$response = $this->do_request( 'https://www.googleapis.com/analytics/v2.4/management/accounts/~all/webproperties/~all/profiles', 'https://www.googleapis.com/auth/analytics.readonly' );
|
138 |
+
|
139 |
+
// Save the accounts and response results in the new transient
|
140 |
+
$this->save_option_api( 'yst_ga_accounts', $accounts );
|
141 |
+
$this->save_option_api( 'yst_ga_response', $response );
|
142 |
+
|
143 |
+
return array(
|
144 |
+
'accounts' => $accounts,
|
145 |
+
'response' => $response,
|
146 |
+
);
|
147 |
+
}
|
148 |
+
|
149 |
/**
|
150 |
* Format the accounts request
|
151 |
*
|
admin/dashboards/class-admin-dashboards-collector.php
CHANGED
@@ -39,18 +39,6 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
|
|
39 |
*/
|
40 |
public $ga_profile_id;
|
41 |
|
42 |
-
/**
|
43 |
-
* The $_GET pages where the shutdown hook should be executed to aggregate data
|
44 |
-
*
|
45 |
-
* @var array
|
46 |
-
*/
|
47 |
-
private $shutdown_get_pages = array( 'yst_ga_dashboard' );
|
48 |
-
|
49 |
-
/**
|
50 |
-
* The $_SERVER['SCRIPT_NAME'] pages where the shutdown hook should be executed to aggregate data
|
51 |
-
*/
|
52 |
-
private $shutdown_pages = array( '/wp-admin/index.php' );
|
53 |
-
|
54 |
/**
|
55 |
* Construct on the dashboards class for GA
|
56 |
*
|
@@ -93,6 +81,7 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
|
|
93 |
if ( is_array( $this->dimensions ) && count( $this->dimensions ) >= 1 ) {
|
94 |
$this->aggregate_dimensions( $access_tokens, $this->dimensions );
|
95 |
}
|
|
|
96 |
} else {
|
97 |
// Failure on authenticating, please reauthenticate
|
98 |
}
|
@@ -104,15 +93,64 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
|
|
104 |
private function init_shutdown_hook() {
|
105 |
$this->api = Yoast_Api_Libs::load_api_libraries( array( 'oauth', 'googleanalytics' ) );
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
}
|
113 |
}
|
114 |
}
|
115 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
/**
|
117 |
* Remove metrics and set them as a dimension if needed
|
118 |
*
|
@@ -188,7 +226,7 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
|
|
188 |
*/
|
189 |
private function aggregate_metrics( $access_tokens, $metrics ) {
|
190 |
foreach ( $metrics as $metric ) {
|
191 |
-
$this->execute_call( $access_tokens, $metric, date( 'Y-m-d', strtotime( '-6 weeks' ) ), date( 'Y-m-d' ) );
|
192 |
}
|
193 |
}
|
194 |
|
@@ -202,44 +240,18 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
|
|
202 |
foreach ( $dimensions as $dimension ) {
|
203 |
if ( ( isset( $dimension['id'] ) || isset( $dimension['dimension'] ) ) && isset( $dimension['metric'] ) ) {
|
204 |
if ( isset( $dimension['id'] ) ) {
|
205 |
-
$this->execute_call( $access_tokens, $dimension['metric'], date( 'Y-m-d', strtotime( '-1 month' ) ), date( 'Y-m-d' ), 'ga:dimension' . $dimension['id'] );
|
206 |
} elseif ( isset( $dimension['dimension'] ) ) {
|
207 |
if ( isset( $dimension['storage_name'] ) ) {
|
208 |
-
$this->execute_call( $access_tokens, $dimension['metric'], date( 'Y-m-d', strtotime( '-1 month' ) ), date( 'Y-m-d' ), 'ga:' . $dimension['dimension'], $dimension['storage_name'] );
|
209 |
} else {
|
210 |
-
$this->execute_call( $access_tokens, $dimension['metric'], date( 'Y-m-d', strtotime( '-1 month' ) ), date( 'Y-m-d' ), 'ga:' . $dimension['dimension'] );
|
211 |
}
|
212 |
}
|
213 |
}
|
214 |
}
|
215 |
}
|
216 |
|
217 |
-
/**
|
218 |
-
* Check if the shutdown hook should be ran on the GET var
|
219 |
-
*
|
220 |
-
* @return bool
|
221 |
-
*/
|
222 |
-
private function run_shutdown_hook_get() {
|
223 |
-
if ( isset( $_GET['page'] ) && in_array( $_GET['page'], $this->shutdown_get_pages ) ) {
|
224 |
-
return true;
|
225 |
-
}
|
226 |
-
|
227 |
-
return false;
|
228 |
-
}
|
229 |
-
|
230 |
-
/**
|
231 |
-
* Check if the shutdown hook should be ran on this page
|
232 |
-
*
|
233 |
-
* @return bool
|
234 |
-
*/
|
235 |
-
private function run_shutdown_hook_page() {
|
236 |
-
if ( isset( $_SERVER['SCRIPT_NAME'] ) && in_array( $_SERVER['SCRIPT_NAME'], $this->shutdown_pages ) ) {
|
237 |
-
return true;
|
238 |
-
}
|
239 |
-
|
240 |
-
return false;
|
241 |
-
}
|
242 |
-
|
243 |
/**
|
244 |
* Execute an API call to Google Analytics and store the data in the dashboards data class
|
245 |
*
|
@@ -394,6 +406,13 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Collector' ) ) {
|
|
394 |
if ( $storage_name != 'auto' ) {
|
395 |
$name = $storage_name;
|
396 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
397 |
|
398 |
return Yoast_GA_Dashboards_Data::set( $name, $response['body'], strtotime( $start_date ), strtotime( $end_date ), $store_as );
|
399 |
} else {
|
39 |
*/
|
40 |
public $ga_profile_id;
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
/**
|
43 |
* Construct on the dashboards class for GA
|
44 |
*
|
81 |
if ( is_array( $this->dimensions ) && count( $this->dimensions ) >= 1 ) {
|
82 |
$this->aggregate_dimensions( $access_tokens, $this->dimensions );
|
83 |
}
|
84 |
+
|
85 |
} else {
|
86 |
// Failure on authenticating, please reauthenticate
|
87 |
}
|
93 |
private function init_shutdown_hook() {
|
94 |
$this->api = Yoast_Api_Libs::load_api_libraries( array( 'oauth', 'googleanalytics' ) );
|
95 |
|
96 |
+
// Hook the WP cron event
|
97 |
+
add_action( 'wp', array( $this, 'setup_wp_cron_aggregate' ) );
|
98 |
+
|
99 |
+
// Hook our function to the WP cron event the fetch data daily
|
100 |
+
add_action( 'yst_ga_aggregate_data', array( $this, 'aggregate_data' ) );
|
101 |
+
|
102 |
+
// Check if the WP cron did run on time
|
103 |
+
if ( isset( $_GET['page'] ) && $_GET['page'] === 'yst_ga_dashboard' ) {
|
104 |
+
add_action( 'shutdown', array( $this, 'check_api_call_hook' ) );
|
105 |
+
}
|
106 |
+
}
|
107 |
|
108 |
+
/**
|
109 |
+
* Check if we scheduled the WP cron event, if not, do so.
|
110 |
+
*/
|
111 |
+
public function setup_wp_cron_aggregate() {
|
112 |
+
if ( ! wp_next_scheduled( 'yst_ga_aggregate_data' ) ) {
|
113 |
+
// Set the next event of fetching data
|
114 |
+
wp_schedule_event( strtotime( date( 'Y-m-d', strtotime( 'tomorrow' ) ) . ' 00:05:00 ' ), 'daily', 'yst_ga_aggregate_data' );
|
115 |
+
}
|
116 |
+
}
|
117 |
+
|
118 |
+
/**
|
119 |
+
* Check if the WP cron did run yesterday. If not, we need to run it form here
|
120 |
+
*/
|
121 |
+
public function check_api_call_hook() {
|
122 |
+
$last_run = get_transient( 'yst_ga_last_wp_run' );
|
123 |
+
|
124 |
+
if ( $last_run === false ) {
|
125 |
+
/**
|
126 |
+
* Transient doesn't exists, so we need to run the
|
127 |
+
* hook (This function runs already on Shutdown so
|
128 |
+
* we can call it directly from now on)
|
129 |
+
*/
|
130 |
+
$this->aggregate_data();
|
131 |
+
} else {
|
132 |
+
// Transient exists
|
133 |
+
if ( $this->hours_between( strtotime( $last_run ), time() ) >= 24 ) {
|
134 |
+
$this->aggregate_data();
|
135 |
}
|
136 |
}
|
137 |
}
|
138 |
|
139 |
+
/**
|
140 |
+
* Calculate the date difference, return the amount of hours between the two dates
|
141 |
+
*
|
142 |
+
* @param $last_run datetime
|
143 |
+
* @param $now datetime
|
144 |
+
*
|
145 |
+
* @return int
|
146 |
+
*/
|
147 |
+
private function hours_between( $last_run, $now ) {
|
148 |
+
$seconds = max( ( $now - $last_run ), 1 );
|
149 |
+
$hours = $seconds / 3600;
|
150 |
+
|
151 |
+
return floor( $hours );
|
152 |
+
}
|
153 |
+
|
154 |
/**
|
155 |
* Remove metrics and set them as a dimension if needed
|
156 |
*
|
226 |
*/
|
227 |
private function aggregate_metrics( $access_tokens, $metrics ) {
|
228 |
foreach ( $metrics as $metric ) {
|
229 |
+
$this->execute_call( $access_tokens, $metric, date( 'Y-m-d', strtotime( '-6 weeks' ) ), date( 'Y-m-d', strtotime( 'yesterday' ) ) );
|
230 |
}
|
231 |
}
|
232 |
|
240 |
foreach ( $dimensions as $dimension ) {
|
241 |
if ( ( isset( $dimension['id'] ) || isset( $dimension['dimension'] ) ) && isset( $dimension['metric'] ) ) {
|
242 |
if ( isset( $dimension['id'] ) ) {
|
243 |
+
$this->execute_call( $access_tokens, $dimension['metric'], date( 'Y-m-d', strtotime( '-1 month' ) ), date( 'Y-m-d', strtotime( 'yesterday' ) ), 'ga:dimension' . $dimension['id'] );
|
244 |
} elseif ( isset( $dimension['dimension'] ) ) {
|
245 |
if ( isset( $dimension['storage_name'] ) ) {
|
246 |
+
$this->execute_call( $access_tokens, $dimension['metric'], date( 'Y-m-d', strtotime( '-1 month' ) ), date( 'Y-m-d', strtotime( 'yesterday' ) ), 'ga:' . $dimension['dimension'], $dimension['storage_name'] );
|
247 |
} else {
|
248 |
+
$this->execute_call( $access_tokens, $dimension['metric'], date( 'Y-m-d', strtotime( '-1 month' ) ), date( 'Y-m-d', strtotime( 'yesterday' ) ), 'ga:' . $dimension['dimension'] );
|
249 |
}
|
250 |
}
|
251 |
}
|
252 |
}
|
253 |
}
|
254 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
255 |
/**
|
256 |
* Execute an API call to Google Analytics and store the data in the dashboards data class
|
257 |
*
|
406 |
if ( $storage_name != 'auto' ) {
|
407 |
$name = $storage_name;
|
408 |
}
|
409 |
+
|
410 |
+
/**
|
411 |
+
* Success, set a transient which stores the latest runtime
|
412 |
+
*/
|
413 |
+
if ( ! empty($response['body'] ) ) {
|
414 |
+
set_transient( 'yst_ga_last_wp_run', date( 'Y-m-d' ), 48 * HOUR_IN_SECONDS );
|
415 |
+
}
|
416 |
|
417 |
return Yoast_GA_Dashboards_Data::set( $name, $response['body'], strtotime( $start_date ), strtotime( $end_date ), $store_as );
|
418 |
} else {
|
admin/dashboards/drivers/class-admin-dashboards-graph-generate.php
CHANGED
@@ -98,6 +98,8 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Graph_Generate' ) ) {
|
|
98 |
$this->add_x_mapping( $timestamp );
|
99 |
$this->add_hover_mapping( $timestamp, $value );
|
100 |
}
|
|
|
|
|
101 |
}
|
102 |
|
103 |
/**
|
@@ -128,7 +130,9 @@ if ( ! class_exists( 'Yoast_GA_Dashboards_Graph_Generate' ) ) {
|
|
128 |
* @param integer $timestamp
|
129 |
*/
|
130 |
private function add_x_mapping( $timestamp ) {
|
131 |
-
|
|
|
|
|
132 |
}
|
133 |
|
134 |
/**
|
98 |
$this->add_x_mapping( $timestamp );
|
99 |
$this->add_hover_mapping( $timestamp, $value );
|
100 |
}
|
101 |
+
|
102 |
+
$this->mapping['x'] = array_filter($this->mapping['x']);
|
103 |
}
|
104 |
|
105 |
/**
|
130 |
* @param integer $timestamp
|
131 |
*/
|
132 |
private function add_x_mapping( $timestamp ) {
|
133 |
+
|
134 |
+
$is_monday = ( 'Mon' === date( 'D', $timestamp ) );
|
135 |
+
$this->mapping['x'][] = $is_monday ? date( $this->date_field . ' M', $timestamp ) : null;
|
136 |
}
|
137 |
|
138 |
/**
|
admin/pages/settings.php
CHANGED
@@ -39,18 +39,18 @@ echo $yoast_ga_admin->create_form( 'settings' );
|
|
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 class="button" href="' . $ga_url . '">' . __( '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->select( 'Analytics profile', 'analytics_profile', $profiles );
|
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" /> </label>';
|
53 |
-
echo '<a class="button" href="' . $ga_url . '">' . __( 'Re-authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
|
54 |
echo '</div>';
|
55 |
}
|
56 |
echo '</div>';
|
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 . '">' . __( '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->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" /> </label>';
|
53 |
+
echo '<a id="yst_ga_authenticate" class="button" href="' . $ga_url . '">' . __( 'Re-authenticate with your Google account', 'google-analytics-for-wordpress' ) . '</a>';
|
54 |
echo '</div>';
|
55 |
}
|
56 |
echo '</div>';
|
assets/css/yoast_ga_admin_dashboard.css
CHANGED
@@ -8,13 +8,13 @@
|
|
8 |
display: inline;
|
9 |
float: left;
|
10 |
width: 840px;
|
11 |
-
height:
|
12 |
margin: 5px;
|
13 |
}
|
14 |
|
15 |
.yoast-graph-holder,
|
16 |
.yoast-graph-yaxis {
|
17 |
-
height:
|
18 |
}
|
19 |
|
20 |
.yoast-graph-holder,
|
8 |
display: inline;
|
9 |
float: left;
|
10 |
width: 840px;
|
11 |
+
height: 315px;
|
12 |
margin: 5px;
|
13 |
}
|
14 |
|
15 |
.yoast-graph-holder,
|
16 |
.yoast-graph-yaxis {
|
17 |
+
height: 240px;
|
18 |
}
|
19 |
|
20 |
.yoast-graph-holder,
|
assets/css/yoast_ga_admin_dashboard.min.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
.yoast-graphs{display:inline-block;clear:both;position:relative}.yoast-graph{display:inline;float:left;width:840px;height:
|
1 |
+
.yoast-graphs{display:inline-block;clear:both;position:relative}.yoast-graph{display:inline;float:left;width:840px;height:315px;margin:5px}.yoast-graph-holder,.yoast-graph-yaxis{height:240px}.yoast-graph-holder,.yoast-graph-xaxis{width:780px}.yoast-graph-holder,.yoast-graph-xaxis,.yoast-graph-yaxis{float:left}.yoast-graph-holder{margin:0 5px 0 0;background:#fff}.yoast-graph-xaxis{height:20px;margin-left:50px}.yoast-graph-yaxis{overflow:hidden;width:50px}.x_label{display:none}.yoast-data-table{margin:25px 0 10px}.yoast-dashboard h3{float:left;clear:both;width:100%;margin:0 0 10px}.yoast-dashboard .period{color:#555;font-size:.8em;font-weight:400;font-style:italic}.yoast-data-table table.dataTable thead .sorting,.yoast-data-table table.dataTable thead .sorting_asc,.yoast-data-table table.dataTable thead .sorting_desc{border-color:#d3d3d3}.yoast-data-table table.dataTable.no-footer{border-bottom:none}
|
assets/css/yoast_ga_styles.css
CHANGED
@@ -187,3 +187,8 @@ select.ga-multiple {
|
|
187 |
.yoast_help {
|
188 |
margin: 2px 5px 0 5px;
|
189 |
}
|
|
|
|
|
|
|
|
|
|
187 |
.yoast_help {
|
188 |
margin: 2px 5px 0 5px;
|
189 |
}
|
190 |
+
|
191 |
+
#enter_ua div {
|
192 |
+
display: inline-block;
|
193 |
+
margin: 0;
|
194 |
+
}
|
assets/js/yoast_ga_admin.js
CHANGED
@@ -27,22 +27,25 @@ jQuery(document).ready(function() {
|
|
27 |
jQuery('#' + activeTab).addClass('active');
|
28 |
jQuery('#' + activeTab + '-tab').addClass('nav-tab-active');
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
// Manually enter a UA code
|
31 |
-
jQuery('#yoast-ga-form-checkbox-settings-manual_ua_code').click(function() {
|
32 |
-
|
33 |
-
jQuery('#enter_ua').show();
|
34 |
-
} else {
|
35 |
-
jQuery('#enter_ua').hide();
|
36 |
-
jQuery('#yoast-ga-form-text-settings-manual_ua_code_field').attr('value', '');
|
37 |
-
}
|
38 |
-
});
|
39 |
|
40 |
jQuery('.nav-tab-active').click();
|
41 |
|
42 |
-
if (jQuery('#yoast-ga-form-checkbox-settings-manual_ua_code').is(':checked')) {
|
43 |
-
jQuery('#enter_ua').show();
|
44 |
-
}
|
45 |
-
|
46 |
jQuery('.yoast_help').qtip({
|
47 |
position: {
|
48 |
corner: {
|
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");
|
34 |
+
jQuery("#yst_ga_authenticate").attr('disabled', true);
|
35 |
+
} else {
|
36 |
+
jQuery('#enter_ua').hide();
|
37 |
+
jQuery('#yoast-ga-form-text-settings-manual_ua_code_field').attr('value', '');
|
38 |
+
jQuery("#yoast-ga-form-select-settings-analytics_profile").prop('disabled', false).trigger("chosen:updated");
|
39 |
+
jQuery("#yst_ga_authenticate").attr('disabled', false);
|
40 |
+
}
|
41 |
+
}
|
42 |
+
|
43 |
// Manually enter a UA code
|
44 |
+
jQuery('#yoast-ga-form-checkbox-settings-manual_ua_code').click( function() { yst_ga_switch_manual(); } );
|
45 |
+
yst_ga_switch_manual();
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
jQuery('.nav-tab-active').click();
|
48 |
|
|
|
|
|
|
|
|
|
49 |
jQuery('.yoast_help').qtip({
|
50 |
position: {
|
51 |
corner: {
|
assets/js/yoast_ga_admin.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
jQuery(document).ready(function(){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
|
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("#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("#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(".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"}})});
|
assets/js/yoast_ga_admin_dashboard.js
CHANGED
@@ -113,7 +113,7 @@ jQuery.fn.extend(
|
|
113 |
},
|
114 |
hover : [],
|
115 |
width : 780, // The width of the graph
|
116 |
-
height :
|
117 |
graph : '', // Graph element
|
118 |
graph_axis : { // The axis for X and Y
|
119 |
x: '',
|
@@ -270,11 +270,14 @@ jQuery.fn.extend(
|
|
270 |
width : this.width,
|
271 |
height : this.height,
|
272 |
series : [{
|
273 |
-
name
|
274 |
-
color: '#
|
275 |
-
|
|
|
276 |
}],
|
277 |
-
renderer: 'area',
|
|
|
|
|
278 |
padding : {
|
279 |
top : 0.10,
|
280 |
bottom: 0.02
|
@@ -303,7 +306,7 @@ jQuery.fn.extend(
|
|
303 |
tickFormat : this.format_axis_x,
|
304 |
grid : true,
|
305 |
orientation : 'bottom',
|
306 |
-
|
307 |
}
|
308 |
);
|
309 |
}
|
@@ -320,7 +323,7 @@ jQuery.fn.extend(
|
|
320 |
element : target.querySelector('.yoast-graph-yaxis'),
|
321 |
graph : this.graph,
|
322 |
orientation: 'left',
|
323 |
-
height : '
|
324 |
// If n is 0 return emptystring, to prevent zero displayed on graph
|
325 |
tickFormat : function (n) {
|
326 |
return (n === 0) ? '' : n;
|
113 |
},
|
114 |
hover : [],
|
115 |
width : 780, // The width of the graph
|
116 |
+
height : 240,
|
117 |
graph : '', // Graph element
|
118 |
graph_axis : { // The axis for X and Y
|
119 |
x: '',
|
270 |
width : this.width,
|
271 |
height : this.height,
|
272 |
series : [{
|
273 |
+
name : element.attr('data-label'),
|
274 |
+
color : '#e6f4fa',
|
275 |
+
stroke: '#058dc7',
|
276 |
+
data : this.data
|
277 |
}],
|
278 |
+
renderer : 'area',
|
279 |
+
stroke : true,
|
280 |
+
interpolation: 'linear',
|
281 |
padding : {
|
282 |
top : 0.10,
|
283 |
bottom: 0.02
|
306 |
tickFormat : this.format_axis_x,
|
307 |
grid : true,
|
308 |
orientation : 'bottom',
|
309 |
+
tickValues : Object.keys(this.axis.x)
|
310 |
}
|
311 |
);
|
312 |
}
|
323 |
element : target.querySelector('.yoast-graph-yaxis'),
|
324 |
graph : this.graph,
|
325 |
orientation: 'left',
|
326 |
+
height : '240',
|
327 |
// If n is 0 return emptystring, to prevent zero displayed on graph
|
328 |
tickFormat : function (n) {
|
329 |
return (n === 0) ? '' : n;
|
assets/js/yoast_ga_admin_dashboard.min.js
CHANGED
@@ -1 +1 @@
|
|
1 |
-
function dimension_switch(a){"use strict";a=jQuery(a);var b=a.closest(".wpseotab").find(".yoast-data-table"),c="";jQuery.each(b,function(a,b){c+='<option value="'+jQuery(b).attr("id")+'">'+jQuery(b).attr("data-label")+"</option>"}),a.append(c),b.not(":eq(0)").hide(),setTimeout(function(){a.chosen().change(function(){b.hide(),jQuery("#"+jQuery(this).val()).show()})},1500)}jQuery.fn.extend({yoast_ga_table:function(){"use strict";return this.each(function(){var a=jQuery(this),b=jQuery(a).attr("id"),c={init:function(){this.get_data()},get_data:function(){var c={action:"yoast_dashboard_tabledata",_ajax_nonce:yoast_ga_dashboard_nonce,graph_id:b,period:"lastmonth",dimension_id:jQuery(a).attr("data-dimension")};jQuery.getJSON(ajaxurl,c,this.parse_response)},parse_response:function(b){a.find("table").dataTable({columns:[{data:"name"},{data:"value"}],data:b.data,order:[1,"dsc"],language:{aria:{sortAscending:dashboard_translate.sort_ascending,sortDescending:dashboard_translate.sort_descending},emptyTable:dashboard_translate.empty_table,info:dashboard_translate.info,infoEmpty:dashboard_translate.info_empty,infoFiltered:dashboard_translate.info_filtered,lengthMenu:dashboard_translate.length_menu,loadingRecords:dashboard_translate.loading_records,paginate:{first:dashboard_translate.pagination_first,last:dashboard_translate.pagination_last,next:dashboard_translate.pagination_next,previous:dashboard_translate.pagination_previous},processing:dashboard_translate.processing,search:"_INPUT_",searchPlaceholder:dashboard_translate.search_placeholder,zeroRecords:dashboard_translate.zero_records}})}};c.init()})},yoast_ga_graph:function(){"use strict";return this.each(function(){var a=jQuery(this),b=jQuery(a).attr("id"),c=document.getElementById(b),d={data:[],axis:{x:[],y:[]},hover:[],width:780,height:
|
1 |
+
function dimension_switch(a){"use strict";a=jQuery(a);var b=a.closest(".wpseotab").find(".yoast-data-table"),c="";jQuery.each(b,function(a,b){c+='<option value="'+jQuery(b).attr("id")+'">'+jQuery(b).attr("data-label")+"</option>"}),a.append(c),b.not(":eq(0)").hide(),setTimeout(function(){a.chosen().change(function(){b.hide(),jQuery("#"+jQuery(this).val()).show()})},1500)}jQuery.fn.extend({yoast_ga_table:function(){"use strict";return this.each(function(){var a=jQuery(this),b=jQuery(a).attr("id"),c={init:function(){this.get_data()},get_data:function(){var c={action:"yoast_dashboard_tabledata",_ajax_nonce:yoast_ga_dashboard_nonce,graph_id:b,period:"lastmonth",dimension_id:jQuery(a).attr("data-dimension")};jQuery.getJSON(ajaxurl,c,this.parse_response)},parse_response:function(b){a.find("table").dataTable({columns:[{data:"name"},{data:"value"}],data:b.data,order:[1,"dsc"],language:{aria:{sortAscending:dashboard_translate.sort_ascending,sortDescending:dashboard_translate.sort_descending},emptyTable:dashboard_translate.empty_table,info:dashboard_translate.info,infoEmpty:dashboard_translate.info_empty,infoFiltered:dashboard_translate.info_filtered,lengthMenu:dashboard_translate.length_menu,loadingRecords:dashboard_translate.loading_records,paginate:{first:dashboard_translate.pagination_first,last:dashboard_translate.pagination_last,next:dashboard_translate.pagination_next,previous:dashboard_translate.pagination_previous},processing:dashboard_translate.processing,search:"_INPUT_",searchPlaceholder:dashboard_translate.search_placeholder,zeroRecords:dashboard_translate.zero_records}})}};c.init()})},yoast_ga_graph:function(){"use strict";return this.each(function(){var a=jQuery(this),b=jQuery(a).attr("id"),c=document.getElementById(b),d={data:[],axis:{x:[],y:[]},hover:[],width:780,height:240,graph:"",graph_axis:{x:"",y:""},graph_hover:[],init:function(){this.get_data(),this.add_events()},add_events:function(){var b=this;jQuery(a).on("graph_update",function(a,c){b.update(c,b)})},get_data:function(){var a={action:"yoast_dashboard_graphdata",_ajax_nonce:yoast_ga_dashboard_nonce,graph_id:b,period:"lastmonth"};jQuery.getJSON(ajaxurl,a,this.parse_response)},parse_response:function(a){d.set_data(a.data),void 0!==a.mapping.x&&d.set_x_axis_mapping(a.mapping.x),void 0!==a.mapping.y&&d.set_y_axis_mapping(a.mapping.y),void 0!==a.mapping.hover&&d.set_hover_mapping(a.mapping.hover),d.create()},set_data:function(a){this.data=a},add_data:function(a){d.data.push(a)},set_x_axis_mapping:function(a){d.axis.x=a},add_x_axis_mapping:function(a){this.axis.x.push(a)},set_y_axis_mapping:function(a){d.axis.y=a},set_hover_mapping:function(a){d.hover=a},add_y_axis_mapping:function(a){this.axis.y.push(a)},create:function(){this.truncate_element(),this.create_graph(),this.create_axis(),this.create_hover(),this.render()},truncate_element:function(){a.find("> div").html("")},create_graph:function(){this.graph=new Rickshaw.Graph({element:c.querySelector(".yoast-graph-holder"),width:this.width,height:this.height,series:[{name:a.attr("data-label"),color:"#e6f4fa",stroke:"#058dc7",data:this.data}],renderer:"area",stroke:!0,interpolation:"linear",padding:{top:.1,bottom:.02}})},create_axis:function(){this.create_x_axis(),this.create_y_axis()},create_x_axis:function(){null!==c.querySelector(".yoast-graph-xaxis")&&(this.graph_axis.x=new Rickshaw.Graph.Axis.X({element:c.querySelector(".yoast-graph-xaxis"),graph:this.graph,tickFormat:this.format_axis_x,grid:!0,orientation:"bottom",tickValues:Object.keys(this.axis.x)}))},create_y_axis:function(){null!==c.querySelector(".yoast-graph-xaxis")&&(this.graph_axis.y=new Rickshaw.Graph.Axis.Y({element:c.querySelector(".yoast-graph-yaxis"),graph:this.graph,orientation:"left",height:"240",tickFormat:function(a){return 0===a?"":a}}))},create_hover:function(){this.graph_hover=new Rickshaw.Graph.HoverDetail({graph:this.graph,formatter:function(b,c){var e=d.hover[c];"1"===a.attr("data-percent")&&(e+="%");var f='<span class="detail_swatch" style="background-color: '+b.color+'"></span>',g=f+e+"<br />";return g}})},render:function(){this.graph.render()},format_axis_x:function(a){return d.axis.x[a]},update:function(a,b){b.add_data(a.data),b.add_x_axis_mapping(a.mapping),b.graph.update(),b.render()}};d.init()})},yoast_ga_graph_update:function(a){"use strict";jQuery(this).trigger("graph_update",[a])},yoast_ga_table_update:function(a){"use strict";jQuery(this).trigger("table_update",[a])}}),jQuery(function(){"use strict";jQuery(".yoast-graph").yoast_ga_graph(),jQuery(".yoast-data-table").yoast_ga_table()});
|
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.
|
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.
|
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.3
|
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.3' );
|
34 |
|
35 |
define( 'GAWP_FILE', __FILE__ );
|
36 |
|
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.0
|
7 |
-
Stable tag: 5.2.
|
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.2 =
|
53 |
|
54 |
Release Date: December 10th, 2014
|
4 |
Tags: analytics, google analytics, statistics, tracking, stats, google, yoast
|
5 |
Requires at least: 3.8
|
6 |
Tested up to: 4.0
|
7 |
+
Stable tag: 5.2.3
|
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.3 =
|
53 |
+
|
54 |
+
Release Date: December 11th, 2014
|
55 |
+
|
56 |
+
Enhancements:
|
57 |
+
* improved visual look and data representation for dashboard graphs, props [Andrey Savchenko](https://github.com/Rarst/)
|
58 |
+
* when manual UA-code is selected, the profile selection gets disabled to clarify that the user is choosing an alternative to regular profile selection.
|
59 |
+
|
60 |
+
Bugfixes:
|
61 |
+
* Fixes a bug where GA profile was fetched with every admin request, resulting in a pile of unnecessary API requests.
|
62 |
+
* Fixes a problem where GA started throttling API requests done by our plugin because there were too many. We now fetch the data only once a day from GA. For realtime data, users should go to Google Analytics.
|
63 |
+
|
64 |
= 5.2.2 =
|
65 |
|
66 |
Release Date: December 10th, 2014
|