Google Analytics Dashboard for WP (GADWP) - Version 4.8

Version Description

  • Enhancement: optimize the number of ajax requests
  • Enhancement: new versioning standard for a better management of automatic updates (M.M.m.u)
  • Enhancement: JavaScript code cleanup and optimization
  • Enhancement: memory usage optimization
  • Enhancement: small assets fixes, UX improvements, props by Adrian Pop
  • Enhancement: introducing reports for all frontend web pages (new feature)
  • Enhancement: gadwp_frontenditem_uri filter to allow URI corrections for frontend item reports
  • Bug Fix: avoid double encoding of UTF-8 URIs
  • Bug Fix: 100% number formatting issue on bounce rate report
Download this release

Release Info

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

Code changes from version 4.7.5 to 4.8

admin/ajax-actions.php CHANGED
@@ -7,125 +7,139 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
-
13
- if (! class_exists('GADWP_Backend_Ajax')) {
14
-
15
- final class GADWP_Backend_Ajax
16
- {
17
-
18
- private $gadwp;
19
-
20
- public function __construct()
21
- {
22
- $this->gadwp = GADWP();
23
-
24
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && (1 == $this->gadwp->config->options['dashboard_widget'])) {
25
- // Admin Widget action
26
- add_action('wp_ajax_gadash_get_widgetreports', array(
27
- $this,
28
- 'ajax_widget_reports'
29
- ));
30
- }
31
-
32
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && (1 == $this->gadwp->config->options['item_reports'])) {
33
- // Items action
34
- add_action('wp_ajax_gadwp_get_ItemReports', array(
35
- $this,
36
- 'ajax_item_reports'
37
- ));
38
- }
39
- }
40
-
41
- /**
42
- * Ajax handler for Items (posts/pages)
43
- *
44
- * @return json|int
45
- */
46
- public function ajax_item_reports()
47
- {
48
- if (! isset($_REQUEST['gadwp_security_item_reports']) || ! wp_verify_nonce($_REQUEST['gadwp_security_item_reports'], 'gadwp_get_itemreports')) {
49
- wp_die(- 30);
50
- }
51
- $from = $_REQUEST['from'];
52
- $to = $_REQUEST['to'];
53
- $query = $_REQUEST['query'];
54
- $filter_id = $_REQUEST['filter'];
55
- if (ob_get_length()) {
56
- ob_clean();
57
- }
58
-
59
- if (! GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) || 0 == $this->gadwp->config->options['item_reports']) {
60
- wp_die(- 31);
61
- }
62
- if ($this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail'] && $from && $to) {
63
- if (null === $this->gadwp->gapi_controller) {
64
- $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
65
- }
66
- } else {
67
- wp_die(- 24);
68
- }
69
- $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
70
- $profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId);
71
- if (isset($profile_info[4])) {
72
- $this->gadwp->gapi_controller->timeshift = $profile_info[4];
73
- } else {
74
- $this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time();
75
- }
76
-
77
- $uri_parts = explode('/', get_permalink($filter_id), 4);
78
-
79
- if (isset($uri_parts[3])) {
80
- $uri = '/' . $uri_parts[3];
81
- } else {
82
- wp_die(- 25);
83
- }
84
-
85
- // allow URL correction before sending an API request
86
- $filter = apply_filters('gadwp_backenditem_uri', $uri);
87
-
88
- //Encode URL
89
- $filter = rawurlencode($filter);
90
-
91
- $this->gadwp->gapi_controller->get($projectId, $query, $from, $to, $filter);
92
- }
93
-
94
- /**
95
- * Ajax handler for Admin Widget
96
- *
97
- * @return json|int
98
- */
99
- public function ajax_widget_reports()
100
- {
101
- if (! isset($_REQUEST['gadash_security_widget_reports']) || ! wp_verify_nonce($_REQUEST['gadash_security_widget_reports'], 'gadash_get_widgetreports')) {
102
- wp_die(- 30);
103
- }
104
- $projectId = $_REQUEST['projectId'];
105
- $from = $_REQUEST['from'];
106
- $to = $_REQUEST['to'];
107
- $query = $_REQUEST['query'];
108
- if (ob_get_length()) {
109
- ob_clean();
110
- }
111
-
112
- if (! GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) || 0 == $this->gadwp->config->options['dashboard_widget']) {
113
- wp_die(- 31);
114
- }
115
- if ($this->gadwp->config->options['ga_dash_token'] && $projectId && $from && $to) {
116
- if (null === $this->gadwp->gapi_controller) {
117
- $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
118
- }
119
- } else {
120
- wp_die(- 24);
121
- }
122
- $profile_info = GADWP_Tools::get_selected_profile($this->gadwp->config->options['ga_dash_profile_list'], $projectId);
123
- if (isset($profile_info[4])) {
124
- $this->gadwp->gapi_controller->timeshift = $profile_info[4];
125
- } else {
126
- $this->gadwp->gapi_controller->timeshift = (int) current_time('timestamp') - time();
127
- }
128
- $this->gadwp->gapi_controller->get($projectId, $query, $from, $to);
129
- }
130
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
131
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
+
13
+ if ( ! class_exists( 'GADWP_Backend_Ajax' ) ) {
14
+
15
+ final class GADWP_Backend_Ajax {
16
+
17
+ private $gadwp;
18
+
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
21
+
22
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) && ( 1 == $this->gadwp->config->options['dashboard_widget'] ) ) {
23
+ // Admin Widget action
24
+ add_action( 'wp_ajax_gadash_get_widgetreports', array( $this, 'ajax_widget_reports' ) );
25
+ }
26
+
27
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) && ( 1 == $this->gadwp->config->options['backend_item_reports'] ) ) {
28
+ // Items action
29
+ add_action( 'wp_ajax_gadwp_backend_item_reports', array( $this, 'ajax_item_reports' ) );
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Ajax handler for Item Reports
35
+ *
36
+ * @return json|int
37
+ */
38
+ public function ajax_item_reports() {
39
+ if ( ! isset( $_REQUEST['gadwp_security_backend_item_reports'] ) || ! wp_verify_nonce( $_REQUEST['gadwp_security_backend_item_reports'], 'gadwp_backend_item_reports' ) ) {
40
+ wp_die( - 30 );
41
+ }
42
+
43
+ $from = $_REQUEST['from'];
44
+ $to = $_REQUEST['to'];
45
+ $query = $_REQUEST['query'];
46
+ $filter_id = $_REQUEST['filter'];
47
+
48
+ if ( ob_get_length() ) {
49
+ ob_clean();
50
+ }
51
+
52
+ if ( ! GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) || 0 == $this->gadwp->config->options['backend_item_reports'] ) {
53
+ wp_die( - 31 );
54
+ }
55
+ if ( $this->gadwp->config->options['ga_dash_token'] && $this->gadwp->config->options['ga_dash_tableid_jail'] && $from && $to ) {
56
+ if ( null === $this->gadwp->gapi_controller ) {
57
+ $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
58
+ }
59
+ } else {
60
+ wp_die( - 24 );
61
+ }
62
+ $projectId = $this->gadwp->config->options['ga_dash_tableid_jail'];
63
+ $profile_info = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $projectId );
64
+ if ( isset( $profile_info[4] ) ) {
65
+ $this->gadwp->gapi_controller->timeshift = $profile_info[4];
66
+ } else {
67
+ $this->gadwp->gapi_controller->timeshift = (int) current_time( 'timestamp' ) - time();
68
+ }
69
+
70
+ $uri_parts = explode( '/', get_permalink( $filter_id ), 4 );
71
+
72
+ if ( isset( $uri_parts[3] ) ) {
73
+ $uri = '/' . $uri_parts[3];
74
+ } else {
75
+ wp_die( - 25 );
76
+ }
77
+
78
+ // allow URL correction before sending an API request
79
+ $filter = apply_filters( 'gadwp_backenditem_uri', $uri );
80
+
81
+ // Encode URL
82
+ $filter = rawurlencode( rawurldecode( $filter ) );
83
+
84
+ $queries = explode( ',', $query );
85
+
86
+ $results = array();
87
+
88
+ foreach ( $queries as $value ) {
89
+ $results[] = $this->gadwp->gapi_controller->get( $projectId, $value, $from, $to, $filter );
90
+ }
91
+
92
+ wp_send_json( $results );
93
+ }
94
+
95
+ /**
96
+ * Ajax handler for Admin Widget
97
+ *
98
+ * @return json|int
99
+ */
100
+ public function ajax_widget_reports() {
101
+ if ( ! isset( $_REQUEST['gadash_security_widget_reports'] ) || ! wp_verify_nonce( $_REQUEST['gadash_security_widget_reports'], 'gadash_get_widgetreports' ) ) {
102
+ wp_die( - 30 );
103
+ }
104
+
105
+ $projectId = $_REQUEST['projectId'];
106
+ $from = $_REQUEST['from'];
107
+ $to = $_REQUEST['to'];
108
+ $query = $_REQUEST['query'];
109
+
110
+ if ( ob_get_length() ) {
111
+ ob_clean();
112
+ }
113
+
114
+ if ( ! GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) || 0 == $this->gadwp->config->options['dashboard_widget'] ) {
115
+ wp_die( - 31 );
116
+ }
117
+
118
+ if ( $this->gadwp->config->options['ga_dash_token'] && $projectId && $from && $to ) {
119
+ if ( null === $this->gadwp->gapi_controller ) {
120
+ $this->gadwp->gapi_controller = new GADWP_GAPI_Controller();
121
+ }
122
+ } else {
123
+ wp_die( - 24 );
124
+ }
125
+
126
+ $profile_info = GADWP_Tools::get_selected_profile( $this->gadwp->config->options['ga_dash_profile_list'], $projectId );
127
+
128
+ if ( isset( $profile_info[4] ) ) {
129
+ $this->gadwp->gapi_controller->timeshift = $profile_info[4];
130
+ } else {
131
+ $this->gadwp->gapi_controller->timeshift = (int) current_time( 'timestamp' ) - time();
132
+ }
133
+
134
+ $queries = explode( ',', $query );
135
+
136
+ $results = array();
137
+
138
+ foreach ( $queries as $value ) {
139
+ $results[] = $this->gadwp->gapi_controller->get( $projectId, $value, $from, $to );
140
+ }
141
+
142
+ wp_send_json( $results );
143
+ }
144
+ }
145
  }
admin/css/gadwp.css CHANGED
@@ -1,5 +1,6 @@
1
  /* Tab navigation */
2
- #gadwp-events, #gadwp-custom, #gadwp-advanced, #gadwp-exclude, #gadwp-config {
 
3
  display: none;
4
  }
5
 
@@ -22,8 +23,8 @@ td.title-select {
22
  width: 300px;
23
  }
24
 
25
- .gadwp-help{
26
- padding-left:15px;
27
  }
28
 
29
  td.debugging {
@@ -78,7 +79,7 @@ td.roles {
78
  }
79
 
80
  #poststuff h2 {
81
- padding-bottom:0;
82
  }
83
 
84
  /* Options pages ON/OFF Switch */
@@ -86,6 +87,13 @@ td.roles {
86
  position: relative;
87
  width: 50px;
88
  float: left;
 
 
 
 
 
 
 
89
  -webkit-user-select: none;
90
  -moz-user-select: none;
91
  -ms-user-select: none;
@@ -95,16 +103,11 @@ td.roles {
95
  display: none !important;
96
  }
97
 
98
- .onoffswitch:hover {
99
- border-color: #5b9dd9;
100
- -webkit-box-shadow: 0 0 2px rgba(30,140,190,.8);
101
- box-shadow: 0 0 2px rgba(30,140,190,.8);
102
- }
103
-
104
  .onoffswitch-label {
105
  display: block;
106
  overflow: hidden;
107
  cursor: pointer;
 
108
  border: 1px solid #ddd;
109
  border-radius: 2px;
110
  }
@@ -112,64 +115,74 @@ td.roles {
112
  .onoffswitch-inner {
113
  width: 200%;
114
  margin-left: -100%;
115
- -moz-transition: margin 0.3s ease-in 0s;
116
- -webkit-transition: margin 0.3s ease-in 0s;
117
- -o-transition: margin 0.3s ease-in 0s;
118
- transition: margin 0.3s ease-in 0s;
 
119
  }
120
 
121
  .onoffswitch-inner:before, .onoffswitch-inner:after {
122
  float: left;
123
  width: 50%;
124
- height: 22px;
125
- padding: 0;
126
- line-height: 22px;
127
- font-size: 12px;
128
- color: white;
129
- font-family: Trebuchet, Arial, sans-serif;
130
  font-weight: normal;
131
  -moz-box-sizing: border-box;
132
  -webkit-box-sizing: border-box;
 
133
  box-sizing: border-box;
 
 
 
134
  }
135
 
136
  .onoffswitch-inner:before {
137
  content: "On";
138
  padding-left: 5px;
139
- background-color: #00a0d2;
140
- color: #fff;
 
141
  }
142
 
143
  .onoffswitch-inner:after {
144
  content: "Off";
145
  padding-right: 5px;
146
- background-color: #fff;
147
- color: #999;
148
  text-align: right;
149
  }
150
 
151
  .onoffswitch-switch {
152
  width: 22px;
153
- margin: 0px;
154
  background: #fff;
 
155
  border: 1px solid #ddd;
156
  border-radius: 2px;
157
  position: absolute;
158
  top: 0;
159
  bottom: 0;
160
- right: 26px;
161
- -moz-transition: all 0.3s ease-in 0s;
162
- -webkit-transition: all 0.3s ease-in 0s;
163
- -o-transition: all 0.3s ease-in 0s;
164
- transition: all 0.3s ease-in 0s;
165
- background-image: -moz-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%,
166
- rgba(0, 0, 0, 0) 100%);
167
- background-image: -webkit-linear-gradient(center top, rgba(0, 0, 0, 0.1)
168
- 0%, rgba(0, 0, 0, 0) 100%);
169
- background-image: -o-linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%,
170
- rgba(0, 0, 0, 0) 100%);
171
- background-image: linear-gradient(center top, rgba(0, 0, 0, 0.1) 0%,
172
- rgba(0, 0, 0, 0) 100%);
 
 
 
 
 
 
 
 
 
 
173
  }
174
 
175
  .onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-inner {
@@ -183,6 +196,7 @@ td.roles {
183
  .switch-desc {
184
  float: left;
185
  margin-left: 10px;
 
186
  }
187
 
188
  /* Admin Widget & Real-Time Stats*/
1
  /* Tab navigation */
2
+ #gadwp-events, #gadwp-custom, #gadwp-advanced, #gadwp-exclude,
3
+ #gadwp-config {
4
  display: none;
5
  }
6
 
23
  width: 300px;
24
  }
25
 
26
+ .gadwp-help {
27
+ padding-left: 15px;
28
  }
29
 
30
  td.debugging {
79
  }
80
 
81
  #poststuff h2 {
82
+ padding-bottom: 0;
83
  }
84
 
85
  /* Options pages ON/OFF Switch */
87
  position: relative;
88
  width: 50px;
89
  float: left;
90
+ border: none !important;
91
+ padding: 0 !important;
92
+ height: 22px !important;
93
+ -moz-box-shadow: none !important;
94
+ -webkit-box-shadow: none !important;
95
+ -o-box-shadow: none !important;
96
+ box-shadow: none !important;
97
  -webkit-user-select: none;
98
  -moz-user-select: none;
99
  -ms-user-select: none;
103
  display: none !important;
104
  }
105
 
 
 
 
 
 
 
106
  .onoffswitch-label {
107
  display: block;
108
  overflow: hidden;
109
  cursor: pointer;
110
+ background: transparent;
111
  border: 1px solid #ddd;
112
  border-radius: 2px;
113
  }
115
  .onoffswitch-inner {
116
  width: 200%;
117
  margin-left: -100%;
118
+ border-radius: 2px;
119
+ -moz-transition: margin 0.2s ease-in 0s;
120
+ -webkit-transition: margin 0.2s ease-in 0s;
121
+ -o-transition: margin 0.2s ease-in 0s;
122
+ transition: margin 0.2s ease-in 0s;
123
  }
124
 
125
  .onoffswitch-inner:before, .onoffswitch-inner:after {
126
  float: left;
127
  width: 50%;
 
 
 
 
 
 
128
  font-weight: normal;
129
  -moz-box-sizing: border-box;
130
  -webkit-box-sizing: border-box;
131
+ -o-box-sizing: border-box;
132
  box-sizing: border-box;
133
+ height: 22px;
134
+ line-height: 22px;
135
+ font-size: 12px;
136
  }
137
 
138
  .onoffswitch-inner:before {
139
  content: "On";
140
  padding-left: 5px;
141
+ border-bottom: none;
142
+ /* background-color: #00a0d2;
143
+ color: #fff; /* inherit from button props */
144
  }
145
 
146
  .onoffswitch-inner:after {
147
  content: "Off";
148
  padding-right: 5px;
149
+ background-color: #ddd;
 
150
  text-align: right;
151
  }
152
 
153
  .onoffswitch-switch {
154
  width: 22px;
155
+ height: 22px;
156
  background: #fff;
157
+ color: #ddd;
158
  border: 1px solid #ddd;
159
  border-radius: 2px;
160
  position: absolute;
161
  top: 0;
162
  bottom: 0;
163
+ right: 27px;
164
+ -moz-transition: all 0.2s ease-in 0s;
165
+ -webkit-transition: all 0.2s ease-in 0s;
166
+ -o-transition: all 0.2s ease-in 0s;
167
+ transition: all 0.2s ease-in 0s;
168
+ }
169
+
170
+ .onoffswitch-switch:hover {
171
+ color: #aaa;
172
+ border-color: #aaa;
173
+ }
174
+
175
+ .onoffswitch-switch:after {
176
+ margin: 0;
177
+ outline: 0;
178
+ display: inline-block;
179
+ font: 400 16px/16px dashicons;
180
+ content: "\f228";
181
+ padding: 3px 0 0 3px;
182
+ text-align: left;
183
+ text-decoration: none;
184
+ -webkit-font-smoothing: antialiased;
185
+ -moz-osx-font-smoothing: grayscale;
186
  }
187
 
188
  .onoffswitch-checkbox:checked+.onoffswitch-label .onoffswitch-inner {
196
  .switch-desc {
197
  float: left;
198
  margin-left: 10px;
199
+ line-height: 20px;
200
  }
201
 
202
  /* Admin Widget & Real-Time Stats*/
admin/css/item-reports.css CHANGED
@@ -1,4 +1,4 @@
1
- /* Posts & Pages stats */
2
  .column-gadwp_stats {
3
  width: 70px;
4
  }
1
+ /* Backend Item Reports */
2
  .column-gadwp_stats {
3
  width: 70px;
4
  }
admin/images/google-analytics-dashboard.png CHANGED
Binary file
admin/item-reports.php CHANGED
@@ -7,65 +7,58 @@
7
  */
8
 
9
  // Exit if accessed directly
10
- if (! defined('ABSPATH'))
11
- exit();
12
 
13
- if (! class_exists('GADWP_Backend_Item_Reports')) {
14
 
15
- final class GADWP_Backend_Item_Reports
16
- {
17
 
18
- private $gadwp;
19
 
20
- public function __construct()
21
- {
22
- $this->gadwp = GADWP();
23
-
24
- if (GADWP_Tools::check_roles($this->gadwp->config->options['ga_dash_access_back']) && 1 == $this->gadwp->config->options['item_reports']) {
25
-
26
- // Add custom column in Posts List
27
- add_filter('manage_posts_columns', array(
28
- $this,
29
- 'add_columns'
30
- ));
31
- // Populate custom column in Posts List
32
- add_action('manage_posts_custom_column', array(
33
- $this,
34
- 'add_icons'
35
- ), 10, 2);
36
- // Add custom column in Pages List
37
- add_filter('manage_pages_columns', array(
38
- $this,
39
- 'add_columns'
40
- ));
41
- // Populate custom column in Pages List
42
- add_action('manage_pages_custom_column', array(
43
- $this,
44
- 'add_icons'
45
- ), 10, 2);
46
- }
47
- }
48
 
49
- public function add_icons($column, $id)
50
- {
51
- global $wp_version;
52
-
53
- if ($column != 'gadwp_stats') {
54
- return;
55
- }
56
-
57
- if (version_compare($wp_version, '3.8.0', '>=')) {
58
- echo '<a id="gadwp-' . $id . '" title="' . get_the_title($id) . '" href="#' . $id . '" class="gadwp-icon dashicons-before dashicons-chart-area"></a>';
59
- } else {
60
- echo '<a id="gadwp-' . $id . '" title="' . get_the_title($id) . '" href="#' . $id . '"><img class="gadwp-icon-oldwp" src="' . GADWP_URL . 'admin/images/gadash-icon.png"</a>';
61
- }
62
- }
63
 
64
- public function add_columns($columns)
65
- {
66
- return array_merge($columns, array(
67
- 'gadwp_stats' => __('Analytics', 'ga-dash')
68
- ));
69
- }
70
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  }
7
  */
8
 
9
  // Exit if accessed directly
10
+ if ( ! defined( 'ABSPATH' ) )
11
+ exit();
12
 
13
+ if ( ! class_exists( 'GADWP_Backend_Item_Reports' ) ) {
14
 
15
+ final class GADWP_Backend_Item_Reports {
 
16
 
17
+ private $gadwp;
18
 
19
+ public function __construct() {
20
+ $this->gadwp = GADWP();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
+ if ( GADWP_Tools::check_roles( $this->gadwp->config->options['ga_dash_access_back'] ) && 1 == $this->gadwp->config->options['backend_item_reports'] ) {
23
+ // Add custom column in Posts List
24
+ add_filter( 'manage_posts_columns', array(
25
+ $this,
26
+ 'add_columns' ) );
 
 
 
 
 
 
 
 
 
27
 
28
+ // Populate custom column in Posts List
29
+ add_action( 'manage_posts_custom_column', array(
30
+ $this,
31
+ 'add_icons' ), 10, 2 );
32
+
33
+ // Add custom column in Pages List
34
+ add_filter( 'manage_pages_columns', array(
35
+ $this,
36
+ 'add_columns' ) );
37
+
38
+ // Populate custom column in Pages List
39
+ add_action( 'manage_pages_custom_column', array(
40
+ $this,
41
+ 'add_icons' ), 10, 2 );
42
+ }
43
+ }
44
+
45
+ public function add_icons( $column, $id ) {
46
+ global $wp_version;
47
+
48
+ if ( $column != 'gadwp_stats' ) {
49
+ return;
50
+ }
51
+
52
+ if ( version_compare( $wp_version, '3.8.0', '>=' ) ) {
53
+ echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '" class="gadwp-icon dashicons-before dashicons-chart-area"></a>';
54
+ } else {
55
+ echo '<a id="gadwp-' . $id . '" title="' . get_the_title( $id ) . '" href="#' . $id . '"><img class="gadwp-icon-oldwp" src="' . GADWP_URL . 'admin/images/gadash-icon.png"</a>';
56
+ }
57
+ }
58
+
59
+ public function add_columns( $columns ) {
60
+ return array_merge( $columns, array(
61
+ 'gadwp_stats' => __( 'Analytics', 'ga-dash' ) ) );
62
+ }
63
+ }
64
  }
admin/js/item-reports.js CHANGED
@@ -1,629 +1,616 @@
1
  "use strict";
2
 
3
- google.load("visualization", "1", {
4
- packages : ["corechart", "table", "orgchart", "geochart"]
5
- });
6
-
7
- jQuery(document).ready(
8
-
9
- function() {
10
- jQuery('a[id^="gadwp-"]').click(function(e) {
11
-
12
- var item_id = getID(this);
13
- var slug = "-" + item_id;
14
-
15
- if (!jQuery("#gadwp-window" + slug).length > 0) {
16
- jQuery("body").append('<div id="gadwp-window' + slug + '"></div>');
17
- }
18
- jQuery('#gadwp-window' + slug).gadwpItemReport(slug, item_id);
19
- });
20
-
21
- function getID(item) {
22
- if (typeof item.id == "undefined") {
23
- return 0
24
- }
25
- if (item.id.split('-')[1] == "undefined") {
26
- return 0;
27
- } else {
28
- return item.id.split('-')[1];
29
- }
30
- }
31
-
32
- // on window resize
33
- jQuery(window).resize(function() {
34
- fluidDialog();
35
- });
36
-
37
- // dialog width larger than viewport
38
- jQuery(document).on("dialogopen", ".ui-dialog", function(event, ui) {
39
- fluidDialog();
40
- });
41
-
42
- function fluidDialog() {
43
- var visible = jQuery(".ui-dialog:visible");
44
- // on each visible dialog
45
- visible.each(function() {
46
- var $this = jQuery(this);
47
- var dialog = $this.find(".ui-dialog-content").data("ui-dialog");
48
- // on each fluid dialog
49
- if (dialog.options.fluid) {
50
- var wWidth = jQuery(window).width();
51
- // window width vs dialog width
52
- if (wWidth < (parseInt(dialog.options.maxWidth) + 50)) {
53
- // don't fill the entire screen
54
- $this.css("max-width", "90%");
55
- } else {
56
- // maxWidth bug fix
57
- $this.css("max-width", dialog.options.maxWidth + "px");
58
- }
59
- // change dialog position
60
- dialog.option("position", dialog.options.position);
61
- }
62
- });
63
-
64
- }
65
- });
66
-
67
- jQuery.fn.extend({
68
- gadwpItemReport : function(slug, item_id) {
69
-
70
- var template = {
71
-
72
- data : '<div id="gadwp-container' + slug + '"><select id="gadwp-sel-period' + slug + '"></select> <select id="gadwp-sel-report' + slug + '"></select><div id="gadwp-progressbar' + slug + '"></div><div id="gadwp-status' + slug + '"></div><div id="gadwp-reports' + slug + '"></div><div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;margin-top:10px;">' + gadwp_item_data.i18n[14] + ' <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;</div></div>',
73
-
74
- addOptions : function(id, list) {
75
-
76
- var output = [];
77
- jQuery.each(list, function(key, value) {
78
- if (key == '30daysAgo' || key == 'sessions') {
79
- output.push('<option value="' + key + '" selected="selected">' + value + '</option>');
80
- } else {
81
- output.push('<option value="' + key + '">' + value + '</option>');
82
- }
83
- });
84
- jQuery(id).html(output.join(''));
85
- },
86
-
87
- init : function() {
88
- if (jQuery('#gadwp-window' + slug).html().length) { // add main template once
89
- return;
90
- }
91
-
92
- jQuery('#gadwp-window' + slug).append(this.data);
93
-
94
- this.addOptions('#gadwp-sel-period' + slug, gadwp_item_data.dateList);
95
- this.addOptions('#gadwp-sel-report' + slug, gadwp_item_data.reportList);
96
-
97
- }
98
- }
99
-
100
- var reports = {
101
-
102
- npcounter : 0,
103
- prs : '',
104
- trafficchannels : '',
105
- trafficmediums : '',
106
- traffictype : '',
107
- trafficorganic : '',
108
- socialnetworks : '',
109
- locations : '',
110
- mainchart : '',
111
- bottomstats : '',
112
-
113
- alertMessage : function(msg) {
114
- jQuery("#gadwp-status" + slug).css({
115
- "margin-top" : "3px",
116
- "padding-left" : "5px",
117
- "height" : "auto",
118
- "color" : "#000",
119
- "border-left" : "5px solid red"
120
- });
121
- jQuery("#gadwp-status" + slug).html(msg);
122
- },
123
-
124
- drawprs : function(gadwp_prs) {
125
- var data = google.visualization.arrayToDataTable(gadwp_prs);
126
- var options = {
127
- page : 'enable',
128
- pageSize : 10,
129
- width : '100%',
130
- allowHtml: true
131
- };
132
-
133
- var chart = new google.visualization.Table(document.getElementById('gadwp-prs' + slug));
134
- chart.draw(data, options);
135
- },
136
-
137
- drawtrafficchannels : function(gadwp_trafficchannels) {
138
- var data = google.visualization.arrayToDataTable(gadwp_trafficchannels);
139
- var options = {
140
- allowCollapse : true,
141
- allowHtml : true
142
- };
143
-
144
- var chart = new google.visualization.OrgChart(document.getElementById('gadwp-trafficchannels' + slug));
145
- chart.draw(data, options);
146
- },
147
-
148
- drawtrafficmediums : function(gadwp_trafficmediums) {
149
- var data = google.visualization.arrayToDataTable(gadwp_trafficmediums);
150
- var options = {
151
- is3D : false,
152
- tooltipText : 'percentage',
153
- legend : 'none',
154
- chartArea : {
155
- width : '99%',
156
- height : '80%'
157
- },
158
- title : gadwp_item_data.i18n[1],
159
- colors : gadwp_item_data.colorVariations
160
- };
161
-
162
- var chart = new google.visualization.PieChart(document.getElementById('gadwp-trafficmediums' + slug));
163
- chart.draw(data, options);
164
- },
165
-
166
- drawtraffictype : function(gadwp_traffictype) {
167
- var data = google.visualization.arrayToDataTable(gadwp_traffictype);
168
- var options = {
169
- is3D : false,
170
- tooltipText : 'percentage',
171
- legend : 'none',
172
- chartArea : {
173
- width : '99%',
174
- height : '80%'
175
- },
176
- title : gadwp_item_data.i18n[2],
177
- colors : gadwp_item_data.colorVariations
178
- };
179
-
180
- var chart = new google.visualization.PieChart(document.getElementById('gadwp-traffictype' + slug));
181
- chart.draw(data, options);
182
- },
183
-
184
- drawsocialnetworks : function(gadwp_socialnetworks) {
185
- var data = google.visualization.arrayToDataTable(gadwp_socialnetworks);
186
- var options = {
187
- is3D : false,
188
- tooltipText : 'percentage',
189
- legend : 'none',
190
- chartArea : {
191
- width : '99%',
192
- height : '80%'
193
- },
194
- title : gadwp_item_data.i18n[3],
195
- colors : gadwp_item_data.colorVariations
196
- };
197
-
198
- var chart = new google.visualization.PieChart(document.getElementById('gadwp-socialnetworks' + slug));
199
- chart.draw(data, options);
200
- },
201
-
202
- drawtrafficorganic : function(gadwp_trafficorganic) {
203
- var data = google.visualization.arrayToDataTable(gadwp_trafficorganic);
204
- var options = {
205
- is3D : false,
206
- tooltipText : 'percentage',
207
- legend : 'none',
208
- chartArea : {
209
- width : '99%',
210
- height : '80%'
211
- },
212
- title : gadwp_item_data.i18n[4],
213
- colors : gadwp_item_data.colorVariations
214
- };
215
-
216
- var chart = new google.visualization.PieChart(document.getElementById('gadwp-trafficorganic' + slug));
217
- chart.draw(data, options);
218
- },
219
-
220
- drawlocations : function(gadwp_locations) {
221
- var data = google.visualization.arrayToDataTable(gadwp_locations);
222
- var options = {
223
- page : 'enable',
224
- pageSize : 10,
225
- width : '100%'
226
- };
227
-
228
- var chart = new google.visualization.Table(document.getElementById('gadwp-locations' + slug));
229
- chart.draw(data, options);
230
- },
231
-
232
- drawmaplocations : function(gadwp_locations) {
233
-
234
- var data = google.visualization.arrayToDataTable(gadwp_locations);
235
-
236
- var options = {
237
- chartArea : {
238
- width : '99%',
239
- height : '90%'
240
- },
241
- colors : [gadwp_item_data.colorVariations[5], gadwp_item_data.colorVariations[4]],
242
- }
243
-
244
- if (gadwp_item_data.region) {
245
- options.region = gadwp_item_data.region;
246
- options.displayMode = 'markers';
247
- options.datalessRegionColor = 'EFEFEF';
248
- }
249
-
250
- var chart = new google.visualization.GeoChart(document.getElementById('gadwp-map' + slug));
251
- chart.draw(data, options);
252
- },
253
-
254
- drawmainchart : function(gadwp_mainchart) {
255
-
256
- var data = google.visualization.arrayToDataTable(gadwp_mainchart);
257
-
258
- var options = {
259
- legend : {
260
- position : 'none'
261
- },
262
- pointSize : 3,
263
- colors : [gadwp_item_data.colorVariations[0], gadwp_item_data.colorVariations[4]],
264
- chartArea : {
265
- width : '99%',
266
- height : '90%'
267
- },
268
- vAxis : {
269
- textPosition : "in",
270
- minValue : 0
271
- },
272
- hAxis : {
273
- textPosition : 'none'
274
- }
275
- };
276
- var chart = new google.visualization.AreaChart(document.getElementById('gadwp-mainchart' + slug));
277
- chart.draw(data, options);
278
- },
279
-
280
- drawbottomstats : function(gadwp_bottomstats) {
281
- jQuery("#gdsessions" + slug).text(gadwp_bottomstats[0]);
282
- jQuery("#gdusers" + slug).text(gadwp_bottomstats[1]);
283
- jQuery("#gdpageviews" + slug).text(gadwp_bottomstats[2]);
284
- jQuery("#gdbouncerate" + slug).text(parseFloat(gadwp_bottomstats[3]).toFixed(2) + "%");
285
- jQuery("#gdorganicsearch" + slug).text(gadwp_bottomstats[4]);
286
- jQuery("#gdpagespervisit" + slug).text(parseFloat(gadwp_bottomstats[5]).toFixed(2));
287
- },
288
-
289
- checknpcounter : function(max) {
290
- try {
291
- if (this.npcounter == max) {
292
- NProgress.done();
293
- } else {
294
- this.npcounter++;
295
- NProgress.set((1 / (max + 1)) * this.npcounter);
296
- }
297
- } catch (e) {
298
- }
299
- },
300
-
301
- throwDebug : function(response) {
302
- jQuery("#gadwp-status" + slug).css({
303
- "margin-top" : "3px",
304
- "padding-left" : "5px",
305
- "height" : "auto",
306
- "color" : "#000",
307
- "border-left" : "5px solid red"
308
- });
309
- jQuery("#gadwp-status" + slug).html(gadwp_item_data.i18n[11]);
310
- console.log("\n********************* GADWP Log ********************* \n\n" + response);
311
- },
312
-
313
- throwError : function(target, response, n, p) {
314
- jQuery(target).css({
315
- "background-color" : "#F7F7F7",
316
- "height" : "auto",
317
- "padding-top" : p,
318
- "padding-bottom" : p,
319
- "color" : "#000",
320
- "text-align" : "center"
321
- });
322
- if (response == -21) {
323
- jQuery(target).html(gadwp_item_data.i18n[12] + ' (' + response + ')');
324
- } else {
325
- jQuery(target).html(gadwp_item_data.i18n[13] + ' (' + response + ')');
326
- }
327
- this.checknpcounter(n);
328
- },
329
-
330
- render : function(period, query) {
331
- var from, to;
332
- jQuery('#gadwp-status' + slug).html('');
333
- switch (period) {
334
- case 'today' :
335
- from = 'today';
336
- to = 'today';
337
- break;
338
- case 'yesterday' :
339
- from = 'yesterday';
340
- to = 'yesterday';
341
- break;
342
- case '7daysAgo' :
343
- from = '7daysAgo';
344
- to = 'yesterday';
345
- break;
346
- case '14daysAgo' :
347
- from = '14daysAgo';
348
- to = 'yesterday';
349
- break;
350
- case '90daysAgo' :
351
- from = '90daysAgo';
352
- to = 'yesterday';
353
- break;
354
- default :
355
- from = '30daysAgo';
356
- to = 'yesterday';
357
- break;
358
- }
359
-
360
- var data = {
361
- action : 'gadwp_get_ItemReports',
362
- gadwp_security_item_reports : gadwp_item_data.security,
363
- from : from,
364
- to : to,
365
- filter : item_id
366
- }
367
-
368
- if (jQuery.inArray(query, ['referrers', 'contentpages', 'searches']) > -1) {
369
- jQuery('#gadwp-reports' + slug).html('<div id="gadwp-trafficchannels' + slug + '"></div>')
370
- jQuery('#gadwp-reports' + slug).append('<div id="gadwp-prs' + slug + '"></div>');
371
- data.query = 'trafficchannels';
372
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
373
- if (!jQuery.isNumeric(response)) {
374
- if (jQuery.isArray(response)) {
375
- reports.trafficchannels = response;
376
- google.setOnLoadCallback(reports.drawtrafficchannels(reports.trafficchannels));
377
- reports.checknpcounter(1);
378
- } else {
379
- reports.throwDebug(response);
380
- reports.checknpcounter(1);
381
- }
382
- } else {
383
- reports.throwError('#gadwp-trafficchannels' + slug, response, 1, "125px");
384
- }
385
- });
386
- data.query = query;
387
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
388
- if (!jQuery.isNumeric(response)) {
389
- if (jQuery.isArray(response)) {
390
- reports.prs = response;
391
- google.setOnLoadCallback(reports.drawprs(reports.prs));
392
- reports.checknpcounter(1);
393
- } else {
394
- reports.throwDebug(response);
395
- reports.checknpcounter(1);
396
- }
397
- } else {
398
- reports.throwError('#gadwp-prs' + slug, response, 1, "125px");
399
- }
400
- });
401
- } else if (query == 'trafficdetails') {
402
- jQuery('#gadwp-reports' + slug).html('<div id="gadwp-trafficchannels' + slug + '"></div>')
403
- jQuery('#gadwp-reports' + slug).append('<div class="gadwp-floatwraper"><div id="gadwp-trafficmediums' + slug + '"></div><div id="gadwp-traffictype' + slug + '"></div></div>');
404
- jQuery('#gadwp-reports' + slug).append('<div class="gadwp-floatwraper"><div id="gadwp-trafficorganic' + slug + '"></div><div id="gadwp-socialnetworks' + slug + '"></div></div>');
405
- data.query = 'trafficchannels';
406
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
407
- if (!jQuery.isNumeric(response)) {
408
- if (jQuery.isArray(response)) {
409
- reports.trafficchannels = response;
410
- google.setOnLoadCallback(reports.drawtrafficchannels(reports.trafficchannels));
411
- reports.checknpcounter(4);
412
- } else {
413
- reports.throwDebug(response);
414
- reports.checknpcounter(4);
415
- }
416
- } else {
417
- reports.throwError('#gadwp-trafficchannels' + slug, response, 4, "125px");
418
- }
419
- });
420
- data.query = 'medium';
421
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
422
- if (!jQuery.isNumeric(response)) {
423
- if (jQuery.isArray(response)) {
424
- reports.trafficmediums = response;
425
- google.setOnLoadCallback(reports.drawtrafficmediums(reports.trafficmediums));
426
- reports.checknpcounter(4);
427
- } else {
428
- reports.throwDebug(response);
429
- reports.checknpcounter(4);
430
- }
431
- } else {
432
- reports.throwError('#gadwp-trafficmediums' + slug, response, 4, "80px");
433
- }
434
- });
435
- data.query = 'visitorType';
436
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
437
- if (!jQuery.isNumeric(response)) {
438
- if (jQuery.isArray(response)) {
439
- reports.traffictype = response;
440
- google.setOnLoadCallback(reports.drawtraffictype(reports.traffictype));
441
- reports.checknpcounter(4);
442
- } else {
443
- reports.throwDebug(response);
444
- reports.checknpcounter(4);
445
- }
446
- } else {
447
- reports.throwError('#gadwp-traffictype' + slug, response, 4, "80px");
448
- }
449
- });
450
- data.query = 'source';
451
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
452
- if (!jQuery.isNumeric(response)) {
453
- if (jQuery.isArray(response)) {
454
- reports.trafficorganic = response;
455
- google.setOnLoadCallback(reports.drawtrafficorganic(reports.trafficorganic));
456
- reports.checknpcounter(4);
457
- } else {
458
- reports.throwDebug(response);
459
- reports.checknpcounter(4);
460
- }
461
- } else {
462
- reports.throwError('#gadwp-trafficorganic' + slug, response, 4, "80px");
463
- }
464
- });
465
- data.query = 'socialNetwork';
466
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
467
- if (!jQuery.isNumeric(response)) {
468
- if (jQuery.isArray(response)) {
469
- reports.socialnetworks = response;
470
- google.setOnLoadCallback(reports.drawsocialnetworks(reports.socialnetworks));
471
- reports.checknpcounter(4);
472
- } else {
473
- reports.throwDebug(response);
474
- reports.checknpcounter(4);
475
- }
476
- } else {
477
- reports.throwError('#gadwp-socialnetworks' + slug, response, 4, "80px");
478
- }
479
- });
480
- } else if (query == 'locations') {
481
- jQuery('#gadwp-reports' + slug).html('<div id="gadwp-map' + slug + '"></div>')
482
- jQuery('#gadwp-reports' + slug).append('<div id="gadwp-locations' + slug + '"></div>');
483
- data.query = query;
484
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
485
- if (!jQuery.isNumeric(response)) {
486
- if (jQuery.isArray(response)) {
487
- reports.locations = response;
488
- google.setOnLoadCallback(reports.drawmaplocations(reports.locations));
489
- reports.checknpcounter(1);
490
- google.setOnLoadCallback(reports.drawlocations(reports.locations));
491
- reports.checknpcounter(1);
492
- } else {
493
- reports.throwDebug(response);
494
- reports.checknpcounter(1);
495
- }
496
- } else {
497
- reports.throwError('#gadwp-map' + slug, response, 1, "125px");
498
- reports.throwError('#gadwp-locations' + slug, response, 1, "125px");
499
- }
500
- });
501
- } else {
502
- jQuery('#gadwp-reports' + slug).html('<div id="gadwp-mainchart' + slug + '"></div>')
503
- jQuery('#gadwp-reports' + slug).append('<div id="gadwp-bottomstats' + slug + '" class="gadwp-wrapper"><div class="inside"><div class="small-box"><h3>' + gadwp_item_data.i18n[5] + '</h3><p id="gdsessions' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[6] + '</h3><p id="gdusers' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[7] + '</h3><p id="gdpageviews' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[8] + '</h3><p id="gdbouncerate' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[9] + '</h3><p id="gdorganicsearch' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[10] + '</h3><p id="gdpagespervisit' + slug + '">&nbsp;</p></div></div></div>');
504
-
505
- data.query = query;
506
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
507
- if (!jQuery.isNumeric(response)) {
508
- if (jQuery.isArray(response)) {
509
- reports.mainchart = response;
510
- google.setOnLoadCallback(reports.drawmainchart(reports.mainchart));
511
- reports.checknpcounter(1);
512
- } else {
513
- reports.throwDebug(response);
514
- reports.checknpcounter(1);
515
- }
516
- } else {
517
- reports.throwError('#gadwp-mainchart' + slug, response, 1, "125px");
518
- }
519
- });
520
-
521
- data.query = 'bottomstats';
522
- jQuery.post(gadwp_item_data.ajaxurl, data, function(response) {
523
-
524
- if (!jQuery.isNumeric(response)) {
525
- if (jQuery.isArray(response)) {
526
- reports.bottomstats = response;
527
- google.setOnLoadCallback(reports.drawbottomstats(reports.bottomstats));
528
- reports.checknpcounter(1);
529
- } else {
530
- reports.throwDebug(response);
531
- reports.checknpcounter(1);
532
- }
533
- } else {
534
- reports.throwError('#gadwp-bottomstats' + slug, response, response, 1, "40px");
535
- }
536
- });
537
-
538
- }
539
-
540
- },
541
-
542
- refresh : function() {
543
- if (jQuery('#gadwp-bottomstats' + slug).length > 0){
544
- this.drawbottomstats(this.bottomstats);
545
- }
546
- if (jQuery('#gadwp-mainchart' + slug).length > 0 && jQuery.isArray(this.mainchart)){
547
- this.drawmainchart(this.mainchart);
548
- }
549
- if (jQuery('#gadwp-map' + slug).length > 0 && jQuery.isArray(this.locations)){
550
- this.drawmaplocations(this.locations);
551
- }
552
- if (jQuery('#gadwp-locations' + slug).length > 0 && jQuery.isArray(this.locations)){
553
- this.drawlocations(this.locations);
554
- }
555
- if (jQuery('#gadwp-socialnetworks' + slug).length > 0 && jQuery.isArray(this.socialnetworks)){
556
- this.drawsocialnetworks(this.socialnetworks);
557
- }
558
- if (jQuery('#gadwp-trafficorganic' + slug).length > 0 && jQuery.isArray(this.trafficorganic)){
559
- this.drawtrafficorganic(this.trafficorganic);
560
- }
561
- if (jQuery('#gadwp-traffictype' + slug).length > 0 && jQuery.isArray(this.traffictype)){
562
- this.drawtraffictype(this.traffictype);
563
- }
564
- if (jQuery('#gadwp-trafficmediums' + slug).length > 0 && jQuery.isArray(this.trafficmediums)){
565
- this.drawtrafficmediums(this.trafficmediums);
566
- }
567
- if (jQuery('#gadwp-trafficchannels' + slug).length > 0 && jQuery.isArray(this.trafficchannels)){
568
- this.drawtrafficchannels(this.trafficchannels);
569
- }
570
- if (jQuery('#gadwp-prs' + slug).length > 0 && jQuery.isArray(this.prs)){
571
- this.drawprs(this.prs);
572
- }
573
- },
574
-
575
- init : function() {
576
-
577
- if (jQuery("#gadwp-reports" + slug).html().length) { // only when report is empty
578
- return;
579
- }
580
-
581
- try {
582
- NProgress.configure({
583
- parent : "#gadwp-progressbar" + slug, showSpinner : false
584
- });
585
- NProgress.start();
586
- } catch (e) {
587
- this.alertMessage(gadwp_item_data.i18n[0]);
588
- }
589
-
590
- this.render(jQuery('#gadwp-sel-period' + slug).val(), jQuery('#gadwp-sel-report' + slug).val());
591
-
592
- jQuery(window).resize(function() {
593
- reports.refresh();
594
- });
595
- }
596
- }
597
-
598
- template.init();
599
-
600
- reports.init();
601
-
602
- jQuery('#gadwp-sel-period' + slug).change(function() {
603
- jQuery('#gadwp-reports' + slug).html('');
604
- reports.init();
605
- });
606
-
607
- jQuery('#gadwp-sel-report' + slug).change(function() {
608
- jQuery('#gadwp-reports' + slug).html('');
609
- reports.init();
610
- });
611
-
612
- return this.dialog({
613
- width : 'auto',
614
- maxWidth : 510,
615
- height : 'auto',
616
- modal : true,
617
- fluid : true,
618
- dialogClass : 'gadwp wp-dialog',
619
- resizable : false,
620
- title : jQuery('#gadwp'+slug).attr( "title" ),
621
- position : {
622
- my : "top",
623
- at : "top+100",
624
- of : window
625
- }
626
- });
627
-
628
- }
629
- });
1
  "use strict";
2
 
3
+ google.load( "visualization", "1", {
4
+ packages : [ "corechart", "table", "orgchart", "geochart" ]
5
+ } );
6
+
7
+ jQuery( document ).ready(
8
+
9
+ function () {
10
+ jQuery( 'a[id^="gadwp-"]' ).click( function ( e ) {
11
+
12
+ var item_id = getID( this );
13
+ var slug = "-" + item_id;
14
+
15
+ if ( !jQuery( "#gadwp-window" + slug ).length > 0 ) {
16
+ jQuery( "body" ).append( '<div id="gadwp-window' + slug + '"></div>' );
17
+ }
18
+ jQuery( '#gadwp-window' + slug ).gadwpItemReport( slug, item_id );
19
+ } );
20
+
21
+ function getID ( item ) {
22
+ if ( typeof item.id == "undefined" ) {
23
+ return 0
24
+ }
25
+ if ( item.id.split( '-' )[ 1 ] == "undefined" ) {
26
+ return 0;
27
+ } else {
28
+ return item.id.split( '-' )[ 1 ];
29
+ }
30
+ }
31
+
32
+ // on window resize
33
+ jQuery( window ).resize( function () {
34
+ fluidDialog();
35
+ } );
36
+
37
+ // dialog width larger than viewport
38
+ jQuery( document ).on( "dialogopen", ".ui-dialog", function ( event, ui ) {
39
+ fluidDialog();
40
+ } );
41
+
42
+ function fluidDialog () {
43
+ var visible = jQuery( ".ui-dialog:visible" );
44
+ // on each visible dialog
45
+ visible.each( function () {
46
+ var $this = jQuery( this );
47
+ var dialog = $this.find( ".ui-dialog-content" ).data( "ui-dialog" );
48
+ // on each fluid dialog
49
+ if ( dialog.options.fluid ) {
50
+ var wWidth = jQuery( window ).width();
51
+ // window width vs dialog width
52
+ if ( wWidth < ( parseInt( dialog.options.maxWidth ) + 50 ) ) {
53
+ // don't fill the entire screen
54
+ $this.css( "max-width", "90%" );
55
+ } else {
56
+ // maxWidth bug fix
57
+ $this.css( "max-width", dialog.options.maxWidth + "px" );
58
+ }
59
+ // change dialog position
60
+ dialog.option( "position", dialog.options.position );
61
+ }
62
+ } );
63
+
64
+ }
65
+ } );
66
+
67
+ jQuery.fn.extend( {
68
+ gadwpItemReport : function ( slug, item_id ) {
69
+
70
+ var template = {
71
+
72
+ data : '<div id="gadwp-container' + slug + '"><select id="gadwp-sel-period' + slug + '"></select> <select id="gadwp-sel-report' + slug + '"></select><div id="gadwp-progressbar' + slug + '"></div><div id="gadwp-status' + slug + '"></div><div id="gadwp-reports' + slug + '"></div><div style="text-align:right;width:100%;font-size:0.8em;clear:both;margin-right:5px;margin-top:10px;">' + gadwp_item_data.i18n[ 14 ] + ' <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;</div></div>',
73
+
74
+ addOptions : function ( id, list ) {
75
+
76
+ var output = [];
77
+ jQuery.each( list, function ( key, value ) {
78
+ if ( key == '30daysAgo' || key == 'sessions' ) {
79
+ output.push( '<option value="' + key + '" selected="selected">' + value + '</option>' );
80
+ } else {
81
+ output.push( '<option value="' + key + '">' + value + '</option>' );
82
+ }
83
+ } );
84
+ jQuery( id ).html( output.join( '' ) );
85
+ },
86
+
87
+ init : function () {
88
+ if ( jQuery( '#gadwp-window' + slug ).html().length ) { // add main template once
89
+ return;
90
+ }
91
+
92
+ jQuery( '#gadwp-window' + slug ).append( this.data );
93
+
94
+ this.addOptions( '#gadwp-sel-period' + slug, gadwp_item_data.dateList );
95
+ this.addOptions( '#gadwp-sel-report' + slug, gadwp_item_data.reportList );
96
+
97
+ }
98
+ }
99
+
100
+ var reports = {
101
+
102
+ npcounter : 0,
103
+ prs : '',
104
+ trafficchannels : '',
105
+ trafficmediums : '',
106
+ traffictype : '',
107
+ trafficorganic : '',
108
+ socialnetworks : '',
109
+ locations : '',
110
+ mainchart : '',
111
+ bottomstats : '',
112
+
113
+ alertMessage : function ( msg ) {
114
+ jQuery( "#gadwp-status" + slug ).css( {
115
+ "margin-top" : "3px",
116
+ "padding-left" : "5px",
117
+ "height" : "auto",
118
+ "color" : "#000",
119
+ "border-left" : "5px solid red"
120
+ } );
121
+ jQuery( "#gadwp-status" + slug ).html( msg );
122
+ },
123
+
124
+ drawprs : function ( gadwp_prs ) {
125
+ var data = google.visualization.arrayToDataTable( gadwp_prs );
126
+ var options = {
127
+ page : 'enable',
128
+ pageSize : 10,
129
+ width : '100%',
130
+ allowHtml : true
131
+ };
132
+
133
+ var chart = new google.visualization.Table( document.getElementById( 'gadwp-prs' + slug ) );
134
+ chart.draw( data, options );
135
+ },
136
+
137
+ drawtrafficchannels : function ( gadwp_trafficchannels ) {
138
+ var data = google.visualization.arrayToDataTable( gadwp_trafficchannels );
139
+ var options = {
140
+ allowCollapse : true,
141
+ allowHtml : true,
142
+ height: '100%'
143
+ };
144
+
145
+ var chart = new google.visualization.OrgChart( document.getElementById( 'gadwp-trafficchannels' + slug ) );
146
+ chart.draw( data, options );
147
+ },
148
+
149
+ drawtrafficmediums : function ( gadwp_trafficmediums ) {
150
+ var data = google.visualization.arrayToDataTable( gadwp_trafficmediums );
151
+ var options = {
152
+ is3D : false,
153
+ tooltipText : 'percentage',
154
+ legend : 'none',
155
+ chartArea : {
156
+ width : '99%',
157
+ height : '80%'
158
+ },
159
+ title : gadwp_item_data.i18n[ 1 ],
160
+ colors : gadwp_item_data.colorVariations
161
+ };
162
+
163
+ var chart = new google.visualization.PieChart( document.getElementById( 'gadwp-trafficmediums' + slug ) );
164
+ chart.draw( data, options );
165
+ },
166
+
167
+ drawtraffictype : function ( gadwp_traffictype ) {
168
+ var data = google.visualization.arrayToDataTable( gadwp_traffictype );
169
+ var options = {
170
+ is3D : false,
171
+ tooltipText : 'percentage',
172
+ legend : 'none',
173
+ chartArea : {
174
+ width : '99%',
175
+ height : '80%'
176
+ },
177
+ title : gadwp_item_data.i18n[ 2 ],
178
+ colors : gadwp_item_data.colorVariations
179
+ };
180
+
181
+ var chart = new google.visualization.PieChart( document.getElementById( 'gadwp-traffictype' + slug ) );
182
+ chart.draw( data, options );
183
+ },
184
+
185
+ drawsocialnetworks : function ( gadwp_socialnetworks ) {
186
+ var data = google.visualization.arrayToDataTable( gadwp_socialnetworks );
187
+ var options = {
188
+ is3D : false,
189
+ tooltipText : 'percentage',
190
+ legend : 'none',
191
+ chartArea : {
192
+ width : '99%',
193
+ height : '80%'
194
+ },
195
+ title : gadwp_item_data.i18n[ 3 ],
196
+ colors : gadwp_item_data.colorVariations
197
+ };
198
+
199
+ var chart = new google.visualization.PieChart( document.getElementById( 'gadwp-socialnetworks' + slug ) );
200
+ chart.draw( data, options );
201
+ },
202
+
203
+ drawtrafficorganic : function ( gadwp_trafficorganic ) {
204
+ var data = google.visualization.arrayToDataTable( gadwp_trafficorganic );
205
+ var options = {
206
+ is3D : false,
207
+ tooltipText : 'percentage',
208
+ legend : 'none',
209
+ chartArea : {
210
+ width : '99%',
211
+ height : '80%'
212
+ },
213
+ title : gadwp_item_data.i18n[ 4 ],
214
+ colors : gadwp_item_data.colorVariations
215
+ };
216
+
217
+ var chart = new google.visualization.PieChart( document.getElementById( 'gadwp-trafficorganic' + slug ) );
218
+ chart.draw( data, options );
219
+ },
220
+
221
+ drawlocations : function ( gadwp_locations ) {
222
+ var data = google.visualization.arrayToDataTable( gadwp_locations );
223
+ var options = {
224
+ page : 'enable',
225
+ pageSize : 10,
226
+ width : '100%'
227
+ };
228
+
229
+ var chart = new google.visualization.Table( document.getElementById( 'gadwp-locations' + slug ) );
230
+ chart.draw( data, options );
231
+ },
232
+
233
+ drawmaplocations : function ( gadwp_locations ) {
234
+
235
+ var data = google.visualization.arrayToDataTable( gadwp_locations );
236
+
237
+ var options = {
238
+ chartArea : {
239
+ width : '99%',
240
+ height : '90%'
241
+ },
242
+ colors : [ gadwp_item_data.colorVariations[ 5 ], gadwp_item_data.colorVariations[ 4 ] ],
243
+ }
244
+
245
+ if ( gadwp_item_data.region ) {
246
+ options.region = gadwp_item_data.region;
247
+ options.displayMode = 'markers';
248
+ options.datalessRegionColor = 'EFEFEF';
249
+ }
250
+
251
+ var chart = new google.visualization.GeoChart( document.getElementById( 'gadwp-map' + slug ) );
252
+ chart.draw( data, options );
253
+ },
254
+
255
+ drawmainchart : function ( gadwp_mainchart ) {
256
+
257
+ var data = google.visualization.arrayToDataTable( gadwp_mainchart );
258
+
259
+ var options = {
260
+ legend : {
261
+ position : 'none'
262
+ },
263
+ pointSize : 3,
264
+ colors : [ gadwp_item_data.colorVariations[ 0 ], gadwp_item_data.colorVariations[ 4 ] ],
265
+ chartArea : {
266
+ width : '99%',
267
+ height : '90%'
268
+ },
269
+ vAxis : {
270
+ textPosition : "in",
271
+ minValue : 0
272
+ },
273
+ hAxis : {
274
+ textPosition : 'none'
275
+ }
276
+ };
277
+ var chart = new google.visualization.AreaChart( document.getElementById( 'gadwp-mainchart' + slug ) );
278
+ chart.draw( data, options );
279
+ },
280
+
281
+ drawbottomstats : function ( gadwp_bottomstats ) {
282
+ jQuery( "#gdsessions" + slug ).text( gadwp_bottomstats[ 0 ] );
283
+ jQuery( "#gdusers" + slug ).text( gadwp_bottomstats[ 1 ] );
284
+ jQuery( "#gdpageviews" + slug ).text( gadwp_bottomstats[ 2 ] );
285
+ jQuery( "#gdbouncerate" + slug ).text( parseFloat( gadwp_bottomstats[ 3 ] ).toFixed( 2 ) + "%" );
286
+ jQuery( "#gdorganicsearch" + slug ).text( gadwp_bottomstats[ 4 ] );
287
+ jQuery( "#gdpagespervisit" + slug ).text( parseFloat( gadwp_bottomstats[ 5 ] ).toFixed( 2 ) );
288
+ },
289
+
290
+ throwDebug : function ( response ) {
291
+ jQuery( "#gadwp-status" + slug ).css( {
292
+ "margin-top" : "3px",
293
+ "padding-left" : "5px",
294
+ "height" : "auto",
295
+ "color" : "#000",
296
+ "border-left" : "5px solid red"
297
+ } );
298
+ jQuery( "#gadwp-status" + slug ).html( gadwp_item_data.i18n[ 11 ] );
299
+ console.log( "\n********************* GADWP Log ********************* \n\n" + response );
300
+ },
301
+
302
+ throwError : function ( target, response, p ) {
303
+ jQuery( target ).css( {
304
+ "background-color" : "#F7F7F7",
305
+ "height" : "auto",
306
+ "padding-top" : p,
307
+ "padding-bottom" : p,
308
+ "color" : "#000",
309
+ "text-align" : "center"
310
+ } );
311
+ if ( response == -21 ) {
312
+ jQuery( target ).html( gadwp_item_data.i18n[ 12 ] + ' (' + response + ')' );
313
+ } else {
314
+ jQuery( target ).html( gadwp_item_data.i18n[ 13 ] + ' (' + response + ')' );
315
+ }
316
+ },
317
+
318
+ render : function ( period, query ) {
319
+ var from, to;
320
+ jQuery( '#gadwp-status' + slug ).html( '' );
321
+ switch ( period ) {
322
+ case 'today':
323
+ from = 'today';
324
+ to = 'today';
325
+ break;
326
+ case 'yesterday':
327
+ from = 'yesterday';
328
+ to = 'yesterday';
329
+ break;
330
+ case '7daysAgo':
331
+ from = '7daysAgo';
332
+ to = 'yesterday';
333
+ break;
334
+ case '14daysAgo':
335
+ from = '14daysAgo';
336
+ to = 'yesterday';
337
+ break;
338
+ case '90daysAgo':
339
+ from = '90daysAgo';
340
+ to = 'yesterday';
341
+ break;
342
+ default:
343
+ from = '30daysAgo';
344
+ to = 'yesterday';
345
+ break;
346
+ }
347
+
348
+ var data = {
349
+ action : 'gadwp_backend_item_reports',
350
+ gadwp_security_backend_item_reports : gadwp_item_data.security,
351
+ from : from,
352
+ to : to,
353
+ filter : item_id
354
+ }
355
+
356
+ if ( jQuery.inArray( query, [ 'referrers', 'contentpages', 'searches' ] ) > -1 ) {
357
+
358
+ jQuery( '#gadwp-reports' + slug ).html( '<div id="gadwp-trafficchannels' + slug + '"></div>' )
359
+ jQuery( '#gadwp-reports' + slug ).append( '<div id="gadwp-prs' + slug + '"></div>' );
360
+
361
+ data.query = 'trafficchannels,' + query;
362
+
363
+ jQuery.post( gadwp_item_data.ajaxurl, data, function ( response ) {
364
+ if ( jQuery.isArray( response ) ) {
365
+ if ( !jQuery.isNumeric( response[ 0 ] ) ) {
366
+ if ( jQuery.isArray( response[ 0 ] ) ) {
367
+ reports.trafficchannels = response[ 0 ];
368
+ google.setOnLoadCallback( reports.drawtrafficchannels( reports.trafficchannels ) );
369
+ } else {
370
+ reports.throwDebug( response[ 0 ] );
371
+ }
372
+ } else {
373
+ reports.throwError( '#gadwp-trafficchannels' + slug, response[ 0 ], "125px" );
374
+ }
375
+
376
+ if ( !jQuery.isNumeric( response[ 1 ] ) ) {
377
+ if ( jQuery.isArray( response[ 1 ] ) ) {
378
+ reports.prs = response[ 1 ];
379
+ google.setOnLoadCallback( reports.drawprs( reports.prs ) );
380
+ } else {
381
+ reports.throwDebug( response[ 1 ] );
382
+ }
383
+ } else {
384
+ reports.throwError( '#gadwp-prs' + slug, response[ 1 ], "125px" );
385
+ }
386
+ } else {
387
+ reports.throwDebug( response );
388
+ }
389
+ NProgress.done();
390
+ } );
391
+
392
+ } else if ( query == 'trafficdetails' ) {
393
+
394
+ jQuery( '#gadwp-reports' + slug ).html( '<div id="gadwp-trafficchannels' + slug + '"></div>' )
395
+ jQuery( '#gadwp-reports' + slug ).append( '<div class="gadwp-floatwraper"><div id="gadwp-trafficmediums' + slug + '"></div><div id="gadwp-traffictype' + slug + '"></div></div>' );
396
+ jQuery( '#gadwp-reports' + slug ).append( '<div class="gadwp-floatwraper"><div id="gadwp-trafficorganic' + slug + '"></div><div id="gadwp-socialnetworks' + slug + '"></div></div>' );
397
+
398
+ data.query = 'trafficchannels,medium,visitorType,source,socialNetwork';
399
+
400
+ jQuery.post( gadwp_item_data.ajaxurl, data, function ( response ) {
401
+ if ( jQuery.isArray( response ) ) {
402
+ if ( !jQuery.isNumeric( response[ 0 ] ) ) {
403
+ if ( jQuery.isArray( response[ 0 ] ) ) {
404
+ reports.trafficchannels = response[ 0 ];
405
+ google.setOnLoadCallback( reports.drawtrafficchannels( reports.trafficchannels ) );
406
+ } else {
407
+ reports.throwDebug( response[ 0 ] );
408
+ }
409
+ } else {
410
+ reports.throwError( '#gadwp-trafficchannels' + slug, response[ 0 ], "125px" );
411
+ }
412
+
413
+ if ( !jQuery.isNumeric( response[ 1 ] ) ) {
414
+ if ( jQuery.isArray( response[ 1 ] ) ) {
415
+ reports.trafficmediums = response[ 1 ];
416
+ google.setOnLoadCallback( reports.drawtrafficmediums( reports.trafficmediums ) );
417
+ } else {
418
+ reports.throwDebug( response[ 1 ] );
419
+ }
420
+ } else {
421
+ reports.throwError( '#gadwp-trafficmediums' + slug, response[ 1 ], "80px" );
422
+ }
423
+
424
+ if ( !jQuery.isNumeric( response[ 2 ] ) ) {
425
+ if ( jQuery.isArray( response[ 2 ] ) ) {
426
+ reports.traffictype = response[ 2 ];
427
+ google.setOnLoadCallback( reports.drawtraffictype( reports.traffictype ) );
428
+ } else {
429
+ reports.throwDebug( response[ 2 ] );
430
+ }
431
+ } else {
432
+ reports.throwError( '#gadwp-traffictype' + slug, response[ 2 ], "80px" );
433
+ }
434
+
435
+ if ( !jQuery.isNumeric( response[ 3 ] ) ) {
436
+ if ( jQuery.isArray( response[ 3 ] ) ) {
437
+ reports.trafficorganic = response[ 3 ];
438
+ google.setOnLoadCallback( reports.drawtrafficorganic( reports.trafficorganic ) );
439
+ } else {
440
+ reports.throwDebug( response[ 3 ] );
441
+ }
442
+ } else {
443
+ reports.throwError( '#gadwp-trafficorganic' + slug, response[ 3 ], "80px" );
444
+ }
445
+
446
+ if ( !jQuery.isNumeric( response[ 4 ] ) ) {
447
+ if ( jQuery.isArray( response[ 4 ] ) ) {
448
+ reports.socialnetworks = response[ 4 ];
449
+ google.setOnLoadCallback( reports.drawsocialnetworks( reports.socialnetworks ) );
450
+ } else {
451
+ reports.throwDebug( response[ 4 ] );
452
+ }
453
+ } else {
454
+ reports.throwError( '#gadwp-socialnetworks' + slug, response[ 4 ], "80px" );
455
+ }
456
+ } else {
457
+ reports.throwDebug( response );
458
+ }
459
+ NProgress.done();
460
+ } );
461
+
462
+ } else if ( query == 'locations' ) {
463
+
464
+ jQuery( '#gadwp-reports' + slug ).html( '<div id="gadwp-map' + slug + '"></div>' )
465
+ jQuery( '#gadwp-reports' + slug ).append( '<div id="gadwp-locations' + slug + '"></div>' );
466
+
467
+ data.query = query;
468
+
469
+ jQuery.post( gadwp_item_data.ajaxurl, data, function ( response ) {
470
+ if ( jQuery.isArray( response ) ) {
471
+ if ( !jQuery.isNumeric( response[ 0 ] ) ) {
472
+ if ( jQuery.isArray( response[ 0 ] ) ) {
473
+ reports.locations = response[ 0 ];
474
+ google.setOnLoadCallback( reports.drawmaplocations( reports.locations ) );
475
+ google.setOnLoadCallback( reports.drawlocations( reports.locations ) );
476
+ } else {
477
+ reports.throwDebug( response[ 0 ] );
478
+ }
479
+ } else {
480
+ reports.throwError( '#gadwp-map' + slug, response[ 0 ], "125px" );
481
+ reports.throwError( '#gadwp-locations' + slug, response[ 0 ], "125px" );
482
+ }
483
+ } else {
484
+ reports.throwDebug( response );
485
+ }
486
+ NProgress.done();
487
+ } );
488
+
489
+ } else {
490
+
491
+ jQuery( '#gadwp-reports' + slug ).html( '<div id="gadwp-mainchart' + slug + '"></div>' )
492
+ jQuery( '#gadwp-reports' + slug ).append( '<div id="gadwp-bottomstats' + slug + '" class="gadwp-wrapper"><div class="inside"><div class="small-box"><h3>' + gadwp_item_data.i18n[ 5 ] + '</h3><p id="gdsessions' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 6 ] + '</h3><p id="gdusers' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 7 ] + '</h3><p id="gdpageviews' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 8 ] + '</h3><p id="gdbouncerate' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 9 ] + '</h3><p id="gdorganicsearch' + slug + '">&nbsp;</p></div><div class="small-box"><h3>' + gadwp_item_data.i18n[ 10 ] + '</h3><p id="gdpagespervisit' + slug + '">&nbsp;</p></div></div></div>' );
493
+
494
+ data.query = query + ',bottomstats';
495
+
496
+ jQuery.post( gadwp_item_data.ajaxurl, data, function ( response ) {
497
+ if ( jQuery.isArray( response ) ) {
498
+ if ( !jQuery.isNumeric( response[ 0 ] ) ) {
499
+ if ( jQuery.isArray( response[ 0 ] ) ) {
500
+ reports.mainchart = response[ 0 ];
501
+ google.setOnLoadCallback( reports.drawmainchart( reports.mainchart ) );
502
+ } else {
503
+ reports.throwDebug( response[ 0 ] );
504
+ }
505
+ } else {
506
+ reports.throwError( '#gadwp-mainchart' + slug, response[ 0 ], "125px" );
507
+ }
508
+ if ( !jQuery.isNumeric( response[ 1 ] ) ) {
509
+ if ( jQuery.isArray( response[ 1 ] ) ) {
510
+ reports.bottomstats = response[ 1 ];
511
+ google.setOnLoadCallback( reports.drawbottomstats( reports.bottomstats ) );
512
+ } else {
513
+ reports.throwDebug( response[ 1 ] );
514
+ }
515
+ } else {
516
+ reports.throwError( '#gadwp-bottomstats' + slug, response[ 1 ], "40px" );
517
+ }
518
+ } else {
519
+ reports.throwDebug( response );
520
+ }
521
+ NProgress.done();
522
+ } );
523
+
524
+ }
525
+
526
+ },
527
+
528
+ refresh : function () {
529
+ if ( jQuery( '#gadwp-bottomstats' + slug ).length > 0 ) {
530
+ this.drawbottomstats( this.bottomstats );
531
+ }
532
+ if ( jQuery( '#gadwp-mainchart' + slug ).length > 0 && jQuery.isArray( this.mainchart ) ) {
533
+ this.drawmainchart( this.mainchart );
534
+ }
535
+ if ( jQuery( '#gadwp-map' + slug ).length > 0 && jQuery.isArray( this.locations ) ) {
536
+ this.drawmaplocations( this.locations );
537
+ }
538
+ if ( jQuery( '#gadwp-locations' + slug ).length > 0 && jQuery.isArray( this.locations ) ) {
539
+ this.drawlocations( this.locations );
540
+ }
541
+ if ( jQuery( '#gadwp-socialnetworks' + slug ).length > 0 && jQuery.isArray( this.socialnetworks ) ) {
542
+ this.drawsocialnetworks( this.socialnetworks );
543
+ }
544
+ if ( jQuery( '#gadwp-trafficorganic' + slug ).length > 0 && jQuery.isArray( this.trafficorganic ) ) {
545
+ this.drawtrafficorganic( this.trafficorganic );
546
+ }
547
+ if ( jQuery( '#gadwp-traffictype' + slug ).length > 0 && jQuery.isArray( this.traffictype ) ) {
548
+ this.drawtraffictype( this.traffictype );
549
+ }
550
+ if ( jQuery( '#gadwp-trafficmediums' + slug ).length > 0 && jQuery.isArray( this.trafficmediums ) ) {
551
+ this.drawtrafficmediums( this.trafficmediums );
552
+ }
553
+ if ( jQuery( '#gadwp-trafficchannels' + slug ).length > 0 && jQuery.isArray( this.trafficchannels ) ) {
554
+ this.drawtrafficchannels( this.trafficchannels );
555
+ }
556
+ if ( jQuery( '#gadwp-prs' + slug ).length > 0 && jQuery.isArray( this.prs ) ) {
557
+ this.drawprs( this.prs );
558
+ }
559
+ },
560
+
561
+ init : function () {
562
+
563
+ if ( jQuery( "#gadwp-reports" + slug ).html().length ) { // only when report is empty
564
+ return;
565
+ }
566
+
567
+ try {
568
+ NProgress.configure( {
569
+ parent : "#gadwp-progressbar" + slug,
570
+ showSpinner : false
571
+ } );
572
+ NProgress.start();
573
+ } catch ( e ) {
574
+ this.alertMessage( gadwp_item_data.i18n[ 0 ] );
575
+ }
576
+
577
+ this.render( jQuery( '#gadwp-sel-period' + slug ).val(), jQuery( '#gadwp-sel-report' + slug ).val() );
578
+
579
+ jQuery( window ).resize( function () {
580
+ reports.refresh();
581
+ } );
582
+ }
583
+ }
584
+
585
+ template.init();
586
+
587
+ reports.init();
588
+
589
+ jQuery( '#gadwp-sel-period' + slug ).change( function () {
590
+ jQuery( '#gadwp-reports' + slug ).html( '' );
591
+ reports.init();
592
+ } );
593
+
594
+ jQuery( '#gadwp-sel-report' + slug ).change( function () {
595
+ jQuery( '#gadwp-reports' + slug ).html( '' );
596
+ reports.init();
597
+ } );
598
+
599
+ return this.dialog( {
600
+ width : 'auto',
601
+ maxWidth : 510,
602
+ height : 'auto',
603
+ modal : true,
604
+ fluid : true,
605
+ dialogClass : 'gadwp wp-dialog',
606
+ resizable : false,
607
+ title : jQuery( '#gadwp' + slug ).attr( "title" ),
608
+ position : {
609
+ my : "top",
610
+ at : "top+100",
611
+ of : window
612
+ }
613
+ } );
614
+
615
+ }
616
+ } );
 
 
 
 
 
 
 
 
 
 
 
 
 
admin/settings.php CHANGED
@@ -8,98 +8,93 @@
8
  */
9
 
10
  // Exit if accessed directly
11
- if (! defined('ABSPATH'))
12
- exit();
13
 
14
- final class GADWP_Settings
15
- {
16
 
17
- private static function update_options($who)
18
- {
19
- $gadwp = GADWP();
20
- $network_settings = false;
21
- $options = $gadwp->config->options; // Get current options
22
- if (isset($_POST['options']['ga_dash_hidden']) && isset($_POST['options']) && (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) && $who != 'Reset') {
23
- $new_options = $_POST['options'];
24
- if ($who == 'tracking') {
25
- $options['ga_dash_anonim'] = 0;
26
- $options['ga_event_tracking'] = 0;
27
- $options['ga_enhanced_links'] = 0;
28
- $options['ga_dash_remarketing'] = 0;
29
- $options['ga_dash_adsense'] = 0;
30
- $options['ga_event_bouncerate'] = 0;
31
- $options['ga_crossdomain_tracking'] = 0;
32
- $options['ga_aff_tracking'] = 0;
33
- $options['ga_hash_tracking'] = 0;
34
- if (isset($_POST['options']['ga_tracking_code'])) {
35
- $new_options['ga_tracking_code'] = trim($new_options['ga_tracking_code'], "\t");
36
- }
37
- if (empty($new_options['ga_track_exclude'])) {
38
- $new_options['ga_track_exclude'] = array();
39
- }
40
- } else
41
- if ($who == 'backend') {
42
- $options['switch_profile'] = 0;
43
- $options['item_reports'] = 0;
44
- $options['dashboard_widget'] = 0;
45
- if (empty($new_options['ga_dash_access_back'])) {
46
- $new_options['ga_dash_access_back'][] = 'administrator';
47
- }
48
- } else
49
- if ($who == 'frontend') {
50
- $options['ga_dash_frontend_stats'] = 0;
51
- $options['ga_dash_frontend_keywords'] = 0;
52
- if (empty($new_options['ga_dash_access_front'])) {
53
- $new_options['ga_dash_access_front'][] = 'administrator';
54
- }
55
- } else
56
- if ($who == 'general') {
57
- $options['ga_dash_userapi'] = 0;
58
- if (! is_multisite()) {
59
- $options['automatic_updates_minorversion'] = 0;
60
- }
61
- } else
62
- if ($who == 'network') {
63
- $options['ga_dash_userapi'] = 0;
64
- $options['ga_dash_network'] = 0;
65
- $options['ga_dash_excludesa'] = 0;
66
- $options['automatic_updates_minorversion'] = 0;
67
- $network_settings = true;
68
- }
69
- $options = array_merge($options, $new_options);
70
- $gadwp->config->options = $options;
71
- $gadwp->config->set_plugin_options($network_settings);
72
- }
73
- return $options;
74
- }
75
 
76
- private static function navigation_tabs($tabs)
77
- {
78
- echo '<div id="icon-themes" class="icon32"><br></div>';
79
- echo '<h2 class="nav-tab-wrapper">';
80
- foreach ($tabs as $tab => $name) {
81
- echo "<a class='nav-tab' id='tab-$tab' href='#top#gadwp-$tab'>$name</a>";
82
- }
83
- echo '</h2>';
84
- }
85
 
86
- public static function frontend_settings()
87
- {
88
- $gadwp = GADWP();
89
- if (! current_user_can('manage_options')) {
90
- return;
91
- }
92
- $options = self::update_options('frontend');
93
- if (isset($_POST['options']['ga_dash_hidden'])) {
94
- $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>";
95
- if (! (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) {
96
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
97
- }
98
- }
99
- if (! $gadwp->config->options['ga_dash_tableid_jail'] || ! $gadwp->config->options['ga_dash_token']) {
100
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
101
- }
102
- ?>
103
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
104
  <div class="wrap">
105
  <?php echo "<h2>" . __( "Google Analytics Frontend Settings", 'ga-dash' ) . "</h2>"; ?><hr>
@@ -118,54 +113,45 @@ final class GADWP_Settings
118
  <td class="roles title"><label for="ga_dash_access_front"><?php _e("Show stats to:", 'ga-dash' ); ?></label></td>
119
  <td class="roles">
120
  <?php
121
- if (! isset($wp_roles)) {
122
- $wp_roles = new WP_Roles();
123
- }
124
- $i = 0;
125
- ?>
126
  <table>
127
  <tr>
128
  <?php
129
- foreach ($wp_roles->role_names as $role => $name) {
130
- if ($role != 'subscriber') {
131
- $i ++;
132
- ?>
133
  <td><label> <input type="checkbox" name="options[ga_dash_access_front][]" value="<?php echo $role; ?>" <?php if (in_array($role,$options['ga_dash_access_front']) || $role=='administrator') echo 'checked="checked"'; if ($role=='administrator') echo 'disabled="disabled"';?> /><?php echo $name; ?>
134
  </label></td>
135
  <?php
136
- }
137
- if ($i % 4 == 0) {
138
- ?>
139
  </tr>
140
  <tr>
141
  <?php
142
- }
143
- }
144
- ?>
145
-
 
 
146
  </table>
147
  </td>
148
  </tr>
149
  <tr>
150
  <td colspan="2" class="title">
151
- <div class="onoffswitch">
152
- <input type="checkbox" name="options[ga_dash_frontend_stats]" value="1" class="onoffswitch-checkbox" id="ga_dash_frontend_stats" <?php checked( $options['ga_dash_frontend_stats'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_frontend_stats">
153
  <div class="onoffswitch-inner"></div>
154
  <div class="onoffswitch-switch"></div>
155
  </label>
156
  </div>
157
- <div class="switch-desc"><?php echo " ".__("show page sessions and users in frontend (after each article)", 'ga-dash' );?></div>
158
- </td>
159
- </tr>
160
- <tr>
161
- <td colspan="2" class="title">
162
- <div class="onoffswitch">
163
- <input type="checkbox" name="options[ga_dash_frontend_keywords]" value="1" class="onoffswitch-checkbox" id="ga_dash_frontend_keywords" <?php checked( $options['ga_dash_frontend_keywords'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_frontend_keywords">
164
- <div class="onoffswitch-inner"></div>
165
- <div class="onoffswitch-switch"></div>
166
- </label>
167
- </div>
168
- <div class="switch-desc"><?php echo " ".__("show page searches (after each article)", 'ga-dash' );?></div>
169
  </td>
170
  </tr>
171
  <tr>
@@ -181,28 +167,29 @@ final class GADWP_Settings
181
 
182
 
183
 
 
 
184
  </form>
185
  <?php
186
- self::output_sidebar();
187
- }
188
 
189
- public static function backend_settings()
190
- {
191
- $gadwp = GADWP();
192
- if (! current_user_can('manage_options')) {
193
- return;
194
- }
195
- $options = self::update_options('backend');
196
- if (isset($_POST['options']['ga_dash_hidden'])) {
197
- $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>";
198
- if (! (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) {
199
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
200
- }
201
- }
202
- if (! $gadwp->config->options['ga_dash_tableid_jail'] || ! $gadwp->config->options['ga_dash_token']) {
203
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
204
- }
205
- ?>
206
  <form name="ga_dash_form" method="post" action="<?php echo esc_url($_SERVER['REQUEST_URI']); ?>">
207
  <div class="wrap">
208
  <?php echo "<h2>" . __( "Google Analytics Backend Settings", 'ga-dash' ) . "</h2>"; ?><hr>
@@ -221,39 +208,41 @@ final class GADWP_Settings
221
  <td class="roles title"><label for="ga_dash_access_back"><?php _e("Show stats to:", 'ga-dash' ); ?></label></td>
222
  <td class="roles">
223
  <?php
224
- if (! isset($wp_roles)) {
225
- $wp_roles = new WP_Roles();
226
- }
227
- $i = 0;
228
- ?>
229
  <table>
230
  <tr>
231
  <?php
232
-
233
- foreach ($wp_roles->role_names as $role => $name) {
234
- if ($role != 'subscriber') {
235
- $i ++;
236
- ?>
237
  <td><label> <input type="checkbox" name="options[ga_dash_access_back][]" value="<?php echo $role; ?>" <?php if (in_array($role,$options['ga_dash_access_back']) || $role=='administrator') echo 'checked="checked"'; if ($role=='administrator') echo 'disabled="disabled"';?> />
238
  <?php echo $name; ?>
239
  </label></td>
240
  <?php
241
- }
242
- if ($i % 4 == 0) {
243
- ?>
244
  </tr>
245
  <tr>
246
  <?php
247
- }
248
- }
249
- ?>
250
-
 
 
251
  </table>
252
  </td>
253
  </tr>
254
  <tr>
255
  <td colspan="2" class="title">
256
- <div class="onoffswitch">
257
  <input type="checkbox" name="options[switch_profile]" value="1" class="onoffswitch-checkbox" id="switch_profile" <?php checked( $options['switch_profile'], 1 ); ?>> <label class="onoffswitch-label" for="switch_profile">
258
  <div class="onoffswitch-inner"></div>
259
  <div class="onoffswitch-switch"></div>
@@ -264,8 +253,8 @@ final class GADWP_Settings
264
  </tr>
265
  <tr>
266
  <td colspan="2" class="title">
267
- <div class="onoffswitch">
268
- <input type="checkbox" name="options[item_reports]" value="1" class="onoffswitch-checkbox" id="item_reports" <?php checked( $options['item_reports'], 1 ); ?>> <label class="onoffswitch-label" for="item_reports">
269
  <div class="onoffswitch-inner"></div>
270
  <div class="onoffswitch-switch"></div>
271
  </label>
@@ -275,7 +264,7 @@ final class GADWP_Settings
275
  </tr>
276
  <tr>
277
  <td colspan="2" class="title">
278
- <div class="onoffswitch">
279
  <input type="checkbox" name="options[dashboard_widget]" value="1" class="onoffswitch-checkbox" id="dashboard_widget" <?php checked( $options['dashboard_widget'], 1 ); ?>> <label class="onoffswitch-label" for="dashboard_widget">
280
  <div class="onoffswitch-inner"></div>
281
  <div class="onoffswitch-switch"></div>
@@ -290,7 +279,7 @@ final class GADWP_Settings
290
  <tr>
291
  <td colspan="2" class="title"> <?php _e("Maximum number of pages to display on real-time tab:", 'ga-dash'); ?>
292
  <input type="number" name="options[ga_realtime_pages]" id="ga_realtime_pages" value="<?php echo (int)$options['ga_realtime_pages']; ?>" size="3">
293
- </td>
294
  </tr>
295
  <tr>
296
  <td colspan="2"><hr><?php echo "<h2>" . __( "Location Settings", 'ga-dash' ) . "</h2>"; ?></td>
@@ -299,7 +288,7 @@ final class GADWP_Settings
299
  <td colspan="2" class="title">
300
  <?php echo __("Target Geo Map to country:", 'ga-dash'); ?>
301
  <input type="text" style="text-align: center;" name="options[ga_target_geomap]" value="<?php echo esc_attr($options['ga_target_geomap']); ?>" size="3">
302
- </td>
303
  </tr>
304
  <tr>
305
  <td colspan="2"><hr></td>
@@ -311,32 +300,33 @@ final class GADWP_Settings
311
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
312
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
313
 
 
 
314
  </form>
315
  <?php
316
- self::output_sidebar();
317
- }
318
 
319
- public static function tracking_settings()
320
- {
321
- $gadwp = GADWP();
322
-
323
- if (! current_user_can('manage_options')) {
324
- return;
325
- }
326
- $options = self::update_options('tracking');
327
- if (isset($_POST['options']['ga_dash_hidden'])) {
328
- $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>";
329
- if (! (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) {
330
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
331
- }
332
- }
333
- if (! $gadwp->config->options['ga_dash_tableid_jail']) {
334
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
335
- }
336
- if (! $options['ga_dash_tracking']) {
337
- $message = "<div class='error'><p>" . __("The tracking component is disabled. You should set <strong>Tracking Options</strong> to <strong>Enabled</strong>", 'ga-dash') . ".</p></div>";
338
- }
339
- ?>
340
  <form name="ga_dash_form" method="post" action="<?php esc_url($_SERVER['REQUEST_URI']); ?>">
341
  <div class="wrap">
342
  <?php echo "<h2>" . __( "Google Analytics Tracking Code", 'ga-dash' ) . "</h2>"; ?>
@@ -347,16 +337,16 @@ final class GADWP_Settings
347
  <div class="settings-wrapper">
348
  <div class="inside">
349
  <?php
350
- $tabs = array(
351
- 'basic' => __("Basic Settings", 'ga-dash'),
352
- 'events' => __("Events Tracking", 'ga-dash'),
353
- 'custom' => __("Custom Definitions", 'ga-dash'),
354
- 'exclude' => __("Exclude Tracking", 'ga-dash'),
355
- 'advanced' => __("Advanced Settings", 'ga-dash')
356
- );
357
- self::navigation_tabs($tabs);
358
- ?>
359
- <?php if (isset($message)) echo $message; ?>
360
  <div id="gadwp-basic">
361
  <table class="options">
362
  <tr>
@@ -390,7 +380,7 @@ final class GADWP_Settings
390
  </tr>
391
  <tr>
392
  <td colspan="2" class="title">
393
- <div class="onoffswitch">
394
  <input type="checkbox" name="options[ga_dash_anonim]" value="1" class="onoffswitch-checkbox" id="ga_dash_anonim" <?php checked( $options['ga_dash_anonim'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_anonim">
395
  <div class="onoffswitch-inner"></div>
396
  <div class="onoffswitch-switch"></div>
@@ -401,7 +391,7 @@ final class GADWP_Settings
401
  </tr>
402
  <tr>
403
  <td colspan="2" class="title">
404
- <div class="onoffswitch">
405
  <input type="checkbox" name="options[ga_dash_remarketing]" value="1" class="onoffswitch-checkbox" id="ga_dash_remarketing" <?php checked( $options['ga_dash_remarketing'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_remarketing">
406
  <div class="onoffswitch-inner"></div>
407
  <div class="onoffswitch-switch"></div>
@@ -419,7 +409,7 @@ final class GADWP_Settings
419
  </tr>
420
  <tr>
421
  <td colspan="2" class="title">
422
- <div class="onoffswitch">
423
  <input type="checkbox" name="options[ga_event_tracking]" value="1" class="onoffswitch-checkbox" id="ga_event_tracking" <?php checked( $options['ga_event_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_event_tracking">
424
  <div class="onoffswitch-inner"></div>
425
  <div class="onoffswitch-switch"></div>
@@ -434,7 +424,7 @@ final class GADWP_Settings
434
  </tr>
435
  <tr>
436
  <td colspan="2" class="title">
437
- <div class="onoffswitch">
438
  <input type="checkbox" name="options[ga_aff_tracking]" value="1" class="onoffswitch-checkbox" id="ga_aff_tracking" <?php checked( $options['ga_aff_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_aff_tracking">
439
  <div class="onoffswitch-inner"></div>
440
  <div class="onoffswitch-switch"></div>
@@ -449,7 +439,7 @@ final class GADWP_Settings
449
  </tr>
450
  <tr>
451
  <td colspan="2" class="title">
452
- <div class="onoffswitch">
453
  <input type="checkbox" name="options[ga_hash_tracking]" value="1" class="onoffswitch-checkbox" id="ga_hash_tracking" <?php checked( $options['ga_hash_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_hash_tracking">
454
  <div class="onoffswitch-inner"></div>
455
  <div class="onoffswitch-switch"></div>
@@ -510,7 +500,7 @@ final class GADWP_Settings
510
  </tr>
511
  <tr>
512
  <td colspan="2" class="title">
513
- <div class="onoffswitch">
514
  <input type="checkbox" name="options[ga_event_bouncerate]" value="1" class="onoffswitch-checkbox" id="ga_event_bouncerate" <?php checked( $options['ga_event_bouncerate'], 1 ); ?>> <label class="onoffswitch-label" for="ga_event_bouncerate">
515
  <div class="onoffswitch-inner"></div>
516
  <div class="onoffswitch-switch"></div>
@@ -521,7 +511,7 @@ final class GADWP_Settings
521
  </tr>
522
  <tr>
523
  <td colspan="2" class="title">
524
- <div class="onoffswitch">
525
  <input type="checkbox" name="options[ga_enhanced_links]" value="1" class="onoffswitch-checkbox" id="ga_enhanced_links" <?php checked( $options['ga_enhanced_links'], 1 ); ?>> <label class="onoffswitch-label" for="ga_enhanced_links">
526
  <div class="onoffswitch-inner"></div>
527
  <div class="onoffswitch-switch"></div>
@@ -532,7 +522,7 @@ final class GADWP_Settings
532
  </tr>
533
  <tr>
534
  <td colspan="2" class="title">
535
- <div class="onoffswitch">
536
  <input type="checkbox" name="options[ga_dash_adsense]" value="1" class="onoffswitch-checkbox" id="ga_dash_adsense" <?php checked( $options['ga_dash_adsense'], 1 ); ?>> <label class="onoffswitch-label" for="ga_dash_adsense">
537
  <div class="onoffswitch-inner"></div>
538
  <div class="onoffswitch-switch"></div>
@@ -543,7 +533,7 @@ final class GADWP_Settings
543
  </tr>
544
  <tr>
545
  <td colspan="2" class="title">
546
- <div class="onoffswitch">
547
  <input type="checkbox" name="options[ga_crossdomain_tracking]" value="1" class="onoffswitch-checkbox" id="ga_crossdomain_tracking" <?php checked( $options['ga_crossdomain_tracking'], 1 ); ?>> <label class="onoffswitch-label" for="ga_crossdomain_tracking">
548
  <div class="onoffswitch-inner"></div>
549
  <div class="onoffswitch-switch"></div>
@@ -567,28 +557,34 @@ final class GADWP_Settings
567
  <td class="roles title"><label for="ga_track_exclude"><?php _e("Exclude tracking for:", 'ga-dash' ); ?></label></td>
568
  <td class="roles">
569
  <?php
570
- if (! isset($wp_roles)) {
571
- $wp_roles = new WP_Roles();
572
- }
573
- $i = 0;
574
- ?> <table>
575
  <tr>
576
  <?php
577
- foreach ($wp_roles->role_names as $role => $name) {
578
- $i ++;
579
- ?>
580
  <td><label> <input type="checkbox" name="options[ga_track_exclude][]" value="<?php echo $role; ?>" <?php if (in_array($role,$options['ga_track_exclude'])) echo 'checked="checked"'; ?> />
581
  <?php echo $name; ?>
582
  </label></td>
583
  <?php
584
- if ($i % 4 == 0) {
585
- ?>
586
  </tr>
587
  <tr>
588
  <?php
589
- }
590
- }
591
- ?>
 
 
 
 
 
 
592
  </table>
593
  </td>
594
  </tr>
@@ -605,45 +601,46 @@ final class GADWP_Settings
605
  <input type="hidden" name="options[ga_dash_hidden]" value="Y">
606
  <?php wp_nonce_field('gadash_form','gadash_security'); ?>
607
 
 
 
608
  </form>
609
  <?php
610
- self::output_sidebar();
611
- }
 
 
 
 
 
 
 
 
 
612
 
613
- public static function errors_debugging()
614
- {
615
- global $wp_version;
616
-
617
- $gadwp = GADWP();
618
-
619
- if (! current_user_can('manage_options')) {
620
- return;
621
- }
622
-
623
- $anonim = $gadwp->config->options;
624
- $anonim['wp_version'] = $wp_version;
625
- $anonim['gadwp_version'] = GADWP_CURRENT_VERSION;
626
- if ($anonim['ga_dash_token']) {
627
- $anonim['ga_dash_token'] = 'HIDDEN';
628
- }
629
- if ($anonim['ga_dash_refresh_token']) {
630
- $anonim['ga_dash_refresh_token'] = 'HIDDEN';
631
- }
632
- if ($anonim['ga_dash_clientid']) {
633
- $anonim['ga_dash_clientid'] = 'HIDDEN';
634
- }
635
- if ($anonim['ga_dash_clientsecret']) {
636
- $anonim['ga_dash_clientsecret'] = 'HIDDEN';
637
- }
638
- if ($anonim['ga_dash_apikey']) {
639
- $anonim['ga_dash_apikey'] = 'HIDDEN';
640
- }
641
-
642
- $options = self::update_options('frontend');
643
- if (! $gadwp->config->options['ga_dash_tableid_jail'] || ! $gadwp->config->options['ga_dash_token']) {
644
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));
645
- }
646
- ?>
647
  <div class="wrap">
648
  <?php echo "<h2>" . __( "Google Analytics Errors & Debugging", 'ga-dash' ) . "</h2>"; ?>
649
  </div>
@@ -654,12 +651,11 @@ final class GADWP_Settings
654
  <div class="inside">
655
  <?php if (isset($message)) echo $message; ?>
656
  <?php
657
- $tabs = array(
658
- 'errors' => __("Errors & Details", 'ga-dash'),
659
- 'config' => __("Plugin Settings", 'ga-dash')
660
- );
661
- self::navigation_tabs($tabs);
662
- ?>
663
  <div id="gadwp-errors">
664
  <table class="options">
665
  <tr>
@@ -670,10 +666,10 @@ final class GADWP_Settings
670
  <tr>
671
  <td>
672
  <?php
673
- $errors = esc_html(print_r(get_transient('ga_dash_lasterror'), true)) ? esc_html(print_r(get_transient('ga_dash_lasterror'), true)) : __("None", 'ga-dash');
674
- echo '<pre class="log_data">Last Error: ';
675
- echo $errors;
676
- ?></pre>
677
  </td>
678
  </tr>
679
  <tr>
@@ -682,16 +678,16 @@ final class GADWP_Settings
682
  <tr>
683
  <td>
684
  <?php
685
- echo '<pre class="log_data">Error Details: ';
686
- $error_details = esc_html(print_r(get_transient('ga_dash_gapi_errors'), true)) ? "\n" . esc_html(print_r(get_transient('ga_dash_gapi_errors'), true)) : __("None", 'ga-dash');
687
- echo $error_details;
688
- ?></pre><br />
689
  <hr>
690
  </td>
691
-
692
-
693
  <tr>
694
-
695
  </table>
696
  </div>
697
  <div id="gadwp-config">
@@ -701,120 +697,118 @@ final class GADWP_Settings
701
  </tr>
702
  <tr>
703
  <td><pre class="log_data"><?php echo esc_html(print_r($anonim, true));?></pre><br />
704
- <hr></td>
705
  </tr>
706
  </table>
707
  </div>
708
  <?php
709
- self::output_sidebar();
710
- }
711
 
712
- public static function general_settings()
713
- {
714
- $gadwp = GADWP();
715
-
716
- global $wp_version;
717
-
718
- if (! current_user_can('manage_options')) {
719
- return;
720
- }
721
- $options = self::update_options('general');
722
- printf('<div id="gapi-warning" class="updated"><p>%1$s <a href="https://deconf.com/google-analytics-dashboard-wordpress/?utm_source=gadwp_config&utm_medium=link&utm_content=general_screen&utm_campaign=gadwp">%2$s</a></p></div>', __('Loading the required libraries. If this results in a blank screen or a fatal error, try this solution:', "ga-dash"), __('Library conflicts between WordPress plugins', "ga-dash"));
723
- if (null === $gadwp->gapi_controller) {
724
- $gadwp->gapi_controller = new GADWP_GAPI_Controller();
725
- }
726
- echo '<script type="text/javascript">jQuery("#gapi-warning").hide()</script>';
727
- if (isset($_POST['ga_dash_code'])) {
728
- if (! stripos('x' . $_POST['ga_dash_code'], 'UA-', 1) == 1) {
729
- try {
730
- $gadwp->gapi_controller->client->authenticate($_POST['ga_dash_code']);
731
- $gadwp->config->options['ga_dash_token'] = $gadwp->gapi_controller->client->getAccessToken();
732
- $google_token = json_decode($gadwp->gapi_controller->client->getAccessToken());
733
- $gadwp->config->options['ga_dash_refresh_token'] = $google_token->refresh_token;
734
- $gadwp->config->options['automatic_updates_minorversion'] = 1;
735
- $gadwp->config->set_plugin_options();
736
- $options = self::update_options('general');
737
- $message = "<div class='updated'><p>" . __("Plugin authorization succeeded.", 'ga-dash') . "</p></div>";
738
- delete_transient('ga_dash_gapi_errors');
739
- delete_transient('ga_dash_lasterror');
740
- } catch (Google_IO_Exception $e) {
741
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $gadwp->gapi_controller->error_timeout);
742
- return false;
743
- } catch (Google_Service_Exception $e) {
744
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html("(" . $e->getCode() . ") " . $e->getMessage()), $gadwp->gapi_controller->error_timeout);
745
- set_transient('ga_dash_gapi_errors', $e->getErrors(), $gadwp->gapi_controller->error_timeout);
746
- return $e->getCode();
747
- } catch (Exception $e) {
748
- set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e) . "\nResponseHttpCode:" . $e->getCode(), $gadwp->gapi_controller->error_timeout);
749
- $gadwp->gapi_controller->reset_token(false);
750
- }
751
- } else {
752
- $message = "<div class='error'><p>" . __("The access code is <strong>NOT</strong> your <strong>Tracking ID</strong> (UA-XXXXX-X). Try again, and use the red link to get your access code", 'ga-dash') . ".</p></div>";
753
- }
754
- }
755
- if ($gadwp->config->options['ga_dash_token'] && $gadwp->gapi_controller->client->getAccessToken()) {
756
- if (!empty($gadwp->config->options['ga_dash_profile_list'])) {
757
- $profiles = $gadwp->config->options['ga_dash_profile_list'];
758
- } else {
759
- $profiles = $gadwp->gapi_controller->refresh_profiles();
760
- }
761
- if ($profiles) {
762
- $gadwp->config->options['ga_dash_profile_list'] = $profiles;
763
- if (! $gadwp->config->options['ga_dash_tableid_jail']) {
764
- $profile = GADWP_Tools::guess_default_domain($profiles);
765
- $gadwp->config->options['ga_dash_tableid_jail'] = $profile;
766
- $gadwp->config->options['ga_dash_tableid'] = $profile;
767
- }
768
- $gadwp->config->set_plugin_options();
769
- $options = self::update_options('general');
770
- }
771
- }
772
- if (isset($_POST['Clear'])) {
773
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
774
- GADWP_Tools::clear_cache();
775
- $message = "<div class='updated'><p>" . __("Cleared Cache.", 'ga-dash') . "</p></div>";
776
- } else {
777
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
778
- }
779
- }
780
- if (isset($_POST['Reset'])) {
781
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
782
- $gadwp->gapi_controller->reset_token(true);
783
- GADWP_Tools::clear_cache();
784
- $message = "<div class='updated'><p>" . __("Token Reseted and Revoked.", 'ga-dash') . "</p></div>";
785
- $options = self::update_options('Reset');
786
- } else {
787
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
788
- }
789
- }
790
- if (isset($_POST['Reset_Err'])) {
791
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
792
- delete_transient('ga_dash_lasterror');
793
- delete_transient('ga_dash_gapi_errors');
794
- $message = "<div class='updated'><p>" . __("All errors reseted.", 'ga-dash') . "</p></div>";
795
- } else {
796
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
797
- }
798
- }
799
- if (isset($_POST['options']['ga_dash_hidden']) && ! isset($_POST['Clear']) && ! isset($_POST['Reset']) && ! isset($_POST['Reset_Err'])) {
800
- $message = "<div class='updated'><p>" . __("Settings saved.", 'ga-dash') . "</p></div>";
801
- if (! (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form'))) {
802
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
803
- }
804
- }
805
- if (isset($_POST['Hide'])) {
806
- if (isset($_POST['gadash_security']) && wp_verify_nonce($_POST['gadash_security'], 'gadash_form')) {
807
- $message = "<div class='updated'><p>" . __("All other domains/properties were removed.", 'ga-dash') . "</p></div>";
808
- $lock_profile = GADWP_Tools::get_selected_profile($gadwp->config->options['ga_dash_profile_list'], $gadwp->config->options['ga_dash_tableid_jail']);
809
- $gadwp->config->options['ga_dash_profile_list'] = array(
810
- $lock_profile
811
- );
812
- $options = self::update_options('general');
813
- } else {
814
- $message = "<div class='error'><p>" . __("Cheating Huh?", 'ga-dash') . "</p></div>";
815
- }
816
- }
817
- ?>
818
  <div class="wrap">
819
  <?php echo "<h2>" . __( "Google Analytics Settings", 'ga-dash' ) . "</h2>"; ?>
820
  <hr>
@@ -823,18 +817,19 @@ final class GADWP_Settings
823
  <div id="post-body" class="metabox-holder columns-2">
824
  <div id="post-body-content">
825
  <div class="settings-wrapper">
826
- <div class="inside">
827
- if ($gadwp->gapi_controller->gapi_errors_handler()) {
828
- $message = sprintf('<div class="error"><p>%s</p></div>', sprintf(__('Something went wrong, check %1$s or %2$s.', 'ga-dash'), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_errors_debugging', false), __('Errors & Debug', 'ga-dash')), sprintf('<a href="%1$s">%2$s</a>', menu_page_url('gadash_settings', false), __('authorize the plugin', 'ga-dash'))));