Google Analytics Dashboard for WP (GADWP) - Version 5.1

Version Description

  • Bug Fixes:
    • if tracking is disabled it keeps it that way while upgrading from versions lower than 5.0
    • fixes the undeclared variable gadwpSubmitObject error on submitted forms
    • added deprecation warning for tracking_code method
    • fix network admin menu capabilities, props by Maxime Culea
  • Enhancements:
    • switch to a customized version of GAPI to avoid conflicts with other plugins
    • automatically remove amp/ from Google Analytics tracking page URL
    • events tracking is now using data-vars-ga- attributes instead of data-ga-
    • increase default report expiration cookie from 7 days to 365 days
  • New Features:
    • sampleRate support for web analytics and AMP
    • custom dimensions tracking support for AMP
    • scrolling depth tracking support for AMP
    • form submit tracking support for AMP
    • downloads, affiliate links, hashmarks, outbound links, telephones, e-mails tracking support for AMP
Download this release

Release Info

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

Code changes from version 5.0.1 to 5.1

Files changed (69) hide show
  1. admin/css/gadwp.css +1 -1
  2. admin/settings.php +15 -5
  3. admin/setup.php +5 -5
  4. admin/views/access-code.php +36 -0
  5. common/js/reports5.js +1 -1
  6. config.php +16 -1
  7. front/js/tracking-analytics-events.js +1 -1
  8. front/js/tracking-tagmanager-events.js +1 -1
  9. front/setup.php +1 -1
  10. front/tracking-analytics.php +236 -83
  11. front/tracking-tagmanager.php +9 -3
  12. front/tracking.php +10 -1
  13. front/views/analytics-amp-code.php +14 -0
  14. front/views/analytics-code.php +9 -1
  15. front/views/optimize-code.php +9 -0
  16. front/views/tagmanager-code.php +9 -1
  17. gadwp.php +2 -2
  18. install/install.php +3 -0
  19. readme.txt +39 -2
  20. tools/gapi.php +26 -46
  21. tools/src/{Google → Deconf}/Auth/Abstract.php +6 -6
  22. tools/src/{Google → Deconf}/Auth/AppIdentity.php +8 -8
  23. tools/src/{Google → Deconf}/Auth/AssertionCredentials.php +7 -7
  24. tools/src/{Google → Deconf}/Auth/ComputeEngine.php +17 -17
  25. tools/src/{Google → Deconf}/Auth/Exception.php +2 -2
  26. tools/src/{Google → Deconf}/Auth/LoginTicket.php +4 -4
  27. tools/src/{Google → Deconf}/Auth/OAuth2.php +50 -50
  28. tools/src/{Google → Deconf}/Auth/Simple.php +7 -7
  29. tools/src/{Google → Deconf}/Cache/Abstract.php +2 -2
  30. tools/src/{Google → Deconf}/Cache/Apc.php +6 -6
  31. tools/src/{Google → Deconf}/Cache/Exception.php +2 -2
  32. tools/src/{Google → Deconf}/Cache/File.php +6 -6
  33. tools/src/{Google → Deconf}/Cache/Memcache.php +9 -9
  34. tools/src/{Google → Deconf}/Cache/Null.php +3 -3
  35. tools/src/{Google → Deconf}/Client.php +50 -50
  36. tools/src/{Google → Deconf}/Collection.php +3 -3
  37. tools/src/{Google → Deconf}/Config.php +18 -18
  38. tools/src/{Google → Deconf}/Exception.php +1 -1
  39. tools/src/{Google → Deconf}/Http/Batch.php +11 -11
  40. tools/src/{Google → Deconf}/Http/CacheParser.php +11 -11
  41. tools/src/{Google → Deconf}/Http/MediaFileUpload.php +14 -14
  42. tools/src/{Google → Deconf}/Http/REST.php +21 -21
  43. tools/src/{Google → Deconf}/Http/Request.php +4 -4
  44. tools/src/{Google → Deconf}/IO/Abstract.php +28 -28
  45. tools/src/{Google → Deconf}/IO/Curl.php +13 -13
  46. tools/src/{Google → Deconf}/IO/Exception.php +2 -2
  47. tools/src/{Google → Deconf}/IO/Stream.php +10 -10
  48. tools/src/{Google → Deconf}/IO/cacerts.pem +0 -0
  49. tools/src/{Google → Deconf}/Logger/Abstract.php +10 -10
  50. tools/src/{Google → Deconf}/Logger/Exception.php +2 -2
  51. tools/src/{Google → Deconf}/Logger/File.php +9 -9
  52. tools/src/{Google → Deconf}/Logger/Null.php +2 -2
  53. tools/src/{Google → Deconf}/Logger/Psr.php +5 -5
  54. tools/src/{Google → Deconf}/Model.php +6 -6
  55. tools/src/{Google → Deconf}/Service.php +6 -6
  56. tools/src/{Google → Deconf}/Service/Analytics.php +509 -509
  57. tools/src/{Google → Deconf}/Service/Exception.php +2 -2
  58. tools/src/{Google → Deconf}/Service/Resource.php +13 -13
  59. tools/src/{Google → Deconf}/Signer/Abstract.php +1 -1
  60. tools/src/{Google → Deconf}/Signer/P12.php +8 -8
  61. tools/src/{Google → Deconf}/Task/Exception.php +2 -2
  62. tools/src/{Google → Deconf}/Task/Retryable.php +2 -2
  63. tools/src/{Google → Deconf}/Task/Runner.php +15 -15
  64. tools/src/{Google → Deconf}/Utils.php +1 -1
  65. tools/src/{Google → Deconf}/Utils/URITemplate.php +1 -1
  66. tools/src/{Google → Deconf}/Verifier/Abstract.php +1 -1
  67. tools/src/{Google → Deconf}/Verifier/Pem.php +8 -8
  68. tools/src/{Google → Deconf}/autoload.php +1 -1
  69. tools/tools.php +16 -2
admin/css/gadwp.css CHANGED
@@ -1 +1 @@
1
- #gadwp-events,#gadwp-custom,#gadwp-advanced,#gadwp-exclude,#gadwp-config,#gadwp-tmdatalayervars,#gadwp-tmintegration,#gadwp-integration{display:none}table.gadwp-settings-options{padding-left:10px;width:100%}.gadwp-settings-options td{padding:0 5px 5px 5px}td.gadwp-settings-title,td.info{width:140px;padding-left:20px}td.gadwp-settings-title-s{width:300px}.gadwp-help{padding-left:15px}td.gadwp-settings-info{padding-bottom:15px}td.gadwp-settings-title label{font-size:1.1em}.gadash-title{float:left;margin-right:10px;margin-top:2px;clear:left}.gadash-desc{font-size:1em}.gadash-top{vertical-align:top}pre.gadwp-settings-logdata{white-space:pre-wrap}td.gadwp-settings-roles{padding-bottom:15px}#ga_speed_samplerate,#ga_realtime_pages{width:50px}#gapi-access-code{color:red !important}#poststuff.gadwp h2{padding-bottom:0;font-size:19.5px;font-weight:normal;padding:0;margin:20px 0 15px 0}#poststuff.gadwp h2.nav-tab-wrapper{border-bottom:1px solid #ccc;padding-bottom:0}.button-primary.gadwp-settings-switchoo{position:relative;width:50px;float:left;border:0;padding:0;height:22px;-moz-box-shadow:none;-webkit-box-shadow:none;-o-box-shadow:none;box-shadow:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}input.gadwp-settings-switchoo-checkbox{display:none}.gadwp-settings-switchoo-label{display:block;overflow:hidden;cursor:pointer;background:transparent;border:1px solid #ddd;border-radius:2px;text-shadow:none}.gadwp-settings-switchoo-inner{width:200%;margin-left:-100%;border-radius:2px;-moz-transition:margin .2s ease-in 0;-webkit-transition:margin .2s ease-in 0;-o-transition:margin .2s ease-in 0;transition:margin .2s ease-in 0}.gadwp-settings-switchoo-inner:before,.gadwp-settings-switchoo-inner:after{float:left;width:50%;font-weight:normal;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;height:22px;line-height:22px;font-size:12px;text-shadow:none}.gadwp-settings-switchoo-inner:before{content:"On";padding-left:5px;border-bottom:0}.gadwp-settings-switchoo-inner:after{content:"Off";padding-right:5px;background-color:#ddd;text-align:right}.gadwp-settings-switchoo-switch{width:22px;height:22px;background:#fff;color:#ddd;border:1px solid #ddd;border-radius:2px;position:absolute;top:0;bottom:0;right:27px;-moz-transition:all .2s ease-in 0;-webkit-transition:all .2s ease-in 0;-o-transition:all .2s ease-in 0;transition:all .2s ease-in 0}.gadwp-settings-switchoo-switch:hover{color:#aaa;border-color:#aaa}.gadwp-settings-switchoo-switch:after{margin:0;outline:0;display:inline-block;font:400 16px/16px dashicons;content:"\f228";padding:3px 0 0 3px;text-align:left;text-decoration:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.gadwp-settings-switchoo-checkbox:checked+.gadwp-settings-switchoo-label .gadwp-settings-switchoo-inner{margin-left:0}.gadwp-settings-switchoo-checkbox:checked+.gadwp-settings-switchoo-label .gadwp-settings-switchoo-switch{right:0}.switch-desc{float:left;margin-left:10px;line-height:20px}
1
+ #gadwp-events,#gadwp-custom,#gadwp-advanced,#gadwp-exclude,#gadwp-config,#gadwp-tmdatalayervars,#gadwp-tmintegration,#gadwp-integration{display:none}table.gadwp-settings-options{padding-left:10px;width:100%}.gadwp-settings-options td{padding:0 5px 5px 5px}td.gadwp-settings-title,td.info{width:140px;padding-left:20px}td.gadwp-settings-title-s{width:300px}.gadwp-help{padding-left:15px}td.gadwp-settings-info{padding-bottom:15px}td.gadwp-settings-title label{font-size:1.1em}.gadash-title{float:left;margin-right:10px;margin-top:2px;clear:left}.gadash-desc{font-size:1em}.gadash-top{vertical-align:top}pre.gadwp-settings-logdata{white-space:pre-wrap}td.gadwp-settings-roles{padding-bottom:15px}#ga_speed_samplerate,#ga_user_samplerate,#ga_realtime_pages{width:50px}#gapi-access-code{color:red !important}#poststuff.gadwp h2{padding-bottom:0;font-size:19.5px;font-weight:normal;padding:0;margin:20px 0 15px 0}#poststuff.gadwp h2.nav-tab-wrapper{border-bottom:1px solid #ccc;padding-bottom:0}.button-primary.gadwp-settings-switchoo{position:relative;width:50px;float:left;border:0;padding:0;height:22px;-moz-box-shadow:none;-webkit-box-shadow:none;-o-box-shadow:none;box-shadow:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}input.gadwp-settings-switchoo-checkbox{display:none}.gadwp-settings-switchoo-label{display:block;overflow:hidden;cursor:pointer;background:transparent;border:1px solid #ddd;border-radius:2px;text-shadow:none}.gadwp-settings-switchoo-inner{width:200%;margin-left:-100%;border-radius:2px;-moz-transition:margin .2s ease-in 0;-webkit-transition:margin .2s ease-in 0;-o-transition:margin .2s ease-in 0;transition:margin .2s ease-in 0}.gadwp-settings-switchoo-inner:before,.gadwp-settings-switchoo-inner:after{float:left;width:50%;font-weight:normal;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;height:22px;line-height:22px;font-size:12px;text-shadow:none}.gadwp-settings-switchoo-inner:before{content:"On";padding-left:5px;border-bottom:0}.gadwp-settings-switchoo-inner:after{content:"Off";padding-right:5px;background-color:#ddd;text-align:right}.gadwp-settings-switchoo-switch{width:22px;height:22px;background:#fff;color:#ddd;border:1px solid #ddd;border-radius:2px;position:absolute;top:0;bottom:0;right:27px;-moz-transition:all .2s ease-in 0;-webkit-transition:all .2s ease-in 0;-o-transition:all .2s ease-in 0;transition:all .2s ease-in 0}.gadwp-settings-switchoo-switch:hover{color:#aaa;border-color:#aaa}.gadwp-settings-switchoo-switch:after{margin:0;outline:0;display:inline-block;font:400 16px/16px dashicons;content:"\f228";padding:3px 0 0 3px;text-align:left;text-decoration:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.gadwp-settings-switchoo-checkbox:checked+.gadwp-settings-switchoo-label .gadwp-settings-switchoo-inner{margin-left:0}.gadwp-settings-switchoo-checkbox:checked+.gadwp-settings-switchoo-label .gadwp-settings-switchoo-switch{right:0}.switch-desc{float:left;margin-left:10px;line-height:20px}
admin/settings.php CHANGED
@@ -691,7 +691,7 @@ final class GADWP_Settings {
691
  </tr>
692
  <tr>
693
  <td class="gadwp-settings-title">
694
- <label for="ga_speed_samplerate"><?php _e("Page Speed SR:", 'google-analytics-dashboard-for-wp'); ?>
695
  </label>
696
  </td>
697
  <td>
@@ -699,6 +699,16 @@ final class GADWP_Settings {
699
  %
700
  </td>
701
  </tr>
 
 
 
 
 
 
 
 
 
 
702
  <tr>
703
  <td colspan="2" class="gadwp-settings-title">
704
  <div class="button-primary gadwp-settings-switchoo">
@@ -1099,10 +1109,10 @@ final class GADWP_Settings {
1099
  $options = self::update_options( 'general' );
1100
  }
1101
  }
1102
- } catch ( Google_IO_Exception $e ) {
1103
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $gadwp->gapi_controller->error_timeout );
1104
  return false;
1105
- } catch ( Google_Service_Exception $e ) {
1106
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $gadwp->gapi_controller->error_timeout );
1107
  GADWP_Tools::set_cache( 'gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout );
1108
  return $e->getCode();
@@ -1393,10 +1403,10 @@ final class GADWP_Settings {
1393
  $options = self::update_options( 'network' );
1394
  }
1395
  }
1396
- } catch ( Google_IO_Exception $e ) {
1397
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $gadwp->gapi_controller->error_timeout );
1398
  return false;
1399
- } catch ( Google_Service_Exception $e ) {
1400
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $gadwp->gapi_controller->error_timeout );
1401
  GADWP_Tools::set_cache( 'gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout );
1402
  return $e->getCode();
691
  </tr>
692
  <tr>
693
  <td class="gadwp-settings-title">
694
+ <label for="ga_speed_samplerate"><?php _e("Speed Sample Rate:", 'google-analytics-dashboard-for-wp'); ?>
695
  </label>
696
  </td>
697
  <td>
699
  %
700
  </td>
701
  </tr>
702
+ <tr>
703
+ <td class="gadwp-settings-title">
704
+ <label for="ga_user_samplerate"><?php _e("User Sample Rate:", 'google-analytics-dashboard-for-wp'); ?>
705
+ </label>
706
+ </td>
707
+ <td>
708
+ <input type="number" id="ga_user_samplerate" name="options[ga_user_samplerate]" value="<?php echo (int)($options['ga_user_samplerate']); ?>" max="100" min="1">
709
+ %
710
+ </td>
711
+ </tr>
712
  <tr>
713
  <td colspan="2" class="gadwp-settings-title">
714
  <div class="button-primary gadwp-settings-switchoo">
1109
  $options = self::update_options( 'general' );
1110
  }
1111
  }
1112
+ } catch ( Deconf_IO_Exception $e ) {
1113
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $gadwp->gapi_controller->error_timeout );
1114
  return false;
1115
+ } catch ( Deconf_Service_Exception $e ) {
1116
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $gadwp->gapi_controller->error_timeout );
1117
  GADWP_Tools::set_cache( 'gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout );
1118
  return $e->getCode();
1403
  $options = self::update_options( 'network' );
1404
  }
1405
  }
1406
+ } catch ( Deconf_IO_Exception $e ) {
1407
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $gadwp->gapi_controller->error_timeout );
1408
  return false;
1409
+ } catch ( Deconf_Service_Exception $e ) {
1410
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $gadwp->gapi_controller->error_timeout );
1411
  GADWP_Tools::set_cache( 'gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout );
1412
  return $e->getCode();
admin/setup.php CHANGED
@@ -53,10 +53,10 @@ if ( ! class_exists( 'GADWP_Backend_Setup' ) ) {
53
  */
54
  public function network_menu() {
55
  global $wp_version;
56
- if ( current_user_can( 'manage_netwrok' ) ) {
57
  include ( GADWP_DIR . 'admin/settings.php' );
58
- add_menu_page( __( "Google Analytics", 'google-analytics-dashboard-for-wp' ), "Google Analytics", 'manage_netwrok', 'gadash_settings', array( 'GADWP_Settings', 'general_settings_network' ), version_compare( $wp_version, '3.8.0', '>=' ) ? 'dashicons-chart-area' : GADWP_URL . 'admin/images/gadash-icon.png' );
59
- add_submenu_page( 'gadash_settings', __( "General Settings", 'google-analytics-dashboard-for-wp' ), __( "General Settings", 'google-analytics-dashboard-for-wp' ), 'manage_netwrok', 'gadash_settings', array( 'GADWP_Settings', 'general_settings_network' ) );
60
  add_submenu_page( 'gadash_settings', __( "Errors & Debug", 'google-analytics-dashboard-for-wp' ), __( "Errors & Debug", 'google-analytics-dashboard-for-wp' ), 'manage_network', 'gadash_errors_debugging', array( 'GADWP_Settings', 'errors_debugging' ) );
61
  }
62
  }
@@ -190,7 +190,7 @@ if ( ! class_exists( 'GADWP_Backend_Setup' ) ) {
190
  __( "Organic Search", 'google-analytics-dashboard-for-wp' ),
191
  __( "Pages/Session", 'google-analytics-dashboard-for-wp' ),
192
  __( "Invalid response", 'google-analytics-dashboard-for-wp' ),
193
- __( "Not enough data collected", 'google-analytics-dashboard-for-wp' ),
194
  __( "This report is unavailable", 'google-analytics-dashboard-for-wp' ),
195
  __( "report generated by", 'google-analytics-dashboard-for-wp' ), //14
196
  __( "This plugin needs an authorization:", 'google-analytics-dashboard-for-wp' ) . ' <a href="' . menu_page_url( 'gadash_settings', false ) . '">' . __( "authorize the plugin", 'google-analytics-dashboard-for-wp' ) . '</a>.',
@@ -290,7 +290,7 @@ if ( ! class_exists( 'GADWP_Backend_Setup' ) ) {
290
  __( "Organic Search", 'google-analytics-dashboard-for-wp' ),
291
  __( "Pages/Session", 'google-analytics-dashboard-for-wp' ),
292
  __( "Invalid response", 'google-analytics-dashboard-for-wp' ),
293
- __( "Not enough data collected", 'google-analytics-dashboard-for-wp' ),
294
  __( "This report is unavailable", 'google-analytics-dashboard-for-wp' ),
295
  __( "report generated by", 'google-analytics-dashboard-for-wp' ), //14
296
  __( "This plugin needs an authorization:", 'google-analytics-dashboard-for-wp' ) . ' <a href="' . menu_page_url( 'gadash_settings', false ) . '">' . __( "authorize the plugin", 'google-analytics-dashboard-for-wp' ) . '</a>.',
53
  */
54
  public function network_menu() {
55
  global $wp_version;
56
+ if ( current_user_can( 'manage_network' ) ) {
57
  include ( GADWP_DIR . 'admin/settings.php' );
58
+ add_menu_page( __( "Google Analytics", 'google-analytics-dashboard-for-wp' ), "Google Analytics", 'manage_network', 'gadash_settings', array( 'GADWP_Settings', 'general_settings_network' ), version_compare( $wp_version, '3.8.0', '>=' ) ? 'dashicons-chart-area' : GADWP_URL . 'admin/images/gadash-icon.png' );
59
+ add_submenu_page( 'gadash_settings', __( "General Settings", 'google-analytics-dashboard-for-wp' ), __( "General Settings", 'google-analytics-dashboard-for-wp' ), 'manage_network', 'gadash_settings', array( 'GADWP_Settings', 'general_settings_network' ) );
60
  add_submenu_page( 'gadash_settings', __( "Errors & Debug", 'google-analytics-dashboard-for-wp' ), __( "Errors & Debug", 'google-analytics-dashboard-for-wp' ), 'manage_network', 'gadash_errors_debugging', array( 'GADWP_Settings', 'errors_debugging' ) );
61
  }
62
  }
190
  __( "Organic Search", 'google-analytics-dashboard-for-wp' ),
191
  __( "Pages/Session", 'google-analytics-dashboard-for-wp' ),
192
  __( "Invalid response", 'google-analytics-dashboard-for-wp' ),
193
+ __( "No Data", 'google-analytics-dashboard-for-wp' ),
194
  __( "This report is unavailable", 'google-analytics-dashboard-for-wp' ),
195
  __( "report generated by", 'google-analytics-dashboard-for-wp' ), //14
196
  __( "This plugin needs an authorization:", 'google-analytics-dashboard-for-wp' ) . ' <a href="' . menu_page_url( 'gadash_settings', false ) . '">' . __( "authorize the plugin", 'google-analytics-dashboard-for-wp' ) . '</a>.',
290
  __( "Organic Search", 'google-analytics-dashboard-for-wp' ),
291
  __( "Pages/Session", 'google-analytics-dashboard-for-wp' ),
292
  __( "Invalid response", 'google-analytics-dashboard-for-wp' ),
293
+ __( "No Data", 'google-analytics-dashboard-for-wp' ),
294
  __( "This report is unavailable", 'google-analytics-dashboard-for-wp' ),
295
  __( "report generated by", 'google-analytics-dashboard-for-wp' ), //14
296
  __( "This plugin needs an authorization:", 'google-analytics-dashboard-for-wp' ) . ' <a href="' . menu_page_url( 'gadash_settings', false ) . '">' . __( "authorize the plugin", 'google-analytics-dashboard-for-wp' ) . '</a>.',
admin/views/access-code.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Author: Alin Marcu
4
+ * Copyright 2017 Alin Marcu
5
+ * Author URI: https://deconf.com
6
+ * License: GPLv2 or later
7
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
+ */
9
+ ?>
10
+ <form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
11
+ <table class="gadwp-settings-options">
12
+ <tr>
13
+ <td colspan="2" class="gadwp-settings-info">
14
+ <?php echo __( "Use this link to get your access code:", 'google-analytics-dashboard-for-wp' ) . ' <a href="' . $data['authUrl'] . '" id="gapi-access-code" target="_blank">' . __ ( "Get Access Code", 'google-analytics-dashboard-for-wp' ) . '</a>.'; ?>
15
+ </td>
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>
26
+ <td colspan="2">
27
+ <hr>
28
+ </td>
29
+ </tr>
30
+ <tr>
31
+ <td colspan="2">
32
+ <input type="submit" class="button button-secondary" name="ga_dash_authorize" value="<?php _e( "Save Access Code", 'google-analytics-dashboard-for-wp' ); ?>" />
33
+ </td>
34
+ </tr>
35
+ </table>
36
+ </form>
common/js/reports5.js CHANGED
@@ -1 +1 @@
1
- "use strict";if(gadwpItemData.mapsApiKey){google.charts.load("current",{mapsApiKey:gadwpItemData.mapsApiKey,packages:["corechart","table","orgchart","geochart"]})}else{google.charts.load("current",{packages:["corechart","table","orgchart","geochart"]})}google.charts.setOnLoadCallback(GADWPReportLoad);gadwpItemData.getID=function(a){if(gadwpItemData.scope=="admin-item"){if(typeof a.id=="undefined"){return 0}if(a.id.split("-")[1]=="undefined"){return 0}else{return a.id.split("-")[1]}}else{if(typeof a.id=="undefined"){return 1}if(a.id.split("-")[4]=="undefined"){return 1}else{return a.id.split("-")[4]}}};gadwpItemData.getSelector=function(a){if(a=="admin-item"){return'a[id^="gadwp-"]'}else{return'li[id^="wp-admin-bar-gadwp"] a'}};gadwpItemData.responsiveDialog=function(){var b,a,c;c=jQuery(".ui-dialog:visible");c.each(function(){b=jQuery(this).find(".ui-dialog-content").data("ui-dialog");if(b.options.fluid){a=jQuery(window).width();if(a<(parseInt(b.options.maxWidth)+50)){jQuery(this).css("max-width","90%")}else{jQuery(this).css("max-width",b.options.maxWidth+"px")}b.option("position",b.options.position)}})};jQuery.fn.extend({gadwpItemReport:function(g){var a,d,h,e,f,i,c,b="-"+g;d={setCookie:function(k,m){var j,l=new Date();if(gadwpItemData.scope=="admin-widgets"){k="gadwp_wg_"+k}else{k="gadwp_ir_"+k}l.setTime(l.getTime()+(24*60*60*1000*7));j="expires="+l.toUTCString();document.cookie=k+"="+m+"; "+j+"; path=/"},getCookie:function(j){var l,m,n,k=0;if(gadwpItemData.scope=="admin-widgets"){j="gadwp_wg_"+j+"="}else{j="gadwp_ir_"+j+"="}m=document.cookie.split(";");for(k=0;k<m.length;k++){l=m[k];while(l.charAt(0)==" "){l=l.substring(1)}if(l.indexOf(j)==0){return l.substring(j.length,l.length)}}return false},escape:function(j){div=document.createElement("div");div.appendChild(document.createTextNode(j));return div.innerHTML}};h={addOptions:function(o,n){var j,l,m,k=[];if(!d.getCookie("default_metric")||!d.getCookie("default_dimension")||!d.getCookie("default_swmetric")){j="sessions";l="30daysAgo";if(gadwpItemData.scope=="front-item"||gadwpItemData.scope=="admin-item"){c="pageviews"}else{c="sessions"}d.setCookie("default_metric",j);d.setCookie("default_dimension",l);d.setCookie("default_swmetric",c)}else{j=d.getCookie("default_metric");l=d.getCookie("default_dimension");m=d.getCookie("default_view");c=d.getCookie("default_swmetric")}if(n==false){if(gadwpItemData.scope=="front-item"||gadwpItemData.scope=="admin-item"){k=""}else{k='<span id="gadwp-swmetric-sessions" title="'+gadwpItemData.i18n[5]+'" class="dashicons dashicons-clock" style="font-size:22px;padding:4px;"></span>'}k+='<span id="gadwp-swmetric-users" title="'+gadwpItemData.i18n[6]+'" class="dashicons dashicons-admin-users" style="font-size:22px;padding:4px;"></span>';k+='<span id="gadwp-swmetric-pageviews" title="'+gadwpItemData.i18n[7]+'" class="dashicons dashicons-admin-page" style="font-size:22px;padding:4px;"></span>';jQuery(o).html(k);jQuery("#gadwp-swmetric-"+c).css("color","#008ec2")}else{jQuery.each(n,function(p,q){if(p==j||p==l||p==m){k.push('<option value="'+p+'" selected="selected">'+q+"</option>")}else{k.push('<option value="'+p+'">'+q+"</option>")}});jQuery(o).html(k.join(""))}},init:function(){var j;if(!jQuery("#gadwp-window"+b).length){return}if(jQuery("#gadwp-window"+b).html().length){return}j='<div id="gadwp-container'+b+'">';if(gadwpItemData.viewList!=false){j+='<select id="gadwp-sel-view'+b+'"></select>'}j+='<select id="gadwp-sel-period'+b+'"></select> ';j+='<select id="gadwp-sel-report'+b+'"></select>';j+='<div id="gadwp-sel-metric'+b+'" style="float:right;display:none;">';j+="</div>";j+='<div id="gadwp-progressbar'+b+'"></div>';j+='<div id="gadwp-status'+b+'"></div>';j+='<div id="gadwp-reports'+b+'"></div>';j+='<div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;margin-top:10px;">';j+=gadwpItemData.i18n[14];j+=' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_report&utm_medium=link&utm_content=back_report&utm_campaign=gadwp" rel="nofollow" style="text-decoration:none;font-size:1em;">GADWP</a>&nbsp;';j+="</div>";j+="</div>",jQuery("#gadwp-window"+b).append(j);h.addOptions("#gadwp-sel-view"+b,gadwpItemData.viewList);h.addOptions("#gadwp-sel-period"+b,gadwpItemData.dateList);h.addOptions("#gadwp-sel-report"+b,gadwpItemData.reportList);h.addOptions("#gadwp-sel-metric"+b,false)}};e={oldViewPort:0,orgChartTableChartData:"",tableChartData:"",orgChartPieChartsData:"",geoChartTableChartData:"",areaChartBottomStatsData:"",realtime:"",rtRuns:null,i18n:null,getTitle:function(j){if(j=="admin-item"){return jQuery("#gadwp"+b).attr("title")}else{return document.getElementsByTagName("title")[0].innerHTML}},alertMessage:function(j){jQuery("#gadwp-status"+b).css({"margin-top":"3px","padding-left":"5px",height:"auto",color:"#000","border-left":"5px solid red"});jQuery("#gadwp-status"+b).html(j)},areaChartBottomStats:function(j){e.areaChartBottomStatsData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();if(a.query=="visitBounceRate,bottomstats"){e.drawAreaChart(j[0],true)}else{e.drawAreaChart(j[0],false)}}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-areachart"+b,j[0],"125px")}if(!jQuery.isNumeric(j[1])){if(jQuery.isArray(j[1])){jQuery("#gadwp-reports"+b).show();e.drawBottomStats(j[1])}else{e.throwDebug(j[1])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-bottomstats"+b,j[1],"40px")}}else{e.throwDebug(j)}NProgress.done()},orgChartPieCharts:function(j){var k=0;e.orgChartPieChartsData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();e.drawOrgChart(j[0])}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-orgchart"+b,j[0],"125px")}for(k=1;k<j.length;k++){if(!jQuery.isNumeric(j[k])){if(jQuery.isArray(j[k])){jQuery("#gadwp-reports"+b).show();e.drawPieChart("piechart-"+k,j[k],e.i18n[k])}else{e.throwDebug(j[k])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-piechart-"+k+b,j[k],"80px")}}}else{e.throwDebug(j)}NProgress.done()},geoChartTableChart:function(j){e.geoChartTableChartData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();e.drawGeoChart(j[0]);e.drawTableChart(j[0])}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-geochart"+b,j[0],"125px");e.throwError("#gadwp-tablechart"+b,j[0],"125px")}}else{e.throwDebug(j)}NProgress.done()},orgChartTableChart:function(j){e.orgChartTableChartData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();e.drawOrgChart(j[0])}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-orgchart"+b,j[0],"125px")}if(!jQuery.isNumeric(j[1])){if(jQuery.isArray(j[1])){e.drawTableChart(j[1])}else{e.throwDebug(j[1])}}else{e.throwError("#gadwp-tablechart"+b,j[1],"125px")}}else{e.throwDebug(j)}NProgress.done()},tableChart:function(j){e.tableChartData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();e.drawTableChart(j[0])}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-tablechart"+b,j[0],"125px")}}else{e.throwDebug(j)}NProgress.done()},drawTableChart:function(m){var l,j,k;l=google.visualization.arrayToDataTable(m);j={page:"enable",pageSize:10,width:"100%",allowHtml:true};k=new google.visualization.Table(document.getElementById("gadwp-tablechart"+b));k.draw(l,j)},drawOrgChart:function(m){var l,j,k;l=google.visualization.arrayToDataTable(m);j={allowCollapse:true,allowHtml:true,height:"100%"};k=new google.visualization.OrgChart(document.getElementById("gadwp-orgchart"+b));k.draw(l,j)},drawPieChart:function(o,m,n){var l,j,k;l=google.visualization.arrayToDataTable(m);j={is3D:false,tooltipText:"percentage",legend:"none",chartArea:{width:"99%",height:"80%"},title:n,pieSliceText:"value",colors:gadwpItemData.colorVariations};k=new google.visualization.PieChart(document.getElementById("gadwp-"+o+b));k.draw(l,j)},drawGeoChart:function(m){var l,j,k;l=google.visualization.arrayToDataTable(m);j={chartArea:{width:"99%",height:"90%"},colors:[gadwpItemData.colorVariations[5],gadwpItemData.colorVariations[4]]};if(gadwpItemData.region){j.region=gadwpItemData.region;j.displayMode="markers";j.datalessRegionColor="EFEFEF"}k=new google.visualization.GeoChart(document.getElementById("gadwp-geochart"+b));k.draw(l,j)},drawAreaChart:function(n,o){var m,j,l,k;m=google.visualization.arrayToDataTable(n);if(o){k=new google.visualization.NumberFormat({suffix:"%",fractionDigits:2});k.format(m,1)}j={legend:{position:"none"},pointSize:3,colors:[gadwpItemData.colorVariations[0],gadwpItemData.colorVariations[4]],chartArea:{width:"99%",height:"90%"},vAxis:{textPosition:"in",minValue:0},hAxis:{textPosition:"none"}};l=new google.visualization.AreaChart(document.getElementById("gadwp-areachart"+b));l.draw(m,j)},drawBottomStats:function(j){jQuery("#gdsessions"+b).html(j[0]);jQuery("#gdusers"+b).html(j[1]);jQuery("#gdpageviews"+b).html(j[2]);jQuery("#gdbouncerate"+b).html(j[3]);jQuery("#gdorganicsearch"+b).html(j[4]);jQuery("#gdpagespervisit"+b).html(j[5]);jQuery("#gdpagetime"+b).html(j[6]);jQuery("#gdpageload"+b).html(j[7]);jQuery("#gdsessionduration"+b).html(j[8])},rtOnlyUniqueValues:function(l,k,j){return j.indexOf(l)===k},rtCountSessions:function(k,m){var l=0,j=0;for(j=0;j<k.rows.length;j++){if(jQuery.inArray(m,k.rows[j])>-1){l+=parseInt(k.rows[j][6])}}return l},rtGenerateTooltip:function(k){var m=0,l="",j=0;for(j=0;j<k.length;j++){m+=parseInt(k[j].count);l+="<tr><td class='gadwp-pgdetailsl'>"+k[j].value+"</td><td class='gadwp-pgdetailsr'>"+k[j].count+"</td></tr>"}if(m){return("<table>"+l+"</table>")}else{return("")}},rtPageDetails:function(y,n){var w,o,r,x=0,v=0,m=0,s=0,t=0,z=0,C=0,q=0,l=0,u="",A="",p="",k="",B="";y=y.rows;for(x=0;x<y.length;x++){if(y[x][0]==n){o=y[x][5];switch(y[x][3]){case"REFERRAL":t+=parseInt(y[x][6]);u+="<tr><td class='gadwp-pgdetailsl'>"+y[x][1]+"</td><td class='gadwp-pgdetailsr'>"+y[x][6]+"</td></tr>";break;case"ORGANIC":z+=parseInt(y[x][6]);A+="<tr><td class='gadwp-pgdetailsl'>"+y[x][2]+"</td><td class='gadwp-pgdetailsr'>"+y[x][6]+"</td></tr>";break;case"SOCIAL":q+=parseInt(y[x][6]);p+="<tr><td class='gadwp-pgdetailsl'>"+y[x][1]+"</td><td class='gadwp-pgdetailsr'>"+y[x][6]+"</td></tr>";break;case"CUSTOM":l+=parseInt(y[x][6]);k+="<tr><td class='gadwp-pgdetailsl'>"+y[x][1]+"</td><td class='gadwp-pgdetailsr'>"+y[x][6]+"</td></tr>";break;case"DIRECT":C+=parseInt(y[x][6]);break}}}if(t){u="<table><tr><td>"+e.i18n[0]+"("+t+")</td></tr>"+u+"</table><br />"}if(z){A="<table><tr><td>"+e.i18n[1]+"("+z+")</td></tr>"+A+"</table><br />"}if(q){p="<table><tr><td>"+e.i18n[2]+"("+q+")</td></tr>"+p+"</table><br />"}if(l){k="<table><tr><td>"+e.i18n[3]+"("+l+")</td></tr>"+k+"</table><br />"}if(C){B="<table><tr><td>"+e.i18n[4]+"("+C+")</td></tr></table><br />"}return("<p><center><strong>"+o+"</strong></center></p>"+u+A+p+k+B)},rtRefresh:function(){if(e.render.focusFlag){a.from=false;a.to=false;a.query="realtime";jQuery.post(gadwpItemData.ajaxurl,a,function(j){if(jQuery.isArray(j)){jQuery("#gadwp-reports"+b).show();e.realtime=j[0];e.drawRealtime(e.realtime)}else{e.throwDebug(j)}NProgress.done()})}},drawRealtime:function(y){var j,n,o,w,t,r,x=0,v=[],z=[],p=[],m=[],q=[],k=[],l=[],s="",o=[],w=[],t=[],r=[],u=["REFERRAL","ORGANIC","SOCIAL","CUSTOM"],A=["DIRECT","NEW"];jQuery(function(){jQuery("#gadwp-widget *").tooltip({tooltipClass:"gadwp"})});y=y[0];if(jQuery.isNumeric(y)||typeof y==="undefined"){y=[];y.totalsForAllResults=[];y.totalsForAllResults["rt:activeUsers"]="0";y.rows=[]}if(y.totalsForAllResults["rt:activeUsers"]!==document.getElementById("gadwp-online").innerHTML){jQuery("#gadwp-online").fadeOut("slow");jQuery("#gadwp-online").fadeOut(500);jQuery("#gadwp-online").fadeOut("slow",function(){if((parseInt(y.totalsForAllResults["rt:activeUsers"]))<(parseInt(document.getElementById("gadwp-online").innerHTML))){jQuery("#gadwp-online").css({"background-color":"#FFE8E8"})}else{jQuery("#gadwp-online").css({"background-color":"#E0FFEC"})}document.getElementById("gadwp-online").innerHTML=y.totalsForAllResults["rt:activeUsers"]});jQuery("#gadwp-online").fadeIn("slow");jQuery("#gadwp-online").fadeIn(500);jQuery("#gadwp-online").fadeIn("slow",function(){jQuery("#gadwp-online").css({"background-color":"#FFFFFF"})})}if(y.totalsForAllResults["rt:activeUsers"]==0){y.rows=[]}for(x=0;x<y.rows.length;x++){v.push(y.rows[x][0]);if(y.rows[x][3]=="REFERRAL"){z.push(y.rows[x][1])}if(y.rows[x][3]=="ORGANIC"){p.push(y.rows[x][2])}if(y.rows[x][3]=="SOCIAL"){m.push(y.rows[x][1])}if(y.rows[x][3]=="CUSTOM"){k.push(y.rows[x][1])}q.push(y.rows[x][3])}n=v.filter(e.rtOnlyUniqueValues);for(x=0;x<n.length;x++){l[x]={pagepath:n[x],count:e.rtCountSessions(y,n[x])}}l.sort(function(C,B){return B.count-C.count});s="";for(x=0;x<l.length;x++){if(x<gadwpItemData.rtLimitPages){s+='<div class="gadwp-pline"><div class="gadwp-pleft"><a href="#" data-gadwp="'+e.rtPageDetails(y,l[x].pagepath)+'">'+l[x].pagepath.substring(0,70)+'</a></div><div class="gadwp-pright">'+l[x].count+"</div></div>"}}document.getElementById("gadwp-pages").innerHTML='<br /><div class="gadwp-pg">'+s+"</div>";o=z.filter(e.rtOnlyUniqueValues);for(x=0;x<o.length;x++){o[x]={value:o[x],count:e.rtCountSessions(y,o[x])}}o.sort(function(C,B){return B.count-C.count});w=p.filter(e.rtOnlyUniqueValues);for(x=0;x<w.length;x++){w[x]={value:w[x],count:e.rtCountSessions(y,w[x])}}w.sort(function(C,B){return B.count-C.count});t=m.filter(e.rtOnlyUniqueValues);for(x=0;x<t.length;x++){t[x]={value:t[x],count:e.rtCountSessions(y,t[x])}}t.sort(function(C,B){return B.count-C.count});r=k.filter(e.rtOnlyUniqueValues);for(x=0;x<r.length;x++){r[x]={value:r[x],count:e.rtCountSessions(y,r[x])}}r.sort(function(C,B){return B.count-C.count});j='<div class="gadwp-bigtext"><a href="#" data-gadwp="'+e.rtGenerateTooltip(o)+'"><div class="gadwp-bleft">'+e.i18n[0]+'</a></div><div class="gadwp-bright">'+e.rtCountSessions(y,u[0])+"</div></div>";j+='<div class="gadwp-bigtext"><a href="#" data-gadwp="'+e.rtGenerateTooltip(w)+'"><div class="gadwp-bleft">'+e.i18n[1]+'</a></div><div class="gadwp-bright">'+e.rtCountSessions(y,u[1])+"</div></div>";j+='<div class="gadwp-bigtext"><a href="#" data-gadwp="'+e.rtGenerateTooltip(t)+'"><div class="gadwp-bleft">'+e.i18n[2]+'</a></div><div class="gadwp-bright">'+e.rtCountSessions(y,u[2])+"</div></div>";j+='<div class="gadwp-bigtext"><a href="#" data-gadwp="'+e.rtGenerateTooltip(r)+'"><div class="gadwp-bleft">'+e.i18n[3]+'</a></div><div class="gadwp-bright">'+e.rtCountSessions(y,u[3])+"</div></div>";j+='<div class="gadwp-bigtext"><div class="gadwp-bleft">'+e.i18n[4]+'</div><div class="gadwp-bright">'+e.rtCountSessions(y,A[0])+"</div></div>";j+='<div class="gadwp-bigtext"><div class="gadwp-bleft">'+e.i18n[5]+'</div><div class="gadwp-bright">'+e.rtCountSessions(y,A[1])+"</div></div>";document.getElementById("gadwp-tdo-right").innerHTML=j},throwDebug:function(j){jQuery("#gadwp-status"+b).css({"margin-top":"3px","padding-left":"5px",height:"auto",color:"#000","border-left":"5px solid red"});if(j=="-24"){jQuery("#gadwp-status"+b).html(gadwpItemData.i18n[15])}else{jQuery("#gadwp-reports"+b).css({"background-color":"#F7F7F7",height:"auto","margin-top":"10px","padding-top":"50px","padding-bottom":"50px",color:"#000","text-align":"center"});jQuery("#gadwp-reports"+b).html(j);jQuery("#gadwp-reports"+b).show();jQuery("#gadwp-status"+b).html(gadwpItemData.i18n[11]);console.log("\n********************* GADWP Log ********************* \n\n"+j);a={action:"gadwp_set_error",response:j,gadwp_security_set_error:gadwpItemData.security};jQuery.post(gadwpItemData.ajaxurl,a)}},throwError:function(l,j,k){jQuery(l).css({"background-color":"#F7F7F7",height:"auto","padding-top":k,"padding-bottom":k,color:"#000","text-align":"center"});if(j==-21){jQuery(l).html(gadwpItemData.i18n[12]+" ("+j+")")}else{jQuery(l).html(gadwpItemData.i18n[13]+" ("+j+")")}},render:function(j,o,n){var k,q,p,l,m;if(o=="realtime"){jQuery("#gadwp-sel-report"+b).hide()}else{jQuery("#gadwp-sel-report"+b).show();clearInterval(e.rtRuns)}jQuery("#gadwp-status"+b).html("");switch(o){case"today":q="today";p="today";break;case"yesterday":q="yesterday";p="yesterday";break;case"7daysAgo":q="7daysAgo";p="yesterday";break;case"14daysAgo":q="14daysAgo";p="yesterday";break;case"90daysAgo":q="90daysAgo";p="yesterday";break;case"365daysAgo":q="365daysAgo";p="yesterday";break;case"1095daysAgo":q="1095daysAgo";p="yesterday";break;default:q="30daysAgo";p="yesterday";break}d.setCookie("default_metric",n);d.setCookie("default_dimension",o);if(typeof j!=="undefined"){d.setCookie("default_view",j);k=j}else{k=false}if(gadwpItemData.scope=="admin-item"){a={action:"gadwp_backend_item_reports",gadwp_security_backend_item_reports:gadwpItemData.security,from:q,to:p,filter:g}}else{if(gadwpItemData.scope=="front-item"){a={action:"gadwp_frontend_item_reports",gadwp_security_frontend_item_reports:gadwpItemData.security,from:q,to:p,filter:gadwpItemData.filter}}else{a={action:"gadwp_backend_item_reports",gadwp_security_backend_item_reports:gadwpItemData.security,projectId:k,from:q,to:p}}}if(o=="realtime"){e.i18n=gadwpItemData.i18n.slice(20,26);e.render.focusFlag=1;jQuery(window).bind("focus",function(r){e.render.focusFlag=1}).bind("blur",function(r){e.render.focusFlag=0});l='<div id="gadwp-realtime'+b+'">';l+='<div class="gadwp-rt-box">';l+='<div class="gadwp-tdo-left">';l+='<div class="gadwp-online" id="gadwp-online">0</div>';l+="</div>";l+='<div class="gadwp-tdo-right" id="gadwp-tdo-right">';l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[0]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[1]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[2]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[3]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[4]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[5]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+="</div>";l+="</div>";l+="<div>";l+='<div id="gadwp-pages" class="gadwp-pages">&nbsp;</div>';l+="</div>";l+="</div>";jQuery("#gadwp-reports"+b).html(l);e.rtRefresh(e.render.focusFlag);e.rtRuns=setInterval(e.rtRefresh,55000)}else{if(jQuery.inArray(n,["referrers","contentpages","searches"])>-1){l='<div id="gadwp-orgcharttablechart'+b+'">';l+='<div id="gadwp-orgchart'+b+'"></div>';l+='<div id="gadwp-tablechart'+b+'"></div>';l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();jQuery("#gadwp-sel-metric"+b).show();a.query="channelGrouping,"+n;a.metric=c;jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.orgChartTableChart(r)})}else{if(n=="404errors"){l='<div id="gadwp-404tablechart'+b+'">';l+='<div id="gadwp-tablechart'+b+'"></div>';l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();jQuery("#gadwp-sel-metric"+b).show();a.query=n;a.metric=c;jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.tableChart(r)})}else{if(n=="trafficdetails"||n=="technologydetails"){l='<div id="gadwp-orgchartpiecharts'+b+'">';l+='<div id="gadwp-orgchart'+b+'"></div>';l+='<div class="gadwp-floatwraper">';l+='<div id="gadwp-piechart-1'+b+'" class="halfsize floatleft"></div>';l+='<div id="gadwp-piechart-2'+b+'" class="halfsize floatright"></div>';l+="</div>";l+='<div class="gadwp-floatwraper">';l+='<div id="gadwp-piechart-3'+b+'" class="halfsize floatleft"></div>';l+='<div id="gadwp-piechart-4'+b+'" class="halfsize floatright"></div>';l+="</div>";l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();jQuery("#gadwp-sel-metric"+b).show();if(n=="trafficdetails"){a.query="channelGrouping,medium,visitorType,source,socialNetwork";e.i18n=gadwpItemData.i18n.slice(0,5)}else{e.i18n=gadwpItemData.i18n.slice(15,20);a.query="deviceCategory,browser,operatingSystem,screenResolution,mobileDeviceBranding"}a.metric=c;jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.orgChartPieCharts(r)})}else{if(n=="locations"){l='<div id="gadwp-geocharttablechart'+b+'">';l+='<div id="gadwp-geochart'+b+'"></div>';l+='<div id="gadwp-tablechart'+b+'"></div>';l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();jQuery("#gadwp-sel-metric"+b).show();a.query=n;a.metric=c;jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.geoChartTableChart(r)})}else{l='<div id="gadwp-areachartbottomstats'+b+'">';l+='<div id="gadwp-areachart'+b+'"></div>';l+='<div id="gadwp-bottomstats'+b+'">';l+='<div class="inside">';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[5]+'</h3><p id="gdsessions'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[6]+'</h3><p id="gdusers'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[7]+'</h3><p id="gdpageviews'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[8]+'</h3><p id="gdbouncerate'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[9]+'</h3><p id="gdorganicsearch'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[10]+'</h3><p id="gdpagespervisit'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[26]+'</h3><p id="gdpagetime'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[27]+'</h3><p id="gdpageload'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[28]+'</h3><p id="gdsessionduration'+b+'">&nbsp;</p></div>';l+="</div>";l+="</div>";l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();a.query=n+",bottomstats";jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.areaChartBottomStats(r)})}}}}}},refresh:function(){if(jQuery("#gadwp-areachartbottomstats"+b).length>0&&jQuery.isArray(e.areaChartBottomStatsData)){e.areaChartBottomStats(e.areaChartBottomStatsData)}if(jQuery("#gadwp-orgchartpiecharts"+b).length>0&&jQuery.isArray(e.orgChartPieChartsData)){e.orgChartPieCharts(e.orgChartPieChartsData)}if(jQuery("#gadwp-geocharttablechart"+b).length>0&&jQuery.isArray(e.geoChartTableChartData)){e.geoChartTableChart(e.geoChartTableChartData)}if(jQuery("#gadwp-orgcharttablechart"+b).length>0&&jQuery.isArray(e.orgChartTableChartData)){e.orgChartTableChart(e.orgChartTableChartData)}if(jQuery("#gadwp-404tablechart"+b).length>0&&jQuery.isArray(e.tableChartData)){e.tableChart(e.tableChartData)}},init:function(){if(!jQuery("#gadwp-reports"+b).length){return}if(jQuery("#gadwp-reports"+b).html().length){return}try{NProgress.configure({parent:"#gadwp-progressbar"+b,showSpinner:false});NProgress.start()}catch(j){e.alertMessage(gadwpItemData.i18n[0])}e.render(jQuery("#gadwp-sel-view"+b).val(),jQuery("#gadwp-sel-period"+b).val(),jQuery("#gadwp-sel-report"+b).val());jQuery(window).resize(function(){var k=jQuery(window).width()-e.oldViewPort;if((k<-5)||(k>5)){e.oldViewPort=jQuery(window).width();e.refresh()}})}};h.init();e.init();jQuery("#gadwp-sel-view"+b).change(function(){jQuery("#gadwp-reports"+b).html("");e.init()});jQuery("#gadwp-sel-period"+b).change(function(){jQuery("#gadwp-sel-metric"+b).hide();jQuery("#gadwp-reports"+b).html("");e.init()});jQuery("#gadwp-sel-report"+b).change(function(){jQuery("#gadwp-sel-metric"+b).hide();jQuery("#gadwp-reports"+b).html("");e.init()});jQuery("[id^=gadwp-swmetric-]").click(function(){c=this.id.replace("gadwp-swmetric-","");d.setCookie("default_swmetric",c);jQuery("#gadwp-swmetric-sessions").css("color","#444");jQuery("#gadwp-swmetric-users").css("color","#444");jQuery("#gadwp-swmetric-pageviews").css("color","#444");jQuery("#"+this.id).css("color","#008ec2");jQuery("#gadwp-reports"+b).html("");e.init()});if(gadwpItemData.scope=="admin-widgets"){return}else{return this.dialog({width:"auto",maxWidth:510,height:"auto",modal:true,fluid:true,dialogClass:"gadwp wp-dialog",resizable:false,title:e.getTitle(gadwpItemData.scope),position:{my:"top",at:"top+100",of:window}})}}});function GADWPReportLoad(){if(gadwpItemData.scope=="admin-widgets"){jQuery("#gadwp-window-1").gadwpItemReport(1)}else{jQuery(gadwpItemData.getSelector(gadwpItemData.scope)).click(function(){if(!jQuery("#gadwp-window-"+gadwpItemData.getID(this)).length>0){jQuery("body").append('<div id="gadwp-window-'+gadwpItemData.getID(this)+'"></div>')}jQuery("#gadwp-window-"+gadwpItemData.getID(this)).gadwpItemReport(gadwpItemData.getID(this))})}jQuery(window).resize(function(){gadwpItemData.responsiveDialog()});jQuery(document).on("dialogopen",".ui-dialog",function(a,b){gadwpItemData.responsiveDialog()})};
1
+ "use strict";if(gadwpItemData.mapsApiKey){google.charts.load("current",{mapsApiKey:gadwpItemData.mapsApiKey,packages:["corechart","table","orgchart","geochart"]})}else{google.charts.load("current",{packages:["corechart","table","orgchart","geochart"]})}google.charts.setOnLoadCallback(GADWPReportLoad);gadwpItemData.getID=function(a){if(gadwpItemData.scope=="admin-item"){if(typeof a.id=="undefined"){return 0}if(a.id.split("-")[1]=="undefined"){return 0}else{return a.id.split("-")[1]}}else{if(typeof a.id=="undefined"){return 1}if(a.id.split("-")[4]=="undefined"){return 1}else{return a.id.split("-")[4]}}};gadwpItemData.getSelector=function(a){if(a=="admin-item"){return'a[id^="gadwp-"]'}else{return'li[id^="wp-admin-bar-gadwp"] a'}};gadwpItemData.responsiveDialog=function(){var b,a,c;c=jQuery(".ui-dialog:visible");c.each(function(){b=jQuery(this).find(".ui-dialog-content").data("ui-dialog");if(b.options.fluid){a=jQuery(window).width();if(a<(parseInt(b.options.maxWidth)+50)){jQuery(this).css("max-width","90%")}else{jQuery(this).css("max-width",b.options.maxWidth+"px")}b.option("position",b.options.position)}})};jQuery.fn.extend({gadwpItemReport:function(g){var a,d,h,e,f,i,c,b="-"+g;d={setCookie:function(k,m){var j,l=new Date();if(gadwpItemData.scope=="admin-widgets"){k="gadwp_wg_"+k}else{k="gadwp_ir_"+k}l.setTime(l.getTime()+(24*60*60*1000*365));j="expires="+l.toUTCString();document.cookie=k+"="+m+"; "+j+"; path=/"},getCookie:function(j){var l,m,n,k=0;if(gadwpItemData.scope=="admin-widgets"){j="gadwp_wg_"+j+"="}else{j="gadwp_ir_"+j+"="}m=document.cookie.split(";");for(k=0;k<m.length;k++){l=m[k];while(l.charAt(0)==" "){l=l.substring(1)}if(l.indexOf(j)==0){return l.substring(j.length,l.length)}}return false},escape:function(j){div=document.createElement("div");div.appendChild(document.createTextNode(j));return div.innerHTML}};h={addOptions:function(o,n){var j,l,m,k=[];if(!d.getCookie("default_metric")||!d.getCookie("default_dimension")||!d.getCookie("default_swmetric")){j="sessions";l="30daysAgo";if(gadwpItemData.scope=="front-item"||gadwpItemData.scope=="admin-item"){c="pageviews"}else{c="sessions"}d.setCookie("default_metric",j);d.setCookie("default_dimension",l);d.setCookie("default_swmetric",c)}else{j=d.getCookie("default_metric");l=d.getCookie("default_dimension");m=d.getCookie("default_view");c=d.getCookie("default_swmetric")}if(n==false){if(gadwpItemData.scope=="front-item"||gadwpItemData.scope=="admin-item"){k=""}else{k='<span id="gadwp-swmetric-sessions" title="'+gadwpItemData.i18n[5]+'" class="dashicons dashicons-clock" style="font-size:22px;padding:4px;"></span>'}k+='<span id="gadwp-swmetric-users" title="'+gadwpItemData.i18n[6]+'" class="dashicons dashicons-admin-users" style="font-size:22px;padding:4px;"></span>';k+='<span id="gadwp-swmetric-pageviews" title="'+gadwpItemData.i18n[7]+'" class="dashicons dashicons-admin-page" style="font-size:22px;padding:4px;"></span>';jQuery(o).html(k);jQuery("#gadwp-swmetric-"+c).css("color","#008ec2")}else{jQuery.each(n,function(p,q){if(p==j||p==l||p==m){k.push('<option value="'+p+'" selected="selected">'+q+"</option>")}else{k.push('<option value="'+p+'">'+q+"</option>")}});jQuery(o).html(k.join(""))}},init:function(){var j;if(!jQuery("#gadwp-window"+b).length){return}if(jQuery("#gadwp-window"+b).html().length){return}j='<div id="gadwp-container'+b+'">';if(gadwpItemData.viewList!=false){j+='<select id="gadwp-sel-view'+b+'"></select>'}j+='<select id="gadwp-sel-period'+b+'"></select> ';j+='<select id="gadwp-sel-report'+b+'"></select>';j+='<div id="gadwp-sel-metric'+b+'" style="float:right;display:none;">';j+="</div>";j+='<div id="gadwp-progressbar'+b+'"></div>';j+='<div id="gadwp-status'+b+'"></div>';j+='<div id="gadwp-reports'+b+'"></div>';j+='<div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;margin-top:10px;">';j+=gadwpItemData.i18n[14];j+=' <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_report&utm_medium=link&utm_content=back_report&utm_campaign=gadwp" rel="nofollow" style="text-decoration:none;font-size:1em;">GADWP</a>&nbsp;';j+="</div>";j+="</div>",jQuery("#gadwp-window"+b).append(j);h.addOptions("#gadwp-sel-view"+b,gadwpItemData.viewList);h.addOptions("#gadwp-sel-period"+b,gadwpItemData.dateList);h.addOptions("#gadwp-sel-report"+b,gadwpItemData.reportList);h.addOptions("#gadwp-sel-metric"+b,false)}};e={oldViewPort:0,orgChartTableChartData:"",tableChartData:"",orgChartPieChartsData:"",geoChartTableChartData:"",areaChartBottomStatsData:"",realtime:"",rtRuns:null,i18n:null,getTitle:function(j){if(j=="admin-item"){return jQuery("#gadwp"+b).attr("title")}else{return document.getElementsByTagName("title")[0].innerHTML}},alertMessage:function(j){jQuery("#gadwp-status"+b).css({"margin-top":"3px","padding-left":"5px",height:"auto",color:"#000","border-left":"5px solid red"});jQuery("#gadwp-status"+b).html(j)},areaChartBottomStats:function(j){e.areaChartBottomStatsData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();if(a.query=="visitBounceRate,bottomstats"){e.drawAreaChart(j[0],true)}else{e.drawAreaChart(j[0],false)}}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-areachart"+b,j[0],"125px")}if(!jQuery.isNumeric(j[1])){if(jQuery.isArray(j[1])){jQuery("#gadwp-reports"+b).show();e.drawBottomStats(j[1])}else{e.throwDebug(j[1])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-bottomstats"+b,j[1],"40px")}}else{e.throwDebug(j)}NProgress.done()},orgChartPieCharts:function(j){var k=0;e.orgChartPieChartsData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();e.drawOrgChart(j[0])}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-orgchart"+b,j[0],"125px")}for(k=1;k<j.length;k++){if(!jQuery.isNumeric(j[k])){if(jQuery.isArray(j[k])){jQuery("#gadwp-reports"+b).show();e.drawPieChart("piechart-"+k,j[k],e.i18n[k])}else{e.throwDebug(j[k])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-piechart-"+k+b,j[k],"80px")}}}else{e.throwDebug(j)}NProgress.done()},geoChartTableChart:function(j){e.geoChartTableChartData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();e.drawGeoChart(j[0]);e.drawTableChart(j[0])}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-geochart"+b,j[0],"125px");e.throwError("#gadwp-tablechart"+b,j[0],"125px")}}else{e.throwDebug(j)}NProgress.done()},orgChartTableChart:function(j){e.orgChartTableChartData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();e.drawOrgChart(j[0])}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-orgchart"+b,j[0],"125px")}if(!jQuery.isNumeric(j[1])){if(jQuery.isArray(j[1])){e.drawTableChart(j[1])}else{e.throwDebug(j[1])}}else{e.throwError("#gadwp-tablechart"+b,j[1],"125px")}}else{e.throwDebug(j)}NProgress.done()},tableChart:function(j){e.tableChartData=j;if(jQuery.isArray(j)){if(!jQuery.isNumeric(j[0])){if(jQuery.isArray(j[0])){jQuery("#gadwp-reports"+b).show();e.drawTableChart(j[0])}else{e.throwDebug(j[0])}}else{jQuery("#gadwp-reports"+b).show();e.throwError("#gadwp-tablechart"+b,j[0],"125px")}}else{e.throwDebug(j)}NProgress.done()},drawTableChart:function(m){var l,j,k;l=google.visualization.arrayToDataTable(m);j={page:"enable",pageSize:10,width:"100%",allowHtml:true};k=new google.visualization.Table(document.getElementById("gadwp-tablechart"+b));k.draw(l,j)},drawOrgChart:function(m){var l,j,k;l=google.visualization.arrayToDataTable(m);j={allowCollapse:true,allowHtml:true,height:"100%"};k=new google.visualization.OrgChart(document.getElementById("gadwp-orgchart"+b));k.draw(l,j)},drawPieChart:function(o,m,n){var l,j,k;l=google.visualization.arrayToDataTable(m);j={is3D:false,tooltipText:"percentage",legend:"none",chartArea:{width:"99%",height:"80%"},title:n,pieSliceText:"value",colors:gadwpItemData.colorVariations};k=new google.visualization.PieChart(document.getElementById("gadwp-"+o+b));k.draw(l,j)},drawGeoChart:function(m){var l,j,k;l=google.visualization.arrayToDataTable(m);j={chartArea:{width:"99%",height:"90%"},colors:[gadwpItemData.colorVariations[5],gadwpItemData.colorVariations[4]]};if(gadwpItemData.region){j.region=gadwpItemData.region;j.displayMode="markers";j.datalessRegionColor="EFEFEF"}k=new google.visualization.GeoChart(document.getElementById("gadwp-geochart"+b));k.draw(l,j)},drawAreaChart:function(n,o){var m,j,l,k;m=google.visualization.arrayToDataTable(n);if(o){k=new google.visualization.NumberFormat({suffix:"%",fractionDigits:2});k.format(m,1)}j={legend:{position:"none"},pointSize:3,colors:[gadwpItemData.colorVariations[0],gadwpItemData.colorVariations[4]],chartArea:{width:"99%",height:"90%"},vAxis:{textPosition:"in",minValue:0},hAxis:{textPosition:"none"}};l=new google.visualization.AreaChart(document.getElementById("gadwp-areachart"+b));l.draw(m,j)},drawBottomStats:function(j){jQuery("#gdsessions"+b).html(j[0]);jQuery("#gdusers"+b).html(j[1]);jQuery("#gdpageviews"+b).html(j[2]);jQuery("#gdbouncerate"+b).html(j[3]);jQuery("#gdorganicsearch"+b).html(j[4]);jQuery("#gdpagespervisit"+b).html(j[5]);jQuery("#gdpagetime"+b).html(j[6]);jQuery("#gdpageload"+b).html(j[7]);jQuery("#gdsessionduration"+b).html(j[8])},rtOnlyUniqueValues:function(l,k,j){return j.indexOf(l)===k},rtCountSessions:function(k,m){var l=0,j=0;for(j=0;j<k.rows.length;j++){if(jQuery.inArray(m,k.rows[j])>-1){l+=parseInt(k.rows[j][6])}}return l},rtGenerateTooltip:function(k){var m=0,l="",j=0;for(j=0;j<k.length;j++){m+=parseInt(k[j].count);l+="<tr><td class='gadwp-pgdetailsl'>"+k[j].value+"</td><td class='gadwp-pgdetailsr'>"+k[j].count+"</td></tr>"}if(m){return("<table>"+l+"</table>")}else{return("")}},rtPageDetails:function(y,n){var w,o,r,x=0,v=0,m=0,s=0,t=0,z=0,C=0,q=0,l=0,u="",A="",p="",k="",B="";y=y.rows;for(x=0;x<y.length;x++){if(y[x][0]==n){o=y[x][5];switch(y[x][3]){case"REFERRAL":t+=parseInt(y[x][6]);u+="<tr><td class='gadwp-pgdetailsl'>"+y[x][1]+"</td><td class='gadwp-pgdetailsr'>"+y[x][6]+"</td></tr>";break;case"ORGANIC":z+=parseInt(y[x][6]);A+="<tr><td class='gadwp-pgdetailsl'>"+y[x][2]+"</td><td class='gadwp-pgdetailsr'>"+y[x][6]+"</td></tr>";break;case"SOCIAL":q+=parseInt(y[x][6]);p+="<tr><td class='gadwp-pgdetailsl'>"+y[x][1]+"</td><td class='gadwp-pgdetailsr'>"+y[x][6]+"</td></tr>";break;case"CUSTOM":l+=parseInt(y[x][6]);k+="<tr><td class='gadwp-pgdetailsl'>"+y[x][1]+"</td><td class='gadwp-pgdetailsr'>"+y[x][6]+"</td></tr>";break;case"DIRECT":C+=parseInt(y[x][6]);break}}}if(t){u="<table><tr><td>"+e.i18n[0]+"("+t+")</td></tr>"+u+"</table><br />"}if(z){A="<table><tr><td>"+e.i18n[1]+"("+z+")</td></tr>"+A+"</table><br />"}if(q){p="<table><tr><td>"+e.i18n[2]+"("+q+")</td></tr>"+p+"</table><br />"}if(l){k="<table><tr><td>"+e.i18n[3]+"("+l+")</td></tr>"+k+"</table><br />"}if(C){B="<table><tr><td>"+e.i18n[4]+"("+C+")</td></tr></table><br />"}return("<p><center><strong>"+o+"</strong></center></p>"+u+A+p+k+B)},rtRefresh:function(){if(e.render.focusFlag){a.from=false;a.to=false;a.query="realtime";jQuery.post(gadwpItemData.ajaxurl,a,function(j){if(jQuery.isArray(j)){jQuery("#gadwp-reports"+b).show();e.realtime=j[0];e.drawRealtime(e.realtime)}else{e.throwDebug(j)}NProgress.done()})}},drawRealtime:function(y){var j,n,o,w,t,r,x=0,v=[],z=[],p=[],m=[],q=[],k=[],l=[],s="",o=[],w=[],t=[],r=[],u=["REFERRAL","ORGANIC","SOCIAL","CUSTOM"],A=["DIRECT","NEW"];jQuery(function(){jQuery("#gadwp-widget *").tooltip({tooltipClass:"gadwp"})});y=y[0];if(jQuery.isNumeric(y)||typeof y==="undefined"){y=[];y.totalsForAllResults=[];y.totalsForAllResults["rt:activeUsers"]="0";y.rows=[]}if(y.totalsForAllResults["rt:activeUsers"]!==document.getElementById("gadwp-online").innerHTML){jQuery("#gadwp-online").fadeOut("slow");jQuery("#gadwp-online").fadeOut(500);jQuery("#gadwp-online").fadeOut("slow",function(){if((parseInt(y.totalsForAllResults["rt:activeUsers"]))<(parseInt(document.getElementById("gadwp-online").innerHTML))){jQuery("#gadwp-online").css({"background-color":"#FFE8E8"})}else{jQuery("#gadwp-online").css({"background-color":"#E0FFEC"})}document.getElementById("gadwp-online").innerHTML=y.totalsForAllResults["rt:activeUsers"]});jQuery("#gadwp-online").fadeIn("slow");jQuery("#gadwp-online").fadeIn(500);jQuery("#gadwp-online").fadeIn("slow",function(){jQuery("#gadwp-online").css({"background-color":"#FFFFFF"})})}if(y.totalsForAllResults["rt:activeUsers"]==0){y.rows=[]}for(x=0;x<y.rows.length;x++){v.push(y.rows[x][0]);if(y.rows[x][3]=="REFERRAL"){z.push(y.rows[x][1])}if(y.rows[x][3]=="ORGANIC"){p.push(y.rows[x][2])}if(y.rows[x][3]=="SOCIAL"){m.push(y.rows[x][1])}if(y.rows[x][3]=="CUSTOM"){k.push(y.rows[x][1])}q.push(y.rows[x][3])}n=v.filter(e.rtOnlyUniqueValues);for(x=0;x<n.length;x++){l[x]={pagepath:n[x],count:e.rtCountSessions(y,n[x])}}l.sort(function(C,B){return B.count-C.count});s="";for(x=0;x<l.length;x++){if(x<gadwpItemData.rtLimitPages){s+='<div class="gadwp-pline"><div class="gadwp-pleft"><a href="#" data-gadwp="'+e.rtPageDetails(y,l[x].pagepath)+'">'+l[x].pagepath.substring(0,70)+'</a></div><div class="gadwp-pright">'+l[x].count+"</div></div>"}}document.getElementById("gadwp-pages").innerHTML='<br /><div class="gadwp-pg">'+s+"</div>";o=z.filter(e.rtOnlyUniqueValues);for(x=0;x<o.length;x++){o[x]={value:o[x],count:e.rtCountSessions(y,o[x])}}o.sort(function(C,B){return B.count-C.count});w=p.filter(e.rtOnlyUniqueValues);for(x=0;x<w.length;x++){w[x]={value:w[x],count:e.rtCountSessions(y,w[x])}}w.sort(function(C,B){return B.count-C.count});t=m.filter(e.rtOnlyUniqueValues);for(x=0;x<t.length;x++){t[x]={value:t[x],count:e.rtCountSessions(y,t[x])}}t.sort(function(C,B){return B.count-C.count});r=k.filter(e.rtOnlyUniqueValues);for(x=0;x<r.length;x++){r[x]={value:r[x],count:e.rtCountSessions(y,r[x])}}r.sort(function(C,B){return B.count-C.count});j='<div class="gadwp-bigtext"><a href="#" data-gadwp="'+e.rtGenerateTooltip(o)+'"><div class="gadwp-bleft">'+e.i18n[0]+'</a></div><div class="gadwp-bright">'+e.rtCountSessions(y,u[0])+"</div></div>";j+='<div class="gadwp-bigtext"><a href="#" data-gadwp="'+e.rtGenerateTooltip(w)+'"><div class="gadwp-bleft">'+e.i18n[1]+'</a></div><div class="gadwp-bright">'+e.rtCountSessions(y,u[1])+"</div></div>";j+='<div class="gadwp-bigtext"><a href="#" data-gadwp="'+e.rtGenerateTooltip(t)+'"><div class="gadwp-bleft">'+e.i18n[2]+'</a></div><div class="gadwp-bright">'+e.rtCountSessions(y,u[2])+"</div></div>";j+='<div class="gadwp-bigtext"><a href="#" data-gadwp="'+e.rtGenerateTooltip(r)+'"><div class="gadwp-bleft">'+e.i18n[3]+'</a></div><div class="gadwp-bright">'+e.rtCountSessions(y,u[3])+"</div></div>";j+='<div class="gadwp-bigtext"><div class="gadwp-bleft">'+e.i18n[4]+'</div><div class="gadwp-bright">'+e.rtCountSessions(y,A[0])+"</div></div>";j+='<div class="gadwp-bigtext"><div class="gadwp-bleft">'+e.i18n[5]+'</div><div class="gadwp-bright">'+e.rtCountSessions(y,A[1])+"</div></div>";document.getElementById("gadwp-tdo-right").innerHTML=j},throwDebug:function(j){jQuery("#gadwp-status"+b).css({"margin-top":"3px","padding-left":"5px",height:"auto",color:"#000","border-left":"5px solid red"});if(j=="-24"){jQuery("#gadwp-status"+b).html(gadwpItemData.i18n[15])}else{jQuery("#gadwp-reports"+b).css({"background-color":"#F7F7F7",height:"auto","margin-top":"10px","padding-top":"50px","padding-bottom":"50px",color:"#000","text-align":"center"});jQuery("#gadwp-reports"+b).html(j);jQuery("#gadwp-reports"+b).show();jQuery("#gadwp-status"+b).html(gadwpItemData.i18n[11]);console.log("\n********************* GADWP Log ********************* \n\n"+j);a={action:"gadwp_set_error",response:j,gadwp_security_set_error:gadwpItemData.security};jQuery.post(gadwpItemData.ajaxurl,a)}},throwError:function(l,j,k){jQuery(l).css({"background-color":"#F7F7F7",height:"auto","padding-top":k,"padding-bottom":k,color:"#000","text-align":"center"});if(j==-21){jQuery(l).html(gadwpItemData.i18n[12])}else{jQuery(l).html(gadwpItemData.i18n[13]+" ("+j+")")}},render:function(j,o,n){var k,q,p,l,m;if(o=="realtime"){jQuery("#gadwp-sel-report"+b).hide()}else{jQuery("#gadwp-sel-report"+b).show();clearInterval(e.rtRuns)}jQuery("#gadwp-status"+b).html("");switch(o){case"today":q="today";p="today";break;case"yesterday":q="yesterday";p="yesterday";break;case"7daysAgo":q="7daysAgo";p="yesterday";break;case"14daysAgo":q="14daysAgo";p="yesterday";break;case"90daysAgo":q="90daysAgo";p="yesterday";break;case"365daysAgo":q="365daysAgo";p="yesterday";break;case"1095daysAgo":q="1095daysAgo";p="yesterday";break;default:q="30daysAgo";p="yesterday";break}d.setCookie("default_metric",n);d.setCookie("default_dimension",o);if(typeof j!=="undefined"){d.setCookie("default_view",j);k=j}else{k=false}if(gadwpItemData.scope=="admin-item"){a={action:"gadwp_backend_item_reports",gadwp_security_backend_item_reports:gadwpItemData.security,from:q,to:p,filter:g}}else{if(gadwpItemData.scope=="front-item"){a={action:"gadwp_frontend_item_reports",gadwp_security_frontend_item_reports:gadwpItemData.security,from:q,to:p,filter:gadwpItemData.filter}}else{a={action:"gadwp_backend_item_reports",gadwp_security_backend_item_reports:gadwpItemData.security,projectId:k,from:q,to:p}}}if(o=="realtime"){e.i18n=gadwpItemData.i18n.slice(20,26);e.render.focusFlag=1;jQuery(window).bind("focus",function(r){e.render.focusFlag=1}).bind("blur",function(r){e.render.focusFlag=0});l='<div id="gadwp-realtime'+b+'">';l+='<div class="gadwp-rt-box">';l+='<div class="gadwp-tdo-left">';l+='<div class="gadwp-online" id="gadwp-online">0</div>';l+="</div>";l+='<div class="gadwp-tdo-right" id="gadwp-tdo-right">';l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[0]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[1]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[2]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[3]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[4]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+='<div class="gadwp-bigtext">';l+='<div class="gadwp-bleft">'+e.i18n[5]+"</div>";l+='<div class="gadwp-bright">0</div>';l+="</div>";l+="</div>";l+="</div>";l+="<div>";l+='<div id="gadwp-pages" class="gadwp-pages">&nbsp;</div>';l+="</div>";l+="</div>";jQuery("#gadwp-reports"+b).html(l);e.rtRefresh(e.render.focusFlag);e.rtRuns=setInterval(e.rtRefresh,55000)}else{if(jQuery.inArray(n,["referrers","contentpages","searches"])>-1){l='<div id="gadwp-orgcharttablechart'+b+'">';l+='<div id="gadwp-orgchart'+b+'"></div>';l+='<div id="gadwp-tablechart'+b+'"></div>';l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();jQuery("#gadwp-sel-metric"+b).show();a.query="channelGrouping,"+n;a.metric=c;jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.orgChartTableChart(r)})}else{if(n=="404errors"){l='<div id="gadwp-404tablechart'+b+'">';l+='<div id="gadwp-tablechart'+b+'"></div>';l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();jQuery("#gadwp-sel-metric"+b).show();a.query=n;a.metric=c;jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.tableChart(r)})}else{if(n=="trafficdetails"||n=="technologydetails"){l='<div id="gadwp-orgchartpiecharts'+b+'">';l+='<div id="gadwp-orgchart'+b+'"></div>';l+='<div class="gadwp-floatwraper">';l+='<div id="gadwp-piechart-1'+b+'" class="halfsize floatleft"></div>';l+='<div id="gadwp-piechart-2'+b+'" class="halfsize floatright"></div>';l+="</div>";l+='<div class="gadwp-floatwraper">';l+='<div id="gadwp-piechart-3'+b+'" class="halfsize floatleft"></div>';l+='<div id="gadwp-piechart-4'+b+'" class="halfsize floatright"></div>';l+="</div>";l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();jQuery("#gadwp-sel-metric"+b).show();if(n=="trafficdetails"){a.query="channelGrouping,medium,visitorType,source,socialNetwork";e.i18n=gadwpItemData.i18n.slice(0,5)}else{e.i18n=gadwpItemData.i18n.slice(15,20);a.query="deviceCategory,browser,operatingSystem,screenResolution,mobileDeviceBranding"}a.metric=c;jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.orgChartPieCharts(r)})}else{if(n=="locations"){l='<div id="gadwp-geocharttablechart'+b+'">';l+='<div id="gadwp-geochart'+b+'"></div>';l+='<div id="gadwp-tablechart'+b+'"></div>';l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();jQuery("#gadwp-sel-metric"+b).show();a.query=n;a.metric=c;jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.geoChartTableChart(r)})}else{l='<div id="gadwp-areachartbottomstats'+b+'">';l+='<div id="gadwp-areachart'+b+'"></div>';l+='<div id="gadwp-bottomstats'+b+'">';l+='<div class="inside">';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[5]+'</h3><p id="gdsessions'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[6]+'</h3><p id="gdusers'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[7]+'</h3><p id="gdpageviews'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[8]+'</h3><p id="gdbouncerate'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[9]+'</h3><p id="gdorganicsearch'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[10]+'</h3><p id="gdpagespervisit'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[26]+'</h3><p id="gdpagetime'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[27]+'</h3><p id="gdpageload'+b+'">&nbsp;</p></div>';l+='<div class="small-box"><h3>'+gadwpItemData.i18n[28]+'</h3><p id="gdsessionduration'+b+'">&nbsp;</p></div>';l+="</div>";l+="</div>";l+="</div>";jQuery("#gadwp-reports"+b).html(l);jQuery("#gadwp-reports"+b).hide();a.query=n+",bottomstats";jQuery.post(gadwpItemData.ajaxurl,a,function(r){e.areaChartBottomStats(r)})}}}}}},refresh:function(){if(jQuery("#gadwp-areachartbottomstats"+b).length>0&&jQuery.isArray(e.areaChartBottomStatsData)){e.areaChartBottomStats(e.areaChartBottomStatsData)}if(jQuery("#gadwp-orgchartpiecharts"+b).length>0&&jQuery.isArray(e.orgChartPieChartsData)){e.orgChartPieCharts(e.orgChartPieChartsData)}if(jQuery("#gadwp-geocharttablechart"+b).length>0&&jQuery.isArray(e.geoChartTableChartData)){e.geoChartTableChart(e.geoChartTableChartData)}if(jQuery("#gadwp-orgcharttablechart"+b).length>0&&jQuery.isArray(e.orgChartTableChartData)){e.orgChartTableChart(e.orgChartTableChartData)}if(jQuery("#gadwp-404tablechart"+b).length>0&&jQuery.isArray(e.tableChartData)){e.tableChart(e.tableChartData)}},init:function(){if(!jQuery("#gadwp-reports"+b).length){return}if(jQuery("#gadwp-reports"+b).html().length){return}try{NProgress.configure({parent:"#gadwp-progressbar"+b,showSpinner:false});NProgress.start()}catch(j){e.alertMessage(gadwpItemData.i18n[0])}e.render(jQuery("#gadwp-sel-view"+b).val(),jQuery("#gadwp-sel-period"+b).val(),jQuery("#gadwp-sel-report"+b).val());jQuery(window).resize(function(){var k=jQuery(window).width()-e.oldViewPort;if((k<-5)||(k>5)){e.oldViewPort=jQuery(window).width();e.refresh()}})}};h.init();e.init();jQuery("#gadwp-sel-view"+b).change(function(){jQuery("#gadwp-reports"+b).html("");e.init()});jQuery("#gadwp-sel-period"+b).change(function(){jQuery("#gadwp-sel-metric"+b).hide();jQuery("#gadwp-reports"+b).html("");e.init()});jQuery("#gadwp-sel-report"+b).change(function(){jQuery("#gadwp-sel-metric"+b).hide();jQuery("#gadwp-reports"+b).html("");e.init()});jQuery("[id^=gadwp-swmetric-]").click(function(){c=this.id.replace("gadwp-swmetric-","");d.setCookie("default_swmetric",c);jQuery("#gadwp-swmetric-sessions").css("color","#444");jQuery("#gadwp-swmetric-users").css("color","#444");jQuery("#gadwp-swmetric-pageviews").css("color","#444");jQuery("#"+this.id).css("color","#008ec2");jQuery("#gadwp-reports"+b).html("");e.init()});if(gadwpItemData.scope=="admin-widgets"){return}else{return this.dialog({width:"auto",maxWidth:510,height:"auto",modal:true,fluid:true,dialogClass:"gadwp wp-dialog",resizable:false,title:e.getTitle(gadwpItemData.scope),position:{my:"top",at:"top+100",of:window}})}}});function GADWPReportLoad(){if(gadwpItemData.scope=="admin-widgets"){jQuery("#gadwp-window-1").gadwpItemReport(1)}else{jQuery(gadwpItemData.getSelector(gadwpItemData.scope)).click(function(){if(!jQuery("#gadwp-window-"+gadwpItemData.getID(this)).length>0){jQuery("body").append('<div id="gadwp-window-'+gadwpItemData.getID(this)+'"></div>')}jQuery("#gadwp-window-"+gadwpItemData.getID(this)).gadwpItemReport(gadwpItemData.getID(this))})}jQuery(window).resize(function(){gadwpItemData.responsiveDialog()});jQuery(document).on("dialogopen",".ui-dialog",function(a,b){gadwpItemData.responsiveDialog()})};
config.php CHANGED
@@ -47,7 +47,7 @@ if ( ! class_exists( 'GADWP_Config' ) ) {
47
  }
48
  if ( isset( $item['slug'] ) && 'google-analytics-dashboard-for-wp' == $item['slug'] ) {
49
  // Only when a minor update is available
50
- if ($this->get_major_version( GADWP_CURRENT_VERSION ) == $this->get_major_version( $item['new_version'] )){
51
  update_option( 'gadwp_got_updated', true );
52
  return ( $this->get_major_version( GADWP_CURRENT_VERSION ) == $this->get_major_version( $item['new_version'] ) );
53
  }
@@ -89,6 +89,8 @@ if ( ! class_exists( 'GADWP_Config' ) ) {
89
  'ga_dash_excludesa',
90
  'ga_pagescrolldepth_tracking',
91
  'tm_pagescrolldepth_tracking',
 
 
92
  );
93
  foreach ( $numerics as $key ) {
94
  if ( isset( $options[$key] ) ) {
@@ -136,6 +138,10 @@ if ( ! class_exists( 'GADWP_Config' ) ) {
136
  $options['ga_speed_samplerate'] = 1;
137
  }
138
 
 
 
 
 
139
  if ( isset( $options['ga_cookieexpires'] ) && $options['ga_cookieexpires'] ) { // v4.9
140
  $options['ga_cookieexpires'] = (int) $options['ga_cookieexpires'];
141
  }
@@ -291,6 +297,11 @@ if ( ! class_exists( 'GADWP_Config' ) ) {
291
  $this->options['frontend_item_reports'] = $this->options['ga_dash_frontend_stats'];
292
  }
293
 
 
 
 
 
 
294
  $unsets = array( 'ga_dash_jailadmins', // v4.7
295
  'ga_tracking_code',
296
  'ga_dash_tableid', // v4.9
@@ -362,6 +373,10 @@ if ( ! class_exists( 'GADWP_Config' ) ) {
362
  $flag = true;
363
  }
364
 
 
 
 
 
365
  if ( ! isset( $this->options['ga_event_downloads'] ) ) {
366
  $this->options['ga_event_downloads'] = 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*';
367
  $flag = true;
47
  }
48
  if ( isset( $item['slug'] ) && 'google-analytics-dashboard-for-wp' == $item['slug'] ) {
49
  // Only when a minor update is available
50
+ if ( $this->get_major_version( GADWP_CURRENT_VERSION ) == $this->get_major_version( $item['new_version'] ) ) {
51
  update_option( 'gadwp_got_updated', true );
52
  return ( $this->get_major_version( GADWP_CURRENT_VERSION ) == $this->get_major_version( $item['new_version'] ) );
53
  }
89
  'ga_dash_excludesa',
90
  'ga_pagescrolldepth_tracking',
91
  'tm_pagescrolldepth_tracking',
92
+ 'ga_speed_samplerate',
93
+ 'ga_user_samplerate',
94
  );
95
  foreach ( $numerics as $key ) {
96
  if ( isset( $options[$key] ) ) {
138
  $options['ga_speed_samplerate'] = 1;
139
  }
140
 
141
+ if ( isset( $options['ga_user_samplerate'] ) && ( $options['ga_user_samplerate'] < 1 || $options['ga_user_samplerate'] > 100 ) ) {
142
+ $options['ga_user_samplerate'] = 100;
143
+ }
144
+
145
  if ( isset( $options['ga_cookieexpires'] ) && $options['ga_cookieexpires'] ) { // v4.9
146
  $options['ga_cookieexpires'] = (int) $options['ga_cookieexpires'];
147
  }
297
  $this->options['frontend_item_reports'] = $this->options['ga_dash_frontend_stats'];
298
  }
299
 
300
+ if ( isset($this->options['ga_dash_tracking']) && 0 == $this->options['ga_dash_tracking'] ) { // v5.0.1
301
+ $this->options['ga_dash_tracking_type'] = 'disabled';
302
+ $flag = true;
303
+ }
304
+
305
  $unsets = array( 'ga_dash_jailadmins', // v4.7
306
  'ga_tracking_code',
307
  'ga_dash_tableid', // v4.9
373
  $flag = true;
374
  }
375
 
376
+ if ( ! isset( $this->options['ga_user_samplerate'] ) ) {
377
+ $this->options['ga_user_samplerate'] = 100;
378
+ }
379
+
380
  if ( ! isset( $this->options['ga_event_downloads'] ) ) {
381
  $this->options['ga_event_downloads'] = 'zip|mp3*|mpe*g|pdf|docx*|pptx*|xlsx*|rar*';
382
  $flag = true;
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}}(function(a){a(window).on("load",function(){if(gadwpUAEventsData.options.event_tracking){a("a").filter(function(){var b=new RegExp(".*\\.("+gadwpUAEventsData.options.event_downloads+")(\\?.*)?$");return this.href.match(b)}).click(function(f){var c=this.getAttribute("data-ga-category")||"download";var d=this.getAttribute("data-ga-action")||"click";var b=this.getAttribute("data-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",c,d,b,{nonInteraction:1})}else{ga("send","event",c,d,b)}});a('a[href^="mailto"]').click(function(f){var c=this.getAttribute("data-ga-category")||"email";var d=this.getAttribute("data-ga-action")||"send";var b=this.getAttribute("data-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",c,d,b,{nonInteraction:1})}else{ga("send","event",c,d,b)}});a('a[href^="tel"]').click(function(f){if(gadwpUAEventsData.options.event_bouncerate){var c=this.getAttribute("data-ga-category")||"telephone";var d=this.getAttribute("data-ga-action")||"call";var b=this.getAttribute("data-ga-label")||this.href;ga("send","event",c,d,b,{nonInteraction:1})}else{ga("send","event",c,d,b)}});if(gadwpUAEventsData.options.root_domain){a('a[href^="http"]').filter(function(){var b=new RegExp(".*\\.("+gadwpUAEventsData.options.event_downloads+")(\\?.*)?$");if(!this.href.match(b)){if(this.href.indexOf(gadwpUAEventsData.options.root_domain)==-1){return this.href}}}).click(function(f){gadwpRedirectCalled=false;gadwpRedirectLink=this.href;var c=this.getAttribute("data-ga-category")||"outbound";var d=this.getAttribute("data-ga-action")||"click";var b=this.getAttribute("data-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",c,d,b,{nonInteraction:1,hitCallback:gadwpRedirect})}else{ga("send","event",c,d,b,{hitCallback:gadwpRedirect})}if(this.target!="_blank"){if(f.isDefaultPrevented()){gadwpDefaultPrevented=true}setTimeout(gadwpRedirect,gadwpUAEventsData.options.event_timeout);return false}else{gadwpRedirectCalled=true}})}}if(gadwpUAEventsData.options.event_affiliates&&gadwpUAEventsData.options.aff_tracking){a("a").filter(function(){if(gadwpUAEventsData.options.event_affiliates!=""){var b=new RegExp("("+gadwpUAEventsData.options.event_affiliates.replace(/\//g,"/")+")");return this.href.match(b)}}).click(function(d){gadwpRedirectCalled=false;gadwpRedirectLink=this.href;var c=this.getAttribute("data-ga-category")||"affiliates";var f=this.getAttribute("data-ga-action")||"click";var b=this.getAttribute("data-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",c,f,b,{nonInteraction:1,hitCallback:gadwpRedirect})}else{ga("send","event",c,f,b,{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){a("a").filter(function(){if(this.href.indexOf(gadwpUAEventsData.options.root_domain)!=-1||this.href.indexOf("://")==-1){return this.hash}}).click(function(f){var c=this.getAttribute("data-ga-category")||"hashmark";var d=this.getAttribute("data-ga-action")||"click";var b=this.getAttribute("data-ga-label")||this.href;if(gadwpUAEventsData.options.event_bouncerate){ga("send","event",c,d,b,{nonInteraction:1})}else{ga("send","event",c,d,b)}})}if(gadwpUAEventsData.options.event_formsubmit){a('input[type="submit"]').click(function(f){gadwpSubmitObject=this;var c=gadwpSubmitObject.getAttribute("data-ga-category")||"form";var d=gadwpSubmitObject.getAttribute("data-ga-action")||"submit";var b=gadwpSubmitObject.getAttribute("data-ga-label")||gadwpSubmitObject.name||gadwpSubmitObject.value;if(gadwpUAEventsData.options.event_formsubmit){ga("send","event",c,d,b,{nonInteraction:1})}else{ga("send","event","form","submit",b)}})}if(gadwpUAEventsData.options.ga_pagescrolldepth_tracking){a.scrollDepth({percentage:true,userTiming:false,pixelDepth:false,gtmOverride:true,nonInteraction:gadwpUAEventsData.options.event_bouncerate})}})})(jQuery);
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})}});
front/js/tracking-tagmanager-events.js CHANGED
@@ -1 +1 @@
1
- (function(a){a(window).on("load",function(){a.scrollDepth({percentage:true,userTiming:false,pixelDepth:false,gtmOverride:false})})})(jQuery);
1
+ jQuery(window).on("load",function(){jQuery.scrollDepth({percentage:true,userTiming:false,pixelDepth:false,gtmOverride:false})});
front/setup.php CHANGED
@@ -98,7 +98,7 @@ if ( ! class_exists( 'GADWP_Frontend_Setup' ) ) {
98
  __( "Organic Search", 'google-analytics-dashboard-for-wp' ),
99
  __( "Pages/Session", 'google-analytics-dashboard-for-wp' ),
100
  __( "Invalid response", 'google-analytics-dashboard-for-wp' ),
101
- __( "Not enough data collected", 'google-analytics-dashboard-for-wp' ),
102
  __( "This report is unavailable", 'google-analytics-dashboard-for-wp' ),
103
  __( "report generated by", 'google-analytics-dashboard-for-wp' ), //14
104
  __( "This plugin needs an authorization:", 'google-analytics-dashboard-for-wp' ) . ' <strong>' . __( "authorize the plugin", 'google-analytics-dashboard-for-wp' ) . '</strong>!',
98
  __( "Organic Search", 'google-analytics-dashboard-for-wp' ),
99
  __( "Pages/Session", 'google-analytics-dashboard-for-wp' ),
100
  __( "Invalid response", 'google-analytics-dashboard-for-wp' ),
101
+ __( "No Data", 'google-analytics-dashboard-for-wp' ),
102
  __( "This report is unavailable", 'google-analytics-dashboard-for-wp' ),
103
  __( "report generated by", 'google-analytics-dashboard-for-wp' ), //14
104
  __( "This plugin needs an authorization:", 'google-analytics-dashboard-for-wp' ) . ' <strong>' . __( "authorize the plugin", 'google-analytics-dashboard-for-wp' ) . '</strong>!',
front/tracking-analytics.php CHANGED
@@ -11,15 +11,13 @@
11
  if ( ! defined( 'ABSPATH' ) )
12
  exit();
13
 
14
- if ( ! class_exists( 'GADWP_Tracking_Analytics' ) ) {
15
-
16
- class GADWP_Tracking_Analytics {
17
 
18
- private $gadwp;
19
 
20
- private $uaid;
21
 
22
- private $commands;
23
 
24
  public function __construct() {
25
  $this->gadwp = GADWP();
@@ -27,6 +25,85 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics' ) ) {
27
  $profile = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $this->gadwp->config->options['ga_dash_tableid_jail'] );
28
 
29
  $this->uaid = esc_html( $profile[2] );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
  $this->load_scripts();
32
 
@@ -39,11 +116,6 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics' ) ) {
39
  } else {
40
  add_action( 'wp_head', array( $this, 'output' ), 99 );
41
  }
42
-
43
- if ( $this->gadwp->config->options['amp_tracking_analytics'] ) {
44
- add_action( 'amp_post_template_head', array( $this, 'amp_add_analytics_script' ) );
45
- add_action( 'amp_post_template_footer', array( $this, 'amp_output' ) );
46
- }
47
  }
48
 
49
  /**
@@ -76,7 +148,7 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics' ) ) {
76
  * Styles & Scripts load
77
  */
78
  private function load_scripts() {
79
- 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'] ) {
80
 
81
  $root_domain = GADWP_Tools::get_root_domain();
82
 
@@ -143,6 +215,9 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics' ) ) {
143
  if ( 1 != $this->gadwp->config->options['ga_speed_samplerate'] ) {
144
  $fieldsobject['siteSpeedSampleRate'] = (int) $this->gadwp->config->options['ga_speed_samplerate'];
145
  }
 
 
 
146
  if ( $this->gadwp->config->options['ga_crossdomain_tracking'] && '' != $this->gadwp->config->options['ga_crossdomain_list'] ) {
147
  $fieldsobject['allowLinker'] = 'true';
148
  }
@@ -186,77 +261,16 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics' ) ) {
186
  $this->add( 'require', $fields );
187
  }
188
 
189
- if ( $this->gadwp->config->options['ga_author_dimindex'] && ( is_single() || is_page() ) ) {
190
- $fields = array();
191
- global $post;
192
- $author_id = $post->post_author;
193
- $author_name = get_the_author_meta( 'display_name', $author_id );
194
- $fields['dimension'] = 'dimension' . (int) $this->gadwp->config->options['ga_author_dimindex'];
195
- $fields['value'] = esc_attr( $author_name );
196
- $this->add( 'set', $fields );
197
- }
198
-
199
- if ( $this->gadwp->config->options['ga_pubyear_dimindex'] && is_single() ) {
200
- $fields = array();
201
- global $post;
202
- $date = get_the_date( 'Y', $post->ID );
203
- $fields['dimension'] = 'dimension' . (int) $this->gadwp->config->options['ga_pubyear_dimindex'];
204
- $fields['value'] = (int) $date;
205
- $this->add( 'set', $fields );
206
- }
207
-
208
- if ( $this->gadwp->config->options['ga_pubyearmonth_dimindex'] && is_single() ) {
209
- $fields = array();
210
- global $post;
211
- $date = get_the_date( 'Y-m', $post->ID );
212
- $fields['dimension'] = 'dimension' . (int) $this->gadwp->config->options['ga_pubyearmonth_dimindex'];
213
- $fields['value'] = esc_attr( $date );
214
- $this->add( 'set', $fields );
215
- }
216
-
217
- if ( $this->gadwp->config->options['ga_category_dimindex'] && is_category() ) {
218
- $fields = array();
219
- $fields['dimension'] = 'dimension' . (int) $this->gadwp->config->options['ga_category_dimindex'];
220
- $fields['value'] = esc_attr( single_tag_title( '', false ) );
221
- $this->add( 'set', $fields );
222
- }
223
- if ( $this->gadwp->config->options['ga_category_dimindex'] && is_single() ) {
224
- $fields = array();
225
- global $post;
226
- $categories = get_the_category( $post->ID );
227
- foreach ( $categories as $category ) {
228
- $fields['dimension'] = 'dimension' . (int) $this->gadwp->config->options['ga_category_dimindex'];
229
- $fields['value'] = esc_attr( $category->name );
230
- $this->add( 'set', $fields );
231
- break;
232
- }
233
- }
234
-
235
- if ( $this->gadwp->config->options['ga_tag_dimindex'] && is_single() ) {
236
- global $post;
237
- $fields = array();
238
- $post_tags_list = '';
239
- $post_tags_array = get_the_tags( $post->ID );
240
- if ( $post_tags_array ) {
241
- foreach ( $post_tags_array as $tag ) {
242
- $post_tags_list .= $tag->name . ', ';
243
- }
244
- }
245
- $post_tags_list = rtrim( $post_tags_list, ', ' );
246
- if ( $post_tags_list ) {
247
- $fields['dimension'] = 'dimension' . (int) $this->gadwp->config->options['ga_tag_dimindex'];
248
- $fields['value'] = esc_attr( $post_tags_list );
249
  $this->add( 'set', $fields );
250
  }
251
  }
252
 
253
- if ( $this->gadwp->config->options['ga_user_dimindex'] ) {
254
- $fields = array();
255
- $fields['dimension'] = 'dimension' . (int) $this->gadwp->config->options['ga_user_dimindex'];
256
- $fields['value'] = is_user_logged_in() ? 'registered' : 'guest';
257
- $this->add( 'set', $fields );
258
- }
259
-
260
  if ( $this->gadwp->config->options['ga_dash_anonim'] ) {
261
  $fields = array();
262
  $fields['option'] = 'anonymizeIp';
@@ -330,19 +344,158 @@ if ( ! class_exists( 'GADWP_Tracking_Analytics' ) ) {
330
 
331
  GADWP_Tools::load_view( 'front/views/analytics-code.php', array( 'trackingcode' => $trackingcode ) );
332
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
333
 
334
  /**
335
  * Inserts the Analytics AMP script in the head section
336
  */
337
- public function amp_add_analytics_script() {
338
- ?><script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script><?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
339
  }
340
 
341
  /**
342
  * Outputs the Google Analytics tracking code for AMP
343
  */
344
- public function amp_output() {
345
- ?><amp-analytics type="googleanalytics" id="gadwp-googleanalytics"> <script type="application/json">{"vars": { "account" : "<?php echo $this->uaid; ?>"}, "triggers": { "trackPageview": { "on": "visible", "request": "pageview" }}}</script> </amp-analytics><?php
 
 
 
 
 
 
 
 
 
 
 
 
346
  }
347
  }
348
  }
11
  if ( ! defined( 'ABSPATH' ) )
12
  exit();
13
 
14
+ if ( ! class_exists( 'GADWP_Tracking_Analytics_Base' ) ) {
 
 
15
 
16
+ class GADWP_Tracking_Analytics_Base {
17
 
18
+ protected $gadwp;
19
 
20
+ protected $uaid;
21
 
22
  public function __construct() {
23
  $this->gadwp = GADWP();
25
  $profile = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $this->gadwp->config->options['ga_dash_tableid_jail'] );
26
 
27
  $this->uaid = esc_html( $profile[2] );
28
+ }
29
+
30
+ protected function bulid_custom_dimensions() {
31
+ $custom_dimensions = array();
32
+
33
+ if ( $this->gadwp->config->options['ga_author_dimindex'] && ( is_single() || is_page() ) ) {
34
+ global $post;
35
+ $author_id = $post->post_author;
36
+ $author_name = get_the_author_meta( 'display_name', $author_id );
37
+ $index = (int) $this->gadwp->config->options['ga_author_dimindex'];
38
+ $custom_dimensions[$index] = esc_attr( $author_name );
39
+ }
40
+
41
+ if ( $this->gadwp->config->options['ga_pubyear_dimindex'] && is_single() ) {
42
+ global $post;
43
+ $date = get_the_date( 'Y', $post->ID );
44
+ $index = (int) $this->gadwp->config->options['ga_pubyear_dimindex'];
45
+ $custom_dimensions[$index] = (int) $date;
46
+ }
47
+
48
+ if ( $this->gadwp->config->options['ga_pubyearmonth_dimindex'] && is_single() ) {
49
+ global $post;
50
+ $date = get_the_date( 'Y-m', $post->ID );
51
+ $index = (int) $this->gadwp->config->options['ga_pubyearmonth_dimindex'];
52
+ $custom_dimensions[$index] = esc_attr( $date );
53
+ }
54
+
55
+ if ( $this->gadwp->config->options['ga_category_dimindex'] && is_category() ) {
56
+ $fields = array();
57
+ $index = (int) $this->gadwp->config->options['ga_category_dimindex'];
58
+ $custom_dimensions[$index] = esc_attr( single_tag_title( '', false ) );
59
+ }
60
+
61
+ if ( $this->gadwp->config->options['ga_category_dimindex'] && is_single() ) {
62
+ global $post;
63
+ $categories = get_the_category( $post->ID );
64
+ foreach ( $categories as $category ) {
65
+ $index = (int) $this->gadwp->config->options['ga_category_dimindex'];
66
+ $custom_dimensions[$index] = esc_attr( $category->name );
67
+ break;
68
+ }
69
+ }
70
+
71
+ if ( $this->gadwp->config->options['ga_tag_dimindex'] && is_single() ) {
72
+ global $post;
73
+ $fields = array();
74
+ $post_tags_list = '';
75
+ $post_tags_array = get_the_tags( $post->ID );
76
+ if ( $post_tags_array ) {
77
+ foreach ( $post_tags_array as $tag ) {
78
+ $post_tags_list .= $tag->name . ', ';
79
+ }
80
+ }
81
+ $post_tags_list = rtrim( $post_tags_list, ', ' );
82
+ if ( $post_tags_list ) {
83
+ $index = (int) $this->gadwp->config->options['ga_tag_dimindex'];
84
+ $custom_dimensions[$index] = esc_attr( $post_tags_list );
85
+ }
86
+ }
87
+
88
+ if ( $this->gadwp->config->options['ga_user_dimindex'] ) {
89
+ $fields = array();
90
+ $index = (int) $this->gadwp->config->options['ga_user_dimindex'];
91
+ $custom_dimensions[$index] = is_user_logged_in() ? 'registered' : 'guest';
92
+ }
93
+
94
+ return $custom_dimensions;
95
+ }
96
+ }
97
+ }
98
+
99
+ if ( ! class_exists( 'GADWP_Tracking_Analytics' ) ) {
100
+
101
+ class GADWP_Tracking_Analytics extends GADWP_Tracking_Analytics_Base {
102
+
103
+ private $commands;
104
+
105
+ public function __construct() {
106
+ parent::__construct();
107
 
108
  $this->load_scripts();
109
 
116
  } else {
117
  add_action( 'wp_head', array( $this, 'output' ), 99 );
118
  }
 
 
 
 
 
119
  }
120
 
121
  /**
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
 
215
  if ( 1 != $this->gadwp->config->options['ga_speed_samplerate'] ) {
216
  $fieldsobject['siteSpeedSampleRate'] = (int) $this->gadwp->config->options['ga_speed_samplerate'];
217
  }
218
+ if ( 100 != $this->gadwp->config->options['ga_user_samplerate'] ) {
219
+ $fieldsobject['sampleRate'] = (int) $this->gadwp->config->options['ga_user_samplerate'];
220
+ }
221
  if ( $this->gadwp->config->options['ga_crossdomain_tracking'] && '' != $this->gadwp->config->options['ga_crossdomain_list'] ) {
222
  $fieldsobject['allowLinker'] = 'true';
223
  }
261
  $this->add( 'require', $fields );
262
  }
263
 
264
+ $custom_dimensions = $this->bulid_custom_dimensions();
265
+ if ( ! empty( $custom_dimensions ) ) {
266
+ foreach ( $custom_dimensions as $index => $value ) {
267
+ $fields = array();
268
+ $fields['dimension'] = 'dimension' . $index;
269
+ $fields['value'] = $value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
270
  $this->add( 'set', $fields );
271
  }
272
  }
273
 
 
 
 
 
 
 
 
274
  if ( $this->gadwp->config->options['ga_dash_anonim'] ) {
275
  $fields = array();
276
  $fields['option'] = 'anonymizeIp';
344
 
345
  GADWP_Tools::load_view( 'front/views/analytics-code.php', array( 'trackingcode' => $trackingcode ) );
346
  }
347
+ }
348
+ }
349
+
350
+ if ( ! class_exists( 'GADWP_Tracking_Analytics_AMP' ) ) {
351
+
352
+ class GADWP_Tracking_Analytics_AMP extends GADWP_Tracking_Analytics_Base {
353
+
354
+ private $config;
355
+
356
+ public function __construct() {
357
+ parent::__construct();
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
  /**
364
  * Inserts the Analytics AMP script in the head section
365
  */
366
+ public function load_scripts( $data ) {
367
+ if ( ! isset( $data['amp_component_scripts'] ) ) {
368
+ $data['amp_component_scripts'] = array();
369
+ }
370
+
371
+ $data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
372
+
373
+ return $data;
374
+ }
375
+
376
+ /**
377
+ * Retrieves the AMP config array
378
+ */
379
+ public function get() {
380
+ return $this->config;
381
+ }
382
+
383
+ /**
384
+ * Stores the AMP config array
385
+ * @param array $config
386
+ */
387
+ public function set( $config ) {
388
+ $this->config = $config;
389
+ }
390
+
391
+ private function build_json() {
392
+ $this->config = array();
393
+
394
+ // Set the Tracking ID
395
+ /* @formatter:off */
396
+ $this->config['vars'] = array(
397
+ 'account' => $this->uaid,
398
+ 'documentLocation' => '${canonicalUrl}',
399
+ );
400
+ /* @formatter:on */
401
+
402
+ // Set Custom Dimensions as extraUrlParams
403
+ $custom_dimensions = $this->bulid_custom_dimensions();
404
+
405
+ if ( ! empty( $custom_dimensions ) ) {
406
+ foreach ( $custom_dimensions as $index => $value ) {
407
+ $dimension = 'cd' . $index;
408
+ $this->config['extraUrlParams'][$dimension] = $value;
409
+ }
410
+ }
411
+
412
+ // Set Triggers
413
+ /* @formatter:off */
414
+ $this->config['triggers']['gadwpTrackPageview'] = array(
415
+ 'on' => 'visible',
416
+ 'request' => 'pageview',
417
+ );
418
+ /* @formatter:on */
419
+
420
+ // Set Sampling Rate only if lower than 100%
421
+ if ( 100 != $this->gadwp->config->options['ga_user_samplerate'] ) {
422
+ /* @formatter:off */
423
+ $this->config['triggers']['gadwpTrackPageview']['sampleSpec'] = array(
424
+ 'sampleOn' => '${clientId}',
425
+ 'threshold' => (int) $this->gadwp->config->options['ga_user_samplerate'],
426
+ );
427
+ /* @formatter:on */
428
+ }
429
+
430
+ // Set Scroll events
431
+ if ( $this->gadwp->config->options['ga_pagescrolldepth_tracking'] ) {
432
+ /* @formatter:off */
433
+ $this->config['triggers']['gadwpScrollPings'] = array (
434
+ 'on' => 'scroll',
435
+ 'scrollSpec' => array(
436
+ 'verticalBoundaries' => '&#91;25, 50, 75, 100&#93;',
437
+ ),
438
+ 'request' => 'event',
439
+ 'vars' => array(
440
+ 'eventCategory' => 'Scroll Depth',
441
+ 'eventAction' => 'Percentage',
442
+ 'eventLabel' => '${verticalScrollBoundary}%',
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}',
472
+ 'eventAction' => '${gaAction}',
473
+ 'eventLabel' => '${gaLabel}',
474
+ ),
475
+ );
476
+ /* @formatter:on */
477
+ }
478
+
479
+ do_action( 'gadwp_analytics_amp_config', $this );
480
  }
481
 
482
  /**
483
  * Outputs the Google Analytics tracking code for AMP
484
  */
485
+ public function output() {
486
+ $this->build_json();
487
+
488
+ if ( version_compare( phpversion(), '5.4.0', '<' ) ) {
489
+ $json = json_encode( $this->config );
490
+ } else {
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
+
498
+ GADWP_Tools::load_view( 'front/views/analytics-amp-code.php', $data );
499
  }
500
  }
501
  }
front/tracking-tagmanager.php CHANGED
@@ -31,7 +31,7 @@ if ( ! class_exists( 'GADWP_Tracking_TagManager' ) ) {
31
  }
32
 
33
  if ( $this->gadwp->config->options['amp_tracking_tagmanager'] && $this->gadwp->config->options['amp_containerid'] ) {
34
- add_action( 'amp_post_template_head', array( $this, 'amp_add_analytics_script' ) );
35
  add_action( 'amp_post_template_footer', array( $this, 'amp_output' ) );
36
  }
37
  }
@@ -153,8 +153,14 @@ if ( ! class_exists( 'GADWP_Tracking_TagManager' ) ) {
153
  /**
154
  * Inserts the Analytics AMP script in the head section
155
  */
156
- public function amp_add_analytics_script() {
157
- ?><script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script><?php
 
 
 
 
 
 
158
  }
159
 
160
  /**
31
  }
32
 
33
  if ( $this->gadwp->config->options['amp_tracking_tagmanager'] && $this->gadwp->config->options['amp_containerid'] ) {
34
+ add_filter( 'amp_post_template_data', array( $this, 'amp_add_analytics_script' ) );
35
  add_action( 'amp_post_template_footer', array( $this, 'amp_output' ) );
36
  }
37
  }
153
  /**
154
  * Inserts the Analytics AMP script in the head section
155
  */
156
+ public function amp_add_analytics_script( $data ) {
157
+ if ( ! isset( $data['amp_component_scripts'] ) ) {
158
+ $data['amp_component_scripts'] = array();
159
+ }
160
+
161
+ $data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
162
+
163
+ return $data;
164
  }
165
 
166
  /**
front/tracking.php CHANGED
@@ -19,7 +19,7 @@ if ( ! class_exists( 'GADWP_Tracking' ) ) {
19
 
20
  public $analytics;
21
 
22
- public $amp;
23
 
24
  public $tagmanager;
25
 
@@ -29,6 +29,10 @@ if ( ! class_exists( 'GADWP_Tracking' ) ) {
29
  $this->init();
30
  }
31
 
 
 
 
 
32
  public function init() {
33
  // excluded roles
34
  if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_track_exclude'], true ) || ( $this->gadwp->config->options['ga_dash_excludesa'] && current_user_can( 'manage_network' ) ) ) {
@@ -40,6 +44,11 @@ if ( ! class_exists( 'GADWP_Tracking' ) ) {
40
  // Analytics
41
  require_once 'tracking-analytics.php';
42
  $this->analytics = new GADWP_Tracking_Analytics();
 
 
 
 
 
43
  }
44
 
45
  if ( 'tagmanager' == $this->gadwp->config->options['ga_dash_tracking_type'] && $this->gadwp->config->options['web_containerid'] ) {
19
 
20
  public $analytics;
21
 
22
+ public $analytics_amp;
23
 
24
  public $tagmanager;
25
 
29
  $this->init();
30
  }
31
 
32
+ public function tracking_code() { // Removed since 5.0
33
+ GADWP_Tools::doing_it_wrong( __METHOD__, __( "This method is deprecated, read the documentation!", 'google-analytics-dashboard-for-wp' ), '5.0' );
34
+ }
35
+
36
  public function init() {
37
  // excluded roles
38
  if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_track_exclude'], true ) || ( $this->gadwp->config->options['ga_dash_excludesa'] && current_user_can( 'manage_network' ) ) ) {
44
  // Analytics
45
  require_once 'tracking-analytics.php';
46
  $this->analytics = new GADWP_Tracking_Analytics();
47
+
48
+ if ( $this->gadwp->config->options['amp_tracking_analytics'] ) {
49
+ $this->analytics_amp = new GADWP_Tracking_Analytics_AMP();
50
+ }
51
+
52
  }
53
 
54
  if ( 'tagmanager' == $this->gadwp->config->options['ga_dash_tracking_type'] && $this->gadwp->config->options['web_containerid'] ) {
front/views/analytics-amp-code.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Author: Alin Marcu
4
+ * Copyright 2017 Alin Marcu
5
+ * Author URI: https://deconf.com
6
+ * License: GPLv2 or later
7
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
+ */
9
+ ?>
10
+ <amp-analytics type="googleanalytics" id="gadwp-googleanalytics">
11
+ <script type="application/json">
12
+ <?php echo $data['json']; ?>
13
+ </script>
14
+ </amp-analytics>
front/views/analytics-code.php CHANGED
@@ -1,4 +1,12 @@
1
-
 
 
 
 
 
 
 
 
2
  <!-- BEGIN GADWP v<?php echo GADWP_CURRENT_VERSION; ?> Universal Analytics - https://deconf.com/google-analytics-dashboard-wordpress/ -->
3
  <script>
4
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
1
+ <?php
2
+ /**
3
+ * Author: Alin Marcu
4
+ * Copyright 2017 Alin Marcu
5
+ * Author URI: https://deconf.com
6
+ * License: GPLv2 or later
7
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
+ */
9
+ ?>
10
  <!-- BEGIN GADWP v<?php echo GADWP_CURRENT_VERSION; ?> Universal Analytics - https://deconf.com/google-analytics-dashboard-wordpress/ -->
11
  <script>
12
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
front/views/optimize-code.php CHANGED
@@ -1,3 +1,12 @@
 
 
 
 
 
 
 
 
 
1
  <style>
2
  .async-hide {
3
  opacity: 0 !important
1
+ <?php
2
+ /**
3
+ * Author: Alin Marcu
4
+ * Copyright 2017 Alin Marcu
5
+ * Author URI: https://deconf.com
6
+ * License: GPLv2 or later
7
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
+ */
9
+ ?>
10
  <style>
11
  .async-hide {
12
  opacity: 0 !important
front/views/tagmanager-code.php CHANGED
@@ -1,4 +1,12 @@
1
-
 
 
 
 
 
 
 
 
2
  <!-- BEGIN GADWP v<?php echo GADWP_CURRENT_VERSION; ?> Tag Manager - https://deconf.com/google-analytics-dashboard-wordpress/ -->
3
  <script>
4
  window.dataLayer = window.dataLayer || [];
1
+ <?php
2
+ /**
3
+ * Author: Alin Marcu
4
+ * Copyright 2017 Alin Marcu
5
+ * Author URI: https://deconf.com
6
+ * License: GPLv2 or later
7
+ * License URI: http://www.gnu.org/licenses/gpl-2.0.html
8
+ */
9
+ ?>
10
  <!-- BEGIN GADWP v<?php echo GADWP_CURRENT_VERSION; ?> Tag Manager - https://deconf.com/google-analytics-dashboard-wordpress/ -->
11
  <script>
12
  window.dataLayer = window.dataLayer || [];
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.0.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.0.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
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' );
20
  }
21
 
22
  if ( ! class_exists( 'GADWP_Manager' ) ) {
install/install.php CHANGED
@@ -42,6 +42,7 @@ class GADWP_Install {
42
  $options['ga_dash_frontend_stats'] = 0;
43
  $options['ga_dash_network'] = 0;
44
  $options['ga_speed_samplerate'] = 1;
 
45
  $options['ga_event_bouncerate'] = 0;
46
  $options['ga_crossdomain_tracking'] = 0;
47
  $options['ga_crossdomain_list'] = '';
@@ -151,6 +152,8 @@ class GADWP_Install {
151
  $options['ga_dash_excludesa'] = 0;
152
  $options['ga_pagescrolldepth_tracking'] = 0;
153
  $options['tm_pagescrolldepth_tracking'] = 0;
 
 
154
 
155
  delete_option( 'ga_dash_clientid' );
156
  delete_option( 'ga_dash_clientsecret' );
42
  $options['ga_dash_frontend_stats'] = 0;
43
  $options['ga_dash_network'] = 0;
44
  $options['ga_speed_samplerate'] = 1;
45
+ $options['ga_user_samplerate'] = 100;
46
  $options['ga_event_bouncerate'] = 0;
47
  $options['ga_crossdomain_tracking'] = 0;
48
  $options['ga_crossdomain_list'] = '';
152
  $options['ga_dash_excludesa'] = 0;
153
  $options['ga_pagescrolldepth_tracking'] = 0;
154
  $options['tm_pagescrolldepth_tracking'] = 0;
155
+ $options['ga_speed_samplerate'] = 1;
156
+ $options['ga_user_samplerate'] = 100;
157
 
158
  delete_option( 'ga_dash_clientid' );
159
  delete_option( 'ga_dash_clientsecret' );
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.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -45,6 +45,7 @@ Installs the latest Google Analytics tracking code and allows full code customiz
45
  - Enhanced link attribution
46
  - Remarketing, demographics and interests tracking
47
  - Page Speed sampling rate control
 
48
  - Cross domain tracking
49
  - Exclude user roles from tracking
50
  - Accelerated Mobile Pages (AMP) support for Google Analytics
@@ -79,7 +80,25 @@ As an alternative to Google Analytics tracking code, you can use Google Tag Mana
79
  - Data Layer variables: authors, publication year, publication month, categories, tags, user type
80
  - Additional Data Layer variables for page scrolling depth
81
  - Exclude user roles from tracking
82
- - Accelerated Mobile Pages (AMP) support for Google Tag Manager
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
  = Google Analytics Dashboard for WP on Multisite =
85
 
@@ -151,6 +170,24 @@ This is a major update, please read the [release notes](https://deconf.com/googl
151
 
152
  == Changelog ==
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  = 5.0.1 =
155
  * Enhancements:
156
  * use site_url() to find the main domain name
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
 
45
  - Enhanced link attribution
46
  - Remarketing, demographics and interests tracking
47
  - Page Speed sampling rate control
48
+ - User sampling rate control
49
  - Cross domain tracking
50
  - Exclude user roles from tracking
51
  - Accelerated Mobile Pages (AMP) support for Google Analytics
80
  - Data Layer variables: authors, publication year, publication month, categories, tags, user type
81
  - Additional Data Layer variables for page scrolling depth
82
  - Exclude user roles from tracking
83
+ - Accelerated Mobile Pages (AMP) support for Google Tag Manager
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
 
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
176
+ * fixes the undeclared variable gadwpSubmitObject error on submitted forms
177
+ * added deprecation warning for tracking_code method
178
+ * fix network admin menu capabilities, props by [Maxime Culea](https://github.com/MaximeCulea)
179
+ * Enhancements:
180
+ * switch to a customized version of GAPI to avoid conflicts with other plugins
181
+ * automatically remove <em>amp/</em> from Google Analytics tracking page URL
182
+ * events tracking is now using <em>data-vars-ga-*</em> attributes instead of <em>data-ga-*</em>
183
+ * increase default report expiration cookie from 7 days to 365 days
184
+ * New Features:
185
+ * sampleRate support for web analytics and AMP
186
+ * custom dimensions tracking support for AMP
187
+ * scrolling depth tracking support for AMP
188
+ * form submit tracking support for AMP
189
+ * downloads, affiliate links, hashmarks, outbound links, telephones, e-mails tracking support for AMP
190
+
191
  = 5.0.1 =
192
  * Enhancements:
193
  * use site_url() to find the main domain name
tools/gapi.php CHANGED
@@ -32,9 +32,9 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
32
  public function __construct() {
33
  $this->gadwp = GADWP();
34
 
35
- include_once ( GADWP_DIR . 'tools/src/Google/autoload.php' );
36
- $config = new Google_Config();
37
- $config->setCacheClass( 'Google_Cache_Null' );
38
  if ( function_exists( 'curl_version' ) ) {
39
  $curlversion = curl_version();
40
  $curl_options = array();
@@ -43,10 +43,10 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
43
  }
44
  $curl_options = apply_filters( 'gadwp_curl_options', $curl_options );
45
  if ( ! empty( $curl_options ) ) {
46
- $config->setClassConfig( 'Google_IO_Curl', array( 'options' => $curl_options ) );
47
  }
48
  }
49
- $this->client = new Google_Client( $config );
50
  $this->client->setScopes( array( 'https://www.googleapis.com/auth/analytics.readonly', 'https://www.googleapis.com/auth/analytics.edit' ) );
51
  $this->client->setAccessType( 'offline' );
52
  $this->client->setApplicationName( 'Google Analytics Dashboard' );
@@ -61,16 +61,16 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
61
  $this->client->setClientId( $this->access[0] );
62
  $this->client->setClientSecret( $this->access[1] );
63
  }
64
- $this->service = new Google_Service_Analytics( $this->client );
65
  if ( $this->gadwp->config->options['ga_dash_token'] ) {
66
  $token = $this->gadwp->config->options['ga_dash_token'];
67
  if ( $token ) {
68
  try {
69
  $this->client->setAccessToken( $token );
70
  $gadwp->config->options['ga_dash_token'] = $this->client->getAccessToken();
71
- } catch ( Google_IO_Exception $e ) {
72
  GADWP_Tools::set_cache( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
73
- } catch ( Google_Service_Exception $e ) {
74
  GADWP_Tools::set_cache( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
75
  GADWP_Tools::set_cache( 'ga_dash_gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
76
  $this->reset_token();
@@ -148,36 +148,8 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
148
  * Generates and retrieves the Access Code
149
  */
150
  public function token_request() {
151
- $authUrl = $this->client->createAuthUrl();
152
- ?>
153
- <form name="input" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>" method="post">
154
- <table class="gadwp-settings-options">
155
- <tr>
156
- <td colspan="2" class="gadwp-settings-info">
157
- <?php echo __( "Use this link to get your access code:", 'google-analytics-dashboard-for-wp' ) . ' <a href="' . $authUrl . '" id="gapi-access-code" target="_blank">' . __ ( "Get Access Code", 'google-analytics-dashboard-for-wp' ) . '</a>.'; ?>
158
- </td>
159
- </tr>
160
- <tr>
161
- <td class="gadwp-settings-title">
162
- <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>
163
- </td>
164
- <td>
165
- <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')?>">
166
- </td>
167
- </tr>
168
- <tr>
169
- <td colspan="2">
170
- <hr>
171
- </td>
172
- </tr>
173
- <tr>
174
- <td colspan="2">
175
- <input type="submit" class="button button-secondary" name="ga_dash_authorize" value="<?php _e( "Save Access Code", 'google-analytics-dashboard-for-wp' ); ?>" />
176
- </td>
177
- </tr>
178
- </table>
179
- </form>
180
- <?php
181
  }
182
 
183
  /**
@@ -218,10 +190,10 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
218
  GADWP_Tools::delete_cache( 'last_error' );
219
  }
220
  return $ga_dash_profile_list;
221
- } catch ( Google_IO_Exception $e ) {
222
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
223
  return $ga_dash_profile_list;
224
- } catch ( Google_Service_Exception $e ) {
225
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
226
  GADWP_Tools::set_cache( 'gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
227
  } catch ( Exception $e ) {
@@ -273,7 +245,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
273
  * $options
274
  * @param
275
  * $serial
276
- * @return int|Google_Service_Analytics_GaData
277
  */
278
  private function handle_corereports( $projectId, $from, $to, $metrics, $options, $serial ) {
279
  try {
@@ -303,7 +275,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
303
  } else {
304
  $data = $transient;
305
  }
306
- } catch ( Google_Service_Exception $e ) {
307
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
308
  GADWP_Tools::set_cache( 'gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
309
  return $e->getCode();
@@ -314,7 +286,9 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
314
  if ( $data->getRows() > 0 ) {
315
  return $data;
316
  } else {
317
- return - 21;
 
 
318
  }
319
  }
320
 
@@ -384,6 +358,9 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
384
  if ( is_numeric( $data ) ) {
385
  return $data;
386
  }
 
 
 
387
  $gadwp_data = array( array( $dayorhour, $title ) );
388
  if ( 'today' == $from || 'yesterday' == $from ) {
389
  foreach ( $data->getRows() as $row ) {
@@ -436,7 +413,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
436
  $serial = 'qr3_' . $this->get_serial( $projectId . $from . $filter );
437
  $data = $this->handle_corereports( $projectId, $from, $to, $metrics, $options, $serial );
438
  if ( is_numeric( $data ) ) {
439
- if ( - 21 == $data ) {
440
  return array_fill( 0, 9, 0 );
441
  } else {
442
  return $data;
@@ -680,6 +657,9 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
680
  if ( is_numeric( $data ) ) {
681
  return $data;
682
  }
 
 
 
683
  $block = ( 'channelGrouping' == $query ) ? __( "Channels", 'google-analytics-dashboard-for-wp' ) : __( "Devices", 'google-analytics-dashboard-for-wp' );
684
  $gadwp_data = array( array( '<div style="color:black; font-size:1.1em">' . $block . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $data['totalsForAllResults'][$metrics] . '</div>', "" ) );
685
  foreach ( $data->getRows() as $row ) {
@@ -810,7 +790,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
810
  } else {
811
  $data = $transient;
812
  }
813
- } catch ( Google_Service_Exception $e ) {
814
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
815
  GADWP_Tools::set_cache( 'gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
816
  return $e->getCode();
@@ -852,7 +832,7 @@ if ( ! class_exists( 'GADWP_GAPI_Controller' ) ) {
852
  * $to
853
  * @param
854
  * $filter
855
- * @return number|Google_Service_Analytics_GaData
856
  */
857
  public function get( $projectId, $query, $from = false, $to = false, $filter = '', $metric = 'sessions' ) {
858
  if ( empty( $projectId ) || ! is_numeric( $projectId ) ) {
32
  public function __construct() {
33
  $this->gadwp = GADWP();
34
 
35
+ include_once ( GADWP_DIR . 'tools/src/Deconf/autoload.php' );
36
+ $config = new Deconf_Config();
37
+ $config->setCacheClass( 'Deconf_Cache_Null' );
38
  if ( function_exists( 'curl_version' ) ) {
39
  $curlversion = curl_version();
40
  $curl_options = array();
43
  }
44
  $curl_options = apply_filters( 'gadwp_curl_options', $curl_options );
45
  if ( ! empty( $curl_options ) ) {
46
+ $config->setClassConfig( 'Deconf_IO_Curl', array( 'options' => $curl_options ) );
47
  }
48
  }
49
+ $this->client = new Deconf_Client( $config );
50
  $this->client->setScopes( array( 'https://www.googleapis.com/auth/analytics.readonly', 'https://www.googleapis.com/auth/analytics.edit' ) );
51
  $this->client->setAccessType( 'offline' );
52
  $this->client->setApplicationName( 'Google Analytics Dashboard' );
61
  $this->client->setClientId( $this->access[0] );
62
  $this->client->setClientSecret( $this->access[1] );
63
  }
64
+ $this->service = new Deconf_Service_Analytics( $this->client );
65
  if ( $this->gadwp->config->options['ga_dash_token'] ) {
66
  $token = $this->gadwp->config->options['ga_dash_token'];
67
  if ( $token ) {
68
  try {
69
  $this->client->setAccessToken( $token );
70
  $gadwp->config->options['ga_dash_token'] = $this->client->getAccessToken();
71
+ } catch ( Deconf_IO_Exception $e ) {
72
  GADWP_Tools::set_cache( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
73
+ } catch ( Deconf_Service_Exception $e ) {
74
  GADWP_Tools::set_cache( 'ga_dash_lasterror', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
75
  GADWP_Tools::set_cache( 'ga_dash_gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
76
  $this->reset_token();
148
  * Generates and retrieves the Access Code
149
  */
150
  public function token_request() {
151
+ $data['authUrl'] = $this->client->createAuthUrl();
152
+ GADWP_Tools::load_view( 'admin/views/access-code.php', $data );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  }
154
 
155
  /**
190
  GADWP_Tools::delete_cache( 'last_error' );
191
  }
192
  return $ga_dash_profile_list;
193
+ } catch ( Deconf_IO_Exception $e ) {
194
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( $e ), $this->error_timeout );
195
  return $ga_dash_profile_list;
196
+ } catch ( Deconf_Service_Exception $e ) {
197
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
198
  GADWP_Tools::set_cache( 'gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
199
  } catch ( Exception $e ) {
245
  * $options
246
  * @param
247
  * $serial
248
+ * @return int|Deconf_Service_Analytics_GaData
249
  */
250
  private function handle_corereports( $projectId, $from, $to, $metrics, $options, $serial ) {
251
  try {
275
  } else {
276
  $data = $transient;
277
  }
278
+ } catch ( Deconf_Service_Exception $e ) {
279
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
280
  GADWP_Tools::set_cache( 'gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
281
  return $e->getCode();
286
  if ( $data->getRows() > 0 ) {
287
  return $data;
288
  } else {
289
+ $data->rows = array();
290
+ return $data;
291
+ // return - 21;
292
  }
293
  }
294
 
358
  if ( is_numeric( $data ) ) {
359
  return $data;
360
  }
361
+ if ( empty( $data->rows ) ) {
362
+ return - 21;
363
+ }
364
  $gadwp_data = array( array( $dayorhour, $title ) );
365
  if ( 'today' == $from || 'yesterday' == $from ) {
366
  foreach ( $data->getRows() as $row ) {
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;
657
  if ( is_numeric( $data ) ) {
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' );
664
  $gadwp_data = array( array( '<div style="color:black; font-size:1.1em">' . $block . '</div><div style="color:darkblue; font-size:1.2em">' . (int) $data['totalsForAllResults'][$metrics] . '</div>', "" ) );
665
  foreach ( $data->getRows() as $row ) {
790
  } else {
791
  $data = $transient;
792
  }
793
+ } catch ( Deconf_Service_Exception $e ) {
794
  GADWP_Tools::set_cache( 'last_error', date( 'Y-m-d H:i:s' ) . ': ' . esc_html( "(" . $e->getCode() . ") " . $e->getMessage() ), $this->error_timeout );
795
  GADWP_Tools::set_cache( 'gapi_errors', array( $e->getCode(), (array) $e->getErrors() ), $this->error_timeout );
796
  return $e->getCode();
832
  * $to
833
  * @param
834
  * $filter
835
+ * @return number|Deconf_Service_Analytics_GaData
836
  */
837
  public function get( $projectId, $query, $from = false, $to = false, $filter = '', $metric = 'sessions' ) {
838
  if ( empty( $projectId ) || ! is_numeric( $projectId ) ) {
tools/src/{Google → Deconf}/Auth/Abstract.php RENAMED
@@ -15,7 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- if (!class_exists('Google_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
@@ -24,15 +24,15 @@ if (!class_exists('Google_Client')) {
24
  * @author Chris Chabot <chabotc@google.com>
25
  *
26
  */
27
- abstract class Google_Auth_Abstract
28
  {
29
  /**
30
  * An utility function that first calls $this->auth->sign($request) and then
31
  * executes makeRequest() on that signed request. Used for when a request
32
  * should be authenticated
33
- * @param Google_Http_Request $request
34
- * @return Google_Http_Request $request
35
  */
36
- abstract public function authenticatedRequest(Google_Http_Request $request);
37
- abstract public function sign(Google_Http_Request $request);
38
  }
15
  * limitations under the License.
16
  */
17
 
18
+ if (!class_exists('Deconf_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
24
  * @author Chris Chabot <chabotc@google.com>
25
  *
26
  */
27
+ abstract class Deconf_Auth_Abstract
28
  {
29
  /**
30
  * An utility function that first calls $this->auth->sign($request) and then
31
  * executes makeRequest() on that signed request. Used for when a request
32
  * should be authenticated
33
+ * @param Deconf_Http_Request $request
34
+ * @return Deconf_Http_Request $request
35
  */
36
+ abstract public function authenticatedRequest(Deconf_Http_Request $request);
37
+ abstract public function sign(Deconf_Http_Request $request);
38
  }
tools/src/{Google → Deconf}/Auth/AppIdentity.php RENAMED
@@ -22,21 +22,21 @@
22
  */
23
  use google\appengine\api\app_identity\AppIdentityService;
24
 
25
- if (!class_exists('Google_Client')) {
26
  require_once dirname(__FILE__) . '/../autoload.php';
27
  }
28
 
29
  /**
30
  * Authentication via the Google App Engine App Identity service.
31
  */
32
- class Google_Auth_AppIdentity extends Google_Auth_Abstract
33
  {
34
- const CACHE_PREFIX = "Google_Auth_AppIdentity::";
35
  private $client;
36
  private $token = false;
37
  private $tokenScopes = false;
38
 
39
- public function __construct(Google_Client $client, $config = null)
40
  {
41
  $this->client = $client;
42
  }
@@ -91,17 +91,17 @@ class Google_Auth_AppIdentity extends Google_Auth_Abstract
91
  * (which can modify the request in what ever way fits the auth mechanism)
92
  * and then calls apiCurlIO::makeRequest on the signed request
93
  *
94
- * @param Google_Http_Request $request
95
- * @return Google_Http_Request The resulting HTTP response including the
96
  * responseHttpCode, responseHeaders and responseBody.
97
  */
98
- public function authenticatedRequest(Google_Http_Request $request)
99
  {
100
  $request = $this->sign($request);
101
  return $this->client->getIo()->makeRequest($request);
102
  }
103
 
104
- public function sign(Google_Http_Request $request)
105
  {
106
  if (!$this->token) {
107
  // No token, so nothing to do.
22
  */
23
  use google\appengine\api\app_identity\AppIdentityService;
24
 
25
+ if (!class_exists('Deconf_Client')) {
26
  require_once dirname(__FILE__) . '/../autoload.php';
27
  }
28
 
29
  /**
30
  * Authentication via the Google App Engine App Identity service.
31
  */
32
+ class Deconf_Auth_AppIdentity extends Deconf_Auth_Abstract
33
  {
34
+ const CACHE_PREFIX = "Deconf_Auth_AppIdentity::";
35
  private $client;
36
  private $token = false;
37
  private $tokenScopes = false;
38
 
39
+ public function __construct(Deconf_Client $client, $config = null)
40
  {
41
  $this->client = $client;
42
  }
91
  * (which can modify the request in what ever way fits the auth mechanism)
92
  * and then calls apiCurlIO::makeRequest on the signed request
93
  *
94
+ * @param Deconf_Http_Request $request
95
+ * @return Deconf_Http_Request The resulting HTTP response including the
96
  * responseHttpCode, responseHeaders and responseBody.
97
  */
98
+ public function authenticatedRequest(Deconf_Http_Request $request)
99
  {
100
  $request = $this->sign($request);
101
  return $this->client->getIo()->makeRequest($request);
102
  }
103
 
104
+ public function sign(Deconf_Http_Request $request)
105
  {
106
  if (!$this->token) {
107
  // No token, so nothing to do.
tools/src/{Google → Deconf}/Auth/AssertionCredentials.php RENAMED
@@ -15,14 +15,14 @@
15
  * limitations under the License.
16
  */
17
 
18
- if (!class_exists('Google_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
22
  /**
23
  * Credentials object used for OAuth 2.0 Signed JWT assertion grants.
24
  */
25
- class Google_Auth_AssertionCredentials
26
  {
27
  const MAX_TOKEN_LIFETIME_SECS = 3600;
28
 
@@ -91,7 +91,7 @@ class Google_Auth_AssertionCredentials
91
  $now = time();
92
 
93
  $jwtParams = array(
94
- 'aud' => Google_Auth_OAuth2::OAUTH2_TOKEN_URI,
95
  'scope' => $this->scopes,
96
  'iat' => $now,
97
  'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
@@ -122,14 +122,14 @@ class Google_Auth_AssertionCredentials
122
  $payload = str_replace('\/', '/', $payload);
123
 
124
  $segments = array(
125
- Google_Utils::urlSafeB64Encode(json_encode($header)),
126
- Google_Utils::urlSafeB64Encode($payload)
127
  );
128
 
129
  $signingInput = implode('.', $segments);
130
- $signer = new Google_Signer_P12($this->privateKey, $this->privateKeyPassword);
131
  $signature = $signer->sign($signingInput);
132
- $segments[] = Google_Utils::urlSafeB64Encode($signature);
133
 
134
  return implode(".", $segments);
135
  }
15
  * limitations under the License.
16
  */
17
 
18
+ if (!class_exists('Deconf_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
22
  /**
23
  * Credentials object used for OAuth 2.0 Signed JWT assertion grants.
24
  */
25
+ class Deconf_Auth_AssertionCredentials
26
  {
27
  const MAX_TOKEN_LIFETIME_SECS = 3600;
28
 
91
  $now = time();
92
 
93
  $jwtParams = array(
94
+ 'aud' => Deconf_Auth_OAuth2::OAUTH2_TOKEN_URI,
95
  'scope' => $this->scopes,
96
  'iat' => $now,
97
  'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
122
  $payload = str_replace('\/', '/', $payload);
123
 
124
  $segments = array(
125
+ Deconf_Utils::urlSafeB64Encode(json_encode($header)),
126
+ Deconf_Utils::urlSafeB64Encode($payload)
127
  );
128
 
129
  $signingInput = implode('.', $segments);
130
+ $signer = new Deconf_Signer_P12($this->privateKey, $this->privateKeyPassword);
131
  $signature = $signer->sign($signingInput);
132
+ $segments[] = Deconf_Utils::urlSafeB64Encode($signature);
133
 
134
  return implode(".", $segments);
135
  }
tools/src/{Google → Deconf}/Auth/ComputeEngine.php RENAMED
@@ -15,7 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- if (!class_exists('Google_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
@@ -25,14 +25,14 @@ if (!class_exists('Google_Client')) {
25
  * and the appropriate scopes.
26
  * @author Jonathan Parrott <jon.wayne.parrott@gmail.com>
27
  */
28
- class Google_Auth_ComputeEngine extends Google_Auth_Abstract
29
  {
30
  const METADATA_AUTH_URL =
31
  'http://metadata/computeMetadata/v1/instance/service-accounts/default/token';
32
  private $client;
33
  private $token;
34
 
35
- public function __construct(Google_Client $client, $config = null)
36
  {
37
  $this->client = $client;
38
  }
@@ -43,11 +43,11 @@ class Google_Auth_ComputeEngine extends Google_Auth_Abstract
43
  * (which can modify the request in what ever way fits the auth mechanism)
44
  * and then calls apiCurlIO::makeRequest on the signed request
45
  *
46
- * @param Google_Http_Request $request
47
- * @return Google_Http_Request The resulting HTTP response including the
48
  * responseHttpCode, responseHeaders and responseBody.
49
  */
50
- public function authenticatedRequest(Google_Http_Request $request)
51
  {
52
  $request = $this->sign($request);
53
  return $this->client->getIo()->makeRequest($request);
@@ -55,16 +55,16 @@ class Google_Auth_ComputeEngine extends Google_Auth_Abstract
55
 
56
  /**
57
  * @param string $token
58
- * @throws Google_Auth_Exception
59
  */
60
  public function setAccessToken($token)
61
  {
62
  $token = json_decode($token, true);
63
  if ($token == null) {
64
- throw new Google_Auth_Exception('Could not json decode the token');
65
  }
66
  if (! isset($token['access_token'])) {
67
- throw new Google_Auth_Exception("Invalid token format");
68
  }
69
  $token['created'] = time();
70
  $this->token = $token;
@@ -77,15 +77,15 @@ class Google_Auth_ComputeEngine extends Google_Auth_Abstract
77
 
78
  /**
79
  * Acquires a new access token from the compute engine metadata server.
80
- * @throws Google_Auth_Exception
81
  */
82
  public function acquireAccessToken()
83
  {
84
- $request = new Google_Http_Request(
85
  self::METADATA_AUTH_URL,
86
  'GET',
87
  array(
88
- 'Metadata-Flavor' => 'Google'
89
  )
90
  );
91
  $request->disableGzip();
@@ -96,7 +96,7 @@ class Google_Auth_ComputeEngine extends Google_Auth_Abstract
96
  $this->token['created'] = time();
97
  return $this->getAccessToken();
98
  } else {
99
- throw new Google_Auth_Exception(
100
  sprintf(
101
  "Error fetching service account access token, message: '%s'",
102
  $response->getResponseBody()
@@ -108,11 +108,11 @@ class Google_Auth_ComputeEngine extends Google_Auth_Abstract
108
 
109
  /**
110
  * Include an accessToken in a given apiHttpRequest.
111
- * @param Google_Http_Request $request
112
- * @return Google_Http_Request
113
- * @throws Google_Auth_Exception
114
  */
115
- public function sign(Google_Http_Request $request)
116
  {
117
  if ($this->isAccessTokenExpired()) {
118
  $this->acquireAccessToken();
15
  * limitations under the License.
16
  */
17
 
18
+ if (!class_exists('Deconf_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
25
  * and the appropriate scopes.
26
  * @author Jonathan Parrott <jon.wayne.parrott@gmail.com>
27
  */
28
+ class Deconf_Auth_ComputeEngine extends Deconf_Auth_Abstract
29
  {
30
  const METADATA_AUTH_URL =
31
  'http://metadata/computeMetadata/v1/instance/service-accounts/default/token';
32
  private $client;
33
  private $token;
34
 
35
+ public function __construct(Deconf_Client $client, $config = null)
36
  {
37
  $this->client = $client;
38
  }
43
  * (which can modify the request in what ever way fits the auth mechanism)
44
  * and then calls apiCurlIO::makeRequest on the signed request
45
  *
46
+ * @param Deconf_Http_Request $request
47
+ * @return Deconf_Http_Request The resulting HTTP response including the
48
  * responseHttpCode, responseHeaders and responseBody.
49
  */
50
+ public function authenticatedRequest(Deconf_Http_Request $request)
51
  {
52
  $request = $this->sign($request);
53
  return $this->client->getIo()->makeRequest($request);
55
 
56
  /**
57
  * @param string $token
58
+ * @throws Deconf_Auth_Exception
59
  */
60
  public function setAccessToken($token)
61
  {
62
  $token = json_decode($token, true);
63
  if ($token == null) {
64
+ throw new Deconf_Auth_Exception('Could not json decode the token');
65
  }
66
  if (! isset($token['access_token'])) {
67
+ throw new Deconf_Auth_Exception("Invalid token format");
68
  }
69
  $token['created'] = time();
70
  $this->token = $token;
77
 
78
  /**
79
  * Acquires a new access token from the compute engine metadata server.
80
+ * @throws Deconf_Auth_Exception
81
  */
82
  public function acquireAccessToken()
83
  {
84
+ $request = new Deconf_Http_Request(
85
  self::METADATA_AUTH_URL,
86
  'GET',
87
  array(
88
+ 'Metadata-Flavor' => 'Deconf'
89
  )
90
  );
91
  $request->disableGzip();
96
  $this->token['created'] = time();
97
  return $this->getAccessToken();
98
  } else {
99
+ throw new Deconf_Auth_Exception(
100
  sprintf(
101
  "Error fetching service account access token, message: '%s'",
102
  $response->getResponseBody()
108
 
109
  /**
110
  * Include an accessToken in a given apiHttpRequest.
111
+ * @param Deconf_Http_Request $request
112
+ * @return Deconf_Http_Request
113
+ * @throws Deconf_Auth_Exception
114
  */
115
+ public function sign(Deconf_Http_Request $request)
116
  {
117
  if ($this->isAccessTokenExpired()) {
118
  $this->acquireAccessToken();
tools/src/{Google → Deconf}/Auth/Exception.php RENAMED
@@ -15,10 +15,10 @@
15
  * limitations under the License.
16
  */
17
 
18
- if (!class_exists('Google_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
22
- class Google_Auth_Exception extends Google_Exception
23
  {
24
  }
15
  * limitations under the License.
16
  */
17
 
18
+ if (!class_exists('Deconf_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
22
+ class Deconf_Auth_Exception extends Deconf_Exception
23
  {
24
  }
tools/src/{Google → Deconf}/Auth/LoginTicket.php RENAMED
@@ -15,7 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- if (!class_exists('Google_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
@@ -24,7 +24,7 @@ if (!class_exists('Google_Client')) {
24
  *
25
  * @author Brian Eaton <beaton@google.com>
26
  */
27
- class Google_Auth_LoginTicket
28
  {
29
  const USER_ATTR = "sub";
30
 
@@ -48,7 +48,7 @@ class Google_Auth_LoginTicket
48
 
49
  /**
50
  * Returns the numeric identifier for the user.
51
- * @throws Google_Auth_Exception
52
  * @return
53
  */
54
  public function getUserId()
@@ -56,7 +56,7 @@ class Google_Auth_LoginTicket
56
  if (array_key_exists(self::USER_ATTR, $this->payload)) {
57
  return $this->payload[self::USER_ATTR];
58
  }
59
- throw new Google_Auth_Exception("No user_id in token");
60
  }
61
 
62
  /**
15
  * limitations under the License.
16
  */
17
 
18
+ if (!class_exists('Deconf_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
24
  *
25
  * @author Brian Eaton <beaton@google.com>
26
  */
27
+ class Deconf_Auth_LoginTicket
28
  {
29
  const USER_ATTR = "sub";
30
 
48
 
49
  /**
50
  * Returns the numeric identifier for the user.
51
+ * @throws Deconf_Auth_Exception
52
  * @return
53
  */
54
  public function getUserId()
56
  if (array_key_exists(self::USER_ATTR, $this->payload)) {
57
  return $this->payload[self::USER_ATTR];
58
  }
59
+ throw new Deconf_Auth_Exception("No user_id in token");
60
  }
61
 
62
  /**
tools/src/{Google → Deconf}/Auth/OAuth2.php RENAMED
@@ -15,7 +15,7 @@
15
  * limitations under the License.
16
  */
17
 
18
- if (!class_exists('Google_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
@@ -23,7 +23,7 @@ if (!class_exists('Google_Client')) {
23
  * Authentication class that deals with the OAuth 2 web-server authentication flow
24
  *
25
  */
26
- class Google_Auth_OAuth2 extends Google_Auth_Abstract
27
  {
28
  const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke';
29
  const OAUTH2_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token';
@@ -34,7 +34,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
34
  const OAUTH2_ISSUER = 'accounts.google.com';
35
  const OAUTH2_ISSUER_HTTPS = 'https://accounts.google.com';
36
 
37
- /** @var Google_Auth_AssertionCredentials $assertionCredentials */
38
  private $assertionCredentials;
39
 
40
  /**
@@ -48,7 +48,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
48
  private $token = array();
49
 
50
  /**
51
- * @var Google_Client the base client
52
  */
53
  private $client;
54
 
@@ -56,7 +56,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
56
  * Instantiates the class, but does not initiate the login flow, leaving it
57
  * to the discretion of the caller.
58
  */
59
- public function __construct(Google_Client $client)
60
  {
61
  $this->client = $client;
62
  }
@@ -67,11 +67,11 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
67
  * (which can modify the request in what ever way fits the auth mechanism)
68
  * and then calls apiCurlIO::makeRequest on the signed request
69
  *
70
- * @param Google_Http_Request $request
71
- * @return Google_Http_Request The resulting HTTP response including the
72
  * responseHttpCode, responseHeaders and responseBody.
73
  */
74
- public function authenticatedRequest(Google_Http_Request $request)
75
  {
76
  $request = $this->sign($request);
77
  return $this->client->getIo()->makeRequest($request);
@@ -80,13 +80,13 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
80
  /**
81
  * @param string $code
82
  * @param boolean $crossClient
83
- * @throws Google_Auth_Exception
84
  * @return string
85
  */
86
  public function authenticate($code, $crossClient = false)
87
  {
88
  if (strlen($code) == 0) {
89
- throw new Google_Auth_Exception("Invalid code");
90
  }
91
 
92
  $arguments = array(
@@ -102,7 +102,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
102
 
103
  // We got here from the redirect from a successful authorization grant,
104
  // fetch the access token
105
- $request = new Google_Http_Request(
106
  self::OAUTH2_TOKEN_URI,
107
  'POST',
108
  array(),
@@ -123,7 +123,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
123
  $errorText .= ": " . $decodedResponse['error_description'];
124
  }
125
  }
126
- throw new Google_Auth_Exception(
127
  sprintf(
128
  "Error fetching OAuth2 access token, message: '%s'",
129
  $errorText
@@ -177,16 +177,16 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
177
 
178
  /**
179
  * @param string $token
180
- * @throws Google_Auth_Exception
181
  */
182
  public function setAccessToken($token)
183
  {
184
  $token = json_decode($token, true);
185
  if ($token == null) {
186
- throw new Google_Auth_Exception('Could not json decode the token');
187
  }
188
  if (! isset($token['access_token'])) {
189
- throw new Google_Auth_Exception("Invalid token format");
190
  }
191
  $this->token = $token;
192
  }
@@ -210,18 +210,18 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
210
  $this->state = $state;
211
  }
212
 
213
- public function setAssertionCredentials(Google_Auth_AssertionCredentials $creds)
214
  {
215
  $this->assertionCredentials = $creds;
216
  }
217
 
218
  /**
219
  * Include an accessToken in a given apiHttpRequest.
220
- * @param Google_Http_Request $request
221
- * @return Google_Http_Request
222
- * @throws Google_Auth_Exception
223
  */
224
- public function sign(Google_Http_Request $request)
225
  {
226
  // add the developer key to the request before signing it
227
  if ($this->client->getClassConfig($this, 'developer_key')) {
@@ -246,7 +246,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
246
  ." are not returned for responses that were auto-approved.";
247
 
248
  $this->client->getLogger()->error($error);
249
- throw new Google_Auth_Exception($error);
250
  }
251
  $this->refreshToken($this->token['refresh_token']);
252
  }
@@ -281,7 +281,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
281
 
282
  /**
283
  * Fetches a fresh access token with a given assertion token.
284
- * @param Google_Auth_AssertionCredentials $assertionCredentials optional.
285
  * @return void
286
  */
287
  public function refreshTokenWithAssertion($assertionCredentials = null)
@@ -333,7 +333,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
333
  $this->client->getLogger()->info('OAuth2 access token refresh');
334
  }
335
 
336
- $http = new Google_Http_Request(
337
  self::OAUTH2_TOKEN_URI,
338
  'POST',
339
  array(),
@@ -347,11 +347,11 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
347
  if (200 == $code) {
348
  $token = json_decode($body, true);
349
  if ($token == null) {
350
- throw new Google_Auth_Exception("Could not json decode the access token");
351
  }
352
 
353
  if (! isset($token['access_token']) || ! isset($token['expires_in'])) {
354
- throw new Google_Auth_Exception("Invalid token format");
355
  }
356
 
357
  if (isset($token['id_token'])) {
@@ -361,14 +361,14 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
361
  $this->token['expires_in'] = $token['expires_in'];
362
  $this->token['created'] = time();
363
  } else {
364
- throw new Google_Auth_Exception("Error refreshing the OAuth2 token, message: '$body'", $code);
365
  }
366
  }
367
 
368
  /**
369
  * Revoke an OAuth2 access token or refresh token. This method will revoke the current access
370
  * token, if a token isn't provided.
371
- * @throws Google_Auth_Exception
372
  * @param string|null $token The token (access token or a refresh token) that should be revoked.
373
  * @return boolean Returns True if the revocation was successful, otherwise False.
374
  */
@@ -384,7 +384,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
384
  $token = $this->token['access_token'];
385
  }
386
  }
387
- $request = new Google_Http_Request(
388
  self::OAUTH2_REVOKE_URI,
389
  'POST',
390
  array(),
@@ -432,7 +432,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
432
  * Retrieve and cache a certificates file.
433
  *
434
  * @param $url string location
435
- * @throws Google_Auth_Exception
436
  * @return array certificates
437
  */
438
  public function retrieveCertsFromLocation($url)
@@ -443,7 +443,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
443
  if ($file) {
444
  return json_decode($file, true);
445
  } else {
446
- throw new Google_Auth_Exception(
447
  "Failed to retrieve verification certificates: '" .
448
  $url . "'."
449
  );
@@ -452,7 +452,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
452
 
453
  // This relies on makeRequest caching certificate responses.
454
  $request = $this->client->getIo()->makeRequest(
455
- new Google_Http_Request(
456
  $url
457
  )
458
  );
@@ -462,7 +462,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
462
  return $certs;
463
  }
464
  }
465
- throw new Google_Auth_Exception(
466
  "Failed to retrieve verification certificates: '" .
467
  $request->getResponseBody() . "'.",
468
  $request->getResponseHttpCode()
@@ -477,7 +477,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
477
  *
478
  * @param $id_token
479
  * @param $audience
480
- * @return Google_Auth_LoginTicket
481
  */
482
  public function verifyIdToken($id_token = null, $audience = null)
483
  {
@@ -505,7 +505,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
505
  * @param $required_audience string the expected consumer of the token
506
  * @param [$issuer] the expected issues, defaults to Google
507
  * @param [$max_expiry] the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS
508
- * @throws Google_Auth_Exception
509
  * @return mixed token information if valid, false if not
510
  */
511
  public function verifySignedJwtWithCerts(
@@ -522,28 +522,28 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
522
 
523
  $segments = explode(".", $jwt);
524
  if (count($segments) != 3) {
525
- throw new Google_Auth_Exception("Wrong number of segments in token: $jwt");
526
  }
527
  $signed = $segments[0] . "." . $segments[1];
528
- $signature = Google_Utils::urlSafeB64Decode($segments[2]);
529
 
530
  // Parse envelope.
531
- $envelope = json_decode(Google_Utils::urlSafeB64Decode($segments[0]), true);
532
  if (!$envelope) {
533
- throw new Google_Auth_Exception("Can't parse token envelope: " . $segments[0]);
534
  }
535
 
536
  // Parse token
537
- $json_body = Google_Utils::urlSafeB64Decode($segments[1]);
538
  $payload = json_decode($json_body, true);
539
  if (!$payload) {
540
- throw new Google_Auth_Exception("Can't parse token payload: " . $segments[1]);
541
  }
542
 
543
  // Check signature
544
  $verified = false;
545
  foreach ($certs as $keyName => $pem) {
546
- $public_key = new Google_Verifier_Pem($pem);
547
  if ($public_key->verify($signed, $signature)) {
548
  $verified = true;
549
  break;
@@ -551,7 +551,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
551
  }
552
 
553
  if (!$verified) {
554
- throw new Google_Auth_Exception("Invalid token signature: $jwt");
555
  }
556
 
557
  // Check issued-at timestamp
@@ -560,7 +560,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
560
  $iat = $payload["iat"];
561
  }
562
  if (!$iat) {
563
- throw new Google_Auth_Exception("No issue time in token: $json_body");
564
  }
565
  $earliest = $iat - self::CLOCK_SKEW_SECS;
566
 
@@ -571,17 +571,17 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
571
  $exp = $payload["exp"];
572
  }
573
  if (!$exp) {
574
- throw new Google_Auth_Exception("No expiration time in token: $json_body");
575
  }
576
  if ($exp >= $now + $max_expiry) {
577
- throw new Google_Auth_Exception(
578
  sprintf("Expiration time too far in future: %s", $json_body)
579
  );
580
  }
581
 
582
  $latest = $exp + self::CLOCK_SKEW_SECS;
583
  if ($now < $earliest) {
584
- throw new Google_Auth_Exception(
585
  sprintf(
586
  "Token used too early, %s < %s: %s",
587
  $now,
@@ -591,7 +591,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
591
  );
592
  }
593
  if ($now > $latest) {
594
- throw new Google_Auth_Exception(
595
  sprintf(
596
  "Token used too late, %s > %s: %s",
597
  $now,
@@ -605,7 +605,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
605
  // @see https://developers.google.com/identity/sign-in/web/backend-auth
606
  $iss = $payload['iss'];
607
  if ($issuer && !in_array($iss, (array) $issuer)) {
608
- throw new Google_Auth_Exception(
609
  sprintf(
610
  "Invalid issuer, %s not in %s: %s",
611
  $iss,
@@ -618,7 +618,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
618
  // Check audience
619
  $aud = $payload["aud"];
620
  if ($aud != $required_audience) {
621
- throw new Google_Auth_Exception(
622
  sprintf(
623
  "Wrong recipient, %s != %s:",
624
  $aud,
@@ -629,7 +629,7 @@ class Google_Auth_OAuth2 extends Google_Auth_Abstract
629
  }
630
 
631
  // All good.
632
- return new Google_Auth_LoginTicket($envelope, $payload);
633
  }
634
 
635
  /**
15
  * limitations under the License.
16
  */
17
 
18
+ if (!class_exists('Deconf_Client')) {
19
  require_once dirname(__FILE__) . '/../autoload.php';
20
  }
21
 
23
  * Authentication class that deals with the OAuth 2 web-server authentication flow
24
  *
25
  */
26
+ class Deconf_Auth_OAuth2 extends Deconf_Auth_Abstract
27
  {
28
  const OAUTH2_REVOKE_URI = 'https://accounts.google.com/o/oauth2/revoke';
29
  const OAUTH2_TOKEN_URI = 'https://accounts.google.com/o/oauth2/token';
34
  const OAUTH2_ISSUER = 'accounts.google.com';
35
  const OAUTH2_ISSUER_HTTPS = 'https://accounts.google.com';
36
 
37
+ /** @var Deconf_Auth_AssertionCredentials $assertionCredentials */
38
  private $assertionCredentials;
39
 
40
  /**
48
  private $token = array();
4