WD Google Analytics - Version 1.0.12

Version Description

Fixed: Bug on report by individual post/page

Download this release

Release Info

Developer webdorado
Plugin Icon 128x128 WD Google Analytics
Version 1.0.12
Comparing to
See all releases

Code changes from version 1.0.11 to 1.0.12

Files changed (3) hide show
  1. gawd_class.php +2238 -4528
  2. google-analytics-wd.php +2 -2
  3. readme.txt +6 -3
gawd_class.php CHANGED
@@ -1,4434 +1,2277 @@
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
 
 
 
 
7
 
 
 
 
 
8
 
9
- class GAWD {
 
 
 
10
 
 
 
 
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
- /**
 
 
 
 
 
 
 
 
 
14
 
15
- * @var GAWD The reference to Singleton instance of this class
 
 
 
16
 
17
- */
 
 
 
 
 
 
 
 
 
18
 
19
- private static $instance;
 
 
 
20
 
21
- private $project_client_id = null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- private $project_client_secret = null;
 
 
 
 
 
 
 
 
24
 
25
- public $redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
 
 
27
 
 
28
 
29
- /**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
- * Protected constructor to prevent creating a new instance of the
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
- * Singleton via the `new` operator from outside of this class.
 
 
 
 
 
34
 
35
- */
 
 
 
36
 
37
- protected function __construct() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
 
 
 
 
 
40
 
41
- if ( isset( $_POST["reset_data"] ) && $_POST["reset_data"] != '' ) {
 
 
 
42
 
43
- $this->reset_user_data();
 
 
 
44
 
45
- }
 
 
 
46
 
47
- add_action( 'admin_menu', array( $this, 'gawd_check_id' ), 1 );
 
 
 
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
 
 
 
 
 
 
 
50
 
51
- add_action( 'admin_notices', array( $this, 'upgrade_pro' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
- add_action( 'admin_menu', array( $this, 'gawd_add_menu' ), 19 );
 
 
 
 
 
 
 
 
56
 
57
- add_action( 'admin_enqueue_scripts', array( $this, 'gawd_enqueue_scripts' ) );
 
 
 
 
 
 
 
 
58
 
 
 
 
 
59
 
 
 
 
 
 
60
 
61
- add_action( 'wp_ajax_gawd_auth', array( $this, 'gawd_auth' ) );
62
 
63
- add_action( 'wp_ajax_create_pdf_file', array( $this, 'create_pdf_file' ) );
64
 
65
- add_action( 'wp_ajax_create_csv_file', array( $this, 'create_csv_file' ) );
66
 
67
- add_action( 'wp_ajax_show_data', array( $this, 'show_data' ) );
68
 
69
- add_action( 'wp_ajax_remove_zoom_message', array( $this, 'remove_zoom_message' ) );
70
 
71
- add_action( 'wp_ajax_show_page_post_data', array( $this, 'show_page_post_data' ) );
72
 
73
- add_action( 'wp_ajax_show_data_compact', array( $this, 'show_data_compact' ) );
74
 
75
- add_action( 'wp_ajax_get_realtime', array( $this, 'get_realtime' ) );
76
 
77
- add_action( 'wp_dashboard_setup', array( $this, 'google_analytics_wd_dashboard_widget' ) );
78
 
79
- add_action( 'admin_menu', array( $this, 'overview_date_meta' ) );
80
 
81
- add_filter( 'cron_schedules', array( $this, 'gawd_my_schedule' ) );
82
 
83
- add_action( 'admin_init', array( $this, 'gawd_export' ) );
84
 
85
- add_action( 'gawd_pushover_daily', array( $this, 'gawd_pushover_daily' ) );
86
 
87
- add_action( 'gawd_pushover_gawd_weekly', array( $this, 'gawd_pushover_weekly' ) );
88
 
89
- add_action( 'gawd_pushover_gawd_monthly', array( $this, 'gawd_pushover_monthly' ) );
90
 
91
- add_action( 'gawd_alert_daily', array( $this, 'gawd_alert_daily' ) );
 
 
92
 
93
- add_action( 'gawd_alert_gawd_monthly', array( $this, 'gawd_alert_monthly' ) );
 
 
 
 
94
 
95
- add_action( 'gawd_alert_gawd_weekly', array( $this, 'gawd_alert_weekly' ) );
 
 
 
 
 
96
 
97
- add_action( 'gawd_email_daily', array( $this, 'gawd_daily_email' ), 0 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
 
99
- add_action( 'gawd_email_gawd_weekly', array( $this, 'gawd_weekly_email' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
 
101
- add_action( 'gawd_email_gawd_monthly', array( $this, 'gawd_monthly_email' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
- //add_action('init', array($this, 'gawd_daily_email'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
- add_action( 'wp_head', array( $this, 'gawd_tracking_code' ), 99 );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
 
107
- include_once(GAWD_DIR . '/include/gawd-notices-class.php');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
- add_action( 'admin_notices', array( $this, 'check_property_delete' ),9999);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
114
 
115
- $gawd_settings = get_option( 'gawd_settings' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
- $gawd_post_page_roles = isset( $gawd_settings['gawd_post_page_roles'] ) ? $gawd_settings['gawd_post_page_roles'] : array();
 
 
 
 
 
 
 
 
 
 
 
118
 
119
- $roles = $this->get_current_user_role();
120
 
121
- if ( ( isset( $gawd_settings['gawd_tracking_enable'] ) && $gawd_settings['gawd_tracking_enable'] == 'on' ) && ( isset( $gawd_settings['post_page_chart'] ) && $gawd_settings['post_page_chart'] != '' ) && ( in_array( $roles, $gawd_post_page_roles ) || current_user_can( 'manage_options' ) ) ) {
122
 
123
- add_filter( 'manage_posts_columns', array( $this, 'gawd_add_columns' ) );
124
 
125
- // Populate custom column in Posts List
126
 
127
- add_action( 'manage_posts_custom_column', array( $this, 'gawd_add_icons' ), 10, 2 );
128
 
129
- // Add custom column in Pages List
130
 
131
- add_filter( 'manage_pages_columns', array( $this, 'gawd_add_columns' ) );
 
 
 
 
132
 
133
- // Populate custom column in Pages List
134
 
135
- add_action( 'manage_pages_custom_column', array( $this, 'gawd_add_icons' ), 10, 2 );
136
 
137
- add_action( 'load-post.php', array( $this, 'gawd_add_custom_box' ) );
138
 
139
- }
140
 
141
- $gawd_frontend_roles = isset( $gawd_settings['gawd_frontend_roles'] ) ? $gawd_settings['gawd_frontend_roles'] : array();
142
 
143
- if ( ( isset( $gawd_settings['gawd_tracking_enable'] ) && $gawd_settings['gawd_tracking_enable'] == 'on' ) && ( in_array( $roles, $gawd_frontend_roles ) || current_user_can( 'manage_options' ) ) ) {
144
 
145
- add_action( 'wp_enqueue_scripts', array( $this, 'gawd_front_scripts' ) );
146
 
147
- add_action( 'admin_bar_menu', array( $this, 'report_adminbar' ), 999 );
148
 
149
- }
150
 
 
151
 
 
152
 
 
153
 
 
154
 
155
- $this->update_credentials();
156
 
157
- $credentials = get_option( 'gawd_credentials' );
158
 
 
159
 
 
160
 
 
161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
162
 
163
- if ( is_array( $credentials ) ) {
164
 
165
- $this->set_project_client_id( $credentials['project_id'] );
166
 
167
- $this->set_project_client_secret( $credentials['project_secret'] );
168
 
169
- } else {
170
 
171
- //send error
172
 
173
- return;
174
 
175
- }
 
 
 
 
176
 
177
- }
178
 
 
179
 
 
180
 
181
- function get_current_user_role() {
182
 
183
- global $wp_roles;
184
 
185
- if ( is_user_logged_in() ) {
186
 
187
- $current_user = wp_get_current_user();
 
 
 
 
 
188
 
189
- $roles = $current_user->roles;
 
 
 
 
190
 
191
- $role = array_shift( $roles );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
 
 
193
 
 
194
 
195
- return $role;
196
 
197
- } else {
198
 
199
- return "";
200
 
201
- }
202
 
203
- }
204
 
 
205
 
 
206
 
 
207
 
 
208
 
209
- function report_adminbar( $wp_admin_bar ) {
210
 
211
- /* @formatter:off */
212
 
213
- $gawd_settings = get_option( 'gawd_settings' );
214
 
215
- $gawd_frontend_roles = isset( $gawd_settings['gawd_frontend_roles'] ) ? $gawd_settings['gawd_frontend_roles'] : array();
 
 
 
 
 
 
216
 
217
- $roles = $this->get_current_user_role();
218
 
219
- if ( ( ( in_array( $roles, $gawd_frontend_roles ) || current_user_can( 'manage_options' ) ) && ! is_admin() ) && $gawd_settings['post_page_chart'] != '' ) {
 
 
220
 
221
- $id = get_the_ID();
 
 
 
222
 
223
- $uri_parts = explode( '/', get_permalink( $id ), 4 );
224
 
225
- if ( $uri_parts[0] != '' ) {
226
 
227
- if ( isset( $uri_parts[3] ) ) {
228
 
229
- $uri = '/' . $uri_parts[3];
230
 
231
- }
 
 
232
 
233
- $uri = explode( '/', $uri );
234
-
235
- end( $uri );
236
-
237
- $key = key( $uri );
238
-
239
- $uri = '/' . $uri[ $key - 1 ];
240
-
241
- $filter = rawurlencode( rawurldecode( $uri ) );
242
-
243
-
244
-
245
- $args = array(
246
-
247
- 'id' => 'gawd',
248
-
249
- 'title' => '<span data-url="' . $filter . '" class="ab-icon"></span><span class="">' . __( "Analytics WD", 'gawd' ) . '</span>',
250
-
251
- 'href' => '#1',
252
-
253
- );
254
-
255
- /* @formatter:on */
256
-
257
- $wp_admin_bar->add_node( $args );
258
-
259
- }
260
-
261
- }
262
-
263
- }
264
-
265
-
266
-
267
- public function update_credentials() {
268
-
269
- //check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
270
-
271
- if ( $_POST ) {
272
-
273
- $gawd_own_project = isset( $_POST['gawd_own_project'] ) ? $_POST['gawd_own_project'] : '';
274
-
275
- $gawd_own_client_id = isset( $_POST['gawd_own_client_id'] ) ? $_POST['gawd_own_client_id'] : '';
276
-
277
- $gawd_own_client_secret = isset( $_POST['gawd_own_client_secret'] ) ? $_POST['gawd_own_client_secret'] : '';
278
-
279
- $gawd_credentials['project_id'] = $gawd_own_client_id;
280
-
281
- $gawd_credentials['project_secret'] = $gawd_own_client_secret;
282
-
283
- if ( $gawd_own_project && $gawd_own_client_id != '' && $gawd_own_client_secret != '' ) {
284
-
285
- update_option( 'gawd_credentials', $gawd_credentials );
286
-
287
- delete_option( 'gawd_user_data' );
288
-
289
- add_option( 'gawd_own_project', 1 );
290
-
291
- }
292
-
293
- }
294
-
295
- }
296
-
297
-
298
-
299
- public function set_project_client_id( $id ) {
300
-
301
- $this->project_client_id = $id;
302
-
303
- }
304
-
305
-
306
-
307
- public function get_project_client_id() {
308
-
309
- return $this->project_client_id;
310
-
311
- }
312
-
313
-
314
-
315
- public function set_project_client_secret( $secret ) {
316
-
317
- $this->project_client_secret = $secret;
318
-
319
- }
320
-
321
-
322
-
323
- public function get_project_client_secret() {
324
-
325
- return $this->project_client_secret;
326
-
327
- }
328
-
329
-
330
-
331
- function gawd_check_id() {
332
-
333
- global $gawd_redirect_to_settings;
334
-
335
- $current_page = isset( $_GET['page'] ) ? $_GET['page'] : "";
336
-
337
- if ( strpos( $current_page, 'gawd' ) !== false ) {
338
-
339
- $gawd_user_data = get_option( 'gawd_user_data' );
340
-
341
- if ( ! isset( $gawd_user_data['refresh_token'] ) || ( $gawd_user_data['refresh_token'] == '' ) ) {
342
-
343
- update_option( 'gawd_redirect_to_settings', 'yes' );
344
-
345
- } else {
346
-
347
- update_option( 'gawd_redirect_to_settings', 'no' );
348
-
349
- }
350
-
351
- }
352
-
353
- $gawd_redirect_to_settings = get_option( 'gawd_redirect_to_settings' );
354
-
355
- }
356
-
357
-
358
-
359
- function gawd_add_custom_box() {
360
-
361
- $screens = array( 'post', 'page' );
362
-
363
- foreach ( $screens as $screen ) {
364
-
365
- add_meta_box( 'gawd_page_post_meta', 'Sessions in month', array(
366
-
367
- $this,
368
-
369
- 'gawd_add_custom_box_callback'
370
-
371
- ), $screen, 'normal' );
372
-
373
- }
374
-
375
- }
376
-
377
-
378
-
379
- function gawd_add_custom_box_callback() {
380
-
381
- require_once( 'admin/post_page_view.php' );
382
-
383
- }
384
-
385
-
386
-
387
- public function gawd_add_icons( $column, $id ) {
388
-
389
- if ( $column != 'gawd_stats' ) {
390
-
391
- return;
392
-
393
- }
394
-
395
- $uri_parts = explode( '/', get_permalink( $id ), 4 );
396
-
397
- if ( isset( $uri_parts[3] ) ) {
398
-
399
- $uri = '/' . $uri_parts[3];
400
-
401
- }
402
-
403
- $uri = explode( '/', $uri );
404
-
405
- end( $uri );
406
-
407
- $key = key( $uri );
408
-
409
- $uri = '/' . $uri[ $key - 1 ];
410
-
411
- $filter = rawurlencode( rawurldecode( $uri ) );
412
-
413
- echo '<a id="gawd-' . $id . '" class="gawd_page_post_stats" title="' . get_the_title( $id ) . '" href="#' . $filter . '"><img src="' . GAWD_URL . '/assets/back_logo.png"</a>';
414
-
415
- }
416
-
417
-
418
-
419
- public function gawd_add_columns( $columns ) {
420
-
421
- return array_merge( $columns, array( 'gawd_stats' => __( 'Analytics WD', 'gawd' ) ) );
422
-
423
- }
424
-
425
-
426
-
427
- public static function gawd_roles( $access_level, $tracking = false ) {
428
-
429
- if ( is_user_logged_in() && isset( $access_level ) ) {
430
-
431
- $current_user = wp_get_current_user();
432
-
433
- $roles = (array) $current_user->roles;
434
-
435
- if ( ( current_user_can( 'manage_options' ) ) && ! $tracking ) {
436
-
437
- return true;
438
-
439
- }
440
-
441
- if ( count( array_intersect( $roles, $access_level ) ) > 0 ) {
442
-
443
- return true;
444
-
445
- } else {
446
-
447
- return false;
448
-
449
- }
450
-
451
- }
452
-
453
-
454
-
455
- return false;
456
-
457
- }
458
-
459
-
460
-
461
- public function gawd_tracking_code() {
462
-
463
- $gawd_user_data = get_option( 'gawd_user_data' );
464
-
465
- if ( isset( $gawd_user_data['default_webPropertyId'] ) && ( $gawd_user_data['default_webPropertyId'] ) ) {
466
-
467
- global $gawd_client;
468
-
469
- $gawd_client = GAWD_google_client::get_instance();
470
-
471
- require_once( GAWD_DIR . '/admin/tracking.php' );
472
-
473
- }
474
-
475
- }
476
-
477
-
478
-
479
- public function create_pdf_file( $ajax = true, $data = null, $dimension = null, $start_date = null, $end_date = null, $metric_compare_recc = null, $metric_recc = null ) {
480
-
481
- $first_data = isset( $_REQUEST["first_data"] ) ? sanitize_text_field( $_REQUEST["first_data"] ) : '';
482
-
483
- $_data_compare = isset( $_REQUEST["_data_compare"] ) ? ( $_REQUEST["_data_compare"] ) : '';
484
-
485
- if ( $ajax == true ) {
486
-
487
- $export_type = isset( $_REQUEST["export_type"] ) ? sanitize_text_field( $_REQUEST["export_type"] ) : '';
488
-
489
- if ( $export_type != 'pdf' ) {
490
-
491
- return;
492
-
493
- }
494
-
495
-
496
-
497
- $report_type = isset( $_REQUEST["report_type"] ) ? sanitize_text_field( $_REQUEST["report_type"] ) : '';
498
-
499
-
500
-
501
-
502
-
503
- if ( $report_type !== 'alert' ) {
504
-
505
- return;
506
-
507
- }
508
-
509
-
510
-
511
- }
512
-
513
-
514
-
515
- include_once GAWD_DIR . '/include/gawd_pdf_file.php';
516
-
517
- $file = new GAWD_PDF_FILE();
518
-
519
-
520
-
521
- /*
522
-
523
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
524
-
525
- $this->gawd_google_client = GAWD_google_client::get_instance();
526
-
527
- */
528
-
529
- $file->get_request_data( $this, $ajax, $data, $dimension, $start_date, $end_date, $metric_compare_recc, $metric_recc );
530
-
531
-
532
-
533
- $file->sort_data();
534
-
535
- if ( $first_data != '' ) {
536
-
537
- $file->create_file( 'pages' );
538
-
539
- } elseif ( ( $_data_compare ) != '' ) {
540
-
541
- $file->create_file( 'compare' );
542
-
543
- } else {
544
-
545
- $file->create_file( true );
546
-
547
- }
548
-
549
- if ( $ajax == true ) {
550
-
551
- die();
552
-
553
- } else {
554
-
555
- return $file->file_dir;
556
-
557
- }
558
-
559
- }
560
-
561
-
562
-
563
- public function create_csv_file( $ajax = true, $data = null, $dimension = null, $start_date = null, $end_date = null, $metric_compare_recc = null, $metric_recc = null ) {
564
-
565
- if ( $ajax == true ) {
566
-
567
- $export_type = isset( $_REQUEST["export_type"] ) ? sanitize_text_field( $_REQUEST["export_type"] ) : '';
568
-
569
- if ( $export_type != 'csv' ) {
570
-
571
- return;
572
-
573
- }
574
-
575
- $report_type = isset( $_REQUEST["report_type"] ) ? sanitize_text_field( $_REQUEST["report_type"] ) : '';
576
-
577
- if ( $report_type !== 'alert' ) {
578
-
579
- return;
580
-
581
- }
582
-
583
- }
584
-
585
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
586
-
587
- $this->gawd_google_client = GAWD_google_client::get_instance();
588
-
589
-
590
-
591
- $first_data = isset( $_REQUEST["first_data"] ) ? sanitize_text_field( $_REQUEST["first_data"] ) : '';
592
-
593
-
594
-
595
-
596
-
597
- include_once GAWD_DIR . '/include/gawd_csv_file.php';
598
-
599
-
600
-
601
- $file = new GAWD_CSV_FILE();
602
-
603
- $file->get_request_data( $this, $ajax, $data, $dimension, $start_date, $end_date, $metric_compare_recc, $metric_recc );
604
-
605
-
606
-
607
- $file->sort_data();
608
-
609
-
610
-
611
- //$file->get_request_data($this);
612
-
613
-
614
-
615
- $file->sort_data();
616
-
617
- if ( $first_data != '' ) {
618
-
619
- $file->create_file( false );
620
-
621
- } else {
622
-
623
- $file->create_file();
624
-
625
- }
626
-
627
- if ( $ajax == true ) {
628
-
629
- die();
630
-
631
- } else {
632
-
633
- return $file->file_dir;
634
-
635
- }
636
-
637
- }
638
-
639
-
640
-
641
- public static function get_domain( $domain ) {
642
-
643
- $root = explode( '/', $domain );
644
-
645
- $ret_domain = str_ireplace( 'www', '', isset( $root[2] ) ? $root[2] : $domain );
646
-
647
-
648
-
649
- return $ret_domain;
650
-
651
- }
652
-
653
-
654
-
655
- public static function error_message( $type, $message ) {
656
-
657
- echo '<div style="width:99%"><div class="' . $type . '"><p><strong>' . $message . '</strong></p></div></div>';
658
-
659
- }
660
-
661
-
662
-
663
- public function gawd_export() {
664
-
665
- if ( ! isset( $_REQUEST['action'] ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] !== 'gawd_export' ) ) {
666
-
667
- return;
668
-
669
- }
670
-
671
-
672
-
673
- $export_type = isset( $_REQUEST["export_type"] ) ? sanitize_text_field( $_REQUEST["export_type"] ) : '';
674
-
675
- if ( $export_type != 'pdf' && $export_type != 'csv' ) {
676
-
677
- return;
678
-
679
- }
680
-
681
-
682
-
683
- $report_type = isset( $_REQUEST["report_type"] ) ? sanitize_text_field( $_REQUEST["report_type"] ) : '';
684
-
685
-
686
-
687
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
688
-
689
- $this->gawd_google_client = GAWD_google_client::get_instance();
690
-
691
-
692
-
693
- if ( $export_type == 'pdf' ) {
694
-
695
- include_once GAWD_DIR . '/include/gawd_pdf_file.php';
696
-
697
- $file = new GAWD_PDF_FILE();
698
-
699
- } else {
700
-
701
- include_once GAWD_DIR . '/include/gawd_csv_file.php';
702
-
703
- $file = new GAWD_CSV_FILE();
704
-
705
- }
706
-
707
-
708
-
709
- if ( $report_type == 'alert' ) {
710
-
711
- if ( $export_type == 'pdf' ) {
712
-
713
- $file->export_file();
714
-
715
- } else {
716
-
717
- $file->export_file();
718
-
719
- }
720
-
721
- } else {
722
-
723
- $metric = isset( $_REQUEST["gawd_metric"] ) ? sanitize_text_field( $_REQUEST["gawd_metric"] ) : '';
724
-
725
- $_data_compare = isset( $_REQUEST["_data_compare"] ) ? ( $_REQUEST["_data_compare"] ) : '';
726
-
727
- $first_data = isset( $_REQUEST["first_data"] ) ? ( $_REQUEST["first_data"] ) : '';
728
-
729
- $view_id = isset( $_REQUEST["view_id"] ) ? sanitize_text_field( $_REQUEST["view_id"] ) : '';
730
-
731
- $metric_compare = isset( $_REQUEST["gawd_metric_compare"] ) ? sanitize_text_field( $_REQUEST["gawd_metric_compare"] ) : '';
732
-
733
- $dimension = isset( $_REQUEST["gawd_dimension"] ) ? sanitize_text_field( $_REQUEST["gawd_dimension"] ) : '';
734
-
735
- $tab_name = isset( $_REQUEST["tab_name"] ) ? sanitize_text_field( $_REQUEST["tab_name"] ) : '';
736
-
737
- $img = isset( $_REQUEST["img"] ) ? sanitize_text_field( $_REQUEST["img"] ) : '';
738
-
739
- $gawd_email_subject = isset( $_REQUEST["gawd_email_subject"] ) ? sanitize_text_field( $_REQUEST["gawd_email_subject"] ) : '';
740
-
741
- $gawd_email_body = isset( $_REQUEST["gawd_email_body"] ) && $_REQUEST["gawd_email_body"] != '' ? sanitize_text_field( $_REQUEST["gawd_email_body"] ) : ' ';
742
-
743
- $email_from = isset( $_REQUEST["gawd_email_from"] ) ? sanitize_email( $_REQUEST["gawd_email_from"] ) : '';
744
-
745
- $email_to = isset( $_REQUEST["gawd_email_to"] ) ? sanitize_email( $_REQUEST["gawd_email_to"] ) : '';
746
-
747
- $email_period = isset( $_REQUEST["gawd_email_period"] ) ? sanitize_text_field( $_REQUEST["gawd_email_period"] ) : '';
748
-
749
- $week_day = isset( $_REQUEST["gawd_email_week_day"] ) ? sanitize_text_field( $_REQUEST["gawd_email_week_day"] ) : '';
750
-
751
- $month_day = isset( $_REQUEST["gawd_email_month_day"] ) ? sanitize_text_field( $_REQUEST["gawd_email_month_day"] ) : '';
752
-
753
- $email_time = isset( $_REQUEST["email_time"] ) ? sanitize_text_field( $_REQUEST["email_time"] ) : '';
754
-
755
- $emails = array();
756
-
757
- $invalid_email = false;
758
-
759
- $email_to = explode( ',', $email_to );
760
-
761
- foreach ( $email_to as $email ) {
762
-
763
- if ( is_email( $email ) == false ) {
764
-
765
- $emails = $email;
766
-
767
- }
768
-
769
- }
770
-
771
- if ( count( $emails ) > 0 ) {
772
-
773
- $invalid_email = true;
774
-
775
- }
776
-
777
- if ( ( $invalid_email != true ) && is_email( $email_from ) && $gawd_email_subject != '' ) {
778
-
779
- if ( $email_period == "once" ) {
780
-
781
- $file->get_request_data( $this );
782
-
783
- $file->sort_data();
784
-
785
- if ( $export_type == 'csv' ) {
786
-
787
- if ( $first_data != '' ) {
788
-
789
- $file->create_file( false );
790
-
791
- } else {
792
-
793
- $file->create_file();
794
-
795
- }
796
-
797
- } else {
798
-
799
- if ( $first_data != '' ) {
800
-
801
- $file->create_file( 'pages' );
802
-
803
- } elseif ( ( $_data_compare ) != '' ) {
804
-
805
- $file->create_file( 'compare' );
806
-
807
- } else {
808
-
809
- $file->create_file( false );
810
-
811
- }
812
-
813
- }
814
-
815
- $attachment = $file->file_dir;
816
-
817
-
818
-
819
- if ( $report_type == 'email' ) {
820
-
821
- $headers = 'From: <' . $email_from . '>';
822
-
823
- wp_mail( $email_to, $gawd_email_subject, $gawd_email_body, $headers, $attachment );
824
-
825
- }
826
-
827
- echo json_encode( array( 'status' => 'success', 'msg' => 'Email successfuly sent' ) );
828
-
829
- } else {
830
-
831
- if ( $email_period == 'gawd_weekly' ) {
832
-
833
- $period_day = $week_day;
834
-
835
- $timestamp = strtotime( 'this ' . $period_day . ' ' . $email_time );
836
-
837
- } elseif ( $email_period == 'gawd_monthly' ) {
838
-
839
- $period_day = $month_day;
840
-
841
- $timestamp = strtotime( date( 'Y-m-' . $period_day . ' ' . $email_time ) );
842
-
843
- } else {
844
-
845
- $period_day = '';
846
-
847
- $timestamp = strtotime( date( 'Y-m-d ' . $email_time ) );
848
-
849
- }
850
-
851
- $saved_email = get_option( 'gawd_email' );
852
-
853
- if ( $saved_email ) {
854
-
855
- $gawd_email_options = array(
856
-
857
- 'name' => $gawd_email_subject,
858
-
859
- 'period' => $email_period,
860
-
861
- 'metric' => $metric,
862
-
863
- 'metric_compare' => $metric_compare,
864
-
865
- 'dimension' => $dimension,
866
-
867
- 'creation_date' => date( 'Y-m-d' ) .' '. $email_time,
868
-
869
- 'emails' => $email_to,
870
-
871
- 'email_from' => $email_from,
872
-
873
- 'email_subject' => $gawd_email_subject,
874
-
875
- 'email_body' => $gawd_email_body,
876
-
877
- 'period_day' => $period_day,
878
-
879
- 'period_time' => $email_time,
880
-
881
- 'img' => $img,
882
-
883
- 'tab_name' => $tab_name,
884
-
885
- 'view_id' => $view_id,
886
-
887
- 'export_type' => $export_type
888
-
889
- );
890
-
891
- $saved_email[] = $gawd_email_options;
892
-
893
- update_option( 'gawd_email', $saved_email );
894
-
895
- } else {
896
-
897
- $gawd_email_options = array(
898
-
899
- 0 => array(
900
-
901
- 'name' => $gawd_email_subject,
902
-
903
- 'period' => $email_period,
904
-
905
- 'metric' => $metric,
906
-
907
- 'metric_compare' => $metric_compare,
908
-
909
- 'dimension' => $dimension,
910
-
911
- 'creation_date' => date( 'Y-m-d' ) .' '. $email_time,
912
-
913
- 'emails' => $email_to,
914
-
915
- 'email_from' => $email_from,
916
-
917
- 'email_subject' => $gawd_email_subject,
918
-
919
- 'email_body' => $gawd_email_body,
920
-
921
- 'period_day' => $period_day,
922
-
923
- 'period_time' => $email_time,
924
-
925
- 'img' => $img,
926
-
927
- 'tab_name' => $tab_name,
928
-
929
- 'view_id' => $view_id,
930
-
931
- 'export_type' => $export_type
932
-
933
- )
934
-
935
- );
936
-
937
- update_option( 'gawd_email', $gawd_email_options );
938
-
939
- }
940
-
941
- $saved_email = get_option( 'gawd_email' );
942
-
943
- if ( $saved_email ) {
944
-
945
- foreach ( $saved_email as $email ) {
946
-
947
- if ( ! wp_next_scheduled( 'gawd_email_' . $email['period'] ) ) {
948
-
949
- wp_schedule_event( $timestamp, $email['period'], 'gawd_email_' . $email['period'] );
950
-
951
- }
952
-
953
- }
954
-
955
- }
956
-
957
- $success_message = 'Email successfuly Scheduled </br> Go to <a href="' . admin_url() . 'admin.php?page=gawd_settings#gawd_emails_tab">Settings page</a> to delete scheduled e-mails.';
958
-
959
- echo json_encode( array( 'status' => 'success', 'msg' => $success_message ) );
960
-
961
- }
962
-
963
-
964
-
965
- die;
966
-
967
- } else {
968
-
969
- if ( $invalid_email == true ) {
970
-
971
- echo json_encode( 'Invalid email' );
972
-
973
- die;
974
-
975
- } else if ( $gawd_email_subject == '' ) {
976
-
977
- echo json_encode( "Can't send email with empty subject" );
978
-
979
- die;
980
-
981
- }
982
-
983
- }
984
-
985
- }
986
-
987
- }
988
-
989
-
990
-
991
- public function overview_date_meta( $screen = null, $context = 'advanced' ) {
992
-
993
- //righ side wide meta..
994
-
995
- $orintation = wp_is_mobile() ? 'side' : 'normal';
996
-
997
- add_meta_box( 'gawd-real-time', __( 'Real Time', 'gawd' ), array(
998
-
999
- $this,
1000
-
1001
- 'gawd_real_time'
1002
-
1003
- ), 'gawd_analytics', 'side', 'high' );
1004
-
1005
- add_meta_box( 'gawd-date-meta', __( 'Audience', 'gawd' ), array(
1006
-
1007
- $this,
1008
-
1009
- 'gawd_date_box'
1010
-
1011
- ), 'gawd_analytics', $orintation, null );
1012
-
1013
- add_meta_box( 'gawd-country-box', __( 'Location', 'gawd' ), array(
1014
-
1015
- $this,
1016
-
1017
- 'gawd_country_box'
1018
-
1019
- ), 'gawd_analytics', $orintation, null );
1020
-
1021
- //left side thin meta.
1022
-
1023
- add_meta_box( 'gawd-visitors-meta', __( 'Visitors', 'gawd' ), array(
1024
-
1025
- $this,
1026
-
1027
- 'gawd_visitors'
1028
-
1029
- ), 'gawd_analytics', 'side', null );
1030
-
1031
- add_meta_box( 'gawd-browser-meta', __( 'Browsers', 'gawd' ), array(
1032
-
1033
- $this,
1034
-
1035
- 'gawd_browser'
1036
-
1037
- ), 'gawd_analytics', 'side', null );
1038
-
1039
- }
1040
-
1041
-
1042
-
1043
- public function gawd_date_box() {
1044
-
1045
- require_once( 'admin/pages/date.php' );
1046
-
1047
- }
1048
-
1049
-
1050
-
1051
- public function gawd_country_box() {
1052
-
1053
- require_once( 'admin/pages/location.php' );
1054
-
1055
- }
1056
-
1057
-
1058
-
1059
- public function gawd_real_time() {
1060
-
1061
- require_once( 'admin/pages/real_time.php' );
1062
-
1063
- }
1064
-
1065
-
1066
-
1067
- public function gawd_visitors() {
1068
-
1069
- require_once( 'admin/pages/visitors.php' );
1070
-
1071
- }
1072
-
1073
-
1074
-
1075
- public function gawd_browser() {
1076
-
1077
- require_once( 'admin/pages/browser.php' );
1078
-
1079
- }
1080
-
1081
-
1082
-
1083
-
1084
-
1085
-
1086
-
1087
- /**
1088
-
1089
- * Activation function needed for the activation hook.
1090
-
1091
- */
1092
-
1093
- public static function activate() {
1094
-
1095
- $credentials['project_id'] = '115052745574-5vbr7tci4hjkr9clkflmnpto5jisgstg.apps.googleusercontent.com';
1096
-
1097
- $credentials['project_secret'] = 'wtNiu3c_bA_g7res6chV0Trt';
1098
-
1099
- if ( ! get_option( 'gawd_credentials' ) ) {
1100
-
1101
- update_option( 'gawd_credentials', $credentials );
1102
-
1103
- }
1104
-
1105
- $gawd_settings = get_option('gawd_settings');
1106
-
1107
- if($gawd_settings === false){
1108
-
1109
- self::gawd_settings_defaults();
1110
-
1111
- }
1112
-
1113
- elseif($gawd_settings && !isset($gawd_settings['show_report_page'])){
1114
-
1115
- $gawd_settings['show_report_page'] = 'on';
1116
-
1117
- update_option('gawd_settings', $gawd_settings);
1118
-
1119
- }
1120
-
1121
- self::add_dashboard_menu();
1122
-
1123
-
1124
-
1125
- }
1126
-
1127
-
1128
-
1129
- /**
1130
-
1131
- * Deactivation function needed for the deactivation hook.
1132
-
1133
- */
1134
-
1135
- public static function deactivate() {
1136
-
1137
-
1138
-
1139
- }
1140
-
1141
-
1142
-
1143
- /**
1144
-
1145
- * Enqueues the required styles and scripts, localizes some js variables.
1146
-
1147
- */
1148
-
1149
- public function gawd_front_scripts() {
1150
-
1151
- if ( is_user_logged_in() ) {
1152
-
1153
- wp_enqueue_style( 'admin_css', GAWD_URL . '/inc/css/gawd_admin.css', false, GAWD_VERSION );
1154
-
1155
- wp_enqueue_script( 'gawd_amcharts', GAWD_URL . '/inc/js/amcharts.js', false, GAWD_VERSION );
1156
-
1157
- wp_enqueue_script( 'gawd_pie', GAWD_URL . '/inc/js/pie.js', false, GAWD_VERSION );
1158
-
1159
- wp_enqueue_script( 'gawd_serial', GAWD_URL . '/inc/js/serial.js', false, GAWD_VERSION );
1160
-
1161
- wp_enqueue_script( 'gawd_light_theme', GAWD_URL . '/inc/js/light.js', array( 'jquery' ), GAWD_VERSION );
1162
-
1163
- wp_enqueue_script( 'gawd_dataloader', GAWD_URL . '/inc/js/dataloader.min.js', array( 'jquery' ), GAWD_VERSION );
1164
-
1165
- wp_enqueue_script( 'gawd_front_js', GAWD_URL . '/inc/js/gawd_front.js', array( 'jquery' ), GAWD_VERSION );
1166
-
1167
- wp_localize_script( 'gawd_front_js', 'gawd_front', array(
1168
-
1169
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1170
-
1171
- 'ajaxnonce' => wp_create_nonce( 'gawd_admin_page_nonce' ),
1172
-
1173
- 'gawd_plugin_url' => GAWD_URL,
1174
-
1175
- 'date_30' => date( 'Y-m-d', strtotime( '-31 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
1176
-
1177
- 'date_7' => date( 'Y-m-d', strtotime( '-8 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
1178
-
1179
- 'date_last_week' => date( 'Y-m-d', strtotime( 'last week -1day' ) ) . '/-/' . date( 'Y-m-d', strtotime( 'last week +5day' ) ),
1180
-
1181
- 'date_last_month' => date( 'Y-m-01', strtotime( 'last month' ) ) . '/-/' . date( 'Y-m-t', strtotime( 'last month' ) ),
1182
-
1183
- 'date_this_month' => date( 'Y-m-01' ) . '/-/' . date( 'Y-m-d' ),
1184
-
1185
- 'date_today' => date( 'Y-m-d' ) . '/-/' . date( 'Y-m-d' ),
1186
-
1187
- 'date_yesterday' => date( 'Y-m-d', strtotime( '-1 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
1188
-
1189
- 'wp_admin_url' => admin_url(),
1190
-
1191
- 'exportUrl' => add_query_arg( array( 'action' => 'gawd_export' ), admin_url( 'admin-ajax.php' ) )
1192
-
1193
- ) );
1194
-
1195
- }
1196
-
1197
- }
1198
-
1199
-
1200
-
1201
- public function gawd_enqueue_scripts() {
1202
-
1203
- $options = get_option( 'gawd_settings' );
1204
-
1205
- $show_report_page = (isset( $options['show_report_page'] ) && $options['show_report_page'] != '' ) ? $options['show_report_page'] : 'on';
1206
-
1207
- $default_date = ( isset( $options['default_date'] ) && $options['default_date'] != '' ) ? $options['default_date'] : 'last_30days';
1208
-
1209
- $default_date_format = ( isset( $options['default_date_format'] ) && $options['default_date_format'] != '' ) ? $options['default_date_format'] : 'ymd_with_week';
1210
-
1211
- $enable_hover_tooltip = ( isset( $options['enable_hover_tooltip'] ) && $options['enable_hover_tooltip'] != '' ) ? $options['enable_hover_tooltip'] : '';
1212
-
1213
- $screen = get_current_screen();
1214
-
1215
- if ( strpos( $screen->base, 'gawd' ) !== false || strpos( $screen->post_type, 'page' ) !== false || strpos( $screen->post_type, 'post' ) !== false || strpos( $screen->base, 'dashboard' ) !== false || strpos( $screen->base, 'edit' ) !== false) {
1216
-
1217
- wp_enqueue_script( 'common' );
1218
-
1219
- wp_enqueue_script( 'wp-lists' );
1220
-
1221
- wp_enqueue_script( 'postbox' );
1222
-
1223
- wp_enqueue_script( 'jquery-ui-tooltip' );
1224
-
1225
- wp_enqueue_script( 'gawd_paging', GAWD_URL . '/inc/js/paging.js', false, GAWD_VERSION );
1226
-
1227
- wp_enqueue_script( 'jquery.cookie', GAWD_URL . '/inc/js/jquery.cookie.js', false, GAWD_VERSION );
1228
-
1229
- wp_enqueue_style( 'timepicker_css', GAWD_URL . '/inc/css/jquery.timepicker.css', false, GAWD_VERSION );
1230
-
1231
- wp_enqueue_style( 'admin_css', GAWD_URL . '/inc/css/gawd_admin.css', false, GAWD_VERSION );
1232
-
1233
- wp_enqueue_style( 'gawd_licensing', GAWD_URL . '/inc/css/gawd_licensing.css', false, GAWD_VERSION );
1234
-
1235
- wp_enqueue_style( 'gawd_featured', GAWD_URL . '/featured/style.css', array(), GAWD_VERSION );
1236
-
1237
- wp_enqueue_style( 'font_awesome', GAWD_URL . '/inc/css/font_awesome.css', false, GAWD_VERSION );
1238
-
1239
- wp_enqueue_style( 'jquery-ui.css', GAWD_URL . '/inc/css/jquery-ui.css', false, GAWD_VERSION );
1240
-
1241
- wp_enqueue_style( 'gawd_bootstrap', GAWD_URL . '/inc/css/bootstrap.css', false, GAWD_VERSION );
1242
-
1243
- wp_enqueue_style( 'gawd_bootstrap-chosen', GAWD_URL . '/inc/css/bootstrap-chosen.css', false, GAWD_VERSION );
1244
-
1245
- wp_enqueue_style( 'gawd_bootstrap-select', GAWD_URL . '/inc/css/bootstrap-select.css', false, GAWD_VERSION );
1246
-
1247
- wp_enqueue_style( 'gawd_datepicker', GAWD_URL . '/inc/css/daterangepicker.css', false, GAWD_VERSION );
1248
-
1249
- wp_enqueue_style( 'ui.jqgrid.css', GAWD_URL . '/inc/css/ui.jqgrid.css', false, GAWD_VERSION );
1250
-
1251
- wp_enqueue_script( 'gawd_moment', GAWD_URL . '/inc/js/moment.min.js', false, GAWD_VERSION );
1252
-
1253
- wp_enqueue_script( 'gawd_daterangepicker', GAWD_URL . '/inc/js/daterangepicker.js', false, GAWD_VERSION );
1254
-
1255
- wp_enqueue_script( 'gawd_amcharts', GAWD_URL . '/inc/js/amcharts.js', false, GAWD_VERSION );
1256
-
1257
- wp_enqueue_script( 'gawd_pie', GAWD_URL . '/inc/js/pie.js', false, GAWD_VERSION );
1258
-
1259
- wp_enqueue_script( 'gawd_serial', GAWD_URL . '/inc/js/serial.js', false, GAWD_VERSION );
1260
-
1261
- /*Map*/
1262
-
1263
- wp_enqueue_script( 'gawd_ammap', GAWD_URL . '/inc/js/ammap.js', false, GAWD_VERSION );
1264
-
1265
- wp_enqueue_script( 'gawd_worldLow', GAWD_URL . '/inc/js/worldLow.js', false, GAWD_VERSION );
1266
-
1267
- wp_enqueue_script( 'gawd_map_chart', GAWD_URL . '/inc/js/gawd_map_chart.js', false, GAWD_VERSION );
1268
-
1269
- /*End Map*/
1270
-
1271
- wp_enqueue_script( 'gawd_light_theme', GAWD_URL . '/inc/js/light.js', array( 'jquery' ), GAWD_VERSION );
1272
-
1273
- wp_enqueue_script( 'gawd_dataloader', GAWD_URL . '/inc/js/dataloader.min.js', array( 'jquery' ), GAWD_VERSION );
1274
-
1275
- wp_enqueue_script( 'rgbcolor.js', GAWD_URL . '/inc/js/rgbcolor.js', array( 'jquery' ), GAWD_VERSION );
1276
-
1277
- wp_enqueue_script( 'StackBlur.js', GAWD_URL . '/inc/js/StackBlur.js', array( 'jquery' ), GAWD_VERSION );
1278
-
1279
- wp_enqueue_script( 'canvg.js', GAWD_URL . '/inc/js/canvg.js', array( 'jquery' ), GAWD_VERSION );
1280
-
1281
- wp_enqueue_script( 'gawd_tables', GAWD_URL . '/inc/js/loader.js', array( 'jquery' ), GAWD_VERSION );
1282
-
1283
- wp_enqueue_script( 'gawd_grid', GAWD_URL . '/inc/js/jquery.jqGrid.min.js', array( 'jquery' ), GAWD_VERSION );
1284
-
1285
- wp_enqueue_script( 'gawd_grid_locale', GAWD_URL . '/inc/js/grid.locale-en.js', array( 'jquery' ), GAWD_VERSION );
1286
-
1287
- wp_enqueue_script( 'date-js', GAWD_URL . '/inc/js/date.js', array( 'jquery' ), GAWD_VERSION );
1288
-
1289
- wp_enqueue_script( 'timepicker_js', GAWD_URL . '/inc/js/jquery.timepicker.min.js', array( 'jquery' ), GAWD_VERSION );
1290
-
1291
- wp_enqueue_script( 'admin_js', GAWD_URL . '/inc/js/gawd_admin.js', array( 'jquery' ), GAWD_VERSION );
1292
-
1293
- wp_enqueue_script( 'chosen.jquery.js', GAWD_URL . '/inc/js/chosen.jquery.js', array( 'jquery' ), GAWD_VERSION );
1294
-
1295
- wp_enqueue_script( 'bootstrap_js', GAWD_URL . '/inc/js/bootstrap_js.js', array( 'jquery' ), GAWD_VERSION );
1296
-
1297
- wp_enqueue_script( 'bootstrap-select', GAWD_URL . '/inc/js/bootstrap-select.js', array( 'jquery' ), GAWD_VERSION );
1298
-
1299
- wp_enqueue_script( 'highlight_js', GAWD_URL . '/inc/js/js_highlight.js', array( 'jquery' ), GAWD_VERSION );
1300
-
1301
- wp_enqueue_script( 'settings_js', GAWD_URL . '/inc/js/gawd_settings.js', array( 'jquery' ), GAWD_VERSION );
1302
-
1303
- wp_enqueue_script( 'overview', GAWD_URL . '/inc/js/gawd_overview.js', array( 'jquery' ), GAWD_VERSION );
1304
-
1305
- wp_localize_script( 'overview', 'gawd_overview', array(
1306
-
1307
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1308
-
1309
- 'ajaxnonce' => wp_create_nonce( 'gawd_admin_page_nonce' ),
1310
-
1311
- 'gawd_plugin_url' => GAWD_URL,
1312
-
1313
- 'default_date' => $default_date,
1314
-
1315
- 'enableHoverTooltip' => $enable_hover_tooltip,
1316
-
1317
- 'wp_admin_url' => admin_url()
1318
-
1319
- ) );
1320
-
1321
- wp_localize_script( 'admin_js', 'gawd_admin', array(
1322
-
1323
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
1324
-
1325
- 'ajaxnonce' => wp_create_nonce( 'gawd_admin_page_nonce' ),
1326
-
1327
- 'gawd_plugin_url' => GAWD_URL,
1328
-
1329
- 'wp_admin_url' => admin_url(),
1330
-
1331
- 'enableHoverTooltip' => $enable_hover_tooltip,
1332
-
1333
- 'default_date' => $default_date,
1334
-
1335
- 'default_date_format' => $default_date_format,
1336
-
1337
- 'date_30' => date( 'Y-m-d', strtotime( '-31 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
1338
-
1339
- 'date_7' => date( 'Y-m-d', strtotime( '-8 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
1340
-
1341
- 'date_last_week' => date( 'Y-m-d', strtotime( 'last week -1day' ) ) . '/-/' . date( 'Y-m-d', strtotime( 'last week +5day' ) ),
1342
-
1343
- 'date_last_month' => date( 'Y-m-01', strtotime( 'last month' ) ) . '/-/' . date( 'Y-m-t', strtotime( 'last month' ) ),
1344
-
1345
- 'date_this_month' => date( 'Y-m-01' ) . '/-/' . date( 'Y-m-d' ),
1346
-
1347
- 'date_today' => date( 'Y-m-d' ) . '/-/' . date( 'Y-m-d' ),
1348
-
1349
- 'date_yesterday' => date( 'Y-m-d', strtotime( '-1 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
1350
-
1351
- 'exportUrl' => add_query_arg( array( 'action' => 'gawd_export' ), admin_url( 'admin-ajax.php' ) ),
1352
-
1353
- 'show_report_page' => $show_report_page
1354
-
1355
- ) );
1356
-
1357
- }
1358
-
1359
- }
1360
-
1361
-
1362
-
1363
- /**
1364
-
1365
- * Adds the menu page with its submenus.
1366
-
1367
- */
1368
-
1369
- public function gawd_add_menu() {
1370
-
1371
-
1372
-
1373
-
1374
-
1375
- $gawd_settings = get_option( 'gawd_settings' );
1376
-
1377
- $gawd_permissions = isset( $gawd_settings['gawd_permissions'] ) ? $gawd_settings['gawd_permissions'] : array();
1378
-
1379
- if ( empty( $gawd_permissions ) ) {
1380
-
1381
- $permission = 'manage_options';
1382
-
1383
- }
1384
-
1385
- else {
1386
-
1387
- if ( in_array( 'manage_options', $gawd_permissions ) ) {
1388
-
1389
- $permission = 'manage_options';
1390
-
1391
- }
1392
-
1393
- if ( in_array( 'moderate_comments', $gawd_permissions ) ) {
1394
-
1395
- $permission = 'moderate_comments';
1396
-
1397
- }
1398
-
1399
- if ( in_array( 'publish_posts', $gawd_permissions ) ) {
1400
-
1401
- $permission = 'publish_posts';
1402
-
1403
- }
1404
-
1405
- if ( in_array( 'edit_posts', $gawd_permissions ) ) {
1406
-
1407
- $permission = 'edit_posts';
1408
-
1409
- }
1410
-
1411
- if(in_array( 'read', $gawd_permissions ) ) {
1412
-
1413
- $permission = 'read';
1414
-
1415
- }
1416
-
1417
-
1418
-
1419
- }
1420
-
1421
-
1422
-
1423
-
1424
-
1425
-
1426
-
1427
- add_menu_page(
1428
-
1429
- __( 'Analytics', 'gawd' ), //$page_title
1430
-
1431
- __( 'Analytics', 'gawd' ), //$menu_title
1432
-
1433
- $permission, //$capability
1434
-
1435
- 'gawd_analytics', //$menu_slug
1436
-
1437
- array( $this, $this->gawd_set_display( 'gawd_display_overview_page' ) ), //$function = '',
1438
-
1439
- GAWD_URL . '/assets/main_icon.png',25,13 );
1440
-
1441
-
1442
-
1443
- add_submenu_page(
1444
-
1445
- 'gawd_analytics', //$parent_slug
1446
-
1447
- __( 'Overview', 'gawd' ), //$page_title
1448
-
1449
- __( 'Overview', 'gawd' ), //$menu_title
1450
-
1451
- $permission, //$capability
1452
-
1453
- $this->gawd_set_slug( 'gawd_analytics' ), //$menu_slug
1454
-
1455
- array( $this, $this->gawd_set_display( 'gawd_display_overview_page' ) ) //$function = '',
1456
-
1457
- );
1458
-
1459
- add_submenu_page(
1460
-
1461
- 'gawd_analytics', //$parent_slug
1462
-
1463
- __( 'Reports', 'gawd' ), //$page_title
1464
-
1465
- __( 'Reports', 'gawd' ), //$menu_title
1466
-
1467
- $permission, //$capability
1468
-
1469
- $this->gawd_set_slug( 'gawd_reports' ), //$menu_slug
1470
-
1471
- array( $this, $this->gawd_set_display( 'gawd_display_reports_page' ) ) //$function = '',
1472
-
1473
- );
1474
-
1475
-
1476
-
1477
- add_submenu_page(
1478
-
1479
- 'gawd_analytics', //$parent_slug
1480
-
1481
- __( 'Settings', 'gawd' ), //$page_title
1482
-
1483
- __( 'Settings', 'gawd' ), //$menu_title
1484
-
1485
- $permission, //$capability
1486
-
1487
- 'gawd_settings', //$menu_slug
1488
-
1489
- array( $this, 'gawd_display_settings_page' ) //$function = '',
1490
-
1491
-
1492
-
1493
- );
1494
-
1495
- add_submenu_page(
1496
-
1497
- 'gawd_analytics', //$parent_slug
1498
-
1499
- __( 'Tracking', 'gawd' ), //$page_title
1500
-
1501
- __( 'Tracking', 'gawd' ), //$menu_title
1502
-
1503
- $permission, //$capability
1504
-
1505
- $this->gawd_set_slug( 'gawd_tracking' ), //$menu_slug
1506
-
1507
- array( $this, $this->gawd_set_display( 'gawd_display_tracking_page' ) ) //$function = '',
1508
-
1509
- );
1510
-
1511
- add_submenu_page(
1512
-
1513
- 'gawd_analytics', //$parent_slug
1514
-
1515
- __( 'Goal Management', 'gawd' ), //$page_title
1516
-
1517
- __( 'Goal Management', 'gawd' ), //$menu_title
1518
-
1519
- $permission, //$capability
1520
-
1521
- $this->gawd_set_slug( 'gawd_goals' ), //$menu_slug
1522
-
1523
- array( $this, $this->gawd_set_display( 'gawd_display_goals_page' ) ) //$function = '',
1524
-
1525
- );
1526
-
1527
-
1528
-
1529
- add_submenu_page(
1530
-
1531
- 'gawd_analytics', //$parent_slug
1532
-
1533
- __( 'Custom Reports', 'gawd' ), //$page_title
1534
-
1535
- __( 'Custom Reports', 'gawd' ), //$menu_title
1536
-
1537
- $permission, //$capability
1538
-
1539
- $this->gawd_set_slug( 'gawd_custom_reports' ), //$menu_slug
1540
-
1541
- array( $this, $this->gawd_set_display( 'gawd_display_custom_reports_page' ) ) //$function = '',
1542
-
1543
- );
1544
-
1545
- add_submenu_page(
1546
-
1547
- 'gawd_analytics', //$parent_slug
1548
-
1549
- __( 'Get Pro', 'gawd' ), //$page_title
1550
-
1551
- __( 'Get Pro', 'gawd' ), //$menu_title
1552
-
1553
- $permission, //$capability
1554
-
1555
- 'gawd_licensing', //$menu_slug
1556
-
1557
- array( $this, 'gawd_display_licensing_page' ) //$function = '',
1558
-
1559
- );
1560
-
1561
- add_submenu_page(
1562
-
1563
- 'gawd_analytics', //$parent_slug
1564
-
1565
- __( 'Featured Plugins', 'gawd' ), //$page_title
1566
-
1567
- __( 'Featured Plugins', 'gawd' ), //$menu_title
1568
-
1569
- $permission, //$capability
1570
-
1571
- 'gawd_featured_plugins', //$menu_slug
1572
-
1573
- array( $this, 'gawd_display_featured_plugins_page' ) //$function = '',
1574
-
1575
- );
1576
-
1577
- add_submenu_page(
1578
-
1579
- 'gawd_analytics', //$parent_slug
1580
-
1581
- __( 'Featured Themes', 'gawd' ), //$page_title
1582
-
1583
- __( 'Featured Themes', 'gawd' ), //$menu_title
1584
-
1585
- $permission, //$capability
1586
-
1587
- 'gawd_featured_themes', //$menu_slug
1588
-
1589
- array( $this, 'gawd_display_featured_themes_page' ) //$function = '',
1590
-
1591
- );
1592
-
1593
- add_submenu_page(
1594
-
1595
- 'gawd_analytics', //$parent_slug
1596
-
1597
- __( 'Uninstall', 'gawd' ), //$page_title
1598
-
1599
- __( 'Uninstall', 'gawd' ), //$menu_title
1600
-
1601
- $permission, //$capability
1602
-
1603
- 'gawd_uninstall', //$menu_slug
1604
-
1605
- array( $this, 'gawd_display_uninstall_page' ) //$function = '',
1606
-
1607
- );
1608
-
1609
-
1610
-
1611
- }
1612
-
1613
-
1614
-
1615
-
1616
-
1617
- public function gawd_set_slug( $slug ) {
1618
-
1619
- global $gawd_redirect_to_settings;
1620
-
1621
- if ( $gawd_redirect_to_settings == 'yes' ) {
1622
-
1623
- return 'gawd_settings';
1624
-
1625
- } else {
1626
-
1627
- return $slug;
1628
-
1629
- }
1630
-
1631
- }
1632
-
1633
-
1634
-
1635
- public function gawd_set_display( $slug ) {
1636
-
1637
- global $gawd_redirect_to_settings;
1638
-
1639
- if ( $gawd_redirect_to_settings == 'yes' ) {
1640
-
1641
- return 'gawd_display_settings_page';
1642
-
1643
- } else {
1644
-
1645
- return $slug;
1646
-
1647
- }
1648
-
1649
- }
1650
-
1651
-
1652
-
1653
- public function gawd_display_licensing_page() {
1654
-
1655
- require_once( GAWD_DIR . '/admin/licensing.php' );
1656
-
1657
- }
1658
-
1659
-
1660
-
1661
- function upgrade_pro() {
1662
-
1663
- $screen = get_current_screen();
1664
-
1665
- if ( strpos( $screen->base, 'gawd' ) !== false && strpos( $screen->base, 'gawd_featured' ) === false ) {
1666
-
1667
- ?>
1668
-
1669
- <div class="gawd_upgrade wd-clear">
1670
-
1671
- <div class="wd-right">
1672
-
1673
- <a href="https://web-dorado.com/products/wordpress-google-analytics-plugin.html" target="_blank">
1674
-
1675
- <div class="wd-table">
1676
-
1677
- <div class="wd-cell wd-cell-valign-middle">
1678
-
1679
- <?php _e( "Upgrade to paid version", "gawd" ); ?>
1680
-
1681
- </div>
1682
-
1683
-
1684
-
1685
- <div class="wd-cell wd-cell-valign-middle">
1686
-
1687
- <img src="<?php echo GAWD_URL; ?>/assets/web-dorado.png">
1688
-
1689
- </div>
1690
-
1691
- </div>
1692
-
1693
- </a>
1694
-
1695
- </div>
1696
-
1697
- </div>
1698
-
1699
- <?php
1700
-
1701
- }
1702
-
1703
- }
1704
-
1705
-
1706
-
1707
- public function gawd_display_featured_plugins_page() {
1708
-
1709
- require_once( GAWD_DIR . '/featured/featured.php' );
1710
-
1711
- gawd_featured_plugins( 'wd-google-analytics' );
1712
-
1713
-
1714
-
1715
- }
1716
-
1717
-
1718
-
1719
- public function gawd_display_featured_themes_page() {
1720
-
1721
- require_once( GAWD_DIR . '/featured/featured_themes.php' );
1722
-
1723
- $controller = new gawd_featured_themes();
1724
-
1725
- $controller->display();
1726
-
1727
- }
1728
-
1729
-
1730
-
1731
- public function gawd_auth() {
1732
-
1733
- check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
1734
-
1735
- $code = $_POST['token'];
1736
-
1737
- $status = GAWD_google_client::authenticate( $code );
1738
-
1739
- if ( $status === true ) {
1740
-
1741
- $res = array(
1742
-
1743
- 'message' => 'successfully saved',
1744
-
1745
- 'status' => $status,
1746
-
1747
- );
1748
-
1749
- } else {
1750
-
1751
- $res = array(
1752
-
1753
- 'message' => 'there is an error',
1754
-
1755
- 'status' => $status
1756
-
1757
- );
1758
-
1759
- }
1760
-
1761
- header( 'content-type: application/json' );
1762
-
1763
- echo json_encode( $res );
1764
-
1765
- wp_die();
1766
-
1767
- }
1768
-
1769
-
1770
-
1771
- /**
1772
-
1773
- * Displays the Dashboard page.
1774
-
1775
- */
1776
-
1777
- public function gawd_display_uninstall_page() {
1778
-
1779
- require_once( 'admin/pages/uninstall.php' );
1780
-
1781
- $gawd_uninstall = new GAWDUninstall();
1782
-
1783
- $deactivate_url = wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . GWD_NAME . '/google-analytics-wd.php', 'deactivate-plugin_' . GWD_NAME . '/google-analytics-wd.php' );
1784
-
1785
- $deactivate_url = str_replace( '&amp;', '&', $deactivate_url );
1786
-
1787
- if ( isset( $_POST['unistall_gawd'] ) ) {
1788
-
1789
- check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
1790
-
1791
- delete_option( 'gawd_custom_reports' );
1792
-
1793
- delete_option( 'gawd_menu_for_user' );
1794
-
1795
- delete_option( 'gawd_all_metrics' );
1796
-
1797
- delete_option( 'gawd_all_dimensions' );
1798
-
1799
- delete_option( 'gawd_custom_dimensions' );
1800
-
1801
- delete_option( 'gawd_settings' );
1802
-
1803
- delete_option( 'gawd_user_data' );
1804
-
1805
- delete_option( 'gawd_credentials' );
1806
-
1807
- delete_option( 'gawd_menu_items' );
1808
-
1809
- delete_option( 'gawd_export_chart_data' );
1810
-
1811
- delete_option( 'gawd_email' );
1812
-
1813
- delete_option( 'gawd_custom_reports' );
1814
-
1815
- delete_option( 'gawd_alerts' );
1816
-
1817
- delete_option( 'gawd_pushovers' );
1818
-
1819
- delete_option( 'gawd_menu_for_users' );
1820
-
1821
- delete_option( 'gawd_own_project' );
1822
-
1823
- delete_option( 'gawd_zoom_message' );
1824
-
1825
- delete_transient( 'gawd_user_profiles' );
1826
-
1827
- echo '<script>window.location.href="' . $deactivate_url . '";</script>';
1828
-
1829
- }
1830
-
1831
- if ( get_option( 'gawd_credentials' ) ) {
1832
-
1833
- $gawd_uninstall->uninstall();
1834
-
1835
- }
1836
-
1837
- }
1838
-
1839
-
1840
-
1841
- public function gawd_display_goals_page() {
1842
-
1843
- global $gawd_client;
1844
-
1845
- if ( $this->manage_ua_code_selection() != 'done' ) {
1846
-
1847
- return;
1848
-
1849
- }
1850
-
1851
- $gawd_client = GAWD_google_client::get_instance();
1852
-
1853
- if ( ! empty( $_POST ) ) {
1854
-
1855
- check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
1856
-
1857
- }
1858
-
1859
- $gawd_goal_profile = isset( $_POST['gawd_goal_profile'] ) ? sanitize_text_field( $_POST['gawd_goal_profile'] ) : '';
1860
-
1861
- $gawd_goal_name = isset( $_POST['gawd_goal_name'] ) ? sanitize_text_field( $_POST['gawd_goal_name'] ) : '';
1862
-
1863
- $gawd_goal_type = isset( $_POST['gawd_goal_type'] ) ? sanitize_text_field( $_POST['gawd_goal_type'] ) : '';
1864
-
1865
- $gawd_visit_hour = isset( $_POST['gawd_visit_hour'] ) ? sanitize_text_field( $_POST['gawd_visit_hour'] ) : '';
1866
-
1867
- $gawd_visit_minute = isset( $_POST['gawd_visit_minute'] ) ? sanitize_text_field( $_POST['gawd_visit_minute'] ) : '';
1868
-
1869
- $gawd_visit_second = isset( $_POST['gawd_visit_second'] ) ? sanitize_text_field( $_POST['gawd_visit_second'] ) : '';
1870
-
1871
- $gawd_goal_duration_comparison = isset( $_POST['gawd_goal_duration_comparison'] ) ? sanitize_text_field( $_POST['gawd_goal_duration_comparison'] ) : '';
1872
-
1873
- $gawd_goal_page_comparison = isset( $_POST['gawd_goal_page_comparison'] ) ? sanitize_text_field( $_POST['gawd_goal_page_comparison'] ) : '';
1874
-
1875
- $gawd_page_sessions = isset( $_POST['gawd_page_sessions'] ) ? sanitize_text_field( $_POST['gawd_page_sessions'] ) : '';
1876
-
1877
- $goal_max_id = isset( $_POST['goal_max_id'] ) ? $_POST['goal_max_id'] + 1 : 1;
1878
-
1879
- $gawd_goal_page_destination_match = isset( $_POST['gawd_goal_page_destination_match'] ) ? sanitize_text_field( $_POST['gawd_goal_page_destination_match'] ) : '';
1880
-
1881
- $gawd_page_url = isset( $_POST['gawd_page_url'] ) ? sanitize_text_field( $_POST['gawd_page_url'] ) : '';
1882
-
1883
- $url_case_sensitve = isset( $_POST['url_case_sensitve'] ) ? $_POST['url_case_sensitve'] : '';
1884
-
1885
- if ( $gawd_goal_type == 'VISIT_TIME_ON_SITE' ) {
1886
-
1887
- if ( $gawd_visit_hour != '' || $gawd_visit_minute != '' || $gawd_visit_second != '' ) {
1888
-
1889
- $value = 0;
1890
-
1891
- if ( $gawd_visit_hour != '' ) {
1892
-
1893
- $value += $gawd_visit_hour * 60 * 60;
1894
-
1895
- }
1896
-
1897
- if ( $gawd_visit_minute != '' ) {
1898
-
1899
- $value += $gawd_visit_minute * 60;
1900
-
1901
- }
1902
-
1903
- if ( $gawd_visit_second != '' ) {
1904
-
1905
- $value += $gawd_visit_second;
1906
-
1907
- }
1908
-
1909
- }
1910
-
1911
- $gawd_client->add_goal( $gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_duration_comparison, $value );
1912
-
1913
- add_option( "gawd_save_goal", 1 );
1914
-
1915
- }
1916
-
1917
- elseif ( $gawd_goal_type == 'VISIT_NUM_PAGES' ) {
1918
-
1919
- if ( $gawd_page_sessions != '' ) {
1920
-
1921
- $gawd_client->add_goal( $gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_page_comparison, $gawd_page_sessions );
1922
-
1923
- }
1924
-
1925
- add_option( "gawd_save_goal", 1 );
1926
-
1927
- }
1928
-
1929
- elseif ( $gawd_goal_type == 'URL_DESTINATION' ) {
1930
-
1931
- if ( $gawd_page_url != '' ) {
1932
-
1933
- $gawd_client->add_goal( $gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_page_destination_match, $gawd_page_url, $url_case_sensitve );
1934
-
1935
- }
1936
-
1937
- add_option( "gawd_save_goal", 1 );
1938
-
1939
- }
1940
-
1941
- elseif ( $gawd_goal_type == 'EVENT' ) {
1942
-
1943
- if ( $gawd_page_url != '' ) {
1944
-
1945
- $gawd_client->add_goal( $gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_page_comparison, $gawd_page_url, $url_case_sensitve );
1946
-
1947
- }
1948
-
1949
- add_option( "gawd_save_goal", 1 );
1950
-
1951
- }
1952
-
1953
- if ( get_option( 'gawd_save_goal' ) == 1 ) {
1954
-
1955
- $this->gawd_admin_notice( 'Goal successfully has been created.', 'success is-dismissible' );
1956
-
1957
- }
1958
-
1959
- delete_option( 'gawd_save_goal' );
1960
-
1961
- require_once( 'admin/pages/goals.php' );
1962
-
1963
-
1964
-
1965
- }
1966
-
1967
-
1968
-
1969
- public function gawd_display_custom_reports_page() {
1970
-
1971
- global $gawd_client;
1972
-
1973
- if ( ! empty( $_POST ) ) {
1974
-
1975
- check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
1976
-
1977
- }
1978
-
1979
- $gawd_client = GAWD_google_client::get_instance();
1980
-
1981
- $gawd_remove_custom_report = isset( $_POST['gawd_remove_custom_report'] ) ? sanitize_text_field( $_POST['gawd_remove_custom_report'] ) : '';
1982
-
1983
- if ( $gawd_remove_custom_report ) {
1984
-
1985
- $all_reports = get_option( "gawd_custom_reports" );
1986
-
1987
- if ( $all_reports ) {
1988
-
1989
- unset( $all_reports[ $gawd_remove_custom_report ] );
1990
-
1991
- update_option( 'gawd_custom_reports', $all_reports );
1992
-
1993
- self::add_dashboard_menu();
1994
-
1995
- }
1996
-
1997
- }
1998
-
1999
- if ( isset( $_POST['gawd_add_custom_report'] ) ) {
2000
-
2001
- $gawd_custom_report_name = isset( $_POST['gawd_custom_report_name'] ) ? sanitize_text_field( $_POST['gawd_custom_report_name'] ) : '';
2002
-
2003
- $gawd_custom_report_metric = isset( $_POST['gawd_custom_report_metric'] ) ? sanitize_text_field( $_POST['gawd_custom_report_metric'] ) : '';
2004
-
2005
- $gawd_custom_report_dimension = isset( $_POST['gawd_custom_report_dimension'] ) ? sanitize_text_field( $_POST['gawd_custom_report_dimension'] ) : '';
2006
-
2007
-
2008
-
2009
- if ( $gawd_custom_report_name != '' && $gawd_custom_report_metric != '' && $gawd_custom_report_dimension != '' ) {
2010
-
2011
- $saved_custom_reports = get_option( "gawd_custom_reports" );
2012
-
2013
- if ( ! isset( $saved_custom_reports[ $gawd_custom_report_name ] ) ) {
2014
-
2015
- if ( $saved_custom_reports ) {
2016
-
2017
- $custom_reports = array(
2018
-
2019
- 'metric' => $gawd_custom_report_metric,
2020
-
2021
- 'dimension' => $gawd_custom_report_dimension,
2022
-
2023
- 'id' => count( $saved_custom_reports ) + 1
2024
-
2025
- );
2026
-
2027
- $saved_custom_reports[ $gawd_custom_report_name ] = $custom_reports;
2028
-
2029
-
2030
-
2031
- update_option( 'gawd_custom_reports', $saved_custom_reports );
2032
-
2033
- } else {
2034
-
2035
- $custom_reports = array(
2036
-
2037
- $gawd_custom_report_name => array(
2038
-
2039
- 'metric' => $gawd_custom_report_metric,
2040
-
2041
- 'dimension' => $gawd_custom_report_dimension,
2042
-
2043
- 'id' => 1
2044
-
2045
- )
2046
-
2047
- );
2048
-
2049
- update_option( 'gawd_custom_reports', $custom_reports );
2050
-
2051
- }
2052
-
2053
- }
2054
-
2055
- }
2056
-
2057
- self::add_dashboard_menu();
2058
-
2059
- }
2060
-
2061
- require_once( 'admin/pages/custom_reports.php' );
2062
-
2063
- }
2064
-
2065
-
2066
-
2067
- public function gawd_display_overview_page() {
2068
-
2069
- global $gawd_client, $gawd_user_data;
2070
-
2071
- $gawd_client = GAWD_google_client::get_instance();
2072
-
2073
- $profiles = $gawd_client->get_profiles();
2074
-
2075
- $gawd_user_data = get_option( 'gawd_user_data' );
2076
-
2077
- if ( isset( $_POST['gawd_id'] ) ) {
2078
-
2079
- $gawd_user_data['gawd_id'] = isset( $_POST['gawd_id'] ) ? $_POST['gawd_id'] : '';
2080
-
2081
- foreach ( $gawd_user_data['gawd_profiles'] as $web_property_name => $web_property ) {
2082
-
2083
- foreach ( $web_property as $profile ) {
2084
-
2085
- if ( $profile['id'] == $gawd_user_data['gawd_id'] ) {
2086
-
2087
- $gawd_user_data['web_property_name'] = $web_property_name;
2088
-
2089
- $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
2090
-
2091
- $gawd_user_data['accountId'] = $profile['accountId'];
2092
-
2093
- }
2094
-
2095
- }
2096
-
2097
- }
2098
-
2099
- $gawd_user_data['web_property_name'] = isset( $_POST['web_property_name'] ) ? $_POST['web_property_name'] : '';
2100
-
2101
- update_option( 'gawd_user_data', $gawd_user_data );
2102
-
2103
- }
2104
-
2105
- require_once( 'admin/pages/overview.php' );
2106
-
2107
- }
2108
-
2109
-
2110
-
2111
- public function gawd_display_reports_page() {
2112
-
2113
- global $gawd_client, $gawd_user_data;
2114
-
2115
- $gawd_client = GAWD_google_client::get_instance();
2116
-
2117
- $profiles = $gawd_client->get_profiles();
2118
-
2119
- $gawd_user_data = get_option( 'gawd_user_data' );
2120
-
2121
- $gawd_settings = get_option('gawd_settings');
2122
-
2123
- if ( isset( $_POST['gawd_id'] ) ) {
2124
-
2125
- $gawd_user_data['gawd_id'] = isset( $_POST['gawd_id'] ) ? $_POST['gawd_id'] : '';
2126
-
2127
- foreach ( $gawd_user_data['gawd_profiles'] as $web_property_name => $web_property ) {
2128
-
2129
- foreach ( $web_property as $profile ) {
2130
-
2131
- if ( $profile['id'] == $gawd_user_data['gawd_id'] ) {
2132
-
2133
- $gawd_user_data['web_property_name'] = $web_property_name;
2134
-
2135
- $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
2136
-
2137
- $gawd_user_data['accountId'] = $profile['accountId'];
2138
-
2139
- }
2140
-
2141
- }
2142
-
2143
- }
2144
-
2145
- $gawd_user_data['web_property_name'] = isset( $_POST['web_property_name'] ) ? $_POST['web_property_name'] : '';
2146
-
2147
- update_option( 'gawd_user_data', $gawd_user_data );
2148
-
2149
- }
2150
-
2151
- require_once( 'admin/pages/dashboard.php' );
2152
-
2153
- }
2154
-
2155
-
2156
-
2157
- public function gawd_daily_email() {
2158
-
2159
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
2160
-
2161
- $gawd_client = GAWD_google_client::get_instance();
2162
-
2163
- $emails = get_option( 'gawd_email' );
2164
-
2165
- $gawd_user_data = get_option( 'gawd_user_data' );
2166
-
2167
- $data = '';
2168
-
2169
- foreach ( $emails as $email ) {
2170
-
2171
- if ( isset( $email['period'] ) && $email['period'] == 'daily' ) {
2172
-
2173
- //pls send email if ....
2174
-
2175
- $date = date( 'Y-m-d', strtotime( 'yesterday' ) );
2176
-
2177
- $email_subject = preg_match( '/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', $email['email_subject'] ) ? preg_replace( '/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', '(' . $date . ' - ' . $date . ')', $email['email_subject'] ) : $email['email_subject'] . ' (' . $date . ' - ' . $date . ')';
2178
-
2179
- $data = $this->show_data( array(
2180
-
2181
- 'metric' => 'ga:' . $email['metric'],
2182
-
2183
- 'dimension' => $email['dimension'],
2184
-
2185
- 'start_date' => $date,
2186
-
2187
- 'end_date' => $date
2188
-
2189
- ) );
2190
-
2191
- if ( $email['export_type'] == 'pdf' ) {
2192
-
2193
- $filedir = $this->create_pdf_file( false, $data, $email['dimension'], $date, $date, $email['metric_compare'], $email['metric'] );
2194
-
2195
- } else {
2196
-
2197
- $filedir = $this->create_csv_file( false, $data, $email['dimension'], $date, $date, $email['metric_compare'], $email['metric'] );
2198
-
2199
- }
2200
-
2201
- //$attachment = gawd_export_data($data, $export_type, 'email', $email['dimension'], $email['metric'], $email['metric_compare'], $email['img'], $email['tab_name'], $start_date, $end_date, $gawd_user_data['web_property_name'],$filter_type);
2202
-
2203
- $attachment = $filedir;
2204
-
2205
- $headers = 'From: <' . $email['email_from'] . '>';
2206
-
2207
- wp_mail( $email['emails'], $email_subject, $email['email_body'], $headers, $attachment );
2208
-
2209
- }
2210
-
2211
- }
2212
-
2213
- }
2214
-
2215
-
2216
-
2217
- public function gawd_weekly_email() {
2218
-
2219
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
2220
-
2221
- $gawd_client = GAWD_google_client::get_instance();
2222
-
2223
- $emails = get_option( 'gawd_email' );
2224
-
2225
- $gawd_user_data = get_option( 'gawd_user_data' );
2226
-
2227
- $data = '';
2228
-
2229
- foreach ( $emails as $email ) {
2230
-
2231
- if ( isset( $email['period'] ) && $email['period'] == 'gawd_weekly' ) {
2232
-
2233
- //pls send email if ....
2234
-
2235
- /*$start_date = date('Y-m-d', strtotime('last' . $email['period_day']));
2236
-
2237
- $end_date = date('Y-m-d', strtotime('this' . $email['period_day']));*/
2238
-
2239
- $start_date = date( 'Y-m-d', strtotime( 'last week -1 day' ) );
2240
-
2241
- $end_date = date( 'l' ) != 'Sunday' ? date( 'Y-m-d', strtotime( 'last sunday -1 day' ) ) : date( 'Y-m-d', strtotime( '-1 day' ) );
2242
-
2243
- $email_subject = preg_match( '/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', $email['email_subject'] ) ? preg_replace( '/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', '(' . $start_date . ' - ' . $end_date . ')', $email['email_subject'] ) : $email['email_subject'] . ' (' . $start_date . ' - ' . $end_date . ')';
2244
-
2245
- $data = $this->show_data( array(
2246
-
2247
- 'metric' => 'ga:' . $email['metric'],
2248
-
2249
- 'dimension' => $email['dimension'],
2250
-
2251
- 'start_date' => $start_date,
2252
-
2253
- 'end_date' => $end_date
2254
-
2255
- ) );
2256
-
2257
- if ( $email['export_type'] == 'pdf' ) {
2258
-
2259
- $filedir = $this->create_pdf_file( false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric'] );
2260
-
2261
- } else {
2262
-
2263
- $filedir = $this->create_csv_file( false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric'] );
2264
-
2265
- }
2266
-
2267
- //$attachment = gawd_export_data($data, $export_type, 'email', $email['dimension'], $email['metric'], $email['metric_compare'], $email['img'], $email['tab_name'], $start_date, $end_date, $gawd_user_data['web_property_name'],$filter_type);
2268
-
2269
- $attachment = $filedir;
2270
-
2271
-
2272
-
2273
- $headers = 'From: <' . $email['email_from'] . '>';
2274
-
2275
- wp_mail( $email['emails'], $email_subject, $email['email_body'], $headers, $attachment );
2276
-
2277
- }
2278
-
2279
- }
2280
-
2281
- }
2282
-
2283
-
2284
-
2285
- public function gawd_monthly_email() {
2286
-
2287
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
2288
-
2289
- $gawd_client = GAWD_google_client::get_instance();
2290
-
2291
- $emails = get_option( 'gawd_email' );
2292
-
2293
- $gawd_user_data = get_option( 'gawd_user_data' );
2294
-
2295
- $data = '';
2296
-
2297
- foreach ( $emails as $email ) {
2298
-
2299
- if ( isset( $email['period'] ) && $email['period'] == 'gawd_monthly' ) {
2300
-
2301
- //pls send email if ....
2302
-
2303
- $end_date = date( 'Y-m-d', strtotime( date( 'Y-' . date( 'm' ) . '-1' ) . '-1 day' ) );
2304
-
2305
- $start_date = date( 'Y-m-d', strtotime( $end_date . '- 1 month' ) );
2306
-
2307
- $data = $this->show_data( array(
2308
-
2309
- 'metric' => 'ga:' . $email['metric'],
2310
-
2311
- 'dimension' => $email['dimension'],
2312
-
2313
- 'start_date' => $start_date,
2314
-
2315
- 'end_date' => $end_date
2316
-
2317
- ) );
2318
-
2319
- $email_subject = preg_match( '/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', $email['email_subject'] ) ? preg_replace( '/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', '(' . $start_date . ' - ' . $end_date . ')', $email['email_subject'] ) : $email['email_subject'] . ' (' . $start_date . ' - ' . $end_date . ')';
2320
-
2321
- if ( $email['export_type'] == 'pdf' ) {
2322
-
2323
- $filedir = $this->create_pdf_file( false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric'] );
2324
-
2325
- } else {
2326
-
2327
- $filedir = $this->create_csv_file( false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric'] );
2328
-
2329
- }
2330
-
2331
- //$attachment = gawd_export_data($data, $export_type, 'email', $email['dimension'], $email['metric'], $email['metric_compare'], $email['img'], $email['tab_name'], $start_date, $end_date, $gawd_user_data['web_property_name'],$filter_type);
2332
-
2333
- $attachment = $filedir;
2334
-
2335
- $headers = 'From: <' . $email['email_from'] . '>';
2336
-
2337
- wp_mail( $email['emails'], $email_subject, $email['email_body'], $headers, $attachment );
2338
-
2339
- }
2340
-
2341
- }
2342
-
2343
- }
2344
-
2345
-
2346
-
2347
- /**
2348
-
2349
- * Prepares the settings to be displayed then displays the settings page.
2350
-
2351
- */
2352
-
2353
- public static function gawd_settings_defaults() {
2354
-
2355
- $settings = get_option( 'gawd_settings' );
2356
-
2357
- $settings['gawd_tracking_enable'] = 'on';
2358
-
2359
- $settings['gawd_custom_dimension_Logged_in'] = 'on';
2360
-
2361
- $settings['gawd_custom_dimension_Post_type'] = 'on';
2362
-
2363
- $settings['gawd_custom_dimension_Author'] = 'on';
2364
-
2365
- $settings['gawd_custom_dimension_Category'] = 'on';
2366
-
2367
- $settings['gawd_custom_dimension_Published_Month'] = 'on';
2368
-
2369
- $settings['gawd_custom_dimension_Published_Year'] = 'on';
2370
-
2371
- $settings['gawd_custom_dimension_Tags'] = 'on';
2372
-
2373
- $settings['enable_hover_tooltip'] = 'on';
2374
-
2375
- $settings['gawd_show_in_dashboard'] = 'on';
2376
-
2377
- $settings['post_page_chart'] = 'on';
2378
-
2379
- $settings['show_report_page'] = 'off';
2380
-
2381
- update_option( 'gawd_settings', $settings );
2382
-
2383
- }
2384
-
2385
-
2386
-
2387
- public function manage_ua_code_selection() {
2388
-
2389
- global $gawd_user_data, $gawd_client;
2390
-
2391
- $gawd_user_data = get_option( 'gawd_user_data' );
2392
-
2393
- if ( isset( $gawd_user_data['default_webPropertyId'] ) && $gawd_user_data['default_webPropertyId'] ) {
2394
-
2395
- return 'done';
2396
-
2397
- } else {
2398
-
2399
- $gawd_client = GAWD_google_client::get_instance();
2400
-
2401
- $property = $gawd_client->property_exists();
2402
-
2403
- if ( $property == 'no_matches' ) {
2404
-
2405
- $this->gawd_admin_notice( "<p class='gawd_notice'>You don't have any web-properties with current site url, go with <a href='" . admin_url( 'admin.php?page=gawd_tracking' ) . "'>this</a> link to add.</p>", 'error' );
2406
-
2407
- // show notice that you don't have property with current site url
2408
-
2409
- // add account or property to an existing account
2410
-
2411
- } elseif ( count( $property ) == 1 ) {
2412
-
2413
- $property = $property[0];
2414
-
2415
- $gawd_user_data['webPropertyId'] = $property['id'];
2416
-
2417
- $gawd_user_data['default_webPropertyId'] = $property['id'];
2418
-
2419
- $gawd_user_data['accountId'] = $property['accountId'];
2420
-
2421
- $gawd_user_data['default_accountId'] = $property['accountId'];
2422
-
2423
- $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
2424
-
2425
- update_option( 'gawd_user_data', $gawd_user_data );
2426
-
2427
- $this->gawd_admin_notice( "In order to enable tracking for your website, you have to go with
2428
-
2429
- <a href='" . admin_url( 'admin.php?page=gawd_tracking' ) . "'>this</a> link and turn the option on.", 'warning is-dismissible' );
2430
-
2431
- // show notice that you have to enable tracking code, link to tracking submenu
2432
-
2433
- } else {
2434
-
2435
- $this->gawd_admin_notice( "You have two or more web-properties configured with current site url. Please go with
2436
-
2437
- <a href='" . admin_url( 'admin.php?page=gawd_tracking' ) . "'>this</a> link to select the proper one.", 'error' );
2438
-
2439
- // show notice that you have >=2 properties with current site url
2440
-
2441
- // select property from same url properties
2442
-
2443
- }
2444
-
2445
- }
2446
-
2447
- }
2448
-
2449
-
2450
-
2451
- public function manage_ua_code_selection_tracking() {
2452
-
2453
- global $gawd_user_data;
2454
-
2455
- if ( isset( $gawd_user_data['default_webPropertyId'] ) && $gawd_user_data['default_webPropertyId'] ) {
2456
-
2457
- return 'done';
2458
-
2459
- }
2460
-
2461
- else {
2462
-
2463
- $gawd_client = GAWD_google_client::get_instance();
2464
-
2465
- $property = $gawd_client->property_exists();
2466
-
2467
- if ( $property == 'no_matches' ) {
2468
-
2469
- $accounts = $gawd_client->get_management_accounts();
2470
-
2471
- if ( ! empty( $accounts ) ) {
2472
-
2473
- echo "<h3 style='margin-top:10px' class='gawd_page_titles'>Tracking</h3>
2474
-
2475
- <p class='gawd_notice notice'>Here you can add a <b>web property</b> on your Google Analytics account using current WordPress website. After creating a <b>web property</b> Google Analytics tracking code will be added to your website.</p></br>
2476
-
2477
- <form method='post' id='gawd_property_add'>
2478
-
2479
- <div class='gawd_settings_wrapper'>
2480
-
2481
- <div class='gawd_goal_row'>
2482
-
2483
- <span class='gawd_goal_label'>Account</span>
2484
-
2485
- <span class='gawd_goal_input'>
2486
-
2487
- <select name='gawd_account_select' class='gawd_account_select' style='padding: 2px;width: 96%;line-height: 30px;height: 30px !important;'>";
2488
-
2489
- foreach ( $accounts as $account ) {
2490
-
2491
- echo "<option value='" . $account['id'] . "'>" . $account['name'] . "</option>";
2492
-
2493
- }
2494
-
2495
- echo "</select>
2496
-
2497
- </span>
2498
-
2499
- <div class='gawd_info' title='Choose the Google Analytics account to connect this property to.'></div>
2500
-
2501
- <div class='clear'></div>
2502
-
2503
- </div>
2504
-
2505
- <div class='gawd_goal_row'>
2506
-
2507
- <span class='gawd_goal_label'>Name</span>
2508
-
2509
- <span class='gawd_goal_input'>
2510
-
2511
- <input id='gawd_property_name' name='gawd_property_name' type='text'>
2512
-
2513
- </span>
2514
-
2515
- <div class='gawd_info' title='Provide a name for the property.'></div>
2516
-
2517
- <div class='clear'></div>
2518
-
2519
- </div>
2520
-
2521
- </div>
2522
-
2523
- <div class='gawd_add_prop gawd_submit'>
2524
-
2525
- <a href='" . admin_url() . "admin.php?page=gawd_analytics' class='gawd_later button_gawd'>Later</a>
2526
-
2527
- <input type='button' id='gawd_add_property' class='button_gawd' value='Add'/>
2528
-
2529
- <input type='hidden' id='add_property' name='add_property'/>
2530
-
2531
- </div>
2532
-
2533
- </form>";
2534
-
2535
- // account select to add web property and web property parameters
2536
-
2537
- // and add link to google analytics for manually creating an account
2538
-
2539
- // wp_die();
2540
-
2541
- } else {
2542
-
2543
- $this->gawd_admin_notice( "You do not have any google analytics accounts set. Please go with <a href='https://analytics.google.com/' target='_blank'>this</a> link to add one.", "error" );
2544
-
2545
- // link to google analytics to add account
2546
-
2547
- // wp_die();
2548
-
2549
- }
2550
-
2551
- } elseif ( count( $property ) == 1 ) {
2552
-
2553
- $property = $property[0];
2554
-
2555
- $gawd_user_data['webPropertyId'] = $property['id'];
2556
-
2557
- $gawd_user_data['default_webPropertyId'] = $property['id'];
2558
-
2559
- $gawd_user_data['accountId'] = $property['accountId'];
2560
-
2561
- $gawd_user_data['default_accountId'] = $property['accountId'];
2562
-
2563
- $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
2564
-
2565
- update_option( 'gawd_user_data', $gawd_user_data );
2566
-
2567
- } else {
2568
-
2569
- echo "<p class='notice'>You have multiple web-properties set with current site url. Please select the one which you want to use for tracking from the list below.</p>
2570
-
2571
- <br/>
2572
-
2573
- <form method='post' id='gawd_property_select'>
2574
-
2575
- <div class='gawd_settings_wrapper'>
2576
-
2577
- <div class='gawd_goal_row'>
2578
-
2579
- <span class='gawd_goal_label'>Web-property</span>
2580
-
2581
- <span class='gawd_goal_input'>
2582
-
2583
- <select name='gawd_property_select' class='gawd_property_select' style='padding: 2px;width: 96%;line-height: 30px;height: 30px !important;'>";
2584
-
2585
- foreach ( $property as $select_property ) {
2586
-
2587
- echo "<option value='" . $select_property['id'] . "'>" . $select_property['name'] . " (" . $select_property['id'] . ")</option>";
2588
-
2589
- }
2590
-
2591
- echo "</select>
2592
-
2593
- </span>
2594
-
2595
- <div class='gawd_info' title=''></div>
2596
-
2597
- <div class='clear'></div>
2598
-
2599
- </div>
2600
-
2601
- </div>
2602
-
2603
- <div class='gawd_submit'><input type='submit' name='lock_property' class='button_gawd' value='SAVE'/></div>
2604
-
2605
- </form>";
2606
-
2607
- // web property select to select from properties with same site url
2608
-
2609
- // wp_die();
2610
-
2611
- }
2612
-
2613
- }
2614
-
2615
- }
2616
-
2617
-
2618
-
2619
- public function gawd_admin_notice( $message, $type ) {
2620
-
2621
- $class = 'notice notice-' . $type;
2622
-
2623
- echo '<div class="' . $class . '"><p>' . $message . '</p></div>';
2624
-
2625
- }
2626
-
2627
-
2628
-
2629
- public function gawd_display_settings_page() {
2630
-
2631
-
2632
-
2633
- global $gawd_user_data;
2634
-
2635
- $gawd_user_data = get_option( 'gawd_user_data' );
2636
-
2637
- if ( isset( $_GET['defaultExist'] ) && $_GET['defaultExist'] == 1 ) {
2638
-
2639
- $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
2640
-
2641
- echo '<script>window.location.href="' . $redirect_url . '";</script>';
2642
-
2643
- }
2644
-
2645
- if ( isset( $_POST['gawd_settings_logout'] ) && $_POST['gawd_settings_logout'] == 1 ) {
2646
-
2647
- delete_option( 'gawd_user_data' );
2648
-
2649
- $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
2650
-
2651
- echo '<script>window.location.href="' . $redirect_url . '";</script>';
2652
-
2653
- }
2654
-
2655
- if ( isset( $_POST['web_property_name'] ) && $_POST['web_property_name'] != '' ) {
2656
-
2657
- $gawd_user_data['gawd_id'] = isset( $_POST['gawd_id'] ) ? $_POST['gawd_id'] : '';
2658
-
2659
- foreach ( $gawd_user_data['gawd_profiles'] as $web_property_name => $web_property ) {
2660
-
2661
- foreach ( $web_property as $profile ) {
2662
-
2663
- if ( $profile['id'] == $gawd_user_data['gawd_id'] ) {
2664
-
2665
- $gawd_user_data['web_property_name'] = $web_property_name;
2666
-
2667
- $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
2668
-
2669
- $gawd_user_data['accountId'] = $profile['accountId'];
2670
-
2671
- }
2672
-
2673
- }
2674
-
2675
- }
2676
-
2677
- $gawd_user_data['web_property_name'] = isset( $_POST['web_property_name'] ) ? $_POST['web_property_name'] : '';
2678
-
2679
- update_option( 'gawd_user_data', $gawd_user_data );
2680
-
2681
- $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
2682
-
2683
- //echo '<script>window.location.href="'.$redirect_url.'";</script>';
2684
-
2685
- }
2686
-
2687
- /* if(isset($_POST['account_name']) && $_POST['account_name'] != ''){
2688
-
2689
- $gawd_user_data['accountId'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
2690
-
2691
- foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
2692
-
2693
- foreach ($web_property as $profile) {
2694
-
2695
- if ($profile['accountId'] == $gawd_user_data['accountId']) {
2696
-
2697
- $gawd_user_data['web_property_name'] = $web_property_name;
2698
-
2699
- $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
2700
-
2701
- $gawd_user_data['accountId'] = $profile['accountId'];
2702
-
2703
- }
2704
-
2705
- }
2706
-
2707
- }
2708
-
2709
- $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
2710
-
2711
- update_option('gawd_user_data', $gawd_user_data);
2712
-
2713
- $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
2714
-
2715
- //echo '<script>window.location.href="'.$redirect_url.'";</script>';
2716
-
2717
- } */
2718
-
2719
- if ( isset( $_GET['errorMsg'] ) ) {
2720
-
2721
- self::error_message( 'error', 'User does not have sufficient permissions for this account to add filter' );
2722
-
2723
- }
2724
-
2725
- if ( ! isset( $gawd_user_data['refresh_token'] ) || ( $gawd_user_data['refresh_token'] == '' ) ) {
2726
-
2727
- echo '<div class="gawd_auth_wrap"><p class="auth_description">Click <b>Authenticate</b> button and login to your Google account. A window asking for relevant permissions will appear. Click <b>Allow</b> and copy the authentication code from the text input.</p><div id="gawd_auth_url" onclick="gawd_auth_popup(' . GAWD_google_client::create_authentication_url() . ',800,400)" style="cursor: pointer;"><div class="gawd_auth_button">AUTHENTICATE</div><div class="clear"></div></div>';
2728
-
2729
- echo '<div id="gawd_auth_code"><form id="gawd_auth_code_paste" action="" method="post" onSubmit="return false;">
2730
-
2731
- <p style="margin:0;color: #444;">Paste the authentication code from the popup to this input.</p>
2732
-
2733
- <input id="gawd_token" type="text">';
2734
-
2735
- wp_nonce_field( "gawd_save_form", "gawd_save_form_fild" );
2736
-
2737
- echo '</form>
2738
-
2739
- <div id="gawd_auth_code_submit">SUBMIT</div></div>';
2740
-
2741
- $gawd_own_project = get_option( 'gawd_own_project' );
2742
-
2743
- if ( isset( $gawd_own_project ) && $gawd_own_project && intval( $gawd_own_project ) == 1 ) {
2744
-
2745
- echo '<form method="post">
2746
-
2747
- <div class="gawd_reset_button">
2748
-
2749
- <input type="hidden" name="reset_data" id="reset_data"/>
2750
-
2751
- <input type="button" class="button_gawd" id="gawd_reset_button" value="RESET"/>
2752
-
2753
- </div>
2754
-
2755
- </form>';
2756
-
2757
- }
2758
-
2759
- echo '</div><div id="opacity_div" style="display: none; background-color: rgba(0, 0, 0, 0.2); position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 99998;"></div>
2760
-
2761
- <div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 99999;">
2762
-
2763
- <img src="' . GAWD_URL . '/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;">
2764
-
2765
- </div>';
2766
-
2767
- } else {
2768
-
2769
- if ( $this->manage_ua_code_selection() != 'done' ) {
2770
-
2771
- // return;
2772
-
2773
- }
2774
-
2775
- try {
2776
-
2777
- $gawd_client = GAWD_google_client::get_instance();
2778
-
2779
- $gawd_client->get_profiles();
2780
-
2781
-
2782
-
2783
- } catch ( Google_Service_Exception $e ) {
2784
-
2785
- $errors = $e->getErrors();
2786
-
2787
-
2788
-
2789
- return $errors[0]["message"];
2790
-
2791
- } catch ( Exception $e ) {
2792
-
2793
- return $e->getMessage();
2794
-
2795
- }
2796
-
2797
-
2798
-
2799
- $gawd_alert_remove = isset( $_POST['gawd_alert_remove'] ) ? intval( $_POST['gawd_alert_remove'] ) : false;
2800
-
2801
- $gawd_menu_remove = isset( $_POST['gawd_menu_remove'] ) ? intval( $_POST['gawd_menu_remove'] ) : false;
2802
-
2803
- $gawd_pushover_remove = isset( $_POST['gawd_pushover_remove'] ) ? intval( $_POST['gawd_pushover_remove'] ) : false;
2804
-
2805
- $gawd_email_remove = isset( $_POST['gawd_email_remove'] ) ? intval( $_POST['gawd_email_remove'] ) : false;
2806
-
2807
- $gawd_filter_remove = isset( $_POST['gawd_filter_remove'] ) ? intval( $_POST['gawd_filter_remove'] ) : false;
2808
-
2809
- if ( $gawd_alert_remove ) {
2810
-
2811
- $all_alerts = get_option( 'gawd_alerts' );
2812
-
2813
- if ( $all_alerts ) {
2814
-
2815
- foreach ( $all_alerts as $alert ) {
2816
-
2817
- wp_unschedule_event( wp_next_scheduled( 'gawd_alert_' . $alert['period'] ), 'gawd_alert_' . $alert['period'] );
2818
-
2819
- }
2820
-
2821
- unset( $all_alerts[ $gawd_alert_remove - 1 ] );
2822
-
2823
- update_option( 'gawd_alerts', $all_alerts );
2824
-
2825
- }
2826
-
2827
- }
2828
-
2829
- if ( $gawd_menu_remove ) {
2830
-
2831
- $all_menues = get_option( 'gawd_menu_for_user' );
2832
-
2833
- if ( $all_menues ) {
2834
-
2835
- unset( $all_menues[ $gawd_menu_remove ] );
2836
-
2837
- update_option( 'gawd_menu_for_user', $all_menues );
2838
-
2839
- }
2840
-
2841
- }
2842
-
2843
- if ( $gawd_email_remove ) {
2844
-
2845
- $all_emails = get_option( 'gawd_email' );
2846
-
2847
- if ( $all_emails ) {
2848
-
2849
- foreach ( $all_emails as $email ) {
2850
-
2851
- wp_unschedule_event( wp_next_scheduled( 'gawd_email_' . $email['period'] ), 'gawd_email_' . $email['period'] );
2852
-
2853
- }
2854
-
2855
- unset( $all_emails[ $gawd_email_remove - 1 ] );
2856
-
2857
- update_option( 'gawd_email', $all_emails );
2858
-
2859
- }
2860
-
2861
- }
2862
-
2863
- if ( $gawd_filter_remove ) {
2864
-
2865
- $analytics = $gawd_client->analytics_member;
2866
-
2867
- $accountId = $gawd_client->get_profile_accountId();
2868
-
2869
- try {
2870
-
2871
- $analytics->management_filters->delete( $accountId, $gawd_filter_remove );
2872
-
2873
- } catch ( apiServiceException $e ) {
2874
-
2875
- print 'There was an Analytics API service error '
2876
-
2877
- . $e->getCode() . ':' . $e->getMessage();
2878
-
2879
- } catch ( apiException $e ) {
2880
-
2881
- print 'There was a general API error '
2882
-
2883
- . $e->getCode() . ':' . $e->getMessage();
2884
-
2885
- } catch ( Exception $e ) {
2886
-
2887
- echo '<script>window.location.href="' . admin_url() . 'admin.php?page=gawd_settings&errorMsg=1#gawd_filters_tab";</script>';
2888
-
2889
- }
2890
-
2891
- }
2892
-
2893
- $gawd_pushover_remove = isset( $_POST['gawd_pushover_remove'] ) ? $_POST['gawd_pushover_remove'] : false;
2894
-
2895
- if ( $gawd_pushover_remove ) {
2896
-
2897
- $all_pushovers = get_option( 'gawd_pushovers' );
2898
-
2899
- if ( $all_pushovers ) {
2900
-
2901
- foreach ( $all_pushovers as $pushover ) {
2902
-
2903
- wp_unschedule_event( wp_next_scheduled( 'gawd_pushover_' . $pushover['period'] ), 'gawd_pushover_' . $pushover['period'] );
2904
-
2905
- }
2906
-
2907
- unset( $all_pushovers[ $gawd_pushover_remove - 1 ] );
2908
-
2909
- update_option( 'gawd_pushovers', $all_pushovers );
2910
-
2911
- }
2912
-
2913
- }
2914
-
2915
- if ( isset( $_POST['settings_submit'] ) ) {
2916
-
2917
- check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
2918
-
2919
- $gawd_user_data = get_option( 'gawd_user_data' );
2920
-
2921
- $gawd_alert_name = isset( $_POST['gawd_alert_name'] ) ? sanitize_text_field( $_POST['gawd_alert_name'] ) : '';
2922
-
2923
- $gawd_alert_period = isset( $_POST['gawd_alert_name'] ) ? sanitize_text_field( $_POST['gawd_alert_period'] ) : '';
2924
-
2925
- $gawd_alert_metric = isset( $_POST['gawd_alert_metric'] ) ? sanitize_text_field( $_POST['gawd_alert_metric'] ) : '';
2926
-
2927
- $gawd_alert_condition = isset( $_POST['gawd_alert_condition'] ) ? sanitize_text_field( $_POST['gawd_alert_condition'] ) : '';
2928
-
2929
- $gawd_alert_value = isset( $_POST['gawd_alert_value'] ) ? sanitize_text_field( $_POST['gawd_alert_value'] ) : '';
2930
-
2931
- $gawd_alert_emails = isset( $_POST['gawd_alert_emails'] ) ? sanitize_email( $_POST['gawd_alert_emails'] ) : '';
2932
-
2933
- $gawd_alert_view = isset( $_POST['gawd_alert_view'] ) ? sanitize_text_field( $_POST['gawd_alert_view'] ) : '';
2934
-
2935
- $alert_view_name = isset( $_POST['alert_view_name'] ) ? sanitize_text_field( $_POST['alert_view_name'] ) : '';
2936
-
2937
- if ( $gawd_alert_name != '' && $gawd_alert_period != '' && $gawd_alert_metric != '' && $gawd_alert_condition != '' && $gawd_alert_value != '' && $gawd_alert_emails != '' ) {
2938
-
2939
- $saved_alerts = get_option( 'gawd_alerts' );
2940
-
2941
- if ( $saved_alerts ) {
2942
-
2943
- $gawd_alert_options = array(
2944
-
2945
- 'name' => $gawd_alert_name,
2946
-
2947
- 'period' => $gawd_alert_period,
2948
-
2949
- 'metric' => $gawd_alert_metric,
2950
-
2951
- 'condition' => $gawd_alert_condition,
2952
-
2953
- 'value' => $gawd_alert_value,
2954
-
2955
- 'creation_date' => date( 'Y-m-d' ),
2956
-
2957
- 'emails' => $gawd_alert_emails,
2958
-
2959
- 'alert_view' => $gawd_alert_view,
2960
-
2961
- 'alert_view_name' => $alert_view_name
2962
-
2963
- );
2964
-
2965
- $saved_alerts[] = $gawd_alert_options;
2966
-
2967
- update_option( 'gawd_alerts', $saved_alerts );
2968
-
2969
- } else {
2970
-
2971
- $gawd_alert_options = array(
2972
-
2973
- 0 => array(
2974
-
2975
- 'name' => $gawd_alert_name,
2976
-
2977
- 'period' => $gawd_alert_period,
2978
-
2979
- 'metric' => $gawd_alert_metric,
2980
-
2981
- 'condition' => $gawd_alert_condition,
2982
-
2983
- 'value' => $gawd_alert_value,
2984
-
2985
- 'creation_date' => date( 'Y-m-d' ),
2986
-
2987
- 'emails' => $gawd_alert_emails,
2988
-
2989
- 'alert_view' => $gawd_alert_view,
2990
-
2991
- 'alert_view_name' => $alert_view_name
2992
-
2993
- )
2994
-
2995
- );
2996
-
2997
- update_option( 'gawd_alerts', $gawd_alert_options );
2998
-
2999
- }
3000
-
3001
- $saved_alerts = get_option( 'gawd_alerts' );
3002
-
3003
- if ( $saved_alerts ) {
3004
-
3005
- foreach ( $saved_alerts as $alert ) {
3006
-
3007
- if ( ! wp_next_scheduled( 'gawd_alert_' . $alert['period'] ) ) {
3008
-
3009
- wp_schedule_event( time(), $alert['period'], 'gawd_alert_' . $alert['period'] );
3010
-
3011
- }
3012
-
3013
- }
3014
-
3015
- }
3016
-
3017
- }
3018
-
3019
- $gawd_pushover_name = isset( $_POST['gawd_pushover_name'] ) ? sanitize_text_field( $_POST['gawd_pushover_name'] ) : '';
3020
-
3021
- $gawd_pushover_period = isset( $_POST['gawd_pushover_period'] ) ? sanitize_text_field( $_POST['gawd_pushover_period'] ) : '';
3022
-
3023
- $gawd_pushover_metric = isset( $_POST['gawd_pushover_metric'] ) ? sanitize_text_field( $_POST['gawd_pushover_metric'] ) : '';
3024
-
3025
- $gawd_pushover_condition = isset( $_POST['gawd_pushover_condition'] ) ? sanitize_text_field( $_POST['gawd_pushover_condition'] ) : '';
3026
-
3027
- $gawd_pushover_value = isset( $_POST['gawd_pushover_value'] ) ? intval( $_POST['gawd_pushover_value'] ) : '';
3028
-
3029
-
3030
-
3031
- $gawd_pushover_user_keys = isset( $_POST['gawd_pushover_user_keys'] ) ? sanitize_text_field( $_POST['gawd_pushover_user_keys'] ) : '';
3032
-
3033
- $gawd_pushover_view = isset( $_POST['gawd_pushover_view'] ) ? sanitize_text_field( $_POST['gawd_pushover_view'] ) : '';
3034
-
3035
- $pushover_view_name = isset( $_POST['pushover_view_name'] ) ? sanitize_text_field( $_POST['pushover_view_name'] ) : '';
3036
-
3037
- if ( $gawd_pushover_name != '' && $gawd_pushover_period != '' && $gawd_pushover_metric != '' && $gawd_pushover_condition != '' && $gawd_pushover_value !== '' && $gawd_pushover_user_keys != '' ) {
3038
-
3039
- $saved_pushovers = get_option( 'gawd_pushovers' );
3040
-
3041
- if ( $saved_pushovers ) {
3042
-
3043
- $gawd_pushover_options = array(
3044
-
3045
- 'name' => $gawd_pushover_name,
3046
-
3047
- 'period' => $gawd_pushover_period,
3048
-
3049
- 'metric' => $gawd_pushover_metric,
3050
-
3051
- 'condition' => $gawd_pushover_condition,
3052
-
3053
- 'value' => $gawd_pushover_value,
3054
-
3055
- 'creation_date' => date( 'Y-m-d' ),
3056
-
3057
- 'user_key' => $gawd_pushover_user_keys,
3058
-
3059
- 'pushover_view' => $gawd_pushover_view,
3060
-
3061
- 'pushover_view_name' => $pushover_view_name
3062
-
3063
- );
3064
-
3065
- $saved_pushovers[] = $gawd_pushover_options;
3066
-
3067
- update_option( 'gawd_pushovers', $saved_pushovers );
3068
-
3069
- } else {
3070
-
3071
- $gawd_pushover_options = array(
3072
-
3073
- 0 => array(
3074
-
3075
- 'name' => $gawd_pushover_name,
3076
-
3077
- 'period' => $gawd_pushover_period,
3078
-
3079
- 'metric' => $gawd_pushover_metric,
3080
-
3081
- 'condition' => $gawd_pushover_condition,
3082
-
3083
- 'value' => $gawd_pushover_value,
3084
-
3085
- 'creation_date' => date( 'Y-m-d' ),
3086
-
3087
- 'user_key' => $gawd_pushover_user_keys,
3088
-
3089
- 'pushover_view' => $gawd_pushover_view,
3090
-
3091
- 'pushover_view_name' => $pushover_view_name
3092
-
3093
- )
3094
-
3095
- );
3096
-
3097
- update_option( 'gawd_pushovers', $gawd_pushover_options );
3098
-
3099
- }
3100
-
3101
- $saved_pushovers = get_option( 'gawd_pushovers' );
3102
-
3103
- if ( $saved_pushovers ) {
3104
-
3105
-
3106
-
3107
- foreach ( $saved_pushovers as $pushover ) {
3108
-
3109
- $this->gawd_pushover_api( $pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value'] );
3110
-
3111
- if ( ! wp_next_scheduled( 'gawd_pushover_' . $pushover['period'] ) ) {
3112
-
3113
- wp_schedule_event( time(), $pushover['period'], 'gawd_pushover_' . $pushover['period'] );
3114
-
3115
- }
3116
-
3117
- }
3118
-
3119
- }
3120
-
3121
- }
3122
-
3123
- $gawd_show_in_dashboard = isset( $_POST['gawd_show_in_dashboard'] ) ? sanitize_text_field( $_POST['gawd_show_in_dashboard'] ) : '';
3124
-
3125
-
3126
-
3127
- $gawd_permissions = isset( $_POST['gawd_permissions'] ) ? explode(',', $_POST['gawd_permissions']) : array('manage_options');
3128
-
3129
- $gawd_own_project = isset( $_POST['gawd_own_project'] ) ? sanitize_text_field( $_POST['gawd_own_project'] ) : '';
3130
-
3131
- $site_speed_rate = isset( $_POST['site_speed_rate'] ) ? intval( $_POST['site_speed_rate'] ) : '1';
3132
-
3133
- $post_page_chart = isset( $_POST['post_page_chart'] ) ? sanitize_text_field( $_POST['post_page_chart'] ) : '';
3134
-
3135
- $enable_cross_domain = isset( $_POST['enable_cross_domain'] ) ? sanitize_text_field( $_POST['enable_cross_domain'] ) : '';
3136
-
3137
- $cross_domains = isset( $_POST['cross_domains'] ) ? sanitize_text_field( $_POST['cross_domains'] ) : '';
3138
-
3139
- $default_date = isset( $_POST['default_date'] ) ? $_POST['default_date'] : 'last_7_days';
3140
-
3141
- $default_date_format = isset( $_POST['default_date_format'] ) ? $_POST['default_date_format'] : 'ymd_with_week';
3142
-
3143
- $enable_hover_tooltip = isset( $_POST['enable_hover_tooltip'] ) ? $_POST['enable_hover_tooltip'] : '';
3144
-
3145
- $gawd_backend_roles = isset( $_POST['gawd_backend_roles'] ) ? explode(',', $_POST['gawd_backend_roles'] ) : array('administrator');
3146
-
3147
- $gawd_frontend_roles = isset( $_POST['gawd_frontend_roles'] ) ? explode(',', $_POST['gawd_frontend_roles'] ) : array('administrator');
3148
-
3149
- $gawd_post_page_roles = isset( $_POST['gawd_post_page_roles'] ) ? explode(',', $_POST['gawd_post_page_roles'] ) : array('administrator');
3150
-
3151
- $exclude_events = isset( $_POST['exclude_events'] ) ? sanitize_text_field( $_POST['exclude_events'] ) : array();
3152
-
3153
- $gawd_settings_exist = get_option( 'gawd_settings' );
3154
-
3155
- $gawd_settings_exist['gawd_show_in_dashboard'] = $gawd_show_in_dashboard;
3156
-
3157
- $gawd_settings_exist['site_speed_rate'] = $site_speed_rate;
3158
-
3159
- $gawd_settings_exist['post_page_chart'] = $post_page_chart;
3160
-
3161
- $gawd_settings_exist['enable_cross_domain'] = $enable_cross_domain;
3162
-
3163
- $gawd_settings_exist['cross_domains'] = $cross_domains;
3164
-
3165
- $gawd_settings_exist['gawd_backend_roles'] = $gawd_backend_roles;
3166
-
3167
- $gawd_settings_exist['gawd_frontend_roles'] = $gawd_frontend_roles;
3168
-
3169
- $gawd_settings_exist['gawd_post_page_roles'] = $gawd_post_page_roles;
3170
-
3171
- $gawd_settings_exist['default_date'] = $default_date;
3172
-
3173
- $gawd_settings_exist['default_date_format'] = $default_date_format;
3174
-
3175
- $gawd_settings_exist['enable_hover_tooltip'] = $enable_hover_tooltip;
3176
-
3177
- $gawd_settings_exist['exclude_events'] = $exclude_events;
3178
-
3179
- $gawd_settings_exist['gawd_permissions'] = $gawd_permissions;
3180
-
3181
- update_option( 'gawd_settings', $gawd_settings_exist );
3182
-
3183
- $gawd_filter_name = isset( $_POST['gawd_filter_name'] ) ? sanitize_text_field( $_POST['gawd_filter_name'] ) : '';
3184
-
3185
- $gawd_filter_type = isset( $_POST['gawd_filter_type'] ) ? sanitize_text_field( $_POST['gawd_filter_type'] ) : '';
3186
-
3187
- $gawd_filter_value = isset( $_POST['gawd_filter_value'] ) ? $gawd_filter_type == 'GEO_IP_ADDRESS' ? ( $_POST['gawd_filter_value'] ) : sanitize_text_field( $_POST['gawd_filter_value'] ) : '';
3188
-
3189
- if ( $gawd_filter_name != '' && $gawd_filter_type != '' && $gawd_filter_value != '' ) {
3190
-
3191
- $gawd_client->add_filter( $gawd_filter_name, $gawd_filter_type, $gawd_filter_value );
3192
-
3193
- }
3194
-
3195
- add_option( "gawd_save_settings", 1 );
3196
-
3197
- }
3198
-
3199
- if ( get_option( 'gawd_save_settings' ) == 1 ) {
3200
-
3201
- $this->gawd_admin_notice( 'Your changes have been saved successfully.', 'success is-dismissible' );
3202
-
3203
- }
3204
-
3205
- delete_option( 'gawd_save_settings' );
3206
-
3207
- require_once( 'admin/pages/settings.php' );
3208
-
3209
- }
3210
-
3211
- }
3212
-
3213
-
3214
-
3215
- public function reset_user_data() {
3216
-
3217
- delete_option( "gawd_credentials" );
3218
-
3219
- $credentials['project_id'] = '115052745574-5vbr7tci4hjkr9clkflmnpto5jisgstg.apps.googleusercontent.com';
3220
-
3221
- $credentials['project_secret'] = 'wtNiu3c_bA_g7res6chV0Trt';
3222
-
3223
- update_option( 'gawd_credentials', $credentials );
3224
-
3225
- delete_option( 'gawd_own_project' );
3226
-
3227
- delete_option( 'gawd_user_data' );
3228
-
3229
-
3230
-
3231
- }
3232
-
3233
-
3234
-
3235
- public function gawd_display_tracking_page() {
3236
-
3237
- global $gawd_client, $gawd_user_data;
3238
-
3239
- $gawd_client = GAWD_google_client::get_instance();
3240
-
3241
- $gawd_user_data = get_option( 'gawd_user_data' );
3242
-
3243
- $add_dimension_value = isset( $_POST['add_dimension_value'] ) ? $_POST['add_dimension_value'] : '';
3244
-
3245
- if ( isset( $_GET['errorMsg'] ) ) {
3246
-
3247
- self::error_message( 'error', 'User does not have sufficient permissions for this account' );
3248
-
3249
- }
3250
-
3251
- if ( isset( $_POST['add_property'] ) ) {
3252
-
3253
- $gawd_account_select = isset( $_POST['gawd_account_select'] ) ? $_POST['gawd_account_select'] : '';
3254
-
3255
- $gawd_property_name = isset( $_POST['gawd_property_name'] ) ? $_POST['gawd_property_name'] : '';
3256
-
3257
- if ( $gawd_account_select && $gawd_property_name ) {
3258
-
3259
- $err_msg = $gawd_client->add_webproperty( $gawd_account_select, $gawd_property_name );
3260
-
3261
- $redirect_url = admin_url() . 'admin.php?page=gawd_tracking&enableTracking=1';
3262
-
3263
- if ( $err_msg ) {
3264
-
3265
- $redirect_url .= '&errorMsg=1';
3266
-
3267
- }
3268
-
3269
- echo '<script>window.location.href="' . $redirect_url . '";</script>';
3270
-
3271
- }
3272
-
3273
- }
3274
-
3275
- if ( isset( $_POST['lock_property'] ) ) {
3276
-
3277
- $property = $gawd_client->property_exists();
3278
-
3279
- $gawd_property_select = $_POST['gawd_property_select'];
3280
-
3281
- foreach ( $property as $property_select ) {
3282
-
3283
- if ( $property_select['id'] == $gawd_property_select ) {
3284
-
3285
- $property = $property_select;
3286
-
3287
- break;
3288
-
3289
- }
3290
-
3291
- }
3292
-
3293
- $gawd_user_data['webPropertyId'] = $property['id'];
3294
-
3295
- $gawd_user_data['default_webPropertyId'] = $property['id'];
3296
-
3297
- $gawd_user_data['accountId'] = $property['accountId'];
3298
-
3299
- $gawd_user_data['default_accountId'] = $property['accountId'];
3300
-
3301
- $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
3302
-
3303
- update_option( 'gawd_user_data', $gawd_user_data );
3304
-
3305
- }
3306
-
3307
- if ( $this->manage_ua_code_selection_tracking() != 'done' ) {
3308
-
3309
- $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
3310
-
3311
-
3312
-
3313
- //echo '<script>window.location.href="'.$redirect_url.'";</script>';
3314
-
3315
- return;
3316
-
3317
- }
3318
-
3319
- $gawd_settings = get_option( 'gawd_settings' );
3320
-
3321
-
3322
-
3323
- if ( $add_dimension_value == 'add_dimension_Logged_in' ) {
3324
-
3325
- $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
3326
-
3327
- $gawd_client->add_custom_dimension( 'Logged in', $id );
3328
-
3329
- $settings = get_option( 'gawd_settings' );
3330
-
3331
- $optname = 'gawd_custom_dimension_Logged_in';
3332
-
3333
- $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
3334
-
3335
- update_option( 'gawd_settings', $settings );
3336
-
3337
-
3338
-
3339
- }
3340
-
3341
- if ( $add_dimension_value == 'add_dimension_Post_type' ) {
3342
-
3343
- $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
3344
-
3345
- $gawd_client->add_custom_dimension( 'Post type', $id );
3346
-
3347
- $settings = get_option( 'gawd_settings' );
3348
-
3349
- $optname = 'gawd_custom_dimension_Post_type';
3350
-
3351
- $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
3352
-
3353
- update_option( 'gawd_settings', $settings );
3354
-
3355
-
3356
-
3357
- }
3358
-
3359
- if ( $add_dimension_value == 'add_dimension_Author' ) {
3360
-
3361
- $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
3362
-
3363
- $gawd_client->add_custom_dimension( 'Author', $id );
3364
-
3365
- $settings = get_option( 'gawd_settings' );
3366
-
3367
- $optname = 'gawd_custom_dimension_Author';
3368
-
3369
- $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
3370
-
3371
- update_option( 'gawd_settings', $settings );
3372
-
3373
-
3374
-
3375
- }
3376
-
3377
- if ( $add_dimension_value == 'add_dimension_Category' ) {
3378
-
3379
- $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
3380
-
3381
- $gawd_client->add_custom_dimension( 'Category', $id );
3382
-
3383
- $settings = get_option( 'gawd_settings' );
3384
-
3385
- $optname = 'gawd_custom_dimension_Category';
3386
-
3387
-
3388
-
3389
- $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
3390
-
3391
- update_option( 'gawd_settings', $settings );
3392
-
3393
- }
3394
-
3395
- if ( $add_dimension_value == 'add_dimension_Published_Month' ) {
3396
-
3397
- $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
3398
-
3399
- $gawd_client->add_custom_dimension( 'Published Month', $id );
3400
-
3401
- $settings = get_option( 'gawd_settings' );
3402
-
3403
- $optname = 'gawd_custom_dimension_Published_Month';
3404
-
3405
- $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
3406
-
3407
- update_option( 'gawd_settings', $settings );
3408
-
3409
-
3410
-
3411
- }
3412
-
3413
- if ( $add_dimension_value == 'add_dimension_Published_Year' ) {
3414
-
3415
- $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
3416
-
3417
- $gawd_client->add_custom_dimension( 'Published Year', $id );
3418
-
3419
- $settings = get_option( 'gawd_settings' );
3420
-
3421
- $optname = 'gawd_custom_dimension_Published_Year';
3422
-
3423
- $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
3424
-
3425
- update_option( 'gawd_settings', $settings );
3426
-
3427
-
3428
-
3429
- }
3430
-
3431
- if ( $add_dimension_value == 'add_dimension_Tags' ) {
3432
-
3433
- $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
3434
-
3435
- $gawd_client->add_custom_dimension( 'Tags', $id );
3436
-
3437
- $settings = get_option( 'gawd_settings' );
3438
-
3439
- $optname = 'gawd_custom_dimension_Tags';
3440
-
3441
- $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
3442
-
3443
- update_option( 'gawd_settings', $settings );
3444
-
3445
- }
3446
-
3447
- if ( isset( $_POST['settings_submit'] ) ) {
3448
-
3449
- check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
3450
-
3451
- $gawd_user_data = get_option( 'gawd_user_data' );
3452
-
3453
- $gawd_file_formats = isset( $_POST['gawd_file_formats'] ) ? sanitize_text_field( $_POST['gawd_file_formats'] ) : '';
3454
-
3455
- $gawd_anonymize = isset( $_POST['gawd_anonymize'] ) ? sanitize_text_field( $_POST['gawd_anonymize'] ) : '';
3456
-
3457
- $gawd_tracking_enable = isset( $_POST['gawd_tracking_enable'] ) ? sanitize_text_field( $_POST['gawd_tracking_enable'] ) : '';
3458
-
3459
- $gawd_outbound = isset( $_POST['gawd_outbound'] ) ? sanitize_text_field( $_POST['gawd_outbound'] ) : '';
3460
-
3461
- $gawd_enhanced = isset( $_POST['gawd_enhanced'] ) ? sanitize_text_field( $_POST['gawd_enhanced'] ) : '';
3462
-
3463
- $enable_custom_code = isset( $_POST['enable_custom_code'] ) ? $_POST['enable_custom_code'] : '';
3464
- $custom_code = isset( $_POST['gawd_custom_code'] ) ? sanitize_text_field( $_POST['gawd_custom_code'] ) : '';
3465
-
3466
- if ( $add_dimension_value == '' ) {
3467
-
3468
- $gawd_cd_Logged_in = isset( $_POST['gawd_custom_dimension_Logged_in'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Logged_in'] ) : '';
3469
-
3470
- $gawd_cd_Post_type = isset( $_POST['gawd_custom_dimension_Post_type'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Post_type'] ) : '';
3471
-
3472
- $gawd_cd_Author = isset( $_POST['gawd_custom_dimension_Author'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Author'] ) : '';
3473
-
3474
- $gawd_cd_Category = isset( $_POST['gawd_custom_dimension_Category'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Category'] ) : '';
3475
-
3476
- $gawd_cd_Published_Month = isset( $_POST['gawd_custom_dimension_Published_Month'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Published_Month'] ) : '';
3477
-
3478
- $gawd_cd_Published_Year = isset( $_POST['gawd_custom_dimension_Published_Year'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Published_Year'] ) : '';
3479
-
3480
- $gawd_cd_Tags = isset( $_POST['gawd_custom_dimension_Tags'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Tags'] ) : '';
3481
-
3482
- $gawd_settings['gawd_custom_dimension_Logged_in'] = $gawd_cd_Logged_in;
3483
-
3484
- $gawd_settings['gawd_custom_dimension_Post_type'] = $gawd_cd_Post_type;
3485
-
3486
- $gawd_settings['gawd_custom_dimension_Author'] = $gawd_cd_Author;
3487
-
3488
- $gawd_settings['gawd_custom_dimension_Category'] = $gawd_cd_Category;
3489
-
3490
- $gawd_settings['gawd_custom_dimension_Published_Month'] = $gawd_cd_Published_Month;
3491
-
3492
- $gawd_settings['gawd_custom_dimension_Published_Year'] = $gawd_cd_Published_Year;
3493
-
3494
- $gawd_settings['gawd_custom_dimension_Tags'] = $gawd_cd_Tags;
3495
-
3496
- }
3497
-
3498
- $gawd_excluded_roles = isset( $_POST['gawd_excluded_roles'] ) ? $_POST['gawd_excluded_roles'] : array();
3499
-
3500
- $gawd_excluded_users = isset( $_POST['gawd_excluded_users'] ) ? $_POST['gawd_excluded_users'] : array();
3501
-
3502
- $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
3503
-
3504
- $gawd_settings['gawd_anonymize'] = $gawd_anonymize;
3505
-
3506
- $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
3507
-
3508
- $gawd_settings['gawd_tracking_enable'] = $gawd_tracking_enable;
3509
-
3510
- $gawd_settings['gawd_outbound'] = $gawd_outbound;
3511
-
3512
- $gawd_settings['gawd_enhanced'] = $gawd_enhanced;
3513
-
3514
- $gawd_settings['gawd_excluded_roles'] = $gawd_excluded_roles;
3515
-
3516
- $gawd_settings['gawd_excluded_users'] = $gawd_excluded_users;
3517
-
3518
- $gawd_settings['enable_custom_code'] = $enable_custom_code;
3519
-
3520
- $gawd_settings['gawd_custom_code'] = $custom_code;
3521
-
3522
- update_option( 'gawd_settings', $gawd_settings );
3523
-
3524
- add_option( "gawd_save_tracking", 1 );
3525
-
3526
- }
3527
-
3528
- if ( get_option( 'gawd_save_tracking' ) == 1 ) {
3529
-
3530
- $this->gawd_admin_notice( 'Your changes have been saved successfully.', 'success is-dismissible' );
3531
-
3532
- }
3533
-
3534
- delete_option( 'gawd_save_tracking' );
3535
-
3536
- if ( $add_dimension_value != '' ) {
3537
-
3538
- $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
3539
-
3540
- echo '<script>window.location.href="' . $redirect_url . '";</script>';
3541
-
3542
- }
3543
-
3544
- require_once( 'admin/pages/tracking.php' );
3545
-
3546
- }
3547
-
3548
-
3549
-
3550
- public function gawd_my_schedule($schedules) {
3551
-
3552
- $schedules['gawd_weekly'] = array(
3553
-
3554
- 'interval' => 604800,
3555
-
3556
- 'display' => __( 'Every week' )
3557
-
3558
- );
3559
-
3560
- $schedules['gawd_monthly'] = array(
3561
-
3562
- 'interval' => 18748800,
3563
-
3564
- 'display' => __( 'Every month' )
3565
-
3566
- );
3567
-
3568
-
3569
-
3570
- return $schedules;
3571
-
3572
- }
3573
-
3574
-
3575
-
3576
- public function gawd_pushover_api( $user_key, $metric, $condition, $value ) {
3577
-
3578
- $ch = curl_init();
3579
-
3580
- curl_setopt( $ch, CURLOPT_URL, "https://api.pushover.net/1/messages.json" );
3581
-
3582
- curl_setopt( $ch, CURLOPT_POSTFIELDS, array(
3583
-
3584
- "token" => "aJBDhTfhR87EaTzs7wpx1MMKwboBjB",
3585
-
3586
- "user" => $user_key,
3587
-
3588
- "message" => 'The ' . $metric . ' less ' . $value
3589
-
3590
- ) );
3591
-
3592
- // curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
3593
-
3594
- curl_exec( $ch );
3595
-
3596
- curl_close( $ch );
3597
-
3598
- }
3599
-
3600
-
3601
-
3602
- public function gawd_pushover_daily() {
3603
-
3604
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
3605
-
3606
- $gawd_client = GAWD_google_client::get_instance();
3607
-
3608
- $pushovers = get_option( 'gawd_pushovers' );
3609
-
3610
- $data = '';
3611
-
3612
- $condition = '';
3613
-
3614
-
3615
-
3616
- foreach ( $pushovers as $pushover ) {
3617
-
3618
- if ( isset( $pushover['period'] ) && $pushover['period'] == 'daily' ) {
3619
-
3620
- //pls send email if ....
3621
-
3622
- $date = date( 'Y-m-d', strtotime( 'yesterday' ) );
3623
-
3624
- $data = $gawd_client->get_data_alert( 'ga:' . $pushover['metric'], 'date', $date, $date, $pushover['pushover_view'] );
3625
-
3626
- $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
3627
-
3628
- if ( ! eval( $data . $pushover_condition . $pushover['value'] . ';' ) ) {
3629
-
3630
- $cond = ' ' . $pushover['condition'] . ' than';
3631
-
3632
- $this->gawd_pushover_api( $pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value'] );
3633
-
3634
- }
3635
-
3636
- }
3637
-
3638
- }
3639
-
3640
- }
3641
-
3642
-
3643
-
3644
- public function gawd_pushover_weekly() {
3645
-
3646
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
3647
-
3648
- $gawd_client = GAWD_google_client::get_instance();
3649
-
3650
- $pushovers = get_option( 'gawd_pushovers' );
3651
-
3652
- $data = '';
3653
-
3654
- $condition = '';
3655
-
3656
- foreach ( $pushovers as $pushover ) {
3657
-
3658
- if ( isset( $pushover['period'] ) && $pushover['period'] == 'gawd_weekly' ) {
3659
-
3660
- //pls send email if ....
3661
-
3662
- $start_date = date( 'Y-m-d', strtotime( 'last week -1 day' ) );
3663
-
3664
- $end_date = date( 'l' ) != 'Sunday' ? date( 'Y-m-d', strtotime( 'last sunday -1 day' ) ) : date( 'Y-m-d', strtotime( '-1 day' ) );
3665
-
3666
- $data = $gawd_client->get_data_alert( 'ga:' . $pushover['metric'], 'date', $start_date, $end_date, $pushover['pushover_view'] );
3667
-
3668
- $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
3669
-
3670
- if ( ! eval( $data . $pushover_condition . $pushover['value'] . ';' ) ) {
3671
-
3672
- $cond = ' ' . $pushover['condition'] . ' than';
3673
-
3674
- $this->gawd_pushover_api( $pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value'] );
3675
-
3676
- }
3677
-
3678
- }
3679
-
3680
- }
3681
-
3682
- }
3683
-
3684
-
3685
-
3686
- public function gawd_pushover_monthly() {
3687
-
3688
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
3689
-
3690
- $gawd_client = GAWD_google_client::get_instance();
3691
-
3692
- $pushovers = get_option( 'gawd_pushovers' );
3693
-
3694
- $data = '';
3695
-
3696
- $condition = '';
3697
-
3698
- foreach ( $pushovers as $pushover ) {
3699
-
3700
- if ( isset( $pushover['period'] ) && $pushover['period'] == 'gawd_monthly' ) {
3701
-
3702
- //pls send email if ....
3703
-
3704
- $end_date = date( 'Y-m-t', strtotime( 'last month' ) );
3705
-
3706
- $start_date = date( 'Y-m-01', strtotime( 'last month' ) );
3707
-
3708
- $data = $gawd_client->get_data_alert( 'ga:' . $pushover['metric'], 'date', $start_date, $end_date, $pushover['pushover_view'] );
3709
-
3710
- $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
3711
-
3712
- if ( ! eval( $data . $pushover_condition . $pushover['value'] . ';' ) ) {
3713
-
3714
- $cond = ' ' . $pushover['condition'] . ' than';
3715
-
3716
- $this->gawd_pushover_api( $pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value'] );
3717
-
3718
- }
3719
-
3720
- }
3721
-
3722
- }
3723
-
3724
- }
3725
-
3726
-
3727
-
3728
- public function gawd_alert_daily() {
3729
-
3730
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
3731
-
3732
- $gawd_client = GAWD_google_client::get_instance();
3733
-
3734
- $alerts = get_option( 'gawd_alerts' );
3735
-
3736
- $data = '';
3737
-
3738
- $condition = '';
3739
-
3740
- $email_from = get_option( 'admin_email' );
3741
-
3742
- foreach ( $alerts as $alert ) {
3743
-
3744
- if ( isset( $alert['period'] ) && $alert['period'] == 'daily' ) {
3745
-
3746
- //pls send email if ....
3747
-
3748
- $date = date( 'Y-m-d', strtotime( 'yesterday' ) );
3749
-
3750
- $data = $gawd_client->get_data_alert( 'ga:' . $alert['metric'], 'date', $date, $date, $alert['alert_view'] );
3751
-
3752
- $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
3753
-
3754
- $color_condition = $alert['condition'] == 'greater' ? 'rgb(157, 207, 172)' : 'rgb(251, 133, 131)';
3755
-
3756
- if ( ! eval( $data . $alert_condition . $alert['value'] . ';' ) ) {
3757
-
3758
- $cond = ' ' . $alert['condition'] . ' than';
3759
-
3760
- $headers = array();
3761
-
3762
- $headers[] = 'From: <' . $email_from . '>';
3763
-
3764
- $headers[] = 'Content-Type: text/html';
3765
-
3766
- $content = '<div style="font-family: sans-serif;width:100%;height:50px;background-color:#FB8583;font-size:20px;color:#fff;margin-bottom:20px;text-align:center;line-height:50px">Google Analytics WD Alert!</div><p style="color:#808080;text-align: center;font-size: 26px;font-family: sans-serif;">' . preg_replace( '!\s+!', ' ', trim( ucfirst( preg_replace( '/([A-Z])/', ' $1', $alert['metric'] ) ) ) ) . ' in <a style="text-decoration:none;color:rgba(124,181,216,1);font-family: sans-serif;" href="' . $alert["alert_view_name"] . '" target="_blank">' . $alert["alert_view_name"] . '</a> are <span style="color:' . $color_condition . '">' . $cond . '</span></p><p style="color:rgba(124,181,216,1);font-size: 26px;font-family: sans-serif; text-align: center;">' . $alert['value'] . '</p>';
3767
-
3768
- wp_mail( $alert['emails'], 'Analytics Alert', $content, $headers );
3769
-
3770
- }
3771
-
3772
- }
3773
-
3774
- }
3775
-
3776
- }
3777
-
3778
-
3779
-
3780
- public function gawd_alert_weekly() {
3781
-
3782
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
3783
-
3784
- $gawd_client = GAWD_google_client::get_instance();
3785
-
3786
- $alerts = get_option( 'gawd_alerts' );
3787
-
3788
- $data = '';
3789
-
3790
- $condition = '';
3791
-
3792
- $email_from = get_option( 'admin_email' );
3793
-
3794
- foreach ( $alerts as $alert ) {
3795
-
3796
- if ( isset( $alert['period'] ) && $alert['period'] == 'gawd_weekly' ) {
3797
-
3798
- //pls send email if ....
3799
-
3800
- $start_date = date( 'Y-m-d', strtotime( 'last week -1 day' ) );
3801
-
3802
- $end_date = date( 'l' ) != 'Sunday' ? date( 'Y-m-d', strtotime( 'last sunday -1 day' ) ) : date( 'Y-m-d', strtotime( '-1 day' ) );
3803
-
3804
- $data = $gawd_client->get_data_alert( 'ga:' . $alert['metric'], 'date', $start_date, $end_date, $alert['alert_view'] );
3805
-
3806
- $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
3807
-
3808
- if ( ! eval( $data . $alert_condition . $alert['value'] . ';' ) ) {
3809
-
3810
- $cond = ' ' . $alert['condition'] . ' than';
3811
-
3812
- $headers = array();
3813
-
3814
- $headers[] = 'From: <' . $email_from . '>';
3815
-
3816
- $headers[] = 'Content-Type: text/html';
3817
-
3818
- $content = '<div style="font-family: sans-serif;width:100%;height:50px;background-color:#FB8583;font-size:20px;color:#fff;margin-bottom:20px;text-align:center;line-height:50px">Google Analytics WD Alert!</div><p style="color:#808080;text-align: center;font-size: 26px;font-family: sans-serif;">' . preg_replace( '!\s+!', ' ', trim( ucfirst( preg_replace( '/([A-Z])/', ' $1', $alert['metric'] ) ) ) ) . ' in <a style="text-decoration:none;color:rgba(124,181,216,1);font-family: sans-serif;" href="' . $alert["alert_view_name"] . '" target="_blank">' . $alert["alert_view_name"] . '</a> are <span style="color:' . $color_condition . '">' . $cond . '</span></p><p style="color:rgba(124,181,216,1);font-size: 26px;font-family: sans-serif; text-align: center;">' . $alert['value'] . '</p>';
3819
-
3820
- wp_mail( $alert['emails'], 'Analytics Alert', $content, $headers );
3821
-
3822
- }
3823
-
3824
- }
3825
-
3826
- }
3827
-
3828
- }
3829
-
3830
-
3831
-
3832
- public function gawd_alert_monthly() {
3833
-
3834
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
3835
-
3836
- $gawd_client = GAWD_google_client::get_instance();
3837
-
3838
- $alerts = get_option( 'gawd_alerts' );
3839
-
3840
- $data = '';
3841
-
3842
- $email_from = get_option( 'admin_email' );
3843
-
3844
- foreach ( $alerts as $alert ) {
3845
-
3846
- if ( isset( $alert['period'] ) && $alert['period'] == 'gawd_monthly' ) {
3847
-
3848
- //pls send email if ....
3849
-
3850
- $end_date = date( 'Y-m-t', strtotime( 'last month' ) );
3851
-
3852
- $start_date = date( 'Y-m-01', strtotime( 'last month' ) );
3853
-
3854
- $data = $gawd_client->get_data_alert( 'ga:' . $alert['metric'], 'date', $start_date, $end_date, $alert['alert_view'] );
3855
-
3856
- $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
3857
-
3858
- if ( ! eval( $data . $alert_condition . $alert['value'] . ';' ) ) {
3859
-
3860
- $cond = ' ' . $alert['condition'] . ' than';
3861
-
3862
- $headers = array();
3863
-
3864
- $headers[] = 'From: <' . $email_from . '>';
3865
-
3866
- $headers[] = 'Content-Type: text/html';
3867
-
3868
- $content = '<div style="font-family: sans-serif;width:100%;height:50px;background-color:#FB8583;font-size:20px;color:#fff;margin-bottom:20px;text-align:center;line-height:50px">Google Analytics WD Alert!</div><p style="color:#808080;text-align: center;font-size: 26px;font-family: sans-serif;">' . preg_replace( '!\s+!', ' ', trim( ucfirst( preg_replace( '/([A-Z])/', ' $1', $alert['metric'] ) ) ) ) . ' in <a style="text-decoration:none;color:rgba(124,181,216,1);font-family: sans-serif;" href="' . $alert["alert_view_name"] . '" target="_blank">' . $alert["alert_view_name"] . '</a> are <span style="color:' . $color_condition . '">' . $cond . '</span></p><p style="color:rgba(124,181,216,1);font-size: 26px;font-family: sans-serif; text-align: center;">' . $alert['value'] . '</p>';
3869
-
3870
- wp_mail( $alert['emails'], 'Analytics Alert', $content, $headers );
3871
-
3872
- }
3873
-
3874
- }
3875
-
3876
- }
3877
-
3878
- }
3879
-
3880
-
3881
-
3882
- public function wd_dashboard_widget() {
3883
-
3884
- global $gawd_client, $gawd_user_data;
3885
-
3886
- $gawd_client = GAWD_google_client::get_instance();
3887
-
3888
- $profiles = $gawd_client->get_profiles();
3889
-
3890
- $gawd_user_data = get_option( 'gawd_user_data' );
3891
-
3892
- if ( isset( $_POST['gawd_id'] ) ) {
3893
-
3894
- $gawd_user_data['gawd_id'] = isset( $_POST['gawd_id'] ) ? $_POST['gawd_id'] : '';
3895
-
3896
- foreach ( $gawd_user_data['gawd_profiles'] as $web_property_name => $web_property ) {
3897
-
3898
- foreach ( $web_property as $profile ) {
3899
-
3900
- if ( $profile['id'] == $gawd_user_data['gawd_id'] ) {
3901
-
3902
- $gawd_user_data['web_property_name'] = $web_property_name;
3903
-
3904
- $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
3905
-
3906
- $gawd_user_data['accountId'] = $profile['accountId'];
3907
-
3908
- }
3909
-
3910
- }
3911
-
3912
- }
3913
-
3914
- $gawd_user_data['web_property_name'] = isset( $_POST['web_property_name'] ) ? $_POST['web_property_name'] : '';
3915
-
3916
- update_option( 'gawd_user_data', $gawd_user_data );
3917
-
3918
- }
3919
-
3920
- require_once( 'admin/pages/dashboard_widget.php' );
3921
-
3922
- }
3923
-
3924
-
3925
-
3926
- public function google_analytics_wd_dashboard_widget() {
3927
-
3928
- $gawd_settings = get_option( 'gawd_settings' );
3929
-
3930
- $gawd_backend_roles = isset( $gawd_settings['gawd_backend_roles'] ) ? $gawd_settings['gawd_backend_roles'] : array();
3931
-
3932
- $roles = $this->get_current_user_role();
3933
-
3934
- if ( isset( $gawd_settings['gawd_show_in_dashboard'] ) && $gawd_settings['gawd_show_in_dashboard'] == 'on' ) {
3935
-
3936
- if ( in_array( $roles, $gawd_backend_roles ) || current_user_can( 'manage_options' ) ) {
3937
-
3938
- wp_add_dashboard_widget( 'wd_dashboard_widget', 'WD Google Analytics', array(
3939
-
3940
- $this,
3941
-
3942
- 'wd_dashboard_widget'
3943
-
3944
- ) );
3945
-
3946
- }
3947
-
3948
- }
3949
-
3950
- }
3951
-
3952
-
3953
-
3954
- public function show_data( $params = array() ) {
3955
-
3956
- /* if (isset($_REQUEST['security'])) {
3957
-
3958
- check_ajax_referer('gawd_admin_page_nonce', 'security');
3959
-
3960
- } else {
3961
-
3962
- check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
3963
-
3964
- } */
3965
-
3966
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
3967
-
3968
- $return = true;
3969
-
3970
- if ( $params == '' ) {
3971
-
3972
- $params = $_POST;
3973
-
3974
- $return = false;
3975
-
3976
- }
3977
-
3978
- $gawd_client = GAWD_google_client::get_instance();
3979
-
3980
- $start_date = isset( $params["start_date"] ) && $params["start_date"] != '' ? $params["start_date"] : date( 'Y-m-d', strtotime( '-7 days' ) );
3981
-
3982
- $end_date = isset( $params["end_date"] ) && $params["end_date"] != '' ? $params["end_date"] : date( 'Y-m-d' );
3983
-
3984
- $metric = isset( $params["metric"] ) ? $params["metric"] : 'ga:sessions';
3985
-
3986
- $metric = is_array( $metric ) ? count( $metric ) > 1 ? implode( ",", $metric ) : $metric[0] : $metric;
3987
-
3988
- $dimension = isset( $params["dimension"] ) ? $params["dimension"] : 'date';
3989
-
3990
-
3991
-
3992
- $country_filter = isset( $params["country_filter"] ) ? $params["country_filter"] : '';
3993
-
3994
- $geo_type = isset( $params["geo_type"] ) ? $params["geo_type"] : '';
3995
-
3996
- $filter_type = isset( $params["filter_type"] ) && $params["filter_type"] != '' ? $params["filter_type"] : '';
3997
-
3998
- $custom = isset( $params["custom"] ) && $params["custom"] != '' ? $params["custom"] : '';
3999
-
4000
- $same_dimension = $dimension;
4001
-
4002
-
4003
-
4004
- $dimension = $filter_type != '' && $dimension == 'date' ? $filter_type : $dimension;
4005
-
4006
- if ( $dimension == 'week' || $dimension == 'month' ) {
4007
-
4008
- $same_dimension = $dimension;
4009
-
4010
- }
4011
-
4012
-
4013
-
4014
-
4015
-
4016
- $timezone = isset( $params["timezone"] ) && $params["timezone"] != '' ? $params["timezone"] : 0;
4017
-
4018
- if ( $dimension == 'pagePath' || $dimension == 'PagePath' || $dimension == 'landingPagePath' || $dimension == 'LandingPagePath' ) {
4019
-
4020
- if ( get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date ) ) {
4021
-
4022
- $grid_data = get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date );
4023
-
4024
- } else {
4025
-
4026
- $grid_data = $gawd_client->get_page_data( $dimension, $start_date, $end_date, $timezone );
4027
-
4028
- }
4029
-
4030
- if ( $return ) {
4031
-
4032
- return $grid_data;
4033
-
4034
- }
4035
-
4036
- echo $grid_data;
4037
-
4038
- die();
4039
-
4040
- } elseif ( $dimension == 'goals' ) {
4041
-
4042
- if ( get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date ) ) {
4043
-
4044
- $goal_data = get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date );
4045
-
4046
- } else {
4047
-
4048
- $goal_data = $gawd_client->get_goal_data( 'date', $start_date, $end_date, $timezone, $same_dimension );
4049
-
4050
- }
4051
-
4052
- if ( $return ) {
4053
-
4054
- return $goal_data;
4055
-
4056
- }
4057
-
4058
- echo $goal_data;
4059
-
4060
- die();
4061
-
4062
- } elseif ( ( $dimension == 'region' || $dimension == 'city' ) || ( $dimension == 'Region' || $dimension == 'City' ) ) {
4063
-
4064
- if ( get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $country_filter . '-' . $start_date . '-' . $end_date ) ) {
4065
-
4066
- $chart_data = get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $country_filter . '-' . $start_date . '-' . $end_date );
4067
-
4068
- } else {
4069
-
4070
-
4071
-
4072
- $chart_data = $gawd_client->get_country_data( $metric, $dimension, $start_date, $end_date, $country_filter, $geo_type, $timezone );
4073
-
4074
- }
4075
-
4076
- if ( $return ) {
4077
-
4078
- return $chart_data;
4079
-
4080
- }
4081
-
4082
- echo $chart_data;
4083
-
4084
- die();
4085
-
4086
- } else {
4087
-
4088
- if ( $custom != '' ) {
4089
-
4090
- $chart_data = $gawd_client->get_data( $metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension );
4091
-
4092
- } else {
4093
-
4094
- if ( $dimension == 'siteSpeed' ) {
4095
-
4096
- if ( get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $same_dimension . '_' . $filter_type . '-' . $start_date . '-' . $end_date ) ) {
4097
-
4098
- $chart_data = get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date );
4099
-
4100
- } else {
4101
-
4102
- $chart_data = $gawd_client->get_data( $metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension );
4103
-
4104
- }
4105
-
4106
- if ( $return ) {
4107
-
4108
- return $chart_data;
4109
-
4110
- }
4111
-
4112
- } else {
4113
-
4114
-
4115
-
4116
- /* if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
4117
-
4118
- $chart_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
4119
-
4120
- } */
4121
-
4122
- //else {
4123
-
4124
-
4125
-
4126
- $chart_data = $gawd_client->get_data( $metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension );
4127
-
4128
- //}
4129
-
4130
- if ( $return ) {
4131
-
4132
- return $chart_data;
4133
-
4134
- }
4135
-
4136
- }
4137
-
4138
- }
4139
-
4140
- echo $chart_data;
4141
-
4142
- die();
4143
-
4144
- }
4145
-
4146
- }
4147
-
4148
-
4149
-
4150
- public function show_data_compact() {
4151
-
4152
- check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
4153
-
4154
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
4155
-
4156
- $gawd_client = GAWD_google_client::get_instance();
4157
-
4158
- $start_date = isset( $_POST["start_date"] ) && $_POST["start_date"] != '' ? $_POST["start_date"] : date( 'Y-m-d', strtotime( '-30 days' ) );
4159
-
4160
- $end_date = isset( $_POST["end_date"] ) && $_POST["end_date"] != '' ? $_POST["end_date"] : date( 'Y-m-d' );
4161
-
4162
- $metric = isset( $_POST["metric"] ) ? $_POST["metric"] : 'sessions';
4163
-
4164
- $metric = is_array( $metric ) ? count( $metric ) > 1 ? implode( ",", $metric ) : $metric[0] : 'ga:' . $metric;
4165
-
4166
- $dimension = isset( $_POST["dimension"] ) ? $_POST["dimension"] : 'date';
4167
-
4168
- $timezone = isset( $_POST["timezone"] ) ? $_POST["timezone"] : 0;
4169
-
4170
- if ( get_transient( 'gawd-compact-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date ) ) {
4171
-
4172
- $chart_data = get_transient( 'gawd-compact-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date );
4173
-
4174
- } else {
4175
-
4176
- $chart_data = $gawd_client->get_data_compact( $metric, $dimension, $start_date, $end_date, $timezone );
4177
-
4178
- }
4179
-
4180
- echo $chart_data;
4181
-
4182
- die();
4183
-
4184
- }
4185
-
4186
-
4187
-
4188
- public function show_page_post_data() {
4189
-
4190
- check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
4191
-
4192
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
4193
-
4194
- $gawd_client = GAWD_google_client::get_instance();
4195
-
4196
- $start_date = isset( $_POST["start_date"] ) && $_POST["start_date"] != '' ? $_POST["start_date"] : date( 'Y-m-d', strtotime( '-30 days' ) );
4197
-
4198
- $end_date = isset( $_POST["end_date"] ) && $_POST["end_date"] != '' ? $_POST["end_date"] : date( 'Y-m-d' );
4199
-
4200
- $metric = isset( $_POST["metric"] ) ? $_POST["metric"] : 'ga:sessions';
4201
-
4202
- $metric = is_array( $metric ) ? count( $metric ) > 1 ? implode( ",", $metric ) : $metric[0] : $metric;
4203
-
4204
- $dimension = isset( $_POST["dimension"] ) ? $_POST["dimension"] : 'date';
4205
-
4206
- $timezone = isset( $_POST["timezone"] ) ? $_POST["timezone"] : 0;
4207
-
4208
- $filter = isset( $_POST["filter"] ) ? substr( $_POST["filter"], 1 ) : '';
4209
- $chart = isset( $_POST["chart"] ) ? $_POST["chart"] : '';
4210
-
4211
- $chart_data = get_transient( 'gawd-page-post-' . $gawd_client->get_profile_id() . '-' . $filter . '-' . '-' . $dimension . '-' . $start_date . '-' . $end_date . '-' . $chart );
4212
-
4213
- if ( ! $chart_data ) {
4214
-
4215
- $chart_data = $gawd_client->get_post_page_data( $metric, $dimension, $start_date, $end_date, $filter, $timezone, $chart );
4216
-
4217
- }
4218
-
4219
- echo $chart_data;
4220
-
4221
- die();
4222
-
4223
- }
4224
-
4225
-
4226
-
4227
- public function get_realtime() {
4228
-
4229
- check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
4230
-
4231
- require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
4232
-
4233
- $gawd_client = GAWD_google_client::get_instance();
4234
-
4235
- $chart_data = get_transient( 'gawd-real' . $gawd_client->get_profile_id() );
4236
-
4237
- if ( ! $chart_data ) {
4238
-
4239
- $chart_data = $gawd_client->gawd_realtime_data();
4240
-
4241
- }
4242
-
4243
-
4244
-
4245
- return $chart_data;
4246
-
4247
- }
4248
-
4249
-
4250
-
4251
- public static function add_dashboard_menu() {
4252
-
4253
- $get_custom_reports = get_option( 'gawd_custom_reports' );
4254
-
4255
- if ( ! $get_custom_reports ) {
4256
-
4257
- $custom_report = array();
4258
-
4259
- } else {
4260
-
4261
- foreach ( $get_custom_reports as $name => $report ) {
4262
-
4263
- $custom_report[ 'custom_report_' . $name ] = __( $name, "gawd" );
4264
-
4265
- }
4266
-
4267
- }
4268
-
4269
- $tabs = array(
4270
-
4271
- "general" => array(
4272
-
4273
- "title" => __( "Audience", "gawd" ),
4274
-
4275
- "childs" => array(),
4276
-
4277
- "desc" => "Report of your website audience. Provides details about new and returning users of your website, sessions, bounces, pageviews and session durations."
4278
-
4279
- ),
4280
-
4281
- "realtime" => array(
4282
-
4283
- "title" => __( "Real Time", "gawd" ),
4284
-
4285
- "childs" => array(),
4286
-
4287
- "desc" => "Real Time statistics show the number of active users currently visiting your website pages."
4288
-
4289
- ),
4290
-
4291
- "Pro" => array(
4292
-
4293
- "title" => __( "Available in pro", "gawd" ),
4294
-
4295
- "childs" => array(),
4296
-
4297
- "desc" => ""
4298
-
4299
- ),
4300
-
4301
- "demographics" => array(
4302
-
4303
- "title" => __( "Demographics", "gawd" ),
4304
-
4305
- "childs" => array(
4306
-
4307
- "userGender" => __( "User Gender", "gawd" ),
4308
-
4309
- "userAge" => __( "User Age", "gawd" )
4310
-
4311
- ),
4312
-
4313
- "desc" => "Demographics display tracking statistics of your website users based on their age and gender. "
4314
-
4315
-
4316
-
4317
- ),
4318
-
4319
- "interests" => array(
4320
-
4321
- "title" => __( "Interests", "gawd" ),
4322
-
4323
- "childs" => array(
4324
-
4325
- "inMarket" => __( "In-Market Segment", "gawd" ),
4326
-
4327
- "affinityCategory" => __( "Affinity Category", "gawd" ),
4328
-
4329
- "otherCategory" => __( "Other Category", "gawd" )
4330
-
4331
- ),
4332
-
4333
- "desc" => "Provides tracking information about site users depending on Affinity Categories (e.g. Music Lovers or Mobile Enthusiasts), In-Market Segments (based on online product purchase interests) and Other Categories (most specific identification, for example, tennis lovers among Sports Fans)."
4334
-
4335
- ),
4336
-
4337
- "geo" => array(
4338
-
4339
- "title" => __( "GEO", "gawd" ),
4340
-
4341
- "childs" => array(
4342
-
4343
- "location" => __( "Location", "gawd" ),
4344
-
4345
- "language" => __( "Language", "gawd" )
4346
-
4347
- ),
4348
-
4349
- "desc" => "Geo-identifier report is built from interactions of location (countries, cities) and language of your website users."
4350
-
4351
- ),
4352
-
4353
- "behavior" => array(
4354
-
4355
- "title" => __( "Behavior", "gawd" ),
4356
-
4357
- "childs" => array(
4358
-
4359
- "behaviour" => __( "New vs Returning", "gawd" ),
4360
-
4361
- "engagement" => __( "Engagement", "gawd" )
4362
-
4363
- ),
4364
-
4365
- "desc" => "Compares number of New visitors and Returning users of your website in percents. You can check the duration of sessions with Engagement report."
4366
-
4367
- ),
4368
-
4369
- "technology" => array(
4370
-
4371
- "title" => __( "Technology", "gawd" ),
4372
-
4373
- "childs" => array(
4374
-
4375
- "os" => __( "OS", "gawd" ),
4376
-
4377
- "browser" => __( "Browser", "gawd" )
4378
-
4379
- ),
4380
-
4381
- "desc" => "Identifies tracking of the site based on operating systems and browsers visitors use."
4382
 
4383
- ),
4384
 
4385
- "mobile" => array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4386
 
4387
- "title" => __( "Mobile", "gawd" ),
 
 
 
 
 
 
 
 
4388
 
4389
- "childs" => array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4390
 
4391
- "device_overview" => __( "Overview", "gawd" ),
 
 
 
 
 
 
 
 
 
 
 
4392
 
4393
- "devices" => __( "Devices", "gawd" )
 
 
 
 
 
 
 
 
 
 
 
 
4394
 
4395
- ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4396
 
4397
- "desc" => "Shows statistics of mobile and desktop devices visitors have used while interacting with your website."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4398
 
4399
- ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4400
 
4401
- "custom" => array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4402
 
4403
- "title" => __( "Custom Dimensions", "gawd" ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4404
 
4405
- "childs" => array(),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4406
 
4407
- "desc" => "Set up Custom Dimensions based on Users, Post type, Author, Category, Publication date and Tags in Custom Dimensions page, and view their report in this tab."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4408
 
4409
- ),
 
 
 
 
 
 
 
 
 
 
 
 
 
4410
 
4411
- "trafficSource" => array(
 
 
4412
 
4413
- "title" => __( "Traffic Source", "gawd" ),
4414
 
4415
- "childs" => array(),
4416
 
4417
- "desc" => "Displays overall graph of traffic sources directing to your website."
4418
 
4419
- ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4420
 
4421
- "adWords" => array(
4422
 
4423
- "title" => __( "AdWords", "gawd" ),
 
 
 
 
 
 
 
 
 
 
 
 
4424
 
4425
- "childs" => array(),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4426
 
4427
- "desc" => "If your website is registered on Google AdWords, you can link its Google Analytics to AdWords, and gather relevant tracking information with this report."
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4428
 
4429
- ),
 
 
 
 
 
 
 
 
 
 
4430
 
4431
- /* "pagePath" => array(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4432
 
4433
  "title" => __("Pages", "gawd"),
4434
 
@@ -4437,269 +2280,136 @@ class GAWD {
4437
  "desc" => "Pages report table will provide you information about Bounces, Entrances, Pageviews, Unique Pageviews, time spent on pages, Exits and Average page loading time."
4438
 
4439
  ), */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4440
 
4441
- "siteContent" => array(
4442
-
4443
- "title" => __( "Site Content", "gawd" ),
4444
-
4445
- "childs" => array(
4446
-
4447
- "pagePath" => __( "All Pages", "gawd" ),
4448
-
4449
- "landingPagePath" => __( "Landing Pages", "gawd" ),
4450
-
4451
- ),
4452
-
4453
- "desc" => "Pages report table will provide you information about Bounces, Entrances, Pageviews, Unique Pageviews, time spent on pages, Exits and Average page loading time."
4454
-
4455
- ),
4456
-
4457
- "siteSpeed" => array(
4458
-
4459
- "title" => __( "Site Speed", "gawd" ),
4460
-
4461
- "childs" => array(),
4462
-
4463
- "desc" => "Shows the average load time of your website users experienced during specified date range."
4464
-
4465
- ),
4466
-
4467
- "events" => array(
4468
-
4469
- "title" => __( "Events", "gawd" ),
4470
-
4471
- "childs" => array(
4472
-
4473
- "eventsLabel" => __( "Events by Label", "gawd" ),
4474
-
4475
- "eventsAction" => __( "Events by Action", "gawd" ),
4476
-
4477
- "eventsCategory" => __( "Events by Category", "gawd" )
4478
-
4479
- ),
4480
-
4481
- "desc" => "Displays the report based on Events you set up on Google Analytics of your website. Graphs are built based on Event Labels, Categories and Actions."
4482
-
4483
- ),
4484
-
4485
- "goals" => array(
4486
-
4487
- "title" => __( "Goals", "gawd" ),
4488
-
4489
- "childs" => array(),
4490
-
4491
- "desc" => "Set Goals from Goal Management and review their Google Analytics reports under this tab."
4492
-
4493
- ),
4494
-
4495
- "ecommerce" => array(
4496
-
4497
- "title" => __( "Ecommerce", "gawd" ),
4498
-
4499
- "childs" => array(
4500
-
4501
- "daysToTransaction" => __( "TIme to Purchase", "gawd" ),
4502
-
4503
- "transactionId" => __( "Transaction ID", "gawd" ),
4504
-
4505
- "sales_performance" => __( "Sales Performance", "gawd" ),
4506
-
4507
- "productSku" => __( "Product Sku", "gawd" ),
4508
-
4509
- "productCategory" => __( "Product Category ", "gawd" ),
4510
-
4511
- "productName" => __( "Product Name", "gawd" ),
4512
-
4513
- ),
4514
-
4515
- "desc" => "Check sales statistics of your website identified by revenues, transactions, products and performance."
4516
-
4517
- ),
4518
-
4519
- "adsense" => array(
4520
-
4521
- "title" => __( "AdSense", "gawd" ),
4522
-
4523
- "childs" => array(),
4524
-
4525
- "desc" => "Link your Google Analytics and AdSense accounts from Google Analytics Admin setting and keep track of AdSense tracking under this report."
4526
-
4527
- ),
4528
-
4529
- "customReport" => array(
4530
-
4531
- "title" => __( "Custom Report", "gawd" ),
4532
-
4533
- "childs" => $custom_report,
4534
-
4535
- "desc" => "Add Custom Reports from any metric and dimension in Custom Reports page, and view relevant Google Analytics tracking information in this tab."
4536
-
4537
- ),
4538
-
4539
- );
4540
-
4541
- update_option( 'gawd_menu_items', $tabs );
4542
-
4543
- }
4544
-
4545
-
4546
-
4547
-
4548
-
4549
- public function remove_zoom_message() {
4550
-
4551
- check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
4552
-
4553
- $got_it = isset( $_REQUEST["got_it"] ) ? sanitize_text_field( $_REQUEST["got_it"] ) : '';
4554
-
4555
- if ( $got_it != '' ) {
4556
-
4557
- add_option( 'gawd_zoom_message', $got_it );
4558
-
4559
- }
4560
-
4561
- }
4562
-
4563
-
4564
-
4565
- public function check_property_delete(){
4566
-
4567
- global $gawd_client;
4568
-
4569
- $gawd_client = GAWD_google_client::get_instance();
4570
-
4571
- $accountId = $gawd_client->get_default_accountId();
4572
-
4573
- $webPropertyId = $gawd_client->get_default_webPropertyId();
4574
-
4575
- $screen = get_current_screen();
4576
-
4577
- if ( strpos( $screen->base, 'gawd' ) !== false && $accountId != null && $webPropertyId != null) {
4578
-
4579
- try{
4580
-
4581
- $deleted = $gawd_client->analytics_member->management_webproperties->get($accountId, $webPropertyId);
4582
-
4583
- }
4584
-
4585
- catch (Exception $e){
4586
-
4587
- if(strpos($e->getMessage(), 'not found.') !==false){
4588
-
4589
- echo '<div class="notice notice-error"><p>You have deleted your web-properties with current site url, please <a href="'.admin_url() . 'admin.php?page=gawd_settings">reauthenticate</a>. </p></div>';
4590
-
4591
  }
4592
-
4593
- }
4594
-
4595
  }
4596
 
4597
- }
4598
-
4599
-
4600
-
4601
- /**
4602
-
4603
- * Checks if the protocol is secure.
4604
-
4605
- *
4606
-
4607
- * @return boolean
4608
-
4609
- */
4610
-
4611
- public static function is_ssl() {
4612
-
4613
- if ( isset( $_SERVER['HTTPS'] ) ) {
4614
-
4615
- if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
4616
-
4617
- return true;
4618
-
4619
- }
4620
-
4621
- if ( '1' == $_SERVER['HTTPS'] ) {
4622
-
4623
- return true;
4624
-
4625
- }
4626
-
4627
- } elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
4628
-
4629
- return true;
4630
-
4631
- }
4632
-
4633
-
4634
-
4635
- return false;
4636
-
4637
- }
4638
-
4639
-
4640
-
4641
- /**
4642
-
4643
- * Returns the Singleton instance of this class.
4644
-
4645
- *
4646
-
4647
- * @return GAWD The Singleton instance.
4648
-
4649
- */
4650
-
4651
- public static function get_instance() {
4652
-
4653
- if ( null === self::$instance ) {
4654
-
4655
- self::$instance = new self();
4656
-
4657
- }
4658
-
4659
-
4660
-
4661
- return self::$instance;
4662
-
4663
- }
4664
-
4665
-
4666
-
4667
- /**
4668
-
4669
- * Private clone method to prevent cloning of the instance of the
4670
-
4671
- * Singleton instance.
4672
-
4673
- *
4674
-
4675
- * @return void
4676
-
4677
- */
4678
-
4679
- private function __clone() {
4680
-
4681
-
4682
-
4683
- }
4684
-
4685
-
4686
-
4687
- /**
4688
-
4689
- * Private unserialize method to prevent unserializing of the Singleton
4690
-
4691
- * instance.
4692
-
4693
- *
4694
-
4695
- * @return void
4696
-
4697
- */
4698
-
4699
- private function __wakeup() {
4700
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4701
 
 
 
 
 
 
 
 
 
 
 
 
 
4702
 
4703
- }
 
 
 
 
 
 
 
 
4704
 
 
 
 
 
 
 
 
 
 
4705
  }
1
  <?php
2
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
3
+
4
+ class GAWD
5
+ {
6
+ /**
7
+ * @var GAWD The reference to Singleton instance of this class
8
+ */
9
+ private static $instance;
10
+ private $project_client_id = null;
11
+ private $project_client_secret = null;
12
+ public $redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
13
+
14
+ /**
15
+ * Protected constructor to prevent creating a new instance of the
16
+ * Singleton via the `new` operator from outside of this class.
17
+ */
18
+ protected function __construct()
19
+ {
20
+ if (isset($_POST["reset_data"]) && $_POST["reset_data"] != '') {
21
+ $this->reset_user_data();
22
+ }
23
+ add_action('admin_menu', array($this, 'gawd_check_id'), 1);
24
+ add_action('admin_notices', array($this, 'upgrade_pro'));
25
+ add_action('admin_menu', array($this, 'gawd_add_menu'), 19);
26
+ add_action('admin_enqueue_scripts', array($this, 'gawd_enqueue_scripts'));
27
+ add_action('wp_ajax_gawd_auth', array($this, 'gawd_auth'));
28
+ add_action('wp_ajax_create_pdf_file', array($this, 'create_pdf_file'));
29
+ add_action('wp_ajax_create_csv_file', array($this, 'create_csv_file'));
30
+ add_action('wp_ajax_show_data', array($this, 'show_data'));
31
+ add_action('wp_ajax_remove_zoom_message', array($this, 'remove_zoom_message'));
32
+ add_action('wp_ajax_show_page_post_data', array($this, 'show_page_post_data'));
33
+ add_action('wp_ajax_show_data_compact', array($this, 'show_data_compact'));
34
+ add_action('wp_ajax_get_realtime', array($this, 'get_realtime'));
35
+ add_action('wp_dashboard_setup', array($this, 'google_analytics_wd_dashboard_widget'));
36
+ add_action('admin_menu', array($this, 'overview_date_meta'));
37
+ add_filter('cron_schedules', array($this, 'gawd_my_schedule'));
38
+ add_action('admin_init', array($this, 'gawd_export'));
39
+ add_action('gawd_pushover_daily', array($this, 'gawd_pushover_daily'));
40
+ add_action('gawd_pushover_gawd_weekly', array($this, 'gawd_pushover_weekly'));
41
+ add_action('gawd_pushover_gawd_monthly', array($this, 'gawd_pushover_monthly'));
42
+ add_action('gawd_alert_daily', array($this, 'gawd_alert_daily'));
43
+ add_action('gawd_alert_gawd_monthly', array($this, 'gawd_alert_monthly'));
44
+ add_action('gawd_alert_gawd_weekly', array($this, 'gawd_alert_weekly'));
45
+ add_action('gawd_email_daily', array($this, 'gawd_daily_email'), 0);
46
+ add_action('gawd_email_gawd_weekly', array($this, 'gawd_weekly_email'));
47
+ add_action('gawd_email_gawd_monthly', array($this, 'gawd_monthly_email'));
48
+ //add_action('init', array($this, 'gawd_daily_email'));
49
+ add_action('wp_head', array($this, 'gawd_tracking_code'), 99);
50
+ include_once(GAWD_DIR . '/include/gawd-notices-class.php');
51
+ add_action('admin_notices', array($this, 'check_property_delete'), 9999);
52
+ $gawd_settings = get_option('gawd_settings');
53
+ $gawd_user_data = get_option('gawd_user_data');
54
+ $gawd_post_page_roles = isset($gawd_settings['gawd_post_page_roles']) ? $gawd_settings['gawd_post_page_roles'] : array();
55
+ $roles = $this->get_current_user_role();
56
+ if ((isset($gawd_settings['gawd_tracking_enable']) && $gawd_settings['gawd_tracking_enable'] == 'on') && (isset($gawd_settings['post_page_chart']) && $gawd_settings['post_page_chart'] != '') && (in_array($roles, $gawd_post_page_roles) || current_user_can('manage_options')) && ( isset( $gawd_user_data['refresh_token'] ) && ( $gawd_user_data['refresh_token'] != '' ) ) && isset($gawd_user_data['default_webPropertyId'])) {
57
+ add_filter('manage_posts_columns', array($this, 'gawd_add_columns'));
58
+ // Populate custom column in Posts List
59
+ add_action('manage_posts_custom_column', array($this, 'gawd_add_icons'), 10, 2);
60
+ // Add custom column in Pages List
61
+ add_filter('manage_pages_columns', array($this, 'gawd_add_columns'));
62
+ // Populate custom column in Pages List
63
+ add_action('manage_pages_custom_column', array($this, 'gawd_add_icons'), 10, 2);
64
+ add_action('load-post.php', array($this, 'gawd_add_custom_box'));
65
+ }
66
+ $gawd_frontend_roles = isset($gawd_settings['gawd_frontend_roles']) ? $gawd_settings['gawd_frontend_roles'] : array();
67
+ if ((isset($gawd_settings['gawd_tracking_enable']) && $gawd_settings['gawd_tracking_enable'] == 'on') && (in_array($roles, $gawd_frontend_roles) || current_user_can('manage_options')) && ( isset( $gawd_user_data['refresh_token'] ) && ( $gawd_user_data['refresh_token'] != '' ) ) && isset($gawd_user_data['default_webPropertyId'])) {
68
+ add_action('wp_enqueue_scripts', array($this, 'gawd_front_scripts'));
69
+ add_action('admin_bar_menu', array($this, 'report_adminbar'), 999);
70
+ }
71
+ $this->update_credentials();
72
+ $credentials = get_option('gawd_credentials');
73
+ if (is_array($credentials)) {
74
+ $this->set_project_client_id($credentials['project_id']);
75
+ $this->set_project_client_secret($credentials['project_secret']);
76
+ } else {
77
+ //send error
78
+ return;
79
+ }
80
+ }
81
 
82
+ function get_current_user_role()
83
+ {
84
+ global $wp_roles;
85
+ if (is_user_logged_in()) {
86
+ $current_user = wp_get_current_user();
87
+ $roles = $current_user->roles;
88
+ $role = array_shift($roles);
89
+ return $role;
90
+ } else {
91
+ return "";
92
+ }
93
+ }
94
 
95
+ function report_adminbar($wp_admin_bar)
96
+ {
97
+ /* @formatter:off */
98
+ $gawd_settings = get_option('gawd_settings');
99
+ $gawd_frontend_roles = isset($gawd_settings['gawd_frontend_roles']) ? $gawd_settings['gawd_frontend_roles'] : array();
100
+ $roles = $this->get_current_user_role();
101
+ if (((in_array($roles, $gawd_frontend_roles) || current_user_can('manage_options')) && !is_admin()) && $gawd_settings['post_page_chart'] != '') {
102
+ $id = get_the_ID();
103
+ $uri_parts = get_post($id);
104
+ $uri = '/' . $uri_parts->post_name;
105
+ $filter = rawurlencode(rawurldecode($uri));
106
+ $args = array(
107
+ 'id' => 'gawd',
108
+ 'title' => '<span data-url="' . $filter . '" class="ab-icon"></span><span class="">' . __("Analytics WD", 'gawd') . '</span>',
109
+ 'href' => '#1',
110
+ );
111
+ /* @formatter:on */
112
+ $wp_admin_bar->add_node($args);
113
+ }
114
+ }
115
 
116
+ public function update_credentials()
117
+ {
118
+ //check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
119
+ if ($_POST) {
120
+ $gawd_own_project = isset($_POST['gawd_own_project']) ? $_POST['gawd_own_project'] : '';
121
+ $gawd_own_client_id = isset($_POST['gawd_own_client_id']) ? $_POST['gawd_own_client_id'] : '';
122
+ $gawd_own_client_secret = isset($_POST['gawd_own_client_secret']) ? $_POST['gawd_own_client_secret'] : '';
123
+ $gawd_credentials['project_id'] = $gawd_own_client_id;
124
+ $gawd_credentials['project_secret'] = $gawd_own_client_secret;
125
+ if ($gawd_own_project && $gawd_own_client_id != '' && $gawd_own_client_secret != '') {
126
+ update_option('gawd_credentials', $gawd_credentials);
127
+ delete_option('gawd_user_data');
128
+ add_option('gawd_own_project', 1);
129
+ }
130
+ }
131
+ }
132
 
133
+ public function set_project_client_id($id)
134
+ {
135
+ $this->project_client_id = $id;
136
+ }
137
 
138
+ public function get_project_client_id()
139
+ {
140
+ return $this->project_client_id;
141
+ }
142
 
143
+ public function set_project_client_secret($secret)
144
+ {
145
+ $this->project_client_secret = $secret;
146
+ }
147
 
148
+ public function get_project_client_secret()
149
+ {
150
+ return $this->project_client_secret;
151
+ }
152
 
153
+ function gawd_check_id()
154
+ {
155
+ global $gawd_redirect_to_settings;
156
+ $current_page = isset($_GET['page']) ? $_GET['page'] : "";
157
+ if (strpos($current_page, 'gawd') !== false) {
158
+ $gawd_user_data = get_option('gawd_user_data');
159
+ if (!isset($gawd_user_data['refresh_token']) || ($gawd_user_data['refresh_token'] == '')) {
160
+ update_option('gawd_redirect_to_settings', 'yes');
161
+ } else {
162
+ update_option('gawd_redirect_to_settings', 'no');
163
+ }
164
+ }
165
+ $gawd_redirect_to_settings = get_option('gawd_redirect_to_settings');
166
+ }
167
 
168
+ function gawd_add_custom_box()
169
+ {
170
+ $screens = array('post', 'page');
171
+ foreach ($screens as $screen) {
172
+ add_meta_box('gawd_page_post_meta', 'Sessions in month', array(
173
+ $this,
174
+ 'gawd_add_custom_box_callback'
175
+ ), $screen, 'normal');
176
+ }
177
+ }
178
 
179
+ function gawd_add_custom_box_callback()
180
+ {
181
+ require_once('admin/post_page_view.php');
182
+ }
183
 
184
+ public function gawd_add_icons($column, $id)
185
+ {
186
+ if ($column != 'gawd_stats') {
187
+ return;
188
+ }
189
+ $uri_parts = get_post($id);
190
+ $uri = '/' . $uri_parts->post_name;
191
+ $filter = rawurlencode(rawurldecode($uri));
192
+ echo '<a id="gawd-' . $id . '" class="gawd_page_post_stats" title="' . get_the_title($id) . '" href="#' . $filter . '"><img src="' . GAWD_URL . '/assets/back_logo.png"</a>';
193
+ }
194
 
195
+ public function gawd_add_columns($columns)
196
+ {
197
+ return array_merge($columns, array('gawd_stats' => __('Analytics WD', 'gawd')));
198
+ }
199
 
200
+ public static function gawd_roles($access_level, $tracking = false)
201
+ {
202
+ if (is_user_logged_in() && isset($access_level)) {
203
+ $current_user = wp_get_current_user();
204
+ $roles = (array)$current_user->roles;
205
+ if ((current_user_can('manage_options')) && !$tracking) {
206
+ return true;
207
+ }
208
+ if (count(array_intersect($roles, $access_level)) > 0) {
209
+ return true;
210
+ } else {
211
+ return false;
212
+ }
213
+ }
214
+ return false;
215
+ }
216
 
217
+ public function gawd_tracking_code()
218
+ {
219
+ $gawd_user_data = get_option('gawd_user_data');
220
+ if (isset($gawd_user_data['default_webPropertyId']) && ($gawd_user_data['default_webPropertyId'])) {
221
+ global $gawd_client;
222
+ $gawd_client = GAWD_google_client::get_instance();
223
+ require_once(GAWD_DIR . '/admin/tracking.php');
224
+ }
225
+ }
226
 
227
+ public function create_pdf_file($ajax = true, $data = null, $dimension = null, $start_date = null, $end_date = null, $metric_compare_recc = null, $metric_recc = null)
228
+ {
229
+ $first_data = isset($_REQUEST["first_data"]) ? sanitize_text_field($_REQUEST["first_data"]) : '';
230
+ $_data_compare = isset($_REQUEST["_data_compare"]) ? ($_REQUEST["_data_compare"]) : '';
231
+ if ($ajax == true) {
232
+ $export_type = isset($_REQUEST["export_type"]) ? sanitize_text_field($_REQUEST["export_type"]) : '';
233
+ if ($export_type != 'pdf') {
234
+ return;
235
+ }
236
+ $report_type = isset($_REQUEST["report_type"]) ? sanitize_text_field($_REQUEST["report_type"]) : '';
237
+ if ($report_type !== 'alert') {
238
+ return;
239
+ }
240
+ }
241
+ include_once GAWD_DIR . '/include/gawd_pdf_file.php';
242
+ $file = new GAWD_PDF_FILE();
243
+ /*
244
 
245
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
246
 
247
+ $this->gawd_google_client = GAWD_google_client::get_instance();
248
 
249
+ */
250
+ $file->get_request_data($this, $ajax, $data, $dimension, $start_date, $end_date, $metric_compare_recc, $metric_recc);
251
+ $file->sort_data();
252
+ if ($first_data != '') {
253
+ $file->create_file('pages');
254
+ } elseif (($_data_compare) != '') {
255
+ $file->create_file('compare');
256
+ } else {
257
+ $file->create_file(true);
258
+ }
259
+ if ($ajax == true) {
260
+ die();
261
+ } else {
262
+ return $file->file_dir;
263
+ }
264
+ }
265
 
266
+ public function create_csv_file($ajax = true, $data = null, $dimension = null, $start_date = null, $end_date = null, $metric_compare_recc = null, $metric_recc = null)
267
+ {
268
+ if ($ajax == true) {
269
+ $export_type = isset($_REQUEST["export_type"]) ? sanitize_text_field($_REQUEST["export_type"]) : '';
270
+ if ($export_type != 'csv') {
271
+ return;
272
+ }
273
+ $report_type = isset($_REQUEST["report_type"]) ? sanitize_text_field($_REQUEST["report_type"]) : '';
274
+ if ($report_type !== 'alert') {
275
+ return;
276
+ }
277
+ }
278
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
279
+ $this->gawd_google_client = GAWD_google_client::get_instance();
280
+ $first_data = isset($_REQUEST["first_data"]) ? sanitize_text_field($_REQUEST["first_data"]) : '';
281
+ include_once GAWD_DIR . '/include/gawd_csv_file.php';
282
+ $file = new GAWD_CSV_FILE();
283
+ $file->get_request_data($this, $ajax, $data, $dimension, $start_date, $end_date, $metric_compare_recc, $metric_recc);
284
+ $file->sort_data();
285
+ //$file->get_request_data($this);
286
+ $file->sort_data();
287
+ if ($first_data != '') {
288
+ $file->create_file(false);
289
+ } else {
290
+ $file->create_file();
291
+ }
292
+ if ($ajax == true) {
293
+ die();
294
+ } else {
295
+ return $file->file_dir;
296
+ }
297
+ }
298
 
299
+ public static function get_domain($domain)
300
+ {
301
+ $root = explode('/', $domain);
302
+ $ret_domain = str_ireplace('www', '', isset($root[2]) ? $root[2] : $domain);
303
+ return $ret_domain;
304
+ }
305
 
306
+ public static function error_message($type, $message)
307
+ {
308
+ echo '<div style="width:99%"><div class="' . $type . '"><p><strong>' . $message . '</strong></p></div></div>';
309
+ }
310
 
311
+ public function gawd_export()
312
+ {
313
+ if (!isset($_REQUEST['action']) || (isset($_REQUEST['action']) && $_REQUEST['action'] !== 'gawd_export')) {
314
+ return;
315
+ }
316
+ $export_type = isset($_REQUEST["export_type"]) ? sanitize_text_field($_REQUEST["export_type"]) : '';
317
+ if ($export_type != 'pdf' && $export_type != 'csv') {
318
+ return;
319
+ }
320
+ $report_type = isset($_REQUEST["report_type"]) ? sanitize_text_field($_REQUEST["report_type"]) : '';
321
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
322
+ $this->gawd_google_client = GAWD_google_client::get_instance();
323
+ if ($export_type == 'pdf') {
324
+ include_once GAWD_DIR . '/include/gawd_pdf_file.php';
325
+ $file = new GAWD_PDF_FILE();
326
+ } else {
327
+ include_once GAWD_DIR . '/include/gawd_csv_file.php';
328
+ $file = new GAWD_CSV_FILE();
329
+ }
330
+ if ($report_type == 'alert') {
331
+ if ($export_type == 'pdf') {
332
+ $file->export_file();
333
+ } else {
334
+ $file->export_file();
335
+ }
336
+ } else {
337
+ $metric = isset($_REQUEST["gawd_metric"]) ? sanitize_text_field($_REQUEST["gawd_metric"]) : '';
338
+ $_data_compare = isset($_REQUEST["_data_compare"]) ? ($_REQUEST["_data_compare"]) : '';
339
+ $first_data = isset($_REQUEST["first_data"]) ? ($_REQUEST["first_data"]) : '';
340
+ $view_id = isset($_REQUEST["view_id"]) ? sanitize_text_field($_REQUEST["view_id"]) : '';
341
+ $metric_compare = isset($_REQUEST["gawd_metric_compare"]) ? sanitize_text_field($_REQUEST["gawd_metric_compare"]) : '';
342
+ $dimension = isset($_REQUEST["gawd_dimension"]) ? sanitize_text_field($_REQUEST["gawd_dimension"]) : '';
343
+ $tab_name = isset($_REQUEST["tab_name"]) ? sanitize_text_field($_REQUEST["tab_name"]) : '';
344
+ $img = isset($_REQUEST["img"]) ? sanitize_text_field($_REQUEST["img"]) : '';
345
+ $gawd_email_subject = isset($_REQUEST["gawd_email_subject"]) ? sanitize_text_field($_REQUEST["gawd_email_subject"]) : '';
346
+ $gawd_email_body = isset($_REQUEST["gawd_email_body"]) && $_REQUEST["gawd_email_body"] != '' ? sanitize_text_field($_REQUEST["gawd_email_body"]) : ' ';
347
+ $email_from = isset($_REQUEST["gawd_email_from"]) ? sanitize_email($_REQUEST["gawd_email_from"]) : '';
348
+ $email_to = isset($_REQUEST["gawd_email_to"]) ? sanitize_email($_REQUEST["gawd_email_to"]) : '';
349
+ $email_period = isset($_REQUEST["gawd_email_period"]) ? sanitize_text_field($_REQUEST["gawd_email_period"]) : '';
350
+ $week_day = isset($_REQUEST["gawd_email_week_day"]) ? sanitize_text_field($_REQUEST["gawd_email_week_day"]) : '';
351
+ $month_day = isset($_REQUEST["gawd_email_month_day"]) ? sanitize_text_field($_REQUEST["gawd_email_month_day"]) : '';
352
+ $email_time = isset($_REQUEST["email_time"]) ? sanitize_text_field($_REQUEST["email_time"]) : '';
353
+ $emails = array();
354
+ $invalid_email = false;
355
+ $email_to = explode(',', $email_to);
356
+ foreach ($email_to as $email) {
357
+ if (is_email($email) == false) {
358
+ $emails = $email;
359
+ }
360
+ }
361
+ if (count($emails) > 0) {
362
+ $invalid_email = true;
363
+ }
364
+ if (($invalid_email != true) && is_email($email_from) && $gawd_email_subject != '') {
365
+ if ($email_period == "once") {
366
+ $file->get_request_data($this);
367
+ $file->sort_data();
368
+ if ($export_type == 'csv') {
369
+ if ($first_data != '') {
370
+ $file->create_file(false);
371
+ } else {
372
+ $file->create_file();
373
+ }
374
+ } else {
375
+ if ($first_data != '') {
376
+ $file->create_file('pages');
377
+ } elseif (($_data_compare) != '') {
378
+ $file->create_file('compare');
379
+ } else {
380
+ $file->create_file(false);
381
+ }
382
+ }
383
+ $attachment = $file->file_dir;
384
+ if ($report_type == 'email') {
385
+ $headers = 'From: <' . $email_from . '>';
386
+ wp_mail($email_to, $gawd_email_subject, $gawd_email_body, $headers, $attachment);
387
+ }
388
+ echo json_encode(array('status' => 'success', 'msg' => 'Email successfuly sent'));
389
+ } else {
390
+ if ($email_period == 'gawd_weekly') {
391
+ $period_day = $week_day;
392
+ $timestamp = strtotime('this ' . $period_day . ' ' . $email_time);
393
+ } elseif ($email_period == 'gawd_monthly') {
394
+ $period_day = $month_day;
395
+ $timestamp = strtotime(date('Y-m-' . $period_day . ' ' . $email_time));
396
+ } else {
397
+ $period_day = '';
398
+ $timestamp = strtotime(date('Y-m-d ' . $email_time));
399
+ }
400
+ $saved_email = get_option('gawd_email');
401
+ if ($saved_email) {
402
+ $gawd_email_options = array(
403
+ 'name' => $gawd_email_subject,
404
+ 'period' => $email_period,
405
+ 'metric' => $metric,
406
+ 'metric_compare' => $metric_compare,
407
+ 'dimension' => $dimension,
408
+ 'creation_date' => date('Y-m-d') . ' ' . $email_time,
409
+ 'emails' => $email_to,
410
+ 'email_from' => $email_from,
411
+ 'email_subject' => $gawd_email_subject,
412
+ 'email_body' => $gawd_email_body,
413
+ 'period_day' => $period_day,
414
+ 'period_time' => $email_time,
415
+ 'img' => $img,
416
+ 'tab_name' => $tab_name,
417
+ 'view_id' => $view_id,
418
+ 'export_type' => $export_type
419
+ );
420
+ $saved_email[] = $gawd_email_options;
421
+ update_option('gawd_email', $saved_email);
422
+ } else {
423
+ $gawd_email_options = array(
424
+ 0 => array(
425
+ 'name' => $gawd_email_subject,
426
+ 'period' => $email_period,
427
+ 'metric' => $metric,
428
+ 'metric_compare' => $metric_compare,
429
+ 'dimension' => $dimension,
430
+ 'creation_date' => date('Y-m-d') . ' ' . $email_time,
431
+ 'emails' => $email_to,
432
+ 'email_from' => $email_from,
433
+ 'email_subject' => $gawd_email_subject,
434
+ 'email_body' => $gawd_email_body,
435
+ 'period_day' => $period_day,
436
+ 'period_time' => $email_time,
437
+ 'img' => $img,
438
+ 'tab_name' => $tab_name,
439
+ 'view_id' => $view_id,
440
+ 'export_type' => $export_type
441
+ )
442
+ );
443
+ update_option('gawd_email', $gawd_email_options);
444
+ }
445
+ $saved_email = get_option('gawd_email');
446
+ if ($saved_email) {
447
+ foreach ($saved_email as $email) {
448
+ if (!wp_next_scheduled('gawd_email_' . $email['period'])) {
449
+ wp_schedule_event($timestamp, $email['period'], 'gawd_email_' . $email['period']);
450
+ }
451
+ }
452
+ }
453
+ $success_message = 'Email successfuly Scheduled </br> Go to <a href="' . admin_url() . 'admin.php?page=gawd_settings#gawd_emails_tab">Settings page</a> to delete scheduled e-mails.';
454
+ echo json_encode(array('status' => 'success', 'msg' => $success_message));
455
+ }
456
+ die;
457
+ } else {
458
+ if ($invalid_email == true) {
459
+ echo json_encode('Invalid email');
460
+ die;
461
+ } else if ($gawd_email_subject == '') {
462
+ echo json_encode("Can't send email with empty subject");
463
+ die;
464
+ }
465
+ }
466
+ }
467
+ }
468
 
469
+ public function overview_date_meta($screen = null, $context = 'advanced')
470
+ {
471
+ //righ side wide meta..
472
+ $orintation = wp_is_mobile() ? 'side' : 'normal';
473
+ add_meta_box('gawd-real-time', __('Real Time', 'gawd'), array(
474
+ $this,
475
+ 'gawd_real_time'
476
+ ), 'gawd_analytics', 'side', 'high');
477
+ add_meta_box('gawd-date-meta', __('Audience', 'gawd'), array(
478
+ $this,
479
+ 'gawd_date_box'
480
+ ), 'gawd_analytics', $orintation, null);
481
+ add_meta_box('gawd-country-box', __('Location', 'gawd'), array(
482
+ $this,
483
+ 'gawd_country_box'
484
+ ), 'gawd_analytics', $orintation, null);
485
+ //left side thin meta.
486
+ add_meta_box('gawd-visitors-meta', __('Visitors', 'gawd'), array(
487
+ $this,
488
+ 'gawd_visitors'
489
+ ), 'gawd_analytics', 'side', null);
490
+ add_meta_box('gawd-browser-meta', __('Browsers', 'gawd'), array(
491
+ $this,
492
+ 'gawd_browser'
493
+ ), 'gawd_analytics', 'side', null);
494
+ }
495
 
496
+ public function gawd_date_box()
497
+ {
498
+ require_once('admin/pages/date.php');
499
+ }
500
 
501
+ public function gawd_country_box()
502
+ {
503
+ require_once('admin/pages/location.php');
504
+ }
505
 
506
+ public function gawd_real_time()
507
+ {
508
+ require_once('admin/pages/real_time.php');
509
+ }
510
 
511
+ public function gawd_visitors()
512
+ {
513
+ require_once('admin/pages/visitors.php');
514
+ }
515
 
516
+ public function gawd_browser()
517
+ {
518
+ require_once('admin/pages/browser.php');
519
+ }
520
 
521
+ /**
522
+ * Activation function needed for the activation hook.
523
+ */
524
+ public static function activate()
525
+ {
526
+ $credentials['project_id'] = '115052745574-5vbr7tci4hjkr9clkflmnpto5jisgstg.apps.googleusercontent.com';
527
+ $credentials['project_secret'] = 'wtNiu3c_bA_g7res6chV0Trt';
528
+ if (!get_option('gawd_credentials')) {
529
+ update_option('gawd_credentials', $credentials);
530
+ }
531
+ $gawd_settings = get_option('gawd_settings');
532
+ if ($gawd_settings === false) {
533
+ self::gawd_settings_defaults();
534
+ } elseif ($gawd_settings && !isset($gawd_settings['show_report_page'])) {
535
+ $gawd_settings['show_report_page'] = 'on';
536
+ update_option('gawd_settings', $gawd_settings);
537
+ }
538
+ self::add_dashboard_menu();
539
+ }
540
 
541
+ /**
542
+ * Deactivation function needed for the deactivation hook.
543
+ */
544
+ public static function deactivate()
545
+ {
546
+ }
547
 
548
+ /**
549
+ * Enqueues the required styles and scripts, localizes some js variables.
550
+ */
551
+ public function gawd_front_scripts()
552
+ {
553
+ if (is_user_logged_in()) {
554
+ wp_enqueue_style('admin_css', GAWD_URL . '/inc/css/gawd_admin.css', false, GAWD_VERSION);
555
+ wp_enqueue_script('gawd_amcharts', GAWD_URL . '/inc/js/amcharts.js', false, GAWD_VERSION);
556
+ wp_enqueue_script('gawd_pie', GAWD_URL . '/inc/js/pie.js', false, GAWD_VERSION);
557
+ wp_enqueue_script('gawd_serial', GAWD_URL . '/inc/js/serial.js', false, GAWD_VERSION);
558
+ wp_enqueue_script('gawd_light_theme', GAWD_URL . '/inc/js/light.js', array('jquery'), GAWD_VERSION);
559
+ wp_enqueue_script('gawd_dataloader', GAWD_URL . '/inc/js/dataloader.min.js', array('jquery'), GAWD_VERSION);
560
+ wp_enqueue_script('gawd_front_js', GAWD_URL . '/inc/js/gawd_front.js', array('jquery'), GAWD_VERSION);
561
+ wp_localize_script('gawd_front_js', 'gawd_front', array(
562
+ 'ajaxurl' => admin_url('admin-ajax.php'),
563
+ 'ajaxnonce' => wp_create_nonce('gawd_admin_page_nonce'),
564
+ 'gawd_plugin_url' => GAWD_URL,
565
+ 'date_30' => date('Y-m-d', strtotime('-31 day')) . '/-/' . date('Y-m-d', strtotime('-1 day')),
566
+ 'date_7' => date('Y-m-d', strtotime('-8 day')) . '/-/' . date('Y-m-d', strtotime('-1 day')),
567
+ 'date_last_week' => date('Y-m-d', strtotime('last week -1day')) . '/-/' . date('Y-m-d', strtotime('last week +5day')),
568
+ 'date_last_month' => date('Y-m-01', strtotime('last month')) . '/-/' . date('Y-m-t', strtotime('last month')),
569
+ 'date_this_month' => date('Y-m-01') . '/-/' . date('Y-m-d'),
570
+ 'date_today' => date('Y-m-d') . '/-/' . date('Y-m-d'),
571
+ 'date_yesterday' => date('Y-m-d', strtotime('-1 day')) . '/-/' . date('Y-m-d', strtotime('-1 day')),
572
+ 'wp_admin_url' => admin_url(),
573
+ 'exportUrl' => add_query_arg(array('action' => 'gawd_export'), admin_url('admin-ajax.php'))
574
+ ));
575
+ }
576
+ }
577
 
578
+ public function gawd_enqueue_scripts()
579
+ {
580
+ $options = get_option('gawd_settings');
581
+ $show_report_page = (isset($options['show_report_page']) && $options['show_report_page'] != '') ? $options['show_report_page'] : 'on';
582
+ $default_date = (isset($options['default_date']) && $options['default_date'] != '') ? $options['default_date'] : 'last_30days';
583
+ $default_date_format = (isset($options['default_date_format']) && $options['default_date_format'] != '') ? $options['default_date_format'] : 'ymd_with_week';
584
+ $enable_hover_tooltip = (isset($options['enable_hover_tooltip']) && $options['enable_hover_tooltip'] != '') ? $options['enable_hover_tooltip'] : '';
585
+ $screen = get_current_screen();
586
+ if (strpos($screen->base, 'gawd') !== false || strpos($screen->post_type, 'page') !== false || strpos($screen->post_type, 'post') !== false || strpos($screen->base, 'dashboard') !== false || strpos($screen->base, 'edit') !== false) {
587
+ wp_enqueue_script('common');
588
+ wp_enqueue_script('wp-lists');
589
+ wp_enqueue_script('postbox');
590
+ wp_enqueue_script('jquery-ui-tooltip');
591
+ wp_enqueue_script('gawd_paging', GAWD_URL . '/inc/js/paging.js', false, GAWD_VERSION);
592
+ wp_enqueue_script('jquery.cookie', GAWD_URL . '/inc/js/jquery.cookie.js', false, GAWD_VERSION);
593
+ wp_enqueue_style('timepicker_css', GAWD_URL . '/inc/css/jquery.timepicker.css', false, GAWD_VERSION);
594
+ wp_enqueue_style('admin_css', GAWD_URL . '/inc/css/gawd_admin.css', false, GAWD_VERSION);
595
+ wp_enqueue_style('gawd_licensing', GAWD_URL . '/inc/css/gawd_licensing.css', false, GAWD_VERSION);
596
+ wp_enqueue_style('gawd_featured', GAWD_URL . '/featured/style.css', array(), GAWD_VERSION);
597
+ wp_enqueue_style('font_awesome', GAWD_URL . '/inc/css/font_awesome.css', false, GAWD_VERSION);
598
+ wp_enqueue_style('jquery-ui.css', GAWD_URL . '/inc/css/jquery-ui.css', false, GAWD_VERSION);
599
+ wp_enqueue_style('gawd_bootstrap', GAWD_URL . '/inc/css/bootstrap.css', false, GAWD_VERSION);
600
+ wp_enqueue_style('gawd_bootstrap-chosen', GAWD_URL . '/inc/css/bootstrap-chosen.css', false, GAWD_VERSION);
601
+ wp_enqueue_style('gawd_bootstrap-select', GAWD_URL . '/inc/css/bootstrap-select.css', false, GAWD_VERSION);
602
+ wp_enqueue_style('gawd_datepicker', GAWD_URL . '/inc/css/daterangepicker.css', false, GAWD_VERSION);
603
+ wp_enqueue_style('ui.jqgrid.css', GAWD_URL . '/inc/css/ui.jqgrid.css', false, GAWD_VERSION);
604
+ wp_enqueue_script('gawd_moment', GAWD_URL . '/inc/js/moment.min.js', false, GAWD_VERSION);
605
+ wp_enqueue_script('gawd_daterangepicker', GAWD_URL . '/inc/js/daterangepicker.js', false, GAWD_VERSION);
606
+ wp_enqueue_script('gawd_amcharts', GAWD_URL . '/inc/js/amcharts.js', false, GAWD_VERSION);
607
+ wp_enqueue_script('gawd_pie', GAWD_URL . '/inc/js/pie.js', false, GAWD_VERSION);
608
+ wp_enqueue_script('gawd_serial', GAWD_URL . '/inc/js/serial.js', false, GAWD_VERSION);
609
+ /*Map*/
610
+ wp_enqueue_script('gawd_ammap', GAWD_URL . '/inc/js/ammap.js', false, GAWD_VERSION);
611
+ wp_enqueue_script('gawd_worldLow', GAWD_URL . '/inc/js/worldLow.js', false, GAWD_VERSION);
612
+ wp_enqueue_script('gawd_map_chart', GAWD_URL . '/inc/js/gawd_map_chart.js', false, GAWD_VERSION);
613
+ /*End Map*/
614
+ wp_enqueue_script('gawd_light_theme', GAWD_URL . '/inc/js/light.js', array('jquery'), GAWD_VERSION);
615
+ wp_enqueue_script('gawd_dataloader', GAWD_URL . '/inc/js/dataloader.min.js', array('jquery'), GAWD_VERSION);
616
+ wp_enqueue_script('rgbcolor.js', GAWD_URL . '/inc/js/rgbcolor.js', array('jquery'), GAWD_VERSION);
617
+ wp_enqueue_script('StackBlur.js', GAWD_URL . '/inc/js/StackBlur.js', array('jquery'), GAWD_VERSION);
618
+ wp_enqueue_script('canvg.js', GAWD_URL . '/inc/js/canvg.js', array('jquery'), GAWD_VERSION);
619
+ wp_enqueue_script('gawd_tables', GAWD_URL . '/inc/js/loader.js', array('jquery'), GAWD_VERSION);
620
+ wp_enqueue_script('gawd_grid', GAWD_URL . '/inc/js/jquery.jqGrid.min.js', array('jquery'), GAWD_VERSION);
621
+ wp_enqueue_script('gawd_grid_locale', GAWD_URL . '/inc/js/grid.locale-en.js', array('jquery'), GAWD_VERSION);
622
+ wp_enqueue_script('date-js', GAWD_URL . '/inc/js/date.js', array('jquery'), GAWD_VERSION);
623
+ wp_enqueue_script('timepicker_js', GAWD_URL . '/inc/js/jquery.timepicker.min.js', array('jquery'), GAWD_VERSION);
624
+ wp_enqueue_script('admin_js', GAWD_URL . '/inc/js/gawd_admin.js', array('jquery'), GAWD_VERSION);
625
+ wp_enqueue_script('chosen.jquery.js', GAWD_URL . '/inc/js/chosen.jquery.js', array('jquery'), GAWD_VERSION);
626
+ wp_enqueue_script('bootstrap_js', GAWD_URL . '/inc/js/bootstrap_js.js', array('jquery'), GAWD_VERSION);
627
+ wp_enqueue_script('bootstrap-select', GAWD_URL . '/inc/js/bootstrap-select.js', array('jquery'), GAWD_VERSION);
628
+ wp_enqueue_script('highlight_js', GAWD_URL . '/inc/js/js_highlight.js', array('jquery'), GAWD_VERSION);
629
+ wp_enqueue_script('settings_js', GAWD_URL . '/inc/js/gawd_settings.js', array('jquery'), GAWD_VERSION);
630
+ wp_enqueue_script('overview', GAWD_URL . '/inc/js/gawd_overview.js', array('jquery'), GAWD_VERSION);
631
+ wp_localize_script('overview', 'gawd_overview', array(
632
+ 'ajaxurl' => admin_url('admin-ajax.php'),
633
+ 'ajaxnonce' => wp_create_nonce('gawd_admin_page_nonce'),
634
+ 'gawd_plugin_url' => GAWD_URL,
635
+ 'default_date' => $default_date,
636
+ 'enableHoverTooltip' => $enable_hover_tooltip,
637
+ 'wp_admin_url' => admin_url()
638
+ ));
639
+ wp_localize_script('admin_js', 'gawd_admin', array(
640
+ 'ajaxurl' => admin_url('admin-ajax.php'),
641
+ 'ajaxnonce' => wp_create_nonce('gawd_admin_page_nonce'),
642
+ 'gawd_plugin_url' => GAWD_URL,
643
+ 'wp_admin_url' => admin_url(),
644
+ 'enableHoverTooltip' => $enable_hover_tooltip,
645
+ 'default_date' => $default_date,
646
+ 'default_date_format' => $default_date_format,
647
+ 'date_30' => date('Y-m-d', strtotime('-31 day')) . '/-/' . date('Y-m-d', strtotime('-1 day')),
648
+ 'date_7' => date('Y-m-d', strtotime('-8 day')) . '/-/' . date('Y-m-d', strtotime('-1 day')),
649
+ 'date_last_week' => date('Y-m-d', strtotime('last week -1day')) . '/-/' . date('Y-m-d', strtotime('last week +5day')),
650
+ 'date_last_month' => date('Y-m-01', strtotime('last month')) . '/-/' . date('Y-m-t', strtotime('last month')),
651
+ 'date_this_month' => date('Y-m-01') . '/-/' . date('Y-m-d'),
652
+ 'date_today' => date('Y-m-d') . '/-/' . date('Y-m-d'),
653
+ 'date_yesterday' => date('Y-m-d', strtotime('-1 day')) . '/-/' . date('Y-m-d', strtotime('-1 day')),
654
+ 'exportUrl' => add_query_arg(array('action' => 'gawd_export'), admin_url('admin-ajax.php')),
655
+ 'show_report_page' => $show_report_page
656
+ ));
657
+ }
658
+ }
659
 
660
+ /**
661
+ * Adds the menu page with its submenus.
662
+ */
663
+ public function gawd_add_menu()
664
+ {
665
+ $gawd_settings = get_option('gawd_settings');
666
+ $gawd_permissions = isset($gawd_settings['gawd_permissions']) ? $gawd_settings['gawd_permissions'] : array();
667
+ if (empty($gawd_permissions)) {
668
+ $permission = 'manage_options';
669
+ } else {
670
+ if (in_array('manage_options', $gawd_permissions)) {
671
+ $permission = 'manage_options';
672
+ }
673
+ if (in_array('moderate_comments', $gawd_permissions)) {
674
+ $permission = 'moderate_comments';
675
+ }
676
+ if (in_array('publish_posts', $gawd_permissions)) {
677
+ $permission = 'publish_posts';
678
+ }
679
+ if (in_array('edit_posts', $gawd_permissions)) {
680
+ $permission = 'edit_posts';
681
+ }
682
+ if (in_array('read', $gawd_permissions)) {
683
+ $permission = 'read';
684
+ }
685
+ }
686
+ add_menu_page(
687
+ __('Analytics', 'gawd'), //$page_title
688
+ __('Analytics', 'gawd'), //$menu_title
689
+ $permission, //$capability
690
+ 'gawd_analytics', //$menu_slug
691
+ array($this, $this->gawd_set_display('gawd_display_overview_page')), //$function = '',
692
+ GAWD_URL . '/assets/main_icon.png', 25, 13);
693
+ add_submenu_page(
694
+ 'gawd_analytics', //$parent_slug
695
+ __('Overview', 'gawd'), //$page_title
696
+ __('Overview', 'gawd'), //$menu_title
697
+ $permission, //$capability
698
+ $this->gawd_set_slug('gawd_analytics'), //$menu_slug
699
+ array($this, $this->gawd_set_display('gawd_display_overview_page')) //$function = '',
700
+ );
701
+ add_submenu_page(
702
+ 'gawd_analytics', //$parent_slug
703
+ __('Reports', 'gawd'), //$page_title
704
+ __('Reports', 'gawd'), //$menu_title
705
+ $permission, //$capability
706
+ $this->gawd_set_slug('gawd_reports'), //$menu_slug
707
+ array($this, $this->gawd_set_display('gawd_display_reports_page')) //$function = '',
708
+ );
709
+ add_submenu_page(
710
+ 'gawd_analytics', //$parent_slug
711
+ __('Settings', 'gawd'), //$page_title
712
+ __('Settings', 'gawd'), //$menu_title
713
+ $permission, //$capability
714
+ 'gawd_settings', //$menu_slug
715
+ array($this, 'gawd_display_settings_page') //$function = '',
716
+ );
717
+ add_submenu_page(
718
+ 'gawd_analytics', //$parent_slug
719
+ __('Tracking', 'gawd'), //$page_title
720
+ __('Tracking', 'gawd'), //$menu_title
721
+ $permission, //$capability
722
+ $this->gawd_set_slug('gawd_tracking'), //$menu_slug
723
+ array($this, $this->gawd_set_display('gawd_display_tracking_page')) //$function = '',
724
+ );
725
+ add_submenu_page(
726
+ 'gawd_analytics', //$parent_slug
727
+ __('Goal Management', 'gawd'), //$page_title
728
+ __('Goal Management', 'gawd'), //$menu_title
729
+ $permission, //$capability
730
+ $this->gawd_set_slug('gawd_goals'), //$menu_slug
731
+ array($this, $this->gawd_set_display('gawd_display_goals_page')) //$function = '',
732
+ );
733
+ add_submenu_page(
734
+ 'gawd_analytics', //$parent_slug
735
+ __('Custom Reports', 'gawd'), //$page_title
736
+ __('Custom Reports', 'gawd'), //$menu_title
737
+ $permission, //$capability
738
+ $this->gawd_set_slug('gawd_custom_reports'), //$menu_slug
739
+ array($this, $this->gawd_set_display('gawd_display_custom_reports_page')) //$function = '',
740
+ );
741
+ add_submenu_page(
742
+ 'gawd_analytics', //$parent_slug
743
+ __('Get Pro', 'gawd'), //$page_title
744
+ __('Get Pro', 'gawd'), //$menu_title
745
+ $permission, //$capability
746
+ 'gawd_licensing', //$menu_slug
747
+ array($this, 'gawd_display_licensing_page') //$function = '',
748
+ );
749
+ add_submenu_page(
750
+ 'gawd_analytics', //$parent_slug
751
+ __('Featured Plugins', 'gawd'), //$page_title
752
+ __('Featured Plugins', 'gawd'), //$menu_title
753
+ $permission, //$capability
754
+ 'gawd_featured_plugins', //$menu_slug
755
+ array($this, 'gawd_display_featured_plugins_page') //$function = '',
756
+ );
757
+ add_submenu_page(
758
+ 'gawd_analytics', //$parent_slug
759
+ __('Featured Themes', 'gawd'), //$page_title
760
+ __('Featured Themes', 'gawd'), //$menu_title
761
+ $permission, //$capability
762
+ 'gawd_featured_themes', //$menu_slug
763
+ array($this, 'gawd_display_featured_themes_page') //$function = '',
764
+ );
765
+ add_submenu_page(
766
+ 'gawd_analytics', //$parent_slug
767
+ __('Uninstall', 'gawd'), //$page_title
768
+ __('Uninstall', 'gawd'), //$menu_title
769
+ $permission, //$capability
770
+ 'gawd_uninstall', //$menu_slug
771
+ array($this, 'gawd_display_uninstall_page') //$function = '',
772
+ );
773
+ }
774
 
775
+ public function gawd_set_slug($slug)
776
+ {
777
+ global $gawd_redirect_to_settings;
778
+ if ($gawd_redirect_to_settings == 'yes') {
779
+ return 'gawd_settings';
780
+ } else {
781
+ return $slug;
782
+ }
783
+ }
784
 
785
+ public function gawd_set_display($slug)
786
+ {
787
+ global $gawd_redirect_to_settings;
788
+ if ($gawd_redirect_to_settings == 'yes') {
789
+ return 'gawd_display_settings_page';
790
+ } else {
791
+ return $slug;
792
+ }
793
+ }
794
 
795
+ public function gawd_display_licensing_page()
796
+ {
797
+ require_once(GAWD_DIR . '/admin/licensing.php');
798
+ }
799
 
800
+ function upgrade_pro()
801
+ {
802
+ $screen = get_current_screen();
803
+ if (strpos($screen->base, 'gawd') !== false && strpos($screen->base, 'gawd_featured') === false) {
804
+ ?>
805
 
806
+ <div class="gawd_upgrade wd-clear">
807
 
808
+ <div class="wd-right">
809
 
810
+ <a href="https://web-dorado.com/products/wordpress-google-analytics-plugin.html" target="_blank">
811
 
812
+ <div class="wd-table">
813
 
814
+ <div class="wd-cell wd-cell-valign-middle">
815
 
816
+ <?php _e("Upgrade to paid version", "gawd"); ?>
817
 
818
+ </div>
819
 
 
820
 
821
+ <div class="wd-cell wd-cell-valign-middle">
822
 
823
+ <img src="<?php echo GAWD_URL; ?>/assets/web-dorado.png">
824
 
825
+ </div>
826
 
827
+ </div>
828
 
829
+ </a>
830
 
831
+ </div>
832
 
833
+ </div>
834
 
835
+ <?php
836
+ }
837
+ }
838
 
839
+ public function gawd_display_featured_plugins_page()
840
+ {
841
+ require_once(GAWD_DIR . '/featured/featured.php');
842
+ gawd_featured_plugins('wd-google-analytics');
843
+ }
844
 
845
+ public function gawd_display_featured_themes_page()
846
+ {
847
+ require_once(GAWD_DIR . '/featured/featured_themes.php');
848
+ $controller = new gawd_featured_themes();
849
+ $controller->display();
850
+ }
851
 
852
+ public function gawd_auth()
853
+ {
854
+ check_ajax_referer('gawd_admin_page_nonce', 'security');
855
+ $code = $_POST['token'];
856
+ $status = GAWD_google_client::authenticate($code);
857
+ if ($status === true) {
858
+ $res = array(
859
+ 'message' => 'successfully saved',
860
+ 'status' => $status,
861
+ );
862
+ } else {
863
+ $res = array(
864
+ 'message' => 'there is an error',
865
+ 'status' => $status
866
+ );
867
+ }
868
+ header('content-type: application/json');
869
+ echo json_encode($res);
870
+ wp_die();
871
+ }
872
 
873
+ /**
874
+ * Displays the Dashboard page.
875
+ */
876
+ public function gawd_display_uninstall_page()
877
+ {
878
+ require_once('admin/pages/uninstall.php');
879
+ $gawd_uninstall = new GAWDUninstall();
880
+ $deactivate_url = wp_nonce_url('plugins.php?action=deactivate&plugin=' . GWD_NAME . '/google-analytics-wd.php', 'deactivate-plugin_' . GWD_NAME . '/google-analytics-wd.php');
881
+ $deactivate_url = str_replace('&amp;', '&', $deactivate_url);
882
+ if (isset($_POST['unistall_gawd'])) {
883
+ check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
884
+ delete_option('gawd_custom_reports');
885
+ delete_option('gawd_menu_for_user');
886
+ delete_option('gawd_all_metrics');
887
+ delete_option('gawd_all_dimensions');
888
+ delete_option('gawd_custom_dimensions');
889
+ delete_option('gawd_settings');
890
+ delete_option('gawd_user_data');
891
+ delete_option('gawd_credentials');
892
+ delete_option('gawd_menu_items');
893
+ delete_option('gawd_export_chart_data');
894
+ delete_option('gawd_email');
895
+ delete_option('gawd_custom_reports');
896
+ delete_option('gawd_alerts');
897
+ delete_option('gawd_pushovers');
898
+ delete_option('gawd_menu_for_users');
899
+ delete_option('gawd_own_project');
900
+ delete_option('gawd_zoom_message');
901
+ delete_transient('gawd_user_profiles');
902
+ echo '<script>window.location.href="' . $deactivate_url . '";</script>';
903
+ }
904
+ if (get_option('gawd_credentials')) {
905
+ $gawd_uninstall->uninstall();
906
+ }
907
+ }
908
 
909
+ public function gawd_display_goals_page()
910
+ {
911
+ global $gawd_client;
912
+ if ($this->manage_ua_code_selection() != 'done') {
913
+ return;
914
+ }
915
+ $gawd_client = GAWD_google_client::get_instance();
916
+ if (!empty($_POST)) {
917
+ check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
918
+ }
919
+ $gawd_goal_profile = isset($_POST['gawd_goal_profile']) ? sanitize_text_field($_POST['gawd_goal_profile']) : '';
920
+ $gawd_goal_name = isset($_POST['gawd_goal_name']) ? sanitize_text_field($_POST['gawd_goal_name']) : '';
921
+ $gawd_goal_type = isset($_POST['gawd_goal_type']) ? sanitize_text_field($_POST['gawd_goal_type']) : '';
922
+ $gawd_visit_hour = isset($_POST['gawd_visit_hour']) ? sanitize_text_field($_POST['gawd_visit_hour']) : '';
923
+ $gawd_visit_minute = isset($_POST['gawd_visit_minute']) ? sanitize_text_field($_POST['gawd_visit_minute']) : '';
924
+ $gawd_visit_second = isset($_POST['gawd_visit_second']) ? sanitize_text_field($_POST['gawd_visit_second']) : '';
925
+ $gawd_goal_duration_comparison = isset($_POST['gawd_goal_duration_comparison']) ? sanitize_text_field($_POST['gawd_goal_duration_comparison']) : '';
926
+ $gawd_goal_page_comparison = isset($_POST['gawd_goal_page_comparison']) ? sanitize_text_field($_POST['gawd_goal_page_comparison']) : '';
927
+ $gawd_page_sessions = isset($_POST['gawd_page_sessions']) ? sanitize_text_field($_POST['gawd_page_sessions']) : '';
928
+ $goal_max_id = isset($_POST['goal_max_id']) ? $_POST['goal_max_id'] + 1 : 1;
929
+ $gawd_goal_page_destination_match = isset($_POST['gawd_goal_page_destination_match']) ? sanitize_text_field($_POST['gawd_goal_page_destination_match']) : '';
930
+ $gawd_page_url = isset($_POST['gawd_page_url']) ? sanitize_text_field($_POST['gawd_page_url']) : '';
931
+ $url_case_sensitve = isset($_POST['url_case_sensitve']) ? $_POST['url_case_sensitve'] : '';
932
+ if ($gawd_goal_type == 'VISIT_TIME_ON_SITE') {
933
+ if ($gawd_visit_hour != '' || $gawd_visit_minute != '' || $gawd_visit_second != '') {
934
+ $value = 0;
935
+ if ($gawd_visit_hour != '') {
936
+ $value += $gawd_visit_hour * 60 * 60;
937
+ }
938
+ if ($gawd_visit_minute != '') {
939
+ $value += $gawd_visit_minute * 60;
940
+ }
941
+ if ($gawd_visit_second != '') {
942
+ $value += $gawd_visit_second;
943
+ }
944
+ }
945
+ $gawd_client->add_goal($gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_duration_comparison, $value);
946
+ add_option("gawd_save_goal", 1);
947
+ } elseif ($gawd_goal_type == 'VISIT_NUM_PAGES') {
948
+ if ($gawd_page_sessions != '') {
949
+ $gawd_client->add_goal($gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_page_comparison, $gawd_page_sessions);
950
+ }
951
+ add_option("gawd_save_goal", 1);
952
+ } elseif ($gawd_goal_type == 'URL_DESTINATION') {
953
+ if ($gawd_page_url != '') {
954
+ $gawd_client->add_goal($gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_page_destination_match, $gawd_page_url, $url_case_sensitve);
955
+ }
956
+ add_option("gawd_save_goal", 1);
957
+ } elseif ($gawd_goal_type == 'EVENT') {
958
+ if ($gawd_page_url != '') {
959
+ $gawd_client->add_goal($gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_page_comparison, $gawd_page_url, $url_case_sensitve);
960
+ }
961
+ add_option("gawd_save_goal", 1);
962
+ }
963
+ if (get_option('gawd_save_goal') == 1) {
964
+ $this->gawd_admin_notice('Goal successfully has been created.', 'success is-dismissible');
965
+ }
966
+ delete_option('gawd_save_goal');
967
+ require_once('admin/pages/goals.php');
968
+ }
969
 
970
+ public function gawd_display_custom_reports_page()
971
+ {
972
+ global $gawd_client;
973
+ if (!empty($_POST)) {
974
+ check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
975
+ }
976
+ $gawd_client = GAWD_google_client::get_instance();
977
+ $gawd_remove_custom_report = isset($_POST['gawd_remove_custom_report']) ? sanitize_text_field($_POST['gawd_remove_custom_report']) : '';
978
+ if ($gawd_remove_custom_report) {
979
+ $all_reports = get_option("gawd_custom_reports");
980
+ if ($all_reports) {
981
+ unset($all_reports[$gawd_remove_custom_report]);
982
+ update_option('gawd_custom_reports', $all_reports);
983
+ self::add_dashboard_menu();
984
+ }
985
+ }
986
+ if (isset($_POST['gawd_add_custom_report'])) {
987
+ $gawd_custom_report_name = isset($_POST['gawd_custom_report_name']) ? sanitize_text_field($_POST['gawd_custom_report_name']) : '';
988
+ $gawd_custom_report_metric = isset($_POST['gawd_custom_report_metric']) ? sanitize_text_field($_POST['gawd_custom_report_metric']) : '';
989
+ $gawd_custom_report_dimension = isset($_POST['gawd_custom_report_dimension']) ? sanitize_text_field($_POST['gawd_custom_report_dimension']) : '';
990
+ if ($gawd_custom_report_name != '' && $gawd_custom_report_metric != '' && $gawd_custom_report_dimension != '') {
991
+ $saved_custom_reports = get_option("gawd_custom_reports");
992
+ if (!isset($saved_custom_reports[$gawd_custom_report_name])) {
993
+ if ($saved_custom_reports) {
994
+ $custom_reports = array(
995
+ 'metric' => $gawd_custom_report_metric,
996
+ 'dimension' => $gawd_custom_report_dimension,
997
+ 'id' => count($saved_custom_reports) + 1
998
+ );
999
+ $saved_custom_reports[$gawd_custom_report_name] = $custom_reports;
1000
+ update_option('gawd_custom_reports', $saved_custom_reports);
1001
+ } else {
1002
+ $custom_reports = array(
1003
+ $gawd_custom_report_name => array(
1004
+ 'metric' => $gawd_custom_report_metric,
1005
+ 'dimension' => $gawd_custom_report_dimension,
1006
+ 'id' => 1
1007
+ )
1008
+ );
1009
+ update_option('gawd_custom_reports', $custom_reports);
1010
+ }
1011
+ }
1012
+ }
1013
+ self::add_dashboard_menu();
1014
+ }
1015
+ require_once('admin/pages/custom_reports.php');
1016
+ }
1017
 
1018
+ public function gawd_display_overview_page()
1019
+ {
1020
+ global $gawd_client, $gawd_user_data;
1021
+ $gawd_client = GAWD_google_client::get_instance();
1022
+ $profiles = $gawd_client->get_profiles();
1023
+ $gawd_user_data = get_option('gawd_user_data');
1024
+ if (isset($_POST['gawd_id'])) {
1025
+ $gawd_user_data['gawd_id'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
1026
+ foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
1027
+ foreach ($web_property as $profile) {
1028
+ if ($profile['id'] == $gawd_user_data['gawd_id']) {
1029
+ $gawd_user_data['web_property_name'] = $web_property_name;
1030
+ $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1031
+ $gawd_user_data['accountId'] = $profile['accountId'];
1032
+ }
1033
+ }
1034
+ }
1035
+ $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
1036
+ update_option('gawd_user_data', $gawd_user_data);
1037
+ }
1038
+ require_once('admin/pages/overview.php');
1039
+ }
1040
 
1041
+ public function gawd_display_reports_page()
1042
+ {
1043
+ global $gawd_client, $gawd_user_data;
1044
+ $gawd_client = GAWD_google_client::get_instance();
1045
+ $profiles = $gawd_client->get_profiles();
1046
+ $gawd_user_data = get_option('gawd_user_data');
1047
+ $gawd_settings = get_option('gawd_settings');
1048
+ if (isset($_POST['gawd_id'])) {
1049
+ $gawd_user_data['gawd_id'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
1050
+ foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
1051
+ foreach ($web_property as $profile) {
1052
+ if ($profile['id'] == $gawd_user_data['gawd_id']) {
1053
+ $gawd_user_data['web_property_name'] = $web_property_name;
1054
+ $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1055
+ $gawd_user_data['accountId'] = $profile['accountId'];
1056
+ }
1057
+ }
1058
+ }
1059
+ $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
1060
+ update_option('gawd_user_data', $gawd_user_data);
1061
+ }
1062
+ require_once('admin/pages/dashboard.php');
1063
+ }
1064
 
1065
+ public function gawd_daily_email()
1066
+ {
1067
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1068
+ $gawd_client = GAWD_google_client::get_instance();
1069
+ $emails = get_option('gawd_email');
1070
+ $gawd_user_data = get_option('gawd_user_data');
1071
+ $data = '';
1072
+ foreach ($emails as $email) {
1073
+ if (isset($email['period']) && $email['period'] == 'daily') {
1074
+ //pls send email if ....
1075
+ $date = date('Y-m-d', strtotime('yesterday'));
1076
+ $email_subject = preg_match('/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', $email['email_subject']) ? preg_replace('/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', '(' . $date . ' - ' . $date . ')', $email['email_subject']) : $email['email_subject'] . ' (' . $date . ' - ' . $date . ')';
1077
+ $data = $this->show_data(array(
1078
+ 'metric' => 'ga:' . $email['metric'],
1079
+ 'dimension' => $email['dimension'],
1080
+ 'start_date' => $date,
1081
+ 'end_date' => $date
1082
+ ));
1083
+ if ($email['export_type'] == 'pdf') {
1084
+ $filedir = $this->create_pdf_file(false, $data, $email['dimension'], $date, $date, $email['metric_compare'], $email['metric']);
1085
+ } else {
1086
+ $filedir = $this->create_csv_file(false, $data, $email['dimension'], $date, $date, $email['metric_compare'], $email['metric']);
1087
+ }
1088
+ //$attachment = gawd_export_data($data, $export_type, 'email', $email['dimension'], $email['metric'], $email['metric_compare'], $email['img'], $email['tab_name'], $start_date, $end_date, $gawd_user_data['web_property_name'],$filter_type);
1089
+ $attachment = $filedir;
1090
+ $headers = 'From: <' . $email['email_from'] . '>';
1091
+ wp_mail($email['emails'], $email_subject, $email['email_body'], $headers, $attachment);
1092
+ }
1093
+ }
1094
+ }
1095
 
1096
+ public function gawd_weekly_email()
1097
+ {
1098
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1099
+ $gawd_client = GAWD_google_client::get_instance();
1100
+ $emails = get_option('gawd_email');
1101
+ $gawd_user_data = get_option('gawd_user_data');
1102
+ $data = '';
1103
+ foreach ($emails as $email) {
1104
+ if (isset($email['period']) && $email['period'] == 'gawd_weekly') {
1105
+ //pls send email if ....
1106
+ /*$start_date = date('Y-m-d', strtotime('last' . $email['period_day']));
1107
 
1108
+ $end_date = date('Y-m-d', strtotime('this' . $email['period_day']));*/
1109
+ $start_date = date('Y-m-d', strtotime('last week -1 day'));
1110
+ $end_date = date('l') != 'Sunday' ? date('Y-m-d', strtotime('last sunday -1 day')) : date('Y-m-d', strtotime('-1 day'));
1111
+ $email_subject = preg_match('/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', $email['email_subject']) ? preg_replace('/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', '(' . $start_date . ' - ' . $end_date . ')', $email['email_subject']) : $email['email_subject'] . ' (' . $start_date . ' - ' . $end_date . ')';
1112
+ $data = $this->show_data(array(
1113
+ 'metric' => 'ga:' . $email['metric'],
1114
+ 'dimension' => $email['dimension'],
1115
+ 'start_date' => $start_date,
1116
+ 'end_date' => $end_date
1117
+ ));
1118
+ if ($email['export_type'] == 'pdf') {
1119
+ $filedir = $this->create_pdf_file(false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric']);
1120
+ } else {
1121
+ $filedir = $this->create_csv_file(false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric']);
1122
+ }
1123
+ //$attachment = gawd_export_data($data, $export_type, 'email', $email['dimension'], $email['metric'], $email['metric_compare'], $email['img'], $email['tab_name'], $start_date, $end_date, $gawd_user_data['web_property_name'],$filter_type);
1124
+ $attachment = $filedir;
1125
+ $headers = 'From: <' . $email['email_from'] . '>';
1126
+ wp_mail($email['emails'], $email_subject, $email['email_body'], $headers, $attachment);
1127
+ }
1128
+ }
1129
+ }
1130
 
1131
+ public function gawd_monthly_email()
1132
+ {
1133
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1134
+ $gawd_client = GAWD_google_client::get_instance();
1135
+ $emails = get_option('gawd_email');
1136
+ $gawd_user_data = get_option('gawd_user_data');
1137
+ $data = '';
1138
+ foreach ($emails as $email) {
1139
+ if (isset($email['period']) && $email['period'] == 'gawd_monthly') {
1140
+ //pls send email if ....
1141
+ $end_date = date('Y-m-d', strtotime(date('Y-' . date('m') . '-1') . '-1 day'));
1142
+ $start_date = date('Y-m-d', strtotime($end_date . '- 1 month'));
1143
+ $data = $this->show_data(array(
1144
+ 'metric' => 'ga:' . $email['metric'],
1145
+ 'dimension' => $email['dimension'],
1146
+ 'start_date' => $start_date,
1147
+ 'end_date' => $end_date
1148
+ ));
1149
+ $email_subject = preg_match('/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', $email['email_subject']) ? preg_replace('/\(([0-9]{4}-[0-1][0-9]-[0-3][0-9] \- [0-9]{4}-[0-1][0-9]-[0-3][0-9])\)/', '(' . $start_date . ' - ' . $end_date . ')', $email['email_subject']) : $email['email_subject'] . ' (' . $start_date . ' - ' . $end_date . ')';
1150
+ if ($email['export_type'] == 'pdf') {
1151
+ $filedir = $this->create_pdf_file(false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric']);
1152
+ } else {
1153
+ $filedir = $this->create_csv_file(false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric']);
1154
+ }
1155
+ //$attachment = gawd_export_data($data, $export_type, 'email', $email['dimension'], $email['metric'], $email['metric_compare'], $email['img'], $email['tab_name'], $start_date, $end_date, $gawd_user_data['web_property_name'],$filter_type);
1156
+ $attachment = $filedir;
1157
+ $headers = 'From: <' . $email['email_from'] . '>';
1158
+ wp_mail($email['emails'], $email_subject, $email['email_body'], $headers, $attachment);
1159
+ }
1160
+ }
1161
+ }
1162
 
1163
+ /**
1164
+ * Prepares the settings to be displayed then displays the settings page.
1165
+ */
1166
+ public static function gawd_settings_defaults()
1167
+ {
1168
+ $settings = get_option('gawd_settings');
1169
+ $settings['gawd_tracking_enable'] = 'on';
1170
+ $settings['gawd_custom_dimension_Logged_in'] = 'on';
1171
+ $settings['gawd_custom_dimension_Post_type'] = 'on';
1172
+ $settings['gawd_custom_dimension_Author'] = 'on';
1173
+ $settings['gawd_custom_dimension_Category'] = 'on';
1174
+ $settings['gawd_custom_dimension_Published_Month'] = 'on';
1175
+ $settings['gawd_custom_dimension_Published_Year'] = 'on';
1176
+ $settings['gawd_custom_dimension_Tags'] = 'on';
1177
+ $settings['enable_hover_tooltip'] = 'on';
1178
+ $settings['gawd_show_in_dashboard'] = 'on';
1179
+ $settings['post_page_chart'] = 'on';
1180
+ $settings['show_report_page'] = 'off';
1181
+ update_option('gawd_settings', $settings);
1182
+ }
1183
 
1184
+ public function manage_ua_code_selection()
1185
+ {
1186
+ global $gawd_user_data, $gawd_client;
1187
+ $gawd_user_data = get_option('gawd_user_data');
1188
+ if (isset($gawd_user_data['default_webPropertyId']) && $gawd_user_data['default_webPropertyId']) {
1189
+ return 'done';
1190
+ } else {
1191
+ $gawd_client = GAWD_google_client::get_instance();
1192
+ $property = $gawd_client->property_exists();
1193
+ if ($property == 'no_matches') {
1194
+ $this->gawd_admin_notice("<p class='gawd_notice'>You don't have any web-properties with current site url, go with <a href='" . admin_url('admin.php?page=gawd_tracking') . "'>this</a> link to add.</p>", 'error');
1195
+ // show notice that you don't have property with current site url
1196
+ // add account or property to an existing account
1197
+ } elseif (count($property) == 1) {
1198
+ $property = $property[0];
1199
+ $gawd_user_data['webPropertyId'] = $property['id'];
1200
+ $gawd_user_data['default_webPropertyId'] = $property['id'];
1201
+ $gawd_user_data['accountId'] = $property['accountId'];
1202
+ $gawd_user_data['default_accountId'] = $property['accountId'];
1203
+ $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
1204
+ update_option('gawd_user_data', $gawd_user_data);
1205
+ $this->gawd_admin_notice("In order to enable tracking for your website, you have to go with
1206
+
1207
+ <a href='" . admin_url('admin.php?page=gawd_tracking') . "'>this</a> link and turn the option on.", 'warning is-dismissible');
1208
+ // show notice that you have to enable tracking code, link to tracking submenu
1209
+ } else {
1210
+ $this->gawd_admin_notice("You have two or more web-properties configured with current site url. Please go with
1211
+
1212
+ <a href='" . admin_url('admin.php?page=gawd_tracking') . "'>this</a> link to select the proper one.", 'error');
1213
+ // show notice that you have >=2 properties with current site url
1214
+ // select property from same url properties
1215
+ }
1216
+ }
1217
+ }
1218
 
1219
+ public function manage_ua_code_selection_tracking()
1220
+ {
1221
+ global $gawd_user_data;
1222
+ if (isset($gawd_user_data['default_webPropertyId']) && $gawd_user_data['default_webPropertyId']) {
1223
+ return 'done';
1224
+ } else {
1225
+ $gawd_client = GAWD_google_client::get_instance();
1226
+ $property = $gawd_client->property_exists();
1227
+ if ($property == 'no_matches') {
1228
+ $accounts = $gawd_client->get_management_accounts();
1229
+ if (!empty($accounts)) {
1230
+ echo "<h3 style='margin-top:10px' class='gawd_page_titles'>Tracking</h3>
1231
 
1232
+ <p class='gawd_notice notice'>Here you can add a <b>web property</b> on your Google Analytics account using current WordPress website. After creating a <b>web property</b> Google Analytics tracking code will be added to your website.</p></br>
1233
 
1234
+ <form method='post' id='gawd_property_add'>
1235
 
1236
+ <div class='gawd_settings_wrapper'>
1237
 
1238
+ <div class='gawd_goal_row'>
1239
 
1240
+ <span class='gawd_goal_label'>Account</span>
1241
 
1242
+ <span class='gawd_goal_input'>
1243
 
1244
+ <select name='gawd_account_select' class='gawd_account_select' style='padding: 2px;width: 96%;line-height: 30px;height: 30px !important;'>";
1245
+ foreach ($accounts as $account) {
1246
+ echo "<option value='" . $account['id'] . "'>" . $account['name'] . "</option>";
1247
+ }
1248
+ echo "</select>
1249
 
1250
+ </span>
1251
 
1252
+ <div class='gawd_info' title='Choose the Google Analytics account to connect this property to.'></div>
1253
 
1254
+ <div class='clear'></div>
1255
 
1256
+ </div>
1257
 
1258
+ <div class='gawd_goal_row'>
1259
 
1260
+ <span class='gawd_goal_label'>Name</span>
1261
 
1262
+ <span class='gawd_goal_input'>
1263
 
1264
+ <input id='gawd_property_name' name='gawd_property_name' type='text'>
1265
 
1266
+ </span>
1267
 
1268
+ <div class='gawd_info' title='Provide a name for the property.'></div>
1269
 
1270
+ <div class='clear'></div>
1271
 
1272
+ </div>
1273
 
1274
+ </div>
1275
 
1276
+ <div class='gawd_add_prop gawd_submit'>
1277
 
1278
+ <a href='" . admin_url() . "admin.php?page=gawd_analytics' class='gawd_later button_gawd'>Later</a>
1279
 
1280
+ <input type='button' id='gawd_add_property' class='button_gawd' value='Add'/>
1281
 
1282
+ <input type='hidden' id='add_property' name='add_property'/>
1283
 
1284
+ </div>
1285
 
1286
+ </form>";
1287
+ // account select to add web property and web property parameters
1288
+ // and add link to google analytics for manually creating an account
1289
+ // wp_die();
1290
+ } else {
1291
+ $this->gawd_admin_notice("You do not have any google analytics accounts set. Please go with <a href='https://analytics.google.com/' target='_blank'>this</a> link to add one.", "error");
1292
+ // link to google analytics to add account
1293
+ // wp_die();
1294
+ }
1295
+ } elseif (count($property) == 1) {
1296
+ $property = $property[0];
1297
+ $gawd_user_data['webPropertyId'] = $property['id'];
1298
+ $gawd_user_data['default_webPropertyId'] = $property['id'];
1299
+ $gawd_user_data['accountId'] = $property['accountId'];
1300
+ $gawd_user_data['default_accountId'] = $property['accountId'];
1301
+ $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
1302
+ update_option('gawd_user_data', $gawd_user_data);
1303
+ } else {
1304
+ echo "<p class='notice'>You have multiple web-properties set with current site url. Please select the one which you want to use for tracking from the list below.</p>
1305
 
1306
+ <br/>
1307
 
1308
+ <form method='post' id='gawd_property_select'>
1309
 
1310
+ <div class='gawd_settings_wrapper'>
1311
 
1312
+ <div class='gawd_goal_row'>
1313
 
1314
+ <span class='gawd_goal_label'>Web-property</span>
1315
 
1316
+ <span class='gawd_goal_input'>
1317
 
1318
+ <select name='gawd_property_select' class='gawd_property_select' style='padding: 2px;width: 96%;line-height: 30px;height: 30px !important;'>";
1319
+ foreach ($property as $select_property) {
1320
+ echo "<option value='" . $select_property['id'] . "'>" . $select_property['name'] . " (" . $select_property['id'] . ")</option>";
1321
+ }
1322
+ echo "</select>
1323
 
1324
+ </span>
1325
 
1326
+ <div class='gawd_info' title=''></div>
1327
 
1328
+ <div class='clear'></div>
1329
 
1330
+ </div>
1331
 
1332
+ </div>
1333
 
1334
+ <div class='gawd_submit'><input type='submit' name='lock_property' class='button_gawd' value='SAVE'/></div>
1335
 
1336
+ </form>";
1337
+ // web property select to select from properties with same site url
1338
+ // wp_die();
1339
+ }
1340
+ }
1341
+ }
1342
 
1343
+ public function gawd_admin_notice($message, $type)
1344
+ {
1345
+ $class = 'notice notice-' . $type;
1346
+ echo '<div class="' . $class . '"><p>' . $message . '</p></div>';
1347
+ }
1348
 
1349
+ public function gawd_display_settings_page()
1350
+ {
1351
+ global $gawd_user_data;
1352
+ $gawd_user_data = get_option('gawd_user_data');
1353
+ if (isset($_GET['defaultExist']) && $_GET['defaultExist'] == 1) {
1354
+ $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1355
+ echo '<script>window.location.href="' . $redirect_url . '";</script>';
1356
+ }
1357
+ if (isset($_POST['gawd_settings_logout']) && $_POST['gawd_settings_logout'] == 1) {
1358
+ delete_option('gawd_user_data');
1359
+ $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
1360
+ echo '<script>window.location.href="' . $redirect_url . '";</script>';
1361
+ }
1362
+ if (isset($_POST['web_property_name']) && $_POST['web_property_name'] != '') {
1363
+ $gawd_user_data['gawd_id'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
1364
+ foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
1365
+ foreach ($web_property as $profile) {
1366
+ if ($profile['id'] == $gawd_user_data['gawd_id']) {
1367
+ $gawd_user_data['web_property_name'] = $web_property_name;
1368
+ $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1369
+ $gawd_user_data['accountId'] = $profile['accountId'];
1370
+ }
1371
+ }
1372
+ }
1373
+ $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
1374
+ update_option('gawd_user_data', $gawd_user_data);
1375
+ $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
1376
+ //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1377
+ }
1378
+ /* if(isset($_POST['account_name']) && $_POST['account_name'] != ''){
1379
 
1380
+ $gawd_user_data['accountId'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
1381
 
1382
+ foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
1383
 
1384
+ foreach ($web_property as $profile) {
1385
 
1386
+ if ($profile['accountId'] == $gawd_user_data['accountId']) {
1387
 
1388
+ $gawd_user_data['web_property_name'] = $web_property_name;
1389
 
1390
+ $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1391
 
1392
+ $gawd_user_data['accountId'] = $profile['accountId'];
1393
 
1394
+ }
1395
 
1396
+ }
1397
 
1398
+ }
1399
 
1400
+ $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
1401
 
1402
+ update_option('gawd_user_data', $gawd_user_data);
1403
 
1404
+ $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
1405
 
1406
+ //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1407
 
1408
+ } */
1409
+ if (isset($_GET['errorMsg'])) {
1410
+ self::error_message('error', 'User does not have sufficient permissions for this account to add filter');
1411
+ }
1412
+ if (!isset($gawd_user_data['refresh_token']) || ($gawd_user_data['refresh_token'] == '')) {
1413
+ echo '<div class="gawd_auth_wrap"><p class="auth_description">Click <b>Authenticate</b> button and login to your Google account. A window asking for relevant permissions will appear. Click <b>Allow</b> and copy the authentication code from the text input.</p><div id="gawd_auth_url" onclick="gawd_auth_popup(' . GAWD_google_client::create_authentication_url() . ',800,400)" style="cursor: pointer;"><div class="gawd_auth_button">AUTHENTICATE</div><div class="clear"></div></div>';
1414
+ echo '<div id="gawd_auth_code"><form id="gawd_auth_code_paste" action="" method="post" onSubmit="return false;">
1415
 
1416
+ <p style="margin:0;color: #444;">Paste the authentication code from the popup to this input.</p>
1417
 
1418
+ <input id="gawd_token" type="text">';
1419
+ wp_nonce_field("gawd_save_form", "gawd_save_form_fild");
1420
+ echo '</form>
1421
 
1422
+ <div id="gawd_auth_code_submit">SUBMIT</div></div>';
1423
+ $gawd_own_project = get_option('gawd_own_project');
1424
+ if (isset($gawd_own_project) && $gawd_own_project && intval($gawd_own_project) == 1) {
1425
+ echo '<form method="post">
1426
 
1427
+ <div class="gawd_reset_button">
1428
 
1429
+ <input type="hidden" name="reset_data" id="reset_data"/>
1430
 
1431
+ <input type="button" class="button_gawd" id="gawd_reset_button" value="RESET"/>
1432
 
1433
+ </div>
1434
 
1435
+ </form>';
1436
+ }
1437
+ echo '</div><div id="opacity_div" style="display: none; background-color: rgba(0, 0, 0, 0.2); position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 99998;"></div>
1438
 
1439
+ <div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 99999;">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1440
 
1441
+ <img src="' . GAWD_URL . '/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;">
1442
 
1443
+ </div>';
1444
+ } else {
1445
+ if ($this->manage_ua_code_selection() != 'done') {
1446
+ // return;
1447
+ }
1448
+ try {
1449
+ $gawd_client = GAWD_google_client::get_instance();
1450
+ $gawd_client->get_profiles();
1451
+ } catch (Google_Service_Exception $e) {
1452
+ $errors = $e->getErrors();
1453
+ return $errors[0]["message"];
1454
+ } catch (Exception $e) {
1455
+ return $e->getMessage();
1456
+ }
1457
+ $gawd_alert_remove = isset($_POST['gawd_alert_remove']) ? intval($_POST['gawd_alert_remove']) : false;
1458
+ $gawd_menu_remove = isset($_POST['gawd_menu_remove']) ? intval($_POST['gawd_menu_remove']) : false;
1459
+ $gawd_pushover_remove = isset($_POST['gawd_pushover_remove']) ? intval($_POST['gawd_pushover_remove']) : false;
1460
+ $gawd_email_remove = isset($_POST['gawd_email_remove']) ? intval($_POST['gawd_email_remove']) : false;
1461
+ $gawd_filter_remove = isset($_POST['gawd_filter_remove']) ? intval($_POST['gawd_filter_remove']) : false;
1462
+ if ($gawd_alert_remove) {
1463
+ $all_alerts = get_option('gawd_alerts');
1464
+ if ($all_alerts) {
1465
+ foreach ($all_alerts as $alert) {
1466
+ wp_unschedule_event(wp_next_scheduled('gawd_alert_' . $alert['period']), 'gawd_alert_' . $alert['period']);
1467
+ }
1468
+ unset($all_alerts[$gawd_alert_remove - 1]);
1469
+ update_option('gawd_alerts', $all_alerts);
1470
+ }
1471
+ }
1472
+ if ($gawd_menu_remove) {
1473
+ $all_menues = get_option('gawd_menu_for_user');
1474
+ if ($all_menues) {
1475
+ unset($all_menues[$gawd_menu_remove]);
1476
+ update_option('gawd_menu_for_user', $all_menues);
1477
+ }
1478
+ }
1479
+ if ($gawd_email_remove) {
1480
+ $all_emails = get_option('gawd_email');
1481
+ if ($all_emails) {
1482
+ foreach ($all_emails as $email) {
1483
+ wp_unschedule_event(wp_next_scheduled('gawd_email_' . $email['period']), 'gawd_email_' . $email['period']);
1484
+ }
1485
+ unset($all_emails[$gawd_email_remove - 1]);
1486
+ update_option('gawd_email', $all_emails);
1487
+ }
1488
+ }
1489
+ if ($gawd_filter_remove) {
1490
+ $analytics = $gawd_client->analytics_member;
1491
+ $accountId = $gawd_client->get_profile_accountId();
1492
+ try {
1493
+ $analytics->management_filters->delete($accountId, $gawd_filter_remove);
1494
+ } catch (apiServiceException $e) {
1495
+ print 'There was an Analytics API service error '
1496
+ . $e->getCode() . ':' . $e->getMessage();
1497
+ } catch (apiException $e) {
1498
+ print 'There was a general API error '
1499
+ . $e->getCode() . ':' . $e->getMessage();
1500
+ } catch (Exception $e) {
1501
+ echo '<script>window.location.href="' . admin_url() . 'admin.php?page=gawd_settings&errorMsg=1#gawd_filters_tab";</script>';
1502
+ }
1503
+ }
1504
+ $gawd_pushover_remove = isset($_POST['gawd_pushover_remove']) ? $_POST['gawd_pushover_remove'] : false;
1505
+ if ($gawd_pushover_remove) {
1506
+ $all_pushovers = get_option('gawd_pushovers');
1507
+ if ($all_pushovers) {
1508
+ foreach ($all_pushovers as $pushover) {
1509
+ wp_unschedule_event(wp_next_scheduled('gawd_pushover_' . $pushover['period']), 'gawd_pushover_' . $pushover['period']);
1510
+ }
1511
+ unset($all_pushovers[$gawd_pushover_remove - 1]);
1512
+ update_option('gawd_pushovers', $all_pushovers);
1513
+ }
1514
+ }
1515
+ if (isset($_POST['settings_submit'])) {
1516
+ check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
1517
+ $gawd_user_data = get_option('gawd_user_data');
1518
+ $gawd_alert_name = isset($_POST['gawd_alert_name']) ? sanitize_text_field($_POST['gawd_alert_name']) : '';
1519
+ $gawd_alert_period = isset($_POST['gawd_alert_name']) ? sanitize_text_field($_POST['gawd_alert_period']) : '';
1520
+ $gawd_alert_metric = isset($_POST['gawd_alert_metric']) ? sanitize_text_field($_POST['gawd_alert_metric']) : '';
1521
+ $gawd_alert_condition = isset($_POST['gawd_alert_condition']) ? sanitize_text_field($_POST['gawd_alert_condition']) : '';
1522
+ $gawd_alert_value = isset($_POST['gawd_alert_value']) ? sanitize_text_field($_POST['gawd_alert_value']) : '';
1523
+ $gawd_alert_emails = isset($_POST['gawd_alert_emails']) ? sanitize_email($_POST['gawd_alert_emails']) : '';
1524
+ $gawd_alert_view = isset($_POST['gawd_alert_view']) ? sanitize_text_field($_POST['gawd_alert_view']) : '';
1525
+ $alert_view_name = isset($_POST['alert_view_name']) ? sanitize_text_field($_POST['alert_view_name']) : '';
1526
+ if ($gawd_alert_name != '' && $gawd_alert_period != '' && $gawd_alert_metric != '' && $gawd_alert_condition != '' && $gawd_alert_value != '' && $gawd_alert_emails != '') {
1527
+ $saved_alerts = get_option('gawd_alerts');
1528
+ if ($saved_alerts) {
1529
+ $gawd_alert_options = array(
1530
+ 'name' => $gawd_alert_name,
1531
+ 'period' => $gawd_alert_period,
1532
+ 'metric' => $gawd_alert_metric,
1533
+ 'condition' => $gawd_alert_condition,
1534
+ 'value' => $gawd_alert_value,
1535
+ 'creation_date' => date('Y-m-d'),
1536
+ 'emails' => $gawd_alert_emails,
1537
+ 'alert_view' => $gawd_alert_view,
1538
+ 'alert_view_name' => $alert_view_name
1539
+ );
1540
+ $saved_alerts[] = $gawd_alert_options;
1541
+ update_option('gawd_alerts', $saved_alerts);
1542
+ } else {
1543
+ $gawd_alert_options = array(
1544
+ 0 => array(
1545
+ 'name' => $gawd_alert_name,
1546
+ 'period' => $gawd_alert_period,
1547
+ 'metric' => $gawd_alert_metric,
1548
+ 'condition' => $gawd_alert_condition,
1549
+ 'value' => $gawd_alert_value,
1550
+ 'creation_date' => date('Y-m-d'),
1551
+ 'emails' => $gawd_alert_emails,
1552
+ 'alert_view' => $gawd_alert_view,
1553
+ 'alert_view_name' => $alert_view_name
1554
+ )
1555
+ );
1556
+ update_option('gawd_alerts', $gawd_alert_options);
1557
+ }
1558
+ $saved_alerts = get_option('gawd_alerts');
1559
+ if ($saved_alerts) {
1560
+ foreach ($saved_alerts as $alert) {
1561
+ if (!wp_next_scheduled('gawd_alert_' . $alert['period'])) {
1562
+ wp_schedule_event(time(), $alert['period'], 'gawd_alert_' . $alert['period']);
1563
+ }
1564
+ }
1565
+ }
1566
+ }
1567
+ $gawd_pushover_name = isset($_POST['gawd_pushover_name']) ? sanitize_text_field($_POST['gawd_pushover_name']) : '';
1568
+ $gawd_pushover_period = isset($_POST['gawd_pushover_period']) ? sanitize_text_field($_POST['gawd_pushover_period']) : '';
1569
+ $gawd_pushover_metric = isset($_POST['gawd_pushover_metric']) ? sanitize_text_field($_POST['gawd_pushover_metric']) : '';
1570
+ $gawd_pushover_condition = isset($_POST['gawd_pushover_condition']) ? sanitize_text_field($_POST['gawd_pushover_condition']) : '';
1571
+ $gawd_pushover_value = isset($_POST['gawd_pushover_value']) ? intval($_POST['gawd_pushover_value']) : '';
1572
+ $gawd_pushover_user_keys = isset($_POST['gawd_pushover_user_keys']) ? sanitize_text_field($_POST['gawd_pushover_user_keys']) : '';
1573
+ $gawd_pushover_view = isset($_POST['gawd_pushover_view']) ? sanitize_text_field($_POST['gawd_pushover_view']) : '';
1574
+ $pushover_view_name = isset($_POST['pushover_view_name']) ? sanitize_text_field($_POST['pushover_view_name']) : '';
1575
+ if ($gawd_pushover_name != '' && $gawd_pushover_period != '' && $gawd_pushover_metric != '' && $gawd_pushover_condition != '' && $gawd_pushover_value !== '' && $gawd_pushover_user_keys != '') {
1576
+ $saved_pushovers = get_option('gawd_pushovers');
1577
+ if ($saved_pushovers) {
1578
+ $gawd_pushover_options = array(
1579
+ 'name' => $gawd_pushover_name,
1580
+ 'period' => $gawd_pushover_period,
1581
+ 'metric' => $gawd_pushover_metric,
1582
+ 'condition' => $gawd_pushover_condition,
1583
+ 'value' => $gawd_pushover_value,
1584
+ 'creation_date' => date('Y-m-d'),
1585
+ 'user_key' => $gawd_pushover_user_keys,
1586
+ 'pushover_view' => $gawd_pushover_view,
1587
+ 'pushover_view_name' => $pushover_view_name
1588
+ );
1589
+ $saved_pushovers[] = $gawd_pushover_options;
1590
+ update_option('gawd_pushovers', $saved_pushovers);
1591
+ } else {
1592
+ $gawd_pushover_options = array(
1593
+ 0 => array(
1594
+ 'name' => $gawd_pushover_name,
1595
+ 'period' => $gawd_pushover_period,
1596
+ 'metric' => $gawd_pushover_metric,
1597
+ 'condition' => $gawd_pushover_condition,
1598
+ 'value' => $gawd_pushover_value,
1599
+ 'creation_date' => date('Y-m-d'),
1600
+ 'user_key' => $gawd_pushover_user_keys,
1601
+ 'pushover_view' => $gawd_pushover_view,
1602
+ 'pushover_view_name' => $pushover_view_name
1603
+ )
1604
+ );
1605
+ update_option('gawd_pushovers', $gawd_pushover_options);
1606
+ }
1607
+ $saved_pushovers = get_option('gawd_pushovers');
1608
+ if ($saved_pushovers) {
1609
+ foreach ($saved_pushovers as $pushover) {
1610
+ $this->gawd_pushover_api($pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value']);
1611
+ if (!wp_next_scheduled('gawd_pushover_' . $pushover['period'])) {
1612
+ wp_schedule_event(time(), $pushover['period'], 'gawd_pushover_' . $pushover['period']);
1613
+ }
1614
+ }
1615
+ }
1616
+ }
1617
+ $gawd_show_in_dashboard = isset($_POST['gawd_show_in_dashboard']) ? sanitize_text_field($_POST['gawd_show_in_dashboard']) : '';
1618
+ $gawd_permissions = isset($_POST['gawd_permissions']) ? explode(',', $_POST['gawd_permissions']) : array('manage_options');
1619
+ $gawd_own_project = isset($_POST['gawd_own_project']) ? sanitize_text_field($_POST['gawd_own_project']) : '';
1620
+ $site_speed_rate = isset($_POST['site_speed_rate']) ? intval($_POST['site_speed_rate']) : '1';
1621
+ $post_page_chart = isset($_POST['post_page_chart']) ? sanitize_text_field($_POST['post_page_chart']) : '';
1622
+ $enable_cross_domain = isset($_POST['enable_cross_domain']) ? sanitize_text_field($_POST['enable_cross_domain']) : '';
1623
+ $cross_domains = isset($_POST['cross_domains']) ? sanitize_text_field($_POST['cross_domains']) : '';
1624
+ $default_date = isset($_POST['default_date']) ? $_POST['default_date'] : 'last_7_days';
1625
+ $default_date_format = isset($_POST['default_date_format']) ? $_POST['default_date_format'] : 'ymd_with_week';
1626
+ $enable_hover_tooltip = isset($_POST['enable_hover_tooltip']) ? $_POST['enable_hover_tooltip'] : '';
1627
+ $gawd_backend_roles = isset($_POST['gawd_backend_roles']) ? explode(',', $_POST['gawd_backend_roles']) : array('administrator');
1628
+ $gawd_frontend_roles = isset($_POST['gawd_frontend_roles']) ? explode(',', $_POST['gawd_frontend_roles']) : array('administrator');
1629
+ $gawd_post_page_roles = isset($_POST['gawd_post_page_roles']) ? explode(',', $_POST['gawd_post_page_roles']) : array('administrator');
1630
+ $exclude_events = isset($_POST['exclude_events']) ? sanitize_text_field($_POST['exclude_events']) : array();
1631
+ $gawd_settings_exist = get_option('gawd_settings');
1632
+ $gawd_settings_exist['gawd_show_in_dashboard'] = $gawd_show_in_dashboard;
1633
+ $gawd_settings_exist['site_speed_rate'] = $site_speed_rate;
1634
+ $gawd_settings_exist['post_page_chart'] = $post_page_chart;
1635
+ $gawd_settings_exist['enable_cross_domain'] = $enable_cross_domain;
1636
+ $gawd_settings_exist['cross_domains'] = $cross_domains;
1637
+ $gawd_settings_exist['gawd_backend_roles'] = $gawd_backend_roles;
1638
+ $gawd_settings_exist['gawd_frontend_roles'] = $gawd_frontend_roles;
1639
+ $gawd_settings_exist['gawd_post_page_roles'] = $gawd_post_page_roles;
1640
+ $gawd_settings_exist['default_date'] = $default_date;
1641
+ $gawd_settings_exist['default_date_format'] = $default_date_format;
1642
+ $gawd_settings_exist['enable_hover_tooltip'] = $enable_hover_tooltip;
1643
+ $gawd_settings_exist['exclude_events'] = $exclude_events;
1644
+ $gawd_settings_exist['gawd_permissions'] = $gawd_permissions;
1645
+ update_option('gawd_settings', $gawd_settings_exist);
1646
+ $gawd_filter_name = isset($_POST['gawd_filter_name']) ? sanitize_text_field($_POST['gawd_filter_name']) : '';
1647
+ $gawd_filter_type = isset($_POST['gawd_filter_type']) ? sanitize_text_field($_POST['gawd_filter_type']) : '';
1648
+ $gawd_filter_value = isset($_POST['gawd_filter_value']) ? $gawd_filter_type == 'GEO_IP_ADDRESS' ? ($_POST['gawd_filter_value']) : sanitize_text_field($_POST['gawd_filter_value']) : '';
1649
+ if ($gawd_filter_name != '' && $gawd_filter_type != '' && $gawd_filter_value != '') {
1650
+ $gawd_client->add_filter($gawd_filter_name, $gawd_filter_type, $gawd_filter_value);
1651
+ }
1652
+ add_option("gawd_save_settings", 1);
1653
+ }
1654
+ if (get_option('gawd_save_settings') == 1) {
1655
+ $this->gawd_admin_notice('Your changes have been saved successfully.', 'success is-dismissible');
1656
+ }
1657
+ delete_option('gawd_save_settings');
1658
+ require_once('admin/pages/settings.php');
1659
+ }
1660
+ }
1661
 
1662
+ public function reset_user_data()
1663
+ {
1664
+ delete_option("gawd_credentials");
1665
+ $credentials['project_id'] = '115052745574-5vbr7tci4hjkr9clkflmnpto5jisgstg.apps.googleusercontent.com';
1666
+ $credentials['project_secret'] = 'wtNiu3c_bA_g7res6chV0Trt';
1667
+ update_option('gawd_credentials', $credentials);
1668
+ delete_option('gawd_own_project');
1669
+ delete_option('gawd_user_data');
1670
+ }
1671
 
1672
+ public function gawd_display_tracking_page()
1673
+ {
1674
+ global $gawd_client, $gawd_user_data;
1675
+ $gawd_client = GAWD_google_client::get_instance();
1676
+ $gawd_user_data = get_option('gawd_user_data');
1677
+ $add_dimension_value = isset($_POST['add_dimension_value']) ? $_POST['add_dimension_value'] : '';
1678
+ if (isset($_GET['errorMsg'])) {
1679
+ self::error_message('error', 'User does not have sufficient permissions for this account');
1680
+ }
1681
+ if (isset($_POST['add_property'])) {
1682
+ $gawd_account_select = isset($_POST['gawd_account_select']) ? $_POST['gawd_account_select'] : '';
1683
+ $gawd_property_name = isset($_POST['gawd_property_name']) ? $_POST['gawd_property_name'] : '';
1684
+ if ($gawd_account_select && $gawd_property_name) {
1685
+ $err_msg = $gawd_client->add_webproperty($gawd_account_select, $gawd_property_name);
1686
+ $redirect_url = admin_url() . 'admin.php?page=gawd_tracking&enableTracking=1';
1687
+ if ($err_msg) {
1688
+ $redirect_url .= '&errorMsg=1';
1689
+ }
1690
+ echo '<script>window.location.href="' . $redirect_url . '";</script>';
1691
+ }
1692
+ }
1693
+ if (isset($_POST['lock_property'])) {
1694
+ $property = $gawd_client->property_exists();
1695
+ $gawd_property_select = $_POST['gawd_property_select'];
1696
+ foreach ($property as $property_select) {
1697
+ if ($property_select['id'] == $gawd_property_select) {
1698
+ $property = $property_select;
1699
+ break;
1700
+ }
1701
+ }
1702
+ $gawd_user_data['webPropertyId'] = $property['id'];
1703
+ $gawd_user_data['default_webPropertyId'] = $property['id'];
1704
+ $gawd_user_data['accountId'] = $property['accountId'];
1705
+ $gawd_user_data['default_accountId'] = $property['accountId'];
1706
+ $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
1707
+ update_option('gawd_user_data', $gawd_user_data);
1708
+ }
1709
+ if ($this->manage_ua_code_selection_tracking() != 'done') {
1710
+ $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1711
+ //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1712
+ return;
1713
+ }
1714
+ $gawd_settings = get_option('gawd_settings');
1715
+ if ($add_dimension_value == 'add_dimension_Logged_in') {
1716
+ $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1717
+ $gawd_client->add_custom_dimension('Logged in', $id);
1718
+ $settings = get_option('gawd_settings');
1719
+ $optname = 'gawd_custom_dimension_Logged_in';
1720
+ $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1721
+ update_option('gawd_settings', $settings);
1722
+ }
1723
+ if ($add_dimension_value == 'add_dimension_Post_type') {
1724
+ $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1725
+ $gawd_client->add_custom_dimension('Post type', $id);
1726
+ $settings = get_option('gawd_settings');
1727
+ $optname = 'gawd_custom_dimension_Post_type';
1728
+ $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1729
+ update_option('gawd_settings', $settings);
1730
+ }
1731
+ if ($add_dimension_value == 'add_dimension_Author') {
1732
+ $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1733
+ $gawd_client->add_custom_dimension('Author', $id);
1734
+ $settings = get_option('gawd_settings');
1735
+ $optname = 'gawd_custom_dimension_Author';
1736
+ $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1737
+ update_option('gawd_settings', $settings);
1738
+ }
1739
+ if ($add_dimension_value == 'add_dimension_Category') {
1740
+ $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1741
+ $gawd_client->add_custom_dimension('Category', $id);
1742
+ $settings = get_option('gawd_settings');
1743
+ $optname = 'gawd_custom_dimension_Category';
1744
+ $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1745
+ update_option('gawd_settings', $settings);
1746
+ }
1747
+ if ($add_dimension_value == 'add_dimension_Published_Month') {
1748
+ $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1749
+ $gawd_client->add_custom_dimension('Published Month', $id);
1750
+ $settings = get_option('gawd_settings');
1751
+ $optname = 'gawd_custom_dimension_Published_Month';
1752
+ $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1753
+ update_option('gawd_settings', $settings);
1754
+ }
1755
+ if ($add_dimension_value == 'add_dimension_Published_Year') {
1756
+ $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1757
+ $gawd_client->add_custom_dimension('Published Year', $id);
1758
+ $settings = get_option('gawd_settings');
1759
+ $optname = 'gawd_custom_dimension_Published_Year';
1760
+ $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1761
+ update_option('gawd_settings', $settings);
1762
+ }
1763
+ if ($add_dimension_value == 'add_dimension_Tags') {
1764
+ $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1765
+ $gawd_client->add_custom_dimension('Tags', $id);
1766
+ $settings = get_option('gawd_settings');
1767
+ $optname = 'gawd_custom_dimension_Tags';
1768
+ $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1769
+ update_option('gawd_settings', $settings);
1770
+ }
1771
+ if (isset($_POST['settings_submit'])) {
1772
+ check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
1773
+ $gawd_user_data = get_option('gawd_user_data');
1774
+ $gawd_file_formats = isset($_POST['gawd_file_formats']) ? sanitize_text_field($_POST['gawd_file_formats']) : '';
1775
+ $gawd_anonymize = isset($_POST['gawd_anonymize']) ? sanitize_text_field($_POST['gawd_anonymize']) : '';
1776
+ $gawd_tracking_enable = isset($_POST['gawd_tracking_enable']) ? sanitize_text_field($_POST['gawd_tracking_enable']) : '';
1777
+ $gawd_outbound = isset($_POST['gawd_outbound']) ? sanitize_text_field($_POST['gawd_outbound']) : '';
1778
+ $gawd_enhanced = isset($_POST['gawd_enhanced']) ? sanitize_text_field($_POST['gawd_enhanced']) : '';
1779
+ $enable_custom_code = isset($_POST['enable_custom_code']) ? $_POST['enable_custom_code'] : '';
1780
+ $custom_code = isset($_POST['gawd_custom_code']) ? sanitize_text_field($_POST['gawd_custom_code']) : '';
1781
+ if ($add_dimension_value == '') {
1782
+ $gawd_cd_Logged_in = isset($_POST['gawd_custom_dimension_Logged_in']) ? sanitize_text_field($_POST['gawd_custom_dimension_Logged_in']) : '';
1783
+ $gawd_cd_Post_type = isset($_POST['gawd_custom_dimension_Post_type']) ? sanitize_text_field($_POST['gawd_custom_dimension_Post_type']) : '';
1784
+ $gawd_cd_Author = isset($_POST['gawd_custom_dimension_Author']) ? sanitize_text_field($_POST['gawd_custom_dimension_Author']) : '';
1785
+ $gawd_cd_Category = isset($_POST['gawd_custom_dimension_Category']) ? sanitize_text_field($_POST['gawd_custom_dimension_Category']) : '';
1786
+ $gawd_cd_Published_Month = isset($_POST['gawd_custom_dimension_Published_Month']) ? sanitize_text_field($_POST['gawd_custom_dimension_Published_Month']) : '';
1787
+ $gawd_cd_Published_Year = isset($_POST['gawd_custom_dimension_Published_Year']) ? sanitize_text_field($_POST['gawd_custom_dimension_Published_Year']) : '';
1788
+ $gawd_cd_Tags = isset($_POST['gawd_custom_dimension_Tags']) ? sanitize_text_field($_POST['gawd_custom_dimension_Tags']) : '';
1789
+ $gawd_settings['gawd_custom_dimension_Logged_in'] = $gawd_cd_Logged_in;
1790
+ $gawd_settings['gawd_custom_dimension_Post_type'] = $gawd_cd_Post_type;
1791
+ $gawd_settings['gawd_custom_dimension_Author'] = $gawd_cd_Author;
1792
+ $gawd_settings['gawd_custom_dimension_Category'] = $gawd_cd_Category;
1793
+ $gawd_settings['gawd_custom_dimension_Published_Month'] = $gawd_cd_Published_Month;
1794
+ $gawd_settings['gawd_custom_dimension_Published_Year'] = $gawd_cd_Published_Year;
1795
+ $gawd_settings['gawd_custom_dimension_Tags'] = $gawd_cd_Tags;
1796
+ }
1797
+ $gawd_excluded_roles = isset($_POST['gawd_excluded_roles']) ? $_POST['gawd_excluded_roles'] : array();
1798
+ $gawd_excluded_users = isset($_POST['gawd_excluded_users']) ? $_POST['gawd_excluded_users'] : array();
1799
+ $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
1800
+ $gawd_settings['gawd_anonymize'] = $gawd_anonymize;
1801
+ $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
1802
+ $gawd_settings['gawd_tracking_enable'] = $gawd_tracking_enable;
1803
+ $gawd_settings['gawd_outbound'] = $gawd_outbound;
1804
+ $gawd_settings['gawd_enhanced'] = $gawd_enhanced;
1805
+ $gawd_settings['gawd_excluded_roles'] = $gawd_excluded_roles;
1806
+ $gawd_settings['gawd_excluded_users'] = $gawd_excluded_users;
1807
+ $gawd_settings['enable_custom_code'] = $enable_custom_code;
1808
+ $gawd_settings['gawd_custom_code'] = $custom_code;
1809
+ update_option('gawd_settings', $gawd_settings);
1810
+ add_option("gawd_save_tracking", 1);
1811
+ }
1812
+ if (get_option('gawd_save_tracking') == 1) {
1813
+ $this->gawd_admin_notice('Your changes have been saved successfully.', 'success is-dismissible');
1814
+ }
1815
+ delete_option('gawd_save_tracking');
1816
+ if ($add_dimension_value != '') {
1817
+ $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1818
+ echo '<script>window.location.href="' . $redirect_url . '";</script>';
1819
+ }
1820
+ require_once('admin/pages/tracking.php');
1821
+ }
1822
 
1823
+ public function gawd_my_schedule($schedules)
1824
+ {
1825
+ $schedules['gawd_weekly'] = array(
1826
+ 'interval' => 604800,
1827
+ 'display' => __('Every week')
1828
+ );
1829
+ $schedules['gawd_monthly'] = array(
1830
+ 'interval' => 18748800,
1831
+ 'display' => __('Every month')
1832
+ );
1833
+ return $schedules;
1834
+ }
1835
 
1836
+ public function gawd_pushover_api($user_key, $metric, $condition, $value)
1837
+ {
1838
+ $ch = curl_init();
1839
+ curl_setopt($ch, CURLOPT_URL, "https://api.pushover.net/1/messages.json");
1840
+ curl_setopt($ch, CURLOPT_POSTFIELDS, array(
1841
+ "token" => "aJBDhTfhR87EaTzs7wpx1MMKwboBjB",
1842
+ "user" => $user_key,
1843
+ "message" => 'The ' . $metric . ' less ' . $value
1844
+ ));
1845
+ // curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
1846
+ curl_exec($ch);
1847
+ curl_close($ch);
1848
+ }
1849
 
1850
+ public function gawd_pushover_daily()
1851
+ {
1852
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1853
+ $gawd_client = GAWD_google_client::get_instance();
1854
+ $pushovers = get_option('gawd_pushovers');
1855
+ $data = '';
1856
+ $condition = '';
1857
+ foreach ($pushovers as $pushover) {
1858
+ if (isset($pushover['period']) && $pushover['period'] == 'daily') {
1859
+ //pls send email if ....
1860
+ $date = date('Y-m-d', strtotime('yesterday'));
1861
+ $data = $gawd_client->get_data_alert('ga:' . $pushover['metric'], 'date', $date, $date, $pushover['pushover_view']);
1862
+ $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
1863
+ if (!eval($data . $pushover_condition . $pushover['value'] . ';')) {
1864
+ $cond = ' ' . $pushover['condition'] . ' than';
1865
+ $this->gawd_pushover_api($pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value']);
1866
+ }
1867
+ }
1868
+ }
1869
+ }
1870
 
1871
+ public function gawd_pushover_weekly()
1872
+ {
1873
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1874
+ $gawd_client = GAWD_google_client::get_instance();
1875
+ $pushovers = get_option('gawd_pushovers');
1876
+ $data = '';
1877
+ $condition = '';
1878
+ foreach ($pushovers as $pushover) {
1879
+ if (isset($pushover['period']) && $pushover['period'] == 'gawd_weekly') {
1880
+ //pls send email if ....
1881
+ $start_date = date('Y-m-d', strtotime('last week -1 day'));
1882
+ $end_date = date('l') != 'Sunday' ? date('Y-m-d', strtotime('last sunday -1 day')) : date('Y-m-d', strtotime('-1 day'));
1883
+ $data = $gawd_client->get_data_alert('ga:' . $pushover['metric'], 'date', $start_date, $end_date, $pushover['pushover_view']);
1884
+ $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
1885
+ if (!eval($data . $pushover_condition . $pushover['value'] . ';')) {
1886
+ $cond = ' ' . $pushover['condition'] . ' than';
1887
+ $this->gawd_pushover_api($pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value']);
1888
+ }
1889
+ }
1890
+ }
1891
+ }
1892
 
1893
+ public function gawd_pushover_monthly()
1894
+ {
1895
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1896
+ $gawd_client = GAWD_google_client::get_instance();
1897
+ $pushovers = get_option('gawd_pushovers');
1898
+ $data = '';
1899
+ $condition = '';
1900
+ foreach ($pushovers as $pushover) {
1901
+ if (isset($pushover['period']) && $pushover['period'] == 'gawd_monthly') {
1902
+ //pls send email if ....
1903
+ $end_date = date('Y-m-t', strtotime('last month'));
1904
+ $start_date = date('Y-m-01', strtotime('last month'));
1905
+ $data = $gawd_client->get_data_alert('ga:' . $pushover['metric'], 'date', $start_date, $end_date, $pushover['pushover_view']);
1906
+ $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
1907
+ if (!eval($data . $pushover_condition . $pushover['value'] . ';')) {
1908
+ $cond = ' ' . $pushover['condition'] . ' than';
1909
+ $this->gawd_pushover_api($pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value']);
1910
+ }
1911
+ }
1912
+ }
1913
+ }
1914
 
1915
+ public function gawd_alert_daily()
1916
+ {
1917
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1918
+ $gawd_client = GAWD_google_client::get_instance();
1919
+ $alerts = get_option('gawd_alerts');
1920
+ $data = '';
1921
+ $condition = '';
1922
+ $email_from = get_option('admin_email');
1923
+ foreach ($alerts as $alert) {
1924
+ if (isset($alert['period']) && $alert['period'] == 'daily') {
1925
+ //pls send email if ....
1926
+ $date = date('Y-m-d', strtotime('yesterday'));
1927
+ $data = $gawd_client->get_data_alert('ga:' . $alert['metric'], 'date', $date, $date, $alert['alert_view']);
1928
+ $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
1929
+ $color_condition = $alert['condition'] == 'greater' ? 'rgb(157, 207, 172)' : 'rgb(251, 133, 131)';
1930
+ if (!eval($data . $alert_condition . $alert['value'] . ';')) {
1931
+ $cond = ' ' . $alert['condition'] . ' than';
1932
+ $headers = array();
1933
+ $headers[] = 'From: <' . $email_from . '>';
1934
+ $headers[] = 'Content-Type: text/html';
1935
+ $content = '<div style="font-family: sans-serif;width:100%;height:50px;background-color:#FB8583;font-size:20px;color:#fff;margin-bottom:20px;text-align:center;line-height:50px">Google Analytics WD Alert!</div><p style="color:#808080;text-align: center;font-size: 26px;font-family: sans-serif;">' . preg_replace('!\s+!', ' ', trim(ucfirst(preg_replace('/([A-Z])/', ' $1', $alert['metric'])))) . ' in <a style="text-decoration:none;color:rgba(124,181,216,1);font-family: sans-serif;" href="' . $alert["alert_view_name"] . '" target="_blank">' . $alert["alert_view_name"] . '</a> are <span style="color:' . $color_condition . '">' . $cond . '</span></p><p style="color:rgba(124,181,216,1);font-size: 26px;font-family: sans-serif; text-align: center;">' . $alert['value'] . '</p>';
1936
+ wp_mail($alert['emails'], 'Analytics Alert', $content, $headers);
1937
+ }
1938
+ }
1939
+ }
1940
+ }
1941
 
1942
+ public function gawd_alert_weekly()
1943
+ {
1944
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1945
+ $gawd_client = GAWD_google_client::get_instance();
1946
+ $alerts = get_option('gawd_alerts');
1947
+ $data = '';
1948
+ $condition = '';
1949
+ $email_from = get_option('admin_email');
1950
+ foreach ($alerts as $alert) {
1951
+ if (isset($alert['period']) && $alert['period'] == 'gawd_weekly') {
1952
+ //pls send email if ....
1953
+ $start_date = date('Y-m-d', strtotime('last week -1 day'));
1954
+ $end_date = date('l') != 'Sunday' ? date('Y-m-d', strtotime('last sunday -1 day')) : date('Y-m-d', strtotime('-1 day'));
1955
+ $data = $gawd_client->get_data_alert('ga:' . $alert['metric'], 'date', $start_date, $end_date, $alert['alert_view']);
1956
+ $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
1957
+ if (!eval($data . $alert_condition . $alert['value'] . ';')) {
1958
+ $cond = ' ' . $alert['condition'] . ' than';
1959
+ $headers = array();
1960
+ $headers[] = 'From: <' . $email_from . '>';
1961
+ $headers[] = 'Content-Type: text/html';
1962
+ $content = '<div style="font-family: sans-serif;width:100%;height:50px;background-color:#FB8583;font-size:20px;color:#fff;margin-bottom:20px;text-align:center;line-height:50px">Google Analytics WD Alert!</div><p style="color:#808080;text-align: center;font-size: 26px;font-family: sans-serif;">' . preg_replace('!\s+!', ' ', trim(ucfirst(preg_replace('/([A-Z])/', ' $1', $alert['metric'])))) . ' in <a style="text-decoration:none;color:rgba(124,181,216,1);font-family: sans-serif;" href="' . $alert["alert_view_name"] . '" target="_blank">' . $alert["alert_view_name"] . '</a> are <span style="color:' . $color_condition . '">' . $cond . '</span></p><p style="color:rgba(124,181,216,1);font-size: 26px;font-family: sans-serif; text-align: center;">' . $alert['value'] . '</p>';
1963
+ wp_mail($alert['emails'], 'Analytics Alert', $content, $headers);
1964
+ }
1965
+ }
1966
+ }
1967
+ }
1968
 
1969
+ public function gawd_alert_monthly()
1970
+ {
1971
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1972
+ $gawd_client = GAWD_google_client::get_instance();
1973
+ $alerts = get_option('gawd_alerts');
1974
+ $data = '';
1975
+ $email_from = get_option('admin_email');
1976
+ foreach ($alerts as $alert) {
1977
+ if (isset($alert['period']) && $alert['period'] == 'gawd_monthly') {
1978
+ //pls send email if ....
1979
+ $end_date = date('Y-m-t', strtotime('last month'));
1980
+ $start_date = date('Y-m-01', strtotime('last month'));
1981
+ $data = $gawd_client->get_data_alert('ga:' . $alert['metric'], 'date', $start_date, $end_date, $alert['alert_view']);
1982
+ $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
1983
+ if (!eval($data . $alert_condition . $alert['value'] . ';')) {
1984
+ $cond = ' ' . $alert['condition'] . ' than';
1985
+ $headers = array();
1986
+ $headers[] = 'From: <' . $email_from . '>';
1987
+ $headers[] = 'Content-Type: text/html';
1988
+ $content = '<div style="font-family: sans-serif;width:100%;height:50px;background-color:#FB8583;font-size:20px;color:#fff;margin-bottom:20px;text-align:center;line-height:50px">Google Analytics WD Alert!</div><p style="color:#808080;text-align: center;font-size: 26px;font-family: sans-serif;">' . preg_replace('!\s+!', ' ', trim(ucfirst(preg_replace('/([A-Z])/', ' $1', $alert['metric'])))) . ' in <a style="text-decoration:none;color:rgba(124,181,216,1);font-family: sans-serif;" href="' . $alert["alert_view_name"] . '" target="_blank">' . $alert["alert_view_name"] . '</a> are <span style="color:' . $color_condition . '">' . $cond . '</span></p><p style="color:rgba(124,181,216,1);font-size: 26px;font-family: sans-serif; text-align: center;">' . $alert['value'] . '</p>';
1989
+ wp_mail($alert['emails'], 'Analytics Alert', $content, $headers);
1990
+ }
1991
+ }
1992
+ }
1993
+ }
1994
 
1995
+ public function wd_dashboard_widget()
1996
+ {
1997
+ global $gawd_client, $gawd_user_data;
1998
+ $gawd_client = GAWD_google_client::get_instance();
1999
+ $profiles = $gawd_client->get_profiles();
2000
+ $gawd_user_data = get_option('gawd_user_data');
2001
+ if (isset($_POST['gawd_id'])) {
2002
+ $gawd_user_data['gawd_id'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
2003
+ foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
2004
+ foreach ($web_property as $profile) {
2005
+ if ($profile['id'] == $gawd_user_data['gawd_id']) {
2006
+ $gawd_user_data['web_property_name'] = $web_property_name;
2007
+ $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
2008
+ $gawd_user_data['accountId'] = $profile['accountId'];
2009
+ }
2010
+ }
2011
+ }
2012
+ $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
2013
+ update_option('gawd_user_data', $gawd_user_data);
2014
+ }
2015
+ require_once('admin/pages/dashboard_widget.php');
2016
+ }
2017
 
2018
+ public function google_analytics_wd_dashboard_widget()
2019
+ {
2020
+ $gawd_settings = get_option('gawd_settings');
2021
+ $gawd_backend_roles = isset($gawd_settings['gawd_backend_roles']) ? $gawd_settings['gawd_backend_roles'] : array();
2022
+ $roles = $this->get_current_user_role();
2023
+ if (isset($gawd_settings['gawd_show_in_dashboard']) && $gawd_settings['gawd_show_in_dashboard'] == 'on') {
2024
+ if (in_array($roles, $gawd_backend_roles) || current_user_can('manage_options')) {
2025
+ wp_add_dashboard_widget('wd_dashboard_widget', 'WD Google Analytics', array(
2026
+ $this,
2027
+ 'wd_dashboard_widget'
2028
+ ));
2029
+ }
2030
+ }
2031
+ }
2032
 
2033
+ public function show_data($params = array())
2034
+ {
2035
+ /* if (isset($_REQUEST['security'])) {
2036
 
2037
+ check_ajax_referer('gawd_admin_page_nonce', 'security');
2038
 
2039
+ } else {
2040
 
2041
+ check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
2042
 
2043
+ } */
2044
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
2045
+ $return = true;
2046
+ if ($params == '') {
2047
+ $params = $_POST;
2048
+ $return = false;
2049
+ }
2050
+ $gawd_client = GAWD_google_client::get_instance();
2051
+ $start_date = isset($params["start_date"]) && $params["start_date"] != '' ? $params["start_date"] : date('Y-m-d', strtotime('-7 days'));
2052
+ $end_date = isset($params["end_date"]) && $params["end_date"] != '' ? $params["end_date"] : date('Y-m-d');
2053
+ $metric = isset($params["metric"]) ? $params["metric"] : 'ga:sessions';
2054
+ $metric = is_array($metric) ? count($metric) > 1 ? implode(",", $metric) : $metric[0] : $metric;
2055
+ $dimension = isset($params["dimension"]) ? $params["dimension"] : 'date';
2056
+ $country_filter = isset($params["country_filter"]) ? $params["country_filter"] : '';
2057
+ $geo_type = isset($params["geo_type"]) ? $params["geo_type"] : '';
2058
+ $filter_type = isset($params["filter_type"]) && $params["filter_type"] != '' ? $params["filter_type"] : '';
2059
+ $custom = isset($params["custom"]) && $params["custom"] != '' ? $params["custom"] : '';
2060
+ $same_dimension = $dimension;
2061
+ $dimension = $filter_type != '' && $dimension == 'date' ? $filter_type : $dimension;
2062
+ if ($dimension == 'week' || $dimension == 'month') {
2063
+ $same_dimension = $dimension;
2064
+ }
2065
+ $timezone = isset($params["timezone"]) && $params["timezone"] != '' ? $params["timezone"] : 0;
2066
+ if ($dimension == 'pagePath' || $dimension == 'PagePath' || $dimension == 'landingPagePath' || $dimension == 'LandingPagePath') {
2067
+ if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
2068
+ $grid_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
2069
+ } else {
2070
+ $grid_data = $gawd_client->get_page_data($dimension, $start_date, $end_date, $timezone);
2071
+ }
2072
+ if ($return) {
2073
+ return $grid_data;
2074
+ }
2075
+ echo $grid_data;
2076
+ die();
2077
+ } elseif ($dimension == 'goals') {
2078
+ if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
2079
+ $goal_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
2080
+ } else {
2081
+ $goal_data = $gawd_client->get_goal_data('date', $start_date, $end_date, $timezone, $same_dimension);
2082
+ }
2083
+ if ($return) {
2084
+ return $goal_data;
2085
+ }
2086
+ echo $goal_data;
2087
+ die();
2088
+ } elseif (($dimension == 'region' || $dimension == 'city') || ($dimension == 'Region' || $dimension == 'City')) {
2089
+ if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $country_filter . '-' . $start_date . '-' . $end_date)) {
2090
+ $chart_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $country_filter . '-' . $start_date . '-' . $end_date);
2091
+ } else {
2092
+ $chart_data = $gawd_client->get_country_data($metric, $dimension, $start_date, $end_date, $country_filter, $geo_type, $timezone);
2093
+ }
2094
+ if ($return) {
2095
+ return $chart_data;
2096
+ }
2097
+ echo $chart_data;
2098
+ die();
2099
+ } else {
2100
+ if ($custom != '') {
2101
+ $chart_data = $gawd_client->get_data($metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension);
2102
+ } else {
2103
+ if ($dimension == 'siteSpeed') {
2104
+ if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $same_dimension . '_' . $filter_type . '-' . $start_date . '-' . $end_date)) {
2105
+ $chart_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
2106
+ } else {
2107
+ $chart_data = $gawd_client->get_data($metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension);
2108
+ }
2109
+ if ($return) {
2110
+ return $chart_data;
2111
+ }
2112
+ } else {
2113
+ /* if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
2114
 
2115
+ $chart_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
2116
 
2117
+ } */
2118
+ //else {
2119
+ $chart_data = $gawd_client->get_data($metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension);
2120
+ //}
2121
+ if ($return) {
2122
+ return $chart_data;
2123
+ }
2124
+ }
2125
+ }
2126
+ echo $chart_data;
2127
+ die();
2128
+ }
2129
+ }
2130
 
2131
+ public function show_data_compact()
2132
+ {
2133
+ check_ajax_referer('gawd_admin_page_nonce', 'security');
2134
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
2135
+ $gawd_client = GAWD_google_client::get_instance();
2136
+ $start_date = isset($_POST["start_date"]) && $_POST["start_date"] != '' ? $_POST["start_date"] : date('Y-m-d', strtotime('-30 days'));
2137
+ $end_date = isset($_POST["end_date"]) && $_POST["end_date"] != '' ? $_POST["end_date"] : date('Y-m-d');
2138
+ $metric = isset($_POST["metric"]) ? $_POST["metric"] : 'sessions';
2139
+ $metric = is_array($metric) ? count($metric) > 1 ? implode(",", $metric) : $metric[0] : 'ga:' . $metric;
2140
+ $dimension = isset($_POST["dimension"]) ? $_POST["dimension"] : 'date';
2141
+ $timezone = isset($_POST["timezone"]) ? $_POST["timezone"] : 0;
2142
+ if (get_transient('gawd-compact-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
2143
+ $chart_data = get_transient('gawd-compact-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
2144
+ } else {
2145
+ $chart_data = $gawd_client->get_data_compact($metric, $dimension, $start_date, $end_date, $timezone);
2146
+ }
2147
+ echo $chart_data;
2148
+ die();
2149
+ }
2150
 
2151
+ public function show_page_post_data()
2152
+ {
2153
+ check_ajax_referer('gawd_admin_page_nonce', 'security');
2154
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
2155
+ $gawd_client = GAWD_google_client::get_instance();
2156
+ $start_date = isset($_POST["start_date"]) && $_POST["start_date"] != '' ? $_POST["start_date"] : date('Y-m-d', strtotime('-30 days'));
2157
+ $end_date = isset($_POST["end_date"]) && $_POST["end_date"] != '' ? $_POST["end_date"] : date('Y-m-d');
2158
+ $metric = isset($_POST["metric"]) ? $_POST["metric"] : 'ga:sessions';
2159
+ $metric = is_array($metric) ? count($metric) > 1 ? implode(",", $metric) : $metric[0] : $metric;
2160
+ $dimension = isset($_POST["dimension"]) ? $_POST["dimension"] : 'date';
2161
+ $timezone = isset($_POST["timezone"]) ? $_POST["timezone"] : 0;
2162
+ $filter = isset($_POST["filter"]) ? substr($_POST["filter"], 1) : '';
2163
+ $chart = isset($_POST["chart"]) ? $_POST["chart"] : '';
2164
+ $chart_data = get_transient('gawd-page-post-' . $gawd_client->get_profile_id() . '-' . $filter . '-' . '-' . $dimension . '-' . $start_date . '-' . $end_date . '-' . $chart);
2165
+ if (!$chart_data) {
2166
+ $chart_data = $gawd_client->get_post_page_data($metric, $dimension, $start_date, $end_date, $filter, $timezone, $chart);
2167
+ }
2168
+ echo $chart_data;
2169
+ die();
2170
+ }
2171
 
2172
+ public function get_realtime()
2173
+ {
2174
+ check_ajax_referer('gawd_admin_page_nonce', 'security');
2175
+ require_once(GAWD_DIR . '/admin/gawd_google_class.php');
2176
+ $gawd_client = GAWD_google_client::get_instance();
2177
+ $chart_data = get_transient('gawd-real' . $gawd_client->get_profile_id());
2178
+ if (!$chart_data) {
2179
+ $chart_data = $gawd_client->gawd_realtime_data();
2180
+ }
2181
+ return $chart_data;
2182
+ }
2183
 
2184
+ public static function add_dashboard_menu()
2185
+ {
2186
+ $get_custom_reports = get_option('gawd_custom_reports');
2187
+ if (!$get_custom_reports) {
2188
+ $custom_report = array();
2189
+ } else {
2190
+ foreach ($get_custom_reports as $name => $report) {
2191
+ $custom_report['custom_report_' . $name] = __($name, "gawd");
2192
+ }
2193
+ }
2194
+ $tabs = array(
2195
+ "general" => array(
2196
+ "title" => __("Audience", "gawd"),
2197
+ "childs" => array(),
2198
+ "desc" => "Report of your website audience. Provides details about new and returning users of your website, sessions, bounces, pageviews and session durations."
2199
+ ),
2200
+ "realtime" => array(
2201
+ "title" => __("Real Time", "gawd"),
2202
+ "childs" => array(),
2203
+ "desc" => "Real Time statistics show the number of active users currently visiting your website pages."
2204
+ ),
2205
+ "Pro" => array(
2206
+ "title" => __("Available in pro", "gawd"),
2207
+ "childs" => array(),
2208
+ "desc" => ""
2209
+ ),
2210
+ "demographics" => array(
2211
+ "title" => __("Demographics", "gawd"),
2212
+ "childs" => array(
2213
+ "userGender" => __("User Gender", "gawd"),
2214
+ "userAge" => __("User Age", "gawd")
2215
+ ),
2216
+ "desc" => "Demographics display tracking statistics of your website users based on their age and gender. "
2217
+ ),
2218
+ "interests" => array(
2219
+ "title" => __("Interests", "gawd"),
2220
+ "childs" => array(
2221
+ "inMarket" => __("In-Market Segment", "gawd"),
2222
+ "affinityCategory" => __("Affinity Category", "gawd"),
2223
+ "otherCategory" => __("Other Category", "gawd")
2224
+ ),
2225
+ "desc" => "Provides tracking information about site users depending on Affinity Categories (e.g. Music Lovers or Mobile Enthusiasts), In-Market Segments (based on online product purchase interests) and Other Categories (most specific identification, for example, tennis lovers among Sports Fans)."
2226
+ ),
2227
+ "geo" => array(
2228
+ "title" => __("GEO", "gawd"),
2229
+ "childs" => array(
2230
+ "location" => __("Location", "gawd"),
2231
+ "language" => __("Language", "gawd")
2232
+ ),
2233
+ "desc" => "Geo-identifier report is built from interactions of location (countries, cities) and language of your website users."
2234
+ ),
2235
+ "behavior" => array(
2236
+ "title" => __("Behavior", "gawd"),
2237
+ "childs" => array(
2238
+ "behaviour" => __("New vs Returning", "gawd"),
2239
+ "engagement" => __("Engagement", "gawd")
2240
+ ),
2241
+ "desc" => "Compares number of New visitors and Returning users of your website in percents. You can check the duration of sessions with Engagement report."
2242
+ ),
2243
+ "technology" => array(
2244
+ "title" => __("Technology", "gawd"),
2245
+ "childs" => array(
2246
+ "os" => __("OS", "gawd"),
2247
+ "browser" => __("Browser", "gawd")
2248
+ ),
2249
+ "desc" => "Identifies tracking of the site based on operating systems and browsers visitors use."
2250
+ ),
2251
+ "mobile" => array(
2252
+ "title" => __("Mobile", "gawd"),
2253
+ "childs" => array(
2254
+ "device_overview" => __("Overview", "gawd"),
2255
+ "devices" => __("Devices", "gawd")
2256
+ ),
2257
+ "desc" => "Shows statistics of mobile and desktop devices visitors have used while interacting with your website."
2258
+ ),
2259
+ "custom" => array(
2260
+ "title" => __("Custom Dimensions", "gawd"),
2261
+ "childs" => array(),
2262
+ "desc" => "Set up Custom Dimensions based on Users, Post type, Author, Category, Publication date and Tags in Custom Dimensions page, and view their report in this tab."
2263
+ ),
2264
+ "trafficSource" => array(
2265
+ "title" => __("Traffic Source", "gawd"),
2266
+ "childs" => array(),
2267
+ "desc" => "Displays overall graph of traffic sources directing to your website."
2268
+ ),
2269
+ "adWords" => array(
2270
+ "title" => __("AdWords", "gawd"),
2271
+ "childs" => array(),
2272
+ "desc" => "If your website is registered on Google AdWords, you can link its Google Analytics to AdWords, and gather relevant tracking information with this report."
2273
+ ),
2274
+ /* "pagePath" => array(
2275
 
2276
  "title" => __("Pages", "gawd"),
2277
 
2280
  "desc" => "Pages report table will provide you information about Bounces, Entrances, Pageviews, Unique Pageviews, time spent on pages, Exits and Average page loading time."
2281
 
2282
  ), */
2283
+ "siteContent" => array(
2284
+ "title" => __("Site Content", "gawd"),
2285
+ "childs" => array(
2286
+ "pagePath" => __("All Pages", "gawd"),
2287
+ "landingPagePath" => __("Landing Pages", "gawd"),
2288
+ ),
2289
+ "desc" => "Pages report table will provide you information about Bounces, Entrances, Pageviews, Unique Pageviews, time spent on pages, Exits and Average page loading time."
2290
+ ),
2291
+ "siteSpeed" => array(
2292
+ "title" => __("Site Speed", "gawd"),
2293
+ "childs" => array(),
2294
+ "desc" => "Shows the average load time of your website users experienced during specified date range."
2295
+ ),
2296
+ "events" => array(
2297
+ "title" => __("Events", "gawd"),
2298
+ "childs" => array(
2299
+ "eventsLabel" => __("Events by Label", "gawd"),
2300
+ "eventsAction" => __("Events by Action", "gawd"),
2301
+ "eventsCategory" => __("Events by Category", "gawd")
2302
+ ),
2303
+ "desc" => "Displays the report based on Events you set up on Google Analytics of your website. Graphs are built based on Event Labels, Categories and Actions."
2304
+ ),
2305
+ "goals" => array(
2306
+ "title" => __("Goals", "gawd"),
2307
+ "childs" => array(),
2308
+ "desc" => "Set Goals from Goal Management and review their Google Analytics reports under this tab."
2309
+ ),
2310
+ "ecommerce" => array(
2311
+ "title" => __("Ecommerce", "gawd"),
2312
+ "childs" => array(
2313
+ "daysToTransaction" => __("TIme to Purchase", "gawd"),
2314
+ "transactionId" => __("Transaction ID", "gawd"),
2315
+ "sales_performance" => __("Sales Performance", "gawd"),
2316
+ "productSku" => __("Product Sku", "gawd"),
2317
+ "productCategory" => __("Product Category ", "gawd"),
2318
+ "productName" => __("Product Name", "gawd"),
2319
+ ),
2320
+ "desc" => "Check sales statistics of your website identified by revenues, transactions, products and performance."
2321
+ ),
2322
+ "adsense" => array(
2323
+ "title" => __("AdSense", "gawd"),
2324
+ "childs" => array(),
2325
+ "desc" => "Link your Google Analytics and AdSense accounts from Google Analytics Admin setting and keep track of AdSense tracking under this report."
2326
+ ),
2327
+ "customReport" => array(
2328
+ "title" => __("Custom Report", "gawd"),
2329
+ "childs" => $custom_report,
2330
+ "desc" => "Add Custom Reports from any metric and dimension in Custom Reports page, and view relevant Google Analytics tracking information in this tab."
2331
+ ),
2332
+ );
2333
+ update_option('gawd_menu_items', $tabs);
2334
+ }
2335
 
2336
+ public function remove_zoom_message()
2337
+ {
2338
+ check_ajax_referer('gawd_admin_page_nonce', 'security');
2339
+ $got_it = isset($_REQUEST["got_it"]) ? sanitize_text_field($_REQUEST["got_it"]) : '';
2340
+ if ($got_it != '') {
2341
+ add_option('gawd_zoom_message', $got_it);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2342
  }
 
 
 
2343
  }
2344
 
2345
+ public function check_property_delete()
2346
+ {
2347
+ global $gawd_client;
2348
+ $gawd_client = GAWD_google_client::get_instance();
2349
+ $accountId = $gawd_client->get_default_accountId();
2350
+ $webPropertyId = $gawd_client->get_default_webPropertyId();
2351
+ $screen = get_current_screen();
2352
+ if (strpos($screen->base, 'gawd') !== false && $accountId != null && $webPropertyId != null) {
2353
+ try {
2354
+ $deleted = $gawd_client->analytics_member->management_webproperties->get($accountId, $webPropertyId);
2355
+ } catch (Exception $e) {
2356
+ if (strpos($e->getMessage(), 'not found.') !== false) {
2357
+ echo '<div class="notice notice-error"><p>You have deleted your web-properties with current site url, please <a href="' . admin_url() . 'admin.php?page=gawd_settings">reauthenticate</a>. </p></div>';
2358
+ }
2359
+ }
2360
+ }
2361
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2362
 
2363
+ /**
2364
+ * Checks if the protocol is secure.
2365
+ *
2366
+ * @return boolean
2367
+ */
2368
+ public static function is_ssl()
2369
+ {
2370
+ if (isset($_SERVER['HTTPS'])) {
2371
+ if ('on' == strtolower($_SERVER['HTTPS'])) {
2372
+ return true;
2373
+ }
2374
+ if ('1' == $_SERVER['HTTPS']) {
2375
+ return true;
2376
+ }
2377
+ } elseif (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) {
2378
+ return true;
2379
+ }
2380
+ return false;
2381
+ }
2382
 
2383
+ /**
2384
+ * Returns the Singleton instance of this class.
2385
+ *
2386
+ * @return GAWD The Singleton instance.
2387
+ */
2388
+ public static function get_instance()
2389
+ {
2390
+ if (null === self::$instance) {
2391
+ self::$instance = new self();
2392
+ }
2393
+ return self::$instance;
2394
+ }
2395
 
2396
+ /**
2397
+ * Private clone method to prevent cloning of the instance of the
2398
+ * Singleton instance.
2399
+ *
2400
+ * @return void
2401
+ */
2402
+ private function __clone()
2403
+ {
2404
+ }
2405
 
2406
+ /**
2407
+ * Private unserialize method to prevent unserializing of the Singleton
2408
+ * instance.
2409
+ *
2410
+ * @return void
2411
+ */
2412
+ private function __wakeup()
2413
+ {
2414
+ }
2415
  }
google-analytics-wd.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Google Analytics
5
  * Plugin URI: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
6
  * Description: Google Analytics WD is a user-friendly all in one plugin, which allows to manage and monitor your website analytics from WordPress dashboard.
7
- * Version: 1.0.11
8
  * Author: WebDorado
9
  * Author URI: https://web-dorado.com
10
  * License: GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
@@ -26,7 +26,7 @@ if (!defined('GAWD_INC')) {
26
  }
27
 
28
  if (!defined('GAWD_VERSION')) {
29
- define('GAWD_VERSION', '1.0.11');
30
  }
31
 
32
  require_once( 'gawd_class.php' );
4
  * Plugin Name: Google Analytics
5
  * Plugin URI: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
6
  * Description: Google Analytics WD is a user-friendly all in one plugin, which allows to manage and monitor your website analytics from WordPress dashboard.
7
+ * Version: 1.0.12
8
  * Author: WebDorado
9
  * Author URI: https://web-dorado.com
10
  * License: GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
26
  }
27
 
28
  if (!defined('GAWD_VERSION')) {
29
+ define('GAWD_VERSION', '1.0.12');
30
  }
31
 
32
  require_once( 'gawd_class.php' );
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === Google Analytics ===
2
  Contributors: webdorado
3
  Donate link: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
4
  Tags: google analytics, google analytics dashboard, statistics, tracking, analytics, analytics dashboard, stats, ga, googleanalytics, ecommerce tracking, custom reports, custom dimensions
5
  Requires at least: 3.9
6
- Tested up to: 4.6
7
- Stable tag: 1.0.11
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -100,6 +100,9 @@ Upgrade to Google Analytics WD Pro for premium features:
100
 
101
  == Changelog ==
102
 
 
 
 
103
  = 1.0.11 =
104
  Added: Custom code option in tracking
105
 
1
+ === Google Analytics ===
2
  Contributors: webdorado
3
  Donate link: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
4
  Tags: google analytics, google analytics dashboard, statistics, tracking, analytics, analytics dashboard, stats, ga, googleanalytics, ecommerce tracking, custom reports, custom dimensions
5
  Requires at least: 3.9
6
+ Tested up to: 4.7
7
+ Stable tag: 1.0.12
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
100
 
101
  == Changelog ==
102
 
103
+ = 1.0.12 =
104
+ Fixed: Bug on report by individual post/page
105
+
106
  = 1.0.11 =
107
  Added: Custom code option in tracking
108