WD Google Analytics - Version 1.0.4

Version Description

Fixed: Unauthenticate issue
Fixed: Errors for php version < 5.3

Download this release

Release Info

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

Code changes from version 1.0.3 to 1.0.4

admin/gawd_google_class.php CHANGED
@@ -18,8 +18,8 @@ class GAWD_google_client {
18
  $this->analytics_member = new Google_Service_Analytics($this->google_client);
19
 
20
  }catch(Google_Service_Exception $e){
21
-
22
- return $e->getErrors()[0]["message"];
23
  }catch(Exception $e){
24
  return $e->getMessage();
25
  }
@@ -85,8 +85,8 @@ class GAWD_google_client {
85
  if ($profiles instanceof Google_Service_Exception) {
86
 
87
  delete_option('gawd_user_data');
88
-
89
- return $profiles->getErrors()[0]["message"];
90
  }
91
 
92
 
@@ -100,7 +100,8 @@ class GAWD_google_client {
100
  }
101
  } catch (Google_Service_Exception $e) {
102
  delete_option('gawd_user_data');
103
- return $e->getErrors()[0]["message"];
 
104
  } catch (Exception $e) {
105
  return $e->getMessage();
106
  }
@@ -238,26 +239,31 @@ class GAWD_google_client {
238
  $gawd_user_data = get_option('gawd_user_data');
239
  try{
240
 
241
- $web_properties = $this->analytics_member->management_webproperties->listManagementWebproperties('~all')->getItems();
242
- $profiles = $this->analytics_member->management_profiles->listManagementProfiles('~all', '~all')->getItems();
243
- $profiles_count = count($profiles);
244
- $web_properties_count = count($web_properties);
245
- for ($i = 0; $i < $web_properties_count; $i++) {
246
- for ($j = 0; $j < $profiles_count; $j++) {
247
- if ($web_properties[$i]['id'] == $profiles[$j]['webPropertyId']) {
248
- $profiles_light[$web_properties[$i]['name']][] = array(
249
- 'id' => $profiles[$j]['id'],
250
- 'name' => $profiles[$j]['name'],
251
- 'webPropertyId' => $profiles[$j]['webPropertyId'],
252
- 'websiteUrl' => $profiles[$j]['websiteUrl'],
253
- 'accountId' => $profiles[$j]['accountId']
254
- );
255
- }
256
- }
257
- }
 
 
 
 
258
  if (!isset($gawd_user_data['gawd_id']) || $gawd_user_data['gawd_id'] == '' || $gawd_user_data['gawd_id'] == NULL) {
259
  if (!empty($profiles_light)) {
260
- $first_profile = reset($profiles_light)[0];
 
261
  $gawd_user_data['gawd_id'] = $first_profile['id'];
262
  $gawd_user_data['webPropertyId'] = $first_profile['webPropertyId'];
263
  $gawd_user_data['accountId'] = $first_profile['accountId'];
@@ -1354,7 +1360,8 @@ class GAWD_google_client {
1354
  $profiles_light = get_transient('gawd_user_profiles') ? get_transient('gawd_user_profiles') : $this->gawd_user_data['gawd_profiles'];
1355
  if (!isset($this->gawd_user_data['gawd_id']) || $this->gawd_user_data['gawd_id'] == '') {
1356
  if (!empty($profiles_light)) {
1357
- $first_profile = reset($profiles_light)[0];
 
1358
  $this->gawd_user_data['gawd_id'] = $first_profile['id'];
1359
  }
1360
  }
@@ -1385,7 +1392,8 @@ class GAWD_google_client {
1385
  $analytics = $this->analytics_member;
1386
  $profileId = $this->get_profile_id();
1387
  $metric = $dimension == 'pagePath' || $dimension == 'PagePath' ? 'ga:pageviews,ga:uniquePageviews,ga:avgTimeOnPage,ga:entrances,ga:bounceRate,ga:exitRate,ga:pageValue,ga:avgPageLoadTime' : 'ga:sessions,ga:percentNewSessions,ga:newUsers,ga:bounceRate,ga:pageviewsPerSession,ga:avgSessionDuration,ga:transactions,ga:transactionRevenue,ga:transactionsPerSession';
1388
- $sort = '-'.explode(',', $metric)[0];
 
1389
 
1390
  try {
1391
  $results = $analytics->data_ga->get(
18
  $this->analytics_member = new Google_Service_Analytics($this->google_client);
19
 
20
  }catch(Google_Service_Exception $e){
21
+ $errors = $e->getErrors();
22
+ return $errors[0]["message"];
23
  }catch(Exception $e){
24
  return $e->getMessage();
25
  }
85
  if ($profiles instanceof Google_Service_Exception) {
86
 
87
  delete_option('gawd_user_data');
88
+ $errors = $profiles->getErrors();
89
+ return $errors[0]["message"];
90
  }
91
 
92
 
100
  }
101
  } catch (Google_Service_Exception $e) {
102
  delete_option('gawd_user_data');
103
+ $errors = $e->getErrors();
104
+ return $errors[0]["message"];
105
  } catch (Exception $e) {
106
  return $e->getMessage();
107
  }
239
  $gawd_user_data = get_option('gawd_user_data');
240
  try{
241
 
242
+ if($this->analytics_member && $this->analytics_member->management_webproperties) {
243
+ $web_properties = $this->analytics_member->management_webproperties->listManagementWebproperties( '~all' )->getItems();
244
+ $profiles = $this->analytics_member->management_profiles->listManagementProfiles( '~all', '~all' )->getItems();
245
+ $profiles_count = count( $profiles );
246
+ $web_properties_count = count( $web_properties );
247
+ for ( $i = 0; $i < $web_properties_count; $i ++ ) {
248
+ for ( $j = 0; $j < $profiles_count; $j ++ ) {
249
+ if ( $web_properties[ $i ]['id'] == $profiles[ $j ]['webPropertyId'] ) {
250
+ $profiles_light[ $web_properties[ $i ]['name'] ][] = array(
251
+ 'id' => $profiles[ $j ]['id'],
252
+ 'name' => $profiles[ $j ]['name'],
253
+ 'webPropertyId' => $profiles[ $j ]['webPropertyId'],
254
+ 'websiteUrl' => $profiles[ $j ]['websiteUrl'],
255
+ 'accountId' => $profiles[ $j ]['accountId']
256
+ );
257
+ }
258
+ }
259
+ }
260
+ }else{
261
+ return 'Something went wrong';
262
+ }
263
  if (!isset($gawd_user_data['gawd_id']) || $gawd_user_data['gawd_id'] == '' || $gawd_user_data['gawd_id'] == NULL) {
264
  if (!empty($profiles_light)) {
265
+ $first_profiles = reset($profiles_light);
266
+ $first_profile = $first_profiles[0];
267
  $gawd_user_data['gawd_id'] = $first_profile['id'];
268
  $gawd_user_data['webPropertyId'] = $first_profile['webPropertyId'];
269
  $gawd_user_data['accountId'] = $first_profile['accountId'];
1360
  $profiles_light = get_transient('gawd_user_profiles') ? get_transient('gawd_user_profiles') : $this->gawd_user_data['gawd_profiles'];
1361
  if (!isset($this->gawd_user_data['gawd_id']) || $this->gawd_user_data['gawd_id'] == '') {
1362
  if (!empty($profiles_light)) {
1363
+ $first_profiles = reset($profiles_light);
1364
+ $first_profile = $first_profiles[0];
1365
  $this->gawd_user_data['gawd_id'] = $first_profile['id'];
1366
  }
1367
  }
1392
  $analytics = $this->analytics_member;
1393
  $profileId = $this->get_profile_id();
1394
  $metric = $dimension == 'pagePath' || $dimension == 'PagePath' ? 'ga:pageviews,ga:uniquePageviews,ga:avgTimeOnPage,ga:entrances,ga:bounceRate,ga:exitRate,ga:pageValue,ga:avgPageLoadTime' : 'ga:sessions,ga:percentNewSessions,ga:newUsers,ga:bounceRate,ga:pageviewsPerSession,ga:avgSessionDuration,ga:transactions,ga:transactionRevenue,ga:transactionsPerSession';
1395
+ $sorts = '-'.explode(',', $metric);
1396
+ $sort = $sorts[0];
1397
 
1398
  try {
1399
  $results = $analytics->data_ga->get(
admin/pages/goals.php CHANGED
@@ -1,6 +1,16 @@
1
  <?php
2
- $profiles = $gawd_client->get_default_profiles();
3
- $goals = $gawd_client->get_default_goals();
 
 
 
 
 
 
 
 
 
 
4
  if (!is_array($goals)) {
5
  $goals = array();
6
  }
@@ -186,7 +196,9 @@ if (!is_array($goals)) {
186
  <input class="button_gawd" type="button" name="add_goal" value="Save"/>
187
  </div>
188
  <?php wp_nonce_field('gawd_save_form', 'gawd_save_form_fild'); ?>
189
- <input class="goal_max_id" id="goal_max_id" name="goal_max_id" type="hidden" value="<?php echo count($goals[$profile_id]);?>"/>
 
 
190
 
191
  </form>
192
  <?php if (!empty($goals)) {
1
  <?php
2
+ try{
3
+ $profiles = $gawd_client->get_default_profiles();
4
+ }catch (Exception $e){
5
+ $profiles = array();
6
+ }
7
+ try{
8
+ $goals = $gawd_client->get_default_goals();
9
+ }catch (Exception $e){
10
+ $goals = array();
11
+ }
12
+
13
+
14
  if (!is_array($goals)) {
15
  $goals = array();
16
  }
196
  <input class="button_gawd" type="button" name="add_goal" value="Save"/>
197
  </div>
198
  <?php wp_nonce_field('gawd_save_form', 'gawd_save_form_fild'); ?>
199
+ <?php if (!empty($goals)) {?>
200
+ <input class="goal_max_id" id="goal_max_id" name="goal_max_id" type="hidden" value="<?php echo count($goals[$profile_id]);?>"/>
201
+ <?php } ?>
202
 
203
  </form>
204
  <?php if (!empty($goals)) {
admin/pages/tracking.php CHANGED
@@ -1,13 +1,17 @@
1
  <?php
2
  $gawd_settings = get_option('gawd_settings');
3
  if (isset($gawd_user_data['default_webPropertyId'])) {
4
- $tracking_dimensions = $gawd_client->get_custom_dimensions_tracking();
5
  } else {
6
- $tracking_dimensions = 'no_custom_dimensions_exist';
 
 
 
 
 
7
  }
8
- $existing_custom_dimensions = $gawd_client->get_custom_dimensions('default');
9
  if (!is_array($existing_custom_dimensions)) {
10
- $existing_custom_dimensions = array();
11
  }
12
  $supported_dimensions = array("Logged in","Post type","Author","Category","Tags","Published Month","Published Year");
13
  $ua_code = isset($gawd_user_data['default_webPropertyId']) ? $gawd_user_data['default_webPropertyId'] : '';
1
  <?php
2
  $gawd_settings = get_option('gawd_settings');
3
  if (isset($gawd_user_data['default_webPropertyId'])) {
4
+ $tracking_dimensions = $gawd_client->get_custom_dimensions_tracking();
5
  } else {
6
+ $tracking_dimensions = 'no_custom_dimensions_exist';
7
+ }
8
+ try{
9
+ $existing_custom_dimensions = $gawd_client->get_custom_dimensions('default');
10
+ }catch (Exception $e){
11
+ $existing_custom_dimensions = array();
12
  }
 
13
  if (!is_array($existing_custom_dimensions)) {
14
+ $existing_custom_dimensions = array();
15
  }
16
  $supported_dimensions = array("Logged in","Post type","Author","Category","Tags","Published Month","Published Year");
17
  $ua_code = isset($gawd_user_data['default_webPropertyId']) ? $gawd_user_data['default_webPropertyId'] : '';
gawd_class.php CHANGED
@@ -1,1136 +1,1200 @@
1
  <?php
2
 
3
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
4
 
5
  class GAWD {
6
 
7
- /**
8
- * @var GAWD The reference to Singleton instance of this class
9
- */
10
- private static $instance;
11
- private $project_client_id = null;
12
- private $project_client_secret = null;
13
- public $redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
14
-
15
- /**
16
- * Protected constructor to prevent creating a new instance of the
17
- * Singleton via the `new` operator from outside of this class.
18
- */
19
- protected function __construct() {
20
-
21
- if(isset($_POST["reset_data"]) && $_POST["reset_data"] != ''){
22
- $this->reset_user_data();
23
- }
24
- add_action('admin_menu', array($this, 'gawd_check_id'), 1);
25
-
26
- add_action('admin_notices', array($this, 'upgrade_pro'));
27
-
28
- add_action('admin_menu', array($this, 'gawd_add_menu'), 19);
29
- add_action('admin_enqueue_scripts', array($this, 'gawd_enqueue_scripts'));
30
-
31
- add_action('wp_ajax_gawd_auth', array($this, 'gawd_auth'));
32
- add_action('wp_ajax_create_pdf_file', array($this, 'create_pdf_file'));
33
- add_action('wp_ajax_create_csv_file', array($this, 'create_csv_file'));
34
- add_action('wp_ajax_show_data', array($this, 'show_data'));
35
- add_action('wp_ajax_remove_zoom_message', array($this, 'remove_zoom_message'));
36
- add_action('wp_ajax_show_page_post_data', array($this, 'show_page_post_data'));
37
- add_action('wp_ajax_show_data_compact', array($this, 'show_data_compact'));
38
- add_action('wp_ajax_get_realtime', array($this, 'get_realtime'));
39
- add_action('wp_dashboard_setup', array($this, 'google_analytics_wd_dashboard_widget'));
40
- add_action('admin_menu', array($this, 'overview_date_meta'));
41
- add_filter('cron_schedules', array($this, 'gawd_my_schedule'));
42
- add_action('admin_init', array($this, 'gawd_export'));
43
- add_action('gawd_pushover_daily', array($this, 'gawd_pushover_daily'));
44
- add_action('gawd_pushover_gawd_weekly', array($this, 'gawd_pushover_weekly'));
45
- add_action('gawd_pushover_gawd_monthly', array($this, 'gawd_pushover_monthly'));
46
- add_action('gawd_alert_daily', array($this, 'gawd_alert_daily'));
47
- add_action('gawd_alert_gawd_monthly', array($this, 'gawd_alert_monthly'));
48
- add_action('gawd_alert_gawd_weekly', array($this, 'gawd_alert_weekly'));
49
- add_action('gawd_email_daily', array($this, 'gawd_daily_email'), 0);
50
- add_action('gawd_email_gawd_weekly', array($this, 'gawd_weekly_email'));
51
- add_action('gawd_email_gawd_monthly', array($this, 'gawd_monthly_email'));
52
- //add_action('init', array($this, 'gawd_daily_email'));
53
- add_action('wp_head', array($this, 'gawd_tracking_code'), 99);
54
- $gawd_settings = get_option('gawd_settings');
55
- $gawd_post_page_roles = isset($gawd_settings['gawd_post_page_roles']) ? $gawd_settings['gawd_post_page_roles'] : array();
56
- $roles = $this->get_current_user_role();
57
- 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'))){
58
- add_filter('manage_posts_columns', array($this, 'gawd_add_columns'));
59
- // Populate custom column in Posts List
60
- add_action('manage_posts_custom_column', array($this, 'gawd_add_icons'), 10, 2);
61
- // Add custom column in Pages List
62
- add_filter('manage_pages_columns', array($this, 'gawd_add_columns'));
63
- // Populate custom column in Pages List
64
- add_action('manage_pages_custom_column', array($this, 'gawd_add_icons'), 10, 2);
65
- add_action('add_meta_boxes', array($this, 'gawd_add_custom_box'));
66
- }
67
- $gawd_frontend_roles = isset( $gawd_settings['gawd_frontend_roles'] ) ? $gawd_settings['gawd_frontend_roles'] : array();
68
- if ( ( isset( $gawd_settings['gawd_tracking_enable'] ) && $gawd_settings['gawd_tracking_enable'] == 'on' ) && ( in_array( $roles, $gawd_frontend_roles ) || current_user_can( 'manage_options' ) ) ) {
69
- add_action( 'wp_enqueue_scripts', array( $this, 'gawd_front_scripts' ) );
70
- add_action( 'admin_bar_menu', array( $this, 'report_adminbar' ), 999 );
71
- }
72
-
73
-
74
- $this->update_credentials();
75
- $credentials = get_option('gawd_credentials');
76
-
77
-
78
- if (is_array($credentials)) {
79
- $this->set_project_client_id($credentials['project_id']);
80
- $this->set_project_client_secret($credentials['project_secret']);
81
- } else {
82
- //send error
83
- return;
84
- }
85
-
86
- }
87
-
88
- function get_current_user_role() {
89
- global $wp_roles;
90
- if ( is_user_logged_in() ) {
91
- $current_user = wp_get_current_user();
92
- $roles = $current_user->roles;
93
- $role = array_shift( $roles );
94
-
95
- return $role;
96
- } else {
97
- return "";
98
- }
99
- }
100
-
101
-
102
- function report_adminbar($wp_admin_bar) {
103
- /* @formatter:off */
104
- $gawd_settings = get_option('gawd_settings');
105
- $gawd_frontend_roles = isset($gawd_settings['gawd_frontend_roles']) ? $gawd_settings['gawd_frontend_roles'] : array();
106
- $roles = $this->get_current_user_role();
107
- if (((in_array($roles, $gawd_frontend_roles) || current_user_can('manage_options')) && !is_admin()) && $gawd_settings['post_page_chart'] != '') {
108
- $id = get_the_ID();
109
- $uri_parts = explode('/', get_permalink($id), 4);
110
- if ($uri_parts[0] != '') {
111
- if (isset($uri_parts[3])) {
112
- $uri = '/' . $uri_parts[3];
113
- }
114
- $uri = explode('/', $uri);
115
- end($uri);
116
- $key = key($uri);
117
- $uri = '/' . $uri[$key - 1];
118
- $filter = rawurlencode(rawurldecode($uri));
119
-
120
- $args = array('id' => 'gawd',
121
- 'title' => '<span data-url="' . $filter . '" class="ab-icon"></span><span class="">' . __("Analytics WD", 'gawd') . '</span>',
122
- 'href' => '#1',
123
- );
124
- /* @formatter:on */
125
- $wp_admin_bar->add_node($args);
126
- }
127
- }
128
- }
129
-
130
- public function update_credentials() {
131
- //check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
132
- if ($_POST) {
133
- $gawd_own_project = isset($_POST['gawd_own_project']) ? $_POST['gawd_own_project'] : '';
134
- $gawd_own_client_id = isset($_POST['gawd_own_client_id']) ? $_POST['gawd_own_client_id'] : '';
135
- $gawd_own_client_secret = isset($_POST['gawd_own_client_secret']) ? $_POST['gawd_own_client_secret'] : '';
136
- $gawd_credentials['project_id'] = $gawd_own_client_id;
137
- $gawd_credentials['project_secret'] = $gawd_own_client_secret;
138
- if ($gawd_own_project && $gawd_own_client_id != '' && $gawd_own_client_secret != '') {
139
- update_option('gawd_credentials', $gawd_credentials);
140
- delete_option('gawd_user_data');
141
- add_option('gawd_own_project' , 1);
142
- }
143
- }
144
- }
145
-
146
- public function set_project_client_id($id) {
147
- $this->project_client_id = $id;
148
- }
149
-
150
- public function get_project_client_id() {
151
- return $this->project_client_id;
152
- }
153
-
154
- public function set_project_client_secret($secret) {
155
- $this->project_client_secret = $secret;
156
- }
157
-
158
- public function get_project_client_secret() {
159
- return $this->project_client_secret;
160
- }
161
-
162
- function gawd_check_id() {
163
- global $gawd_redirect_to_settings;
164
- $current_page = isset($_GET['page'])?$_GET['page']:"";
165
- if (strpos($current_page, 'gawd')!==false) {
166
- $gawd_user_data = get_option('gawd_user_data');
167
- if (!isset($gawd_user_data['refresh_token']) || ($gawd_user_data['refresh_token'] == '')) {
168
- update_option('gawd_redirect_to_settings', 'yes');
169
- }else{
170
- update_option('gawd_redirect_to_settings', 'no');
171
- }
172
- }
173
- $gawd_redirect_to_settings = get_option('gawd_redirect_to_settings');
174
- }
175
-
176
- function gawd_add_custom_box() {
177
- $screens = array('post', 'page');
178
- foreach ($screens as $screen)
179
- add_meta_box('gawd_page_post_meta', 'Sessions in month', array($this, 'gawd_add_custom_box_callback'), $screen, 'normal');
180
- }
181
-
182
- function gawd_add_custom_box_callback() {
183
- require_once( 'admin/post_page_view.php' );
184
- }
185
-
186
- public function gawd_add_icons($column, $id) {
187
- if ($column != 'gawd_stats') {
188
- return;
189
- }
190
- $uri_parts = explode('/', get_permalink($id), 4);
191
- if (isset($uri_parts[3])) {
192
- $uri = '/' . $uri_parts[3];
193
- }
194
- $uri = explode('/', $uri);
195
- end($uri);
196
- $key = key($uri);
197
- $uri = '/' . $uri[$key - 1];
198
- $filter = rawurlencode(rawurldecode($uri));
199
- 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>';
200
- }
201
-
202
- public function gawd_add_columns($columns) {
203
- return array_merge($columns, array('gawd_stats' => __('Analytics WD', 'gawd')));
204
- }
205
-
206
- public static function gawd_roles($access_level, $tracking = false) {
207
- if (is_user_logged_in() && isset($access_level)) {
208
- $current_user = wp_get_current_user();
209
- $roles = (array) $current_user->roles;
210
- if (( current_user_can('manage_options') ) && !$tracking) {
211
- return true;
212
- }
213
- if (count(array_intersect($roles, $access_level)) > 0) {
214
- return true;
215
- } else {
216
- return false;
217
- }
218
- }
219
- return false;
220
- }
221
-
222
- public function gawd_tracking_code() {
223
- $gawd_user_data = get_option('gawd_user_data');
224
- if (isset($gawd_user_data['default_webPropertyId']) && ($gawd_user_data['default_webPropertyId'])) {
225
- global $gawd_client;
226
- $gawd_client = GAWD_google_client::get_instance();
227
- require_once(GAWD_DIR . '/admin/tracking.php');
228
- }
229
- }
230
-
231
- public function create_pdf_file($ajax=true,$data = null,$dimension = null, $start_date = null, $end_date = null,$metric_compare_recc = null, $metric_recc = null) {
232
- $first_data = isset($_REQUEST["first_data"]) ? sanitize_text_field($_REQUEST["first_data"]) : '';
233
- $_data_compare = isset($_REQUEST["_data_compare"]) ? ($_REQUEST["_data_compare"]) : '';
234
- if($ajax == true){
235
- $export_type = isset($_REQUEST["export_type"]) ? sanitize_text_field($_REQUEST["export_type"]) : '';
236
- if ($export_type != 'pdf') {
237
- return;
238
- }
239
 
240
- $report_type = isset($_REQUEST["report_type"]) ? sanitize_text_field($_REQUEST["report_type"]) : '';
241
 
 
 
242
 
243
- if ($report_type !== 'alert') {
244
- return;
245
- }
246
 
247
- }
 
 
 
 
 
 
 
 
248
 
249
- include_once GAWD_DIR . '/include/gawd_pdf_file.php';
250
- $file = new GAWD_PDF_FILE();
 
 
 
 
251
 
252
- /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  require_once(GAWD_DIR . '/admin/gawd_google_class.php');
254
  $this->gawd_google_client = GAWD_google_client::get_instance();
255
  */
256
- $file->get_request_data($this,$ajax,$data,$dimension, $start_date, $end_date,$metric_compare_recc, $metric_recc );
257
-
258
- $file->sort_data();
259
- if($first_data != ''){
260
- $file->create_file('pages');
261
- }
262
- elseif(($_data_compare) != ''){
263
- $file->create_file('compare');
264
- }
265
- else{
266
- $file->create_file(true);
267
- }
268
- if($ajax == true){
269
- die();
270
- }
271
- else{
272
- return $file->file_dir;
273
- }
274
- }
275
- public function create_csv_file($ajax=true,$data = null,$dimension = null, $start_date = null, $end_date = null, $metric_compare_recc = null, $metric_recc = null){
276
- if($ajax == true){
277
- $export_type = isset($_REQUEST["export_type"]) ? sanitize_text_field($_REQUEST["export_type"]) : '';
278
- if ($export_type != 'csv') {
279
- return;
280
- }
281
- $report_type = isset($_REQUEST["report_type"]) ? sanitize_text_field($_REQUEST["report_type"]) : '';
282
- if ($report_type !== 'alert') {
283
- return;
284
- }
285
- }
286
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
287
- $this->gawd_google_client = GAWD_google_client::get_instance();
288
-
289
- $first_data = isset($_REQUEST["first_data"]) ? sanitize_text_field($_REQUEST["first_data"]) : '';
290
-
291
-
292
-
293
- include_once GAWD_DIR . '/include/gawd_csv_file.php';
294
-
295
- $file = new GAWD_CSV_FILE();
296
- $file->get_request_data($this,$ajax,$data,$dimension, $start_date, $end_date,$metric_compare_recc, $metric_recc );
297
-
298
- $file->sort_data();
299
-
300
- //$file->get_request_data($this);
301
-
302
- $file->sort_data();
303
- if($first_data != ''){
304
- $file->create_file(false);
305
- }
306
- else{
307
- $file->create_file();
308
- }
309
- if($ajax == true){
310
- die();
311
- }
312
- else{
313
- return $file->file_dir;
314
- }
315
- }
316
-
317
- public static function get_domain($domain) {
318
- $root = explode('/', $domain);
319
- $ret_domain = str_ireplace('www', '', isset($root[2]) ? $root[2] : $domain );
320
- return $ret_domain;
321
- }
322
-
323
- public static function error_message($type,$message){
324
- echo '<div style="width:99%"><div class="' . $type . '"><p><strong>' . $message . '</strong></p></div></div>';
325
- }
326
- public function gawd_export() {
327
- if (!isset($_REQUEST['action']) || (isset($_REQUEST['action']) && $_REQUEST['action'] !== 'gawd_export')) {
328
- return;
329
- }
330
-
331
- $export_type = isset($_REQUEST["export_type"]) ? sanitize_text_field($_REQUEST["export_type"]) : '';
332
- if ($export_type != 'pdf' && $export_type != 'csv') {
333
- return;
334
- }
335
-
336
- $report_type = isset($_REQUEST["report_type"]) ? sanitize_text_field($_REQUEST["report_type"]) : '';
337
-
338
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
339
- $this->gawd_google_client = GAWD_google_client::get_instance();
340
-
341
- if ($export_type == 'pdf') {
342
- include_once GAWD_DIR . '/include/gawd_pdf_file.php';
343
- $file = new GAWD_PDF_FILE();
344
- } else {
345
- include_once GAWD_DIR . '/include/gawd_csv_file.php';
346
- $file = new GAWD_CSV_FILE();
347
- }
348
-
349
- if ($report_type == 'alert') {
350
- if ($export_type == 'pdf') {
351
- $file->export_file();
352
- } else {
353
- $file->export_file();
354
- }
355
- }
356
-
357
- else {
358
- $metric = isset($_REQUEST["gawd_metric"]) ? sanitize_text_field($_REQUEST["gawd_metric"]) : '';
359
- $_data_compare = isset($_REQUEST["_data_compare"]) ? ($_REQUEST["_data_compare"]) : '';
360
- $first_data = isset($_REQUEST["first_data"]) ? ($_REQUEST["first_data"]) : '';
361
- $view_id = isset($_REQUEST["view_id"]) ? sanitize_text_field($_REQUEST["view_id"]) : '';
362
- $metric_compare = isset($_REQUEST["gawd_metric_compare"]) ? sanitize_text_field($_REQUEST["gawd_metric_compare"]) : '';
363
- $dimension = isset($_REQUEST["gawd_dimension"]) ? sanitize_text_field($_REQUEST["gawd_dimension"]) : '';
364
- $tab_name = isset($_REQUEST["tab_name"]) ? sanitize_text_field($_REQUEST["tab_name"]) : '';
365
- $img = isset($_REQUEST["img"]) ? sanitize_text_field($_REQUEST["img"]) : '';
366
- $gawd_email_subject = isset($_REQUEST["gawd_email_subject"]) ? sanitize_text_field($_REQUEST["gawd_email_subject"]) : '';
367
- $gawd_email_body = isset($_REQUEST["gawd_email_body"]) && $_REQUEST["gawd_email_body"] != '' ? sanitize_text_field($_REQUEST["gawd_email_body"]) : ' ';
368
- $email_from = isset($_REQUEST["gawd_email_from"]) ? sanitize_email($_REQUEST["gawd_email_from"]) : '';
369
- $email_to = isset($_REQUEST["gawd_email_to"]) ? sanitize_email($_REQUEST["gawd_email_to"]) : '';
370
- $email_period = isset($_REQUEST["gawd_email_period"]) ? sanitize_text_field($_REQUEST["gawd_email_period"]) : '';
371
- $week_day = isset($_REQUEST["gawd_email_week_day"]) ? sanitize_text_field($_REQUEST["gawd_email_week_day"]) : '';
372
- $month_day = isset($_REQUEST["gawd_email_month_day"]) ? sanitize_text_field($_REQUEST["gawd_email_month_day"]) : '';
373
- $emails = array();
374
- $invalid_email = false;
375
- $email_to = explode(',', $email_to);
376
- foreach ($email_to as $email) {
377
- if (is_email($email) == false) {
378
- $emails = $email;
379
- }
380
- }
381
- if (count($emails) > 0) {
382
- $invalid_email = true;
383
- }
384
- if (($invalid_email != true) && is_email($email_from) && $gawd_email_subject != '') {
385
- if ($email_period == "once") {
386
- $file->get_request_data($this);
387
- $file->sort_data();
388
- if($export_type == 'csv'){
389
- if($first_data != ''){
390
- $file->create_file(false);
391
- }
392
- else{
393
- $file->create_file();
394
- }
395
- }
396
- else{
397
- if($first_data != ''){
398
- $file->create_file('pages');
399
- }
400
- elseif(($_data_compare) != ''){
401
- $file->create_file('compare');
402
- }
403
- else{
404
- $file->create_file(false);
405
- }
406
- }
407
- $attachment = $file->file_dir;
408
 
409
- if ($report_type == 'email') {
410
- $headers = 'From: <' . $email_from . '>';
411
- wp_mail($email_to, $gawd_email_subject, $gawd_email_body, $headers, $attachment);
412
- }
413
- echo json_encode( array('status'=>'success','msg'=>'Email successfuly sent'));
414
- }
415
- else {
416
- if ($email_period == 'gawd_weekly') {
417
- $period_day = $week_day;
418
- $timestamp = strtotime('this ' . $period_day);
419
- }
420
- elseif ($email_period == 'gawd_monthly') {
421
- $period_day = $month_day;
422
- $timestamp = strtotime(date('Y-m-' . $period_day));
423
- }
424
- else {
425
- $period_day = '';
426
- $timestamp = time();
427
- }
428
- $saved_email = get_option('gawd_email');
429
- if ($saved_email) {
430
- $gawd_email_options = array('name' => $gawd_email_subject, 'period' => $email_period, 'metric' => $metric, 'metric_compare' => $metric_compare, 'dimension' => $dimension, 'creation_date' => date('Y-m-d'), 'emails' => $email_to, 'email_from' => $email_from, 'email_subject' => $gawd_email_subject, 'email_body' => $gawd_email_body, 'period_day' => $period_day, 'img' => $img, 'tab_name' => $tab_name, 'view_id' => $view_id, 'export_type' => $export_type);
431
- $saved_email[] = $gawd_email_options;
432
- update_option('gawd_email', $saved_email);
433
- }
434
- else {
435
- $gawd_email_options = array(0 => array('name' => $gawd_email_subject, 'period' => $email_period, 'metric' => $metric, 'metric_compare' => $metric_compare, 'dimension' => $dimension, 'creation_date' => date('Y-m-d'), 'emails' => $email_to, 'email_from' => $email_from, 'email_subject' => $gawd_email_subject, 'email_body' => $gawd_email_body, 'period_day' => $period_day, 'img' => $img, 'tab_name' => $tab_name, 'view_id' => $view_id, 'export_type' => $export_type));
436
- update_option('gawd_email', $gawd_email_options);
437
- }
438
- $saved_email = get_option('gawd_email');
439
- if ($saved_email) {
440
- foreach ($saved_email as $email) {
441
- if (!wp_next_scheduled('gawd_email_' . $email['period'])) {
442
- wp_schedule_event($timestamp, $email['period'], 'gawd_email_' . $email['period']);
443
- }
444
- }
445
- }
446
- $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.';
447
- echo json_encode( array('status'=>'success','msg'=>$success_message));
448
- }
449
 
450
- die;
451
- }
452
- else {
453
- if ($invalid_email == true) {
454
- echo json_encode('Invalid email');
455
- die;
456
- }
457
- else if ($gawd_email_subject == '') {
458
- echo json_encode("Can't send email with empty subject");
459
- die;
460
- }
461
- }
462
- }
463
- }
464
-
465
- public function overview_date_meta($screen = null, $context = 'advanced') {
466
- //righ side wide meta..
467
- $orintation = wp_is_mobile() ? 'side' : 'normal';
468
- add_meta_box('gawd-real-time', __('Real Time', 'gawd'), array($this, 'gawd_real_time'), 'gawd_analytics', 'side', 'high');
469
- add_meta_box('gawd-date-meta', __('Audience', 'gawd'), array($this, 'gawd_date_box'), 'gawd_analytics', $orintation, null);
470
- add_meta_box('gawd-country-box', __('Location', 'gawd'), array($this, 'gawd_country_box'), 'gawd_analytics', $orintation, null);
471
- //left side thin meta.
472
- add_meta_box('gawd-visitors-meta', __('Visitors', 'gawd'), array($this, 'gawd_visitors'), 'gawd_analytics', 'side', null);
473
- add_meta_box('gawd-browser-meta', __('Browsers', 'gawd'), array($this, 'gawd_browser'), 'gawd_analytics', 'side', null);
474
- }
475
-
476
- public function gawd_date_box() {
477
- require_once( 'admin/pages/date.php' );
478
- }
479
-
480
- public function gawd_country_box() {
481
- require_once( 'admin/pages/location.php' );
482
- }
483
-
484
- public function gawd_real_time() {
485
- require_once( 'admin/pages/real_time.php' );
486
- }
487
-
488
- public function gawd_visitors() {
489
- require_once( 'admin/pages/visitors.php' );
490
- }
491
-
492
- public function gawd_browser() {
493
- require_once( 'admin/pages/browser.php' );
494
- }
495
-
496
- /**
497
- * Activation function needed for the activation hook.
498
- */
499
- public static function activate() {
500
- $credentials['project_id'] = '115052745574-5vbr7tci4hjkr9clkflmnpto5jisgstg.apps.googleusercontent.com';
501
- $credentials['project_secret'] = 'wtNiu3c_bA_g7res6chV0Trt';
502
- if (!get_option('gawd_credentials')) {
503
- update_option('gawd_credentials', $credentials);
504
- }
505
- self::gawd_settings_defaults();
506
- self::add_dashboard_menu();
507
- }
508
-
509
- /**
510
- * Deactivation function needed for the deactivation hook.
511
- */
512
- public static function deactivate() {
513
-
514
- }
515
-
516
- /**
517
- * Enqueues the required styles and scripts, localizes some js variables.
518
- */
519
- public function gawd_front_scripts() {
520
- if(is_user_logged_in()) {
521
- wp_enqueue_style( 'admin_css', GAWD_URL . '/inc/css/gawd_admin.css', false, GAWD_VERSION );
522
- wp_enqueue_script( 'gawd_amcharts', GAWD_URL . '/inc/js/amcharts.js', false, GAWD_VERSION );
523
- wp_enqueue_script( 'gawd_pie', GAWD_URL . '/inc/js/pie.js', false, GAWD_VERSION );
524
- wp_enqueue_script( 'gawd_serial', GAWD_URL . '/inc/js/serial.js', false, GAWD_VERSION );
525
- wp_enqueue_script( 'gawd_light_theme', GAWD_URL . '/inc/js/light.js', array( 'jquery' ), GAWD_VERSION );
526
- wp_enqueue_script( 'gawd_dataloader', GAWD_URL . '/inc/js/dataloader.min.js', array( 'jquery' ), GAWD_VERSION );
527
- wp_enqueue_script( 'date-js', GAWD_URL . '/inc/js/date.js', array( 'jquery' ), GAWD_VERSION );
528
- wp_enqueue_script( 'gawd_front_js', GAWD_URL . '/inc/js/gawd_front.js', array( 'jquery' ), GAWD_VERSION );
529
- wp_localize_script( 'gawd_front_js', 'gawd_front', array(
530
- 'ajaxurl' => admin_url( 'admin-ajax.php' ),
531
- 'ajaxnonce' => wp_create_nonce( 'gawd_admin_page_nonce' ),
532
- 'gawd_plugin_url' => GAWD_URL,
533
- 'date_30' => date( 'Y-m-d', strtotime( '-31 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
534
- 'date_7' => date( 'Y-m-d', strtotime( '-8 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
535
- 'date_last_week' => date( 'Y-m-d', strtotime( 'last week -1day' ) ) . '/-/' . date( 'Y-m-d', strtotime( 'last week +5day' ) ),
536
- 'date_last_month' => date( 'Y-m-01', strtotime( 'last month' ) ) . '/-/' . date( 'Y-m-t', strtotime( 'last month' ) ),
537
- 'date_this_month' => date( 'Y-m-01' ) . '/-/' . date( 'Y-m-d' ),
538
- 'date_today' => date( 'Y-m-d' ) . '/-/' . date( 'Y-m-d' ),
539
- 'date_yesterday' => date( 'Y-m-d', strtotime( '-1 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
540
- 'wp_admin_url' => admin_url(),
541
- 'exportUrl' => add_query_arg( array( 'action' => 'gawd_export' ), admin_url( 'admin-ajax.php' ) )
542
- ) );
543
- }
544
- }
545
-
546
- public function gawd_enqueue_scripts() {
547
- $options = get_option('gawd_settings');
548
- $default_date = (isset($options['default_date']) && $options['default_date'] != '') ? $options['default_date'] : 'last_30days';
549
- $default_date_format = (isset($options['default_date_format']) && $options['default_date_format'] != '') ? $options['default_date_format'] : 'ymd_with_week';
550
- $enable_hover_tooltip = (isset($options['enable_hover_tooltip']) && $options['enable_hover_tooltip'] != '') ? $options['enable_hover_tooltip'] : '';
551
- $screen = get_current_screen();
552
- if (strpos($screen->base, 'gawd') !== false || strpos($screen->post_type, 'page') !== false || strpos($screen->post_type, 'post') !== false || strpos($screen->base, 'dashboard') !== false) {
553
- wp_enqueue_script('common');
554
- wp_enqueue_script('wp-lists');
555
- wp_enqueue_script('postbox');
556
- wp_enqueue_script('jquery-ui-tooltip');
557
- wp_enqueue_script('gawd_paging', GAWD_URL . '/inc/js/paging.js',false,GAWD_VERSION);
558
- wp_enqueue_script('jquery.cookie', GAWD_URL . '/inc/js/jquery.cookie.js',false,GAWD_VERSION);
559
- wp_enqueue_style('admin_css', GAWD_URL . '/inc/css/gawd_admin.css', false, GAWD_VERSION);
560
- wp_enqueue_style('gawd_licensing', GAWD_URL . '/inc/css/gawd_licensing.css', false, GAWD_VERSION);
561
- wp_enqueue_style('gawd_featured', GAWD_URL . '/featured/style.css', array(), GAWD_VERSION);
562
- wp_enqueue_style('font_awesome', GAWD_URL . '/inc/css/font_awesome.css', false, GAWD_VERSION);
563
- wp_enqueue_style('jquery-ui.css', GAWD_URL . '/inc/css/jquery-ui.css', false, GAWD_VERSION);
564
- wp_enqueue_style('gawd_bootstrap', GAWD_URL . '/inc/css/bootstrap.css', false, GAWD_VERSION);
565
- wp_enqueue_style('gawd_bootstrap-chosen', GAWD_URL . '/inc/css/bootstrap-chosen.css', false, GAWD_VERSION);
566
- wp_enqueue_style('gawd_bootstrap-select', GAWD_URL . '/inc/css/bootstrap-select.css', false, GAWD_VERSION);
567
- wp_enqueue_style('gawd_datepicker', GAWD_URL . '/inc/css/daterangepicker.css', false, GAWD_VERSION);
568
- wp_enqueue_style('ui.jqgrid.css', GAWD_URL . '/inc/css/ui.jqgrid.css', false, GAWD_VERSION);
569
- wp_enqueue_script('gawd_moment', GAWD_URL . '/inc/js/moment.min.js', false, GAWD_VERSION);
570
- wp_enqueue_script('gawd_daterangepicker', GAWD_URL . '/inc/js/daterangepicker.js', false, GAWD_VERSION);
571
- wp_enqueue_script('gawd_amcharts', GAWD_URL . '/inc/js/amcharts.js', false, GAWD_VERSION);
572
- wp_enqueue_script('ddd', 'http://www.amcharts.com/lib/3/plugins/responsive/responsive.min.js?0.9.1a', false, GAWD_VERSION);
573
- wp_enqueue_script('gawd_pie', GAWD_URL . '/inc/js/pie.js', false, GAWD_VERSION);
574
- wp_enqueue_script('gawd_serial', GAWD_URL . '/inc/js/serial.js', false, GAWD_VERSION);
575
- /*Map*/
576
- wp_enqueue_script('gawd_ammap', GAWD_URL . '/inc/js/ammap.js', false, GAWD_VERSION);
577
- wp_enqueue_script('gawd_worldLow', GAWD_URL . '/inc/js/worldLow.js', false, GAWD_VERSION);
578
- wp_enqueue_script('gawd_map_chart', GAWD_URL . '/inc/js/gawd_map_chart.js', false, GAWD_VERSION);
579
- /*End Map*/
580
- wp_enqueue_script('gawd_light_theme', GAWD_URL . '/inc/js/light.js', array('jquery'), GAWD_VERSION);
581
- wp_enqueue_script('gawd_dataloader', GAWD_URL . '/inc/js/dataloader.min.js', array('jquery'), GAWD_VERSION);
582
- wp_enqueue_script('rgbcolor.js', GAWD_URL . '/inc/js/rgbcolor.js', array('jquery'), GAWD_VERSION);
583
- wp_enqueue_script('StackBlur.js', GAWD_URL . '/inc/js/StackBlur.js', array('jquery'), GAWD_VERSION);
584
- wp_enqueue_script('canvg.js', GAWD_URL . '/inc/js/canvg.js', array('jquery'), GAWD_VERSION);
585
- wp_enqueue_script('gawd_tables', GAWD_URL . '/inc/js/loader.js', array('jquery'), GAWD_VERSION);
586
- wp_enqueue_script('gawd_grid', GAWD_URL . '/inc/js/jquery.jqGrid.min.js', array('jquery'), GAWD_VERSION);
587
- wp_enqueue_script('gawd_grid_locale', GAWD_URL . '/inc/js/grid.locale-en.js', array('jquery'), GAWD_VERSION);
588
- wp_enqueue_script('date-js', GAWD_URL . '/inc/js/date.js', array('jquery'), GAWD_VERSION);
589
- wp_enqueue_script('admin_js', GAWD_URL . '/inc/js/gawd_admin.js', array('jquery'), GAWD_VERSION);
590
- wp_enqueue_script('chosen.jquery.js', GAWD_URL . '/inc/js/chosen.jquery.js', array('jquery'), GAWD_VERSION);
591
- wp_enqueue_script('bootstrap_js', GAWD_URL . '/inc/js/bootstrap_js.js', array('jquery'), GAWD_VERSION);
592
- wp_enqueue_script('bootstrap-select', GAWD_URL . '/inc/js/bootstrap-select.js', array('jquery'), GAWD_VERSION);
593
- wp_enqueue_script('highlight_js', GAWD_URL . '/inc/js/js_highlight.js', array('jquery'), GAWD_VERSION);
594
- wp_enqueue_script('settings_js', GAWD_URL . '/inc/js/gawd_settings.js', array('jquery'), GAWD_VERSION);
595
- wp_enqueue_script('overview', GAWD_URL . '/inc/js/gawd_overview.js', array('jquery'), GAWD_VERSION);
596
- wp_localize_script('overview', 'gawd_overview', array(
597
- 'ajaxurl' => admin_url('admin-ajax.php'),
598
- 'ajaxnonce' => wp_create_nonce('gawd_admin_page_nonce'),
599
- 'gawd_plugin_url' => GAWD_URL,
600
- 'default_date' => $default_date,
601
- 'enableHoverTooltip' => $enable_hover_tooltip,
602
- 'wp_admin_url' => admin_url()
603
- ));
604
- wp_localize_script('admin_js', 'gawd_admin', array(
605
- 'ajaxurl' => admin_url('admin-ajax.php'),
606
- 'ajaxnonce' => wp_create_nonce('gawd_admin_page_nonce'),
607
- 'gawd_plugin_url' => GAWD_URL,
608
- 'wp_admin_url' => admin_url(),
609
- 'enableHoverTooltip' => $enable_hover_tooltip,
610
- 'default_date' => $default_date,
611
- 'default_date_format' => $default_date_format,
612
- 'date_30' => date('Y-m-d',strtotime('-31 day')).'/-/'.date('Y-m-d',strtotime('-1 day')),
613
- 'date_7' => date('Y-m-d',strtotime('-8 day')).'/-/'.date('Y-m-d',strtotime('-1 day')),
614
- 'date_last_week' => date('Y-m-d',strtotime('last week -1day')).'/-/'.date('Y-m-d',strtotime('last week +5day')),
615
- 'date_last_month' => date('Y-m-01',strtotime('last month')).'/-/'.date('Y-m-t',strtotime('last month')),
616
- 'date_this_month' =>date('Y-m-01').'/-/'.date('Y-m-d'),
617
- 'date_today' => date('Y-m-d').'/-/'.date('Y-m-d'),
618
- 'date_yesterday' => date('Y-m-d',strtotime('-1 day')).'/-/'.date('Y-m-d',strtotime('-1 day')),
619
- 'exportUrl' => add_query_arg(array('action' => 'gawd_export'), admin_url('admin-ajax.php'))
620
- ));
621
- }
622
- }
623
-
624
- /**
625
- * Adds the menu page with its submenus.
626
- */
627
- public function gawd_add_menu() {
628
-
629
-
630
- $gawd_settings = get_option('gawd_settings');
631
- $gawd_permissions = isset($gawd_settings['gawd_permissions']) ? $gawd_settings['gawd_permissions'] : array();
632
- if (empty($gawd_permissions)) {
633
- $permission = 'manage_options';
634
- } else {
635
- if (in_array('manage_options', $gawd_permissions)) {
636
- $permission = 'manage_options';
637
- }
638
- if (in_array('moderate_comments', $gawd_permissions)) {
639
- $permission = 'moderate_comments';
640
- }
641
- if (in_array('publish_posts', $gawd_permissions)) {
642
- $permission = 'publish_posts';
643
- }
644
- if (in_array('edit_posts', $gawd_permissions)) {
645
- $permission = 'edit_posts';
646
- }
647
- }
648
- add_menu_page(
649
- __('Analytics', 'gawd'), //$page_title
650
- __('Analytics', 'gawd'), //$menu_title
651
- $permission, //$capability
652
- 'gawd_analytics', //$menu_slug
653
- array($this, $this->gawd_set_display('gawd_display_overview_page')), //$function = '',
654
- GAWD_URL . '/assets/main_icon.png'
655
- //$position = null
656
- );
657
-
658
- add_submenu_page(
659
- 'gawd_analytics', //$parent_slug
660
- __('Overview', 'gawd'), //$page_title
661
- __('Overview', 'gawd'), //$menu_title
662
- $permission, //$capability
663
- $this->gawd_set_slug('gawd_analytics'), //$menu_slug
664
- array($this, $this->gawd_set_display('gawd_display_overview_page')) //$function = '',
665
- );
666
- add_submenu_page(
667
- 'gawd_analytics', //$parent_slug
668
- __('Reports', 'gawd'), //$page_title
669
- __('Reports', 'gawd'), //$menu_title
670
- $permission, //$capability
671
- $this->gawd_set_slug('gawd_reports'), //$menu_slug
672
- array($this, $this->gawd_set_display('gawd_display_reports_page')) //$function = '',
673
- );
674
-
675
- add_submenu_page(
676
- 'gawd_analytics', //$parent_slug
677
- __('Settings', 'gawd'), //$page_title
678
- __('Settings', 'gawd'), //$menu_title
679
- $permission, //$capability
680
- 'gawd_settings', //$menu_slug
681
- array($this, 'gawd_display_settings_page') //$function = '',
682
-
683
- );
684
- add_submenu_page(
685
- 'gawd_analytics', //$parent_slug
686
- __('Tracking', 'gawd'), //$page_title
687
- __('Tracking', 'gawd'), //$menu_title
688
- $permission, //$capability
689
- $this->gawd_set_slug('gawd_tracking'), //$menu_slug
690
- array($this, $this->gawd_set_display('gawd_display_tracking_page')) //$function = '',
691
- );
692
- add_submenu_page(
693
- 'gawd_analytics', //$parent_slug
694
- __('Goal Management', 'gawd'), //$page_title
695
- __('Goal Management', 'gawd'), //$menu_title
696
- $permission, //$capability
697
- $this->gawd_set_slug('gawd_goals'), //$menu_slug
698
- array($this, $this->gawd_set_display('gawd_display_goals_page')) //$function = '',
699
- );
700
-
701
- add_submenu_page(
702
- 'gawd_analytics', //$parent_slug
703
- __('Custom Reports', 'gawd'), //$page_title
704
- __('Custom Reports', 'gawd'), //$menu_title
705
- $permission, //$capability
706
- $this->gawd_set_slug('gawd_custom_reports'), //$menu_slug
707
- array($this, $this->gawd_set_display('gawd_display_custom_reports_page')) //$function = '',
708
- );
709
- add_submenu_page(
710
- 'gawd_analytics', //$parent_slug
711
- __('Get Pro', 'gawd'), //$page_title
712
- __('Get Pro', 'gawd'), //$menu_title
713
- $permission, //$capability
714
- 'gawd_licensing', //$menu_slug
715
- array($this, 'gawd_display_licensing_page') //$function = '',
716
- );
717
- add_submenu_page(
718
- 'gawd_analytics', //$parent_slug
719
- __('Featured Plugins', 'gawd'), //$page_title
720
- __('Featured Plugins', 'gawd'), //$menu_title
721
- $permission, //$capability
722
- 'gawd_featured_plugins', //$menu_slug
723
- array($this, 'gawd_display_featured_plugins_page') //$function = '',
724
- );
725
- add_submenu_page(
726
- 'gawd_analytics', //$parent_slug
727
- __('Featured Themes', 'gawd'), //$page_title
728
- __('Featured Themes', 'gawd'), //$menu_title
729
- $permission, //$capability
730
- 'gawd_featured_themes', //$menu_slug
731
- array($this, 'gawd_display_featured_themes_page') //$function = '',
732
- );
733
- add_submenu_page(
734
- 'gawd_analytics', //$parent_slug
735
- __('Uninstall', 'gawd'), //$page_title
736
- __('Uninstall', 'gawd'), //$menu_title
737
- $permission, //$capability
738
- 'gawd_uninstall', //$menu_slug
739
- array($this, 'gawd_display_uninstall_page') //$function = '',
740
- );
741
-
742
- }
743
-
744
-
745
- public function gawd_set_slug($slug){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
746
  global $gawd_redirect_to_settings;
747
- if($gawd_redirect_to_settings=='yes'){
748
  return 'gawd_settings';
749
- }else{
750
  return $slug;
751
  }
752
  }
753
 
754
- public function gawd_set_display($slug){
755
  global $gawd_redirect_to_settings;
756
- if($gawd_redirect_to_settings=='yes'){
757
  return 'gawd_display_settings_page';
758
- }else{
759
  return $slug;
760
  }
761
  }
762
 
763
- public function gawd_display_licensing_page() {
764
- require_once(GAWD_DIR . '/admin/licensing.php');
765
- }
766
- function upgrade_pro(){
767
- $screen = get_current_screen();
768
- if (strpos($screen->base, 'gawd') !== false && strpos($screen->base, 'gawd_featured') === false) {
769
- ?>
770
- <div class="gawd_upgrade wd-clear" >
771
- <div class="wd-right">
772
- <a href="https://web-dorado.com/products/wordpress-google-analytics-plugin.html" target="_blank">
773
- <div class="wd-table">
774
- <div class="wd-cell wd-cell-valign-middle">
775
- <?php _e("Upgrade to paid version", "gawd"); ?>
776
- </div>
777
-
778
- <div class="wd-cell wd-cell-valign-middle">
779
- <img src="<?php echo GAWD_URL; ?>/assets/web-dorado.png" >
780
- </div>
781
- </div>
782
- </a>
783
- </div>
784
- </div>
785
- <?php
786
- }
787
- }
788
-
789
- public function gawd_display_featured_plugins_page() {
790
- require_once(GAWD_DIR . '/featured/featured.php');
791
- gawd_featured_plugins('wd-google-analytics');
792
-
793
- }
794
- public function gawd_display_featured_themes_page() {
795
- require_once(GAWD_DIR . '/featured/featured_themes.php');
796
- $controller = new gawd_featured_themes();
797
- $controller->display();
798
- }
799
-
800
- public function gawd_auth() {
801
- check_ajax_referer('gawd_admin_page_nonce', 'security');
802
- $code = $_POST['token'];
803
- $status = GAWD_google_client::authenticate($code);
804
- if ($status === true) {
805
- $res = array(
806
- 'message' => 'successfully saved',
807
- 'status' => $status,
808
- );
809
- } else {
810
- $res = array(
811
- 'message' => 'there is an error',
812
- 'status' => $status
813
- );
814
- }
815
- header('content-type: application/json');
816
- echo json_encode($res);
817
- wp_die();
818
- }
819
-
820
- /**
821
- * Displays the Dashboard page.
822
- */
823
- public function gawd_display_uninstall_page() {
824
- require_once( 'admin/pages/uninstall.php' );
825
- $gawd_uninstall = new GAWDUninstall();
826
- $deactivate_url = wp_nonce_url('plugins.php?action=deactivate&plugin='.GWD_NAME.'/google-analytics-wd.php', 'deactivate-plugin_'.GWD_NAME.'/google-analytics-wd.php');
827
- $deactivate_url = str_replace('&amp;','&',$deactivate_url);
828
- if (isset($_POST['unistall_gawd'])) {
829
- check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
830
- delete_option('gawd_custom_reports');
831
- delete_option('gawd_menu_for_user');
832
- delete_option('gawd_all_metrics');
833
- delete_option('gawd_all_dimensions');
834
- delete_option('gawd_custom_dimensions');
835
- delete_option('gawd_settings');
836
- delete_option('gawd_user_data');
837
- delete_option('gawd_credentials');
838
- delete_option('gawd_menu_items');
839
- delete_option('gawd_export_chart_data');
840
- delete_option('gawd_email');
841
- delete_option('gawd_custom_reports');
842
- delete_option('gawd_alerts');
843
- delete_option('gawd_pushovers');
844
- delete_option('gawd_menu_for_users');
845
- delete_option('gawd_own_project');
846
- delete_option('gawd_zoom_message');
847
- delete_transient('gawd_user_profiles');
848
- echo '<script>window.location.href="'.$deactivate_url.'";</script>';
849
- }
850
- if (get_option('gawd_credentials')) {
851
- $gawd_uninstall->uninstall();
852
- }
853
- }
854
-
855
- public function gawd_display_goals_page() {
856
- if($this->manage_ua_code_selection() != 'done') {
857
- return;
858
- }
859
- global $gawd_client;
860
- $gawd_client = GAWD_google_client::get_instance();
861
- if (!empty($_POST)) {
862
- check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
863
- }
864
- $gawd_goal_profile = isset($_POST['gawd_goal_profile']) ? sanitize_text_field($_POST['gawd_goal_profile']) : '';
865
- $gawd_goal_name = isset($_POST['gawd_goal_name']) ? sanitize_text_field($_POST['gawd_goal_name']) : '';
866
- $gawd_goal_type = isset($_POST['gawd_goal_type']) ? sanitize_text_field($_POST['gawd_goal_type']) : '';
867
- $gawd_visit_hour = isset($_POST['gawd_visit_hour']) ? sanitize_text_field($_POST['gawd_visit_hour']) : '';
868
- $gawd_visit_minute = isset($_POST['gawd_visit_minute']) ? sanitize_text_field($_POST['gawd_visit_minute']) : '';
869
- $gawd_visit_second = isset($_POST['gawd_visit_second']) ? sanitize_text_field($_POST['gawd_visit_second']) : '';
870
- $gawd_goal_duration_comparison = isset($_POST['gawd_goal_duration_comparison']) ? sanitize_text_field($_POST['gawd_goal_duration_comparison']) : '';
871
- $gawd_goal_page_comparison = isset($_POST['gawd_goal_page_comparison']) ? sanitize_text_field($_POST['gawd_goal_page_comparison']) : '';
872
- $gawd_page_sessions = isset($_POST['gawd_page_sessions']) ? sanitize_text_field($_POST['gawd_page_sessions']) : '';
873
- $goal_max_id = isset($_POST['goal_max_id']) ? $_POST['goal_max_id'] + 1 : 1;
874
- $gawd_goal_page_destination_match = isset($_POST['gawd_goal_page_destination_match']) ? sanitize_text_field($_POST['gawd_goal_page_destination_match']) : '';
875
- $gawd_page_url = isset($_POST['gawd_page_url']) ? sanitize_text_field($_POST['gawd_page_url']) : '';
876
- $url_case_sensitve = isset($_POST['url_case_sensitve']) ? $_POST['url_case_sensitve'] : '';
877
- if ($gawd_goal_type == 'VISIT_TIME_ON_SITE') {
878
- if ($gawd_visit_hour != '' || $gawd_visit_minute != '' || $gawd_visit_second != '') {
879
- $value = 0;
880
- if ($gawd_visit_hour != '') {
881
- $value += $gawd_visit_hour * 60 * 60;
882
- }
883
- if ($gawd_visit_minute != '') {
884
- $value += $gawd_visit_minute * 60;
885
- }
886
- if ($gawd_visit_second != '') {
887
- $value += $gawd_visit_second;
888
- }
889
- }
890
- $gawd_client->add_goal($gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_duration_comparison, $value);
891
- } elseif ($gawd_goal_type == 'VISIT_NUM_PAGES') {
892
- if ($gawd_page_sessions != '') {
893
- $gawd_client->add_goal($gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_page_comparison, $gawd_page_sessions);
894
- }
895
- } elseif ($gawd_goal_type == 'URL_DESTINATION') {
896
- if ($gawd_page_url != '') {
897
- $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);
898
- }
899
- } elseif ($gawd_goal_type == 'EVENT') {
900
- if ($gawd_page_url != '') {
901
- $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);
902
- }
903
- }
904
- require_once( 'admin/pages/goals.php' );
905
-
906
- }
907
-
908
- public function gawd_display_custom_reports_page() {
909
- global $gawd_client;
910
- if (!empty($_POST)) {
911
- check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
912
- }
913
- $gawd_client = GAWD_google_client::get_instance();
914
- $gawd_remove_custom_report = isset($_POST['gawd_remove_custom_report']) ? sanitize_text_field($_POST['gawd_remove_custom_report']) : '';
915
- if ($gawd_remove_custom_report) {
916
- $all_reports = get_option("gawd_custom_reports");
917
- if ($all_reports) {
918
- unset($all_reports[$gawd_remove_custom_report]);
919
- update_option('gawd_custom_reports', $all_reports);
920
- self::add_dashboard_menu();
921
- }
922
- }
923
- if (isset($_POST['gawd_add_custom_report'])) {
924
- $gawd_custom_report_name = isset($_POST['gawd_custom_report_name']) ? sanitize_text_field($_POST['gawd_custom_report_name']) : '';
925
- $gawd_custom_report_metric = isset($_POST['gawd_custom_report_metric']) ? sanitize_text_field($_POST['gawd_custom_report_metric']) : '';
926
- $gawd_custom_report_dimension = isset($_POST['gawd_custom_report_dimension']) ? sanitize_text_field($_POST['gawd_custom_report_dimension']) : '';
927
-
928
- if ($gawd_custom_report_name != '' && $gawd_custom_report_metric != '' && $gawd_custom_report_dimension != '') {
929
- $saved_custom_reports = get_option("gawd_custom_reports");
930
- if(!isset($saved_custom_reports[$gawd_custom_report_name])){
931
- if ($saved_custom_reports) {
932
- $custom_reports = array('metric' => $gawd_custom_report_metric, 'dimension' => $gawd_custom_report_dimension, 'id' => count($saved_custom_reports) + 1);
933
- $saved_custom_reports[$gawd_custom_report_name] = $custom_reports;
934
-
935
- update_option('gawd_custom_reports', $saved_custom_reports);
936
- }
937
- else {
938
- $custom_reports = array($gawd_custom_report_name => array('metric' => $gawd_custom_report_metric, 'dimension' => $gawd_custom_report_dimension, 'id' => 1));
939
- update_option('gawd_custom_reports', $custom_reports);
940
- }
941
- }
942
- }
943
- self::add_dashboard_menu();
944
- }
945
- require_once( 'admin/pages/custom_reports.php' );
946
- }
947
-
948
- public function gawd_display_overview_page() {
949
- global $gawd_client, $gawd_user_data;
950
- $gawd_client = GAWD_google_client::get_instance();
951
- $profiles = $gawd_client->get_profiles();
952
- $gawd_user_data = get_option('gawd_user_data');
953
- if(isset($_POST['gawd_id'])){
954
- $gawd_user_data['gawd_id'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
955
- foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
956
- foreach ($web_property as $profile) {
957
- if ($profile['id'] == $gawd_user_data['gawd_id']) {
958
- $gawd_user_data['web_property_name'] = $web_property_name;
959
- $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
960
- $gawd_user_data['accountId'] = $profile['accountId'];
961
- }
962
- }
963
- }
964
- $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
965
- update_option('gawd_user_data', $gawd_user_data);
966
- }
967
- require_once( 'admin/pages/overview.php' );
968
- }
969
-
970
- public function gawd_display_reports_page() {
971
- global $gawd_client, $gawd_user_data;
972
- $gawd_client = GAWD_google_client::get_instance();
973
- $profiles = $gawd_client->get_profiles();
974
- $gawd_user_data = get_option('gawd_user_data');
975
- if(isset($_POST['gawd_id'])){
976
- $gawd_user_data['gawd_id'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
977
- foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
978
- foreach ($web_property as $profile) {
979
- if ($profile['id'] == $gawd_user_data['gawd_id']) {
980
- $gawd_user_data['web_property_name'] = $web_property_name;
981
- $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
982
- $gawd_user_data['accountId'] = $profile['accountId'];
983
- }
984
- }
985
- }
986
- $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
987
- update_option('gawd_user_data', $gawd_user_data);
988
- }
989
- require_once( 'admin/pages/dashboard.php' );
990
- }
991
-
992
- public function gawd_daily_email() {
993
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
994
- $gawd_client = GAWD_google_client::get_instance();
995
- $emails = get_option('gawd_email');
996
- $gawd_user_data = get_option('gawd_user_data');
997
- $data = '';
998
- foreach ($emails as $email) {
999
- if (isset($email['period']) && $email['period'] == 'daily') {
1000
- //pls send email if ....
1001
- $date = date('Y-m-d', strtotime('yesterday'));
1002
- $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 . ')';
1003
- $data = $this->show_data(array('metric'=>'ga:' . $email['metric'], 'dimension'=>$email['dimension'], 'start_date'=>$date,'end_date'=> $date));
1004
- if($email['export_type'] == 'pdf'){
1005
- $filedir = $this->create_pdf_file(false,$data, $email['dimension'], $date, $date,$email['metric_compare'],$email['metric']);
1006
- }
1007
- else{
1008
- $filedir = $this->create_csv_file(false,$data, $email['dimension'], $date, $date,$email['metric_compare'],$email['metric']);
1009
- }
1010
- //$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);
1011
- $attachment = $filedir;
1012
- $headers = 'From: <' . $email['email_from'] . '>';
1013
- wp_mail($email['emails'], $email_subject, $email['email_body'], $headers, $attachment);
1014
- }
1015
- }
1016
- }
1017
-
1018
- public function gawd_weekly_email() {
1019
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1020
- $gawd_client = GAWD_google_client::get_instance();
1021
- $emails = get_option('gawd_email');
1022
- $gawd_user_data = get_option('gawd_user_data');
1023
- $data = '';
1024
- foreach ($emails as $email) {
1025
- if (isset($email['period']) && $email['period'] == 'gawd_weekly') {
1026
- //pls send email if ....
1027
- /*$start_date = date('Y-m-d', strtotime('last' . $email['period_day']));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1028
  $end_date = date('Y-m-d', strtotime('this' . $email['period_day']));*/
1029
- $start_date = date('Y-m-d', strtotime('last week -1 day'));
1030
- $end_date = date('l') != 'Sunday' ? date('Y-m-d',strtotime('last sunday -1 day')) : date('Y-m-d', strtotime('-1 day'));
1031
- $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 . ')';
1032
- $data = $this->show_data(array('metric'=>'ga:' . $email['metric'], 'dimension'=>$email['dimension'], 'start_date'=>$start_date,'end_date'=> $end_date));
1033
- if($email['export_type'] == 'pdf'){
1034
- $filedir = $this->create_pdf_file(false,$data, $email['dimension'], $start_date, $end_date,$email['metric_compare'],$email['metric']);
1035
- }
1036
- else{
1037
- $filedir = $this->create_csv_file(false,$data, $email['dimension'], $start_date, $end_date, $email['metric_compare'],$email['metric']);
1038
- }
1039
- //$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);
1040
- $attachment = $filedir;
 
 
 
 
 
 
 
 
 
 
1041
 
1042
- $headers = 'From: <' . $email['email_from'] . '>';
1043
- wp_mail($email['emails'], $email_subject, $email['email_body'], $headers, $attachment);
1044
- }
1045
- }
1046
- }
1047
-
1048
- public function gawd_monthly_email() {
1049
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1050
- $gawd_client = GAWD_google_client::get_instance();
1051
- $emails = get_option('gawd_email');
1052
- $gawd_user_data = get_option('gawd_user_data');
1053
- $data = '';
1054
- foreach ($emails as $email) {
1055
- if (isset($email['period']) && $email['period'] == 'gawd_monthly') {
1056
- //pls send email if ....
1057
- $end_date = date('Y-m-d', strtotime(date('Y-' . date('m') . '-1') . '-1 day'));
1058
- $start_date = date('Y-m-d', strtotime($end_date . '- 1 month'));
1059
- $data = $this->show_data(array('metric'=>'ga:' . $email['metric'], 'dimension'=>$email['dimension'], 'start_date'=>$start_date,'end_date'=> $end_date));
1060
- $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 . ')';
1061
- if($email['export_type'] == 'pdf'){
1062
- $filedir = $this->create_pdf_file(false,$data, $email['dimension'], $start_date, $end_date,$email['metric_compare'],$email['metric']);
1063
- }
1064
- else{
1065
- $filedir = $this->create_csv_file(false,$data, $email['dimension'], $start_date, $end_date,$email['metric_compare'],$email['metric']);
1066
- }
1067
- //$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);
1068
- $attachment = $filedir;
1069
- $headers = 'From: <' . $email['email_from'] . '>';
1070
- wp_mail($email['emails'], $email_subject, $email['email_body'], $headers, $attachment);
1071
- }
1072
- }
1073
- }
1074
-
1075
- /**
1076
- * Prepares the settings to be displayed then displays the settings page.
1077
- */
1078
- public static function gawd_settings_defaults() {
1079
- $settings = get_option('gawd_settings');
1080
- $settings['gawd_tracking_enable'] = 'on';
1081
- $settings['gawd_custom_dimension_Logged_in'] = 'on';
1082
- $settings['gawd_custom_dimension_Post_type'] = 'on';
1083
- $settings['gawd_custom_dimension_Author'] = 'on';
1084
- $settings['gawd_custom_dimension_Category'] = 'on';
1085
- $settings['gawd_custom_dimension_Published_Month'] = 'on';
1086
- $settings['gawd_custom_dimension_Published_Year'] = 'on';
1087
- $settings['gawd_custom_dimension_Tags'] = 'on';
1088
- $settings['enable_hover_tooltip'] = 'on';
1089
- update_option('gawd_settings', $settings);
1090
- }
1091
-
1092
- public function manage_ua_code_selection() {
1093
- global $gawd_user_data;
1094
- if (isset($gawd_user_data['default_webPropertyId']) && $gawd_user_data['default_webPropertyId']) {
1095
- return 'done';
1096
- } else {
1097
- $gawd_client = GAWD_google_client::get_instance();
1098
- $property = $gawd_client->property_exists();
1099
- if ($property == 'no_matches') {
1100
- $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');
1101
- // show notice that you don't have property with current site url
1102
- // add account or property to an existing account
1103
- } elseif (count($property) == 1) {
1104
- $property = $property[0];
1105
- $gawd_user_data['webPropertyId'] = $property['id'];
1106
- $gawd_user_data['default_webPropertyId'] = $property['id'];
1107
- $gawd_user_data['accountId'] = $property['accountId'];
1108
- $gawd_user_data['default_accountId'] = $property['accountId'];
1109
- $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
1110
- update_option('gawd_user_data', $gawd_user_data);
1111
- $this->gawd_admin_notice("In order to enable tracking for your website, you have to go with
1112
- <a href='" . admin_url('admin.php?page=gawd_tracking') . "'>this</a> link and turn the option on.", 'warning is-dismissible');
1113
- // show notice that you have to enable tracking code, link to tracking submenu
1114
- } else {
1115
- $this->gawd_admin_notice("You have two or more web-properties configured with current site url. Please go with
1116
- <a href='" . admin_url('admin.php?page=gawd_tracking') . "'>this</a> link to select the proper one.", 'error');
1117
- // show notice that you have >=2 properties with current site url
1118
- // select property from same url properties
1119
- }
1120
- }
1121
- }
1122
-
1123
- public function manage_ua_code_selection_tracking() {
1124
- global $gawd_user_data;
1125
- if (isset($gawd_user_data['default_webPropertyId']) && $gawd_user_data['default_webPropertyId']) {
1126
- return 'done';
1127
- } else {
1128
- $gawd_client = GAWD_google_client::get_instance();
1129
- $property = $gawd_client->property_exists();
1130
- if ($property == 'no_matches') {
1131
- $accounts = $gawd_client->get_management_accounts();
1132
- if (!empty($accounts)) {
1133
- echo "<h3 style='margin-top:10px' class='gawd_page_titles'>Tracking</h3>
1134
  <p class='gawd_notice notice'>Here you can add a <b>web property</b> on your Google Analytics account using current WordPress website.<br>
1135
  Provide a <b>Name</b> for the property and click <b>Add</b>. You can check and manage web properties from your Google Analytics account, <b>Admin</b> page.<br>
1136
  Alternatively, you can click <b>Later</b> and configure the web property any other time.</p>
@@ -1141,10 +1205,10 @@ Alternatively, you can click <b>Later</b> and configure the web property any oth
1141
  <span class='gawd_goal_label'>Account</span>
1142
  <span class='gawd_goal_input'>
1143
  <select name='gawd_account_select' class='gawd_account_select' style='padding: 2px;width: 96%;line-height: 30px;height: 30px !important;'>";
1144
- foreach ($accounts as $account) {
1145
- echo "<option value='" . $account['id'] . "'>" . $account['name'] . "</option>";
1146
- }
1147
- echo "</select>
1148
  </span>
1149
  <div class='gawd_info' title='this_is_tooltip'></div>
1150
  <div class='clear'></div>
@@ -1159,28 +1223,28 @@ Alternatively, you can click <b>Later</b> and configure the web property any oth
1159
  </div>
1160
  </div>
1161
  <div class='gawd_add_prop gawd_submit'>
1162
- <a href='".admin_url() . "admin.php?page=gawd_analytics' class='gawd_later button_gawd'>Later</a>
1163
  <input type='submit' name='add_property' class='button_gawd' value='ADD'/>
1164
  </div>
1165
  </form>";
1166
- // account select to add web property and web property parameters
1167
- // and add link to google analytics for manually creating an account
1168
- // wp_die();
1169
- } else {
1170
- $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");
1171
- // link to google analytics to add account
1172
- // wp_die();
1173
- }
1174
- } elseif (count($property) == 1) {
1175
- $property = $property[0];
1176
- $gawd_user_data['webPropertyId'] = $property['id'];
1177
- $gawd_user_data['default_webPropertyId'] = $property['id'];
1178
- $gawd_user_data['accountId'] = $property['accountId'];
1179
- $gawd_user_data['default_accountId'] = $property['accountId'];
1180
- $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
1181
- update_option('gawd_user_data', $gawd_user_data);
1182
- } else {
1183
- 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>
1184
  <br/>
1185
  <form method='post' id='gawd_property_select'>
1186
  <div class='gawd_settings_wrapper'>
@@ -1188,10 +1252,10 @@ Alternatively, you can click <b>Later</b> and configure the web property any oth
1188
  <span class='gawd_goal_label'>Web-property</span>
1189
  <span class='gawd_goal_input'>
1190
  <select name='gawd_property_select' class='gawd_property_select' style='padding: 2px;width: 96%;line-height: 30px;height: 30px !important;'>";
1191
- foreach ($property as $select_property) {
1192
- echo "<option value='" . $select_property['id'] . "'>" . $select_property['name'] . " (" . $select_property['id'] . ")</option>";
1193
- }
1194
- echo "</select>
1195
  </span>
1196
  <div class='gawd_info' title='this_is_tooltip'></div>
1197
  <div class='clear'></div>
@@ -1199,47 +1263,47 @@ Alternatively, you can click <b>Later</b> and configure the web property any oth
1199
  </div>
1200
  <div class='gawd_submit'><input type='submit' name='lock_property' class='button_gawd' value='SAVE'/></div>
1201
  </form>";
1202
- // web property select to select from properties with same site url
1203
- // wp_die();
1204
- }
1205
- }
1206
- }
1207
-
1208
- public function gawd_admin_notice($message, $type) {
1209
- $class = 'notice notice-' . $type;
1210
- echo '<div class="' . $class . '"><p>' . $message . '</p></div>';
1211
- }
1212
-
1213
- public function gawd_display_settings_page() {
1214
-
1215
- global $gawd_user_data;
1216
- $gawd_user_data = get_option('gawd_user_data');
1217
- if(isset($_GET['defaultExist']) && $_GET['defaultExist'] ==1){
1218
- $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1219
- echo '<script>window.location.href="'.$redirect_url.'";</script>';
1220
- }
1221
- if(isset($_POST['gawd_settings_logout'])&& $_POST['gawd_settings_logout'] == 1){
1222
- delete_option('gawd_user_data');
1223
- $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
1224
- echo '<script>window.location.href="'.$redirect_url.'";</script>';
1225
- }
1226
- if(isset($_POST['web_property_name']) && $_POST['web_property_name'] != ''){
1227
- $gawd_user_data['gawd_id'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
1228
- foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
1229
- foreach ($web_property as $profile) {
1230
- if ($profile['id'] == $gawd_user_data['gawd_id']) {
1231
- $gawd_user_data['web_property_name'] = $web_property_name;
1232
- $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1233
- $gawd_user_data['accountId'] = $profile['accountId'];
1234
- }
1235
- }
1236
- }
1237
- $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
1238
- update_option('gawd_user_data', $gawd_user_data);
1239
- $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
1240
- //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1241
- }
1242
- /* if(isset($_POST['account_name']) && $_POST['account_name'] != ''){
1243
  $gawd_user_data['accountId'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
1244
  foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
1245
  foreach ($web_property as $profile) {
@@ -1255,916 +1319,970 @@ Alternatively, you can click <b>Later</b> and configure the web property any oth
1255
  $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
1256
  //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1257
  } */
1258
- if(isset($_GET['errorMsg'])){
1259
- self::error_message('error','User does not have sufficient permissions for this account to add filter');
1260
- }
1261
- if (!isset($gawd_user_data['refresh_token']) || ($gawd_user_data['refresh_token'] == '')) {
1262
- 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;">AUTHENTICATE</div>';
1263
- echo '<div id="gawd_auth_code"><form id="gawd_auth_code_paste" action="" method="post"><input id="gawd_token" type="text">';
1264
- wp_nonce_field("gawd_save_form", "gawd_save_form_fild");
1265
- echo '</form>
1266
  <div id="gawd_auth_code_submit">SUBMIT</div></div>';
1267
- $gawd_own_project = get_option('gawd_own_project');
1268
- if(isset($gawd_own_project) && $gawd_own_project && intval($gawd_own_project)==1){
1269
- echo'<form method="post">
1270
  <div class="gawd_reset_button">
1271
  <input type="hidden" name="reset_data" id="reset_data"/>
1272
  <input type="button" class="button_gawd" id="gawd_reset_button" value="RESET"/>
1273
  </div>
1274
  </form>';
1275
- }
1276
- 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>
1277
  <div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 99999;">
1278
  <img src="' . GAWD_URL . '/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;">
1279
  </div>';
1280
- }
1281
- else {
1282
- if($this->manage_ua_code_selection() != 'done') {
1283
- // return;
1284
- }
1285
- try{
1286
- $gawd_client = GAWD_google_client::get_instance();
1287
- $gawd_client->get_profiles();
1288
-
1289
- }catch(Google_Service_Exception $e){
1290
- return $e->getErrors()[0]["message"];
1291
- }catch(Exception $e){
1292
- return $e->getMessage();
1293
- }
1294
-
1295
- $gawd_alert_remove = isset($_POST['gawd_alert_remove']) ? intval($_POST['gawd_alert_remove']) : false;
1296
- $gawd_menu_remove = isset($_POST['gawd_menu_remove']) ? intval($_POST['gawd_menu_remove']) : false;
1297
- $gawd_pushover_remove = isset($_POST['gawd_pushover_remove']) ? intval($_POST['gawd_pushover_remove']) : false;
1298
- $gawd_email_remove = isset($_POST['gawd_email_remove']) ? intval($_POST['gawd_email_remove']) : false;
1299
- $gawd_filter_remove = isset($_POST['gawd_filter_remove']) ? intval($_POST['gawd_filter_remove']) : false;
1300
- if ($gawd_alert_remove) {
1301
- $all_alerts = get_option('gawd_alerts');
1302
- if ($all_alerts) {
1303
- foreach ($all_alerts as $alert) {
1304
- wp_unschedule_event(wp_next_scheduled('gawd_alert_' . $alert['period']), 'gawd_alert_' . $alert['period']);
1305
- }
1306
- unset($all_alerts[$gawd_alert_remove - 1]);
1307
- update_option('gawd_alerts', $all_alerts);
1308
- }
1309
- }
1310
- if ($gawd_menu_remove) {
1311
- $all_menues = get_option('gawd_menu_for_user');
1312
- if ($all_menues) {
1313
- unset($all_menues[$gawd_menu_remove]);
1314
- update_option('gawd_menu_for_user', $all_menues);
1315
- }
1316
- }
1317
- if ($gawd_email_remove) {
1318
- $all_emails = get_option('gawd_email');
1319
- if ($all_emails) {
1320
- foreach ($all_emails as $email) {
1321
- wp_unschedule_event(wp_next_scheduled('gawd_email_' . $email['period']), 'gawd_email_' . $email['period']);
1322
- }
1323
- unset($all_emails[$gawd_email_remove - 1]);
1324
- update_option('gawd_email', $all_emails);
1325
- }
1326
- }
1327
- if ($gawd_filter_remove) {
1328
- $analytics = $gawd_client->analytics_member;
1329
- $accountId = $gawd_client->get_profile_accountId();
1330
- try{
1331
- $analytics->management_filters->delete($accountId, $gawd_filter_remove);
1332
- } catch (apiServiceException $e) {
1333
- print 'There was an Analytics API service error '
1334
- . $e->getCode() . ':' . $e->getMessage();
1335
- } catch (apiException $e) {
1336
- print 'There was a general API error '
1337
- . $e->getCode() . ':' . $e->getMessage();
1338
- } catch (Exception $e) {
1339
- echo '<script>window.location.href="' . admin_url() . 'admin.php?page=gawd_settings&errorMsg=1#gawd_filters_tab";</script>';
1340
- }
1341
- }
1342
- $gawd_pushover_remove = isset($_POST['gawd_pushover_remove']) ? $_POST['gawd_pushover_remove'] : false;
1343
- if ($gawd_pushover_remove) {
1344
- $all_pushovers = get_option('gawd_pushovers');
1345
- if ($all_pushovers) {
1346
- foreach ($all_pushovers as $pushover) {
1347
- wp_unschedule_event(wp_next_scheduled('gawd_pushover_' . $pushover['period']), 'gawd_pushover_' . $pushover['period']);
1348
- }
1349
- unset($all_pushovers[$gawd_pushover_remove - 1]);
1350
- update_option('gawd_pushovers', $all_pushovers);
1351
- }
1352
- }
1353
- if (isset($_POST['settings_submit'])) {
1354
- check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
1355
- $gawd_user_data = get_option('gawd_user_data');
1356
- $gawd_alert_name = isset($_POST['gawd_alert_name']) ? sanitize_text_field($_POST['gawd_alert_name']) : '';
1357
- $gawd_alert_period = isset($_POST['gawd_alert_name']) ? sanitize_text_field($_POST['gawd_alert_period']) : '';
1358
- $gawd_alert_metric = isset($_POST['gawd_alert_metric']) ? sanitize_text_field($_POST['gawd_alert_metric']) : '';
1359
- $gawd_alert_condition = isset($_POST['gawd_alert_condition']) ? sanitize_text_field($_POST['gawd_alert_condition']) : '';
1360
- $gawd_alert_value = isset($_POST['gawd_alert_value']) ? sanitize_text_field($_POST['gawd_alert_value']) : '';
1361
- $gawd_alert_emails = isset($_POST['gawd_alert_emails']) ? sanitize_email($_POST['gawd_alert_emails']) : '';
1362
- $gawd_alert_view = isset($_POST['gawd_alert_view']) ? sanitize_text_field($_POST['gawd_alert_view']) : '';
1363
- $alert_view_name = isset($_POST['alert_view_name']) ? sanitize_text_field($_POST['alert_view_name']) : '';
1364
- if ($gawd_alert_name != '' && $gawd_alert_period != '' && $gawd_alert_metric != '' && $gawd_alert_condition != '' && $gawd_alert_value != '' && $gawd_alert_emails != '') {
1365
- $saved_alerts = get_option('gawd_alerts');
1366
- if ($saved_alerts) {
1367
- $gawd_alert_options = array('name' => $gawd_alert_name, 'period' => $gawd_alert_period, 'metric' => $gawd_alert_metric, 'condition' => $gawd_alert_condition, 'value' => $gawd_alert_value, 'creation_date' => date('Y-m-d'), 'emails' => $gawd_alert_emails, 'alert_view' => $gawd_alert_view, 'alert_view_name' => $alert_view_name);
1368
- $saved_alerts[] = $gawd_alert_options;
1369
- update_option('gawd_alerts', $saved_alerts);
1370
- } else {
1371
- $gawd_alert_options = array(0 => array('name' => $gawd_alert_name, 'period' => $gawd_alert_period, 'metric' => $gawd_alert_metric, 'condition' => $gawd_alert_condition, 'value' => $gawd_alert_value, 'creation_date' => date('Y-m-d'), 'emails' => $gawd_alert_emails, 'alert_view' => $gawd_alert_view, 'alert_view_name' => $alert_view_name));
1372
- update_option('gawd_alerts', $gawd_alert_options);
1373
- }
1374
- $saved_alerts = get_option('gawd_alerts');
1375
- if ($saved_alerts) {
1376
- foreach ($saved_alerts as $alert) {
1377
- if (!wp_next_scheduled('gawd_alert_' . $alert['period'])) {
1378
- wp_schedule_event(time(), $alert['period'], 'gawd_alert_' . $alert['period']);
1379
- }
1380
- }
1381
- }
1382
- }
1383
- $gawd_pushover_name = isset($_POST['gawd_pushover_name']) ? sanitize_text_field($_POST['gawd_pushover_name']) : '';
1384
- $gawd_pushover_period = isset($_POST['gawd_pushover_period']) ? sanitize_text_field($_POST['gawd_pushover_period']) : '';
1385
- $gawd_pushover_metric = isset($_POST['gawd_pushover_metric']) ? sanitize_text_field($_POST['gawd_pushover_metric']) : '';
1386
- $gawd_pushover_condition = isset($_POST['gawd_pushover_condition']) ? sanitize_text_field($_POST['gawd_pushover_condition']) : '';
1387
- $gawd_pushover_value = isset($_POST['gawd_pushover_value']) ? intval($_POST['gawd_pushover_value']) : '';
1388
-
1389
- $gawd_pushover_user_keys = isset($_POST['gawd_pushover_user_keys']) ? sanitize_text_field($_POST['gawd_pushover_user_keys']) : '';
1390
- $gawd_pushover_view = isset($_POST['gawd_pushover_view']) ? sanitize_text_field($_POST['gawd_pushover_view']) : '';
1391
- $pushover_view_name = isset($_POST['pushover_view_name']) ? sanitize_text_field($_POST['pushover_view_name']) : '';
1392
- if ($gawd_pushover_name != '' && $gawd_pushover_period != '' && $gawd_pushover_metric != '' && $gawd_pushover_condition != '' && $gawd_pushover_value !== '' && $gawd_pushover_user_keys != '') {
1393
- $saved_pushovers = get_option('gawd_pushovers');
1394
- if ($saved_pushovers) {
1395
- $gawd_pushover_options = array('name' => $gawd_pushover_name, 'period' => $gawd_pushover_period, 'metric' => $gawd_pushover_metric, 'condition' => $gawd_pushover_condition, 'value' => $gawd_pushover_value, 'creation_date' => date('Y-m-d'), 'user_key' => $gawd_pushover_user_keys,'pushover_view' => $gawd_pushover_view, 'pushover_view_name' => $pushover_view_name);
1396
- $saved_pushovers[] = $gawd_pushover_options;
1397
- update_option('gawd_pushovers', $saved_pushovers);
1398
- }
1399
- else {
1400
- $gawd_pushover_options = array(0 => array('name' => $gawd_pushover_name, 'period' => $gawd_pushover_period, 'metric' => $gawd_pushover_metric, 'condition' => $gawd_pushover_condition, 'value' => $gawd_pushover_value, 'creation_date' => date('Y-m-d'), 'user_key' => $gawd_pushover_user_keys,'pushover_view' => $gawd_pushover_view, 'pushover_view_name' => $pushover_view_name));
1401
- update_option('gawd_pushovers', $gawd_pushover_options);
1402
- }
1403
- $saved_pushovers = get_option('gawd_pushovers');
1404
- if ($saved_pushovers) {
1405
-
1406
- foreach ($saved_pushovers as $pushover) {
1407
- $this->gawd_pushover_api($pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value']);
1408
- if(!wp_next_scheduled('gawd_pushover_'.$pushover['period'])){
1409
- wp_schedule_event(time(),$pushover['period'], 'gawd_pushover_'.$pushover['period']) ;
1410
- }
1411
- }
1412
- }
1413
- }
1414
- $gawd_show_in_dashboard = isset($_POST['gawd_show_in_dashboard']) ? sanitize_text_field($_POST['gawd_show_in_dashboard']) : '';
1415
-
1416
- $gawd_permissions = isset($_POST['gawd_permissions']) ? $_POST['gawd_permissions'] : array();
1417
- $gawd_own_project = isset($_POST['gawd_own_project']) ? sanitize_text_field($_POST['gawd_own_project']) : '';
1418
- $site_speed_rate = isset($_POST['site_speed_rate']) ? intval($_POST['site_speed_rate']) : '1';
1419
- $post_page_chart = isset($_POST['post_page_chart']) ? sanitize_text_field($_POST['post_page_chart']) : '';
1420
- $enable_cross_domain = isset($_POST['enable_cross_domain']) ? sanitize_text_field($_POST['enable_cross_domain']) : '';
1421
- $cross_domains = isset($_POST['cross_domains']) ? sanitize_text_field($_POST['cross_domains']) : '';
1422
- $default_date = isset($_POST['default_date']) ? $_POST['default_date'] : 'last_7_days';
1423
- $default_date_format = isset($_POST['default_date_format']) ? $_POST['default_date_format'] : 'ymd_with_week';
1424
- $enable_hover_tooltip = isset($_POST['enable_hover_tooltip']) ? $_POST['enable_hover_tooltip'] : '';
1425
- $gawd_backend_roles = isset($_POST['gawd_backend_roles']) ? ($_POST['gawd_backend_roles']) : array();
1426
- $gawd_frontend_roles = isset($_POST['gawd_frontend_roles']) ? ($_POST['gawd_frontend_roles']) : array();
1427
- $gawd_post_page_roles = isset($_POST['gawd_post_page_roles']) ? ($_POST['gawd_post_page_roles']) : array();
1428
- $exclude_events = isset($_POST['exclude_events']) ? sanitize_text_field($_POST['exclude_events']) : array();
1429
- $gawd_settings_exist = get_option('gawd_settings');
1430
- $gawd_settings_exist['gawd_show_in_dashboard'] = $gawd_show_in_dashboard;
1431
- $gawd_settings_exist['site_speed_rate'] = $site_speed_rate;
1432
- $gawd_settings_exist['post_page_chart'] = $post_page_chart;
1433
- $gawd_settings_exist['enable_cross_domain'] = $enable_cross_domain;
1434
- $gawd_settings_exist['cross_domains'] = $cross_domains;
1435
- $gawd_settings_exist['gawd_backend_roles'] = $gawd_backend_roles;
1436
- $gawd_settings_exist['gawd_frontend_roles'] = $gawd_frontend_roles;
1437
- $gawd_settings_exist['gawd_post_page_roles'] = $gawd_post_page_roles;
1438
- $gawd_settings_exist['default_date'] = $default_date;
1439
- $gawd_settings_exist['default_date_format'] = $default_date_format;
1440
- $gawd_settings_exist['enable_hover_tooltip'] = $enable_hover_tooltip;
1441
- $gawd_settings_exist['exclude_events'] = $exclude_events;
1442
- $gawd_settings_exist['gawd_permissions'] = $gawd_permissions;
1443
- update_option('gawd_settings', $gawd_settings_exist);
1444
- $gawd_filter_name = isset($_POST['gawd_filter_name']) ? sanitize_text_field($_POST['gawd_filter_name']) : '';
1445
- $gawd_filter_type = isset($_POST['gawd_filter_type']) ? sanitize_text_field($_POST['gawd_filter_type']) : '';
1446
- $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']) : '';
1447
- if ($gawd_filter_name != '' && $gawd_filter_type != '' && $gawd_filter_value != '') {
1448
- $gawd_client->add_filter($gawd_filter_name, $gawd_filter_type, $gawd_filter_value);
1449
- }
1450
- add_option("gawd_save_settings",1) ;
1451
- }
1452
- if(get_option('gawd_save_settings') == 1){
1453
- $this->gawd_admin_notice('Your changes have been saved successfully.','success is-dismissible');
1454
- }
1455
- delete_option('gawd_save_settings');
1456
- require_once( 'admin/pages/settings.php' );
1457
- }
1458
- }
1459
-
1460
- public function reset_user_data(){
1461
- delete_option("gawd_credentials");
1462
- $credentials['project_id'] = '115052745574-5vbr7tci4hjkr9clkflmnpto5jisgstg.apps.googleusercontent.com';
1463
- $credentials['project_secret'] = 'wtNiu3c_bA_g7res6chV0Trt';
1464
- update_option('gawd_credentials', $credentials);
1465
- delete_option('gawd_own_project');
1466
- delete_option('gawd_user_data');
1467
-
1468
- }
1469
- public function gawd_display_tracking_page() {
1470
- global $gawd_client, $gawd_user_data;
1471
- $gawd_client = GAWD_google_client::get_instance();
1472
- $gawd_user_data = get_option('gawd_user_data');
1473
- $add_dimension_value = isset($_POST['add_dimension_value']) ? $_POST['add_dimension_value'] : '';
1474
- if(isset($_GET['errorMsg'])){
1475
- self::error_message('error','User does not have sufficient permissions for this account');
1476
- }
1477
- if (isset($_POST['add_property'])) {
1478
- $gawd_account_select = isset($_POST['gawd_account_select']) ? $_POST['gawd_account_select'] : '';
1479
- $gawd_property_name = isset($_POST['gawd_property_name']) ? $_POST['gawd_property_name'] : '';
1480
- if ($gawd_account_select && $gawd_property_name) {
1481
- $err_msg = $gawd_client->add_webproperty($gawd_account_select, $gawd_property_name);
1482
- $redirect_url = admin_url() . 'admin.php?page=gawd_tracking&enableTracking=1';
1483
- if($err_msg){
1484
- $redirect_url .='&errorMsg=1';
1485
- }
1486
- echo '<script>window.location.href="'.$redirect_url.'";</script>';
1487
- }
1488
- }
1489
- if (isset($_POST['lock_property'])) {
1490
- $property = $gawd_client->property_exists();
1491
- $gawd_property_select = $_POST['gawd_property_select'];
1492
- foreach ($property as $property_select) {
1493
- if ($property_select['id'] == $gawd_property_select) {
1494
- $property = $property_select;
1495
- break;
1496
- }
1497
- }
1498
- $gawd_user_data['webPropertyId'] = $property['id'];
1499
- $gawd_user_data['default_webPropertyId'] = $property['id'];
1500
- $gawd_user_data['accountId'] = $property['accountId'];
1501
- $gawd_user_data['default_accountId'] = $property['accountId'];
1502
- $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
1503
- update_option('gawd_user_data', $gawd_user_data);
1504
- }
1505
- if($this->manage_ua_code_selection_tracking() != 'done') {
1506
- $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1507
- //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1508
- return;
1509
- }
1510
- if ($add_dimension_value == 'add_dimension_Logged_in') {
1511
- $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1512
- $gawd_client->add_custom_dimension('Logged in', $id);
1513
- $settings = get_option('gawd_settings');
1514
- $optname = 'gawd_custom_dimension_Logged_in';
1515
- $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1516
- update_option('gawd_settings', $settings);
1517
-
1518
- }
1519
- if ($add_dimension_value == 'add_dimension_Post_type') {
1520
- $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1521
- $gawd_client->add_custom_dimension('Post type', $id);
1522
- $settings = get_option('gawd_settings');
1523
- $optname = 'gawd_custom_dimension_Post_type';
1524
- $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1525
- update_option('gawd_settings', $settings);
1526
-
1527
- }
1528
- if ($add_dimension_value == 'add_dimension_Author') {
1529
- $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1530
- $gawd_client->add_custom_dimension('Author', $id);
1531
- $settings = get_option('gawd_settings');
1532
- $optname = 'gawd_custom_dimension_Author';
1533
- $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1534
- update_option('gawd_settings', $settings);
1535
-
1536
- }
1537
- if ($add_dimension_value == 'add_dimension_Category') {
1538
- $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1539
- $gawd_client->add_custom_dimension('Category', $id);
1540
- $settings = get_option('gawd_settings');
1541
- $optname = 'gawd_custom_dimension_Category';
1542
-
1543
- $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1544
- update_option('gawd_settings', $settings);
1545
- }
1546
- if ($add_dimension_value == 'add_dimension_Published_Month') {
1547
- $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1548
- $gawd_client->add_custom_dimension('Published Month', $id);
1549
- $settings = get_option('gawd_settings');
1550
- $optname = 'gawd_custom_dimension_Published_Month';
1551
- $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1552
- update_option('gawd_settings', $settings);
1553
-
1554
- }
1555
- if ($add_dimension_value == 'add_dimension_Published_Year') {
1556
- $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1557
- $gawd_client->add_custom_dimension('Published Year', $id);
1558
- $settings = get_option('gawd_settings');
1559
- $optname = 'gawd_custom_dimension_Published_Year';
1560
- $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1561
- update_option('gawd_settings', $settings);
1562
-
1563
- }
1564
- if ($add_dimension_value == 'add_dimension_Tags') {
1565
- $id = isset($_POST['gawd_custom_dimension_id']) ? ($_POST['gawd_custom_dimension_id'] + 1) : 1;
1566
- $gawd_client->add_custom_dimension('Tags', $id);
1567
- $settings = get_option('gawd_settings');
1568
- $optname = 'gawd_custom_dimension_Tags';
1569
- $settings[$optname] = isset($_POST['gawd_tracking_enable']) ? $_POST['gawd_tracking_enable'] : '';
1570
- update_option('gawd_settings', $settings);
1571
- }
1572
- if (isset($_POST['settings_submit'])) {
1573
- check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
1574
- $gawd_user_data = get_option('gawd_user_data');
1575
- $gawd_file_formats = isset($_POST['gawd_file_formats']) ? sanitize_text_field($_POST['gawd_file_formats']) : '';
1576
- $gawd_anonymize = isset($_POST['gawd_anonymize']) ? sanitize_text_field($_POST['gawd_anonymize']) : '';
1577
- $gawd_tracking_enable = isset($_POST['gawd_tracking_enable']) ? sanitize_text_field($_POST['gawd_tracking_enable']) : '';
1578
- $gawd_outbound = isset($_POST['gawd_outbound']) ? sanitize_text_field($_POST['gawd_outbound']) : '';
1579
- $gawd_enhanced = isset($_POST['gawd_enhanced']) ? sanitize_text_field($_POST['gawd_enhanced']) : '';
1580
- if($add_dimension_value == ''){
1581
- $gawd_cd_Logged_in = isset($_POST['gawd_custom_dimension_Logged_in']) ? sanitize_text_field($_POST['gawd_custom_dimension_Logged_in']) : '';
1582
- $gawd_cd_Post_type = isset($_POST['gawd_custom_dimension_Post_type']) ? sanitize_text_field($_POST['gawd_custom_dimension_Post_type']) : '';
1583
- $gawd_cd_Author = isset($_POST['gawd_custom_dimension_Author']) ? sanitize_text_field($_POST['gawd_custom_dimension_Author']) : '';
1584
- $gawd_cd_Category = isset($_POST['gawd_custom_dimension_Category']) ? sanitize_text_field($_POST['gawd_custom_dimension_Category']) : '';
1585
- $gawd_cd_Published_Month = isset($_POST['gawd_custom_dimension_Published_Month']) ? sanitize_text_field($_POST['gawd_custom_dimension_Published_Month']) : '';
1586
- $gawd_cd_Published_Year = isset($_POST['gawd_custom_dimension_Published_Year']) ? sanitize_text_field($_POST['gawd_custom_dimension_Published_Year']) : '';
1587
- $gawd_cd_Tags = isset($_POST['gawd_custom_dimension_Tags']) ? sanitize_text_field($_POST['gawd_custom_dimension_Tags']) : '';
1588
- $gawd_settings['gawd_custom_dimension_Logged_in'] = $gawd_cd_Logged_in;
1589
- $gawd_settings['gawd_custom_dimension_Post_type'] = $gawd_cd_Post_type;
1590
- $gawd_settings['gawd_custom_dimension_Author'] = $gawd_cd_Author;
1591
- $gawd_settings['gawd_custom_dimension_Category'] = $gawd_cd_Category;
1592
- $gawd_settings['gawd_custom_dimension_Published_Month'] = $gawd_cd_Published_Month;
1593
- $gawd_settings['gawd_custom_dimension_Published_Year'] = $gawd_cd_Published_Year;
1594
- $gawd_settings['gawd_custom_dimension_Tags'] = $gawd_cd_Tags;
1595
- }
1596
- $gawd_excluded_roles = isset($_POST['gawd_excluded_roles']) ? $_POST['gawd_excluded_roles'] : array();
1597
- $gawd_excluded_users = isset($_POST['gawd_excluded_users']) ? $_POST['gawd_excluded_users'] : array();
1598
- $gawd_settings = get_option('gawd_settings');
1599
- $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
1600
- $gawd_settings['gawd_anonymize'] = $gawd_anonymize;
1601
- $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
1602
- $gawd_settings['gawd_tracking_enable'] = $gawd_tracking_enable;
1603
- $gawd_settings['gawd_outbound'] = $gawd_outbound;
1604
- $gawd_settings['gawd_enhanced'] = $gawd_enhanced;
1605
- $gawd_settings['gawd_excluded_roles'] = $gawd_excluded_roles;
1606
- $gawd_settings['gawd_excluded_users'] = $gawd_excluded_users;
1607
- update_option('gawd_settings', $gawd_settings);
1608
- add_option("gawd_save_tracking",1) ;
1609
- }
1610
- if(get_option('gawd_save_tracking') == 1){
1611
- $this->gawd_admin_notice('Your changes have been saved successfully.','success is-dismissible');
1612
- }
1613
- delete_option('gawd_save_tracking');
1614
- $gawd_settings = get_option('gawd_settings');
1615
- if($add_dimension_value != ''){
1616
- $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1617
- echo '<script>window.location.href="'.$redirect_url.'";</script>';
1618
- }
1619
- require_once( 'admin/pages/tracking.php' );
1620
- }
1621
-
1622
- public function gawd_my_schedule() {
1623
- $schedules['gawd_weekly'] = array(
1624
- 'interval' => 604800,
1625
- 'display' => __('Every week')
1626
- );
1627
- $schedules['gawd_monthly'] = array(
1628
- 'interval' => 18748800,
1629
- 'display' => __('Every month')
1630
- );
1631
- return $schedules;
1632
- }
1633
-
1634
- public function gawd_pushover_api($user_key, $metric, $condition, $value) {
1635
- $ch = curl_init();
1636
- curl_setopt($ch, CURLOPT_URL, "https://api.pushover.net/1/messages.json");
1637
- curl_setopt($ch, CURLOPT_POSTFIELDS, array(
1638
- "token" => "aJBDhTfhR87EaTzs7wpx1MMKwboBjB",
1639
- "user" => $user_key,
1640
- "message" => 'The ' . $metric . ' less ' . $value));
1641
- // curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
1642
- curl_exec($ch);
1643
- curl_close($ch);
1644
- }
1645
-
1646
- public function gawd_pushover_daily() {
1647
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1648
- $gawd_client = GAWD_google_client::get_instance();
1649
- $pushovers = get_option('gawd_pushovers');
1650
- $data = '';
1651
- $condition = '';
1652
-
1653
- foreach ($pushovers as $pushover) {
1654
- if (isset($pushover['period']) && $pushover['period'] == 'daily') {
1655
- //pls send email if ....
1656
- $date = date('Y-m-d', strtotime('yesterday'));
1657
- $data = $gawd_client->get_data_alert('ga:' . $pushover['metric'], 'date', $date, $date, $pushover['pushover_view']);
1658
- $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
1659
- if (!eval($data . $pushover_condition . $pushover['value'] . ';')) {
1660
- $cond = ' '.$pushover['condition'] . ' than';
1661
- $this->gawd_pushover_api($pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value']);
1662
- }
1663
- }
1664
- }
1665
- }
1666
-
1667
- public function gawd_pushover_weekly() {
1668
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1669
- $gawd_client = GAWD_google_client::get_instance();
1670
- $pushovers = get_option('gawd_pushovers');
1671
- $data = '';
1672
- $condition = '';
1673
- foreach ($pushovers as $pushover) {
1674
- if (isset($pushover['period']) && $pushover['period'] == 'gawd_weekly') {
1675
- //pls send email if ....
1676
- $start_date = date('Y-m-d', strtotime('last week -1 day'));
1677
- $end_date = date('l') != 'Sunday' ? date('Y-m-d',strtotime('last sunday -1 day')) : date('Y-m-d', strtotime('-1 day'));
1678
- $data = $gawd_client->get_data_alert('ga:' . $pushover['metric'], 'date', $start_date, $end_date, $pushover['pushover_view']);
1679
- $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
1680
- if (!eval($data . $pushover_condition . $pushover['value'] . ';')) {
1681
- $cond = ' '.$pushover['condition'] . ' than';
1682
- $this->gawd_pushover_api($pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value']);
1683
- }
1684
- }
1685
- }
1686
- }
1687
-
1688
- public function gawd_pushover_monthly() {
1689
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1690
- $gawd_client = GAWD_google_client::get_instance();
1691
- $pushovers = get_option('gawd_pushovers');
1692
- $data = '';
1693
- $condition = '';
1694
- foreach ($pushovers as $pushover) {
1695
- if (isset($pushover['period']) && $pushover['period'] == 'gawd_monthly') {
1696
- //pls send email if ....
1697
- $end_date = date('Y-m-t', strtotime('last month'));
1698
- $start_date = date('Y-m-01', strtotime('last month'));
1699
- $data = $gawd_client->get_data_alert('ga:' . $pushover['metric'], 'date', $start_date, $end_date, $pushover['pushover_view']);
1700
- $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
1701
- if (!eval($data . $pushover_condition . $pushover['value'] . ';')) {
1702
- $cond = ' '.$pushover['condition'] . ' than';
1703
- $this->gawd_pushover_api($pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value']);
1704
- }
1705
- }
1706
- }
1707
- }
1708
-
1709
- public function gawd_alert_daily() {
1710
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1711
- $gawd_client = GAWD_google_client::get_instance();
1712
- $alerts = get_option('gawd_alerts');
1713
- $data = '';
1714
- $condition = '';
1715
- $email_from = get_option('admin_email');
1716
- foreach ($alerts as $alert) {
1717
- if (isset($alert['period']) && $alert['period'] == 'daily') {
1718
- //pls send email if ....
1719
- $date = date('Y-m-d', strtotime('yesterday'));
1720
- $data = $gawd_client->get_data_alert('ga:' . $alert['metric'], 'date', $date, $date, $alert['alert_view']);
1721
- $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
1722
- $color_condition = $alert['condition'] == 'greater' ? 'rgb(157, 207, 172)' : 'rgb(251, 133, 131)';
1723
- if (!eval($data . $alert_condition . $alert['value'] . ';')) {
1724
- $cond = ' '.$alert['condition'] . ' than';
1725
- $headers = array();
1726
- $headers[] = 'From: <' . $email_from . '>';
1727
- $headers[] = 'Content-Type: text/html';
1728
- $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>';
1729
- wp_mail($alert['emails'], 'Analytics Alert',$content, $headers);
1730
- }
1731
- }
1732
- }
1733
- }
1734
- public function gawd_alert_weekly() {
1735
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1736
- $gawd_client = GAWD_google_client::get_instance();
1737
- $alerts = get_option('gawd_alerts');
1738
- $data = '';
1739
- $condition = '';
1740
- $email_from = get_option('admin_email');
1741
- foreach ($alerts as $alert) {
1742
- if (isset($alert['period']) && $alert['period'] == 'gawd_weekly') {
1743
- //pls send email if ....
1744
- $start_date = date('Y-m-d', strtotime('last week -1 day'));
1745
- $end_date = date('l') != 'Sunday' ? date('Y-m-d',strtotime('last sunday -1 day')) : date('Y-m-d', strtotime('-1 day'));
1746
- $data = $gawd_client->get_data_alert('ga:' . $alert['metric'], 'date', $start_date, $end_date, $alert['alert_view']);
1747
- $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
1748
- if (!eval($data . $alert_condition . $alert['value'] . ';')) {
1749
- $cond = ' '.$alert['condition'] . ' than';
1750
- $headers = array();
1751
- $headers[] = 'From: <' . $email_from . '>';
1752
- $headers[] = 'Content-Type: text/html';
1753
- $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>';
1754
- wp_mail($alert['emails'], 'Analytics Alert',$content, $headers);
1755
- }
1756
- }
1757
- }
1758
- }
1759
-
1760
- public function gawd_alert_monthly() {
1761
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1762
- $gawd_client = GAWD_google_client::get_instance();
1763
- $alerts = get_option('gawd_alerts');
1764
- $data = '';
1765
- $email_from = get_option('admin_email');
1766
- foreach ($alerts as $alert) {
1767
- if (isset($alert['period']) && $alert['period'] == 'gawd_monthly') {
1768
- //pls send email if ....
1769
- $end_date = date('Y-m-t', strtotime('last month'));
1770
- $start_date = date('Y-m-01', strtotime('last month'));
1771
- $data = $gawd_client->get_data_alert('ga:' . $alert['metric'], 'date', $start_date, $end_date, $alert['alert_view']);
1772
- $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
1773
- if (!eval($data . $alert_condition . $alert['value'] . ';')) {
1774
- $cond = ' '.$alert['condition'] . ' than';
1775
- $headers = array();
1776
- $headers[] = 'From: <' . $email_from . '>';
1777
- $headers[] = 'Content-Type: text/html';
1778
- $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>';
1779
- wp_mail($alert['emails'], 'Analytics Alert',$content, $headers);
1780
- }
1781
- }
1782
- }
1783
- }
1784
-
1785
- public function wd_dashboard_widget() {
1786
- global $gawd_client, $gawd_user_data;
1787
- $gawd_client = GAWD_google_client::get_instance();
1788
- $profiles = $gawd_client->get_profiles();
1789
- $gawd_user_data = get_option('gawd_user_data');
1790
- if(isset($_POST['gawd_id'])){
1791
- $gawd_user_data['gawd_id'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
1792
- foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
1793
- foreach ($web_property as $profile) {
1794
- if ($profile['id'] == $gawd_user_data['gawd_id']) {
1795
- $gawd_user_data['web_property_name'] = $web_property_name;
1796
- $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1797
- $gawd_user_data['accountId'] = $profile['accountId'];
1798
- }
1799
- }
1800
- }
1801
- $gawd_user_data['web_property_name'] = isset($_POST['web_property_name']) ? $_POST['web_property_name'] : '';
1802
- update_option('gawd_user_data', $gawd_user_data);
1803
- }
1804
- require_once( 'admin/pages/dashboard_widget.php' );
1805
- }
1806
-
1807
- public function google_analytics_wd_dashboard_widget() {
1808
- $gawd_settings = get_option('gawd_settings');
1809
- $gawd_backend_roles = isset($gawd_settings['gawd_backend_roles']) ? $gawd_settings['gawd_backend_roles'] : array();
1810
- $roles = $this->get_current_user_role();
1811
-
1812
- if (isset($gawd_settings['gawd_show_in_dashboard']) && $gawd_settings['gawd_show_in_dashboard'] == 'on') {
1813
- if (in_array($roles, $gawd_backend_roles) || current_user_can('manage_options')) {
1814
- wp_add_dashboard_widget('wd_dashboard_widget', 'WD Google Analytics', array($this, 'wd_dashboard_widget'));
1815
- }
1816
- }
1817
- }
1818
 
1819
- public function show_data($params = array()) {
1820
- /* if (isset($_REQUEST['security'])) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1821
  check_ajax_referer('gawd_admin_page_nonce', 'security');
1822
  } else {
1823
  check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
1824
  } */
1825
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1826
- $return = true;
1827
- if ($params == '') {
1828
- $params = $_POST;
1829
- $return = false;
1830
- }
1831
- $gawd_client = GAWD_google_client::get_instance();
1832
- $start_date = isset($params["start_date"]) && $params["start_date"] != '' ? $params["start_date"] : date('Y-m-d', strtotime('-7 days'));
1833
- $end_date = isset($params["end_date"]) && $params["end_date"] != '' ? $params["end_date"] : date('Y-m-d');
1834
- $metric = isset($params["metric"]) ? $params["metric"] : 'ga:sessions';
1835
- $metric = is_array($metric) ? count($metric) > 1 ? implode(",", $metric) : $metric[0] : $metric;
1836
- $dimension = isset($params["dimension"]) ? $params["dimension"] : 'date';
1837
-
1838
- $country_filter = isset($params["country_filter"]) ? $params["country_filter"] : '';
1839
- $geo_type = isset($params["geo_type"]) ? $params["geo_type"] : '';
1840
- $filter_type = isset($params["filter_type"]) && $params["filter_type"] != '' ? $params["filter_type"] : '';
1841
- $custom = isset($params["custom"]) && $params["custom"] != '' ? $params["custom"] : '';
1842
- $same_dimension = $dimension;
1843
-
1844
- $dimension = $filter_type != '' && $dimension == 'date' ? $filter_type : $dimension;
1845
- if ($dimension == 'week' || $dimension == 'month') {
1846
- $same_dimension = $dimension;
1847
- }
1848
-
1849
-
1850
- $timezone = isset($params["timezone"]) && $params["timezone"] != '' ? $params["timezone"] : 0;
1851
- if ($dimension == 'pagePath' || $dimension == 'PagePath' || $dimension == 'landingPagePath' || $dimension == 'LandingPagePath') {
1852
- if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
1853
- $grid_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
1854
- } else {
1855
- $grid_data = $gawd_client->get_page_data($dimension, $start_date, $end_date, $timezone);
1856
- }
1857
- if ($return) {
1858
- return $grid_data;
1859
- }
1860
- echo $grid_data;
1861
- die();
1862
- }
1863
- elseif ($dimension == 'goals') {
1864
- if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
1865
- $goal_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
1866
- } else {
1867
- $goal_data = $gawd_client->get_goal_data('date', $start_date, $end_date, $timezone,$same_dimension);
1868
- }
1869
- if ($return) {
1870
- return $goal_data;
1871
- }
1872
- echo $goal_data;
1873
- die();
1874
- }
1875
- elseif (($dimension == 'region' || $dimension == 'city') || ($dimension == 'Region' || $dimension == 'City')) {
1876
- if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $country_filter . '-' . $start_date . '-' . $end_date)) {
1877
- $chart_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $country_filter . '-' . $start_date . '-' . $end_date);
1878
- } else {
1879
-
1880
- $chart_data = $gawd_client->get_country_data($metric, $dimension, $start_date, $end_date, $country_filter, $geo_type, $timezone);
1881
- }
1882
- if ($return) {
1883
- return $chart_data;
1884
- }
1885
- echo $chart_data;
1886
- die();
1887
- }
1888
- else {
1889
- if($custom != ''){
1890
- $chart_data = $gawd_client->get_data($metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension);
1891
- }
1892
- else{
1893
- if($dimension == 'siteSpeed'){
1894
- if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $same_dimension . '_' . $filter_type . '-' . $start_date . '-' . $end_date)) {
1895
- $chart_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
1896
- } else {
1897
- $chart_data = $gawd_client->get_data($metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension);
1898
- }
1899
- if ($return) {
1900
- return $chart_data;
1901
- }
1902
- }
1903
- else{
1904
 
1905
- /* if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1906
  $chart_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
1907
  } */
1908
- //else {
 
 
 
 
 
 
 
 
 
 
 
 
1909
 
1910
- $chart_data = $gawd_client->get_data($metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension);
1911
- //}
1912
- if ($return) {
1913
- return $chart_data;
1914
- }
1915
- }
1916
- }
1917
- echo $chart_data;
1918
- die();
1919
- }
1920
- }
1921
-
1922
- public function show_data_compact() {
1923
- check_ajax_referer('gawd_admin_page_nonce', 'security');
1924
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1925
- $gawd_client = GAWD_google_client::get_instance();
1926
- $start_date = isset($_POST["start_date"]) && $_POST["start_date"] != '' ? $_POST["start_date"] : date('Y-m-d', strtotime('-30 days'));
1927
- $end_date = isset($_POST["end_date"]) && $_POST["end_date"] != '' ? $_POST["end_date"] : date('Y-m-d');
1928
- $metric = isset($_POST["metric"]) ? $_POST["metric"] : 'sessions';
1929
- $metric = is_array($metric) ? count($metric) > 1 ? implode(",", $metric) : $metric[0] : 'ga:' . $metric;
1930
- $dimension = isset($_POST["dimension"]) ? $_POST["dimension"] : 'date';
1931
- $timezone = isset($_POST["timezone"]) ? $_POST["timezone"] : 0;
1932
- if (get_transient('gawd-compact-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
1933
- $chart_data = get_transient('gawd-compact-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
1934
- } else {
1935
- $chart_data = $gawd_client->get_data_compact($metric, $dimension, $start_date, $end_date, $timezone);
1936
- }
1937
- echo $chart_data;
1938
- die();
1939
- }
1940
-
1941
- public function show_page_post_data() {
1942
- check_ajax_referer('gawd_admin_page_nonce', 'security');
1943
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1944
- $gawd_client = GAWD_google_client::get_instance();
1945
- $start_date = isset($_POST["start_date"]) && $_POST["start_date"] != '' ? $_POST["start_date"] : date('Y-m-d', strtotime('-30 days'));
1946
- $end_date = isset($_POST["end_date"]) && $_POST["end_date"] != '' ? $_POST["end_date"] : date('Y-m-d');
1947
- $metric = isset($_POST["metric"]) ? $_POST["metric"] : 'ga:sessions';
1948
- $metric = is_array($metric) ? count($metric) > 1 ? implode(",", $metric) : $metric[0] : $metric;
1949
- $dimension = isset($_POST["dimension"]) ? $_POST["dimension"] : 'date';
1950
- $timezone = isset($_POST["timezone"]) ? $_POST["timezone"] : 0;
1951
- $filter = isset($_POST["filter"]) ? substr($_POST["filter"], 1) : '';
1952
- $chart = isset($_POST["chart"]) ? $_POST["chart"] : '';
1953
- $chart_data = get_transient('gawd-page-post-' . $gawd_client->get_profile_id() . '-' . $filter . '-' . '-' . $dimension . '-' . $start_date . '-' . $end_date. '-' . $chart);
1954
- if (!$chart_data) {
1955
- $chart_data = $gawd_client->get_post_page_data($metric, $dimension, $start_date, $end_date, $filter, $timezone, $chart);
1956
- }
1957
- echo $chart_data;
1958
- die();
1959
- }
1960
-
1961
- public function get_realtime() {
1962
- check_ajax_referer('gawd_admin_page_nonce', 'security');
1963
- require_once(GAWD_DIR . '/admin/gawd_google_class.php');
1964
- $gawd_client = GAWD_google_client::get_instance();
1965
- $chart_data = get_transient('gawd-real' . $gawd_client->get_profile_id());
1966
- if (!$chart_data) {
1967
- $chart_data = $gawd_client->gawd_realtime_data();
1968
- }
1969
- return $chart_data;
1970
- }
1971
-
1972
- /**
1973
- * Checks if the protocol is secure.
1974
- *
1975
- * @return boolean
1976
- */
1977
- public static function is_ssl() {
1978
- if (isset($_SERVER['HTTPS'])) {
1979
- if ('on' == strtolower($_SERVER['HTTPS']))
1980
- return true;
1981
- if ('1' == $_SERVER['HTTPS'])
1982
- return true;
1983
- } elseif (isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] )) {
1984
- return true;
1985
- }
1986
- return false;
1987
- }
1988
-
1989
- /**
1990
- * Returns the Singleton instance of this class.
1991
- *
1992
- * @return GAWD The Singleton instance.
1993
- */
1994
- public static function get_instance() {
1995
- if (null === static::$instance) {
1996
- static::$instance = new static();
1997
- }
1998
- return static::$instance;
1999
- }
2000
-
2001
- /**
2002
- * Private clone method to prevent cloning of the instance of the
2003
- * Singleton instance.
2004
- *
2005
- * @return void
2006
- */
2007
- private function __clone() {
2008
-
2009
- }
2010
-
2011
- /**
2012
- * Private unserialize method to prevent unserializing of the Singleton
2013
- * instance.
2014
- *
2015
- * @return void
2016
- */
2017
- private function __wakeup() {
2018
-
2019
- }
2020
-
2021
- public static function add_dashboard_menu() {
2022
- $get_custom_reports = get_option('gawd_custom_reports');
2023
- if (!$get_custom_reports) {
2024
- $custom_report = array();
2025
- } else {
2026
- foreach ($get_custom_reports as $name => $report) {
2027
- $custom_report['custom_report_' . $name] = __($name, "gawd");
2028
- }
2029
- }
2030
- $tabs = array(
2031
- "general" => array(
2032
- "title" => __("Audience", "gawd"),
2033
- "childs" => array(),
2034
- "desc" => "Report of your website audience. Provides details about new and returning users of your website, sessions, bounces, pageviews and session durations."
2035
- ),
2036
- "realtime" => array(
2037
- "title" => __("Real Time", "gawd"),
2038
- "childs" => array(),
2039
- "desc" => "Real Time statistics show the number of active users currently visiting your website pages."
2040
- ),
2041
- "demographics" => array(
2042
- "title" => __("Demographics", "gawd"),
2043
- "childs" => array(
2044
- "userGender" => __("User Gender", "gawd"),
2045
- "userAge" => __("User Age", "gawd")
2046
- ),
2047
- "desc" => "Demographics display tracking statistics of your website users based on their age and gender. "
2048
-
2049
- ),
2050
- "interests" => array(
2051
- "title" => __("Interests", "gawd"),
2052
- "childs" => array(
2053
- "inMarket" => __("In-Market Segment", "gawd"),
2054
- "affinityCategory" => __("Affinity Category", "gawd"),
2055
- "otherCategory" => __("Other Category", "gawd")
2056
- ),
2057
- "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)."
2058
- ),
2059
- "geo" => array(
2060
- "title" => __("GEO", "gawd"),
2061
- "childs" => array(
2062
- "location" => __("Location", "gawd"),
2063
- "language" => __("Language", "gawd")
2064
- ),
2065
- "desc" => "Geo-identifier report is built from interactions of location (countries, cities) and language of your website users."
2066
- ),
2067
- "behavior" => array(
2068
- "title" => __("Behavior", "gawd"),
2069
- "childs" => array(
2070
- "behaviour" => __("New vs Returning", "gawd"),
2071
- "engagement" => __("Engagement", "gawd")
2072
- ),
2073
- "desc" => "Compares number of New visitors and Returning users of your website in percents. You can check the duration of sessions with Engagement report."
2074
- ),
2075
- "technology" => array(
2076
- "title" => __("Technology", "gawd"),
2077
- "childs" => array(
2078
- "os" => __("OS", "gawd"),
2079
- "browser" => __("Browser", "gawd")
2080
- ),
2081
- "desc" => "Identifies tracking of the site based on operating systems and browsers visitors use."
2082
- ),
2083
- "mobile" => array(
2084
- "title" => __("Mobile", "gawd"),
2085
- "childs" => array(
2086
- "device_overview" => __("Overview", "gawd"),
2087
- "devices" => __("Devices", "gawd")
2088
- ),
2089
- "desc" => "Shows statistics of mobile and desktop devices visitors have used while interacting with your website."
2090
- ),
2091
- "custom" => array(
2092
- "title" => __("Custom Dimensions", "gawd"),
2093
- "childs" => array(),
2094
- "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."
2095
- ),
2096
- "trafficSource" => array(
2097
- "title" => __("Traffic Source", "gawd"),
2098
- "childs" => array(),
2099
- "desc" => "Displays overall graph of traffic sources directing to your website."
2100
- ),
2101
- "adWords" => array(
2102
- "title" => __("AdWords", "gawd"),
2103
- "childs" => array(),
2104
- "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."
2105
- ),
2106
- /* "pagePath" => array(
2107
  "title" => __("Pages", "gawd"),
2108
  "childs" => array(),
2109
  "desc" => "Pages report table will provide you information about Bounces, Entrances, Pageviews, Unique Pageviews, time spent on pages, Exits and Average page loading time."
2110
  ), */
2111
- "siteContent" => array(
2112
- "title" => __("Site Content", "gawd"),
2113
- "childs" => array(
2114
- "pagePath" => __("All Pages", "gawd"),
2115
- "landingPagePath" => __("Landing Pages", "gawd"),
2116
- ),
2117
- "desc" => "Pages report table will provide you information about Bounces, Entrances, Pageviews, Unique Pageviews, time spent on pages, Exits and Average page loading time."
2118
- ),
2119
- "siteSpeed" => array(
2120
- "title" => __("Site Speed", "gawd"),
2121
- "childs" => array(),
2122
- "desc" => "Shows the average load time of your website users experienced during specified date range."
2123
- ),
2124
- "events" => array(
2125
- "title" => __("Events", "gawd"),
2126
- "childs" => array(
2127
- "eventsLabel" => __("Events by Label", "gawd"),
2128
- "eventsAction" => __("Events by Action", "gawd"),
2129
- "eventsCategory" => __("Events by Category", "gawd")
2130
- ),
2131
- "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."
2132
- ),
2133
- "goals" => array(
2134
- "title" => __("Goals", "gawd"),
2135
- "childs" => array(),
2136
- "desc" => "Set Goals from Goal Management and review their Google Analytics reports under this tab."
2137
- ),
2138
- "ecommerce" => array(
2139
- "title" => __("Ecommerce", "gawd"),
2140
- "childs" => array(
2141
- "daysToTransaction" => __("TIme to Purchase", "gawd"),
2142
- "transactionId" => __("Transaction ID", "gawd"),
2143
- "sales_performance" => __("Sales Performance", "gawd"),
2144
- "productSku" => __("Product Sku", "gawd"),
2145
- "productCategory" => __("Product Category ", "gawd"),
2146
- "productName" => __("Product Name", "gawd"),
2147
- ),
2148
- "desc" => "Check sales statistics of your website identified by revenues, transactions, products and performance."
2149
- ),
2150
- "adsense" => array(
2151
- "title" => __("AdSense", "gawd"),
2152
- "childs" => array(),
2153
- "desc" => "Link your Google Analytics and AdSense accounts from Google Analytics Admin setting and keep track of AdSense tracking under this report."
2154
- ),
2155
- "customReport" => array(
2156
- "title" => __("Custom Report", "gawd"),
2157
- "childs" => $custom_report,
2158
- "desc" => "Add Custom Reports from any metric and dimension in Custom Reports page, and view relevant Google Analytics tracking information in this tab."
2159
- ),
2160
- );
2161
- update_option('gawd_menu_items', $tabs);
2162
- }
2163
- public function remove_zoom_message(){
2164
- check_ajax_referer('gawd_admin_page_nonce', 'security');
2165
- $got_it = isset($_REQUEST["got_it"]) ? sanitize_text_field($_REQUEST["got_it"]) : '';
2166
- if($got_it != ''){
2167
- add_option('gawd_zoom_message',$got_it);
2168
- }
2169
- }
 
2170
  }
1
  <?php
2
 
3
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
4
 
5
  class GAWD {
6
 
7
+ /**
8
+ * @var GAWD The reference to Singleton instance of this class
9
+ */
10
+ private static $instance;
11
+ private $project_client_id = null;
12
+ private $project_client_secret = null;
13
+ public $redirect_uri = "urn:ietf:wg:oauth:2.0:oob";
14
+
15
+ /**
16
+ * Protected constructor to prevent creating a new instance of the
17
+ * Singleton via the `new` operator from outside of this class.
18
+ */
19
+ protected function __construct() {
20
+
21
+ if ( isset( $_POST["reset_data"] ) && $_POST["reset_data"] != '' ) {
22
+ $this->reset_user_data();
23
+ }
24
+ add_action( 'admin_menu', array( $this, 'gawd_check_id' ), 1 );
25
+
26
+ add_action( 'admin_notices', array( $this, 'upgrade_pro' ) );
27
+
28
+ add_action( 'admin_menu', array( $this, 'gawd_add_menu' ), 19 );
29
+ add_action( 'admin_enqueue_scripts', array( $this, 'gawd_enqueue_scripts' ) );
30
+
31
+ add_action( 'wp_ajax_gawd_auth', array( $this, 'gawd_auth' ) );
32
+ add_action( 'wp_ajax_create_pdf_file', array( $this, 'create_pdf_file' ) );
33
+ add_action( 'wp_ajax_create_csv_file', array( $this, 'create_csv_file' ) );
34
+ add_action( 'wp_ajax_show_data', array( $this, 'show_data' ) );
35
+ add_action( 'wp_ajax_remove_zoom_message', array( $this, 'remove_zoom_message' ) );
36
+ add_action( 'wp_ajax_show_page_post_data', array( $this, 'show_page_post_data' ) );
37
+ add_action( 'wp_ajax_show_data_compact', array( $this, 'show_data_compact' ) );
38
+ add_action( 'wp_ajax_get_realtime', array( $this, 'get_realtime' ) );
39
+ add_action( 'wp_dashboard_setup', array( $this, 'google_analytics_wd_dashboard_widget' ) );
40
+ add_action( 'admin_menu', array( $this, 'overview_date_meta' ) );
41
+ add_filter( 'cron_schedules', array( $this, 'gawd_my_schedule' ) );
42
+ add_action( 'admin_init', array( $this, 'gawd_export' ) );
43
+ add_action( 'gawd_pushover_daily', array( $this, 'gawd_pushover_daily' ) );
44
+ add_action( 'gawd_pushover_gawd_weekly', array( $this, 'gawd_pushover_weekly' ) );
45
+ add_action( 'gawd_pushover_gawd_monthly', array( $this, 'gawd_pushover_monthly' ) );
46
+ add_action( 'gawd_alert_daily', array( $this, 'gawd_alert_daily' ) );
47
+ add_action( 'gawd_alert_gawd_monthly', array( $this, 'gawd_alert_monthly' ) );
48
+ add_action( 'gawd_alert_gawd_weekly', array( $this, 'gawd_alert_weekly' ) );
49
+ add_action( 'gawd_email_daily', array( $this, 'gawd_daily_email' ), 0 );
50
+ add_action( 'gawd_email_gawd_weekly', array( $this, 'gawd_weekly_email' ) );
51
+ add_action( 'gawd_email_gawd_monthly', array( $this, 'gawd_monthly_email' ) );
52
+ //add_action('init', array($this, 'gawd_daily_email'));
53
+ add_action( 'wp_head', array( $this, 'gawd_tracking_code' ), 99 );
54
+ $gawd_settings = get_option( 'gawd_settings' );
55
+ $gawd_post_page_roles = isset( $gawd_settings['gawd_post_page_roles'] ) ? $gawd_settings['gawd_post_page_roles'] : array();
56
+ $roles = $this->get_current_user_role();
57
+ 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' ) ) ) {
58
+ add_filter( 'manage_posts_columns', array( $this, 'gawd_add_columns' ) );
59
+ // Populate custom column in Posts List
60
+ add_action( 'manage_posts_custom_column', array( $this, 'gawd_add_icons' ), 10, 2 );
61
+ // Add custom column in Pages List
62
+ add_filter( 'manage_pages_columns', array( $this, 'gawd_add_columns' ) );
63
+ // Populate custom column in Pages List
64
+ add_action( 'manage_pages_custom_column', array( $this, 'gawd_add_icons' ), 10, 2 );
65
+ add_action( 'add_meta_boxes', array( $this, 'gawd_add_custom_box' ) );
66
+ }
67
+ $gawd_frontend_roles = isset( $gawd_settings['gawd_frontend_roles'] ) ? $gawd_settings['gawd_frontend_roles'] : array();
68
+ if ( ( isset( $gawd_settings['gawd_tracking_enable'] ) && $gawd_settings['gawd_tracking_enable'] == 'on' ) && ( in_array( $roles, $gawd_frontend_roles ) || current_user_can( 'manage_options' ) ) ) {
69
+ add_action( 'wp_enqueue_scripts', array( $this, 'gawd_front_scripts' ) );
70
+ add_action( 'admin_bar_menu', array( $this, 'report_adminbar' ), 999 );
71
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
 
73
 
74
+ $this->update_credentials();
75
+ $credentials = get_option( 'gawd_credentials' );
76
 
 
 
 
77
 
78
+ if ( is_array( $credentials ) ) {
79
+ $this->set_project_client_id( $credentials['project_id'] );
80
+ $this->set_project_client_secret( $credentials['project_secret'] );
81
+ } else {
82
+ //send error
83
+ return;
84
+ }
85
+
86
+ }
87
 
88
+ function get_current_user_role() {
89
+ global $wp_roles;
90
+ if ( is_user_logged_in() ) {
91
+ $current_user = wp_get_current_user();
92
+ $roles = $current_user->roles;
93
+ $role = array_shift( $roles );
94
 
95
+ return $role;
96
+ } else {
97
+ return "";
98
+ }
99
+ }
100
+
101
+
102
+ function report_adminbar( $wp_admin_bar ) {
103
+ /* @formatter:off */
104
+ $gawd_settings = get_option( 'gawd_settings' );
105
+ $gawd_frontend_roles = isset( $gawd_settings['gawd_frontend_roles'] ) ? $gawd_settings['gawd_frontend_roles'] : array();
106
+ $roles = $this->get_current_user_role();
107
+ if ( ( ( in_array( $roles, $gawd_frontend_roles ) || current_user_can( 'manage_options' ) ) && ! is_admin() ) && $gawd_settings['post_page_chart'] != '' ) {
108
+ $id = get_the_ID();
109
+ $uri_parts = explode( '/', get_permalink( $id ), 4 );
110
+ if ( $uri_parts[0] != '' ) {
111
+ if ( isset( $uri_parts[3] ) ) {
112
+ $uri = '/' . $uri_parts[3];
113
+ }
114
+ $uri = explode( '/', $uri );
115
+ end( $uri );
116
+ $key = key( $uri );
117
+ $uri = '/' . $uri[ $key - 1 ];
118
+ $filter = rawurlencode( rawurldecode( $uri ) );
119
+
120
+ $args = array(
121
+ 'id' => 'gawd',
122
+ 'title' => '<span data-url="' . $filter . '" class="ab-icon"></span><span class="">' . __( "Analytics WD", 'gawd' ) . '</span>',
123
+ 'href' => '#1',
124
+ );
125
+ /* @formatter:on */
126
+ $wp_admin_bar->add_node( $args );
127
+ }
128
+ }
129
+ }
130
+
131
+ public function update_credentials() {
132
+ //check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
133
+ if ( $_POST ) {
134
+ $gawd_own_project = isset( $_POST['gawd_own_project'] ) ? $_POST['gawd_own_project'] : '';
135
+ $gawd_own_client_id = isset( $_POST['gawd_own_client_id'] ) ? $_POST['gawd_own_client_id'] : '';
136
+ $gawd_own_client_secret = isset( $_POST['gawd_own_client_secret'] ) ? $_POST['gawd_own_client_secret'] : '';
137
+ $gawd_credentials['project_id'] = $gawd_own_client_id;
138
+ $gawd_credentials['project_secret'] = $gawd_own_client_secret;
139
+ if ( $gawd_own_project && $gawd_own_client_id != '' && $gawd_own_client_secret != '' ) {
140
+ update_option( 'gawd_credentials', $gawd_credentials );
141
+ delete_option( 'gawd_user_data' );
142
+ add_option( 'gawd_own_project', 1 );
143
+ }
144
+ }
145
+ }
146
+
147
+ public function set_project_client_id( $id ) {
148
+ $this->project_client_id = $id;
149
+ }
150
+
151
+ public function get_project_client_id() {
152
+ return $this->project_client_id;
153
+ }
154
+
155
+ public function set_project_client_secret( $secret ) {
156
+ $this->project_client_secret = $secret;
157
+ }
158
+
159
+ public function get_project_client_secret() {
160
+ return $this->project_client_secret;
161
+ }
162
+
163
+ function gawd_check_id() {
164
+ global $gawd_redirect_to_settings;
165
+ $current_page = isset( $_GET['page'] ) ? $_GET['page'] : "";
166
+ if ( strpos( $current_page, 'gawd' ) !== false ) {
167
+ $gawd_user_data = get_option( 'gawd_user_data' );
168
+ if ( ! isset( $gawd_user_data['refresh_token'] ) || ( $gawd_user_data['refresh_token'] == '' ) ) {
169
+ update_option( 'gawd_redirect_to_settings', 'yes' );
170
+ } else {
171
+ update_option( 'gawd_redirect_to_settings', 'no' );
172
+ }
173
+ }
174
+ $gawd_redirect_to_settings = get_option( 'gawd_redirect_to_settings' );
175
+ }
176
+
177
+ function gawd_add_custom_box() {
178
+ $screens = array( 'post', 'page' );
179
+ foreach ( $screens as $screen ) {
180
+ add_meta_box( 'gawd_page_post_meta', 'Sessions in month', array(
181
+ $this,
182
+ 'gawd_add_custom_box_callback'
183
+ ), $screen, 'normal' );
184
+ }
185
+ }
186
+
187
+ function gawd_add_custom_box_callback() {
188
+ require_once( 'admin/post_page_view.php' );
189
+ }
190
+
191
+ public function gawd_add_icons( $column, $id ) {
192
+ if ( $column != 'gawd_stats' ) {
193
+ return;
194
+ }
195
+ $uri_parts = explode( '/', get_permalink( $id ), 4 );
196
+ if ( isset( $uri_parts[3] ) ) {
197
+ $uri = '/' . $uri_parts[3];
198
+ }
199
+ $uri = explode( '/', $uri );
200
+ end( $uri );
201
+ $key = key( $uri );
202
+ $uri = '/' . $uri[ $key - 1 ];
203
+ $filter = rawurlencode( rawurldecode( $uri ) );
204
+ 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>';
205
+ }
206
+
207
+ public function gawd_add_columns( $columns ) {
208
+ return array_merge( $columns, array( 'gawd_stats' => __( 'Analytics WD', 'gawd' ) ) );
209
+ }
210
+
211
+ public static function gawd_roles( $access_level, $tracking = false ) {
212
+ if ( is_user_logged_in() && isset( $access_level ) ) {
213
+ $current_user = wp_get_current_user();
214
+ $roles = (array) $current_user->roles;
215
+ if ( ( current_user_can( 'manage_options' ) ) && ! $tracking ) {
216
+ return true;
217
+ }
218
+ if ( count( array_intersect( $roles, $access_level ) ) > 0 ) {
219
+ return true;
220
+ } else {
221
+ return false;
222
+ }
223
+ }
224
+
225
+ return false;
226
+ }
227
+
228
+ public function gawd_tracking_code() {
229
+ $gawd_user_data = get_option( 'gawd_user_data' );
230
+ if ( isset( $gawd_user_data['default_webPropertyId'] ) && ( $gawd_user_data['default_webPropertyId'] ) ) {
231
+ global $gawd_client;
232
+ $gawd_client = GAWD_google_client::get_instance();
233
+ require_once( GAWD_DIR . '/admin/tracking.php' );
234
+ }
235
+ }
236
+
237
+ public function create_pdf_file( $ajax = true, $data = null, $dimension = null, $start_date = null, $end_date = null, $metric_compare_recc = null, $metric_recc = null ) {
238
+ $first_data = isset( $_REQUEST["first_data"] ) ? sanitize_text_field( $_REQUEST["first_data"] ) : '';
239
+ $_data_compare = isset( $_REQUEST["_data_compare"] ) ? ( $_REQUEST["_data_compare"] ) : '';
240
+ if ( $ajax == true ) {
241
+ $export_type = isset( $_REQUEST["export_type"] ) ? sanitize_text_field( $_REQUEST["export_type"] ) : '';
242
+ if ( $export_type != 'pdf' ) {
243
+ return;
244
+ }
245
+
246
+ $report_type = isset( $_REQUEST["report_type"] ) ? sanitize_text_field( $_REQUEST["report_type"] ) : '';
247
+
248
+
249
+ if ( $report_type !== 'alert' ) {
250
+ return;
251
+ }
252
+
253
+ }
254
+
255
+ include_once GAWD_DIR . '/include/gawd_pdf_file.php';
256
+ $file = new GAWD_PDF_FILE();
257
+
258
+ /*
259
  require_once(GAWD_DIR . '/admin/gawd_google_class.php');
260
  $this->gawd_google_client = GAWD_google_client::get_instance();
261
  */
262
+ $file->get_request_data( $this, $ajax, $data, $dimension, $start_date, $end_date, $metric_compare_recc, $metric_recc );
263
+
264
+ $file->sort_data();
265
+ if ( $first_data != '' ) {
266
+ $file->create_file( 'pages' );
267
+ } elseif ( ( $_data_compare ) != '' ) {
268
+ $file->create_file( 'compare' );
269
+ } else {
270
+ $file->create_file( true );
271
+ }
272
+ if ( $ajax == true ) {
273
+ die();
274
+ } else {
275
+ return $file->file_dir;
276
+ }
277
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
278
 
279
+ public function create_csv_file( $ajax = true, $data = null, $dimension = null, $start_date = null, $end_date = null, $metric_compare_recc = null, $metric_recc = null ) {
280
+ if ( $ajax == true ) {
281
+ $export_type = isset( $_REQUEST["export_type"] ) ? sanitize_text_field( $_REQUEST["export_type"] ) : '';
282
+ if ( $export_type != 'csv' ) {
283
+ return;
284
+ }
285
+ $report_type = isset( $_REQUEST["report_type"] ) ? sanitize_text_field( $_REQUEST["report_type"] ) : '';
286
+ if ( $report_type !== 'alert' ) {
287
+ return;
288
+ }
289
+ }
290
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
291
+ $this->gawd_google_client = GAWD_google_client::get_instance();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
 
293
+ $first_data = isset( $_REQUEST["first_data"] ) ? sanitize_text_field( $_REQUEST["first_data"] ) : '';
294
+
295
+
296
+ include_once GAWD_DIR . '/include/gawd_csv_file.php';
297
+
298
+ $file = new GAWD_CSV_FILE();
299
+ $file->get_request_data( $this, $ajax, $data, $dimension, $start_date, $end_date, $metric_compare_recc, $metric_recc );
300
+
301
+ $file->sort_data();
302
+
303
+ //$file->get_request_data($this);
304
+
305
+ $file->sort_data();
306
+ if ( $first_data != '' ) {
307
+ $file->create_file( false );
308
+ } else {
309
+ $file->create_file();
310
+ }
311
+ if ( $ajax == true ) {
312
+ die();
313
+ } else {
314
+ return $file->file_dir;
315
+ }
316
+ }
317
+
318
+ public static function get_domain( $domain ) {
319
+ $root = explode( '/', $domain );
320
+ $ret_domain = str_ireplace( 'www', '', isset( $root[2] ) ? $root[2] : $domain );
321
+
322
+ return $ret_domain;
323
+ }
324
+
325
+ public static function error_message( $type, $message ) {
326
+ echo '<div style="width:99%"><div class="' . $type . '"><p><strong>' . $message . '</strong></p></div></div>';
327
+ }
328
+
329
+ public function gawd_export() {
330
+ if ( ! isset( $_REQUEST['action'] ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] !== 'gawd_export' ) ) {
331
+ return;
332
+ }
333
+
334
+ $export_type = isset( $_REQUEST["export_type"] ) ? sanitize_text_field( $_REQUEST["export_type"] ) : '';
335
+ if ( $export_type != 'pdf' && $export_type != 'csv' ) {
336
+ return;
337
+ }
338
+
339
+ $report_type = isset( $_REQUEST["report_type"] ) ? sanitize_text_field( $_REQUEST["report_type"] ) : '';
340
+
341
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
342
+ $this->gawd_google_client = GAWD_google_client::get_instance();
343
+
344
+ if ( $export_type == 'pdf' ) {
345
+ include_once GAWD_DIR . '/include/gawd_pdf_file.php';
346
+ $file = new GAWD_PDF_FILE();
347
+ } else {
348
+ include_once GAWD_DIR . '/include/gawd_csv_file.php';
349
+ $file = new GAWD_CSV_FILE();
350
+ }
351
+
352
+ if ( $report_type == 'alert' ) {
353
+ if ( $export_type == 'pdf' ) {
354
+ $file->export_file();
355
+ } else {
356
+ $file->export_file();
357
+ }
358
+ } else {
359
+ $metric = isset( $_REQUEST["gawd_metric"] ) ? sanitize_text_field( $_REQUEST["gawd_metric"] ) : '';
360
+ $_data_compare = isset( $_REQUEST["_data_compare"] ) ? ( $_REQUEST["_data_compare"] ) : '';
361
+ $first_data = isset( $_REQUEST["first_data"] ) ? ( $_REQUEST["first_data"] ) : '';
362
+ $view_id = isset( $_REQUEST["view_id"] ) ? sanitize_text_field( $_REQUEST["view_id"] ) : '';
363
+ $metric_compare = isset( $_REQUEST["gawd_metric_compare"] ) ? sanitize_text_field( $_REQUEST["gawd_metric_compare"] ) : '';
364
+ $dimension = isset( $_REQUEST["gawd_dimension"] ) ? sanitize_text_field( $_REQUEST["gawd_dimension"] ) : '';
365
+ $tab_name = isset( $_REQUEST["tab_name"] ) ? sanitize_text_field( $_REQUEST["tab_name"] ) : '';
366
+ $img = isset( $_REQUEST["img"] ) ? sanitize_text_field( $_REQUEST["img"] ) : '';
367
+ $gawd_email_subject = isset( $_REQUEST["gawd_email_subject"] ) ? sanitize_text_field( $_REQUEST["gawd_email_subject"] ) : '';
368
+ $gawd_email_body = isset( $_REQUEST["gawd_email_body"] ) && $_REQUEST["gawd_email_body"] != '' ? sanitize_text_field( $_REQUEST["gawd_email_body"] ) : ' ';
369
+ $email_from = isset( $_REQUEST["gawd_email_from"] ) ? sanitize_email( $_REQUEST["gawd_email_from"] ) : '';
370
+ $email_to = isset( $_REQUEST["gawd_email_to"] ) ? sanitize_email( $_REQUEST["gawd_email_to"] ) : '';
371
+ $email_period = isset( $_REQUEST["gawd_email_period"] ) ? sanitize_text_field( $_REQUEST["gawd_email_period"] ) : '';
372
+ $week_day = isset( $_REQUEST["gawd_email_week_day"] ) ? sanitize_text_field( $_REQUEST["gawd_email_week_day"] ) : '';
373
+ $month_day = isset( $_REQUEST["gawd_email_month_day"] ) ? sanitize_text_field( $_REQUEST["gawd_email_month_day"] ) : '';
374
+ $emails = array();
375
+ $invalid_email = false;
376
+ $email_to = explode( ',', $email_to );
377
+ foreach ( $email_to as $email ) {
378
+ if ( is_email( $email ) == false ) {
379
+ $emails = $email;
380
+ }
381
+ }
382
+ if ( count( $emails ) > 0 ) {
383
+ $invalid_email = true;
384
+ }
385
+ if ( ( $invalid_email != true ) && is_email( $email_from ) && $gawd_email_subject != '' ) {
386
+ if ( $email_period == "once" ) {
387
+ $file->get_request_data( $this );
388
+ $file->sort_data();
389
+ if ( $export_type == 'csv' ) {
390
+ if ( $first_data != '' ) {
391
+ $file->create_file( false );
392
+ } else {
393
+ $file->create_file();
394
+ }
395
+ } else {
396
+ if ( $first_data != '' ) {
397
+ $file->create_file( 'pages' );
398
+ } elseif ( ( $_data_compare ) != '' ) {
399
+ $file->create_file( 'compare' );
400
+ } else {
401
+ $file->create_file( false );
402
+ }
403
+ }
404
+ $attachment = $file->file_dir;
405
+
406
+ if ( $report_type == 'email' ) {
407
+ $headers = 'From: <' . $email_from . '>';
408
+ wp_mail( $email_to, $gawd_email_subject, $gawd_email_body, $headers, $attachment );
409
+ }
410
+ echo json_encode( array( 'status' => 'success', 'msg' => 'Email successfuly sent' ) );
411
+ } else {
412
+ if ( $email_period == 'gawd_weekly' ) {
413
+ $period_day = $week_day;
414
+ $timestamp = strtotime( 'this ' . $period_day );
415
+ } elseif ( $email_period == 'gawd_monthly' ) {
416
+ $period_day = $month_day;
417
+ $timestamp = strtotime( date( 'Y-m-' . $period_day ) );
418
+ } else {
419
+ $period_day = '';
420
+ $timestamp = time();
421
+ }
422
+ $saved_email = get_option( 'gawd_email' );
423
+ if ( $saved_email ) {
424
+ $gawd_email_options = 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' ),
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
+ 'img' => $img,
437
+ 'tab_name' => $tab_name,
438
+ 'view_id' => $view_id,
439
+ 'export_type' => $export_type
440
+ );
441
+ $saved_email[] = $gawd_email_options;
442
+ update_option( 'gawd_email', $saved_email );
443
+ } else {
444
+ $gawd_email_options = array(
445
+ 0 => array(
446
+ 'name' => $gawd_email_subject,
447
+ 'period' => $email_period,
448
+ 'metric' => $metric,
449
+ 'metric_compare' => $metric_compare,
450
+ 'dimension' => $dimension,
451
+ 'creation_date' => date( 'Y-m-d' ),
452
+ 'emails' => $email_to,
453
+ 'email_from' => $email_from,
454
+ 'email_subject' => $gawd_email_subject,
455
+ 'email_body' => $gawd_email_body,
456
+ 'period_day' => $period_day,
457
+ 'img' => $img,
458
+ 'tab_name' => $tab_name,
459
+ 'view_id' => $view_id,
460
+ 'export_type' => $export_type
461
+ )
462
+ );
463
+ update_option( 'gawd_email', $gawd_email_options );
464
+ }
465
+ $saved_email = get_option( 'gawd_email' );
466
+ if ( $saved_email ) {
467
+ foreach ( $saved_email as $email ) {
468
+ if ( ! wp_next_scheduled( 'gawd_email_' . $email['period'] ) ) {
469
+ wp_schedule_event( $timestamp, $email['period'], 'gawd_email_' . $email['period'] );
470
+ }
471
+ }
472
+ }
473
+ $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.';
474
+ echo json_encode( array( 'status' => 'success', 'msg' => $success_message ) );
475
+ }
476
+
477
+ die;
478
+ } else {
479
+ if ( $invalid_email == true ) {
480
+ echo json_encode( 'Invalid email' );
481
+ die;
482
+ } else if ( $gawd_email_subject == '' ) {
483
+ echo json_encode( "Can't send email with empty subject" );
484
+ die;
485
+ }
486
+ }
487
+ }
488
+ }
489
+
490
+ public function overview_date_meta( $screen = null, $context = 'advanced' ) {
491
+ //righ side wide meta..
492
+ $orintation = wp_is_mobile() ? 'side' : 'normal';
493
+ add_meta_box( 'gawd-real-time', __( 'Real Time', 'gawd' ), array(
494
+ $this,
495
+ 'gawd_real_time'
496
+ ), 'gawd_analytics', 'side', 'high' );
497
+ add_meta_box( 'gawd-date-meta', __( 'Audience', 'gawd' ), array(
498
+ $this,
499
+ 'gawd_date_box'
500
+ ), 'gawd_analytics', $orintation, null );
501
+ add_meta_box( 'gawd-country-box', __( 'Location', 'gawd' ), array(
502
+ $this,
503
+ 'gawd_country_box'
504
+ ), 'gawd_analytics', $orintation, null );
505
+ //left side thin meta.
506
+ add_meta_box( 'gawd-visitors-meta', __( 'Visitors', 'gawd' ), array(
507
+ $this,
508
+ 'gawd_visitors'
509
+ ), 'gawd_analytics', 'side', null );
510
+ add_meta_box( 'gawd-browser-meta', __( 'Browsers', 'gawd' ), array(
511
+ $this,
512
+ 'gawd_browser'
513
+ ), 'gawd_analytics', 'side', null );
514
+ }
515
+
516
+ public function gawd_date_box() {
517
+ require_once( 'admin/pages/date.php' );
518
+ }
519
+
520
+ public function gawd_country_box() {
521
+ require_once( 'admin/pages/location.php' );
522
+ }
523
+
524
+ public function gawd_real_time() {
525
+ require_once( 'admin/pages/real_time.php' );
526
+ }
527
+
528
+ public function gawd_visitors() {
529
+ require_once( 'admin/pages/visitors.php' );
530
+ }
531
+
532
+ public function gawd_browser() {
533
+ require_once( 'admin/pages/browser.php' );
534
+ }
535
+
536
+ /**
537
+ * Activation function needed for the activation hook.
538
+ */
539
+ public static function activate() {
540
+ $credentials['project_id'] = '115052745574-5vbr7tci4hjkr9clkflmnpto5jisgstg.apps.googleusercontent.com';
541
+ $credentials['project_secret'] = 'wtNiu3c_bA_g7res6chV0Trt';
542
+ if ( ! get_option( 'gawd_credentials' ) ) {
543
+ update_option( 'gawd_credentials', $credentials );
544
+ }
545
+ self::gawd_settings_defaults();
546
+ self::add_dashboard_menu();
547
+ }
548
+
549
+ /**
550
+ * Deactivation function needed for the deactivation hook.
551
+ */
552
+ public static function deactivate() {
553
+
554
+ }
555
+
556
+ /**
557
+ * Enqueues the required styles and scripts, localizes some js variables.
558
+ */
559
+ public function gawd_front_scripts() {
560
+ if ( is_user_logged_in() ) {
561
+ wp_enqueue_style( 'admin_css', GAWD_URL . '/inc/css/gawd_admin.css', false, GAWD_VERSION );
562
+ wp_enqueue_script( 'gawd_amcharts', GAWD_URL . '/inc/js/amcharts.js', false, GAWD_VERSION );
563
+ wp_enqueue_script( 'gawd_pie', GAWD_URL . '/inc/js/pie.js', false, GAWD_VERSION );
564
+ wp_enqueue_script( 'gawd_serial', GAWD_URL . '/inc/js/serial.js', false, GAWD_VERSION );
565
+ wp_enqueue_script( 'gawd_light_theme', GAWD_URL . '/inc/js/light.js', array( 'jquery' ), GAWD_VERSION );
566
+ wp_enqueue_script( 'gawd_dataloader', GAWD_URL . '/inc/js/dataloader.min.js', array( 'jquery' ), GAWD_VERSION );
567
+ wp_enqueue_script( 'date-js', GAWD_URL . '/inc/js/date.js', array( 'jquery' ), GAWD_VERSION );
568
+ wp_enqueue_script( 'gawd_front_js', GAWD_URL . '/inc/js/gawd_front.js', array( 'jquery' ), GAWD_VERSION );
569
+ wp_localize_script( 'gawd_front_js', 'gawd_front', array(
570
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
571
+ 'ajaxnonce' => wp_create_nonce( 'gawd_admin_page_nonce' ),
572
+ 'gawd_plugin_url' => GAWD_URL,
573
+ 'date_30' => date( 'Y-m-d', strtotime( '-31 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
574
+ 'date_7' => date( 'Y-m-d', strtotime( '-8 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
575
+ 'date_last_week' => date( 'Y-m-d', strtotime( 'last week -1day' ) ) . '/-/' . date( 'Y-m-d', strtotime( 'last week +5day' ) ),
576
+ 'date_last_month' => date( 'Y-m-01', strtotime( 'last month' ) ) . '/-/' . date( 'Y-m-t', strtotime( 'last month' ) ),
577
+ 'date_this_month' => date( 'Y-m-01' ) . '/-/' . date( 'Y-m-d' ),
578
+ 'date_today' => date( 'Y-m-d' ) . '/-/' . date( 'Y-m-d' ),
579
+ 'date_yesterday' => date( 'Y-m-d', strtotime( '-1 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
580
+ 'wp_admin_url' => admin_url(),
581
+ 'exportUrl' => add_query_arg( array( 'action' => 'gawd_export' ), admin_url( 'admin-ajax.php' ) )
582
+ ) );
583
+ }
584
+ }
585
+
586
+ public function gawd_enqueue_scripts() {
587
+ $options = get_option( 'gawd_settings' );
588
+ $default_date = ( isset( $options['default_date'] ) && $options['default_date'] != '' ) ? $options['default_date'] : 'last_30days';
589
+ $default_date_format = ( isset( $options['default_date_format'] ) && $options['default_date_format'] != '' ) ? $options['default_date_format'] : 'ymd_with_week';
590
+ $enable_hover_tooltip = ( isset( $options['enable_hover_tooltip'] ) && $options['enable_hover_tooltip'] != '' ) ? $options['enable_hover_tooltip'] : '';
591
+ $screen = get_current_screen();
592
+ if ( strpos( $screen->base, 'gawd' ) !== false || strpos( $screen->post_type, 'page' ) !== false || strpos( $screen->post_type, 'post' ) !== false || strpos( $screen->base, 'dashboard' ) !== false ) {
593
+ wp_enqueue_script( 'common' );
594
+ wp_enqueue_script( 'wp-lists' );
595
+ wp_enqueue_script( 'postbox' );
596
+ wp_enqueue_script( 'jquery-ui-tooltip' );
597
+ wp_enqueue_script( 'gawd_paging', GAWD_URL . '/inc/js/paging.js', false, GAWD_VERSION );
598
+ wp_enqueue_script( 'jquery.cookie', GAWD_URL . '/inc/js/jquery.cookie.js', false, GAWD_VERSION );
599
+ wp_enqueue_style( 'admin_css', GAWD_URL . '/inc/css/gawd_admin.css', false, GAWD_VERSION );
600
+ wp_enqueue_style( 'gawd_licensing', GAWD_URL . '/inc/css/gawd_licensing.css', false, GAWD_VERSION );
601
+ wp_enqueue_style( 'gawd_featured', GAWD_URL . '/featured/style.css', array(), GAWD_VERSION );
602
+ wp_enqueue_style( 'font_awesome', GAWD_URL . '/inc/css/font_awesome.css', false, GAWD_VERSION );
603
+ wp_enqueue_style( 'jquery-ui.css', GAWD_URL . '/inc/css/jquery-ui.css', false, GAWD_VERSION );
604
+ wp_enqueue_style( 'gawd_bootstrap', GAWD_URL . '/inc/css/bootstrap.css', false, GAWD_VERSION );
605
+ wp_enqueue_style( 'gawd_bootstrap-chosen', GAWD_URL . '/inc/css/bootstrap-chosen.css', false, GAWD_VERSION );
606
+ wp_enqueue_style( 'gawd_bootstrap-select', GAWD_URL . '/inc/css/bootstrap-select.css', false, GAWD_VERSION );
607
+ wp_enqueue_style( 'gawd_datepicker', GAWD_URL . '/inc/css/daterangepicker.css', false, GAWD_VERSION );
608
+ wp_enqueue_style( 'ui.jqgrid.css', GAWD_URL . '/inc/css/ui.jqgrid.css', false, GAWD_VERSION );
609
+ wp_enqueue_script( 'gawd_moment', GAWD_URL . '/inc/js/moment.min.js', false, GAWD_VERSION );
610
+ wp_enqueue_script( 'gawd_daterangepicker', GAWD_URL . '/inc/js/daterangepicker.js', false, GAWD_VERSION );
611
+ wp_enqueue_script( 'gawd_amcharts', GAWD_URL . '/inc/js/amcharts.js', false, GAWD_VERSION );
612
+ wp_enqueue_script( 'ddd', 'http://www.amcharts.com/lib/3/plugins/responsive/responsive.min.js?0.9.1a', false, GAWD_VERSION );
613
+ wp_enqueue_script( 'gawd_pie', GAWD_URL . '/inc/js/pie.js', false, GAWD_VERSION );
614
+ wp_enqueue_script( 'gawd_serial', GAWD_URL . '/inc/js/serial.js', false, GAWD_VERSION );
615
+ /*Map*/
616
+ wp_enqueue_script( 'gawd_ammap', GAWD_URL . '/inc/js/ammap.js', false, GAWD_VERSION );
617
+ wp_enqueue_script( 'gawd_worldLow', GAWD_URL . '/inc/js/worldLow.js', false, GAWD_VERSION );
618
+ wp_enqueue_script( 'gawd_map_chart', GAWD_URL . '/inc/js/gawd_map_chart.js', false, GAWD_VERSION );
619
+ /*End Map*/
620
+ wp_enqueue_script( 'gawd_light_theme', GAWD_URL . '/inc/js/light.js', array( 'jquery' ), GAWD_VERSION );
621
+ wp_enqueue_script( 'gawd_dataloader', GAWD_URL . '/inc/js/dataloader.min.js', array( 'jquery' ), GAWD_VERSION );
622
+ wp_enqueue_script( 'rgbcolor.js', GAWD_URL . '/inc/js/rgbcolor.js', array( 'jquery' ), GAWD_VERSION );
623
+ wp_enqueue_script( 'StackBlur.js', GAWD_URL . '/inc/js/StackBlur.js', array( 'jquery' ), GAWD_VERSION );
624
+ wp_enqueue_script( 'canvg.js', GAWD_URL . '/inc/js/canvg.js', array( 'jquery' ), GAWD_VERSION );
625
+ wp_enqueue_script( 'gawd_tables', GAWD_URL . '/inc/js/loader.js', array( 'jquery' ), GAWD_VERSION );
626
+ wp_enqueue_script( 'gawd_grid', GAWD_URL . '/inc/js/jquery.jqGrid.min.js', array( 'jquery' ), GAWD_VERSION );
627
+ wp_enqueue_script( 'gawd_grid_locale', GAWD_URL . '/inc/js/grid.locale-en.js', array( 'jquery' ), GAWD_VERSION );
628
+ wp_enqueue_script( 'date-js', GAWD_URL . '/inc/js/date.js', array( 'jquery' ), GAWD_VERSION );
629
+ wp_enqueue_script( 'admin_js', GAWD_URL . '/inc/js/gawd_admin.js', array( 'jquery' ), GAWD_VERSION );
630
+ wp_enqueue_script( 'chosen.jquery.js', GAWD_URL . '/inc/js/chosen.jquery.js', array( 'jquery' ), GAWD_VERSION );
631
+ wp_enqueue_script( 'bootstrap_js', GAWD_URL . '/inc/js/bootstrap_js.js', array( 'jquery' ), GAWD_VERSION );
632
+ wp_enqueue_script( 'bootstrap-select', GAWD_URL . '/inc/js/bootstrap-select.js', array( 'jquery' ), GAWD_VERSION );
633
+ wp_enqueue_script( 'highlight_js', GAWD_URL . '/inc/js/js_highlight.js', array( 'jquery' ), GAWD_VERSION );
634
+ wp_enqueue_script( 'settings_js', GAWD_URL . '/inc/js/gawd_settings.js', array( 'jquery' ), GAWD_VERSION );
635
+ wp_enqueue_script( 'overview', GAWD_URL . '/inc/js/gawd_overview.js', array( 'jquery' ), GAWD_VERSION );
636
+ wp_localize_script( 'overview', 'gawd_overview', array(
637
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
638
+ 'ajaxnonce' => wp_create_nonce( 'gawd_admin_page_nonce' ),
639
+ 'gawd_plugin_url' => GAWD_URL,
640
+ 'default_date' => $default_date,
641
+ 'enableHoverTooltip' => $enable_hover_tooltip,
642
+ 'wp_admin_url' => admin_url()
643
+ ) );
644
+ wp_localize_script( 'admin_js', 'gawd_admin', array(
645
+ 'ajaxurl' => admin_url( 'admin-ajax.php' ),
646
+ 'ajaxnonce' => wp_create_nonce( 'gawd_admin_page_nonce' ),
647
+ 'gawd_plugin_url' => GAWD_URL,
648
+ 'wp_admin_url' => admin_url(),
649
+ 'enableHoverTooltip' => $enable_hover_tooltip,
650
+ 'default_date' => $default_date,
651
+ 'default_date_format' => $default_date_format,
652
+ 'date_30' => date( 'Y-m-d', strtotime( '-31 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
653
+ 'date_7' => date( 'Y-m-d', strtotime( '-8 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
654
+ 'date_last_week' => date( 'Y-m-d', strtotime( 'last week -1day' ) ) . '/-/' . date( 'Y-m-d', strtotime( 'last week +5day' ) ),
655
+ 'date_last_month' => date( 'Y-m-01', strtotime( 'last month' ) ) . '/-/' . date( 'Y-m-t', strtotime( 'last month' ) ),
656
+ 'date_this_month' => date( 'Y-m-01' ) . '/-/' . date( 'Y-m-d' ),
657
+ 'date_today' => date( 'Y-m-d' ) . '/-/' . date( 'Y-m-d' ),
658
+ 'date_yesterday' => date( 'Y-m-d', strtotime( '-1 day' ) ) . '/-/' . date( 'Y-m-d', strtotime( '-1 day' ) ),
659
+ 'exportUrl' => add_query_arg( array( 'action' => 'gawd_export' ), admin_url( 'admin-ajax.php' ) )
660
+ ) );
661
+ }
662
+ }
663
+
664
+ /**
665
+ * Adds the menu page with its submenus.
666
+ */
667
+ public function gawd_add_menu() {
668
+
669
+
670
+ $gawd_settings = get_option( 'gawd_settings' );
671
+ $gawd_permissions = isset( $gawd_settings['gawd_permissions'] ) ? $gawd_settings['gawd_permissions'] : array();
672
+ if ( empty( $gawd_permissions ) ) {
673
+ $permission = 'manage_options';
674
+ } else {
675
+ if ( in_array( 'manage_options', $gawd_permissions ) ) {
676
+ $permission = 'manage_options';
677
+ }
678
+ if ( in_array( 'moderate_comments', $gawd_permissions ) ) {
679
+ $permission = 'moderate_comments';
680
+ }
681
+ if ( in_array( 'publish_posts', $gawd_permissions ) ) {
682
+ $permission = 'publish_posts';
683
+ }
684
+ if ( in_array( 'edit_posts', $gawd_permissions ) ) {
685
+ $permission = 'edit_posts';
686
+ }
687
+ }
688
+ add_menu_page(
689
+ __( 'Analytics', 'gawd' ), //$page_title
690
+ __( 'Analytics', 'gawd' ), //$menu_title
691
+ $permission, //$capability
692
+ 'gawd_analytics', //$menu_slug
693
+ array( $this, $this->gawd_set_display( 'gawd_display_overview_page' ) ), //$function = '',
694
+ GAWD_URL . '/assets/main_icon.png'
695
+ //$position = null
696
+ );
697
+
698
+ add_submenu_page(
699
+ 'gawd_analytics', //$parent_slug
700
+ __( 'Overview', 'gawd' ), //$page_title
701
+ __( 'Overview', 'gawd' ), //$menu_title
702
+ $permission, //$capability
703
+ $this->gawd_set_slug( 'gawd_analytics' ), //$menu_slug
704
+ array( $this, $this->gawd_set_display( 'gawd_display_overview_page' ) ) //$function = '',
705
+ );
706
+ add_submenu_page(
707
+ 'gawd_analytics', //$parent_slug
708
+ __( 'Reports', 'gawd' ), //$page_title
709
+ __( 'Reports', 'gawd' ), //$menu_title
710
+ $permission, //$capability
711
+ $this->gawd_set_slug( 'gawd_reports' ), //$menu_slug
712
+ array( $this, $this->gawd_set_display( 'gawd_display_reports_page' ) ) //$function = '',
713
+ );
714
+
715
+ add_submenu_page(
716
+ 'gawd_analytics', //$parent_slug
717
+ __( 'Settings', 'gawd' ), //$page_title
718
+ __( 'Settings', 'gawd' ), //$menu_title
719
+ $permission, //$capability
720
+ 'gawd_settings', //$menu_slug
721
+ array( $this, 'gawd_display_settings_page' ) //$function = '',
722
+
723
+ );
724
+ add_submenu_page(
725
+ 'gawd_analytics', //$parent_slug
726
+ __( 'Tracking', 'gawd' ), //$page_title
727
+ __( 'Tracking', 'gawd' ), //$menu_title
728
+ $permission, //$capability
729
+ $this->gawd_set_slug( 'gawd_tracking' ), //$menu_slug
730
+ array( $this, $this->gawd_set_display( 'gawd_display_tracking_page' ) ) //$function = '',
731
+ );
732
+ add_submenu_page(
733
+ 'gawd_analytics', //$parent_slug
734
+ __( 'Goal Management', 'gawd' ), //$page_title
735
+ __( 'Goal Management', 'gawd' ), //$menu_title
736
+ $permission, //$capability
737
+ $this->gawd_set_slug( 'gawd_goals' ), //$menu_slug
738
+ array( $this, $this->gawd_set_display( 'gawd_display_goals_page' ) ) //$function = '',
739
+ );
740
+
741
+ add_submenu_page(
742
+ 'gawd_analytics', //$parent_slug
743
+ __( 'Custom Reports', 'gawd' ), //$page_title
744
+ __( 'Custom Reports', 'gawd' ), //$menu_title
745
+ $permission, //$capability
746
+ $this->gawd_set_slug( 'gawd_custom_reports' ), //$menu_slug
747
+ array( $this, $this->gawd_set_display( 'gawd_display_custom_reports_page' ) ) //$function = '',
748
+ );
749
+ add_submenu_page(
750
+ 'gawd_analytics', //$parent_slug
751
+ __( 'Get Pro', 'gawd' ), //$page_title
752
+ __( 'Get Pro', 'gawd' ), //$menu_title
753
+ $permission, //$capability
754
+ 'gawd_licensing', //$menu_slug
755
+ array( $this, 'gawd_display_licensing_page' ) //$function = '',
756
+ );
757
+ add_submenu_page(
758
+ 'gawd_analytics', //$parent_slug
759
+ __( 'Featured Plugins', 'gawd' ), //$page_title
760
+ __( 'Featured Plugins', 'gawd' ), //$menu_title
761
+ $permission, //$capability
762
+ 'gawd_featured_plugins', //$menu_slug
763
+ array( $this, 'gawd_display_featured_plugins_page' ) //$function = '',
764
+ );
765
+ add_submenu_page(
766
+ 'gawd_analytics', //$parent_slug
767
+ __( 'Featured Themes', 'gawd' ), //$page_title
768
+ __( 'Featured Themes', 'gawd' ), //$menu_title
769
+ $permission, //$capability
770
+ 'gawd_featured_themes', //$menu_slug
771
+ array( $this, 'gawd_display_featured_themes_page' ) //$function = '',
772
+ );
773
+ add_submenu_page(
774
+ 'gawd_analytics', //$parent_slug
775
+ __( 'Uninstall', 'gawd' ), //$page_title
776
+ __( 'Uninstall', 'gawd' ), //$menu_title
777
+ $permission, //$capability
778
+ 'gawd_uninstall', //$menu_slug
779
+ array( $this, 'gawd_display_uninstall_page' ) //$function = '',
780
+ );
781
+
782
+ }
783
+
784
+
785
+ public function gawd_set_slug( $slug ) {
786
  global $gawd_redirect_to_settings;
787
+ if ( $gawd_redirect_to_settings == 'yes' ) {
788
  return 'gawd_settings';
789
+ } else {
790
  return $slug;
791
  }
792
  }
793
 
794
+ public function gawd_set_display( $slug ) {
795
  global $gawd_redirect_to_settings;
796
+ if ( $gawd_redirect_to_settings == 'yes' ) {
797
  return 'gawd_display_settings_page';
798
+ } else {
799
  return $slug;
800
  }
801
  }
802
 
803
+ public function gawd_display_licensing_page() {
804
+ require_once( GAWD_DIR . '/admin/licensing.php' );
805
+ }
806
+
807
+ function upgrade_pro() {
808
+ $screen = get_current_screen();
809
+ if ( strpos( $screen->base, 'gawd' ) !== false && strpos( $screen->base, 'gawd_featured' ) === false ) {
810
+ ?>
811
+ <div class="gawd_upgrade wd-clear">
812
+ <div class="wd-right">
813
+ <a href="https://web-dorado.com/products/wordpress-google-analytics-plugin.html" target="_blank">
814
+ <div class="wd-table">
815
+ <div class="wd-cell wd-cell-valign-middle">
816
+ <?php _e( "Upgrade to paid version", "gawd" ); ?>
817
+ </div>
818
+
819
+ <div class="wd-cell wd-cell-valign-middle">
820
+ <img src="<?php echo GAWD_URL; ?>/assets/web-dorado.png">
821
+ </div>
822
+ </div>
823
+ </a>
824
+ </div>
825
+ </div>
826
+ <?php
827
+ }
828
+ }
829
+
830
+ public function gawd_display_featured_plugins_page() {
831
+ require_once( GAWD_DIR . '/featured/featured.php' );
832
+ gawd_featured_plugins( 'wd-google-analytics' );
833
+
834
+ }
835
+
836
+ public function gawd_display_featured_themes_page() {
837
+ require_once( GAWD_DIR . '/featured/featured_themes.php' );
838
+ $controller = new gawd_featured_themes();
839
+ $controller->display();
840
+ }
841
+
842
+ public function gawd_auth() {
843
+ check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
844
+ $code = $_POST['token'];
845
+ $status = GAWD_google_client::authenticate( $code );
846
+ if ( $status === true ) {
847
+ $res = array(
848
+ 'message' => 'successfully saved',
849
+ 'status' => $status,
850
+ );
851
+ } else {
852
+ $res = array(
853
+ 'message' => 'there is an error',
854
+ 'status' => $status
855
+ );
856
+ }
857
+ header( 'content-type: application/json' );
858
+ echo json_encode( $res );
859
+ wp_die();
860
+ }
861
+
862
+ /**
863
+ * Displays the Dashboard page.
864
+ */
865
+ public function gawd_display_uninstall_page() {
866
+ require_once( 'admin/pages/uninstall.php' );
867
+ $gawd_uninstall = new GAWDUninstall();
868
+ $deactivate_url = wp_nonce_url( 'plugins.php?action=deactivate&plugin=' . GWD_NAME . '/google-analytics-wd.php', 'deactivate-plugin_' . GWD_NAME . '/google-analytics-wd.php' );
869
+ $deactivate_url = str_replace( '&amp;', '&', $deactivate_url );
870
+ if ( isset( $_POST['unistall_gawd'] ) ) {
871
+ check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
872
+ delete_option( 'gawd_custom_reports' );
873
+ delete_option( 'gawd_menu_for_user' );
874
+ delete_option( 'gawd_all_metrics' );
875
+ delete_option( 'gawd_all_dimensions' );
876
+ delete_option( 'gawd_custom_dimensions' );
877
+ delete_option( 'gawd_settings' );
878
+ delete_option( 'gawd_user_data' );
879
+ delete_option( 'gawd_credentials' );
880
+ delete_option( 'gawd_menu_items' );
881
+ delete_option( 'gawd_export_chart_data' );
882
+ delete_option( 'gawd_email' );
883
+ delete_option( 'gawd_custom_reports' );
884
+ delete_option( 'gawd_alerts' );
885
+ delete_option( 'gawd_pushovers' );
886
+ delete_option( 'gawd_menu_for_users' );
887
+ delete_option( 'gawd_own_project' );
888
+ delete_option( 'gawd_zoom_message' );
889
+ delete_transient( 'gawd_user_profiles' );
890
+ echo '<script>window.location.href="' . $deactivate_url . '";</script>';
891
+ }
892
+ if ( get_option( 'gawd_credentials' ) ) {
893
+ $gawd_uninstall->uninstall();
894
+ }
895
+ }
896
+
897
+ public function gawd_display_goals_page() {
898
+ global $gawd_client;
899
+ if ( $this->manage_ua_code_selection() != 'done' ) {
900
+ return;
901
+ }
902
+ $gawd_client = GAWD_google_client::get_instance();
903
+ if ( ! empty( $_POST ) ) {
904
+ check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
905
+ }
906
+ $gawd_goal_profile = isset( $_POST['gawd_goal_profile'] ) ? sanitize_text_field( $_POST['gawd_goal_profile'] ) : '';
907
+ $gawd_goal_name = isset( $_POST['gawd_goal_name'] ) ? sanitize_text_field( $_POST['gawd_goal_name'] ) : '';
908
+ $gawd_goal_type = isset( $_POST['gawd_goal_type'] ) ? sanitize_text_field( $_POST['gawd_goal_type'] ) : '';
909
+ $gawd_visit_hour = isset( $_POST['gawd_visit_hour'] ) ? sanitize_text_field( $_POST['gawd_visit_hour'] ) : '';
910
+ $gawd_visit_minute = isset( $_POST['gawd_visit_minute'] ) ? sanitize_text_field( $_POST['gawd_visit_minute'] ) : '';
911
+ $gawd_visit_second = isset( $_POST['gawd_visit_second'] ) ? sanitize_text_field( $_POST['gawd_visit_second'] ) : '';
912
+ $gawd_goal_duration_comparison = isset( $_POST['gawd_goal_duration_comparison'] ) ? sanitize_text_field( $_POST['gawd_goal_duration_comparison'] ) : '';
913
+ $gawd_goal_page_comparison = isset( $_POST['gawd_goal_page_comparison'] ) ? sanitize_text_field( $_POST['gawd_goal_page_comparison'] ) : '';
914
+ $gawd_page_sessions = isset( $_POST['gawd_page_sessions'] ) ? sanitize_text_field( $_POST['gawd_page_sessions'] ) : '';
915
+ $goal_max_id = isset( $_POST['goal_max_id'] ) ? $_POST['goal_max_id'] + 1 : 1;
916
+ $gawd_goal_page_destination_match = isset( $_POST['gawd_goal_page_destination_match'] ) ? sanitize_text_field( $_POST['gawd_goal_page_destination_match'] ) : '';
917
+ $gawd_page_url = isset( $_POST['gawd_page_url'] ) ? sanitize_text_field( $_POST['gawd_page_url'] ) : '';
918
+ $url_case_sensitve = isset( $_POST['url_case_sensitve'] ) ? $_POST['url_case_sensitve'] : '';
919
+ if ( $gawd_goal_type == 'VISIT_TIME_ON_SITE' ) {
920
+ if ( $gawd_visit_hour != '' || $gawd_visit_minute != '' || $gawd_visit_second != '' ) {
921
+ $value = 0;
922
+ if ( $gawd_visit_hour != '' ) {
923
+ $value += $gawd_visit_hour * 60 * 60;
924
+ }
925
+ if ( $gawd_visit_minute != '' ) {
926
+ $value += $gawd_visit_minute * 60;
927
+ }
928
+ if ( $gawd_visit_second != '' ) {
929
+ $value += $gawd_visit_second;
930
+ }
931
+ }
932
+ $gawd_client->add_goal( $gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_duration_comparison, $value );
933
+ } elseif ( $gawd_goal_type == 'VISIT_NUM_PAGES' ) {
934
+ if ( $gawd_page_sessions != '' ) {
935
+ $gawd_client->add_goal( $gawd_goal_profile, $goal_max_id, $gawd_goal_type, $gawd_goal_name, $gawd_goal_page_comparison, $gawd_page_sessions );
936
+ }
937
+ } elseif ( $gawd_goal_type == 'URL_DESTINATION' ) {
938
+ if ( $gawd_page_url != '' ) {
939
+ $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 );
940
+ }
941
+ } elseif ( $gawd_goal_type == 'EVENT' ) {
942
+ if ( $gawd_page_url != '' ) {
943
+ $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 );
944
+ }
945
+ }
946
+ require_once( 'admin/pages/goals.php' );
947
+
948
+ }
949
+
950
+ public function gawd_display_custom_reports_page() {
951
+ global $gawd_client;
952
+ if ( ! empty( $_POST ) ) {
953
+ check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
954
+ }
955
+ $gawd_client = GAWD_google_client::get_instance();
956
+ $gawd_remove_custom_report = isset( $_POST['gawd_remove_custom_report'] ) ? sanitize_text_field( $_POST['gawd_remove_custom_report'] ) : '';
957
+ if ( $gawd_remove_custom_report ) {
958
+ $all_reports = get_option( "gawd_custom_reports" );
959
+ if ( $all_reports ) {
960
+ unset( $all_reports[ $gawd_remove_custom_report ] );
961
+ update_option( 'gawd_custom_reports', $all_reports );
962
+ self::add_dashboard_menu();
963
+ }
964
+ }
965
+ if ( isset( $_POST['gawd_add_custom_report'] ) ) {
966
+ $gawd_custom_report_name = isset( $_POST['gawd_custom_report_name'] ) ? sanitize_text_field( $_POST['gawd_custom_report_name'] ) : '';
967
+ $gawd_custom_report_metric = isset( $_POST['gawd_custom_report_metric'] ) ? sanitize_text_field( $_POST['gawd_custom_report_metric'] ) : '';
968
+ $gawd_custom_report_dimension = isset( $_POST['gawd_custom_report_dimension'] ) ? sanitize_text_field( $_POST['gawd_custom_report_dimension'] ) : '';
969
+
970
+ if ( $gawd_custom_report_name != '' && $gawd_custom_report_metric != '' && $gawd_custom_report_dimension != '' ) {
971
+ $saved_custom_reports = get_option( "gawd_custom_reports" );
972
+ if ( ! isset( $saved_custom_reports[ $gawd_custom_report_name ] ) ) {
973
+ if ( $saved_custom_reports ) {
974
+ $custom_reports = array(
975
+ 'metric' => $gawd_custom_report_metric,
976
+ 'dimension' => $gawd_custom_report_dimension,
977
+ 'id' => count( $saved_custom_reports ) + 1
978
+ );
979
+ $saved_custom_reports[ $gawd_custom_report_name ] = $custom_reports;
980
+
981
+ update_option( 'gawd_custom_reports', $saved_custom_reports );
982
+ } else {
983
+ $custom_reports = array(
984
+ $gawd_custom_report_name => array(
985
+ 'metric' => $gawd_custom_report_metric,
986
+ 'dimension' => $gawd_custom_report_dimension,
987
+ 'id' => 1
988
+ )
989
+ );
990
+ update_option( 'gawd_custom_reports', $custom_reports );
991
+ }
992
+ }
993
+ }
994
+ self::add_dashboard_menu();
995
+ }
996
+ require_once( 'admin/pages/custom_reports.php' );
997
+ }
998
+
999
+ public function gawd_display_overview_page() {
1000
+ global $gawd_client, $gawd_user_data;
1001
+ $gawd_client = GAWD_google_client::get_instance();
1002
+ $profiles = $gawd_client->get_profiles();
1003
+ $gawd_user_data = get_option( 'gawd_user_data' );
1004
+ if ( isset( $_POST['gawd_id'] ) ) {
1005
+ $gawd_user_data['gawd_id'] = isset( $_POST['gawd_id'] ) ? $_POST['gawd_id'] : '';
1006
+ foreach ( $gawd_user_data['gawd_profiles'] as $web_property_name => $web_property ) {
1007
+ foreach ( $web_property as $profile ) {
1008
+ if ( $profile['id'] == $gawd_user_data['gawd_id'] ) {
1009
+ $gawd_user_data['web_property_name'] = $web_property_name;
1010
+ $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1011
+ $gawd_user_data['accountId'] = $profile['accountId'];
1012
+ }
1013
+ }
1014
+ }
1015
+ $gawd_user_data['web_property_name'] = isset( $_POST['web_property_name'] ) ? $_POST['web_property_name'] : '';
1016
+ update_option( 'gawd_user_data', $gawd_user_data );
1017
+ }
1018
+ require_once( 'admin/pages/overview.php' );
1019
+ }
1020
+
1021
+ public function gawd_display_reports_page() {
1022
+ global $gawd_client, $gawd_user_data;
1023
+ $gawd_client = GAWD_google_client::get_instance();
1024
+ $profiles = $gawd_client->get_profiles();
1025
+ $gawd_user_data = get_option( 'gawd_user_data' );
1026
+ if ( isset( $_POST['gawd_id'] ) ) {
1027
+ $gawd_user_data['gawd_id'] = isset( $_POST['gawd_id'] ) ? $_POST['gawd_id'] : '';
1028
+ foreach ( $gawd_user_data['gawd_profiles'] as $web_property_name => $web_property ) {
1029
+ foreach ( $web_property as $profile ) {
1030
+ if ( $profile['id'] == $gawd_user_data['gawd_id'] ) {
1031
+ $gawd_user_data['web_property_name'] = $web_property_name;
1032
+ $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1033
+ $gawd_user_data['accountId'] = $profile['accountId'];
1034
+ }
1035
+ }
1036
+ }
1037
+ $gawd_user_data['web_property_name'] = isset( $_POST['web_property_name'] ) ? $_POST['web_property_name'] : '';
1038
+ update_option( 'gawd_user_data', $gawd_user_data );
1039
+ }
1040
+ require_once( 'admin/pages/dashboard.php' );
1041
+ }
1042
+
1043
+ public function gawd_daily_email() {
1044
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1045
+ $gawd_client = GAWD_google_client::get_instance();
1046
+ $emails = get_option( 'gawd_email' );
1047
+ $gawd_user_data = get_option( 'gawd_user_data' );
1048
+ $data = '';
1049
+ foreach ( $emails as $email ) {
1050
+ if ( isset( $email['period'] ) && $email['period'] == 'daily' ) {
1051
+ //pls send email if ....
1052
+ $date = date( 'Y-m-d', strtotime( 'yesterday' ) );
1053
+ $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 . ')';
1054
+ $data = $this->show_data( array(
1055
+ 'metric' => 'ga:' . $email['metric'],
1056
+ 'dimension' => $email['dimension'],
1057
+ 'start_date' => $date,
1058
+ 'end_date' => $date
1059
+ ) );
1060
+ if ( $email['export_type'] == 'pdf' ) {
1061
+ $filedir = $this->create_pdf_file( false, $data, $email['dimension'], $date, $date, $email['metric_compare'], $email['metric'] );
1062
+ } else {
1063
+ $filedir = $this->create_csv_file( false, $data, $email['dimension'], $date, $date, $email['metric_compare'], $email['metric'] );
1064
+ }
1065
+ //$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);
1066
+ $attachment = $filedir;
1067
+ $headers = 'From: <' . $email['email_from'] . '>';
1068
+ wp_mail( $email['emails'], $email_subject, $email['email_body'], $headers, $attachment );
1069
+ }
1070
+ }
1071
+ }
1072
+
1073
+ public function gawd_weekly_email() {
1074
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1075
+ $gawd_client = GAWD_google_client::get_instance();
1076
+ $emails = get_option( 'gawd_email' );
1077
+ $gawd_user_data = get_option( 'gawd_user_data' );
1078
+ $data = '';
1079
+ foreach ( $emails as $email ) {
1080
+ if ( isset( $email['period'] ) && $email['period'] == 'gawd_weekly' ) {
1081
+ //pls send email if ....
1082
+ /*$start_date = date('Y-m-d', strtotime('last' . $email['period_day']));
1083
  $end_date = date('Y-m-d', strtotime('this' . $email['period_day']));*/
1084
+ $start_date = date( 'Y-m-d', strtotime( 'last week -1 day' ) );
1085
+ $end_date = date( 'l' ) != 'Sunday' ? date( 'Y-m-d', strtotime( 'last sunday -1 day' ) ) : date( 'Y-m-d', strtotime( '-1 day' ) );
1086
+ $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 . ')';
1087
+ $data = $this->show_data( array(
1088
+ 'metric' => 'ga:' . $email['metric'],
1089
+ 'dimension' => $email['dimension'],
1090
+ 'start_date' => $start_date,
1091
+ 'end_date' => $end_date
1092
+ ) );
1093
+ if ( $email['export_type'] == 'pdf' ) {
1094
+ $filedir = $this->create_pdf_file( false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric'] );
1095
+ } else {
1096
+ $filedir = $this->create_csv_file( false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric'] );
1097
+ }
1098
+ //$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);
1099
+ $attachment = $filedir;
1100
+
1101
+ $headers = 'From: <' . $email['email_from'] . '>';
1102
+ wp_mail( $email['emails'], $email_subject, $email['email_body'], $headers, $attachment );
1103
+ }
1104
+ }
1105
+ }
1106
 
1107
+ public function gawd_monthly_email() {
1108
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1109
+ $gawd_client = GAWD_google_client::get_instance();
1110
+ $emails = get_option( 'gawd_email' );
1111
+ $gawd_user_data = get_option( 'gawd_user_data' );
1112
+ $data = '';
1113
+ foreach ( $emails as $email ) {
1114
+ if ( isset( $email['period'] ) && $email['period'] == 'gawd_monthly' ) {
1115
+ //pls send email if ....
1116
+ $end_date = date( 'Y-m-d', strtotime( date( 'Y-' . date( 'm' ) . '-1' ) . '-1 day' ) );
1117
+ $start_date = date( 'Y-m-d', strtotime( $end_date . '- 1 month' ) );
1118
+ $data = $this->show_data( array(
1119
+ 'metric' => 'ga:' . $email['metric'],
1120
+ 'dimension' => $email['dimension'],
1121
+ 'start_date' => $start_date,
1122
+ 'end_date' => $end_date
1123
+ ) );
1124
+ $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 . ')';
1125
+ if ( $email['export_type'] == 'pdf' ) {
1126
+ $filedir = $this->create_pdf_file( false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric'] );
1127
+ } else {
1128
+ $filedir = $this->create_csv_file( false, $data, $email['dimension'], $start_date, $end_date, $email['metric_compare'], $email['metric'] );
1129
+ }
1130
+ //$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);
1131
+ $attachment = $filedir;
1132
+ $headers = 'From: <' . $email['email_from'] . '>';
1133
+ wp_mail( $email['emails'], $email_subject, $email['email_body'], $headers, $attachment );
1134
+ }
1135
+ }
1136
+ }
1137
+
1138
+ /**
1139
+ * Prepares the settings to be displayed then displays the settings page.
1140
+ */
1141
+ public static function gawd_settings_defaults() {
1142
+ $settings = get_option( 'gawd_settings' );
1143
+ $settings['gawd_tracking_enable'] = 'on';
1144
+ $settings['gawd_custom_dimension_Logged_in'] = 'on';
1145
+ $settings['gawd_custom_dimension_Post_type'] = 'on';
1146
+ $settings['gawd_custom_dimension_Author'] = 'on';
1147
+ $settings['gawd_custom_dimension_Category'] = 'on';
1148
+ $settings['gawd_custom_dimension_Published_Month'] = 'on';
1149
+ $settings['gawd_custom_dimension_Published_Year'] = 'on';
1150
+ $settings['gawd_custom_dimension_Tags'] = 'on';
1151
+ $settings['enable_hover_tooltip'] = 'on';
1152
+ update_option( 'gawd_settings', $settings );
1153
+ }
1154
+
1155
+ public function manage_ua_code_selection() {
1156
+ global $gawd_user_data, $gawd_client;
1157
+ $gawd_user_data = get_option( 'gawd_user_data' );
1158
+ if ( isset( $gawd_user_data['default_webPropertyId'] ) && $gawd_user_data['default_webPropertyId'] ) {
1159
+ return 'done';
1160
+ } else {
1161
+ $gawd_client = GAWD_google_client::get_instance();
1162
+ $property = $gawd_client->property_exists();
1163
+ if ( $property == 'no_matches' ) {
1164
+ $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' );
1165
+ // show notice that you don't have property with current site url
1166
+ // add account or property to an existing account
1167
+ } elseif ( count( $property ) == 1 ) {
1168
+ $property = $property[0];
1169
+ $gawd_user_data['webPropertyId'] = $property['id'];
1170
+ $gawd_user_data['default_webPropertyId'] = $property['id'];
1171
+ $gawd_user_data['accountId'] = $property['accountId'];
1172
+ $gawd_user_data['default_accountId'] = $property['accountId'];
1173
+ $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
1174
+ update_option( 'gawd_user_data', $gawd_user_data );
1175
+ $this->gawd_admin_notice( "In order to enable tracking for your website, you have to go with
1176
+ <a href='" . admin_url( 'admin.php?page=gawd_tracking' ) . "'>this</a> link and turn the option on.", 'warning is-dismissible' );
1177
+ // show notice that you have to enable tracking code, link to tracking submenu
1178
+ } else {
1179
+ $this->gawd_admin_notice( "You have two or more web-properties configured with current site url. Please go with
1180
+ <a href='" . admin_url( 'admin.php?page=gawd_tracking' ) . "'>this</a> link to select the proper one.", 'error' );
1181
+ // show notice that you have >=2 properties with current site url
1182
+ // select property from same url properties
1183
+ }
1184
+ }
1185
+ }
1186
+
1187
+ public function manage_ua_code_selection_tracking() {
1188
+ global $gawd_user_data;
1189
+ if ( isset( $gawd_user_data['default_webPropertyId'] ) && $gawd_user_data['default_webPropertyId'] ) {
1190
+ return 'done';
1191
+ } else {
1192
+ $gawd_client = GAWD_google_client::get_instance();
1193
+ $property = $gawd_client->property_exists();
1194
+ if ( $property == 'no_matches' ) {
1195
+ $accounts = $gawd_client->get_management_accounts();
1196
+ if ( ! empty( $accounts ) ) {
1197
+ echo "<h3 style='margin-top:10px' class='gawd_page_titles'>Tracking</h3>
 
1198
  <p class='gawd_notice notice'>Here you can add a <b>web property</b> on your Google Analytics account using current WordPress website.<br>
1199
  Provide a <b>Name</b> for the property and click <b>Add</b>. You can check and manage web properties from your Google Analytics account, <b>Admin</b> page.<br>
1200
  Alternatively, you can click <b>Later</b> and configure the web property any other time.</p>
1205
  <span class='gawd_goal_label'>Account</span>
1206
  <span class='gawd_goal_input'>
1207
  <select name='gawd_account_select' class='gawd_account_select' style='padding: 2px;width: 96%;line-height: 30px;height: 30px !important;'>";
1208
+ foreach ( $accounts as $account ) {
1209
+ echo "<option value='" . $account['id'] . "'>" . $account['name'] . "</option>";
1210
+ }
1211
+ echo "</select>
1212
  </span>
1213
  <div class='gawd_info' title='this_is_tooltip'></div>
1214
  <div class='clear'></div>
1223
  </div>
1224
  </div>
1225
  <div class='gawd_add_prop gawd_submit'>
1226
+ <a href='" . admin_url() . "admin.php?page=gawd_analytics' class='gawd_later button_gawd'>Later</a>
1227
  <input type='submit' name='add_property' class='button_gawd' value='ADD'/>
1228
  </div>
1229
  </form>";
1230
+ // account select to add web property and web property parameters
1231
+ // and add link to google analytics for manually creating an account
1232
+ // wp_die();
1233
+ } else {
1234
+ $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" );
1235
+ // link to google analytics to add account
1236
+ // wp_die();
1237
+ }
1238
+ } elseif ( count( $property ) == 1 ) {
1239
+ $property = $property[0];
1240
+ $gawd_user_data['webPropertyId'] = $property['id'];
1241
+ $gawd_user_data['default_webPropertyId'] = $property['id'];
1242
+ $gawd_user_data['accountId'] = $property['accountId'];
1243
+ $gawd_user_data['default_accountId'] = $property['accountId'];
1244
+ $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
1245
+ update_option( 'gawd_user_data', $gawd_user_data );
1246
+ } else {
1247
+ 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>
1248
  <br/>
1249
  <form method='post' id='gawd_property_select'>
1250
  <div class='gawd_settings_wrapper'>
1252
  <span class='gawd_goal_label'>Web-property</span>
1253
  <span class='gawd_goal_input'>
1254
  <select name='gawd_property_select' class='gawd_property_select' style='padding: 2px;width: 96%;line-height: 30px;height: 30px !important;'>";
1255
+ foreach ( $property as $select_property ) {
1256
+ echo "<option value='" . $select_property['id'] . "'>" . $select_property['name'] . " (" . $select_property['id'] . ")</option>";
1257
+ }
1258
+ echo "</select>
1259
  </span>
1260
  <div class='gawd_info' title='this_is_tooltip'></div>
1261
  <div class='clear'></div>
1263
  </div>
1264
  <div class='gawd_submit'><input type='submit' name='lock_property' class='button_gawd' value='SAVE'/></div>
1265
  </form>";
1266
+ // web property select to select from properties with same site url
1267
+ // wp_die();
1268
+ }
1269
+ }
1270
+ }
1271
+
1272
+ public function gawd_admin_notice( $message, $type ) {
1273
+ $class = 'notice notice-' . $type;
1274
+ echo '<div class="' . $class . '"><p>' . $message . '</p></div>';
1275
+ }
1276
+
1277
+ public function gawd_display_settings_page() {
1278
+
1279
+ global $gawd_user_data;
1280
+ $gawd_user_data = get_option( 'gawd_user_data' );
1281
+ if ( isset( $_GET['defaultExist'] ) && $_GET['defaultExist'] == 1 ) {
1282
+ $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1283
+ echo '<script>window.location.href="' . $redirect_url . '";</script>';
1284
+ }
1285
+ if ( isset( $_POST['gawd_settings_logout'] ) && $_POST['gawd_settings_logout'] == 1 ) {
1286
+ delete_option( 'gawd_user_data' );
1287
+ $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
1288
+ echo '<script>window.location.href="' . $redirect_url . '";</script>';
1289
+ }
1290
+ if ( isset( $_POST['web_property_name'] ) && $_POST['web_property_name'] != '' ) {
1291
+ $gawd_user_data['gawd_id'] = isset( $_POST['gawd_id'] ) ? $_POST['gawd_id'] : '';
1292
+ foreach ( $gawd_user_data['gawd_profiles'] as $web_property_name => $web_property ) {
1293
+ foreach ( $web_property as $profile ) {
1294
+ if ( $profile['id'] == $gawd_user_data['gawd_id'] ) {
1295
+ $gawd_user_data['web_property_name'] = $web_property_name;
1296
+ $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1297
+ $gawd_user_data['accountId'] = $profile['accountId'];
1298
+ }
1299
+ }
1300
+ }
1301
+ $gawd_user_data['web_property_name'] = isset( $_POST['web_property_name'] ) ? $_POST['web_property_name'] : '';
1302
+ update_option( 'gawd_user_data', $gawd_user_data );
1303
+ $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
1304
+ //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1305
+ }
1306
+ /* if(isset($_POST['account_name']) && $_POST['account_name'] != ''){
1307
  $gawd_user_data['accountId'] = isset($_POST['gawd_id']) ? $_POST['gawd_id'] : '';
1308
  foreach ($gawd_user_data['gawd_profiles'] as $web_property_name => $web_property) {
1309
  foreach ($web_property as $profile) {
1319
  $redirect_url = admin_url() . 'admin.php?page=gawd_settings';
1320
  //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1321
  } */
1322
+ if ( isset( $_GET['errorMsg'] ) ) {
1323
+ self::error_message( 'error', 'User does not have sufficient permissions for this account to add filter' );
1324
+ }
1325
+ if ( ! isset( $gawd_user_data['refresh_token'] ) || ( $gawd_user_data['refresh_token'] == '' ) ) {
1326
+ 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;">AUTHENTICATE</div>';
1327
+ echo '<div id="gawd_auth_code"><form id="gawd_auth_code_paste" action="" method="post"><input id="gawd_token" type="text">';
1328
+ wp_nonce_field( "gawd_save_form", "gawd_save_form_fild" );
1329
+ echo '</form>
1330
  <div id="gawd_auth_code_submit">SUBMIT</div></div>';
1331
+ $gawd_own_project = get_option( 'gawd_own_project' );
1332
+ if ( isset( $gawd_own_project ) && $gawd_own_project && intval( $gawd_own_project ) == 1 ) {
1333
+ echo '<form method="post">
1334
  <div class="gawd_reset_button">
1335
  <input type="hidden" name="reset_data" id="reset_data"/>
1336
  <input type="button" class="button_gawd" id="gawd_reset_button" value="RESET"/>
1337
  </div>
1338
  </form>';
1339
+ }
1340
+ 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>
1341
  <div id="loading_div" style="display:none; text-align: center; position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 99999;">
1342
  <img src="' . GAWD_URL . '/assets/ajax_loader.gif" style="margin-top: 200px; width:50px;">
1343
  </div>';
1344
+ } else {
1345
+ if ( $this->manage_ua_code_selection() != 'done' ) {
1346
+ // return;
1347
+ }
1348
+ try {
1349
+ $gawd_client = GAWD_google_client::get_instance();
1350
+ $gawd_client->get_profiles();
1351
+
1352
+ } catch ( Google_Service_Exception $e ) {
1353
+ $errors = $e->getErrors();
1354
+
1355
+ return $errors[0]["message"];
1356
+ } catch ( Exception $e ) {
1357
+ return $e->getMessage();
1358
+ }
1359
+
1360
+ $gawd_alert_remove = isset( $_POST['gawd_alert_remove'] ) ? intval( $_POST['gawd_alert_remove'] ) : false;
1361
+ $gawd_menu_remove = isset( $_POST['gawd_menu_remove'] ) ? intval( $_POST['gawd_menu_remove'] ) : false;
1362
+ $gawd_pushover_remove = isset( $_POST['gawd_pushover_remove'] ) ? intval( $_POST['gawd_pushover_remove'] ) : false;
1363
+ $gawd_email_remove = isset( $_POST['gawd_email_remove'] ) ? intval( $_POST['gawd_email_remove'] ) : false;
1364
+ $gawd_filter_remove = isset( $_POST['gawd_filter_remove'] ) ? intval( $_POST['gawd_filter_remove'] ) : false;
1365
+ if ( $gawd_alert_remove ) {
1366
+ $all_alerts = get_option( 'gawd_alerts' );
1367
+ if ( $all_alerts ) {
1368
+ foreach ( $all_alerts as $alert ) {
1369
+ wp_unschedule_event( wp_next_scheduled( 'gawd_alert_' . $alert['period'] ), 'gawd_alert_' . $alert['period'] );
1370
+ }
1371
+ unset( $all_alerts[ $gawd_alert_remove - 1 ] );
1372
+ update_option( 'gawd_alerts', $all_alerts );
1373
+ }
1374
+ }
1375
+ if ( $gawd_menu_remove ) {
1376
+ $all_menues = get_option( 'gawd_menu_for_user' );
1377
+ if ( $all_menues ) {
1378
+ unset( $all_menues[ $gawd_menu_remove ] );
1379
+ update_option( 'gawd_menu_for_user', $all_menues );
1380
+ }
1381
+ }
1382
+ if ( $gawd_email_remove ) {
1383
+ $all_emails = get_option( 'gawd_email' );
1384
+ if ( $all_emails ) {
1385
+ foreach ( $all_emails as $email ) {
1386
+ wp_unschedule_event( wp_next_scheduled( 'gawd_email_' . $email['period'] ), 'gawd_email_' . $email['period'] );
1387
+ }
1388
+ unset( $all_emails[ $gawd_email_remove - 1 ] );
1389
+ update_option( 'gawd_email', $all_emails );
1390
+ }
1391
+ }
1392
+ if ( $gawd_filter_remove ) {
1393
+ $analytics = $gawd_client->analytics_member;
1394
+ $accountId = $gawd_client->get_profile_accountId();
1395
+ try {
1396
+ $analytics->management_filters->delete( $accountId, $gawd_filter_remove );
1397
+ } catch ( apiServiceException $e ) {
1398
+ print 'There was an Analytics API service error '
1399
+ . $e->getCode() . ':' . $e->getMessage();
1400
+ } catch ( apiException $e ) {
1401
+ print 'There was a general API error '
1402
+ . $e->getCode() . ':' . $e->getMessage();
1403
+ } catch ( Exception $e ) {
1404
+ echo '<script>window.location.href="' . admin_url() . 'admin.php?page=gawd_settings&errorMsg=1#gawd_filters_tab";</script>';
1405
+ }
1406
+ }
1407
+ $gawd_pushover_remove = isset( $_POST['gawd_pushover_remove'] ) ? $_POST['gawd_pushover_remove'] : false;
1408
+ if ( $gawd_pushover_remove ) {
1409
+ $all_pushovers = get_option( 'gawd_pushovers' );
1410
+ if ( $all_pushovers ) {
1411
+ foreach ( $all_pushovers as $pushover ) {
1412
+ wp_unschedule_event( wp_next_scheduled( 'gawd_pushover_' . $pushover['period'] ), 'gawd_pushover_' . $pushover['period'] );
1413
+ }
1414
+ unset( $all_pushovers[ $gawd_pushover_remove - 1 ] );
1415
+ update_option( 'gawd_pushovers', $all_pushovers );
1416
+ }
1417
+ }
1418
+ if ( isset( $_POST['settings_submit'] ) ) {
1419
+ check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
1420
+ $gawd_user_data = get_option( 'gawd_user_data' );
1421
+ $gawd_alert_name = isset( $_POST['gawd_alert_name'] ) ? sanitize_text_field( $_POST['gawd_alert_name'] ) : '';
1422
+ $gawd_alert_period = isset( $_POST['gawd_alert_name'] ) ? sanitize_text_field( $_POST['gawd_alert_period'] ) : '';
1423
+ $gawd_alert_metric = isset( $_POST['gawd_alert_metric'] ) ? sanitize_text_field( $_POST['gawd_alert_metric'] ) : '';
1424
+ $gawd_alert_condition = isset( $_POST['gawd_alert_condition'] ) ? sanitize_text_field( $_POST['gawd_alert_condition'] ) : '';
1425
+ $gawd_alert_value = isset( $_POST['gawd_alert_value'] ) ? sanitize_text_field( $_POST['gawd_alert_value'] ) : '';
1426
+ $gawd_alert_emails = isset( $_POST['gawd_alert_emails'] ) ? sanitize_email( $_POST['gawd_alert_emails'] ) : '';
1427
+ $gawd_alert_view = isset( $_POST['gawd_alert_view'] ) ? sanitize_text_field( $_POST['gawd_alert_view'] ) : '';
1428
+ $alert_view_name = isset( $_POST['alert_view_name'] ) ? sanitize_text_field( $_POST['alert_view_name'] ) : '';
1429
+ if ( $gawd_alert_name != '' && $gawd_alert_period != '' && $gawd_alert_metric != '' && $gawd_alert_condition != '' && $gawd_alert_value != '' && $gawd_alert_emails != '' ) {
1430
+ $saved_alerts = get_option( 'gawd_alerts' );
1431
+ if ( $saved_alerts ) {
1432
+ $gawd_alert_options = array(
1433
+ 'name' => $gawd_alert_name,
1434
+ 'period' => $gawd_alert_period,
1435
+ 'metric' => $gawd_alert_metric,
1436
+ 'condition' => $gawd_alert_condition,
1437
+ 'value' => $gawd_alert_value,
1438
+ 'creation_date' => date( 'Y-m-d' ),
1439
+ 'emails' => $gawd_alert_emails,
1440
+ 'alert_view' => $gawd_alert_view,
1441
+ 'alert_view_name' => $alert_view_name
1442
+ );
1443
+ $saved_alerts[] = $gawd_alert_options;
1444
+ update_option( 'gawd_alerts', $saved_alerts );
1445
+ } else {
1446
+ $gawd_alert_options = array(
1447
+ 0 => array(
1448
+ 'name' => $gawd_alert_name,
1449
+ 'period' => $gawd_alert_period,
1450
+ 'metric' => $gawd_alert_metric,
1451
+ 'condition' => $gawd_alert_condition,
1452
+ 'value' => $gawd_alert_value,
1453
+ 'creation_date' => date( 'Y-m-d' ),
1454
+ 'emails' => $gawd_alert_emails,
1455
+ 'alert_view' => $gawd_alert_view,
1456
+ 'alert_view_name' => $alert_view_name
1457
+ )
1458
+ );
1459
+ update_option( 'gawd_alerts', $gawd_alert_options );
1460
+ }
1461
+ $saved_alerts = get_option( 'gawd_alerts' );
1462
+ if ( $saved_alerts ) {
1463
+ foreach ( $saved_alerts as $alert ) {
1464
+ if ( ! wp_next_scheduled( 'gawd_alert_' . $alert['period'] ) ) {
1465
+ wp_schedule_event( time(), $alert['period'], 'gawd_alert_' . $alert['period'] );
1466
+ }
1467
+ }
1468
+ }
1469
+ }
1470
+ $gawd_pushover_name = isset( $_POST['gawd_pushover_name'] ) ? sanitize_text_field( $_POST['gawd_pushover_name'] ) : '';
1471
+ $gawd_pushover_period = isset( $_POST['gawd_pushover_period'] ) ? sanitize_text_field( $_POST['gawd_pushover_period'] ) : '';
1472
+ $gawd_pushover_metric = isset( $_POST['gawd_pushover_metric'] ) ? sanitize_text_field( $_POST['gawd_pushover_metric'] ) : '';
1473
+ $gawd_pushover_condition = isset( $_POST['gawd_pushover_condition'] ) ? sanitize_text_field( $_POST['gawd_pushover_condition'] ) : '';
1474
+ $gawd_pushover_value = isset( $_POST['gawd_pushover_value'] ) ? intval( $_POST['gawd_pushover_value'] ) : '';
1475
+
1476
+ $gawd_pushover_user_keys = isset( $_POST['gawd_pushover_user_keys'] ) ? sanitize_text_field( $_POST['gawd_pushover_user_keys'] ) : '';
1477
+ $gawd_pushover_view = isset( $_POST['gawd_pushover_view'] ) ? sanitize_text_field( $_POST['gawd_pushover_view'] ) : '';
1478
+ $pushover_view_name = isset( $_POST['pushover_view_name'] ) ? sanitize_text_field( $_POST['pushover_view_name'] ) : '';
1479
+ if ( $gawd_pushover_name != '' && $gawd_pushover_period != '' && $gawd_pushover_metric != '' && $gawd_pushover_condition != '' && $gawd_pushover_value !== '' && $gawd_pushover_user_keys != '' ) {
1480
+ $saved_pushovers = get_option( 'gawd_pushovers' );
1481
+ if ( $saved_pushovers ) {
1482
+ $gawd_pushover_options = array(
1483
+ 'name' => $gawd_pushover_name,
1484
+ 'period' => $gawd_pushover_period,
1485
+ 'metric' => $gawd_pushover_metric,
1486
+ 'condition' => $gawd_pushover_condition,
1487
+ 'value' => $gawd_pushover_value,
1488
+ 'creation_date' => date( 'Y-m-d' ),
1489
+ 'user_key' => $gawd_pushover_user_keys,
1490
+ 'pushover_view' => $gawd_pushover_view,
1491
+ 'pushover_view_name' => $pushover_view_name
1492
+ );
1493
+ $saved_pushovers[] = $gawd_pushover_options;
1494
+ update_option( 'gawd_pushovers', $saved_pushovers );
1495
+ } else {
1496
+ $gawd_pushover_options = array(
1497
+ 0 => array(
1498
+ 'name' => $gawd_pushover_name,
1499
+ 'period' => $gawd_pushover_period,
1500
+ 'metric' => $gawd_pushover_metric,
1501
+ 'condition' => $gawd_pushover_condition,
1502
+ 'value' => $gawd_pushover_value,
1503
+ 'creation_date' => date( 'Y-m-d' ),
1504
+ 'user_key' => $gawd_pushover_user_keys,
1505
+ 'pushover_view' => $gawd_pushover_view,
1506
+ 'pushover_view_name' => $pushover_view_name
1507
+ )
1508
+ );
1509
+ update_option( 'gawd_pushovers', $gawd_pushover_options );
1510
+ }
1511
+ $saved_pushovers = get_option( 'gawd_pushovers' );
1512
+ if ( $saved_pushovers ) {
1513
+
1514
+ foreach ( $saved_pushovers as $pushover ) {
1515
+ $this->gawd_pushover_api( $pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value'] );
1516
+ if ( ! wp_next_scheduled( 'gawd_pushover_' . $pushover['period'] ) ) {
1517
+ wp_schedule_event( time(), $pushover['period'], 'gawd_pushover_' . $pushover['period'] );
1518
+ }
1519
+ }
1520
+ }
1521
+ }
1522
+ $gawd_show_in_dashboard = isset( $_POST['gawd_show_in_dashboard'] ) ? sanitize_text_field( $_POST['gawd_show_in_dashboard'] ) : '';
1523
+
1524
+ $gawd_permissions = isset( $_POST['gawd_permissions'] ) ? $_POST['gawd_permissions'] : array();
1525
+ $gawd_own_project = isset( $_POST['gawd_own_project'] ) ? sanitize_text_field( $_POST['gawd_own_project'] ) : '';
1526
+ $site_speed_rate = isset( $_POST['site_speed_rate'] ) ? intval( $_POST['site_speed_rate'] ) : '1';
1527
+ $post_page_chart = isset( $_POST['post_page_chart'] ) ? sanitize_text_field( $_POST['post_page_chart'] ) : '';
1528
+ $enable_cross_domain = isset( $_POST['enable_cross_domain'] ) ? sanitize_text_field( $_POST['enable_cross_domain'] ) : '';
1529
+ $cross_domains = isset( $_POST['cross_domains'] ) ? sanitize_text_field( $_POST['cross_domains'] ) : '';
1530
+ $default_date = isset( $_POST['default_date'] ) ? $_POST['default_date'] : 'last_7_days';
1531
+ $default_date_format = isset( $_POST['default_date_format'] ) ? $_POST['default_date_format'] : 'ymd_with_week';
1532
+ $enable_hover_tooltip = isset( $_POST['enable_hover_tooltip'] ) ? $_POST['enable_hover_tooltip'] : '';
1533
+ $gawd_backend_roles = isset( $_POST['gawd_backend_roles'] ) ? ( $_POST['gawd_backend_roles'] ) : array();
1534
+ $gawd_frontend_roles = isset( $_POST['gawd_frontend_roles'] ) ? ( $_POST['gawd_frontend_roles'] ) : array();
1535
+ $gawd_post_page_roles = isset( $_POST['gawd_post_page_roles'] ) ? ( $_POST['gawd_post_page_roles'] ) : array();
1536
+ $exclude_events = isset( $_POST['exclude_events'] ) ? sanitize_text_field( $_POST['exclude_events'] ) : array();
1537
+ $gawd_settings_exist = get_option( 'gawd_settings' );
1538
+ $gawd_settings_exist['gawd_show_in_dashboard'] = $gawd_show_in_dashboard;
1539
+ $gawd_settings_exist['site_speed_rate'] = $site_speed_rate;
1540
+ $gawd_settings_exist['post_page_chart'] = $post_page_chart;
1541
+ $gawd_settings_exist['enable_cross_domain'] = $enable_cross_domain;
1542
+ $gawd_settings_exist['cross_domains'] = $cross_domains;
1543
+ $gawd_settings_exist['gawd_backend_roles'] = $gawd_backend_roles;
1544
+ $gawd_settings_exist['gawd_frontend_roles'] = $gawd_frontend_roles;
1545
+ $gawd_settings_exist['gawd_post_page_roles'] = $gawd_post_page_roles;
1546
+ $gawd_settings_exist['default_date'] = $default_date;
1547
+ $gawd_settings_exist['default_date_format'] = $default_date_format;
1548
+ $gawd_settings_exist['enable_hover_tooltip'] = $enable_hover_tooltip;
1549
+ $gawd_settings_exist['exclude_events'] = $exclude_events;
1550
+ $gawd_settings_exist['gawd_permissions'] = $gawd_permissions;
1551
+ update_option( 'gawd_settings', $gawd_settings_exist );
1552
+ $gawd_filter_name = isset( $_POST['gawd_filter_name'] ) ? sanitize_text_field( $_POST['gawd_filter_name'] ) : '';
1553
+ $gawd_filter_type = isset( $_POST['gawd_filter_type'] ) ? sanitize_text_field( $_POST['gawd_filter_type'] ) : '';
1554
+ $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'] ) : '';
1555
+ if ( $gawd_filter_name != '' && $gawd_filter_type != '' && $gawd_filter_value != '' ) {
1556
+ $gawd_client->add_filter( $gawd_filter_name, $gawd_filter_type, $gawd_filter_value );
1557
+ }
1558
+ add_option( "gawd_save_settings", 1 );
1559
+ }
1560
+ if ( get_option( 'gawd_save_settings' ) == 1 ) {
1561
+ $this->gawd_admin_notice( 'Your changes have been saved successfully.', 'success is-dismissible' );
1562
+ }
1563
+ delete_option( 'gawd_save_settings' );
1564
+ require_once( 'admin/pages/settings.php' );
1565
+ }
1566
+ }
1567
+
1568
+ public function reset_user_data() {
1569
+ delete_option( "gawd_credentials" );
1570
+ $credentials['project_id'] = '115052745574-5vbr7tci4hjkr9clkflmnpto5jisgstg.apps.googleusercontent.com';
1571
+ $credentials['project_secret'] = 'wtNiu3c_bA_g7res6chV0Trt';
1572
+ update_option( 'gawd_credentials', $credentials );
1573
+ delete_option( 'gawd_own_project' );
1574
+ delete_option( 'gawd_user_data' );
1575
+
1576
+ }
1577
+
1578
+ public function gawd_display_tracking_page() {
1579
+ global $gawd_client, $gawd_user_data;
1580
+ $gawd_client = GAWD_google_client::get_instance();
1581
+ $gawd_user_data = get_option( 'gawd_user_data' );
1582
+ $add_dimension_value = isset( $_POST['add_dimension_value'] ) ? $_POST['add_dimension_value'] : '';
1583
+ if ( isset( $_GET['errorMsg'] ) ) {
1584
+ self::error_message( 'error', 'User does not have sufficient permissions for this account' );
1585
+ }
1586
+ if ( isset( $_POST['add_property'] ) ) {
1587
+ $gawd_account_select = isset( $_POST['gawd_account_select'] ) ? $_POST['gawd_account_select'] : '';
1588
+ $gawd_property_name = isset( $_POST['gawd_property_name'] ) ? $_POST['gawd_property_name'] : '';
1589
+ if ( $gawd_account_select && $gawd_property_name ) {
1590
+ $err_msg = $gawd_client->add_webproperty( $gawd_account_select, $gawd_property_name );
1591
+ $redirect_url = admin_url() . 'admin.php?page=gawd_tracking&enableTracking=1';
1592
+ if ( $err_msg ) {
1593
+ $redirect_url .= '&errorMsg=1';
1594
+ }
1595
+ echo '<script>window.location.href="' . $redirect_url . '";</script>';
1596
+ }
1597
+ }
1598
+ if ( isset( $_POST['lock_property'] ) ) {
1599
+ $property = $gawd_client->property_exists();
1600
+ $gawd_property_select = $_POST['gawd_property_select'];
1601
+ foreach ( $property as $property_select ) {
1602
+ if ( $property_select['id'] == $gawd_property_select ) {
1603
+ $property = $property_select;
1604
+ break;
1605
+ }
1606
+ }
1607
+ $gawd_user_data['webPropertyId'] = $property['id'];
1608
+ $gawd_user_data['default_webPropertyId'] = $property['id'];
1609
+ $gawd_user_data['accountId'] = $property['accountId'];
1610
+ $gawd_user_data['default_accountId'] = $property['accountId'];
1611
+ $gawd_user_data['gawd_id'] = $property['defaultProfileId'];
1612
+ update_option( 'gawd_user_data', $gawd_user_data );
1613
+ }
1614
+ if ( $this->manage_ua_code_selection_tracking() != 'done' ) {
1615
+ $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1616
 
1617
+ //echo '<script>window.location.href="'.$redirect_url.'";</script>';
1618
+ return;
1619
+ }
1620
+
1621
+ if ( $add_dimension_value == 'add_dimension_Logged_in' ) {
1622
+ $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
1623
+ $gawd_client->add_custom_dimension( 'Logged in', $id );
1624
+ $settings = get_option( 'gawd_settings' );
1625
+ $optname = 'gawd_custom_dimension_Logged_in';
1626
+ $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
1627
+ update_option( 'gawd_settings', $settings );
1628
+
1629
+ }
1630
+ if ( $add_dimension_value == 'add_dimension_Post_type' ) {
1631
+ $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
1632
+ $gawd_client->add_custom_dimension( 'Post type', $id );
1633
+ $settings = get_option( 'gawd_settings' );
1634
+ $optname = 'gawd_custom_dimension_Post_type';
1635
+ $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
1636
+ update_option( 'gawd_settings', $settings );
1637
+
1638
+ }
1639
+ if ( $add_dimension_value == 'add_dimension_Author' ) {
1640
+ $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
1641
+ $gawd_client->add_custom_dimension( 'Author', $id );
1642
+ $settings = get_option( 'gawd_settings' );
1643
+ $optname = 'gawd_custom_dimension_Author';
1644
+ $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
1645
+ update_option( 'gawd_settings', $settings );
1646
+
1647
+ }
1648
+ if ( $add_dimension_value == 'add_dimension_Category' ) {
1649
+ $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
1650
+ $gawd_client->add_custom_dimension( 'Category', $id );
1651
+ $settings = get_option( 'gawd_settings' );
1652
+ $optname = 'gawd_custom_dimension_Category';
1653
+
1654
+ $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
1655
+ update_option( 'gawd_settings', $settings );
1656
+ }
1657
+ if ( $add_dimension_value == 'add_dimension_Published_Month' ) {
1658
+ $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
1659
+ $gawd_client->add_custom_dimension( 'Published Month', $id );
1660
+ $settings = get_option( 'gawd_settings' );
1661
+ $optname = 'gawd_custom_dimension_Published_Month';
1662
+ $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
1663
+ update_option( 'gawd_settings', $settings );
1664
+
1665
+ }
1666
+ if ( $add_dimension_value == 'add_dimension_Published_Year' ) {
1667
+ $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
1668
+ $gawd_client->add_custom_dimension( 'Published Year', $id );
1669
+ $settings = get_option( 'gawd_settings' );
1670
+ $optname = 'gawd_custom_dimension_Published_Year';
1671
+ $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
1672
+ update_option( 'gawd_settings', $settings );
1673
+
1674
+ }
1675
+ if ( $add_dimension_value == 'add_dimension_Tags' ) {
1676
+ $id = isset( $_POST['gawd_custom_dimension_id'] ) ? ( $_POST['gawd_custom_dimension_id'] + 1 ) : 1;
1677
+ $gawd_client->add_custom_dimension( 'Tags', $id );
1678
+ $settings = get_option( 'gawd_settings' );
1679
+ $optname = 'gawd_custom_dimension_Tags';
1680
+ $settings[ $optname ] = isset( $_POST['gawd_tracking_enable'] ) ? $_POST['gawd_tracking_enable'] : '';
1681
+ update_option( 'gawd_settings', $settings );
1682
+ }
1683
+ if ( isset( $_POST['settings_submit'] ) ) {
1684
+ check_admin_referer( 'gawd_save_form', 'gawd_save_form_fild' );
1685
+ $gawd_user_data = get_option( 'gawd_user_data' );
1686
+ $gawd_file_formats = isset( $_POST['gawd_file_formats'] ) ? sanitize_text_field( $_POST['gawd_file_formats'] ) : '';
1687
+ $gawd_anonymize = isset( $_POST['gawd_anonymize'] ) ? sanitize_text_field( $_POST['gawd_anonymize'] ) : '';
1688
+ $gawd_tracking_enable = isset( $_POST['gawd_tracking_enable'] ) ? sanitize_text_field( $_POST['gawd_tracking_enable'] ) : '';
1689
+ $gawd_outbound = isset( $_POST['gawd_outbound'] ) ? sanitize_text_field( $_POST['gawd_outbound'] ) : '';
1690
+ $gawd_enhanced = isset( $_POST['gawd_enhanced'] ) ? sanitize_text_field( $_POST['gawd_enhanced'] ) : '';
1691
+ if ( $add_dimension_value == '' ) {
1692
+ $gawd_cd_Logged_in = isset( $_POST['gawd_custom_dimension_Logged_in'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Logged_in'] ) : '';
1693
+ $gawd_cd_Post_type = isset( $_POST['gawd_custom_dimension_Post_type'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Post_type'] ) : '';
1694
+ $gawd_cd_Author = isset( $_POST['gawd_custom_dimension_Author'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Author'] ) : '';
1695
+ $gawd_cd_Category = isset( $_POST['gawd_custom_dimension_Category'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Category'] ) : '';
1696
+ $gawd_cd_Published_Month = isset( $_POST['gawd_custom_dimension_Published_Month'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Published_Month'] ) : '';
1697
+ $gawd_cd_Published_Year = isset( $_POST['gawd_custom_dimension_Published_Year'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Published_Year'] ) : '';
1698
+ $gawd_cd_Tags = isset( $_POST['gawd_custom_dimension_Tags'] ) ? sanitize_text_field( $_POST['gawd_custom_dimension_Tags'] ) : '';
1699
+ $gawd_settings['gawd_custom_dimension_Logged_in'] = $gawd_cd_Logged_in;
1700
+ $gawd_settings['gawd_custom_dimension_Post_type'] = $gawd_cd_Post_type;
1701
+ $gawd_settings['gawd_custom_dimension_Author'] = $gawd_cd_Author;
1702
+ $gawd_settings['gawd_custom_dimension_Category'] = $gawd_cd_Category;
1703
+ $gawd_settings['gawd_custom_dimension_Published_Month'] = $gawd_cd_Published_Month;
1704
+ $gawd_settings['gawd_custom_dimension_Published_Year'] = $gawd_cd_Published_Year;
1705
+ $gawd_settings['gawd_custom_dimension_Tags'] = $gawd_cd_Tags;
1706
+ }
1707
+ $gawd_excluded_roles = isset( $_POST['gawd_excluded_roles'] ) ? $_POST['gawd_excluded_roles'] : array();
1708
+ $gawd_excluded_users = isset( $_POST['gawd_excluded_users'] ) ? $_POST['gawd_excluded_users'] : array();
1709
+ $gawd_settings = get_option( 'gawd_settings' );
1710
+ $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
1711
+ $gawd_settings['gawd_anonymize'] = $gawd_anonymize;
1712
+ $gawd_settings['gawd_file_formats'] = $gawd_file_formats;
1713
+ $gawd_settings['gawd_tracking_enable'] = $gawd_tracking_enable;
1714
+ $gawd_settings['gawd_outbound'] = $gawd_outbound;
1715
+ $gawd_settings['gawd_enhanced'] = $gawd_enhanced;
1716
+ $gawd_settings['gawd_excluded_roles'] = $gawd_excluded_roles;
1717
+ $gawd_settings['gawd_excluded_users'] = $gawd_excluded_users;
1718
+ update_option( 'gawd_settings', $gawd_settings );
1719
+ add_option( "gawd_save_tracking", 1 );
1720
+ }
1721
+ if ( get_option( 'gawd_save_tracking' ) == 1 ) {
1722
+ $this->gawd_admin_notice( 'Your changes have been saved successfully.', 'success is-dismissible' );
1723
+ }
1724
+ delete_option( 'gawd_save_tracking' );
1725
+ $gawd_settings = get_option( 'gawd_settings' );
1726
+ if ( $add_dimension_value != '' ) {
1727
+ $redirect_url = admin_url() . 'admin.php?page=gawd_tracking';
1728
+ echo '<script>window.location.href="' . $redirect_url . '";</script>';
1729
+ }
1730
+ require_once( 'admin/pages/tracking.php' );
1731
+ }
1732
+
1733
+ public function gawd_my_schedule() {
1734
+ $schedules['gawd_weekly'] = array(
1735
+ 'interval' => 604800,
1736
+ 'display' => __( 'Every week' )
1737
+ );
1738
+ $schedules['gawd_monthly'] = array(
1739
+ 'interval' => 18748800,
1740
+ 'display' => __( 'Every month' )
1741
+ );
1742
+
1743
+ return $schedules;
1744
+ }
1745
+
1746
+ public function gawd_pushover_api( $user_key, $metric, $condition, $value ) {
1747
+ $ch = curl_init();
1748
+ curl_setopt( $ch, CURLOPT_URL, "https://api.pushover.net/1/messages.json" );
1749
+ curl_setopt( $ch, CURLOPT_POSTFIELDS, array(
1750
+ "token" => "aJBDhTfhR87EaTzs7wpx1MMKwboBjB",
1751
+ "user" => $user_key,
1752
+ "message" => 'The ' . $metric . ' less ' . $value
1753
+ ) );
1754
+ // curl_setopt($ch, CURLOPT_SAFE_UPLOAD, true);
1755
+ curl_exec( $ch );
1756
+ curl_close( $ch );
1757
+ }
1758
+
1759
+ public function gawd_pushover_daily() {
1760
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1761
+ $gawd_client = GAWD_google_client::get_instance();
1762
+ $pushovers = get_option( 'gawd_pushovers' );
1763
+ $data = '';
1764
+ $condition = '';
1765
+
1766
+ foreach ( $pushovers as $pushover ) {
1767
+ if ( isset( $pushover['period'] ) && $pushover['period'] == 'daily' ) {
1768
+ //pls send email if ....
1769
+ $date = date( 'Y-m-d', strtotime( 'yesterday' ) );
1770
+ $data = $gawd_client->get_data_alert( 'ga:' . $pushover['metric'], 'date', $date, $date, $pushover['pushover_view'] );
1771
+ $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
1772
+ if ( ! eval( $data . $pushover_condition . $pushover['value'] . ';' ) ) {
1773
+ $cond = ' ' . $pushover['condition'] . ' than';
1774
+ $this->gawd_pushover_api( $pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value'] );
1775
+ }
1776
+ }
1777
+ }
1778
+ }
1779
+
1780
+ public function gawd_pushover_weekly() {
1781
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1782
+ $gawd_client = GAWD_google_client::get_instance();
1783
+ $pushovers = get_option( 'gawd_pushovers' );
1784
+ $data = '';
1785
+ $condition = '';
1786
+ foreach ( $pushovers as $pushover ) {
1787
+ if ( isset( $pushover['period'] ) && $pushover['period'] == 'gawd_weekly' ) {
1788
+ //pls send email if ....
1789
+ $start_date = date( 'Y-m-d', strtotime( 'last week -1 day' ) );
1790
+ $end_date = date( 'l' ) != 'Sunday' ? date( 'Y-m-d', strtotime( 'last sunday -1 day' ) ) : date( 'Y-m-d', strtotime( '-1 day' ) );
1791
+ $data = $gawd_client->get_data_alert( 'ga:' . $pushover['metric'], 'date', $start_date, $end_date, $pushover['pushover_view'] );
1792
+ $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
1793
+ if ( ! eval( $data . $pushover_condition . $pushover['value'] . ';' ) ) {
1794
+ $cond = ' ' . $pushover['condition'] . ' than';
1795
+ $this->gawd_pushover_api( $pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value'] );
1796
+ }
1797
+ }
1798
+ }
1799
+ }
1800
+
1801
+ public function gawd_pushover_monthly() {
1802
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1803
+ $gawd_client = GAWD_google_client::get_instance();
1804
+ $pushovers = get_option( 'gawd_pushovers' );
1805
+ $data = '';
1806
+ $condition = '';
1807
+ foreach ( $pushovers as $pushover ) {
1808
+ if ( isset( $pushover['period'] ) && $pushover['period'] == 'gawd_monthly' ) {
1809
+ //pls send email if ....
1810
+ $end_date = date( 'Y-m-t', strtotime( 'last month' ) );
1811
+ $start_date = date( 'Y-m-01', strtotime( 'last month' ) );
1812
+ $data = $gawd_client->get_data_alert( 'ga:' . $pushover['metric'], 'date', $start_date, $end_date, $pushover['pushover_view'] );
1813
+ $pushover_condition = $pushover['condition'] == 'greater' ? '>' : '<';
1814
+ if ( ! eval( $data . $pushover_condition . $pushover['value'] . ';' ) ) {
1815
+ $cond = ' ' . $pushover['condition'] . ' than';
1816
+ $this->gawd_pushover_api( $pushover['user_key'], $pushover['metric'], $pushover['condition'], $pushover['value'] );
1817
+ }
1818
+ }
1819
+ }
1820
+ }
1821
+
1822
+ public function gawd_alert_daily() {
1823
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1824
+ $gawd_client = GAWD_google_client::get_instance();
1825
+ $alerts = get_option( 'gawd_alerts' );
1826
+ $data = '';
1827
+ $condition = '';
1828
+ $email_from = get_option( 'admin_email' );
1829
+ foreach ( $alerts as $alert ) {
1830
+ if ( isset( $alert['period'] ) && $alert['period'] == 'daily' ) {
1831
+ //pls send email if ....
1832
+ $date = date( 'Y-m-d', strtotime( 'yesterday' ) );
1833
+ $data = $gawd_client->get_data_alert( 'ga:' . $alert['metric'], 'date', $date, $date, $alert['alert_view'] );
1834
+ $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
1835
+ $color_condition = $alert['condition'] == 'greater' ? 'rgb(157, 207, 172)' : 'rgb(251, 133, 131)';
1836
+ if ( ! eval( $data . $alert_condition . $alert['value'] . ';' ) ) {
1837
+ $cond = ' ' . $alert['condition'] . ' than';
1838
+ $headers = array();
1839
+ $headers[] = 'From: <' . $email_from . '>';
1840
+ $headers[] = 'Content-Type: text/html';
1841
+ $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>';
1842
+ wp_mail( $alert['emails'], 'Analytics Alert', $content, $headers );
1843
+ }
1844
+ }
1845
+ }
1846
+ }
1847
+
1848
+ public function gawd_alert_weekly() {
1849
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1850
+ $gawd_client = GAWD_google_client::get_instance();
1851
+ $alerts = get_option( 'gawd_alerts' );
1852
+ $data = '';
1853
+ $condition = '';
1854
+ $email_from = get_option( 'admin_email' );
1855
+ foreach ( $alerts as $alert ) {
1856
+ if ( isset( $alert['period'] ) && $alert['period'] == 'gawd_weekly' ) {
1857
+ //pls send email if ....
1858
+ $start_date = date( 'Y-m-d', strtotime( 'last week -1 day' ) );
1859
+ $end_date = date( 'l' ) != 'Sunday' ? date( 'Y-m-d', strtotime( 'last sunday -1 day' ) ) : date( 'Y-m-d', strtotime( '-1 day' ) );
1860
+ $data = $gawd_client->get_data_alert( 'ga:' . $alert['metric'], 'date', $start_date, $end_date, $alert['alert_view'] );
1861
+ $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
1862
+ if ( ! eval( $data . $alert_condition . $alert['value'] . ';' ) ) {
1863
+ $cond = ' ' . $alert['condition'] . ' than';
1864
+ $headers = array();
1865
+ $headers[] = 'From: <' . $email_from . '>';
1866
+ $headers[] = 'Content-Type: text/html';
1867
+ $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>';
1868
+ wp_mail( $alert['emails'], 'Analytics Alert', $content, $headers );
1869
+ }
1870
+ }
1871
+ }
1872
+ }
1873
+
1874
+ public function gawd_alert_monthly() {
1875
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1876
+ $gawd_client = GAWD_google_client::get_instance();
1877
+ $alerts = get_option( 'gawd_alerts' );
1878
+ $data = '';
1879
+ $email_from = get_option( 'admin_email' );
1880
+ foreach ( $alerts as $alert ) {
1881
+ if ( isset( $alert['period'] ) && $alert['period'] == 'gawd_monthly' ) {
1882
+ //pls send email if ....
1883
+ $end_date = date( 'Y-m-t', strtotime( 'last month' ) );
1884
+ $start_date = date( 'Y-m-01', strtotime( 'last month' ) );
1885
+ $data = $gawd_client->get_data_alert( 'ga:' . $alert['metric'], 'date', $start_date, $end_date, $alert['alert_view'] );
1886
+ $alert_condition = $alert['condition'] == 'greater' ? '>' : '<';
1887
+ if ( ! eval( $data . $alert_condition . $alert['value'] . ';' ) ) {
1888
+ $cond = ' ' . $alert['condition'] . ' than';
1889
+ $headers = array();
1890
+ $headers[] = 'From: <' . $email_from . '>';
1891
+ $headers[] = 'Content-Type: text/html';
1892
+ $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>';
1893
+ wp_mail( $alert['emails'], 'Analytics Alert', $content, $headers );
1894
+ }
1895
+ }
1896
+ }
1897
+ }
1898
+
1899
+ public function wd_dashboard_widget() {
1900
+ global $gawd_client, $gawd_user_data;
1901
+ $gawd_client = GAWD_google_client::get_instance();
1902
+ $profiles = $gawd_client->get_profiles();
1903
+ $gawd_user_data = get_option( 'gawd_user_data' );
1904
+ if ( isset( $_POST['gawd_id'] ) ) {
1905
+ $gawd_user_data['gawd_id'] = isset( $_POST['gawd_id'] ) ? $_POST['gawd_id'] : '';
1906
+ foreach ( $gawd_user_data['gawd_profiles'] as $web_property_name => $web_property ) {
1907
+ foreach ( $web_property as $profile ) {
1908
+ if ( $profile['id'] == $gawd_user_data['gawd_id'] ) {
1909
+ $gawd_user_data['web_property_name'] = $web_property_name;
1910
+ $gawd_user_data['webPropertyId'] = $profile['webPropertyId'];
1911
+ $gawd_user_data['accountId'] = $profile['accountId'];
1912
+ }
1913
+ }
1914
+ }
1915
+ $gawd_user_data['web_property_name'] = isset( $_POST['web_property_name'] ) ? $_POST['web_property_name'] : '';
1916
+ update_option( 'gawd_user_data', $gawd_user_data );
1917
+ }
1918
+ require_once( 'admin/pages/dashboard_widget.php' );
1919
+ }
1920
+
1921
+ public function google_analytics_wd_dashboard_widget() {
1922
+ $gawd_settings = get_option( 'gawd_settings' );
1923
+ $gawd_backend_roles = isset( $gawd_settings['gawd_backend_roles'] ) ? $gawd_settings['gawd_backend_roles'] : array();
1924
+ $roles = $this->get_current_user_role();
1925
+
1926
+ if ( isset( $gawd_settings['gawd_show_in_dashboard'] ) && $gawd_settings['gawd_show_in_dashboard'] == 'on' ) {
1927
+ if ( in_array( $roles, $gawd_backend_roles ) || current_user_can( 'manage_options' ) ) {
1928
+ wp_add_dashboard_widget( 'wd_dashboard_widget', 'WD Google Analytics', array(
1929
+ $this,
1930
+ 'wd_dashboard_widget'
1931
+ ) );
1932
+ }
1933
+ }
1934
+ }
1935
+
1936
+ public function show_data( $params = array() ) {
1937
+ /* if (isset($_REQUEST['security'])) {
1938
  check_ajax_referer('gawd_admin_page_nonce', 'security');
1939
  } else {
1940
  check_admin_referer('gawd_save_form', 'gawd_save_form_fild');
1941
  } */
1942
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
1943
+ $return = true;
1944
+ if ( $params == '' ) {
1945
+ $params = $_POST;
1946
+ $return = false;
1947
+ }
1948
+ $gawd_client = GAWD_google_client::get_instance();
1949
+ $start_date = isset( $params["start_date"] ) && $params["start_date"] != '' ? $params["start_date"] : date( 'Y-m-d', strtotime( '-7 days' ) );
1950
+ $end_date = isset( $params["end_date"] ) && $params["end_date"] != '' ? $params["end_date"] : date( 'Y-m-d' );
1951
+ $metric = isset( $params["metric"] ) ? $params["metric"] : 'ga:sessions';
1952
+ $metric = is_array( $metric ) ? count( $metric ) > 1 ? implode( ",", $metric ) : $metric[0] : $metric;
1953
+ $dimension = isset( $params["dimension"] ) ? $params["dimension"] : 'date';
1954
+
1955
+ $country_filter = isset( $params["country_filter"] ) ? $params["country_filter"] : '';
1956
+ $geo_type = isset( $params["geo_type"] ) ? $params["geo_type"] : '';
1957
+ $filter_type = isset( $params["filter_type"] ) && $params["filter_type"] != '' ? $params["filter_type"] : '';
1958
+ $custom = isset( $params["custom"] ) && $params["custom"] != '' ? $params["custom"] : '';
1959
+ $same_dimension = $dimension;
1960
+
1961
+ $dimension = $filter_type != '' && $dimension == 'date' ? $filter_type : $dimension;
1962
+ if ( $dimension == 'week' || $dimension == 'month' ) {
1963
+ $same_dimension = $dimension;
1964
+ }
1965
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1966
 
1967
+ $timezone = isset( $params["timezone"] ) && $params["timezone"] != '' ? $params["timezone"] : 0;
1968
+ if ( $dimension == 'pagePath' || $dimension == 'PagePath' || $dimension == 'landingPagePath' || $dimension == 'LandingPagePath' ) {
1969
+ if ( get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date ) ) {
1970
+ $grid_data = get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date );
1971
+ } else {
1972
+ $grid_data = $gawd_client->get_page_data( $dimension, $start_date, $end_date, $timezone );
1973
+ }
1974
+ if ( $return ) {
1975
+ return $grid_data;
1976
+ }
1977
+ echo $grid_data;
1978
+ die();
1979
+ } elseif ( $dimension == 'goals' ) {
1980
+ if ( get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date ) ) {
1981
+ $goal_data = get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date );
1982
+ } else {
1983
+ $goal_data = $gawd_client->get_goal_data( 'date', $start_date, $end_date, $timezone, $same_dimension );
1984
+ }
1985
+ if ( $return ) {
1986
+ return $goal_data;
1987
+ }
1988
+ echo $goal_data;
1989
+ die();
1990
+ } elseif ( ( $dimension == 'region' || $dimension == 'city' ) || ( $dimension == 'Region' || $dimension == 'City' ) ) {
1991
+ if ( get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $country_filter . '-' . $start_date . '-' . $end_date ) ) {
1992
+ $chart_data = get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $country_filter . '-' . $start_date . '-' . $end_date );
1993
+ } else {
1994
+
1995
+ $chart_data = $gawd_client->get_country_data( $metric, $dimension, $start_date, $end_date, $country_filter, $geo_type, $timezone );
1996
+ }
1997
+ if ( $return ) {
1998
+ return $chart_data;
1999
+ }
2000
+ echo $chart_data;
2001
+ die();
2002
+ } else {
2003
+ if ( $custom != '' ) {
2004
+ $chart_data = $gawd_client->get_data( $metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension );
2005
+ } else {
2006
+ if ( $dimension == 'siteSpeed' ) {
2007
+ if ( get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $same_dimension . '_' . $filter_type . '-' . $start_date . '-' . $end_date ) ) {
2008
+ $chart_data = get_transient( 'gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date );
2009
+ } else {
2010
+ $chart_data = $gawd_client->get_data( $metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension );
2011
+ }
2012
+ if ( $return ) {
2013
+ return $chart_data;
2014
+ }
2015
+ } else {
2016
+
2017
+ /* if (get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date)) {
2018
  $chart_data = get_transient('gawd-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date);
2019
  } */
2020
+ //else {
2021
+
2022
+ $chart_data = $gawd_client->get_data( $metric, $dimension, $start_date, $end_date, $filter_type, $timezone, $same_dimension );
2023
+ //}
2024
+ if ( $return ) {
2025
+ return $chart_data;
2026
+ }
2027
+ }
2028
+ }
2029
+ echo $chart_data;
2030
+ die();
2031
+ }
2032
+ }
2033
 
2034
+ public function show_data_compact() {
2035
+ check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
2036
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
2037
+ $gawd_client = GAWD_google_client::get_instance();
2038
+ $start_date = isset( $_POST["start_date"] ) && $_POST["start_date"] != '' ? $_POST["start_date"] : date( 'Y-m-d', strtotime( '-30 days' ) );
2039
+ $end_date = isset( $_POST["end_date"] ) && $_POST["end_date"] != '' ? $_POST["end_date"] : date( 'Y-m-d' );
2040
+ $metric = isset( $_POST["metric"] ) ? $_POST["metric"] : 'sessions';
2041
+ $metric = is_array( $metric ) ? count( $metric ) > 1 ? implode( ",", $metric ) : $metric[0] : 'ga:' . $metric;
2042
+ $dimension = isset( $_POST["dimension"] ) ? $_POST["dimension"] : 'date';
2043
+ $timezone = isset( $_POST["timezone"] ) ? $_POST["timezone"] : 0;
2044
+ if ( get_transient( 'gawd-compact-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date ) ) {
2045
+ $chart_data = get_transient( 'gawd-compact-' . $gawd_client->get_profile_id() . '-' . $dimension . '-' . $start_date . '-' . $end_date );
2046
+ } else {
2047
+ $chart_data = $gawd_client->get_data_compact( $metric, $dimension, $start_date, $end_date, $timezone );
2048
+ }
2049
+ echo $chart_data;
2050
+ die();
2051
+ }
2052
+
2053
+ public function show_page_post_data() {
2054
+ check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
2055
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
2056
+ $gawd_client = GAWD_google_client::get_instance();
2057
+ $start_date = isset( $_POST["start_date"] ) && $_POST["start_date"] != '' ? $_POST["start_date"] : date( 'Y-m-d', strtotime( '-30 days' ) );
2058
+ $end_date = isset( $_POST["end_date"] ) && $_POST["end_date"] != '' ? $_POST["end_date"] : date( 'Y-m-d' );
2059
+ $metric = isset( $_POST["metric"] ) ? $_POST["metric"] : 'ga:sessions';
2060
+ $metric = is_array( $metric ) ? count( $metric ) > 1 ? implode( ",", $metric ) : $metric[0] : $metric;
2061
+ $dimension = isset( $_POST["dimension"] ) ? $_POST["dimension"] : 'date';
2062
+ $timezone = isset( $_POST["timezone"] ) ? $_POST["timezone"] : 0;
2063
+ $filter = isset( $_POST["filter"] ) ? substr( $_POST["filter"], 1 ) : '';
2064
+ $chart = isset( $_POST["chart"] ) ? $_POST["chart"] : '';
2065
+ $chart_data = get_transient( 'gawd-page-post-' . $gawd_client->get_profile_id() . '-' . $filter . '-' . '-' . $dimension . '-' . $start_date . '-' . $end_date . '-' . $chart );
2066
+ if ( ! $chart_data ) {
2067
+ $chart_data = $gawd_client->get_post_page_data( $metric, $dimension, $start_date, $end_date, $filter, $timezone, $chart );
2068
+ }
2069
+ echo $chart_data;
2070
+ die();
2071
+ }
2072
+
2073
+ public function get_realtime() {
2074
+ check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
2075
+ require_once( GAWD_DIR . '/admin/gawd_google_class.php' );
2076
+ $gawd_client = GAWD_google_client::get_instance();
2077
+ $chart_data = get_transient( 'gawd-real' . $gawd_client->get_profile_id() );
2078
+ if ( ! $chart_data ) {
2079
+ $chart_data = $gawd_client->gawd_realtime_data();
2080
+ }
2081
+
2082
+ return $chart_data;
2083
+ }
2084
+
2085
+ /**
2086
+ * Checks if the protocol is secure.
2087
+ *
2088
+ * @return boolean
2089
+ */
2090
+ public static function is_ssl() {
2091
+ if ( isset( $_SERVER['HTTPS'] ) ) {
2092
+ if ( 'on' == strtolower( $_SERVER['HTTPS'] ) ) {
2093
+ return true;
2094
+ }
2095
+ if ( '1' == $_SERVER['HTTPS'] ) {
2096
+ return true;
2097
+ }
2098
+ } elseif ( isset( $_SERVER['SERVER_PORT'] ) && ( '443' == $_SERVER['SERVER_PORT'] ) ) {
2099
+ return true;
2100
+ }
2101
+
2102
+ return false;
2103
+ }
2104
+
2105
+ /**
2106
+ * Returns the Singleton instance of this class.
2107
+ *
2108
+ * @return GAWD The Singleton instance.
2109
+ */
2110
+ public static function get_instance() {
2111
+ if ( null === static::$instance ) {
2112
+ static::$instance = new static();
2113
+ }
2114
+
2115
+ return static::$instance;
2116
+ }
2117
+
2118
+ /**
2119
+ * Private clone method to prevent cloning of the instance of the
2120
+ * Singleton instance.
2121
+ *
2122
+ * @return void
2123
+ */
2124
+ private function __clone() {
2125
+
2126
+ }
2127
+
2128
+ /**
2129
+ * Private unserialize method to prevent unserializing of the Singleton
2130
+ * instance.
2131
+ *
2132
+ * @return void
2133
+ */
2134
+ private function __wakeup() {
2135
+
2136
+ }
2137
+
2138
+ public static function add_dashboard_menu() {
2139
+ $get_custom_reports = get_option( 'gawd_custom_reports' );
2140
+ if ( ! $get_custom_reports ) {
2141
+ $custom_report = array();
2142
+ } else {
2143
+ foreach ( $get_custom_reports as $name => $report ) {
2144
+ $custom_report[ 'custom_report_' . $name ] = __( $name, "gawd" );
2145
+ }
2146
+ }
2147
+ $tabs = array(
2148
+ "general" => array(
2149
+ "title" => __( "Audience", "gawd" ),
2150
+ "childs" => array(),
2151
+ "desc" => "Report of your website audience. Provides details about new and returning users of your website, sessions, bounces, pageviews and session durations."
2152
+ ),
2153
+ "realtime" => array(
2154
+ "title" => __( "Real Time", "gawd" ),
2155
+ "childs" => array(),
2156
+ "desc" => "Real Time statistics show the number of active users currently visiting your website pages."
2157
+ ),
2158
+ "demographics" => array(
2159
+ "title" => __( "Demographics", "gawd" ),
2160
+ "childs" => array(
2161
+ "userGender" => __( "User Gender", "gawd" ),
2162
+ "userAge" => __( "User Age", "gawd" )
2163
+ ),
2164
+ "desc" => "Demographics display tracking statistics of your website users based on their age and gender. "
2165
+
2166
+ ),
2167
+ "interests" => array(
2168
+ "title" => __( "Interests", "gawd" ),
2169
+ "childs" => array(
2170
+ "inMarket" => __( "In-Market Segment", "gawd" ),
2171
+ "affinityCategory" => __( "Affinity Category", "gawd" ),
2172
+ "otherCategory" => __( "Other Category", "gawd" )
2173
+ ),
2174
+ "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)."
2175
+ ),
2176
+ "geo" => array(
2177
+ "title" => __( "GEO", "gawd" ),
2178
+ "childs" => array(
2179
+ "location" => __( "Location", "gawd" ),
2180
+ "language" => __( "Language", "gawd" )
2181
+ ),
2182
+ "desc" => "Geo-identifier report is built from interactions of location (countries, cities) and language of your website users."
2183
+ ),
2184
+ "behavior" => array(
2185
+ "title" => __( "Behavior", "gawd" ),
2186
+ "childs" => array(
2187
+ "behaviour" => __( "New vs Returning", "gawd" ),
2188
+ "engagement" => __( "Engagement", "gawd" )
2189
+ ),
2190
+ "desc" => "Compares number of New visitors and Returning users of your website in percents. You can check the duration of sessions with Engagement report."
2191
+ ),
2192
+ "technology" => array(
2193
+ "title" => __( "Technology", "gawd" ),
2194
+ "childs" => array(
2195
+ "os" => __( "OS", "gawd" ),
2196
+ "browser" => __( "Browser", "gawd" )
2197
+ ),
2198
+ "desc" => "Identifies tracking of the site based on operating systems and browsers visitors use."
2199
+ ),
2200
+ "mobile" => array(
2201
+ "title" => __( "Mobile", "gawd" ),
2202
+ "childs" => array(
2203
+ "device_overview" => __( "Overview", "gawd" ),
2204
+ "devices" => __( "Devices", "gawd" )
2205
+ ),
2206
+ "desc" => "Shows statistics of mobile and desktop devices visitors have used while interacting with your website."
2207
+ ),
2208
+ "custom" => array(
2209
+ "title" => __( "Custom Dimensions", "gawd" ),
2210
+ "childs" => array(),
2211
+ "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."
2212
+ ),
2213
+ "trafficSource" => array(
2214
+ "title" => __( "Traffic Source", "gawd" ),
2215
+ "childs" => array(),
2216
+ "desc" => "Displays overall graph of traffic sources directing to your website."
2217
+ ),
2218
+ "adWords" => array(
2219
+ "title" => __( "AdWords", "gawd" ),
2220
+ "childs" => array(),
2221
+ "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."
2222
+ ),
2223
+ /* "pagePath" => array(
 
 
 
 
 
 
 
2224
  "title" => __("Pages", "gawd"),
2225
  "childs" => array(),
2226
  "desc" => "Pages report table will provide you information about Bounces, Entrances, Pageviews, Unique Pageviews, time spent on pages, Exits and Average page loading time."
2227
  ), */
2228
+ "siteContent" => array(
2229
+ "title" => __( "Site Content", "gawd" ),
2230
+ "childs" => array(
2231
+ "pagePath" => __( "All Pages", "gawd" ),
2232
+ "landingPagePath" => __( "Landing Pages", "gawd" ),
2233
+ ),
2234
+ "desc" => "Pages report table will provide you information about Bounces, Entrances, Pageviews, Unique Pageviews, time spent on pages, Exits and Average page loading time."
2235
+ ),
2236
+ "siteSpeed" => array(
2237
+ "title" => __( "Site Speed", "gawd" ),
2238
+ "childs" => array(),
2239
+ "desc" => "Shows the average load time of your website users experienced during specified date range."
2240
+ ),
2241
+ "events" => array(
2242
+ "title" => __( "Events", "gawd" ),
2243
+ "childs" => array(
2244
+ "eventsLabel" => __( "Events by Label", "gawd" ),
2245
+ "eventsAction" => __( "Events by Action", "gawd" ),
2246
+ "eventsCategory" => __( "Events by Category", "gawd" )
2247
+ ),
2248
+ "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."
2249
+ ),
2250
+ "goals" => array(
2251
+ "title" => __( "Goals", "gawd" ),
2252
+ "childs" => array(),
2253
+ "desc" => "Set Goals from Goal Management and review their Google Analytics reports under this tab."
2254
+ ),
2255
+ "ecommerce" => array(
2256
+ "title" => __( "Ecommerce", "gawd" ),
2257
+ "childs" => array(
2258
+ "daysToTransaction" => __( "TIme to Purchase", "gawd" ),
2259
+ "transactionId" => __( "Transaction ID", "gawd" ),
2260
+ "sales_performance" => __( "Sales Performance", "gawd" ),
2261
+ "productSku" => __( "Product Sku", "gawd" ),
2262
+ "productCategory" => __( "Product Category ", "gawd" ),
2263
+ "productName" => __( "Product Name", "gawd" ),
2264
+ ),
2265
+ "desc" => "Check sales statistics of your website identified by revenues, transactions, products and performance."
2266
+ ),
2267
+ "adsense" => array(
2268
+ "title" => __( "AdSense", "gawd" ),
2269
+ "childs" => array(),
2270
+ "desc" => "Link your Google Analytics and AdSense accounts from Google Analytics Admin setting and keep track of AdSense tracking under this report."
2271
+ ),
2272
+ "customReport" => array(
2273
+ "title" => __( "Custom Report", "gawd" ),
2274
+ "childs" => $custom_report,
2275
+ "desc" => "Add Custom Reports from any metric and dimension in Custom Reports page, and view relevant Google Analytics tracking information in this tab."
2276
+ ),
2277
+ );
2278
+ update_option( 'gawd_menu_items', $tabs );
2279
+ }
2280
+
2281
+ public function remove_zoom_message() {
2282
+ check_ajax_referer( 'gawd_admin_page_nonce', 'security' );
2283
+ $got_it = isset( $_REQUEST["got_it"] ) ? sanitize_text_field( $_REQUEST["got_it"] ) : '';
2284
+ if ( $got_it != '' ) {
2285
+ add_option( 'gawd_zoom_message', $got_it );
2286
+ }
2287
+ }
2288
  }
google-analytics-wd.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: WD Google Analytics
5
  * Plugin URI: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
6
  * Description: WD Google Analytics is a user-friendly all in one plugin, which allows to manage and monitor your website analytics from WordPress dashboard.
7
- * Version: 1.0.3
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.3');
30
  }
31
 
32
  require_once( 'gawd_class.php' );
4
  * Plugin Name: WD Google Analytics
5
  * Plugin URI: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
6
  * Description: WD Google Analytics is a user-friendly all in one plugin, which allows to manage and monitor your website analytics from WordPress dashboard.
7
+ * Version: 1.0.4
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.4');
30
  }
31
 
32
  require_once( 'gawd_class.php' );
readme.txt CHANGED
@@ -1,10 +1,10 @@
1
- === Google Analytics WD ===
2
  Contributors: webdorado
3
  Donate link: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
4
  Tags: analytics, analytics dashboard, google analytics, google analytics dashboard, statistics, tracking, stats, ga, universal analytics, ecommerce tracking, custom dimensions, custom reports
5
  Requires at least: 3.9
6
  Tested up to: 4.6
7
- Stable tag: 1.0.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -98,6 +98,10 @@ Upgrade to Google Analytics WD Pro for premium features:
98
 
99
  == Changelog ==
100
 
 
 
 
 
101
  = 1.0.3 =
102
  Fixed: Front reports permissions
103
  Fixed: Analytics menu
1
+ === Google Analytics ===
2
  Contributors: webdorado
3
  Donate link: https://web-dorado.com/products/wordpress-google-analytics-plugin.html
4
  Tags: analytics, analytics dashboard, google analytics, google analytics dashboard, statistics, tracking, stats, ga, universal analytics, ecommerce tracking, custom dimensions, custom reports
5
  Requires at least: 3.9
6
  Tested up to: 4.6
7
+ Stable tag: 1.0.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
98
 
99
  == Changelog ==
100
 
101
+ = 1.0.4 =
102
+ Fixed: Unauthenticate issue
103
+ Fixed: Errors for php version < 5.3
104
+
105
  = 1.0.3 =
106
  Fixed: Front reports permissions
107
  Fixed: Analytics menu