WD Google Analytics - Version 1.0.11

Version Description

Added: Custom code option in tracking

Download this release

Release Info

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

Code changes from version 1.0.10 to 1.0.11

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