Google Analytics - Version 2.5.3

Version Description

Download this release

Release Info

Developer ShareThis
Plugin Icon wp plugin Google Analytics
Version 2.5.3
Comparing to
See all releases

Code changes from version 2.5.2 to 2.5.3

assets/images/demo-ad.png DELETED
Binary file
assets/images/demo-ex.png DELETED
Binary file
class/Ga_Admin.php CHANGED
@@ -829,14 +829,14 @@ class Ga_Admin {
829
  );
830
  $sources = ! empty( $sources_data ) ? Ga_Stats::get_sources( $sources_data->getData() ) : array();
831
 
832
- // Add gender/age data for 30 days.
833
  if ($update_data) {
834
- $gender_params = Ga_Stats::get_query( 'gender', $selected['view_id'], '30daysAgo' );
835
  $gender_data = self::api_client()->call(
836
  'ga_api_data',
837
  [$gender_params]
838
  );
839
- $age_params = Ga_Stats::get_query( 'age', $selected['view_id'], '30daysAgo' );
840
  $age_data = self::api_client()->call(
841
  'ga_api_data',
842
  [$age_params]
829
  );
830
  $sources = ! empty( $sources_data ) ? Ga_Stats::get_sources( $sources_data->getData() ) : array();
831
 
832
+ // Add gender/age data for default period (1 week ago vs 2 weeks ago).
833
  if ($update_data) {
834
+ $gender_params = Ga_Stats::get_query( 'gender', $selected['view_id'] );
835
  $gender_data = self::api_client()->call(
836
  'ga_api_data',
837
  [$gender_params]
838
  );
839
+ $age_params = Ga_Stats::get_query( 'age', $selected['view_id'] );
840
  $age_data = self::api_client()->call(
841
  'ga_api_data',
842
  [$age_params]
class/Ga_Autoloader.php CHANGED
@@ -1,56 +1,56 @@
1
- <?php
2
-
3
- class Ga_Autoloader {
4
-
5
- /**
6
- * Registers clas loader.
7
- */
8
- public static function register() {
9
- spl_autoload_register( 'Ga_Autoloader::loader' );
10
- }
11
-
12
- /**
13
- * Class loader.
14
- *
15
- * @param $class_name
16
- */
17
- private static function loader( $class_name ) {
18
-
19
- // Core classes
20
- if ( preg_match( '/_Core/', $class_name ) ) {
21
- $file_name = GA_PLUGIN_DIR . '/class/core/' . $class_name . '.php';
22
- if ( file_exists( $file_name ) ) {
23
- require $file_name;
24
- }
25
- }
26
-
27
- // Controllers
28
- if ( preg_match( '/_Controller/', $class_name ) ) {
29
- $file_name = GA_PLUGIN_DIR . '/class/controller/' . $class_name . '.php';
30
- if ( file_exists( $file_name ) ) {
31
- require $file_name;
32
- }
33
- }
34
-
35
- // classes
36
- $file_name = GA_PLUGIN_DIR . '/class/' . $class_name . '.php';
37
- if ( file_exists( $file_name ) ) {
38
- require $file_name;
39
- }
40
-
41
- // tools
42
- $file_name_tools = GA_PLUGIN_DIR . '/tools/' . $class_name . '.php';
43
- if ( file_exists( $file_name_tools ) ) {
44
- require $file_name_tools;
45
- }
46
-
47
- // Libs
48
- if ( preg_match( '/Ga_Lib/', $class_name ) ) {
49
- $file_name = GA_PLUGIN_DIR . '/lib/' . $class_name . '.php';
50
- if ( file_exists( $file_name ) ) {
51
- require $file_name;
52
- }
53
- }
54
- }
55
-
56
- }
1
+ <?php
2
+
3
+ class Ga_Autoloader {
4
+
5
+ /**
6
+ * Registers clas loader.
7
+ */
8
+ public static function register() {
9
+ spl_autoload_register( 'Ga_Autoloader::loader' );
10
+ }
11
+
12
+ /**
13
+ * Class loader.
14
+ *
15
+ * @param $class_name
16
+ */
17
+ private static function loader( $class_name ) {
18
+
19
+ // Core classes
20
+ if ( preg_match( '/_Core/', $class_name ) ) {
21
+ $file_name = GA_PLUGIN_DIR . '/class/core/' . $class_name . '.php';
22
+ if ( file_exists( $file_name ) ) {
23
+ require $file_name;
24
+ }
25
+ }
26
+
27
+ // Controllers
28
+ if ( preg_match( '/_Controller/', $class_name ) ) {
29
+ $file_name = GA_PLUGIN_DIR . '/class/controller/' . $class_name . '.php';
30
+ if ( file_exists( $file_name ) ) {
31
+ require $file_name;
32
+ }
33
+ }
34
+
35
+ // classes
36
+ $file_name = GA_PLUGIN_DIR . '/class/' . $class_name . '.php';
37
+ if ( file_exists( $file_name ) ) {
38
+ require $file_name;
39
+ }
40
+
41
+ // tools
42
+ $file_name_tools = GA_PLUGIN_DIR . '/tools/' . $class_name . '.php';
43
+ if ( file_exists( $file_name_tools ) ) {
44
+ require $file_name_tools;
45
+ }
46
+
47
+ // Libs
48
+ if ( preg_match( '/Ga_Lib/', $class_name ) ) {
49
+ $file_name = GA_PLUGIN_DIR . '/lib/' . $class_name . '.php';
50
+ if ( file_exists( $file_name ) ) {
51
+ require $file_name;
52
+ }
53
+ }
54
+ }
55
+
56
+ }
class/Ga_Hook.php CHANGED
@@ -1,16 +1,16 @@
1
- <?php
2
-
3
- class Ga_Hook {
4
-
5
- /**
6
- * Adds WordPress hooks.
7
- *
8
- * @param string $plugin_file_path
9
- */
10
- public static function add_hooks( $plugin_file_path ) {
11
- register_activation_hook( $plugin_file_path, 'Ga_Admin::activate_googleanalytics' );
12
- register_deactivation_hook( $plugin_file_path, 'Ga_Admin::deactivate_googleanalytics' );
13
- register_uninstall_hook( $plugin_file_path, 'Ga_Admin::uninstall_googleanalytics' );
14
- }
15
-
16
- }
1
+ <?php
2
+
3
+ class Ga_Hook {
4
+
5
+ /**
6
+ * Adds WordPress hooks.
7
+ *
8
+ * @param string $plugin_file_path
9
+ */
10
+ public static function add_hooks( $plugin_file_path ) {
11
+ register_activation_hook( $plugin_file_path, 'Ga_Admin::activate_googleanalytics' );
12
+ register_deactivation_hook( $plugin_file_path, 'Ga_Admin::deactivate_googleanalytics' );
13
+ register_uninstall_hook( $plugin_file_path, 'Ga_Admin::uninstall_googleanalytics' );
14
+ }
15
+
16
+ }
class/Ga_Stats.php CHANGED
@@ -215,6 +215,10 @@ class Ga_Stats {
215
  * @return array Chart query
216
  */
217
  public static function gender_chart_query( $id_view, $date_ranges = null, $metric = null ) {
 
 
 
 
218
  $reports_requests = array();
219
  $reports_requests[] = array(
220
  'viewId' => $id_view,
@@ -264,6 +268,10 @@ class Ga_Stats {
264
  * @return array Chart query
265
  */
266
  public static function age_chart_query( $id_view, $date_ranges = null, $metric = null ) {
 
 
 
 
267
  $reports_requests = array();
268
  $reports_requests[] = array(
269
  'viewId' => $id_view,
215
  * @return array Chart query
216
  */
217
  public static function gender_chart_query( $id_view, $date_ranges = null, $metric = null ) {
218
+ if ( true === empty( $date_ranges ) ) {
219
+ $date_ranges = self::set_date_ranges( '7daysAgo', 'yesterday', '14daysAgo', '8daysAgo' );
220
+ }
221
+
222
  $reports_requests = array();
223
  $reports_requests[] = array(
224
  'viewId' => $id_view,
268
  * @return array Chart query
269
  */
270
  public static function age_chart_query( $id_view, $date_ranges = null, $metric = null ) {
271
+ if ( true === empty( $date_ranges ) ) {
272
+ $date_ranges = self::set_date_ranges( '7daysAgo', 'yesterday', '14daysAgo', '8daysAgo' );
273
+ }
274
+
275
  $reports_requests = array();
276
  $reports_requests[] = array(
277
  'viewId' => $id_view,
googleanalytics.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: ShareThis Dashboard for Google Analytics
4
  * Plugin URI: http://wordpress.org/extend/plugins/googleanalytics/
5
  * Description: Use Google Analytics on your WordPress site without touching any code, and view visitor reports right in your WordPress admin dashboard!
6
- * Version: 2.5.2
7
  * Author: ShareThis
8
  * Author URI: http://sharethis.com
9
  */
@@ -46,7 +46,7 @@ if ( !preg_match( '/(\/|\\\)' . GA_NAME . '(\/|\\\)/', realpath( __FILE__ ), $te
46
  die();
47
  }
48
 
49
- define( 'GOOGLEANALYTICS_VERSION', '2.5.2' );
50
  include_once GA_PLUGIN_DIR . '/overwrite/ga_overwrite.php';
51
  include_once GA_PLUGIN_DIR . '/class/Ga_Autoloader.php';
52
  include_once GA_PLUGIN_DIR . '/tools/class-support-logging.php';
3
  * Plugin Name: ShareThis Dashboard for Google Analytics
4
  * Plugin URI: http://wordpress.org/extend/plugins/googleanalytics/
5
  * Description: Use Google Analytics on your WordPress site without touching any code, and view visitor reports right in your WordPress admin dashboard!
6
+ * Version: 2.5.3
7
  * Author: ShareThis
8
  * Author URI: http://sharethis.com
9
  */
46
  die();
47
  }
48
 
49
+ define( 'GOOGLEANALYTICS_VERSION', '2.5.3' );
50
  include_once GA_PLUGIN_DIR . '/overwrite/ga_overwrite.php';
51
  include_once GA_PLUGIN_DIR . '/class/Ga_Autoloader.php';
52
  include_once GA_PLUGIN_DIR . '/tools/class-support-logging.php';
js/googleanalytics_dashboard.js CHANGED
@@ -1,207 +1,207 @@
1
- (function ($) {
2
-
3
- const wrapperSelector = '#ga_dashboard_widget';
4
- const minWidth = 350;
5
- const offset = 10;
6
-
7
- ga_dashboard = {
8
- chartData: [],
9
- init: function (dataArr, showLoader) {
10
- if (showLoader) {
11
- ga_loader.show();
12
- }
13
- google.charts.load('current', {'packages': ['corechart']});
14
- google.charts.setOnLoadCallback(function () {
15
- if (dataArr) {
16
- ga_dashboard.drawChart(dataArr);
17
- ga_dashboard.setChartData(dataArr);
18
- }
19
- });
20
- },
21
- events: function (data) {
22
- $(document).ready(function () {
23
- $('#range-selector').on('change', function () {
24
- const selected = $(this).val();
25
- const selected_name = $('#metrics-selector option:selected').html();
26
- const selected_metric = $('#metrics-selector option:selected').val() || null;
27
-
28
- ga_loader.show();
29
-
30
- var dataObj = {};
31
- dataObj['action'] = "ga_ajax_data_change";
32
- dataObj['date_range'] = selected;
33
- dataObj['metric'] = selected_metric;
34
- dataObj[GA_NONCE_FIELD] = GA_NONCE;
35
-
36
- $.ajax({
37
- type: "post",
38
- dataType: "json",
39
- url: ajaxurl,
40
- data: dataObj,
41
- success: function (response) {
42
-
43
- ga_loader.hide();
44
-
45
- if (typeof response.error !== "undefined") {
46
- $('#ga_widget_error').show().html(response.error);
47
- } else {
48
- var dataT = [['Day', selected_name]];
49
- $.each(response.chart, function (k, v) {
50
- dataT.push([v.day, parseInt(v.current)]);
51
- });
52
-
53
- $.each(response.boxes, function (k, v) {
54
- $('#ga_box_dashboard_label_' + k).html(v.label)
55
- $('#ga_box_dashboard_value_' + k).html(v.value);
56
- });
57
-
58
- ga_dashboard.drawChart(dataT, selected_name);
59
-
60
- // Set new data
61
- ga_dashboard.setChartData(dataT);
62
- }
63
- }
64
- });
65
- });
66
-
67
- $('#metrics-selector').on('change', function () {
68
- const selected = $(this).val();
69
- const selected_name = $('#metrics-selector option:selected').html();
70
- const selected_range = $('#range-selector option:selected').val() || null;
71
-
72
- ga_loader.show();
73
-
74
- var dataObj = {};
75
- dataObj['action'] = "ga_ajax_data_change";
76
- dataObj['metric'] = selected;
77
- dataObj['date_range'] = selected_range;
78
- dataObj[GA_NONCE_FIELD] = GA_NONCE;
79
-
80
- $.ajax({
81
- type: "post",
82
- dataType: "json",
83
- url: ajaxurl,
84
- data: dataObj,
85
- success: function (response) {
86
- ga_loader.hide();
87
-
88
- if (typeof response.error !== "undefined") {
89
- $('#ga_widget_error').show().html(response.error);
90
- } else {
91
- var dataT = [['Day', selected_name]];
92
- $.each(response.chart, function (k, v) {
93
- dataT.push([v.day, parseInt(v.current)]);
94
- });
95
-
96
- ga_dashboard.drawChart(dataT, selected_name);
97
-
98
- // Set new data
99
- ga_dashboard.setChartData(dataT);
100
- }
101
- }
102
- });
103
- });
104
-
105
- $('#ga-widget-trigger').on('click', function () {
106
- const selected_name = $('#metrics-selector option:selected').html();
107
- const selected_metric = $('#metrics-selector option:selected').val() || null;
108
- const selected_range = $('#range-selector option:selected').val() || null;
109
-
110
- ga_loader.show();
111
-
112
- var dataObj = {};
113
- dataObj['action'] = "ga_ajax_data_change";
114
- dataObj['metric'] = selected_metric;
115
- dataObj['date_range'] = selected_range;
116
- dataObj[GA_NONCE_FIELD] = GA_NONCE;
117
-
118
- $.ajax({
119
- type: "post",
120
- dataType: "json",
121
- url: ajaxurl,
122
- data: dataObj,
123
- success: function (response) {
124
-
125
- ga_loader.hide();
126
-
127
- if (typeof response.error !== "undefined") {
128
- $('#ga_widget_error').show().html(response.error);
129
- } else {
130
- var dataT = [['Day', selected_name]];
131
- $.each(response.chart, function (k, v) {
132
- dataT.push([v.day, parseInt(v.current)]);
133
- });
134
-
135
- $.each(response.boxes, function (k, v) {
136
- $('#ga_box_dashboard_label_' + k).html(v.label)
137
- $('#ga_box_dashboard_value_' + k).html(v.value);
138
- });
139
-
140
- ga_dashboard.drawChart(dataT, selected_name);
141
-
142
- // Set new data
143
- ga_dashboard.setChartData(dataT);
144
- }
145
- }
146
- });
147
- });
148
-
149
- $(window).on('resize', function () {
150
- ga_dashboard.drawChart(ga_dashboard.getChartData(), ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector));
151
- });
152
- });
153
- },
154
- /**
155
- * Returns chart data array.
156
- * @returns {Array}
157
- */
158
- getChartData: function () {
159
- return ga_dashboard.chartData;
160
- },
161
- /**
162
- * Overwrites initial data array.
163
- * @param new_data
164
- */
165
- setChartData: function (new_data) {
166
- ga_dashboard.chartData = new_data;
167
- },
168
- drawChart: function (dataArr, title) {
169
- const chart_dom_element = document.getElementById('chart_div');
170
-
171
- if (typeof title == 'undefined') {
172
- title = 'Pageviews';
173
- }
174
-
175
- if (dataArr.length > 1) {
176
- const data = google.visualization.arrayToDataTable(dataArr);
177
-
178
- const options = {
179
- /*title: title,*/
180
- legend: 'top',
181
- lineWidth: 2,
182
- chartArea: {
183
- left: 10,
184
- top: 60,
185
- bottom: 50,
186
- right: 10
187
-
188
- },
189
- width: '95%',
190
- height: 300,
191
- hAxis: {title: 'Day', titleTextStyle: {color: '#333'}, direction: 1},
192
- vAxis: {minValue: 0},
193
- pointSize: 5
194
- };
195
-
196
- var chart = new google.visualization.AreaChart(chart_dom_element);
197
- google.visualization.events.addListener(chart, 'ready', function () {
198
- ga_loader.hide();
199
- });
200
- chart.draw(data, options);
201
- } else {
202
- $('#ga_widget_error').show().html('No data available for selected range.');
203
- }
204
- }
205
- };
206
-
207
- })(jQuery);
1
+ (function ($) {
2
+
3
+ const wrapperSelector = '#ga_dashboard_widget';
4
+ const minWidth = 350;
5
+ const offset = 10;
6
+
7
+ ga_dashboard = {
8
+ chartData: [],
9
+ init: function (dataArr, showLoader) {
10
+ if (showLoader) {
11
+ ga_loader.show();
12
+ }
13
+ google.charts.load('current', {'packages': ['corechart']});
14
+ google.charts.setOnLoadCallback(function () {
15
+ if (dataArr) {
16
+ ga_dashboard.drawChart(dataArr);
17
+ ga_dashboard.setChartData(dataArr);
18
+ }
19
+ });
20
+ },
21
+ events: function (data) {
22
+ $(document).ready(function () {
23
+ $('#range-selector').on('change', function () {
24
+ const selected = $(this).val();
25
+ const selected_name = $('#metrics-selector option:selected').html();
26
+ const selected_metric = $('#metrics-selector option:selected').val() || null;
27
+
28
+ ga_loader.show();
29
+
30
+ var dataObj = {};
31
+ dataObj['action'] = "ga_ajax_data_change";
32
+ dataObj['date_range'] = selected;
33
+ dataObj['metric'] = selected_metric;
34
+ dataObj[GA_NONCE_FIELD] = GA_NONCE;
35
+
36
+ $.ajax({
37
+ type: "post",
38
+ dataType: "json",
39
+ url: ajaxurl,
40
+ data: dataObj,
41
+ success: function (response) {
42
+
43
+ ga_loader.hide();
44
+
45
+ if (typeof response.error !== "undefined") {
46
+ $('#ga_widget_error').show().html(response.error);
47
+ } else {
48
+ var dataT = [['Day', selected_name]];
49
+ $.each(response.chart, function (k, v) {
50
+ dataT.push([v.day, parseInt(v.current)]);
51
+ });
52
+
53
+ $.each(response.boxes, function (k, v) {
54
+ $('#ga_box_dashboard_label_' + k).html(v.label)
55
+ $('#ga_box_dashboard_value_' + k).html(v.value);
56
+ });
57
+
58
+ ga_dashboard.drawChart(dataT, selected_name);
59
+
60
+ // Set new data
61
+ ga_dashboard.setChartData(dataT);
62
+ }
63
+ }
64
+ });
65
+ });
66
+
67
+ $('#metrics-selector').on('change', function () {
68
+ const selected = $(this).val();
69
+ const selected_name = $('#metrics-selector option:selected').html();
70
+ const selected_range = $('#range-selector option:selected').val() || null;
71
+
72
+ ga_loader.show();
73
+
74
+ var dataObj = {};
75
+ dataObj['action'] = "ga_ajax_data_change";
76
+ dataObj['metric'] = selected;
77
+ dataObj['date_range'] = selected_range;
78
+ dataObj[GA_NONCE_FIELD] = GA_NONCE;
79
+
80
+ $.ajax({
81
+ type: "post",
82
+ dataType: "json",
83
+ url: ajaxurl,
84
+ data: dataObj,
85
+ success: function (response) {
86
+ ga_loader.hide();
87
+
88
+ if (typeof response.error !== "undefined") {
89
+ $('#ga_widget_error').show().html(response.error);
90
+ } else {
91
+ var dataT = [['Day', selected_name]];
92
+ $.each(response.chart, function (k, v) {
93
+ dataT.push([v.day, parseInt(v.current)]);
94
+ });
95
+
96
+ ga_dashboard.drawChart(dataT, selected_name);
97
+
98
+ // Set new data
99
+ ga_dashboard.setChartData(dataT);
100
+ }
101
+ }
102
+ });
103
+ });
104
+
105
+ $('#ga-widget-trigger').on('click', function () {
106
+ const selected_name = $('#metrics-selector option:selected').html();
107
+ const selected_metric = $('#metrics-selector option:selected').val() || null;
108
+ const selected_range = $('#range-selector option:selected').val() || null;
109
+
110
+ ga_loader.show();
111
+
112
+ var dataObj = {};
113
+ dataObj['action'] = "ga_ajax_data_change";
114
+ dataObj['metric'] = selected_metric;
115
+ dataObj['date_range'] = selected_range;
116
+ dataObj[GA_NONCE_FIELD] = GA_NONCE;
117
+
118
+ $.ajax({
119
+ type: "post",
120
+ dataType: "json",
121
+ url: ajaxurl,
122
+ data: dataObj,
123
+ success: function (response) {
124
+
125
+ ga_loader.hide();
126
+
127
+ if (typeof response.error !== "undefined") {
128
+ $('#ga_widget_error').show().html(response.error);
129
+ } else {
130
+ var dataT = [['Day', selected_name]];
131
+ $.each(response.chart, function (k, v) {
132
+ dataT.push([v.day, parseInt(v.current)]);
133
+ });
134
+
135
+ $.each(response.boxes, function (k, v) {
136
+ $('#ga_box_dashboard_label_' + k).html(v.label)
137
+ $('#ga_box_dashboard_value_' + k).html(v.value);
138
+ });
139
+
140
+ ga_dashboard.drawChart(dataT, selected_name);
141
+
142
+ // Set new data
143
+ ga_dashboard.setChartData(dataT);
144
+ }
145
+ }
146
+ });
147
+ });
148
+
149
+ $(window).on('resize', function () {
150
+ ga_dashboard.drawChart(ga_dashboard.getChartData(), ga_tools.recomputeChartWidth(minWidth, offset, wrapperSelector));
151
+ });
152
+ });
153
+ },
154
+ /**
155
+ * Returns chart data array.
156
+ * @returns {Array}
157
+ */
158
+ getChartData: function () {
159
+ return ga_dashboard.chartData;
160
+ },
161
+ /**
162
+ * Overwrites initial data array.
163
+ * @param new_data
164
+ */
165
+ setChartData: function (new_data) {
166
+ ga_dashboard.chartData = new_data;
167
+ },
168
+ drawChart: function (dataArr, title) {
169
+ const chart_dom_element = document.getElementById('chart_div');
170
+
171
+ if (typeof title == 'undefined') {
172
+ title = 'Pageviews';
173
+ }
174
+
175
+ if (dataArr.length > 1) {
176
+ const data = google.visualization.arrayToDataTable(dataArr);
177
+
178
+ const options = {
179
+ /*title: title,*/
180
+ legend: 'top',
181
+ lineWidth: 2,
182
+ chartArea: {
183
+ left: 10,
184
+ top: 60,
185
+ bottom: 50,
186
+ right: 10
187
+
188
+ },
189
+ width: '95%',
190
+ height: 300,
191
+ hAxis: {title: 'Day', titleTextStyle: {color: '#333'}, direction: 1},
192
+ vAxis: {minValue: 0},
193
+ pointSize: 5
194
+ };
195
+
196
+ var chart = new google.visualization.AreaChart(chart_dom_element);
197
+ google.visualization.events.addListener(chart, 'ready', function () {
198
+ ga_loader.hide();
199
+ });
200
+ chart.draw(data, options);
201
+ } else {
202
+ $('#ga_widget_error').show().html('No data available for selected range.');
203
+ }
204
+ }
205
+ };
206
+
207
+ })(jQuery);
lib/Ga_Lib_Api_Response.php CHANGED
@@ -1,42 +1,42 @@
1
- <?php
2
-
3
- class Ga_Lib_Api_Response {
4
-
5
- public static $empty_response = array( '', '' );
6
- private $header;
7
- private $body;
8
- private $data;
9
-
10
- function __construct( $raw_response = null ) {
11
- if (!empty($raw_response)) {
12
- $this->setHeader( $raw_response[ 0 ] );
13
- $this->setBody( $raw_response[ 1 ] );
14
- $this->setData( json_decode( $raw_response[ 1 ], true ) );
15
- }
16
- }
17
-
18
- public function setHeader( $header ) {
19
- $this->header = $header;
20
- }
21
-
22
- public function getHeader() {
23
- return $this->header;
24
- }
25
-
26
- public function setBody( $body ) {
27
- $this->body = $body;
28
- }
29
-
30
- public function getBody() {
31
- return $this->body;
32
- }
33
-
34
- public function setData( $data ) {
35
- $this->data = $data;
36
- }
37
-
38
- public function getData() {
39
- return $this->data;
40
- }
41
-
42
- }
1
+ <?php
2
+
3
+ class Ga_Lib_Api_Response {
4
+
5
+ public static $empty_response = array( '', '' );
6
+ private $header;
7
+ private $body;
8
+ private $data;
9
+
10
+ function __construct( $raw_response = null ) {
11
+ if (!empty($raw_response)) {
12
+ $this->setHeader( $raw_response[ 0 ] );
13
+ $this->setBody( $raw_response[ 1 ] );
14
+ $this->setData( json_decode( $raw_response[ 1 ], true ) );
15
+ }
16
+ }
17
+
18
+ public function setHeader( $header ) {
19
+ $this->header = $header;
20
+ }
21
+
22
+ public function getHeader() {
23
+ return $this->header;
24
+ }
25
+
26
+ public function setBody( $body ) {
27
+ $this->body = $body;
28
+ }
29
+
30
+ public function getBody() {
31
+ return $this->body;
32
+ }
33
+
34
+ public function setData( $data ) {
35
+ $this->data = $data;
36
+ }
37
+
38
+ public function getData() {
39
+ return $this->data;
40
+ }
41
+
42
+ }
readme.txt CHANGED
@@ -2,10 +2,10 @@
2
  Contributors: sharethis, scottstorebloom, scottmweaver
3
  Tags: analytics, google analytics, google analytics plugin, google analytics widget, google analytics dashboard
4
  Requires at least: 5.2
5
- Tested up to: 5.8
6
- Stable tag: 2.5.2
7
 
8
- Use Google Analytics on your Wordpress site without touching any code, and view visitor reports right in your Wordpress admin dashboard!
9
 
10
  == Description ==
11
 
@@ -87,7 +87,7 @@ While some publishers prefer the manual option, installing the Google Analytics
87
 
88
  = Do I Need to Put Google Analytics Tracking Code on Every Page? =
89
  Google Analytics tracking code is a block of JavaScript code that executes Google Analytics tracking when a visitor loads a page on your website. The script that triggers these events must be loaded on every page in order for Google Analytics tracking to work.
90
- That doesnt mean you need to become an expert in JavaScript code or spend hours manually inserting Google Analytics tracking code on every page of your WordPress website. You can insert the tracking code in your header.php file so that it automatically loads on every page, or you can install the Google Analytics Dashboard for WordPress plugin and follow a few simple steps to get Google Analytics tracking setup in minutes by authenticating with Google.
91
  Even if you prefer the traditional manual option of adding the UA tracking code to every page, the Google Analytics Dashboard for WordPress plugin makes that process easier, too. Simply click “Manually enter Tracking ID” and paste your Google Tracking code into the box that appears. Then, just click “Save Changes,” and your code will instantly be live on all your pages. Click here for more details on this process. However, keep in mind that using this option means your dashboards won’t appear, so to get the most from the Google Analytics Dashboard for WordPress plugin, we recommend using the authenticate with Google setup option from our latest update.
92
 
93
  = How Do I Use Google Analytics for SEO? =
@@ -114,6 +114,10 @@ If you’re using Google Analytics on your WordPress website or a plugin like th
114
 
115
  == Changelog ==
116
 
 
 
 
 
117
  = 2.5.2
118
  * Add custom date range selector instead of 7/30-day selector.
119
  * Add device breakdown under demographics section.
@@ -219,7 +223,7 @@ If you’re using Google Analytics on your WordPress website or a plugin like th
219
  * No need to find your GA property ID and copy it over, just sign in with Google and choose your site
220
  * See analytics right inside the plugin, the past 7 days vs your previous 7 days
221
  * Shows pageviews, users, pages per session and bounce rate + top 5 traffic referrals
222
- * Wordpress Dashboard widget for 7, 30 or 90 days graph and top site usage stats
223
  * Disable tracking for logged in users like admins or editors for more reliable analytics
224
 
225
  = 1.0.7 =
2
  Contributors: sharethis, scottstorebloom, scottmweaver
3
  Tags: analytics, google analytics, google analytics plugin, google analytics widget, google analytics dashboard
4
  Requires at least: 5.2
5
+ Tested up to: 5.8.1
6
+ Stable tag: 2.5.3
7
 
8
+ Use Google Analytics on your WordPress site without touching any code, and view visitor reports right in your WordPress admin dashboard!
9
 
10
  == Description ==
11
 
87
 
88
  = Do I Need to Put Google Analytics Tracking Code on Every Page? =
89
  Google Analytics tracking code is a block of JavaScript code that executes Google Analytics tracking when a visitor loads a page on your website. The script that triggers these events must be loaded on every page in order for Google Analytics tracking to work.
90
+ That doesn't mean you need to become an expert in JavaScript code or spend hours manually inserting Google Analytics tracking code on every page of your WordPress website. You can insert the tracking code in your header.php file so that it automatically loads on every page, or you can install the Google Analytics Dashboard for WordPress plugin and follow a few simple steps to get Google Analytics tracking setup in minutes by authenticating with Google.
91
  Even if you prefer the traditional manual option of adding the UA tracking code to every page, the Google Analytics Dashboard for WordPress plugin makes that process easier, too. Simply click “Manually enter Tracking ID” and paste your Google Tracking code into the box that appears. Then, just click “Save Changes,” and your code will instantly be live on all your pages. Click here for more details on this process. However, keep in mind that using this option means your dashboards won’t appear, so to get the most from the Google Analytics Dashboard for WordPress plugin, we recommend using the authenticate with Google setup option from our latest update.
92
 
93
  = How Do I Use Google Analytics for SEO? =
114
 
115
  == Changelog ==
116
 
117
+ = 2.5.3
118
+ * Fix sending of demographic data once per month.
119
+ * Test plugin with WordPress 5.8.1.
120
+
121
  = 2.5.2
122
  * Add custom date range selector instead of 7/30-day selector.
123
  * Add device breakdown under demographics section.
223
  * No need to find your GA property ID and copy it over, just sign in with Google and choose your site
224
  * See analytics right inside the plugin, the past 7 days vs your previous 7 days
225
  * Shows pageviews, users, pages per session and bounce rate + top 5 traffic referrals
226
+ * WordPress Dashboard widget for 7, 30 or 90 days graph and top site usage stats
227
  * Disable tracking for logged in users like admins or editors for more reliable analytics
228
 
229
  = 1.0.7 =
view/ga_accounts_selector.php CHANGED
@@ -1,26 +1,26 @@
1
- <div class="wrap">
2
- <input type="hidden" name="<?php echo esc_attr( Ga_Admin::GA_SELECTED_ACCOUNT ); ?>"
3
- value="<?php echo esc_attr( $selected ); ?>">
4
- <select id="ga_account_selector"
5
- name="<?php echo esc_attr( Ga_Admin::GA_SELECTED_ACCOUNT ); ?>" <?php echo esc_attr( $add_manually_enabled ? 'disabled="disabled"' : '' ); ?>>
6
- <option><?php _e( 'Please select your Google Analytics account:' ); ?></option>
7
- <?php
8
- if ( ! empty( $selector ) ) {
9
- foreach ( $selector as $account ) {
10
- ?>
11
- <optgroup label="<?php echo $account['name']; ?>">
12
- <?php foreach ( $account['webProperties'] as $property ): ?>
13
- <?php foreach ( $property['profiles'] as $profile ): ?>
14
- <option
15
- value="<?php echo esc_attr( $account['id'] . "_" . $property['webPropertyId'] . "_" . $profile['id'] ) ?>"
16
- <?php echo( $selected === $account['id'] . "_" . $property['webPropertyId'] . "_" . $profile['id'] ? 'selected="selected"' : '' ); ?>><?php echo esc_html( $property['name'] . "&nbsp;[" . $property['webPropertyId'] . "][" . $profile['id'] . "]" ) ?></option>
17
- <?php endforeach; ?>
18
- <?php endforeach; ?>
19
- </optgroup>
20
- <?php
21
- }
22
- }
23
- ?>
24
- </select>
25
- </div>
26
-
1
+ <div class="wrap">
2
+ <input type="hidden" name="<?php echo esc_attr( Ga_Admin::GA_SELECTED_ACCOUNT ); ?>"
3
+ value="<?php echo esc_attr( $selected ); ?>">
4
+ <select id="ga_account_selector"
5
+ name="<?php echo esc_attr( Ga_Admin::GA_SELECTED_ACCOUNT ); ?>" <?php echo esc_attr( $add_manually_enabled ? 'disabled="disabled"' : '' ); ?>>
6
+ <option><?php _e( 'Please select your Google Analytics account:' ); ?></option>
7
+ <?php
8
+ if ( ! empty( $selector ) ) {
9
+ foreach ( $selector as $account ) {
10
+ ?>
11
+ <optgroup label="<?php echo $account['name']; ?>">
12
+ <?php foreach ( $account['webProperties'] as $property ): ?>
13
+ <?php foreach ( $property['profiles'] as $profile ): ?>
14
+ <option
15
+ value="<?php echo esc_attr( $account['id'] . "_" . $property['webPropertyId'] . "_" . $profile['id'] ) ?>"
16
+ <?php echo( $selected === $account['id'] . "_" . $property['webPropertyId'] . "_" . $profile['id'] ? 'selected="selected"' : '' ); ?>><?php echo esc_html( $property['name'] . "&nbsp;[" . $property['webPropertyId'] . "][" . $profile['id'] . "]" ) ?></option>
17
+ <?php endforeach; ?>
18
+ <?php endforeach; ?>
19
+ </optgroup>
20
+ <?php
21
+ }
22
+ }
23
+ ?>
24
+ </select>
25
+ </div>
26
+
view/ga_code.php CHANGED
@@ -1,24 +1,24 @@
1
- <script>
2
- (function() {
3
- (function (i, s, o, g, r, a, m) {
4
- i['GoogleAnalyticsObject'] = r;
5
- i[r] = i[r] || function () {
6
- (i[r].q = i[r].q || []).push(arguments)
7
- }, i[r].l = 1 * new Date();
8
- a = s.createElement(o),
9
- m = s.getElementsByTagName(o)[0];
10
- a.async = 1;
11
- a.src = g;
12
- m.parentNode.insertBefore(a, m)
13
- })(window, document, 'script', 'https://google-analytics.com/analytics.js', 'ga');
14
-
15
- ga('create', '<?php echo esc_attr( $data[ Ga_Admin::GA_WEB_PROPERTY_ID_OPTION_NAME ] ); ?>', 'auto');
16
- <?php if ( 'on' === $data['anonymization'] ) : ?>
17
- ga('set', 'anonymizeIp', true);
18
- <?php endif; ?>
19
- <?php if ( ! empty( $data['optimize'] ) ) : ?>
20
- ga('require', '<?php echo esc_html( $data['optimize'] ); ?>' );
21
- <?php endif; ?>
22
- ga('send', 'pageview');
23
- })();
24
- </script>
1
+ <script>
2
+ (function() {
3
+ (function (i, s, o, g, r, a, m) {
4
+ i['GoogleAnalyticsObject'] = r;
5
+ i[r] = i[r] || function () {
6
+ (i[r].q = i[r].q || []).push(arguments)
7
+ }, i[r].l = 1 * new Date();
8
+ a = s.createElement(o),
9
+ m = s.getElementsByTagName(o)[0];
10
+ a.async = 1;
11
+ a.src = g;
12
+ m.parentNode.insertBefore(a, m)
13
+ })(window, document, 'script', 'https://google-analytics.com/analytics.js', 'ga');
14
+
15
+ ga('create', '<?php echo esc_attr( $data[ Ga_Admin::GA_WEB_PROPERTY_ID_OPTION_NAME ] ); ?>', 'auto');
16
+ <?php if ( 'on' === $data['anonymization'] ) : ?>
17
+ ga('set', 'anonymizeIp', true);
18
+ <?php endif; ?>
19
+ <?php if ( ! empty( $data['optimize'] ) ) : ?>
20
+ ga('require', '<?php echo esc_html( $data['optimize'] ); ?>' );
21
+ <?php endif; ?>
22
+ ga('send', 'pageview');
23
+ })();
24
+ </script>
view/ga_dashboard_widget.php CHANGED
@@ -1,88 +1,88 @@
1
- <div class="wrap ga-wrap">
2
-
3
- <div class="form-group">
4
- <select id="range-selector" autocomplete="off">
5
- <option value="7daysAgo">Last 7 Days</option>
6
- <option value="30daysAgo" selected="selected">Last 30 Days</option>
7
- <option value="90daysAgo">Last 90 Days</option>
8
- </select>
9
-
10
- <select id="metrics-selector" autocomplete="off">
11
- <option value="pageviews">Pageviews</option>
12
- <option value="sessions">Visits</option>
13
- <option value="users">Users</option>
14
- <option value="organicSearches">Organic Search</option>
15
- <option value="visitBounceRate">Bounce Rate</option>
16
- </select>
17
-
18
- <div class="ga-loader-wrapper">
19
- <div class="ga-loader"></div>
20
- </div>
21
- </div>
22
-
23
- <div>
24
- <div id="chart_div" style="width: 100%;">
25
- <?php if ( $show_trigger_button ): ?>
26
- <div style="text-align: center">
27
- <div style="margin: 20px auto;">
28
- <button id="ga-widget-trigger" style="border: 1px solid #cccccc;width: 60%; padding: 10px"
29
- class="button-link">Click here to get data
30
- </button>
31
- </div>
32
- </div>
33
- <?php endif; ?>
34
- </div>
35
- <div id="ga_widget_error" class="notice notice-warning" style="display: none;"></div>
36
- <div>
37
- <div id="boxes-container">
38
- <div class="ga-box-row">
39
- <?php if ( ! empty( $boxes ) ) : ?>
40
- <?php $iter = 1; ?>
41
- <?php foreach ( $boxes as $k => $v ) : ?>
42
- <div class="ga-box-column ga-box-dashboard">
43
- <div style="color: grey; font-size: 13px;"
44
- id="ga_box_dashboard_label_<?php echo $k; ?>"><?php echo $v['label'] ?></div>
45
- <div style="font-size: 15px;"
46
- id="ga_box_dashboard_value_<?php echo $k; ?>"><?php echo $v['value'] ?></div>
47
- </div>
48
- <?php if ( ( ( $iter ++ ) % 3 ) == 0 ) : ?>
49
- </div>
50
- <div class="ga-box-row">
51
- <?php endif; ?>
52
- <?php endforeach; ?>
53
- <?php endif; ?>
54
- </div>
55
- </div>
56
- </div>
57
- </div>
58
-
59
- <div style="margin-top: 5px;"><?php echo sprintf( '<a href="%s">' . __( 'Show more details' ) . '</a>',
60
- $more_details_url ); ?></div>
61
- </div>
62
-
63
- <script type="text/javascript">
64
- const GA_NONCE = '<?php echo $ga_nonce; ?>';
65
- const GA_NONCE_FIELD = '<?php echo Ga_Admin_Controller::GA_NONCE_FIELD_NAME; ?>';
66
- <?php if ( empty( $show_trigger_button ) ): ?>
67
- <?php if ( ! empty( $chart ) ) : ?>
68
- dataArr = [['Day', 'Pageviews'],<?php
69
- $arr = "";
70
- foreach ( $chart as $row ) {
71
- if ( $arr ) {
72
- $arr .= ",";
73
- }
74
- $arr .= "['" . $row['day'] . "'," . $row['current'] . "]";
75
- }
76
-
77
- echo $arr;
78
- ?>];
79
-
80
- ga_dashboard.init(dataArr, true);
81
- ga_dashboard.events(dataArr);
82
- <?php endif; ?>
83
- <?php else: ?>
84
- dataArr = [['Day', 'Pageviews'], []];
85
- ga_dashboard.init(false, false);
86
- ga_dashboard.events();
87
- <?php endif; ?>
88
- </script>
1
+ <div class="wrap ga-wrap">
2
+
3
+ <div class="form-group">
4
+ <select id="range-selector" autocomplete="off">
5
+ <option value="7daysAgo">Last 7 Days</option>
6
+ <option value="30daysAgo" selected="selected">Last 30 Days</option>
7
+ <option value="90daysAgo">Last 90 Days</option>
8
+ </select>
9
+
10
+ <select id="metrics-selector" autocomplete="off">
11
+ <option value="pageviews">Pageviews</option>
12
+ <option value="sessions">Visits</option>
13
+ <option value="users">Users</option>
14
+ <option value="organicSearches">Organic Search</option>
15
+ <option value="visitBounceRate">Bounce Rate</option>
16
+ </select>
17
+
18
+ <div class="ga-loader-wrapper">
19
+ <div class="ga-loader"></div>
20
+ </div>
21
+ </div>
22
+
23
+ <div>
24
+ <div id="chart_div" style="width: 100%;">
25
+ <?php if ( $show_trigger_button ): ?>
26
+ <div style="text-align: center">
27
+ <div style="margin: 20px auto;">
28
+ <button id="ga-widget-trigger" style="border: 1px solid #cccccc;width: 60%; padding: 10px"
29
+ class="button-link">Click here to get data
30
+ </button>
31
+ </div>
32
+ </div>
33
+ <?php endif; ?>
34
+ </div>
35
+ <div id="ga_widget_error" class="notice notice-warning" style="display: none;"></div>
36
+ <div>
37
+ <div id="boxes-container">
38
+ <div class="ga-box-row">
39
+ <?php if ( ! empty( $boxes ) ) : ?>
40
+ <?php $iter = 1; ?>
41
+ <?php foreach ( $boxes as $k => $v ) : ?>
42
+ <div class="ga-box-column ga-box-dashboard">
43
+ <div style="color: grey; font-size: 13px;"
44
+ id="ga_box_dashboard_label_<?php echo $k; ?>"><?php echo $v['label'] ?></div>
45
+ <div style="font-size: 15px;"
46
+ id="ga_box_dashboard_value_<?php echo $k; ?>"><?php echo $v['value'] ?></div>
47
+ </div>
48
+ <?php if ( ( ( $iter ++ ) % 3 ) == 0 ) : ?>
49
+ </div>
50
+ <div class="ga-box-row">
51
+ <?php endif; ?>
52
+ <?php endforeach; ?>
53
+ <?php endif; ?>
54
+ </div>
55
+ </div>
56
+ </div>
57
+ </div>
58
+
59
+ <div style="margin-top: 5px;"><?php echo sprintf( '<a href="%s">' . __( 'Show more details' ) . '</a>',
60
+ $more_details_url ); ?></div>
61
+ </div>
62
+
63
+ <script type="text/javascript">
64
+ const GA_NONCE = '<?php echo $ga_nonce; ?>';
65
+ const GA_NONCE_FIELD = '<?php echo Ga_Admin_Controller::GA_NONCE_FIELD_NAME; ?>';
66
+ <?php if ( empty( $show_trigger_button ) ): ?>
67
+ <?php if ( ! empty( $chart ) ) : ?>
68
+ dataArr = [['Day', 'Pageviews'],<?php
69
+ $arr = "";
70
+ foreach ( $chart as $row ) {
71
+ if ( $arr ) {
72
+ $arr .= ",";
73
+ }
74
+ $arr .= "['" . $row['day'] . "'," . $row['current'] . "]";
75
+ }
76
+
77
+ echo $arr;
78
+ ?>];
79
+
80
+ ga_dashboard.init(dataArr, true);
81
+ ga_dashboard.events(dataArr);
82
+ <?php endif; ?>
83
+ <?php else: ?>
84
+ dataArr = [['Day', 'Pageviews'], []];
85
+ ga_dashboard.init(false, false);
86
+ ga_dashboard.events();
87
+ <?php endif; ?>
88
+ </script>
view/ga_oauth_notice.php CHANGED
@@ -1,3 +1,3 @@
1
- <div class="ga-alert ga-alert-warning">
2
- <?php echo $msg; ?>
3
- </div>
1
+ <div class="ga-alert ga-alert-warning">
2
+ <?php echo $msg; ?>
3
+ </div>