Google Analytics Dashboard for WP (GADWP) - Version 4.4.5

Version Description

  • Enhancement: GAPI requests optimization
  • Enhancement: server responses improvements
  • Enhancement: filter data through query options
  • Bugfix: additional checks before displaying an error
  • Bugfix: wrong error displayed on IE
  • Bugfix: set correct Content-Type before sending responses
Download this release

Release Info

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

Code changes from version 4.4.4 to 4.4.5

admin/ajax-actions.php CHANGED
@@ -5,6 +5,7 @@
5
  * License: GPLv2 or later
6
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
7
  */
 
8
  if (! class_exists('GADASH_Backend_Ajax')) {
9
 
10
  final class GADASH_Backend_Ajax
@@ -23,6 +24,16 @@ if (! class_exists('GADASH_Backend_Ajax')) {
23
  'ajax_adminwidget_reports'
24
  ));
25
  }
 
 
 
 
 
 
 
 
 
 
26
 
27
  /**
28
  * Ajax handler for getting reports for Admin Widget
@@ -58,40 +69,39 @@ if (! class_exists('GADASH_Backend_Ajax')) {
58
  }
59
  switch ($query) {
60
  case 'referrers':
61
- print($GADASH_GAPI->get_referrers($projectId, $from, $to));
62
  break;
63
  case 'contentpages':
64
- print($GADASH_GAPI->get_contentpages($projectId, $from, $to));
65
  break;
66
  case 'locations':
67
- print($GADASH_GAPI->get_locations($projectId, $from, $to));
68
  break;
69
  case 'bottomstats':
70
- print(json_encode($GADASH_GAPI->get_bottomstats($projectId, $from, $to)));
71
  break;
72
  case 'trafficchannels':
73
- print($GADASH_GAPI->get_trafficchannels($projectId, $from, $to));
74
  break;
75
  case 'medium':
76
- print($GADASH_GAPI->get_trafficdetails($projectId, $from, $to, 'medium'));
77
  break;
78
  case 'visitorType':
79
- print($GADASH_GAPI->get_trafficdetails($projectId, $from, $to, 'visitorType'));
80
  break;
81
  case 'socialNetwork':
82
- print($GADASH_GAPI->get_trafficdetails($projectId, $from, $to, 'socialNetwork'));
83
  break;
84
  case 'source':
85
- print($GADASH_GAPI->get_trafficdetails($projectId, $from, $to, 'source'));
86
  break;
87
  case 'searches':
88
- print($GADASH_GAPI->get_searches($projectId, $from, $to));
89
  break;
90
  default:
91
- print($GADASH_GAPI->get_mainreport($projectId, $from, $to, $query));
92
  break;
93
  }
94
- wp_die();
95
  }
96
  // Real-Time Request
97
  /**
@@ -123,8 +133,7 @@ if (! class_exists('GADASH_Backend_Ajax')) {
123
  } else {
124
  wp_die(- 24);
125
  }
126
- print($GADASH_GAPI->gadash_realtime_data($projectId));
127
- wp_die();
128
  }
129
  }
130
  }
5
  * License: GPLv2 or later
6
  * License URI: http://www.gnu.org/licenses/gpl-2.0.html
7
  */
8
+
9
  if (! class_exists('GADASH_Backend_Ajax')) {
10
 
11
  final class GADASH_Backend_Ajax
24
  'ajax_adminwidget_reports'
25
  ));
26
  }
27
+
28
+ function send_json($response)
29
+ {
30
+ @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
31
+ echo wp_json_encode($response);
32
+ if (defined('DOING_AJAX') && DOING_AJAX)
33
+ wp_die();
34
+ else
35
+ die();
36
+ }
37
 
38
  /**
39
  * Ajax handler for getting reports for Admin Widget
69
  }
70
  switch ($query) {
71
  case 'referrers':
72
+ $this->send_json($GADASH_GAPI->get_referrers($projectId, $from, $to));
73
  break;
74
  case 'contentpages':
75
+ $this->send_json($GADASH_GAPI->get_contentpages($projectId, $from, $to));
76
  break;
77
  case 'locations':
78
+ $this->send_json($GADASH_GAPI->get_locations($projectId, $from, $to));
79
  break;
80
  case 'bottomstats':
81
+ $this->send_json($GADASH_GAPI->get_bottomstats($projectId, $from, $to));
82
  break;
83
  case 'trafficchannels':
84
+ $this->send_json($GADASH_GAPI->get_trafficchannels($projectId, $from, $to));
85
  break;
86
  case 'medium':
87
+ $this->send_json($GADASH_GAPI->get_trafficdetails($projectId, $from, $to, 'medium'));
88
  break;
89
  case 'visitorType':
90
+ $this->send_json($GADASH_GAPI->get_trafficdetails($projectId, $from, $to, 'visitorType'));
91
  break;
92
  case 'socialNetwork':
93
+ $this->send_json($GADASH_GAPI->get_trafficdetails($projectId, $from, $to, 'socialNetwork'));
94
  break;
95
  case 'source':
96
+ $this->send_json($GADASH_GAPI->get_trafficdetails($projectId, $from, $to, 'source'));
97
  break;
98
  case 'searches':
99
+ $this->send_json($GADASH_GAPI->get_searches($projectId, $from, $to));
100
  break;
101
  default:
102
+ $this->send_json($GADASH_GAPI->get_mainreport($projectId, $from, $to, $query));
103
  break;
104
  }
 
105
  }
106
  // Real-Time Request
107
  /**
133
  } else {
134
  wp_die(- 24);
135
  }
136
+ $this->send_json($GADASH_GAPI->gadash_realtime_data($projectId));
 
137
  }
138
  }
139
  }
admin/dashboard_widgets.php CHANGED
@@ -543,8 +543,7 @@ if (! class_exists('GADASH_Widgets')) {
543
  function online_refresh(){
544
  if (focusFlag){
545
 
546
- jQuery.post(ajaxurl, {action: "gadashadmin_get_realtime", projectId: "<?php echo $projectId;?>", gadashadmin_security_widgetrealtime: "<?php echo wp_create_nonce('gadashadmin_get_realtime');?>"}, function(response){
547
- var data = jQuery.parseJSON(response);
548
 
549
  if (jQuery.isNumeric(data) || typeof data === "undefined"){
550
  data = [];
@@ -687,10 +686,10 @@ if (! class_exists('GADASH_Widgets')) {
687
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
688
 
689
  if (!jQuery.isNumeric(response)){
690
- try{
691
- gadash_prs=jQuery.parseJSON(response);
692
  google.setOnLoadCallback(ga_dash_drawprs(gadash_prs));
693
- } catch(e) {
694
  checknpcounter(0);
695
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
696
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
@@ -704,12 +703,11 @@ if (! class_exists('GADASH_Widgets')) {
704
  });
705
 
706
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "trafficchannels",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
707
-
708
  if (!jQuery.isNumeric(response)){
709
- try{
710
- gadash_trafficchannels=jQuery.parseJSON(response);
711
  google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels));
712
- } catch(e) {
713
  checknpcounter(0);
714
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
715
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
@@ -784,10 +782,10 @@ if (! class_exists('GADASH_Widgets')) {
784
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "medium",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
785
 
786
  if (!jQuery.isNumeric(response)){
787
- try{
788
- gadash_trafficmediums=jQuery.parseJSON(response);
789
  google.setOnLoadCallback(ga_dash_drawtrafficmediums(gadash_trafficmediums));
790
- } catch(e) {
791
  checknpcounter(0);
792
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
793
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
@@ -801,10 +799,16 @@ if (! class_exists('GADASH_Widgets')) {
801
  });
802
 
803
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "visitorType",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
804
-
805
  if (!jQuery.isNumeric(response)){
806
- gadash_traffictype=jQuery.parseJSON(response);
807
- google.setOnLoadCallback(ga_dash_drawtraffictype(gadash_traffictype));
 
 
 
 
 
 
 
808
  }else{
809
  jQuery("#gadash-traffictype").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
810
  jQuery("#gadash-traffictype").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
@@ -815,10 +819,10 @@ if (! class_exists('GADASH_Widgets')) {
815
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "trafficchannels",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
816
 
817
  if (!jQuery.isNumeric(response)){
818
- try{
819
- gadash_trafficchannels=jQuery.parseJSON(response);
820
  google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels));
821
- } catch(e) {
822
  checknpcounter(0);
823
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
824
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
@@ -834,10 +838,10 @@ if (! class_exists('GADASH_Widgets')) {
834
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "socialNetwork",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
835
 
836
  if (!jQuery.isNumeric(response)){
837
- try{
838
- gadash_socialnetworks=jQuery.parseJSON(response);
839
  google.setOnLoadCallback(ga_dash_drawsocialnetworks(gadash_socialnetworks));
840
- } catch(e) {
841
  checknpcounter(0);
842
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
843
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
@@ -854,10 +858,10 @@ if (! class_exists('GADASH_Widgets')) {
854
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "source",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
855
 
856
  if (!jQuery.isNumeric(response)){
857
- try{
858
- gadash_trafficorganic=jQuery.parseJSON(response);
859
  google.setOnLoadCallback(ga_dash_drawtrafficorganic(gadash_trafficorganic));
860
- } catch(e) {
861
  checknpcounter(0);
862
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
863
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
@@ -976,11 +980,11 @@ if (! class_exists('GADASH_Widgets')) {
976
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
977
 
978
  if (!jQuery.isNumeric(response)){
979
- try{
980
- gadash_locations=jQuery.parseJSON(response);
981
  google.setOnLoadCallback(ga_dash_drawmaplocations(gadash_locations));
982
  google.setOnLoadCallback(ga_dash_drawlocations(gadash_locations));
983
- } catch(e) {
984
  checknpcounter(0);
985
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
986
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
@@ -1087,10 +1091,10 @@ if (! class_exists('GADASH_Widgets')) {
1087
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
1088
 
1089
  if (!jQuery.isNumeric(response)){
1090
- try{
1091
- gadash_mainchart=jQuery.parseJSON(response);
1092
  google.setOnLoadCallback(ga_dash_drawmainchart(gadash_mainchart));
1093
- } catch(e) {
1094
  checknpcounter(0);
1095
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
1096
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
@@ -1106,10 +1110,10 @@ if (! class_exists('GADASH_Widgets')) {
1106
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "bottomstats",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
1107
 
1108
  if (!jQuery.isNumeric(response)){
1109
- try{
1110
- gadash_bottomstats=jQuery.parseJSON(response);
1111
  ga_dash_drawbottomstats(gadash_bottomstats);
1112
- } catch(e) {
1113
  checknpcounter(0);
1114
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
1115
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
543
  function online_refresh(){
544
  if (focusFlag){
545
 
546
+ jQuery.post(ajaxurl, {action: "gadashadmin_get_realtime", projectId: "<?php echo $projectId;?>", gadashadmin_security_widgetrealtime: "<?php echo wp_create_nonce('gadashadmin_get_realtime');?>"}, function(data){
 
547
 
548
  if (jQuery.isNumeric(data) || typeof data === "undefined"){
549
  data = [];
686
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
687
 
688
  if (!jQuery.isNumeric(response)){
689
+ if (jQuery.isArray(response)){
690
+ gadash_prs=response;
691
  google.setOnLoadCallback(ga_dash_drawprs(gadash_prs));
692
+ } else {
693
  checknpcounter(0);
694
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
695
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
703
  });
704
 
705
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "trafficchannels",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
 
706
  if (!jQuery.isNumeric(response)){
707
+ if (jQuery.isArray(response)){
708
+ gadash_trafficchannels=response;
709
  google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels));
710
+ } else {
711
  checknpcounter(0);
712
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
713
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
782
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "medium",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
783
 
784
  if (!jQuery.isNumeric(response)){
785
+ if (jQuery.isArray(response)){
786
+ gadash_trafficmediums=response;
787
  google.setOnLoadCallback(ga_dash_drawtrafficmediums(gadash_trafficmediums));
788
+ } else {
789
  checknpcounter(0);
790
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
791
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
799
  });
800
 
801
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "visitorType",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
 
802
  if (!jQuery.isNumeric(response)){
803
+ if (jQuery.isArray(response)){
804
+ gadash_traffictype=response;
805
+ google.setOnLoadCallback(ga_dash_drawtraffictype(gadash_traffictype));
806
+ } else {
807
+ checknpcounter(0);
808
+ jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
809
+ jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
810
+ console.log("\n********************* GADWP Log ********************* \n\n"+response);
811
+ }
812
  }else{
813
  jQuery("#gadash-traffictype").css({"background-color":"#F7F7F7","height":"auto","padding-top":"80px","padding-bottom":"80px","color":"#000","text-align":"center"});
814
  jQuery("#gadash-traffictype").html("<?php _e("This report is unavailable", 'ga-dash'); ?> ("+response+")");
819
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "trafficchannels",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
820
 
821
  if (!jQuery.isNumeric(response)){
822
+ if (jQuery.isArray(response)){
823
+ gadash_trafficchannels=response;
824
  google.setOnLoadCallback(ga_dash_drawtrafficchannels(gadash_trafficchannels));
825
+ } else {
826
  checknpcounter(0);
827
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
828
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
838
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "socialNetwork",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
839
 
840
  if (!jQuery.isNumeric(response)){
841
+ if (jQuery.isArray(response)){
842
+ gadash_socialnetworks=response;
843
  google.setOnLoadCallback(ga_dash_drawsocialnetworks(gadash_socialnetworks));
844
+ } else {
845
  checknpcounter(0);
846
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
847
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
858
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "source",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
859
 
860
  if (!jQuery.isNumeric(response)){
861
+ if (jQuery.isArray(response)){
862
+ gadash_trafficorganic=response;
863
  google.setOnLoadCallback(ga_dash_drawtrafficorganic(gadash_trafficorganic));
864
+ } else {
865
  checknpcounter(0);
866
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
867
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
980
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
981
 
982
  if (!jQuery.isNumeric(response)){
983
+ if (jQuery.isArray(response)){
984
+ gadash_locations=response;
985
  google.setOnLoadCallback(ga_dash_drawmaplocations(gadash_locations));
986
  google.setOnLoadCallback(ga_dash_drawlocations(gadash_locations));
987
+ } else {
988
  checknpcounter(0);
989
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
990
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
1091
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "<?php echo $query; ?>",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
1092
 
1093
  if (!jQuery.isNumeric(response)){
1094
+ if (jQuery.isArray(response)){
1095
+ gadash_mainchart=response;
1096
  google.setOnLoadCallback(ga_dash_drawmainchart(gadash_mainchart));
1097
+ } else {
1098
  checknpcounter(0);
1099
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
1100
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
1110
  jQuery.post(ajaxurl, {action: "gadashadmin_get_widgetreports",projectId: "<?php echo $projectId; ?>",from: "<?php echo $from; ?>",to: "<?php echo $to; ?>",query: "bottomstats",gadashadmin_security_widget_reports: "<?php echo wp_create_nonce('gadashadmin_get_widgetreports'); ?>"}, function(response){
1111
 
1112
  if (!jQuery.isNumeric(response)){
1113
+ if (jQuery.isArray(response)){
1114
+ gadash_bottomstats=response;
1115
  ga_dash_drawbottomstats(gadash_bottomstats);
1116
+ } else {
1117
  checknpcounter(0);
1118
  jQuery("#gadash-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red"});
1119
  jQuery("#gadash-progressbar").html("<?php _e("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'); ?>");
admin/ga_dash_settings.php CHANGED
@@ -675,6 +675,7 @@ final class GADASH_Settings
675
  public static function errors_debugging()
676
  {
677
  global $GADASH_Config;
 
678
  if (! current_user_can('manage_options')) {
679
  return;
680
  }
@@ -1447,10 +1448,10 @@ final class GADASH_Settings
1447
  </h3>
1448
  <div class="inside">
1449
  <div class="gadash-title">
1450
- <a href="http://tracking.maxcdn.com/c/94142/36539/378"><img
1451
  src="<?php echo plugins_url( 'images/mcdn.png' , __FILE__ ); ?>" /></a>
1452
  </div>
1453
- <div class="gadash-desc"><?php echo __('Speed up your website and plug into a whole', 'ga-dash').' <a href="http://tracking.maxcdn.com/c/94142/36539/378">'.__('new level of site speed', 'ga-dash').'</a>.'; ?></div>
1454
  <br />
1455
  <div class="gadash-title">
1456
  <a
675
  public static function errors_debugging()
676
  {
677
  global $GADASH_Config;
678
+ global $wp_version;
679
  if (! current_user_can('manage_options')) {
680
  return;
681
  }
1448
  </h3>
1449
  <div class="inside">
1450
  <div class="gadash-title">
1451
+ <a href="https://deconf.com/wordpress-cdn-speeds-up-your-site/"><img
1452
  src="<?php echo plugins_url( 'images/mcdn.png' , __FILE__ ); ?>" /></a>
1453
  </div>
1454
+ <div class="gadash-desc"><?php echo __('Speed up your website and plug into a whole', 'ga-dash').' <a href="https://deconf.com/wordpress-cdn-speeds-up-your-site/">'.__('new level of site speed', 'ga-dash').'</a>.'; ?></div>
1455
  <br />
1456
  <div class="gadash-title">
1457
  <a
front/ajax-actions.php CHANGED
@@ -27,7 +27,17 @@ if (! class_exists('GADASH_Frontend_Ajax')) {
27
  'ajax_frontend_widget'
28
  ));
29
  }
30
- // Frontend Reports/Page
 
 
 
 
 
 
 
 
 
 
31
  /**
32
  * Ajax handler for getting analytics data for frontend Views vs UniqueViews
33
  *
@@ -37,7 +47,7 @@ if (! class_exists('GADASH_Frontend_Ajax')) {
37
  {
38
  global $GADASH_Config;
39
  if (! isset($_REQUEST['gadash_security_pagereports']) or ! wp_verify_nonce($_REQUEST['gadash_security_pagereports'], 'gadash_get_frontend_pagereports')) {
40
- wp_die(-30);
41
  }
42
  $page_url = esc_url($_REQUEST['gadash_pageurl']);
43
  $post_id = (int) $_REQUEST['gadash_postid'];
@@ -51,13 +61,13 @@ if (! class_exists('GADASH_Frontend_Ajax')) {
51
  include_once ($GADASH_Config->plugin_path . '/tools/tools.php');
52
  $tools = new GADASH_Tools();
53
  if (! $tools->check_roles($GADASH_Config->options['ga_dash_access_front']) or ! ($GADASH_Config->options['ga_dash_frontend_stats'] or $GADASH_Config->options['ga_dash_frontend_keywords'])) {
54
- wp_die(-31);
55
  }
56
  if ($GADASH_Config->options['ga_dash_token'] and $GADASH_Config->options['ga_dash_tableid_jail']) {
57
  include_once ($GADASH_Config->plugin_path . '/tools/gapi.php');
58
  global $GADASH_GAPI;
59
  } else {
60
- wp_die(-24);
61
  }
62
  $projectId = $GADASH_Config->options['ga_dash_tableid_jail'];
63
  $profile_info = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $projectId);
@@ -67,17 +77,16 @@ if (! class_exists('GADASH_Frontend_Ajax')) {
67
  $GADASH_GAPI->timeshift = (int) current_time('timestamp') - time();
68
  }
69
  if (! $GADASH_GAPI->client->getAccessToken()) {
70
- wp_die(-25);
71
  }
72
  switch ($query) {
73
  case 'pageviews':
74
- print($GADASH_GAPI->frontend_afterpost_pageviews($projectId, $page_url, $post_id));
75
  break;
76
  default:
77
- print($GADASH_GAPI->frontend_afterpost_searches($projectId, $page_url, $post_id));
78
  break;
79
  }
80
- wp_die();
81
  }
82
  // Frontend Widget Reports
83
  /**
@@ -89,7 +98,7 @@ if (! class_exists('GADASH_Frontend_Ajax')) {
89
  {
90
  global $GADASH_Config;
91
  if (! isset($_REQUEST['gadash_number']) or ! isset($_REQUEST['gadash_optionname']) or ! is_active_widget(false, false, 'gadash_frontend_widget')) {
92
- wp_die(-30);
93
  }
94
  $widget_index = $_REQUEST['gadash_number'];
95
  $option_name = $_REQUEST['gadash_optionname'];
@@ -97,7 +106,7 @@ if (! class_exists('GADASH_Frontend_Ajax')) {
97
  if (isset($options[$widget_index])) {
98
  $instance = $options[$widget_index];
99
  } else {
100
- wp_die(-32);
101
  }
102
  switch ($instance['period']) { // make sure we have a valid request
103
  case '7daysAgo':
@@ -119,7 +128,7 @@ if (! class_exists('GADASH_Frontend_Ajax')) {
119
  include_once ($GADASH_Config->plugin_path . '/tools/tools.php');
120
  $tools = new GADASH_Tools();
121
  } else {
122
- wp_die(-24);
123
  }
124
  $projectId = $GADASH_Config->options['ga_dash_tableid_jail'];
125
  $profile_info = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $projectId);
@@ -129,11 +138,9 @@ if (! class_exists('GADASH_Frontend_Ajax')) {
129
  $GADASH_GAPI->timeshift = (int) current_time('timestamp') - time();
130
  }
131
  if (! $GADASH_GAPI->client->getAccessToken()) {
132
- wp_die(-25);
133
  }
134
- $data_widget = $GADASH_GAPI->frontend_widget_stats($projectId, $period, (int) $instance['anonim']);
135
- print(json_encode($data_widget));
136
- wp_die();
137
  }
138
  }
139
  }
27
  'ajax_frontend_widget'
28
  ));
29
  }
30
+
31
+ function send_json($response)
32
+ {
33
+ @header('Content-Type: application/json; charset=' . get_option('blog_charset'));
34
+ echo wp_json_encode($response);
35
+ if (defined('DOING_AJAX') && DOING_AJAX)
36
+ wp_die();
37
+ else
38
+ die();
39
+ }
40
+
41
  /**
42
  * Ajax handler for getting analytics data for frontend Views vs UniqueViews
43
  *
47
  {
48
  global $GADASH_Config;
49
  if (! isset($_REQUEST['gadash_security_pagereports']) or ! wp_verify_nonce($_REQUEST['gadash_security_pagereports'], 'gadash_get_frontend_pagereports')) {
50
+ wp_die(- 30);
51
  }
52
  $page_url = esc_url($_REQUEST['gadash_pageurl']);
53
  $post_id = (int) $_REQUEST['gadash_postid'];
61
  include_once ($GADASH_Config->plugin_path . '/tools/tools.php');
62
  $tools = new GADASH_Tools();
63
  if (! $tools->check_roles($GADASH_Config->options['ga_dash_access_front']) or ! ($GADASH_Config->options['ga_dash_frontend_stats'] or $GADASH_Config->options['ga_dash_frontend_keywords'])) {
64
+ wp_die(- 31);
65
  }
66
  if ($GADASH_Config->options['ga_dash_token'] and $GADASH_Config->options['ga_dash_tableid_jail']) {
67
  include_once ($GADASH_Config->plugin_path . '/tools/gapi.php');
68
  global $GADASH_GAPI;
69
  } else {
70
+ wp_die(- 24);
71
  }
72
  $projectId = $GADASH_Config->options['ga_dash_tableid_jail'];
73
  $profile_info = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $projectId);
77
  $GADASH_GAPI->timeshift = (int) current_time('timestamp') - time();
78
  }
79
  if (! $GADASH_GAPI->client->getAccessToken()) {
80
+ wp_die(- 25);
81
  }
82
  switch ($query) {
83
  case 'pageviews':
84
+ $this->send_json($GADASH_GAPI->frontend_afterpost_pageviews($projectId, $page_url, $post_id));
85
  break;
86
  default:
87
+ $this->send_json($GADASH_GAPI->frontend_afterpost_searches($projectId, $page_url, $post_id));
88
  break;
89
  }
 
90
  }
91
  // Frontend Widget Reports
92
  /**
98
  {
99
  global $GADASH_Config;
100
  if (! isset($_REQUEST['gadash_number']) or ! isset($_REQUEST['gadash_optionname']) or ! is_active_widget(false, false, 'gadash_frontend_widget')) {
101
+ wp_die(- 30);
102
  }
103
  $widget_index = $_REQUEST['gadash_number'];
104
  $option_name = $_REQUEST['gadash_optionname'];
106
  if (isset($options[$widget_index])) {
107
  $instance = $options[$widget_index];
108
  } else {
109
+ wp_die(- 32);
110
  }
111
  switch ($instance['period']) { // make sure we have a valid request
112
  case '7daysAgo':
128
  include_once ($GADASH_Config->plugin_path . '/tools/tools.php');
129
  $tools = new GADASH_Tools();
130
  } else {
131
+ wp_die(- 24);
132
  }
133
  $projectId = $GADASH_Config->options['ga_dash_tableid_jail'];
134
  $profile_info = $tools->get_selected_profile($GADASH_Config->options['ga_dash_profile_list'], $projectId);
138
  $GADASH_GAPI->timeshift = (int) current_time('timestamp') - time();
139
  }
140
  if (! $GADASH_GAPI->client->getAccessToken()) {
141
+ wp_die(- 25);
142
  }
143
+ $this->send_json($GADASH_GAPI->frontend_widget_stats($projectId, $period, (int) $instance['anonim']));
 
 
144
  }
145
  }
146
  }
front/frontend.php CHANGED
@@ -91,13 +91,13 @@ if (! class_exists('GADASH_Frontend')) {
91
  if(typeof ga_dash_drawpagesessions == "function"){
92
  jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",gadash_postid: "' . $post_id . '",query: "pageviews",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){
93
  if (!jQuery.isNumeric(response)){
94
- try{
95
- gadash_pagesessions = jQuery.parseJSON(response);
96
  google.setOnLoadCallback(ga_dash_drawpagesessions(gadash_pagesessions));
97
- } catch(e) {
98
  checknpcounter(0);
99
  jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
100
- jQuery("#gadwp-progressbar").html("'. __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'). '");
101
  console.log("\n********************* GADWP Log ********************* \n\n"+response);
102
  }
103
  }else{
@@ -110,13 +110,13 @@ if (! class_exists('GADASH_Frontend')) {
110
  if(typeof ga_dash_drawpagesearches == "function"){
111
  jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",gadash_postid: "' . $post_id . '",query: "searches",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){
112
  if (!jQuery.isNumeric(response)){
113
- try{
114
- gadash_pagesearches = jQuery.parseJSON(response);
115
  google.setOnLoadCallback(ga_dash_drawpagesearches(gadash_pagesearches));
116
- } catch(e) {
117
  checknpcounter(0);
118
  jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
119
- jQuery("#gadwp-progressbar").html("'. __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash'). '");
120
  console.log("\n********************* GADWP Log ********************* \n\n"+response);
121
  }
122
  }else{
91
  if(typeof ga_dash_drawpagesessions == "function"){
92
  jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",gadash_postid: "' . $post_id . '",query: "pageviews",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){
93
  if (!jQuery.isNumeric(response)){
94
+ if (jQuery.isArray(response)){
95
+ gadash_pagesessions = response;
96
  google.setOnLoadCallback(ga_dash_drawpagesessions(gadash_pagesessions));
97
+ } else {
98
  checknpcounter(0);
99
  jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
100
+ jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '");
101
  console.log("\n********************* GADWP Log ********************* \n\n"+response);
102
  }
103
  }else{
110
  if(typeof ga_dash_drawpagesearches == "function"){
111
  jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontend_pagereports",gadash_pageurl: "' . $page_url . '",gadash_postid: "' . $post_id . '",query: "searches",gadash_security_pagereports: "' . wp_create_nonce('gadash_get_frontend_pagereports') . '"}, function(response){
112
  if (!jQuery.isNumeric(response)){
113
+ if (jQuery.isArray(response)){
114
+ gadash_pagesearches = response;
115
  google.setOnLoadCallback(ga_dash_drawpagesearches(gadash_pagesearches));
116
+ } else {
117
  checknpcounter(0);
118
  jQuery("#gadwp-progressbar").css({"margin-top":"3px","padding-left":"5px","height":"auto","color":"#000","border-left":"5px solid red","font-size":"13px"});
119
+ jQuery("#gadwp-progressbar").html("' . __("Invalid response, more details in JavaScript Console (F12).", 'ga-dash') . '");
120
  console.log("\n********************* GADWP Log ********************* \n\n"+response);
121
  }
122
  }else{
front/widgets.php CHANGED
@@ -95,14 +95,13 @@ class GADSH_Frontend_Widget extends WP_Widget
95
  echo '<script type="text/javascript">
96
 
97
  jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontendwidget_data",gadash_number: "' . $this->number . '",gadash_optionname: "' . $this->option_name . '"}, function(response){
98
- if (!jQuery.isNumeric(response)){
99
- response = jQuery.parseJSON(response);
100
  if (jQuery("#gadwp-widgetchart")[0]){
101
- gadash_widgetsessions=jQuery.parseJSON(response[0]);
102
  google.setOnLoadCallback(ga_dash_drawfwidgetsessions(gadash_widgetsessions));
103
  }
104
  if (jQuery("#gadwp-widgettotals")[0]){
105
- ga_dash_drawtotalsstats(jQuery.parseJSON(response[1]));
106
  }
107
  }else{
108
  jQuery("#gadwp-widgetchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"50px","padding-bottom":"50px","color":"#000","text-align":"center"});
95
  echo '<script type="text/javascript">
96
 
97
  jQuery.post("' . admin_url('admin-ajax.php') . '", {action: "gadash_get_frontendwidget_data",gadash_number: "' . $this->number . '",gadash_optionname: "' . $this->option_name . '"}, function(response){
98
+ if (!jQuery.isNumeric(response) && jQuery.isArray(response)){
 
99
  if (jQuery("#gadwp-widgetchart")[0]){
100
+ gadash_widgetsessions=response[0];
101
  google.setOnLoadCallback(ga_dash_drawfwidgetsessions(gadash_widgetsessions));
102
  }
103
  if (jQuery("#gadwp-widgettotals")[0]){
104
+ ga_dash_drawtotalsstats(response[1]);
105
  }
106
  }else{
107
  jQuery("#gadwp-widgetchart").css({"background-color":"#F7F7F7","height":"auto","padding-top":"50px","padding-bottom":"50px","color":"#000","text-align":"center"});
gadwp.php CHANGED
@@ -4,10 +4,10 @@
4
  * Plugin URI: https://deconf.com
5
  * Description: Displays Google Analytics Reports and Real-Time Statistics in your Dashboard. Automatically inserts the tracking code in every page of your website.
6
  * Author: Alin Marcu
7
- * Version: 4.4.4
8
  * Author URI: https://deconf.com
9
  */
10
- define('GADWP_CURRENT_VERSION', '4.4.4');
11
  /*
12
  * Include Install
13
  */
4
  * Plugin URI: https://deconf.com
5
  * Description: Displays Google Analytics Reports and Real-Time Statistics in your Dashboard. Automatically inserts the tracking code in every page of your website.
6
  * Author: Alin Marcu
7
+ * Version: 4.4.5
8
  * Author URI: https://deconf.com
9
  */
10
+ define('GADWP_CURRENT_VERSION', '4.4.5');
11
  /*
12
  * Include Install
13
  */
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: deconf
3
  Donate link: https://deconf.com/donate/
4
  Tags: google,analytics,google analytics,dashboard,analytics dashboard,google analytics dashboard,google analytics widget,tracking,realtime,wpmu,multisite
5
- Requires at least: 2.8
6
  Tested up to: 4.1
7
- Stable tag: 4.4.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -126,6 +126,14 @@ This plugin it's released under the GPLv2, you can use it free of charge on your
126
 
127
  == Changelog ==
128
 
 
 
 
 
 
 
 
 
129
  = 4.4.4 =
130
  - Bug Fix: end tag missing on error message
131
  - Bug Fix: additional checks before making a View list request
2
  Contributors: deconf
3
  Donate link: https://deconf.com/donate/
4
  Tags: google,analytics,google analytics,dashboard,analytics dashboard,google analytics dashboard,google analytics widget,tracking,realtime,wpmu,multisite
5
+ Requires at least: 3.0
6
  Tested up to: 4.1
7
+ Stable tag: 4.4.5
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
126
 
127
  == Changelog ==
128
 
129
+ = 4.4.5 =
130
+ - Enhancement: GAPI requests optimization
131
+ - Enhancement: server responses improvements
132
+ - Enhancement: filter data through query options
133
+ - Bugfix: additional checks before displaying an error
134
+ - Bugfix: wrong error displayed on IE
135
+ - Bugfix: set correct Content-Type before sending responses
136
+
137
  = 4.4.4 =
138
  - Bug Fix: end tag missing on error message
139
  - Bug Fix: additional checks before making a View list request
tools/gapi.php CHANGED
@@ -337,7 +337,7 @@ if (! class_exists('GADASH_GAPI')) {
337
  set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
338
  return $e->getCode();
339
  }
340
- if (isset($data['rows'])) {
341
  return $data;
342
  } else {
343
  return - 21;
@@ -355,7 +355,7 @@ if (! class_exists('GADASH_GAPI')) {
355
  * $to
356
  * @param
357
  * $query
358
- * @return string|int
359
  */
360
  function get_mainreport($projectId, $from, $to, $query)
361
  {
@@ -395,21 +395,28 @@ if (! class_exists('GADASH_GAPI')) {
395
  if (is_numeric($data)) {
396
  return $data;
397
  }
398
- $ga_dash_data = "";
 
 
 
 
 
399
  if ($from == "today" or $from == "yesterday") {
400
- for ($i = 0; $i < $data['totalResults']; $i ++) {
401
- $ga_dash_data .= '["' . (int) $data["rows"][$i][0] . ':00",' . round($data["rows"][$i][1], 2) . '],';
 
 
 
402
  }
403
  } else {
404
- for ($i = 0; $i < $data['totalResults']; $i ++) {
405
- $ga_dash_data .= '["' . esc_html(ucfirst(__($data["rows"][$i][1]))) . ", " . esc_html(substr_replace(substr_replace($data["rows"][$i][0], "-", 4, 0), "-", 7, 0)) . '",' . round($data["rows"][$i][2], 2) . '],';
 
 
 
406
  }
407
  }
408
- if ($ga_dash_data) {
409
- return '[["' . $dayorhour . '","' . $title . '"],' . rtrim($ga_dash_data, ',') . ']';
410
- } else {
411
- return - 22;
412
- }
413
  }
414
 
415
  /**
@@ -438,8 +445,10 @@ if (! class_exists('GADASH_GAPI')) {
438
  return $data;
439
  }
440
  }
441
- $ga_dash_data = $data['rows'][0];
442
- array_map('floatval', $ga_dash_data);
 
 
443
  return $ga_dash_data;
444
  }
445
 
@@ -452,7 +461,7 @@ if (! class_exists('GADASH_GAPI')) {
452
  * $from
453
  * @param
454
  * $to
455
- * @return string|int
456
  */
457
  function get_contentpages($projectId, $from, $to)
458
  {
@@ -467,17 +476,19 @@ if (! class_exists('GADASH_GAPI')) {
467
  if (is_numeric($data)) {
468
  return $data;
469
  }
470
- $ga_dash_data = "";
471
- $i = 0;
472
- while (isset($data['rows'][$i][0])) {
473
- $ga_dash_data .= '["' . $this->prepare_json($data['rows'][$i][0]) . '",' . (int) $data['rows'][$i][1] . '],';
474
- $i ++;
475
- }
476
- if ($ga_dash_data) {
477
- return '[["' . __("Pages", 'ga-dash') . '","' . __("Views", 'ga-dash') . '"],' . rtrim($ga_dash_data, ',') . ']';
478
- } else {
479
- return - 22;
 
480
  }
 
481
  }
482
 
483
  /**
@@ -489,7 +500,7 @@ if (! class_exists('GADASH_GAPI')) {
489
  * $from
490
  * @param
491
  * $to
492
- * @return string|int
493
  */
494
  function get_referrers($projectId, $from, $to)
495
  {
@@ -505,17 +516,19 @@ if (! class_exists('GADASH_GAPI')) {
505
  if (is_numeric($data)) {
506
  return $data;
507
  }
508
- $ga_dash_data = "";
509
- $i = 0;
510
- while (isset($data['rows'][$i][0])) {
511
- $ga_dash_data .= '["' . $this->prepare_json($data["rows"][$i][0]) . '",' . (int) $data["rows"][$i][1] . '],';
512
- $i ++;
513
- }
514
- if ($ga_dash_data) {
515
- return '[["' . __("Referrers", 'ga-dash') . '","' . __("Sessions", 'ga-dash') . '"],' . rtrim($ga_dash_data, ',') . ']';
516
- } else {
517
- return - 22;
 
518
  }
 
519
  }
520
 
521
  /**
@@ -527,7 +540,7 @@ if (! class_exists('GADASH_GAPI')) {
527
  * $from
528
  * @param
529
  * $to
530
- * @return string|int
531
  */
532
  function get_searches($projectId, $from, $to)
533
  {
@@ -537,24 +550,26 @@ if (! class_exists('GADASH_GAPI')) {
537
  $data = $this->handle_corereports($projectId, $from, $to, $metrics, array(
538
  'dimensions' => $dimensions,
539
  'sort' => '-ga:sessions',
 
540
  'quotaUser' => $this->managequota . 'p' . $projectId
541
  ), $serial);
542
  if (is_numeric($data)) {
543
  return $data;
544
  }
545
- $ga_dash_data = "";
546
- $i = 0;
547
- while (isset($data['rows'][$i][0])) {
548
- if ($data['rows'][$i][0] != "(not set)") {
549
- $ga_dash_data .= '["' . $this->prepare_json($data["rows"][$i][0]) . '",' . (int) $data["rows"][$i][1] . '],';
550
- }
551
- $i ++;
552
- }
553
- if ($ga_dash_data) {
554
- return '[["' . __("Searches", 'ga-dash') . '","' . __("Sessions", 'ga-dash') . '"],' . rtrim($ga_dash_data, ',') . ']';
555
- } else {
556
- return - 22;
557
  }
 
558
  }
559
 
560
  /**
@@ -566,7 +581,7 @@ if (! class_exists('GADASH_GAPI')) {
566
  * $from
567
  * @param
568
  * $to
569
- * @return string|int
570
  */
571
  function get_locations($projectId, $from, $to)
572
  {
@@ -601,21 +616,26 @@ if (! class_exists('GADASH_GAPI')) {
601
  if (is_numeric($data)) {
602
  return $data;
603
  }
604
- $ga_dash_data = "";
605
- $i = 0;
606
- while (isset($data['rows'][$i][1])) {
607
- if (isset($data['rows'][$i][2])) {
608
- $ga_dash_data .= '["' . $this->prepare_json($data["rows"][$i][0]) . ', ' . $this->prepare_json($data["rows"][$i][1]) . '",' . (int) $data["rows"][$i][2] . '],';
 
 
 
 
 
 
 
609
  } else {
610
- $ga_dash_data .= '["' . $this->prepare_json($data["rows"][$i][0]) . '",' . (int) $data["rows"][$i][1] . '],';
 
 
 
611
  }
612
- $i ++;
613
- }
614
- if ($ga_dash_data) {
615
- return '[["' . $title . '", "' . __("Sessions", 'ga-dash') . '"],' . rtrim($ga_dash_data, ',') . ']';
616
- } else {
617
- return - 22;
618
  }
 
619
  }
620
 
621
  /**
@@ -627,7 +647,7 @@ if (! class_exists('GADASH_GAPI')) {
627
  * $from
628
  * @param
629
  * $to
630
- * @return string|int
631
  */
632
  function get_trafficchannels($projectId, $from, $to)
633
  {
@@ -642,16 +662,20 @@ if (! class_exists('GADASH_GAPI')) {
642
  return $data;
643
  }
644
  $title = __("Channels", 'ga-dash');
645
- $ga_dash_data = "";
646
- for ($i = 0; $i < $data['totalResults']; $i ++) {
647
- $shrink = explode(" ", $data["rows"][$i][0]);
648
- $ga_dash_data .= '["' . '<div style=\\"color:black; font-size:1.1em\\">' . esc_html($shrink[0]) . '</div><div style=\\"color:darkblue; font-size:1.2em\\">' . (int) $data["rows"][$i][1] . '</div>","' . '<div style=\\"color:black; font-size:1.1em\\">' . $title . '</div><div style=\\"color:darkblue; font-size:1.2em\\">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>"],';
649
- }
650
- if ($ga_dash_data) {
651
- return '[["' . '<div style=\\"color:black; font-size:1.1em\\">' . $title . '</div><div style=\\"color:darkblue; font-size:1.2em\\">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>", ""],' . rtrim($ga_dash_data, ',') . ']';
652
- } else {
653
- return - 22;
 
 
 
654
  }
 
655
  }
656
 
657
  /**
@@ -665,7 +689,7 @@ if (! class_exists('GADASH_GAPI')) {
665
  * $to
666
  * @param
667
  * $query
668
- * @return string|int
669
  */
670
  function get_trafficdetails($projectId, $from, $to, $query)
671
  {
@@ -674,7 +698,7 @@ if (! class_exists('GADASH_GAPI')) {
674
  if ($query == 'source') {
675
  $options = array(
676
  'dimensions' => $dimensions,
677
- 'filters' => 'ga:medium==organic',
678
  'quotaUser' => $this->managequota . 'p' . $projectId
679
  );
680
  } else {
@@ -688,17 +712,19 @@ if (! class_exists('GADASH_GAPI')) {
688
  if (is_numeric($data)) {
689
  return $data;
690
  }
691
- $ga_dash_data = "";
692
- for ($i = 0; $i < $data['totalResults']; $i ++) {
693
- if ($data['rows'][$i][0] != '(not set)') {
694
- $ga_dash_data .= '["' . str_replace("(none)", "direct", esc_html($data['rows'][$i][0])) . '",' . (int) $data["rows"][$i][1] . '],';
695
- }
696
- }
697
- if ($ga_dash_data) {
698
- return '[["' . __("Type", 'ga-dash') . '", "Sessions"],' . rtrim($ga_dash_data, ',') . ']';
699
- } else {
700
- return - 22;
 
701
  }
 
702
  }
703
 
704
  /**
@@ -730,23 +756,30 @@ if (! class_exists('GADASH_GAPI')) {
730
  if (is_numeric($data)) {
731
  return $data;
732
  }
733
- $ga_dash_data = "";
734
- $max_array = array();
735
- foreach ($data['rows'] as $item) {
736
- $max_array[] = $item[2];
737
- }
738
- $max = max($max_array) ? max($max_array) : 1;
739
- for ($i = 0; $i < $data['totalResults']; $i ++) {
740
- $ga_dash_data .= '["' . ucfirst(esc_html((__($data["rows"][$i][1])))) . ", " . esc_html(substr_replace(substr_replace($data["rows"][$i][0], "-", 4, 0), "-", 7, 0)) . '",' . ($anonim ? str_replace(",", ".", round($data["rows"][$i][2] * 100 / $max, 2)) : (int) $data["rows"][$i][2]) . '],';
 
 
 
 
741
  }
742
- if ($ga_dash_data) {
743
- return array(
744
- '[["' . __("Date", 'ga-dash') . '", "' . __("Sessions", 'ga-dash') . ($anonim ? "' " . __("trend", 'ga-dash') : '') . '"],' . rtrim($ga_dash_data, ",") . "]",
745
- $anonim ? 0 : (int) $data['totalsForAllResults']['ga:sessions']
746
  );
747
- } else {
748
- return - 22;
749
  }
 
 
 
 
 
750
  }
751
 
752
  /**
@@ -758,7 +791,7 @@ if (! class_exists('GADASH_GAPI')) {
758
  * $page_url
759
  * @param
760
  * $post_id
761
- * @return string|int
762
  */
763
  function frontend_afterpost_pageviews($projectId, $page_url, $post_id)
764
  {
@@ -775,15 +808,21 @@ if (! class_exists('GADASH_GAPI')) {
775
  if (is_numeric($data)) {
776
  return $data;
777
  }
778
- $ga_dash_data = "";
779
- for ($i = 0; $i < $data['totalResults']; $i ++) {
780
- $ga_dash_data .= '["' . ucfirst(esc_html(__($data['rows'][$i][1]))) . ", " . esc_html(substr_replace(substr_replace($data['rows'][$i][0], "-", 4, 0), "-", 7, 0)) . '",' . round($data['rows'][$i][2], 2) . ',' . round($data['rows'][$i][3], 2) . '],';
781
- }
782
- if ($ga_dash_data) {
783
- return '[["' . __('Date', "ga-dash") . '", "' . __('Views', "ga-dash") . '", "' . __('UniqueViews', "ga-dash") . '"],' . rtrim($ga_dash_data, ',') . ']';
784
- } else {
785
- return - 22;
 
 
 
 
 
786
  }
 
787
  }
788
 
789
  /**
@@ -795,7 +834,7 @@ if (! class_exists('GADASH_GAPI')) {
795
  * $page_url
796
  * @param
797
  * $post_id
798
- * @return string|int
799
  */
800
  function frontend_afterpost_searches($projectId, $page_url, $post_id)
801
  {
@@ -807,25 +846,25 @@ if (! class_exists('GADASH_GAPI')) {
807
  $data = $this->handle_corereports($projectId, $from, $to, $metrics, array(
808
  'dimensions' => $dimensions,
809
  'sort' => '-ga:sessions',
810
- 'filters' => 'ga:pagePath==' . $page_url,
811
  'quotaUser' => $this->managequota . 'p' . $projectId
812
  ), $serial);
813
  if (is_numeric($data)) {
814
  return $data;
815
  }
816
- $ga_dash_data = "";
817
- $i = 0;
818
- while (isset($data['rows'][$i][0])) {
819
- if ($data['rows'][$i][0] != "(not set)") {
820
- $ga_dash_data .= '["' . $this->prepare_json($data['rows'][$i][0]) . '",' . (int) $data['rows'][$i][1] . '],';
821
- }
822
- $i ++;
823
- }
824
- if ($ga_dash_data) {
825
- return '[["' . __('Searches', "ga-dash") . '", "' . __('Sessions', "ga-dash") . '"],' . rtrim($ga_dash_data, ',') . ' ]';
826
- } else {
827
- return - 22;
828
  }
 
829
  }
830
 
831
  /**
@@ -833,7 +872,7 @@ if (! class_exists('GADASH_GAPI')) {
833
  *
834
  * @param
835
  * $projectId
836
- * @return string|int
837
  */
838
  function gadash_realtime_data($projectId)
839
  {
@@ -865,16 +904,16 @@ if (! class_exists('GADASH_GAPI')) {
865
  set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
866
  return $e->getCode();
867
  }
868
- if (! isset($data['rows'])) {
869
  return - 21;
870
  }
871
  $i = 0;
872
  $ga_dash_data = $data;
873
- while (isset($data->rows[$i])) {
874
- $ga_dash_data->rows[$i] = array_map('esc_html', $data->rows[$i]);
875
  $i ++;
876
  }
877
- return print_r(json_encode($ga_dash_data), true);
878
  }
879
 
880
  public function getcountrycodes()
337
  set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
338
  return $e->getCode();
339
  }
340
+ if ($data->getRows() > 0) {
341
  return $data;
342
  } else {
343
  return - 21;
355
  * $to
356
  * @param
357
  * $query
358
+ * @return array|int
359
  */
360
  function get_mainreport($projectId, $from, $to, $query)
361
  {
395
  if (is_numeric($data)) {
396
  return $data;
397
  }
398
+ $ga_dash_data = array(
399
+ array(
400
+ $dayorhour,
401
+ $title
402
+ )
403
+ );
404
  if ($from == "today" or $from == "yesterday") {
405
+ foreach ($data->getRows() as $row) {
406
+ $ga_dash_data[] = array(
407
+ (int) $row[0] . ':00',
408
+ round($row[1], 2)
409
+ );
410
  }
411
  } else {
412
+ foreach ($data->getRows() as $row) {
413
+ $ga_dash_data[] = array(
414
+ esc_html(ucfirst(__($row[1]))) . ',' . esc_html(substr_replace(substr_replace($row[0], "-", 4, 0), "-", 7, 0)),
415
+ round($row[2], 2)
416
+ );
417
  }
418
  }
419
+ return $ga_dash_data;
 
 
 
 
420
  }
421
 
422
  /**
445
  return $data;
446
  }
447
  }
448
+ $ga_dash_data = array();
449
+ foreach ($data->getRows() as $row) {
450
+ $ga_dash_data = array_map('floatval', $row);
451
+ }
452
  return $ga_dash_data;
453
  }
454
 
461
  * $from
462
  * @param
463
  * $to
464
+ * @return array|int
465
  */
466
  function get_contentpages($projectId, $from, $to)
467
  {
476
  if (is_numeric($data)) {
477
  return $data;
478
  }
479
+ $ga_dash_data = array(
480
+ array(
481
+ __("Pages", 'ga-dash'),
482
+ __("Views", 'ga-dash')
483
+ )
484
+ );
485
+ foreach ($data->getRows() as $row) {
486
+ $ga_dash_data[] = array(
487
+ $this->prepare_json($row[0]),
488
+ (int) $row[1]
489
+ );
490
  }
491
+ return $ga_dash_data;
492
  }
493
 
494
  /**
500
  * $from
501
  * @param
502
  * $to
503
+ * @return array|int
504
  */
505
  function get_referrers($projectId, $from, $to)
506
  {
516
  if (is_numeric($data)) {
517
  return $data;
518
  }
519
+ $ga_dash_data = array(
520
+ array(
521
+ __("Referrers", 'ga-dash'),
522
+ __("Sessions", 'ga-dash')
523
+ )
524
+ );
525
+ foreach ($data->getRows() as $row) {
526
+ $ga_dash_data[] = array(
527
+ $this->prepare_json($row[0]),
528
+ (int) $row[1]
529
+ );
530
  }
531
+ return $ga_dash_data;
532
  }
533
 
534
  /**
540
  * $from
541
  * @param
542
  * $to
543
+ * @return array|int
544
  */
545
  function get_searches($projectId, $from, $to)
546
  {
550
  $data = $this->handle_corereports($projectId, $from, $to, $metrics, array(
551
  'dimensions' => $dimensions,
552
  'sort' => '-ga:sessions',
553
+ 'filters' => 'ga:keyword!=(not set)',
554
  'quotaUser' => $this->managequota . 'p' . $projectId
555
  ), $serial);
556
  if (is_numeric($data)) {
557
  return $data;
558
  }
559
+
560
+ $ga_dash_data = array(
561
+ array(
562
+ __("Searches", 'ga-dash'),
563
+ __("Sessions", 'ga-dash')
564
+ )
565
+ );
566
+ foreach ($data->getRows() as $row) {
567
+ $ga_dash_data[] = array(
568
+ $this->prepare_json($row[0]),
569
+ (int) $row[1]
570
+ );
571
  }
572
+ return $ga_dash_data;
573
  }
574
 
575
  /**
581
  * $from
582
  * @param
583
  * $to
584
+ * @return array|int
585
  */
586
  function get_locations($projectId, $from, $to)
587
  {
616
  if (is_numeric($data)) {
617
  return $data;
618
  }
619
+ $ga_dash_data = array(
620
+ array(
621
+ $title,
622
+ __("Sessions", 'ga-dash')
623
+ )
624
+ );
625
+ foreach ($data->getRows() as $row) {
626
+ if (isset($row[2])) {
627
+ $ga_dash_data[] = array(
628
+ $this->prepare_json($row[0]) . ', ' . $this->prepare_json($row[1]),
629
+ (int) $row[2]
630
+ );
631
  } else {
632
+ $ga_dash_data[] = array(
633
+ $this->prepare_json($row[0]),
634
+ (int) $row[1]
635
+ );
636
  }
 
 
 
 
 
 
637
  }
638
+ return $ga_dash_data;
639
  }
640
 
641
  /**
647
  * $from
648
  * @param
649
  * $to
650
+ * @return array|int
651
  */
652
  function get_trafficchannels($projectId, $from, $to)
653
  {
662
  return $data;
663
  }
664
  $title = __("Channels", 'ga-dash');
665
+ $ga_dash_data = array(
666
+ array(
667
+ '<div style=\\"color:black; font-size:1.1em\\">' . $title . '</div><div style=\\"color:darkblue; font-size:1.2em\\">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>',
668
+ ""
669
+ )
670
+ );
671
+ foreach ($data->getRows() as $row) {
672
+ $shrink = explode(" ", $row[0]);
673
+ $ga_dash_data[] = array(
674
+ '<div style=\\"color:black; font-size:1.1em\\">' . esc_html($shrink[0]) . '</div><div style=\\"color:darkblue; font-size:1.2em\\">' . (int) $row[1] . '</div>',
675
+ '<div style=\\"color:black; font-size:1.1em\\">' . $title . '</div><div style=\\"color:darkblue; font-size:1.2em\\">' . (int) $data['totalsForAllResults']["ga:sessions"] . '</div>'
676
+ );
677
  }
678
+ return $ga_dash_data;
679
  }
680
 
681
  /**
689
  * $to
690
  * @param
691
  * $query
692
+ * @return array|int
693
  */
694
  function get_trafficdetails($projectId, $from, $to, $query)
695
  {
698
  if ($query == 'source') {
699
  $options = array(
700
  'dimensions' => $dimensions,
701
+ 'filters' => 'ga:medium==organic;ga:keyword!=(not set)',
702
  'quotaUser' => $this->managequota . 'p' . $projectId
703
  );
704
  } else {
712
  if (is_numeric($data)) {
713
  return $data;
714
  }
715
+ $ga_dash_data = array(
716
+ array(
717
+ __("Type", 'ga-dash'),
718
+ __("Sessions", 'ga-dash')
719
+ )
720
+ );
721
+ foreach ($data->getRows() as $row) {
722
+ $ga_dash_data[] = array(
723
+ str_replace("(none)", "direct", esc_html($row[0])),
724
+ (int) $row[1]
725
+ );
726
  }
727
+ return $ga_dash_data;
728
  }
729
 
730
  /**
756
  if (is_numeric($data)) {
757
  return $data;
758
  }
759
+ $ga_dash_data = array(
760
+ array(
761
+ __("Date", 'ga-dash'),
762
+ __("Sessions", 'ga-dash') . ($anonim ? "' " . __("trend", 'ga-dash') : '')
763
+ )
764
+ );
765
+ if ($anonim) {
766
+ $max_array = array();
767
+ foreach ($data->getRows() as $item) {
768
+ $max_array[] = $item[2];
769
+ }
770
+ $max = max($max_array) ? max($max_array) : 1;
771
  }
772
+ foreach ($data->getRows() as $row) {
773
+ $ga_dash_data[] = array(
774
+ ucfirst(esc_html((__($row[1])))) . ', ' . esc_html(substr_replace(substr_replace($row[0], "-", 4, 0), "-", 7, 0)),
775
+ ($anonim ? str_replace(",", ".", round($row[2] * 100 / $max, 2)) : (int) $row[2])
776
  );
 
 
777
  }
778
+ $totals = $data->getTotalsForAllResults();
779
+ return array(
780
+ $ga_dash_data,
781
+ $anonim ? 0 : $totals['ga:sessions']
782
+ );
783
  }
784
 
785
  /**
791
  * $page_url
792
  * @param
793
  * $post_id
794
+ * @return array|int
795
  */
796
  function frontend_afterpost_pageviews($projectId, $page_url, $post_id)
797
  {
808
  if (is_numeric($data)) {
809
  return $data;
810
  }
811
+ $ga_dash_data = array(
812
+ array(
813
+ __("Date", 'ga-dash'),
814
+ __("Views", 'ga-dash'),
815
+ __('UniqueViews', "ga-dash")
816
+ )
817
+ );
818
+ foreach ($data->getRows() as $row) {
819
+ $ga_dash_data[] = array(
820
+ ucfirst(esc_html(__($row[1]))) . ',' . esc_html(substr_replace(substr_replace($row[0], "-", 4, 0), "-", 7, 0)),
821
+ round($row[2], 2),
822
+ round($row[3], 2)
823
+ );
824
  }
825
+ return $ga_dash_data;
826
  }
827
 
828
  /**
834
  * $page_url
835
  * @param
836
  * $post_id
837
+ * @return array|int
838
  */
839
  function frontend_afterpost_searches($projectId, $page_url, $post_id)
840
  {
846
  $data = $this->handle_corereports($projectId, $from, $to, $metrics, array(
847
  'dimensions' => $dimensions,
848
  'sort' => '-ga:sessions',
849
+ 'filters' => 'ga:pagePath==' . $page_url . ';ga:keyword!=(not set)',
850
  'quotaUser' => $this->managequota . 'p' . $projectId
851
  ), $serial);
852
  if (is_numeric($data)) {
853
  return $data;
854
  }
855
+ $ga_dash_data = array(
856
+ array(
857
+ __("Searches", 'ga-dash'),
858
+ __("Sessions", 'ga-dash')
859
+ )
860
+ );
861
+ foreach ($data->getRows() as $row) {
862
+ $ga_dash_data[] = array(
863
+ $this->prepare_json($row[0]),
864
+ (int) $row[1]
865
+ );
 
866
  }
867
+ return $ga_dash_data;
868
  }
869
 
870
  /**
872
  *
873
  * @param
874
  * $projectId
875
+ * @return array|int
876
  */
877
  function gadash_realtime_data($projectId)
878
  {
904
  set_transient('ga_dash_lasterror', date('Y-m-d H:i:s') . ': ' . esc_html($e), $this->error_timeout);
905
  return $e->getCode();
906
  }
907
+ if ($data->getRows() < 1) {
908
  return - 21;
909
  }
910
  $i = 0;
911
  $ga_dash_data = $data;
912
+ foreach ($data->getRows() as $row) {
913
+ $ga_dash_data->rows[$i] = array_map('esc_html', $row);
914
  $i ++;
915
  }
916
+ return $ga_dash_data;
917
  }
918
 
919
  public function getcountrycodes()