Google Analytics Dashboard for WP (GADWP) - Version 5.1.1

Version Description

  • New Features:
    • adds non-interaction hit support for AMP
  • Enhancements:
    • automatically annotates all AMP HTML elements with the appropriate data when DOM and libxml PHP extension are available
    • renames the access code POST variable
    • exclude scroll page depth events from bounce rate calculation
  • Bug Fixes:
    • fixes the switch between metrics on Location report
    • fixes PHP notices on empty reports
Download this release

Release Info

Developer deconf
Plugin Icon 128x128 Google Analytics Dashboard for WP (GADWP)
Version 5.1.1
Comparing to
See all releases

Code changes from version 5.1 to 5.1.1

admin/item-reports.php CHANGED
@@ -43,7 +43,7 @@ if ( ! class_exists( 'GADWP_Backend_Item_Reports' ) ) {
43
  }
44
 
45
  if ( version_compare( $wp_version, '3.8.0', '>=' ) ) {
46
- echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '" class="gadwp-icon dashicons-before dashicons-chart-area"></a>';
47
  } else {
48
  echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '"><img class="gadwp-icon-oldwp" src="' . GADWP_URL . 'admin/images/gadash-icon.png"</a>';
49
  }
43
  }
44
 
45
  if ( version_compare( $wp_version, '3.8.0', '>=' ) ) {
46
+ echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '" class="gadwp-icon dashicons-before dashicons-chart-area">&nbsp;</a>';
47
  } else {
48
  echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '"><img class="gadwp-icon-oldwp" src="' . GADWP_URL . 'admin/images/gadash-icon.png"</a>';
49
  }
admin/settings.php CHANGED
@@ -742,7 +742,7 @@ final class GADWP_Settings {
742
  <div class="gadwp-settings-switchoo-switch"></div>
743
  </label>
744
  </div>
745
- <div class="switch-desc"><?php echo " ".__("exclude events from bounce-rate calculation", 'google-analytics-dashboard-for-wp' );?></div>
746
  </td>
747
  </tr>
748
  <tr>
@@ -1081,10 +1081,10 @@ final class GADWP_Settings {
1081
  $gadwp->gapi_controller = new GADWP_GAPI_Controller();
1082
  }
1083
  echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
1084
- if ( isset( $_POST['ga_dash_code'] ) ) {
1085
- if ( 1 == ! stripos( 'x' . $_POST['ga_dash_code'], 'UA-', 1 ) ) {
1086
  try {
1087
- $gadwp->gapi_controller->client->authenticate( $_POST['ga_dash_code'] );
1088
  $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
1089
  $gadwp->config->options['automatic_updates_minorversion'] = 1;
1090
  $gadwp->config->set_plugin_options();
@@ -1368,10 +1368,10 @@ final class GADWP_Settings {
1368
  }
1369
 
1370
  echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
1371
- if ( isset( $_POST['ga_dash_code'] ) ) {
1372
- if ( 1 == ! stripos( 'x' . $_POST['ga_dash_code'], 'UA-', 1 ) ) {
1373
  try {
1374
- $gadwp->gapi_controller->client->authenticate( $_POST['ga_dash_code'] );
1375
  $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
1376
  $gadwp->config->options['automatic_updates_minorversion'] = 1;
1377
  $gadwp->config->set_plugin_options( true );
742
  <div class="gadwp-settings-switchoo-switch"></div>
743
  </label>
744
  </div>
745
+ <div class="switch-desc"><?php echo " ".__("exclude events from bounce-rate and time on page calculation", 'google-analytics-dashboard-for-wp' );?></div>
746
  </td>
747
  </tr>
748
  <tr>
1081
  $gadwp->gapi_controller = new GADWP_GAPI_Controller();
1082
  }
1083
  echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
1084
+ if ( isset( $_POST['gadwp_access_code'] ) ) {
1085
+ if ( 1 == ! stripos( 'x' . $_POST['gadwp_access_code'], 'UA-', 1 ) ) {
1086
  try {
1087
+ $gadwp->gapi_controller->client->authenticate( $_POST['gadwp_access_code'] );
1088
  $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
1089
  $gadwp->config->options['automatic_updates_minorversion'] = 1;
1090
  $gadwp->config->set_plugin_options();
1368
  }
1369
 
1370
  echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
1371
+ if ( isset( $_POST['gadwp_access_code'] ) ) {
1372
+ if ( 1 == ! stripos( 'x' . $_POST['gadwp_access_code'], 'UA-', 1 ) ) {
1373
  try {
1374
+ $gadwp->gapi_controller->client->authenticate( $_POST['gadwp_access_code'] );
1375
  $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
1376
  $gadwp->config->options['automatic_updates_minorversion'] = 1;
1377
  $gadwp->config->set_plugin_options( true );
admin/views/access-code.php CHANGED
@@ -16,10 +16,10 @@
16
  </tr>
17
  <tr>
18
  <td class="gadwp-settings-title">
19
- <label for="ga_dash_code" title="<?php _e("Use the red link to get your access code!",'google-analytics-dashboard-for-wp')?>"><?php echo _e( "Access Code:", 'google-analytics-dashboard-for-wp' ); ?></label>
20
  </td>
21
  <td>
22
- <input type="text" id="ga_dash_code" name="ga_dash_code" value="" size="61" required="required" title="<?php _e("Use the red link to get your access code!",'google-analytics-dashboard-for-wp')?>">
23
  </td>
24
  </tr>
25
  <tr>
16
  </tr>
17
  <tr>
18
  <td class="gadwp-settings-title">
19
+ <label for="gadwp_access_code" title="<?php _e("Use the red link to get your access code!",'google-analytics-dashboard-for-wp')?>"><?php echo _e( "Access Code:", 'google-analytics-dashboard-for-wp' ); ?></label>
20
  </td>
21
  <td>
22
+ <input type="text" id="gadwp_access_code" name="gadwp_access_code" value="" size="61" required="required" title="<?php _e("Use the red link to get your access code!",'google-analytics-dashboard-for-wp')?>">
23
  </td>
24
  </tr>
25
  <tr>
config.php CHANGED
@@ -91,7 +91,7 @@ if ( ! class_exists( 'GADWP_Config' ) ) {
91
  'tm_pagescrolldepth_tracking',
92
  'ga_speed_samplerate',
93
  'ga_user_samplerate',
94
- );
95
  foreach ( $numerics as $key ) {
96
  if ( isset( $options[$key] ) ) {
97
  $options[$key] = (int) $options[$key];
@@ -114,7 +114,7 @@ if ( ! class_exists( 'GADWP_Config' ) ) {
114
  'ga_event_affiliates',
115
  'ecommerce_mode',
116
  'ga_dash_tracking_type',
117
- );
118
  foreach ( $texts as $key ) {
119
  if ( isset( $options[$key] ) ) {
120
  $options[$key] = trim (sanitize_text_field( $options[$key] ));
@@ -244,9 +244,9 @@ if ( ! class_exists( 'GADWP_Config' ) ) {
244
  } else {
245
  GADWP_Tools::delete_cache( 'gapi_errors' );
246
  }
247
- GADWP_Tools::unset_cookie( 'default_metric' );
248
- GADWP_Tools::unset_cookie( 'default_dimension' );
249
- GADWP_Tools::unset_cookie( 'default_view' );
250
  }
251
 
252
  /* @formatter:off */
@@ -282,7 +282,7 @@ if ( ! class_exists( 'GADWP_Config' ) ) {
282
  'ga_dash_excludesa', //v5.0
283
  'ga_pagescrolldepth_tracking', //v5.0
284
  'tm_pagescrolldepth_tracking', //v5.0
285
- );
286
  foreach ( $zeros as $key ) {
287
  if ( ! isset( $this->options[$key] ) ) {
288
  $this->options[$key] = 0;
91
  'tm_pagescrolldepth_tracking',
92
  'ga_speed_samplerate',
93
  'ga_user_samplerate',
94
+ );
95
  foreach ( $numerics as $key ) {
96
  if ( isset( $options[$key] ) ) {
97
  $options[$key] = (int) $options[$key];
114
  'ga_event_affiliates',
115
  'ecommerce_mode',
116
  'ga_dash_tracking_type',
117
+ );
118
  foreach ( $texts as $key ) {
119
  if ( isset( $options[$key] ) ) {
120
  $options[$key] = trim (sanitize_text_field( $options[$key] ));
244
  } else {
245
  GADWP_Tools::delete_cache( 'gapi_errors' );
246
  }
247
+ // GADWP_Tools::unset_cookie( 'default_metric' );
248
+ // GADWP_Tools::unset_cookie( 'default_dimension' );
249
+ // GADWP_Tools::unset_cookie( 'default_view' );
250
  }
251
 
252
  /* @formatter:off */
282
  'ga_dash_excludesa', //v5.0
283
  'ga_pagescrolldepth_tracking', //v5.0
284
  'tm_pagescrolldepth_tracking', //v5.0
285
+ );
286
  foreach ( $zeros as $key ) {
287
  if ( ! isset( $this->options[$key] ) ) {
288
  $this->options[$key] = 0;
front/js/tracking-analytics-events.js CHANGED
@@ -1 +1 @@
1
- "use strict";var gadwpRedirectLink;var gadwpRedirectCalled=false;var gadwpDefaultPrevented=false;function gadwpRedirect(){if(gadwpRedirectCalled){return}gadwpRedirectCalled=true;if(!gadwpDefaultPrevented){document.location.href=gadwpRedirectLink}else{gadwpDefaultPrevented=false}}jQuery(window).on("load",function(){if(gadwpUAEventsData.options.event_tracking){jQuery("a").filter(function(){var a=new RegExp(".*\\.("+gadwpUAEventsData.options.event_downloads+")(\\?.*)?$");return this.href.match(a)}).click(function(d){var b=this.getAttribute("data-vars-ga-category")||"download";var c=this.getAttribute("data-vars-ga-action")||"click";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}});jQuery('a[href^="mailto"]').click(function(d){var b=this.getAttribute("data-vars-ga-category")||"email";var c=this.getAttribute("data-vars-ga-action")||"send";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}});jQuery('a[href^="tel"]').click(function(d){if(gadwpUAEventsData.options.event_bouncerate){var b=this.getAttribute("data-vars-ga-category")||"telephone";var c=this.getAttribute("data-vars-ga-action")||"call";var a=this.getAttribute("data-vars-ga-label")||this.href;ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}});if(gadwpUAEventsData.options.root_domain){jQuery('a[href^="http"]').filter(function(){var a=new RegExp(".*\\.("+gadwpUAEventsData.options.event_downloads+")(\\?.*)?$");if(!this.href.match(a)){if(this.href.indexOf(gadwpUAEventsData.options.root_domain)==-1){return this.href}}}).click(function(d){gadwpRedirectCalled=false;gadwpRedirectLink=this.href;var b=this.getAttribute("data-vars-ga-category")||"outbound";var c=this.getAttribute("data-vars-ga-action")||"click";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,c,a,{nonInteraction:1,hitCallback:gadwpRedirect})}else{ga("send","event",b,c,a,{hitCallback:gadwpRedirect})}if(this.target!="_blank"){if(d.isDefaultPrevented()){gadwpDefaultPrevented=true}setTimeout(gadwpRedirect,gadwpUAEventsData.options.event_timeout);return false}else{gadwpRedirectCalled=true}})}}if(gadwpUAEventsData.options.event_affiliates&&gadwpUAEventsData.options.aff_tracking){jQuery("a").filter(function(){if(gadwpUAEventsData.options.event_affiliates!=""){var a=new RegExp("("+gadwpUAEventsData.options.event_affiliates.replace(/\//g,"/")+")");return this.href.match(a)}}).click(function(c){gadwpRedirectCalled=false;gadwpRedirectLink=this.href;var b=this.getAttribute("data-vars-ga-category")||"affiliates";var d=this.getAttribute("data-vars-ga-action")||"click";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,d,a,{nonInteraction:1,hitCallback:gadwpRedirect})}else{ga("send","event",b,d,a,{hitCallback:gadwpRedirect})}if(this.target!="_blank"){if(e.isDefaultPrevented()){gadwpDefaultPrevented=true}setTimeout(gadwpRedirect,gadwpUAEventsData.options.event_timeout);return false}else{gadwpRedirectCalled=true}})}if(gadwpUAEventsData.options.root_domain&&gadwpUAEventsData.options.hash_tracking){jQuery("a").filter(function(){if(this.href.indexOf(gadwpUAEventsData.options.root_domain)!=-1||this.href.indexOf("://")==-1){return this.hash}}).click(function(d){var b=this.getAttribute("data-vars-ga-category")||"hashmark";var c=this.getAttribute("data-vars-ga-action")||"click";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}})}if(gadwpUAEventsData.options.event_formsubmit){jQuery('input[type="submit"]').click(function(f){var d=this;var b=d.getAttribute("data-vars-ga-category")||"form";var c=d.getAttribute("data-vars-ga-action")||"submit";var a=d.getAttribute("data-vars-ga-label")||d.name||d.value;if(gadwpUAEventsData.options.event_formsubmit){ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}})}if(gadwpUAEventsData.options.ga_pagescrolldepth_tracking){jQuery.scrollDepth({percentage:true,userTiming:false,pixelDepth:false,gtmOverride:true,nonInteraction:gadwpUAEventsData.options.event_bouncerate})}});
1
+ "use strict";var gadwpRedirectLink;var gadwpRedirectCalled=false;var gadwpDefaultPrevented=false;function gadwpRedirect(){if(gadwpRedirectCalled){return}gadwpRedirectCalled=true;if(!gadwpDefaultPrevented){document.location.href=gadwpRedirectLink}else{gadwpDefaultPrevented=false}}jQuery(window).on("load",function(){if(gadwpUAEventsData.options.event_tracking){jQuery("a").filter(function(){var a=new RegExp(".*\\.("+gadwpUAEventsData.options.event_downloads+")(\\?.*)?$");return this.href.match(a)}).click(function(d){var b=this.getAttribute("data-vars-ga-category")||"download";var c=this.getAttribute("data-vars-ga-action")||"click";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}});jQuery('a[href^="mailto"]').click(function(d){var b=this.getAttribute("data-vars-ga-category")||"email";var c=this.getAttribute("data-vars-ga-action")||"send";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}});jQuery('a[href^="tel"]').click(function(d){if(gadwpUAEventsData.options.event_bouncerate){var b=this.getAttribute("data-vars-ga-category")||"telephone";var c=this.getAttribute("data-vars-ga-action")||"call";var a=this.getAttribute("data-vars-ga-label")||this.href;ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}});if(gadwpUAEventsData.options.root_domain){jQuery('a[href^="http"]').filter(function(){var a=new RegExp(".*\\.("+gadwpUAEventsData.options.event_downloads+")(\\?.*)?$");if(!this.href.match(a)){if(this.href.indexOf(gadwpUAEventsData.options.root_domain)==-1&&this.href.indexOf("://")>-1){return this.href}}}).click(function(d){gadwpRedirectCalled=false;gadwpRedirectLink=this.href;var b=this.getAttribute("data-vars-ga-category")||"outbound";var c=this.getAttribute("data-vars-ga-action")||"click";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,c,a,{nonInteraction:1,hitCallback:gadwpRedirect})}else{ga("send","event",b,c,a,{hitCallback:gadwpRedirect})}if(this.target!="_blank"){if(d.isDefaultPrevented()){gadwpDefaultPrevented=true}setTimeout(gadwpRedirect,gadwpUAEventsData.options.event_timeout);return false}else{gadwpRedirectCalled=true}})}}if(gadwpUAEventsData.options.event_affiliates&&gadwpUAEventsData.options.aff_tracking){jQuery("a").filter(function(){if(gadwpUAEventsData.options.event_affiliates!=""){var a=new RegExp("("+gadwpUAEventsData.options.event_affiliates.replace(/\//g,"/")+")");return this.href.match(a)}}).click(function(c){gadwpRedirectCalled=false;gadwpRedirectLink=this.href;var b=this.getAttribute("data-vars-ga-category")||"affiliates";var d=this.getAttribute("data-vars-ga-action")||"click";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,d,a,{nonInteraction:1,hitCallback:gadwpRedirect})}else{ga("send","event",b,d,a,{hitCallback:gadwpRedirect})}if(this.target!="_blank"){if(e.isDefaultPrevented()){gadwpDefaultPrevented=true}setTimeout(gadwpRedirect,gadwpUAEventsData.options.event_timeout);return false}else{gadwpRedirectCalled=true}})}if(gadwpUAEventsData.options.root_domain&&gadwpUAEventsData.options.hash_tracking){jQuery("a").filter(function(){if(this.href.indexOf(gadwpUAEventsData.options.root_domain)!=-1||this.href.indexOf("://")==-1){return this.hash}}).click(function(d){var b=this.getAttribute("data-vars-ga-category")||"hashmark";var c=this.getAttribute("data-vars-ga-action")||"click";var a=this.getAttribute("data-vars-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}})}if(gadwpUAEventsData.options.event_formsubmit){jQuery('input[type="submit"]').click(function(f){var d=this;var b=d.getAttribute("data-vars-ga-category")||"form";var c=d.getAttribute("data-vars-ga-action")||"submit";var a=d.getAttribute("data-vars-ga-label")||d.name||d.value;if(gadwpUAEventsData.options.event_formsubmit){ga("send","event",b,c,a,{nonInteraction:1})}else{ga("send","event",b,c,a)}})}if(gadwpUAEventsData.options.ga_pagescrolldepth_tracking){jQuery.scrollDepth({percentage:true,userTiming:false,pixelDepth:false,gtmOverride:true,nonInteraction:true})}});
front/tracking-analytics.php CHANGED
@@ -93,6 +93,17 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics_Base' ) ) {
93
 
94
  return $custom_dimensions;
95
  }
 
 
 
 
 
 
 
 
 
 
 
96
  }
97
  }
98
 
@@ -148,7 +159,7 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics' ) ) {
148
  * Styles & Scripts load
149
  */
150
  private function load_scripts() {
151
- if ( $this->gadwp->config->options['ga_event_tracking'] || $this->gadwp->config->options['ga_aff_tracking'] || $this->gadwp->config->options['ga_hash_tracking'] || $this->gadwp->config->options['ga_pagescrolldepth_tracking'] || $this->gadwp->config->options['ga_formsubmit_tracking'] ) {
152
 
153
  $root_domain = GADWP_Tools::get_root_domain();
154
 
@@ -358,6 +369,105 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics_AMP' ) ) {
358
 
359
  add_filter( 'amp_post_template_data', array( $this, 'load_scripts' ) );
360
  add_action( 'amp_post_template_footer', array( $this, 'output' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
  }
362
 
363
  /**
@@ -443,29 +553,15 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics_AMP' ) ) {
443
  ),
444
  );
445
  /* @formatter:on */
 
446
  }
447
 
448
- // Set downloads, outbound links, affiliate links, hashmarks, email, telephone events
449
- if ( $this->gadwp->config->options['ga_event_tracking'] ) {
450
  /* @formatter:off */
451
  $this->config['triggers']['gadwpEventTracking'] = array (
452
  'on' => 'click',
453
- 'selector' => 'a',
454
- 'request' => 'event',
455
- 'vars' => array(
456
- 'eventCategory' => '${gaCategory}',
457
- 'eventAction' => '${gaAction}',
458
- 'eventLabel' => '${gaLabel}',
459
- ),
460
- );
461
- /* @formatter:on */
462
- }
463
- // Set form submit event
464
- if ( $this->gadwp->config->options['ga_formsubmit_tracking'] ) {
465
- /* @formatter:off */
466
- $this->config['triggers']['gadwpFormSubmit'] = array (
467
- 'on' => 'click',
468
- 'selector' => 'input[type="submit"]',
469
  'request' => 'event',
470
  'vars' => array(
471
  'eventCategory' => '${gaCategory}',
@@ -474,8 +570,10 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics_AMP' ) ) {
474
  ),
475
  );
476
  /* @formatter:on */
 
 
 
477
  }
478
-
479
  do_action( 'gadwp_analytics_amp_config', $this );
480
  }
481
 
@@ -491,7 +589,7 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics_AMP' ) ) {
491
  $json = json_encode( $this->config, JSON_PRETTY_PRINT );
492
  }
493
 
494
- $json = str_replace( array( '"&#91;', '&#93;"' ), array( '[', ']' ), $json ); //make verticalBoundaries a JavaScript array
495
 
496
  $data = array( 'json' => $json );
497
 
93
 
94
  return $custom_dimensions;
95
  }
96
+
97
+ protected function is_event_tracking( $opt, $with_pagescrolldepth = true ) {
98
+ if ( $this->gadwp->config->options['ga_event_tracking'] || $this->gadwp->config->options['ga_aff_tracking'] || $this->gadwp->config->options['ga_hash_tracking'] || $this->gadwp->config->options['ga_formsubmit_tracking'] ) {
99
+ return true;
100
+ }
101
+
102
+ if ( $this->gadwp->config->options['ga_pagescrolldepth_tracking'] && $with_pagescrolldepth ) {
103
+ return true;
104
+ }
105
+ return false;
106
+ }
107
  }
108
  }
109
 
159
  * Styles & Scripts load
160
  */
161
  private function load_scripts() {
162
+ if ( $this->is_event_tracking( true ) ) {
163
 
164
  $root_domain = GADWP_Tools::get_root_domain();
165
 
369
 
370
  add_filter( 'amp_post_template_data', array( $this, 'load_scripts' ) );
371
  add_action( 'amp_post_template_footer', array( $this, 'output' ) );
372
+ add_filter( 'the_content', array( $this, 'add_data_attributes' ), 999, 1 );
373
+ }
374
+
375
+ private function get_link_event_data( $link ) {
376
+ if ( empty( $link ) ) {
377
+ return false;
378
+ }
379
+ if ( $this->gadwp->config->options['ga_event_tracking'] ) {
380
+ // on changes adjust the substr() length parameter
381
+ if ( substr( $link, 0, 7 ) === "mailto:" ) {
382
+ return array( 'email', 'send', $link );
383
+ }
384
+
385
+ // on changes adjust the substr() length parameter
386
+ if ( substr( $link, 0, 4 ) === "tel:" ) {
387
+ return array( 'telephone', 'call', $link );
388
+ }
389
+
390
+ // Add download data-vars
391
+ if ( $this->gadwp->config->options['ga_event_downloads'] && preg_match( '/.*\.(' . $this->gadwp->config->options['ga_event_downloads'] . ')(\?.*)?$/i', $link, $matches ) ) {
392
+ return array( 'download', 'click', $link );
393
+ }
394
+ }
395
+ if ( $this->gadwp->config->options['ga_hash_tracking'] ) {
396
+ // Add hashmark data-vars
397
+ $root_domain = GADWP_Tools::get_root_domain();
398
+ if ( $root_domain && ( strpos( $link, $root_domain ) > - 1 || strpos( $link, '://' ) === false ) && strpos( $link, '#' ) > - 1 ) {
399
+ return array( 'hashmark', 'click', $link );
400
+ }
401
+ }
402
+ if ( $this->gadwp->config->options['ga_aff_tracking'] ) {
403
+ // Add affiliate data-vars
404
+ if ( strpos( $link, $this->gadwp->config->options['ga_event_affiliates'] ) > - 1 ) {
405
+ return array( 'affiliates', 'click', $link );
406
+ }
407
+ }
408
+ if ( $this->gadwp->config->options['ga_event_tracking'] ) {
409
+ // Add outbound data-vars
410
+ $root_domain = GADWP_Tools::get_root_domain();
411
+ if ( $root_domain && strpos( $link, $root_domain ) === false && strpos( $link, '://' ) > - 1 ) {
412
+ return array( 'outbound', 'click', $link );
413
+ }
414
+ }
415
+ return false;
416
+ }
417
+
418
+ public function add_data_attributes( $content ) {
419
+ if ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() && $this->is_event_tracking( false ) ) {
420
+
421
+ $dom = GADWP_Tools::get_dom_from_content( $content );
422
+
423
+ if ( $dom ) {
424
+
425
+ $links = $dom->getElementsByTagName( 'a' );
426
+
427
+ foreach ( $links as $item ) {
428
+
429
+ $data_attributes = $this->get_link_event_data( $item->getAttribute( 'href' ) );
430
+
431
+ if ( $data_attributes ) {
432
+ if ( ! $item->hasAttribute( 'data-vars-ga-category' ) ) {
433
+ $item->setAttribute( 'data-vars-ga-category', $data_attributes[0] );
434
+ }
435
+ if ( ! $item->hasAttribute( 'data-vars-ga-action' ) ) {
436
+ $item->setAttribute( 'data-vars-ga-action', $data_attributes[1] );
437
+ }
438
+ if ( ! $item->hasAttribute( 'data-vars-ga-label' ) ) {
439
+ $item->setAttribute( 'data-vars-ga-label', $data_attributes[2] );
440
+ }
441
+ }
442
+ }
443
+
444
+ if ( $this->gadwp->config->options['ga_formsubmit_tracking'] ) {
445
+ $form_submits = $dom->getElementsByTagName( 'input' );
446
+ foreach ( $form_submits as $item ) {
447
+ if ( $item->getAttribute( 'type' ) == 'submit' ) {
448
+ if ( ! $item->hasAttribute( 'data-vars-ga-category' ) ) {
449
+ $item->setAttribute( 'data-vars-ga-category', 'form' );
450
+ }
451
+ if ( ! $item->hasAttribute( 'data-vars-ga-action' ) ) {
452
+ $item->setAttribute( 'data-vars-ga-action', 'submit' );
453
+ }
454
+ if ( ! $item->hasAttribute( 'data-vars-ga-label' ) ) {
455
+ if ( $item->getAttribute( 'value' ) ) {
456
+ $label = $item->getAttribute( 'value' );
457
+ }
458
+ if ( $item->getAttribute( 'name' ) ) {
459
+ $label = $item->getAttribute( 'name' );
460
+ }
461
+ $item->setAttribute( 'data-vars-ga-label', $label );
462
+ }
463
+ }
464
+ }
465
+ }
466
+ return GADWP_Tools::get_content_from_dom( $dom );
467
+ }
468
+ }
469
+
470
+ return $content;
471
  }
472
 
473
  /**
553
  ),
554
  );
555
  /* @formatter:on */
556
+ $this->config['triggers']['gadwpScrollPings']['extraUrlParams'] = array( 'ni' => true );
557
  }
558
 
559
+ if ( $this->is_event_tracking( false ) ) {
560
+ // Set downloads, outbound links, affiliate links, hashmarks, e-mails, telephones, form submits events
561
  /* @formatter:off */
562
  $this->config['triggers']['gadwpEventTracking'] = array (
563
  'on' => 'click',
564
+ 'selector' => '[data-vars-ga-category][data-vars-ga-action][data-vars-ga-label]',
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
565
  'request' => 'event',
566
  'vars' => array(
567
  'eventCategory' => '${gaCategory}',
570
  ),
571
  );
572
  /* @formatter:on */
573
+ if ( $this->gadwp->config->options['ga_event_bouncerate'] ) {
574
+ $this->config['triggers']['gadwpEventTracking']['extraUrlParams'] = array( 'ni' => (bool) $this->gadwp->config->options['ga_event_bouncerate'] );
575
+ }
576
  }
 
577
  do_action( 'gadwp_analytics_amp_config', $this );
578
  }
579
 
589
  $json = json_encode( $this->config, JSON_PRETTY_PRINT );
590
  }
591
 
592
+ $json = str_replace( array( '"&#91;', '&#93;"' ), array( '[', ']' ), $json ); // make verticalBoundaries a JavaScript array
593
 
594
  $data = array( 'json' => $json );
595
 
gadwp.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin URI: https://deconf.com
5
  * Description: Displays Google Analytics Reports and Real-Time Statistics in your Dashboard. Automatically inserts the tracking code in every page of your website.
6
  * Author: Alin Marcu
7
- * Version: 5.1
8
  * Author URI: https://deconf.com
9
  * Text Domain: google-analytics-dashboard-for-wp
10
  * Domain Path: /languages
@@ -16,7 +16,7 @@ if ( ! defined( 'ABSPATH' ) )
16
 
17
  // Plugin Version
18
  if ( ! defined( 'GADWP_CURRENT_VERSION' ) ) {
19
- define( 'GADWP_CURRENT_VERSION', '5.1' );
20
  }
21
 
22
  if ( ! class_exists( 'GADWP_Manager' ) ) {
4
  * Plugin URI: https://deconf.com
5
  * Description: Displays Google Analytics Reports and Real-Time Statistics in your Dashboard. Automatically inserts the tracking code in every page of your website.
6
  * Author: Alin Marcu
7
+ * Version: 5.1.1
8
  * Author URI: https://deconf.com
9
  * Text Domain: google-analytics-dashboard-for-wp
10
  * Domain Path: /languages
16
 
17
  // Plugin Version
18
  if ( ! defined( 'GADWP_CURRENT_VERSION' ) ) {
19
+ define( 'GADWP_CURRENT_VERSION', '5.1.1' );
20
  }
21
 
22
  if ( ! class_exists( 'GADWP_Manager' ) ) {
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://deconf.com/donate/
4
  Tags: analytics,google analytics,google analytics dashboard,google analytics plugin,google analytics widget
5
  Requires at least: 3.5
6
  Tested up to: 4.8
7
- Stable tag: 5.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -60,6 +60,7 @@ Google Analytics Dashboard for WP enables you to easily track events like:
60
  - Fragment identifiers
61
  - Telephone
62
  - Page Scrolling Depth
 
63
 
64
  With Google Analytics Dashboard for WP you can use custom dimensions to track:
65
 
@@ -84,21 +85,17 @@ As an alternative to Google Analytics tracking code, you can use Google Tag Mana
84
 
85
  = Accelerated Mobile Pages (AMP) features =
86
 
87
- Out-of-the box features for AMP:
88
-
89
  - Google Tag Manager basic tracking
90
  - Google Analytics basic tracking
91
  - Automatically removes <em>amp/</em> from Google Analytics tracking page URL
92
  - Scrolling depth tracking
93
  - Custom dimensions tracking
94
  - User sampling rate control
95
-
96
- Events tracking for AMP using annotated HTML elements (data-vars-ga-* attributes):
97
-
98
- - form submit tracking
99
- - file downloads tracking
100
- - affiliate links tracking
101
- - hashmarks, outbound links, telephones and e-mails tracking
102
 
103
  = Google Analytics Dashboard for WP on Multisite =
104
 
@@ -170,6 +167,17 @@ This is a major update, please read the [release notes](https://deconf.com/googl
170
 
171
  == Changelog ==
172
 
 
 
 
 
 
 
 
 
 
 
 
173
  = 5.1 =
174
  * Bug Fixes:
175
  * if tracking is disabled it keeps it that way while upgrading from versions lower than 5.0
4
  Tags: analytics,google analytics,google analytics dashboard,google analytics plugin,google analytics widget
5
  Requires at least: 3.5
6
  Tested up to: 4.8
7
+ Stable tag: 5.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
60
  - Fragment identifiers
61
  - Telephone
62
  - Page Scrolling Depth
63
+ - Custom event categories, actions and labels using annotated HTML elements
64
 
65
  With Google Analytics Dashboard for WP you can use custom dimensions to track:
66
 
85
 
86
  = Accelerated Mobile Pages (AMP) features =
87
 
 
 
88
  - Google Tag Manager basic tracking
89
  - Google Analytics basic tracking
90
  - Automatically removes <em>amp/</em> from Google Analytics tracking page URL
91
  - Scrolling depth tracking
92
  - Custom dimensions tracking
93
  - User sampling rate control
94
+ - Form submit tracking
95
+ - File downloads tracking
96
+ - Affiliate links tracking
97
+ - Hashmarks, outbound links, telephones and e-mails tracking
98
+ - Custom event categories, actions and labels using annotated HTML elements
 
 
99
 
100
  = Google Analytics Dashboard for WP on Multisite =
101
 
167
 
168
  == Changelog ==
169
 
170
+ = 5.1.1 =
171
+ * New Features:
172
+ * adds non-interaction hit support for AMP
173
+ * Enhancements:
174
+ * automatically annotates all AMP HTML elements with the appropriate data when DOM and libxml PHP extension are available
175
+ * renames the access code POST variable
176
+ * exclude scroll page depth events from bounce rate calculation
177
+ * Bug Fixes:
178
+ * fixes the switch between metrics on Location report
179
+ * fixes PHP notices on empty reports
180
+
181
  = 5.1 =
182
  * Bug Fixes:
183
  * if tracking is disabled it keeps it that way while upgrading from versions lower than 5.0
tools/gapi.php CHANGED
@@ -288,7 +288,6 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
288
  } else {
289
  $data->rows = array();
290
  return $data;
291
- // return - 21;
292
  }
293
  }
294
 
@@ -359,6 +358,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
359
  return $data;
360
  }
361
  if ( empty( $data->rows ) ) {
 
362
  return - 21;
363
  }
364
  $gadwp_data = array( array( $dayorhour, $title ) );
@@ -413,11 +413,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
413
  $serial = 'qr3_' . $this->get_serial( $projectId . $from . $filter );
414
  $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
415
  if ( is_numeric( $data ) ) {
416
- if ( - 21 == $data or empty( $data->rows ) ) {
417
- return array_fill( 0, 9, 0 );
418
- } else {
419
- return $data;
420
- }
421
  }
422
  $gadwp_data = array();
423
  foreach ( $data->getRows() as $row ) {
@@ -425,25 +421,25 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
425
  }
426
 
427
  // i18n support
428
- $gadwp_data[0] = number_format_i18n( $gadwp_data[0] );
429
- $gadwp_data[1] = number_format_i18n( $gadwp_data[1] );
430
- $gadwp_data[2] = number_format_i18n( $gadwp_data[2] );
431
- $gadwp_data[3] = number_format_i18n( $gadwp_data[3], 2 ) . '%';
432
- $gadwp_data[4] = number_format_i18n( $gadwp_data[4] );
433
- $gadwp_data[5] = number_format_i18n( $gadwp_data[5], 2 );
434
- $gadwp_data[6] = gmdate( "H:i:s", $gadwp_data[6] );
435
- $gadwp_data[7] = number_format_i18n( $gadwp_data[7], 2 );
436
  if ( $filter ) {
437
- $gadwp_data[8] = number_format_i18n( $gadwp_data[8], 2 ) . '%';
438
  } else {
439
- $gadwp_data[8] = gmdate( "H:i:s", $gadwp_data[8] );
440
  }
441
 
442
  return $gadwp_data;
443
  }
444
 
445
  /**
446
- * Analytics data for Org Charts & Table Charts (content pages)
447
  *
448
  * @param
449
  * $projectId
@@ -505,7 +501,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
505
  }
506
 
507
  /**
508
- * Analytics data for Org Charts & Table Charts (referrers)
509
  *
510
  * @param
511
  * $projectId
@@ -539,7 +535,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
539
  }
540
 
541
  /**
542
- * Analytics data for Org Charts & Table Charts (searches)
543
  *
544
  * @param
545
  * $projectId
@@ -574,7 +570,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
574
  }
575
 
576
  /**
577
- * Analytics data for Org Charts & Table Charts (location reports)
578
  *
579
  * @param
580
  * $projectId
@@ -590,7 +586,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
590
  $metrics = 'ga:' . $metric;
591
  $options = "";
592
  $title = __( "Countries", 'google-analytics-dashboard-for-wp' );
593
- $serial = 'qr7_' . $this->get_serial( $projectId . $from . $filter );
594
  $dimensions = 'ga:country';
595
  $local_filter = '';
596
  if ( $this->gadwp->config->options['ga_target_geomap'] ) {
@@ -658,6 +654,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
658
  return $data;
659
  }
660
  if ( empty( $data->rows ) ) {
 
661
  return - 21;
662
  }
663
  $block = ( 'channelGrouping' == $query ) ? __( "Channels", 'google-analytics-dashboard-for-wp' ) : __( "Devices", 'google-analytics-dashboard-for-wp' );
288
  } else {
289
  $data->rows = array();
290
  return $data;
 
291
  }
292
  }
293
 
358
  return $data;
359
  }
360
  if ( empty( $data->rows ) ) {
361
+ // unable to render it as an Area Chart, returns a numeric value to be handled by reportsx.js
362
  return - 21;
363
  }
364
  $gadwp_data = array( array( $dayorhour, $title ) );
413
  $serial = 'qr3_' . $this->get_serial( $projectId . $from . $filter );
414
  $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
415
  if ( is_numeric( $data ) ) {
416
+ return $data;
 
 
 
 
417
  }
418
  $gadwp_data = array();
419
  foreach ( $data->getRows() as $row ) {
421
  }
422
 
423
  // i18n support
424
+ $gadwp_data[0] = isset( $gadwp_data[0] ) ? number_format_i18n( $gadwp_data[0] ) : 0;
425
+ $gadwp_data[1] = isset( $gadwp_data[1] ) ? number_format_i18n( $gadwp_data[1] ) : 0;
426
+ $gadwp_data[2] = isset( $gadwp_data[2] ) ? number_format_i18n( $gadwp_data[2] ) : 0;
427
+ $gadwp_data[3] = isset( $gadwp_data[3] ) ? number_format_i18n( $gadwp_data[3], 2 ) . '%' : '0%';
428
+ $gadwp_data[4] = isset( $gadwp_data[4] ) ? number_format_i18n( $gadwp_data[4] ) : 0;
429
+ $gadwp_data[5] = isset( $gadwp_data[5] ) ? number_format_i18n( $gadwp_data[5], 2 ) : 0;
430
+ $gadwp_data[6] = isset( $gadwp_data[6] ) ? gmdate( "H:i:s", $gadwp_data[6] ) : '00:00:00';
431
+ $gadwp_data[7] = isset( $gadwp_data[7] ) ? number_format_i18n( $gadwp_data[7], 2 ) : 0;
432
  if ( $filter ) {
433
+ $gadwp_data[8] = isset( $gadwp_data[8] ) ? number_format_i18n( $gadwp_data[8], 2 ) . '%' : '0%';
434
  } else {
435
+ $gadwp_data[8] = isset( $gadwp_data[8] ) ? gmdate( "H:i:s", $gadwp_data[8] ) : '00:00:00';
436
  }
437
 
438
  return $gadwp_data;
439
  }
440
 
441
  /**
442
+ * Analytics data for Table Charts (content pages)
443
  *
444
  * @param
445
  * $projectId
501
  }
502
 
503
  /**
504
+ * Analytics data for Table Charts (referrers)
505
  *
506
  * @param
507
  * $projectId
535
  }
536
 
537
  /**
538
+ * Analytics data for Table Charts (searches)
539
  *
540
  * @param
541
  * $projectId
570
  }
571
 
572
  /**
573
+ * Analytics data for Table Charts (location reports)
574
  *
575
  * @param
576
  * $projectId
586
  $metrics = 'ga:' . $metric;
587
  $options = "";
588
  $title = __( "Countries", 'google-analytics-dashboard-for-wp' );
589
+ $serial = 'qr7_' . $this->get_serial( $projectId . $from . $filter . $metric );
590
  $dimensions = 'ga:country';
591
  $local_filter = '';
592
  if ( $this->gadwp->config->options['ga_target_geomap'] ) {
654
  return $data;
655
  }
656
  if ( empty( $data->rows ) ) {
657
+ // unable to render as an Org Chart, returns a numeric value to be handled by reportsx.js
658
  return - 21;
659
  }
660
  $block = ( 'channelGrouping' == $query ) ? __( "Channels", 'google-analytics-dashboard-for-wp' ) : __( "Devices", 'google-analytics-dashboard-for-wp' );
tools/tools.php CHANGED
@@ -219,5 +219,31 @@ if ( ! class_exists( 'GADWP_Tools' ) ) {
219
  trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', 'google-analytics-dashboard-for-wp' ), $function, $message, $version ) );
220
  }
221
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
222
  }
223
  }
219
  trigger_error( sprintf( __( '%1$s was called <strong>incorrectly</strong>. %2$s %3$s', 'google-analytics-dashboard-for-wp' ), $function, $message, $version ) );
220
  }
221
  }
222
+
223
+ public static function get_dom_from_content( $content ) {
224
+ $libxml_previous_state = libxml_use_internal_errors( true );
225
+ if ( class_exists( 'DOMDocument' ) ) {
226
+ $dom = new DOMDocument();
227
+ $result = $dom->loadHTML( '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body>' . $content . '</body></html>' );
228
+ libxml_clear_errors();
229
+ libxml_use_internal_errors( $libxml_previous_state );
230
+ if ( ! $result ) {
231
+ return false;
232
+ }
233
+ return $dom;
234
+ } else {
235
+ self::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . __( 'DOM is disabled or libxml PHP extension is missing. Contact your hosting provider. Automatic tracking of events for AMP pages is not possible.', 'google-analytics-dashboard-for-wp' ), 24*60*60 );
236
+ return false;
237
+ }
238
+ }
239
+
240
+ public static function get_content_from_dom( $dom ) {
241
+ $out = '';
242
+ $body = $dom->getElementsByTagName( 'body' )->item( 0 );
243
+ foreach ( $body->childNodes as $node ) {
244
+ $out .= $dom->saveXML( $node );
245
+ }
246
+ return $out;
247
+ }
248
  }
249
  }