Google Analytics for WordPress by MonsterInsights - Version 5.3.1

Version Description

Release Date: February 11th, 2015

  • Enhancements:

    • Added a filter (yst-ga-filter-api-end-date) to enable our premium plugin to show more recent data in the dashboards.
  • Features:

    • Added Enhanced link attribution for Universal tracking.
  • Bugfixes

    • Fixes a bug in the grunt task we use for downloading translations from GlotPress, which caused the translations to no longer be loaded.
    • Fixes a bug where the links to our submenu pages were broken in case of a locale other than en_US being set.
Download this release

Release Info

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

Code changes from version 5.3 to 5.3.1

admin/api-libs/composer.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name" : "yoast/api-libs",
3
+ "description": "Shared API libraries for Yoast projects.",
4
+ "keywords" : ["wordpress"],
5
+ "homepage" : "https://github.com/Yoast/api-libs",
6
+ "license" : "GPL-2.0+",
7
+ "authors" : [
8
+ {
9
+ "name" : "Team Yoast",
10
+ "email" : "support@yoast.com",
11
+ "homepage": "https://yoast.com"
12
+ }
13
+ ],
14
+ "support" : {
15
+ "issues": "https://github.com/Yoast/api-libs/issues"
16
+ },
17
+ "autoload" : {
18
+ "classmap": ["class-api-libs.php"]
19
+ }
20
+ }
admin/class-admin-form.php CHANGED
@@ -32,13 +32,18 @@ class Yoast_GA_Admin_Form {
32
  *
33
  * @param string $button_label
34
  * @param string $name
 
35
  *
36
  * @return null|string
37
  */
38
- public static function end_form( $button_label = 'Save changes', $name = 'submit' ) {
39
  $output = null;
40
  $output .= '<div class="ga-form ga-form-input">';
41
- $output .= '<input type="submit" name="ga-form-' . $name . '" value="' . $button_label . '" class="button button-primary ga-form-submit" id="yoast-ga-form-submit-' . self::$form_namespace . '">';
 
 
 
 
42
  $output .= '</div></form>';
43
 
44
  return $output;
32
  *
33
  * @param string $button_label
34
  * @param string $name
35
+ * @param string $onclick
36
  *
37
  * @return null|string
38
  */
39
+ public static function end_form( $button_label = 'Save changes', $name = 'submit', $onclick = null ) {
40
  $output = null;
41
  $output .= '<div class="ga-form ga-form-input">';
42
+ $output .= '<input type="submit" name="ga-form-' . $name . '" value="' . $button_label . '" class="button button-primary ga-form-submit" id="yoast-ga-form-submit-' . self::$form_namespace . '"';
43
+ if( ! is_null( $onclick ) ){
44
+ $output .= ' onclick="' . $onclick . '"';
45
+ }
46
+ $output .= ' />';
47
  $output .= '</div></form>';
48
 
49
  return $output;
admin/class-admin-menu.php CHANGED
@@ -3,7 +3,7 @@
3
  /**
4
  * This class is for the backend, extendable for all child classes
5
  */
6
- class Yoast_GA_Admin_Menu extends Yoast_GA_Options {
7
 
8
  /**
9
  * The property used for storing target object (class admin)
@@ -19,6 +19,13 @@ class Yoast_GA_Admin_Menu extends Yoast_GA_Options {
19
  */
20
  private $dashboards_disabled;
21
 
 
 
 
 
 
 
 
22
  /**
23
  * Setting the target_object and adding actions
24
  *
@@ -39,6 +46,7 @@ class Yoast_GA_Admin_Menu extends Yoast_GA_Options {
39
  }
40
 
41
  $this->dashboards_disabled = Yoast_GA_Settings::get_instance()->dashboards_disabled();
 
42
  }
43
 
44
  /**
@@ -106,9 +114,9 @@ class Yoast_GA_Admin_Menu extends Yoast_GA_Options {
106
  private function get_menu_position_value( $location ) {
107
  if ( $location == 'top' ) {
108
  return '2.00013467543';
109
- } else {
110
- return '100.00013467543';
111
  }
 
 
112
  }
113
 
114
  /**
@@ -119,22 +127,15 @@ class Yoast_GA_Admin_Menu extends Yoast_GA_Options {
119
  *
120
  * @return array
121
  */
122
- private function prepare_submenu_page( $submenu_name, $font_color = '' ) {
123
- $menu_title = $this->parse_menu_title( $submenu_name, $font_color );
124
- $submenu_page = array(
125
- 'parent_slug' => 'yst_ga_dashboard',
126
  'page_title' => __( 'Yoast Google Analytics:', 'google-analytics-for-wordpress' ) . ' ' . $submenu_name,
127
- 'menu_title' => $menu_title,
128
  'capability' => 'manage_options',
129
- 'menu_slug' => 'yst_ga_' . strtolower( $submenu_name ),
130
  'submenu_function' => array( $this->target_object, 'load_page' ),
131
  );
132
-
133
- if ( $this->dashboards_disabled ) {
134
- $submenu_page['parent_slug'] = 'yst_ga_settings';
135
- }
136
-
137
- return $submenu_page;
138
  }
139
 
140
  /**
@@ -190,13 +191,34 @@ class Yoast_GA_Admin_Menu extends Yoast_GA_Options {
190
  * @return array
191
  */
192
  private function add_submenu_pages() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  /**
194
  * Array structure:
195
  *
196
  * array(
197
  * $submenu_name => array(
198
  * 'color' => $font_color,
199
- * 'label' => __( 'text-label', 'google-analytics-for-wordpress' ),
 
200
  * ),
201
  * ..,
202
  * )
@@ -204,38 +226,29 @@ class Yoast_GA_Admin_Menu extends Yoast_GA_Options {
204
  * $font_color can be left empty.
205
  *
206
  */
207
- $submenu_types = array(
208
- 'extensions' => array(
209
- 'color' => '#f18500',
210
- 'label' => __( 'Extensions', 'google-analytics-for-wordpress' ),
211
- ),
212
- );
213
 
214
  if ( ! is_network_admin() ) {
215
- $submenu_types = array_merge(
216
- array(
217
- 'dashboard' => array(
218
- 'label' => __( 'Dashboard', 'google-analytics-for-wordpress' ),
219
- ),
220
- 'settings' => array(
221
- 'label' => __( 'Settings', 'google-analytics-for-wordpress' ),
222
- ),
223
- ),
224
- $submenu_types
 
225
  );
226
  }
227
 
228
- if ( $this->dashboards_disabled ) {
229
- unset( $submenu_types['dashboard'] );
230
- }
 
 
231
 
232
- foreach ( $submenu_types as $submenu_key => $submenu ) {
233
- if ( isset( $submenu['color'] ) ) {
234
- $submenu_page = $this->prepare_submenu_page( $submenu['label'], $submenu['color'] );
235
- } else {
236
- $submenu_page = $this->prepare_submenu_page( $submenu['label'] );
237
- }
238
- $this->add_submenu_page( $submenu_page );
239
- }
240
  }
241
  }
3
  /**
4
  * This class is for the backend, extendable for all child classes
5
  */
6
+ class Yoast_GA_Admin_Menu {
7
 
8
  /**
9
  * The property used for storing target object (class admin)
19
  */
20
  private $dashboards_disabled;
21
 
22
+ /**
23
+ * The parent slug for the submenu items based on if the dashboards are disabled or not.
24
+ *
25
+ * @var string
26
+ */
27
+ private $parent_slug;
28
+
29
  /**
30
  * Setting the target_object and adding actions
31
  *
46
  }
47
 
48
  $this->dashboards_disabled = Yoast_GA_Settings::get_instance()->dashboards_disabled();
49
+ $this->parent_slug = ( $this->dashboards_disabled ? 'yst_ga_settings' : 'yst_ga_dashboard' );
50
  }
51
 
52
  /**
114
  private function get_menu_position_value( $location ) {
115
  if ( $location == 'top' ) {
116
  return '2.00013467543';
 
 
117
  }
118
+
119
+ return '100.00013467543';
120
  }
121
 
122
  /**
127
  *
128
  * @return array
129
  */
130
+ private function prepare_submenu_page( $submenu_name, $submenu_slug, $font_color = '' ) {
131
+ return array(
132
+ 'parent_slug' => $this->parent_slug,
 
133
  'page_title' => __( 'Yoast Google Analytics:', 'google-analytics-for-wordpress' ) . ' ' . $submenu_name,
134
+ 'menu_title' => $this->parse_menu_title( $submenu_name, $font_color ),
135
  'capability' => 'manage_options',
136
+ 'menu_slug' => 'yst_ga_' . $submenu_slug,
137
  'submenu_function' => array( $this->target_object, 'load_page' ),
138
  );
 
 
 
 
 
 
139
  }
140
 
141
  /**
191
  * @return array
192
  */
193
  private function add_submenu_pages() {
194
+ foreach ( $this->get_submenu_types() as $submenu ) {
195
+ if ( isset( $submenu['color'] ) ) {
196
+ $submenu_page = $this->prepare_submenu_page( $submenu['label'], $submenu['slug'], $submenu['color'] );
197
+ } else {
198
+ $submenu_page = $this->prepare_submenu_page( $submenu['label'], $submenu['slug'] );
199
+ }
200
+ $this->add_submenu_page( $submenu_page );
201
+ }
202
+ }
203
+
204
+ /**
205
+ * Determine which submenu types should be added as a submenu page.
206
+ *
207
+ * Dashboard can be disables by user
208
+ *
209
+ * Dashboard and settings are disables in network admin
210
+ *
211
+ * @return array
212
+ */
213
+ private function get_submenu_types() {
214
  /**
215
  * Array structure:
216
  *
217
  * array(
218
  * $submenu_name => array(
219
  * 'color' => $font_color,
220
+ * 'label' => __( 'text-label', 'google-analytics-for-wordpress' ),
221
+ * 'slug' => $menu_slug,
222
  * ),
223
  * ..,
224
  * )
226
  * $font_color can be left empty.
227
  *
228
  */
229
+ $submenu_types = array();
 
 
 
 
 
230
 
231
  if ( ! is_network_admin() ) {
232
+
233
+ if ( ! $this->dashboards_disabled ) {
234
+ $submenu_types['dashboard'] = array(
235
+ 'label' => __( 'Dashboard', 'google-analytics-for-wordpress' ),
236
+ 'slug' => 'dashboard',
237
+ );
238
+ }
239
+
240
+ $submenu_types['settings'] = array(
241
+ 'label' => __( 'Settings', 'google-analytics-for-wordpress' ),
242
+ 'slug' => 'settings',
243
  );
244
  }
245
 
246
+ $submenu_types['extensions'] = array(
247
+ 'color' => '#f18500',
248
+ 'label' => __( 'Extensions', 'google-analytics-for-wordpress' ),
249
+ 'slug' => 'extensions',
250
+ );
251
 
252
+ return $submenu_types;
 
 
 
 
 
 
 
253
  }
254
  }
admin/dashboards/class-admin-dashboards-collector.php CHANGED
@@ -33,16 +33,16 @@ class Yoast_GA_Dashboards_Collector {
33
  /**
34
  * Store the GA Profile ID
35
  *
36
- * @var
37
  */
38
  public $ga_profile_id;
39
 
40
  /**
41
  * Construct on the dashboards class for GA
42
  *
43
- * @param $ga_profile_id
44
- * @param $active_metrics
45
- * @param $valid_metrics
46
  */
47
  public function __construct( $ga_profile_id, $active_metrics, $valid_metrics ) {
48
  $this->ga_profile_id = $ga_profile_id;
@@ -132,7 +132,7 @@ class Yoast_GA_Dashboards_Collector {
132
  /**
133
  * Get the datetime when the aggregate data function was succesful
134
  *
135
- * @return datetime
136
  */
137
  private function get_last_aggregate_run() {
138
  return get_option( 'yst_ga_last_wp_run' );
@@ -141,7 +141,7 @@ class Yoast_GA_Dashboards_Collector {
141
  /**
142
  * Remove metrics and set them as a dimension if needed
143
  *
144
- * @param $metrics
145
  *
146
  * @return mixed
147
  */
@@ -192,7 +192,7 @@ class Yoast_GA_Dashboards_Collector {
192
  *
193
  * @filter ga_dashboards_dimensions
194
  *
195
- * @param $dimensions
196
  *
197
  * @return array
198
  */
@@ -205,32 +205,54 @@ class Yoast_GA_Dashboards_Collector {
205
  return $this->dimensions;
206
  }
207
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  /**
209
  * Aggregate metrics from GA. This function should be called in the shutdown function.
210
  *
211
- * @param $metrics
212
  */
213
  private function aggregate_metrics( $metrics ) {
 
 
214
  foreach ( $metrics as $metric ) {
215
- $this->execute_call( $metric, date( 'Y-m-d', strtotime( '-6 weeks' ) ), date( 'Y-m-d', strtotime( 'yesterday' ) ) );
216
  }
217
  }
218
 
219
  /**
220
  * Aggregate dimensions from GA. This function should be called in the shutdown function.
221
  *
222
- * @param $dimensions
223
  */
224
  private function aggregate_dimensions( $dimensions ) {
 
 
225
  foreach ( $dimensions as $dimension ) {
226
- if ( ( isset( $dimension['id'] ) || isset( $dimension['dimension'] ) ) && isset( $dimension['metric'] ) ) {
227
  if ( isset( $dimension['id'] ) ) {
228
- $this->execute_call( $dimension['metric'], date( 'Y-m-d', strtotime( '-1 month' ) ), date( 'Y-m-d', strtotime( 'yesterday' ) ), 'ga:dimension' . $dimension['id'] );
229
  } elseif ( isset( $dimension['dimension'] ) ) {
230
  if ( isset( $dimension['storage_name'] ) ) {
231
- $this->execute_call( $dimension['metric'], date( 'Y-m-d', strtotime( '-1 month' ) ), date( 'Y-m-d', strtotime( 'yesterday' ) ), 'ga:' . $dimension['dimension'], $dimension['storage_name'] );
232
  } else {
233
- $this->execute_call( $dimension['metric'], date( 'Y-m-d', strtotime( '-1 month' ) ), date( 'Y-m-d', strtotime( 'yesterday' ) ), 'ga:' . $dimension['dimension'] );
234
  }
235
  }
236
  }
@@ -240,11 +262,11 @@ class Yoast_GA_Dashboards_Collector {
240
  /**
241
  * Execute an API call to Google Analytics and store the data in the dashboards data class
242
  *
243
- * @param $metric
244
- * @param $start_date 2014-10-16
245
- * @param $end_date 2014-11-20
246
- * @param $dimensions ga:date
247
- * @param $storage_name string
248
  *
249
  * @return bool
250
  */
@@ -280,7 +302,6 @@ class Yoast_GA_Dashboards_Collector {
280
 
281
  /**
282
  * When the API isn't able to get a successful response (code 200), we have to save that the call has failed
283
- *
284
  */
285
  private function save_api_failure() {
286
  update_option( 'yst_ga_api_call_fail', true );
@@ -289,7 +310,7 @@ class Yoast_GA_Dashboards_Collector {
289
  /**
290
  * Get the storage type from dimensions
291
  *
292
- * @param $dimensions
293
  *
294
  * @return string
295
  */
@@ -304,9 +325,10 @@ class Yoast_GA_Dashboards_Collector {
304
  /**
305
  * Prepare dimensions before adding them as a parameter in a call
306
  *
307
- * @param $dimensions
 
308
  *
309
- * @return string
310
  */
311
  private function prepare_dimensions( $dimensions, $metric ) {
312
  $filter_metrics = $this->get_filter_metrics();
@@ -329,12 +351,12 @@ class Yoast_GA_Dashboards_Collector {
329
  /**
330
  * Build the params for a call to Google Analytics, return them prepared for a http query
331
  *
332
- * @param $start_date
333
- * @param $end_date
334
- * @param $dimensions
335
- * @param $metric
336
  *
337
- * @return array|string
338
  */
339
  private function build_params_for_call( $start_date, $end_date, $dimensions, $metric ) {
340
  /**
@@ -364,9 +386,9 @@ class Yoast_GA_Dashboards_Collector {
364
  * Add a sort direction if we need to (Especially on dimensions which are
365
  * listed in $this->get_filter_metrics())
366
  *
367
- * @param $params
368
  *
369
- * @return mixed
370
  */
371
  private function add_sort_direction( $params, $dimensions, $metric ) {
372
  $filter_dimensions = $this->get_filter_metrics();
@@ -383,13 +405,13 @@ class Yoast_GA_Dashboards_Collector {
383
  /**
384
  * Handle the response from the Google Analytics api.
385
  *
386
- * @param $response
387
- * @param $metric
388
- * @param $dimensions
389
- * @param $start_date
390
- * @param $end_date
391
- * @param $store_as
392
- * @param $storage_name
393
  *
394
  * @return bool
395
  */
@@ -427,7 +449,7 @@ class Yoast_GA_Dashboards_Collector {
427
  /**
428
  * Log an error while calling the Google Analytics API
429
  *
430
- * @param $error
431
  */
432
  private function log_error( $error ) {
433
  if ( true == WP_DEBUG ) {
33
  /**
34
  * Store the GA Profile ID
35
  *
36
+ * @var int
37
  */
38
  public $ga_profile_id;
39
 
40
  /**
41
  * Construct on the dashboards class for GA
42
  *
43
+ * @param int $ga_profile_id
44
+ * @param array $active_metrics
45
+ * @param array $valid_metrics
46
  */
47
  public function __construct( $ga_profile_id, $active_metrics, $valid_metrics ) {
48
  $this->ga_profile_id = $ga_profile_id;
132
  /**
133
  * Get the datetime when the aggregate data function was succesful
134
  *
135
+ * @return mixed
136
  */
137
  private function get_last_aggregate_run() {
138
  return get_option( 'yst_ga_last_wp_run' );
141
  /**
142
  * Remove metrics and set them as a dimension if needed
143
  *
144
+ * @param array $metrics
145
  *
146
  * @return mixed
147
  */
192
  *
193
  * @filter ga_dashboards_dimensions
194
  *
195
+ * @param array $dimensions
196
  *
197
  * @return array
198
  */
205
  return $this->dimensions;
206
  }
207
 
208
+ /**
209
+ * Get the start and and date for aggregation functionality
210
+ *
211
+ * @return array
212
+ */
213
+ private function get_date_range() {
214
+ /**
215
+ * Filter: 'yst-ga-filter-api-end-date' - Allow people to change the end date for the dashboard
216
+ * data. Default: yesterday.
217
+ *
218
+ * @api string Date (Y-m-d)
219
+ */
220
+ return array(
221
+ 'start' => date( 'Y-m-d', strtotime( '-1 month' ) ),
222
+ 'end' => apply_filters( 'yst-ga-filter-api-end-date', date( 'Y-m-d', strtotime( 'yesterday' ) ) ),
223
+ );
224
+ }
225
+
226
  /**
227
  * Aggregate metrics from GA. This function should be called in the shutdown function.
228
  *
229
+ * @param array $metrics
230
  */
231
  private function aggregate_metrics( $metrics ) {
232
+ $dates = $this->get_date_range();
233
+
234
  foreach ( $metrics as $metric ) {
235
+ $this->execute_call( $metric, $dates['start'], $dates['end'] );
236
  }
237
  }
238
 
239
  /**
240
  * Aggregate dimensions from GA. This function should be called in the shutdown function.
241
  *
242
+ * @param array $dimensions
243
  */
244
  private function aggregate_dimensions( $dimensions ) {
245
+ $dates = $this->get_date_range();
246
+
247
  foreach ( $dimensions as $dimension ) {
248
+ if ( isset( $dimension['metric'] ) ) {
249
  if ( isset( $dimension['id'] ) ) {
250
+ $this->execute_call( $dimension['metric'], $dates['start'], $dates['end'], 'ga:dimension' . $dimension['id'] );
251
  } elseif ( isset( $dimension['dimension'] ) ) {
252
  if ( isset( $dimension['storage_name'] ) ) {
253
+ $this->execute_call( $dimension['metric'], $dates['start'], $dates['end'], 'ga:' . $dimension['dimension'], $dimension['storage_name'] );
254
  } else {
255
+ $this->execute_call( $dimension['metric'], $dates['start'], $dates['end'], 'ga:' . $dimension['dimension'] );
256
  }
257
  }
258
  }
262
  /**
263
  * Execute an API call to Google Analytics and store the data in the dashboards data class
264
  *
265
+ * @param string $metric
266
+ * @param string $start_date 2014-10-16
267
+ * @param string $end_date 2014-11-20
268
+ * @param string $dimensions ga:date
269
+ * @param string $storage_name
270
  *
271
  * @return bool
272
  */
302
 
303
  /**
304
  * When the API isn't able to get a successful response (code 200), we have to save that the call has failed
 
305
  */
306
  private function save_api_failure() {
307
  update_option( 'yst_ga_api_call_fail', true );
310
  /**
311
  * Get the storage type from dimensions
312
  *
313
+ * @param string $dimensions
314
  *
315
  * @return string
316
  */
325
  /**
326
  * Prepare dimensions before adding them as a parameter in a call
327
  *
328
+ * @param array $dimensions
329
+ * @param array $metric
330
  *
331
+ * @return array
332
  */
333
  private function prepare_dimensions( $dimensions, $metric ) {
334
  $filter_metrics = $this->get_filter_metrics();
351
  /**
352
  * Build the params for a call to Google Analytics, return them prepared for a http query
353
  *
354
+ * @param string $start_date
355
+ * @param string $end_date
356
+ * @param string $dimensions
357
+ * @param string $metric
358
  *
359
+ * @return string
360
  */
361
  private function build_params_for_call( $start_date, $end_date, $dimensions, $metric ) {
362
  /**
386
  * Add a sort direction if we need to (Especially on dimensions which are
387
  * listed in $this->get_filter_metrics())
388
  *
389
+ * @param array $params
390
  *
391
+ * @return array
392
  */
393
  private function add_sort_direction( $params, $dimensions, $metric ) {
394
  $filter_dimensions = $this->get_filter_metrics();
405
  /**
406
  * Handle the response from the Google Analytics api.
407
  *
408
+ * @param array|boolean $response
409
+ * @param string $metric
410
+ * @param array $dimensions
411
+ * @param string $start_date
412
+ * @param string $end_date
413
+ * @param string $store_as
414
+ * @param string $storage_name
415
  *
416
  * @return bool
417
  */
449
  /**
450
  * Log an error while calling the Google Analytics API
451
  *
452
+ * @param string $error
453
  */
454
  private function log_error( $error ) {
455
  if ( true == WP_DEBUG ) {
admin/pages/settings.php CHANGED
@@ -66,7 +66,7 @@ echo Yoast_GA_Admin_Form::create_form( 'settings' );
66
  echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, null );
67
 
68
  echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle-submit">&nbsp;</label>';
69
- echo '<div class="ga-form ga-form-input"><input type="submit" name="ga-form-settings" value="' . __('Save authentication code', 'google-analytics-for-wordpress') . '" class="button button-primary ga-form-submit" id="yoast-ga-form-submit-settings"></div>';
70
  echo '</div>';
71
  } else {
72
  echo '<h3>' . __( 'Cannot connect to Google', 'google-analytics-for-wordpress' ) . '</h3>';
@@ -101,6 +101,7 @@ echo Yoast_GA_Admin_Form::create_form( 'settings' );
101
  echo '<h2>' . __( 'Universal settings', 'google-analytics-for-wordpress' ) . '</h2>';
102
  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. 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>' ) );
103
  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 knowledge base article in our %1$sknowledge 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&amp;utm_source=gawp-config&amp;utm_campaign=wpgaplugin" target="_blank">', '</a>' ) );
 
104
  ?>
105
  </div>
106
  <div id="advanced" class="gatab">
@@ -142,7 +143,7 @@ echo Yoast_GA_Admin_Form::create_form( 'settings' );
142
  </div>
143
  </div>
144
  <?php
145
- echo Yoast_GA_Admin_Form::end_form( 'Save changes', 'settings' );
146
  echo $yoast_ga_admin->content_footer();
147
  ?>
148
  <script type="text/javascript">
66
  echo Yoast_GA_Admin_Form::input( 'text', null, 'google_auth_code', null, null );
67
 
68
  echo '<label class="ga-form ga-form-text-label ga-form-label-left" id="yoast-ga-form-label-text-ga-authwithgoogle-submit">&nbsp;</label>';
69
+ echo '<div class="ga-form ga-form-input"><input type="submit" name="ga-form-settings" value="' . __('Save authentication code', 'google-analytics-for-wordpress') . '" class="button button-primary ga-form-submit" id="yoast-ga-form-submit-settings" onclick="yst_closepopupwindow();"></div>';
70
  echo '</div>';
71
  } else {
72
  echo '<h3>' . __( 'Cannot connect to Google', 'google-analytics-for-wordpress' ) . '</h3>';
101
  echo '<h2>' . __( 'Universal settings', 'google-analytics-for-wordpress' ) . '</h2>';
102
  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. 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>' ) );
103
  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 knowledge base article in our %1$sknowledge 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&amp;utm_source=gawp-config&amp;utm_campaign=wpgaplugin" target="_blank">', '</a>' ) );
104
+ echo Yoast_GA_Admin_Form::input( 'checkbox', __( 'Enhanced Link Attribution', 'google-analytics-for-wordpress' ), 'enhanced_link_attribution', null, sprintf( __( 'Add %1$sEnhanced Link Attribution%2$s to your tracking code.', 'google-analytics-for-wordpress' ), '<a href="https://support.google.com/analytics/answer/2558867" target="_blank">', ' </a>' ) );
105
  ?>
106
  </div>
107
  <div id="advanced" class="gatab">
143
  </div>
144
  </div>
145
  <?php
146
+ echo Yoast_GA_Admin_Form::end_form( 'Save changes', 'settings', 'yst_closepopupwindow();' );
147
  echo $yoast_ga_admin->content_footer();
148
  ?>
149
  <script type="text/javascript">
assets/js/yoast_ga_admin.js CHANGED
@@ -1,8 +1,14 @@
 
 
1
  function yst_popupwindow(url, w, h) {
2
  'use strict';
3
  var left = (screen.width/2)-(w/2);
4
  var top = (screen.height/8);
5
- 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);
 
 
 
 
6
  }
7
 
8
  function yst_ga_switch_manual() {
1
+ var authwindow;
2
+
3
  function yst_popupwindow(url, w, h) {
4
  'use strict';
5
  var left = (screen.width/2)-(w/2);
6
  var top = (screen.height/8);
7
+ authwindow = window.open(url, 'yst_ga_auth_window', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
8
+ }
9
+
10
+ function yst_closepopupwindow() {
11
+ authwindow.close();
12
  }
13
 
14
  function yst_ga_switch_manual() {
assets/js/yoast_ga_admin.min.js CHANGED
@@ -1 +1 @@
1
- function yst_popupwindow(a,b,c){"use strict";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)}function yst_ga_switch_manual(){if(jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").is(":checked")){var a=!0;jQuery("#enter_ua").show(),jQuery("#oauth_code").hide()}else{var a=!1;jQuery("#enter_ua").hide(),jQuery("#yoast-ga-form-text-settings-manual_ua_code_field").attr("value",""),jQuery("#oauth_code").hide()}jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",a).trigger("chosen:updated"),jQuery("#yst_ga_authenticate").attr("disabled",a)}jQuery(document).ready(function(){"use strict";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 a=window.location.hash.replace("#top#","");(""===a||"#_=_"===a)&&(a=jQuery(".gatab").attr("id")),jQuery("#"+a).addClass("active"),jQuery("#"+a+"-tab").addClass("nav-tab-active"),jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").click(yst_ga_switch_manual),yst_ga_switch_manual(),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"}})});
1
+ function yst_popupwindow(e,t,n){"use strict";var r=screen.width/2-t/2;var i=screen.height/8;authwindow=window.open(e,"yst_ga_auth_window","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width="+t+", height="+n+", top="+i+", left="+r)}function yst_closepopupwindow(){authwindow.close()}function yst_ga_switch_manual(){if(jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").is(":checked")){var e=true;jQuery("#enter_ua").show();jQuery("#oauth_code").hide()}else{var e=false;jQuery("#enter_ua").hide();jQuery("#yoast-ga-form-text-settings-manual_ua_code_field").attr("value","");jQuery("#oauth_code").hide()}jQuery("#yoast-ga-form-select-settings-analytics_profile").prop("disabled",e).trigger("chosen:updated");jQuery("#yst_ga_authenticate").attr("disabled",e)}var authwindow;jQuery(document).ready(function(){"use strict";jQuery("#ga-tabs").find("a").click(function(){jQuery("#ga-tabs").find("a").removeClass("nav-tab-active");jQuery(".gatab").removeClass("active");var e=jQuery(this).attr("id").replace("-tab","");jQuery("#"+e).addClass("active");jQuery(this).addClass("nav-tab-active");jQuery("#return_tab").val(e)});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 e=window.location.hash.replace("#top#","");if(e===""||e==="#_=_"){e=jQuery(".gatab").attr("id")}jQuery("#"+e).addClass("active");jQuery("#"+e+"-tab").addClass("nav-tab-active");jQuery("#yoast-ga-form-checkbox-settings-manual_ua_code").click(yst_ga_switch_manual);yst_ga_switch_manual();jQuery("#oauth_code").hide();jQuery("#yst_ga_authenticate").click(function(){jQuery("#oauth_code").show();Focusable.setFocus(jQuery("#oauth_code"),{hideOnESC:true});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:true,when:{event:"mouseout"}},style:{tip:"bottomLeft",name:"blue"}})})
frontend/abstract-class-tracking.php CHANGED
@@ -15,7 +15,7 @@ abstract class Yoast_GA_Tracking {
15
  * Storage for the currently set options
16
  * @var mixed|void
17
  */
18
- protected $options;
19
 
20
  /**
21
  * Should the tracking code be added
@@ -46,8 +46,8 @@ abstract class Yoast_GA_Tracking {
46
  * Class constructor
47
  */
48
  public function __construct() {
49
-
50
- $this->options = Yoast_GA_Options::instance()->options;
51
 
52
  add_action( 'wp_head', array( $this, 'tracking' ), 8 );
53
 
@@ -56,13 +56,31 @@ abstract class Yoast_GA_Tracking {
56
  }
57
  }
58
 
 
 
 
 
 
 
 
 
 
59
  /**
60
  * Delegates `get_tracking_code` to the options class
61
  *
62
  * @return null
63
  */
64
  public function get_tracking_code() {
65
- return Yoast_GA_Options::instance()->get_tracking_code();
 
 
 
 
 
 
 
 
 
66
  }
67
 
68
  /**
15
  * Storage for the currently set options
16
  * @var mixed|void
17
  */
18
+ public $options;
19
 
20
  /**
21
  * Should the tracking code be added
46
  * Class constructor
47
  */
48
  public function __construct() {
49
+ $options_class = $this->get_options_class();
50
+ $this->options = $options_class->options;
51
 
52
  add_action( 'wp_head', array( $this, 'tracking' ), 8 );
53
 
56
  }
57
  }
58
 
59
+ /**
60
+ * Get the options class
61
+ *
62
+ * @return object|Yoast_GA_Options
63
+ */
64
+ protected function get_options_class() {
65
+ return Yoast_GA_Options::instance();
66
+ }
67
+
68
  /**
69
  * Delegates `get_tracking_code` to the options class
70
  *
71
  * @return null
72
  */
73
  public function get_tracking_code() {
74
+ return $this->get_options_class()->get_tracking_code();
75
+ }
76
+
77
+ /**
78
+ * Get 1 or 0 if we need to do enhanced link attribution
79
+ *
80
+ * @return mixed
81
+ */
82
+ public function get_enhanced_link_attribution() {
83
+ return $this->options['enhanced_link_attribution'];
84
  }
85
 
86
  /**
frontend/class-universal.php CHANGED
@@ -5,6 +5,13 @@
5
  */
6
  class Yoast_GA_Universal extends Yoast_GA_Tracking {
7
 
 
 
 
 
 
 
 
8
  /**
9
  * Function to output the GA Tracking code in the wp_head()
10
  */
@@ -69,8 +76,9 @@ class Yoast_GA_Universal extends Yoast_GA_Tracking {
69
  $gaq_push[] = "'require', 'displayfeatures'";
70
  }
71
 
72
- if ( isset( $this->options['allowhash'] ) && $this->options['allowhash'] ) {
73
- $gaq_push[] = "'_setAllowHash',false";
 
74
  }
75
 
76
  if ( is_404() ) {
@@ -155,7 +163,7 @@ class Yoast_GA_Universal extends Yoast_GA_Tracking {
155
  case 'internal-as-outbound':
156
  $label = $this->sanitize_internal_label();
157
 
158
- $onclick = "__gaTracker('send', 'event', '" . esc_attr( $link['category'] ) . '-' . esc_attr( $label ) . "', '" . esc_attr( $full_url ) . "', '" . esc_attr( strip_tags( $link['link_text'] ) ) . "');";
159
 
160
  break;
161
  case 'outbound':
@@ -168,8 +176,11 @@ class Yoast_GA_Universal extends Yoast_GA_Tracking {
168
 
169
  $link['link_attributes'] = $this->output_add_onclick( $link['link_attributes'], $onclick );
170
 
171
- return '<a href="' . $full_url . '" ' . $link['link_attributes'] . '>' . $link['link_text'] . '</a>';
 
 
172
 
 
173
  }
174
 
175
  }
5
  */
6
  class Yoast_GA_Universal extends Yoast_GA_Tracking {
7
 
8
+ /**
9
+ * Test helper function
10
+ */
11
+ public function get_options(){
12
+ return $this->options;
13
+ }
14
+
15
  /**
16
  * Function to output the GA Tracking code in the wp_head()
17
  */
76
  $gaq_push[] = "'require', 'displayfeatures'";
77
  }
78
 
79
+ // Check for Enhanced link attribution
80
+ if ( $this->get_enhanced_link_attribution() == 1 ) {
81
+ $gaq_push[] = "'require', 'linkid', 'linkid.js'";
82
  }
83
 
84
  if ( is_404() ) {
163
  case 'internal-as-outbound':
164
  $label = $this->sanitize_internal_label();
165
 
166
+ $onclick = "__gaTracker('send', '" . $this->options['track_download_as'] . "', '" . esc_attr( $link['category'] ) . '-' . esc_attr( $label ) . "', '" . esc_attr( $full_url ) . "', '" . esc_attr( strip_tags( $link['link_text'] ) ) . "');";
167
 
168
  break;
169
  case 'outbound':
176
 
177
  $link['link_attributes'] = $this->output_add_onclick( $link['link_attributes'], $onclick );
178
 
179
+ if( !empty( $link['link_attributes'] ) ) {
180
+ return '<a href="' . $full_url . '" ' . trim( $link['link_attributes'] ) . '>' . $link['link_text'] . '</a>';
181
+ }
182
 
183
+ return '<a href="' . $full_url . '">' . $link['link_text'] . '</a>';
184
  }
185
 
186
  }
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 site, adding lots of features, e.g. error page, search result and automatic outgoing links and download tracking.
6
  Author: Team Yoast
7
- Version: 5.3
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.3' );
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 site, adding lots of features, e.g. error page, search result and automatic outgoing links and download tracking.
6
  Author: Team Yoast
7
+ Version: 5.3.1
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.3.1' );
34
 
35
  define( 'GAWP_FILE', __FILE__ );
36
 
includes/class-options.php CHANGED
@@ -219,9 +219,11 @@ class Yoast_GA_Options {
219
  }
220
  // Fallback to make sure every default option has a value
221
  $defaults = $this->default_ga_values();
222
- foreach ( $defaults[$this->option_prefix] as $key => $value ) {
223
- if ( ! isset( $this->options[$key] ) ) {
224
- $this->options[$key] = $value;
 
 
225
  }
226
  }
227
  // Set to the current version now that we've done all needed upgrades
@@ -256,11 +258,13 @@ class Yoast_GA_Options {
256
  'tag_links_in_rss' => 0,
257
  'allow_anchor' => 0,
258
  'add_allow_linker' => 0,
 
259
  'custom_code' => null,
260
  'debug_mode' => 0,
261
  )
262
  );
263
  $options = apply_filters( 'yst_ga_default-ga-values', $options, $this->option_prefix );
 
264
  return $options;
265
  }
266
 
219
  }
220
  // Fallback to make sure every default option has a value
221
  $defaults = $this->default_ga_values();
222
+ if ( is_array( $defaults ) ) {
223
+ foreach ( $defaults[$this->option_prefix] as $key => $value ) {
224
+ if ( ! isset( $this->options[$key] ) ) {
225
+ $this->options[$key] = $value;
226
+ }
227
  }
228
  }
229
  // Set to the current version now that we've done all needed upgrades
258
  'tag_links_in_rss' => 0,
259
  'allow_anchor' => 0,
260
  'add_allow_linker' => 0,
261
+ 'enhanced_link_attribution' => 0,
262
  'custom_code' => null,
263
  'debug_mode' => 0,
264
  )
265
  );
266
  $options = apply_filters( 'yst_ga_default-ga-values', $options, $this->option_prefix );
267
+
268
  return $options;
269
  }
270
 
languages/google-analytics-for-wordpress-da_DK.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-en_GB.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-es_MX.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-fi.mo DELETED
Binary file
languages/google-analytics-for-wordpress-fr_FR.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-he_IL.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-it_IT.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-nb_NO.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-nl_NL.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-pl_PL.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-pt_BR.mo CHANGED
Binary file
languages/google-analytics-for-wordpress-ru_RU.mo CHANGED
Binary file
languages/google-analytics-for-wordpress.pot CHANGED
@@ -5,7 +5,7 @@ msgstr ""
5
  "Project-Id-Version: Google Analytics by Yoast 5.3\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://github.com/yoast/google-analytics-for-wordpress/issues\n"
8
- "POT-Creation-Date: 2015-01-27 12:07:54+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
5
  "Project-Id-Version: Google Analytics by Yoast 5.3\n"
6
  "Report-Msgid-Bugs-To: "
7
  "https://github.com/yoast/google-analytics-for-wordpress/issues\n"
8
+ "POT-Creation-Date: 2015-02-09 10:47:19+00:00\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=utf-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
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.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,6 +49,20 @@ This section describes how to install the plugin and get it working.
49
 
50
  == Changelog ==
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  = 5.3 =
53
 
54
  Release Date: January 27th, 2015
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.3.1
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.3.1 =
53
+
54
+ Release Date: February 11th, 2015
55
+
56
+ * Enhancements:
57
+ * Added a filter (`yst-ga-filter-api-end-date`) to enable our [premium plugin](https://yoast.com/wordpress/plugins/google-analytics/) to show more recent data in the dashboards.
58
+
59
+ * Features:
60
+ * Added [Enhanced link attribution](https://support.google.com/analytics/answer/2558867) for Universal tracking.
61
+
62
+ * Bugfixes
63
+ * [Fixes a bug](https://github.com/markoheijnen/grunt-glotpress/pull/14) in the grunt task we use for downloading translations from GlotPress, which caused the translations to no longer be loaded.
64
+ * Fixes a bug where the links to our submenu pages were broken in case of a locale other than `en_US` being set.
65
+
66
  = 5.3 =
67
 
68
  Release Date: January 27th, 2015