PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 3.1.2
ShareThis Dashboard for Google Analytics v3.1.2
3.3.2 trunk 1.0.7 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.5 2.3.5 2.3.6 2.3.7 2.3.8 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 3.0.0 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.2.0 3.2.1 3.2.2 3.2.3 3.2.4 3.3.0 3.3.1
googleanalytics / view / stats.php
googleanalytics / view Last commit date
templates 3 years ago ga-accounts-selector.php 4 years ago ga-auth-button.php 4 years ago ga-code.php 4 years ago ga-dashboard-widget.php 4 years ago ga-debug-modal.php 4 years ago ga-ga4-settings.php 3 years ago ga-googleanalytics-loader.php 4 years ago ga-notice.php 3 years ago ga-oauth-notice.php 4 years ago ga-wp-notice.php 4 years ago page.php 3 years ago statistics.php 3 years ago stats.php 3 years ago trending.php 4 years ago
stats.php
375 lines
1 <?php
2 /**
3 * Stats view.
4 *
5 * @package GoogleAnalytics
6 */
7
8 // Variables passed in (with fallbacks in case they aren't).
9 $age_chart = true === isset( $age_chart ) ? $age_chart : array();
10 $gender_chart = true === isset( $gender_chart ) ? $gender_chart : array();
11 $event_count_chart = true === isset( $event_count_chart ) ? $event_count_chart : array();
12
13 $account_data = json_decode( get_option( 'googleanalytics_account_data', true ), true );
14 $selected_data = json_decode( get_option( 'googleanalytics_selected_account', true ), true );
15 $demo_enabled = get_option('googleanalytics_demographic');
16 $demo_enabled = false === empty($demo_enabled);
17 $ga4_demo_enabled = 'on' === get_option('googleanalytics-ga4-demo');
18 $ga4_property = get_option('googleanalytics-ga4-property');
19 $ga4_property = isset($ga4_property) ? $ga4_property : false;
20
21 if (isset($selected_data)) {
22 foreach ($account_data as $properties) {
23 if ($properties['id'] === $selected_data[0]) {
24 foreach ($properties['webProperties'] as $web_property) {
25 if ($web_property['webPropertyId'] === $selected_data[1]) {
26 $internal_prop = $web_property['internalWebPropertyId'];
27 }
28 }
29 }
30 }
31
32 $ts = filter_input(INPUT_GET, 'ts', FILTER_SANITIZE_STRING);
33 $selected_page = false === empty($ts) ? '' : 'selected';
34 $selected_source = false === empty($ts) ? 'selected' : '';
35
36 $report_url = 'https://analytics.google.com/analytics/web/#/report/content-pages/a' . $selected_data[0] . 'w' . $internal_prop . 'p' . $selected_data[2];
37 $source_page_url = false === empty($ts) ? str_replace(
38 'content-pages',
39 'trafficsources-all-traffic',
40 $report_url
41 ) : $report_url;
42 $demographic_page_url = str_replace('content-pages', 'visitors-demographics-overview', $report_url);
43 $type_label = false === empty($ts) ? 'Traffic Sources' : 'Pages/Posts';
44 $source_url = 'admin.php?page=googleanalytics&ts=1';
45 $send_data = get_option('googleanalytics_send_data');
46 $need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
47 }
48
49 // Filter GA Action.
50 $ga_action = filter_input( INPUT_GET, 'ga_action', FILTER_SANITIZE_STRING );
51 $date_range = Ga_Helper::get_date_range_from_request();
52 $days_in_english = Ga_Helper::get_period_in_days_words( $date_range['from'], $date_range['to'] );
53 ?>
54 <?php
55 if ( false === $demo_enabled && false === $ga4_demo_enabled ) {
56 echo wp_kses(
57 Ga_Helper::ga_wp_notice(
58 __( 'Visualize gender and age data with our new demographic feature.' ),
59 'warning',
60 false,
61 array(
62 'url' => Ga_Helper::create_url(
63 Ga_Helper::get_current_url(),
64 array( Ga_Controller_Core::ACTION_PARAM_NAME => 'demo-ad' )
65 ),
66 'label' => __( 'Access Now', 'googleanalytics' ),
67 )
68 ),
69 array(
70 'button' => array(
71 'class' => array(),
72 'onclick' => array(),
73 ),
74 'div' => array(
75 'class' => array(),
76 ),
77 'p' => array(),
78 )
79 );
80 }
81 ?>
82 <div class="wrap ga-wrap" id="ga-stats-container" data-scroll="<?php echo esc_attr( $ga_action ); ?>">
83 <?php if (false === empty($selected_data)) : ?>
84 <div class="dashboard-title">Universal Analytics</div>
85 <?php endif; ?>
86 <div class="filter-choices">
87 <div>
88 <?php
89 Ga_Template::load(
90 'templates/date-custom-range-filter',
91 array(
92 'date_from' => $date_range['from'],
93 'date_to' => $date_range['to'],
94 )
95 );
96 ?>
97 </div>
98 </div>
99 <?php
100 if (isset($selected_data)) :
101 if ( false === empty( $chart ) ) : ?>
102 <div class="ga-panel ga-panel-default">
103 <div class="ga-panel-heading">
104 <strong>
105 <?php echo esc_html( 'Pageviews - ' . $days_in_english ); ?>
106 </strong>
107 </div>
108 <div class="ga-panel-body ga-chart">
109 <div id="chart_div" style="width: 100%;"></div>
110 <div class="ga-loader-wrapper stats-page">
111 <div class="ga-loader stats-page-loader"></div>
112 </div>
113 </div>
114 </div>
115 <?php endif; ?>
116
117 <?php if ( ! empty( $boxes ) ) : ?>
118 <div class="ga-panel ga-panel-default">
119 <div class="ga-panel-heading"><strong><?php echo esc_html( 'Comparison - ' . $days_in_english ); ?></strong>
120 </div>
121 <div class="ga-panel-body">
122 <div class="ga-row">
123 <?php foreach ( $boxes as $box ) : ?>
124 <div class="ga-box">
125 <div class="ga-panel ga-panel-default">
126 <div class="ga-panel-body ga-box-centered">
127 <div class="ga-box-label"><?php echo esc_html( $box['label'] ); ?></div>
128 <div class="ga-box-diff" style="color: <?php echo esc_attr( $box['color'] ); ?>;">
129 <?php echo esc_html( Ga_Helper::format_percent( $box['diff'] ) ); ?>
130 </div>
131 <div class="ga-box-comparison"><?php echo esc_html( $box['comparison'] ); ?></div>
132 </div>
133 </div>
134 </div>
135 <?php endforeach; ?>
136 </div>
137 </div>
138 </div>
139 <?php
140 endif;
141
142 require plugin_dir_path( __FILE__ ) . '/templates/demographic-chart.php';
143
144 if ( ! empty( $sources ) ) :
145 ?>
146 <div class="filter-choices" id="traffic-sources">
147 <a href="<?php echo esc_url( get_admin_url( '', 'admin.php?page=googleanalytics#traffic-sources' ) ); ?>"
148 class="<?php echo esc_attr( $selected_page ); ?>">
149 <?php esc_html_e( 'Page View', 'googleanalytics' ); ?>
150 </a>
151 <a href="<?php echo esc_url( get_admin_url( '', 'admin.php?page=googleanalytics&ts=1#traffic-sources' ) ); ?>"
152 class="<?php echo esc_attr( $selected_source ); ?>">
153 <?php esc_html_e( 'Traffic Source', 'googleanalytics' ); ?>
154 </a>
155 </div>
156 <div class="ga-panel ga-panel-default">
157 <div class="ga-panel-heading">
158 <strong><?php echo esc_html( 'Top 10 ' . $type_label . ' by page views' ); ?></strong>
159 </div>
160 <div class="ga-panel-body">
161
162 <div id="table-container">
163 <table class="ga-table">
164 <tr>
165 <td colspan="2">
166 </td>
167 <th style="text-align: right;">
168 <?php echo esc_html( 'Pageviews' ); ?>
169 </th>
170 <th style="text-align: right;">
171 <?php echo '%'; ?>
172 </th>
173 </tr>
174 <tr>
175 <td colspan="2"></td>
176 <td class="ga-col-pageviews" style="text-align: right">
177 <div style="font-size: 16px;"><?php echo esc_html( $sources['total'] ); ?></div>
178 <div style="color: grey; font-size: 10px;">% of
179 Total:
180 <?php
181 echo esc_html(
182 Ga_Helper::format_percent(
183 ( false === empty( $sources['total'] ) ) ? number_format(
184 $sources['sum'] / $sources['total'] * 100,
185 2,
186 '.',
187 ' '
188 ) : 100
189 )
190 );
191 ?>
192 (<?php echo esc_html( $sources['sum'] ); ?>)
193 </div>
194 </td>
195 <td class="ga-col-progressbar" style="text-align: right">
196 <div style="font-size: 16px;"><?php echo esc_html( $sources['total'] ); ?></div>
197 <div style="color: grey; font-size: 10px;">% of
198 Total:
199 <?php
200 echo esc_html(
201 Ga_Helper::format_percent(
202 ( false === empty( $sources['total'] ) ) ? number_format(
203 $sources['sum'] / $sources['total'] * 100,
204 2,
205 '.',
206 ' '
207 ) : 100
208 )
209 );
210 ?>
211 (<?php echo esc_html( $sources['sum'] ); ?>)
212 </div>
213 </td>
214 </tr>
215 <?php foreach ( $sources['rows'] as $key => $source ) : ?>
216 <tr>
217 <td style="width: 5%;text-align: right"><?php echo esc_html( $key ); ?>.</td>
218 <td class="ga-col-name">
219 <?php
220 if ( '(direct) / (none)' !== $source['name'] ) :
221 $single_breakdown = false === empty( $ts ) ?
222 '/explorer-table.plotKeys=%5B%5D&_r.drilldown=analytics.sourceMedium:' :
223 '/explorer-table.plotKeys=%5B%5D&_r.drilldown=analytics.pagePath:';
224 ?>
225 <a class="ga-source-name"
226 href="
227 <?php
228 echo esc_url(
229 $source_page_url . $single_breakdown . str_replace(
230 '+',
231 '%20',
232 str_replace(
233 '2F',
234 '~2F',
235 str_replace( '%', '', rawurlencode( $source['url'] ) )
236 )
237 )
238 );
239 ?>
240 /"
241 target="_blank"><?php echo esc_html( $source['name'] ); ?></a>
242 <?php else : ?>
243 <?php echo esc_html( $source['name'] ); ?>
244 <?php endif; ?>
245 </td>
246 <td style="text-align: right"><?php echo esc_html( $source['number'] ); ?></td>
247 <td>
248 <div class="progress">
249 <div class="progress-bar" role="progressbar"
250 aria-valuenow="<?php echo esc_attr( $source['percent'] ); ?>" aria-valuemin="0"
251 aria-valuemax="100"
252 style="width: <?php echo esc_attr( $source['percent'] ); ?>%;"></div>
253 <span style="margin-left: 10px;">
254 <?php echo esc_html( Ga_Helper::format_percent( $source['percent'] ) ); ?>
255 </span>
256 </div>
257 </td>
258 </tr>
259 <?php endforeach; ?>
260 </table>
261 </div>
262 <a href="<?php echo esc_url( $source_page_url ); ?>/" class="view-report" target="_blank">
263 <?php echo esc_html__( 'View Full Report' ); ?>
264 </a>
265 </div>
266 </div>
267 <?php endif; ?>
268
269 <?php
270 if ( ! empty( $chart ) ) :
271 ?>
272 <script type="text/javascript">
273
274 ga_charts.init( function() {
275
276 var data = new google.visualization.DataTable();
277
278 data.addColumn( 'string', '<?php echo esc_js( __( 'Day', 'googleanalytics' ) ); ?>' );
279 data.addColumn( 'number', '<?php echo esc_js( __( 'Pageviews', 'googleanalytics' ) ); ?>' );
280 data.addColumn( { type: 'string', role: 'tooltip', 'p': { 'html': true } } );
281
282 <?php foreach ( $chart as $row ) : ?>
283 data.addRow( [
284 '<?php echo esc_js( $row['day'] ); ?>',
285 <?php echo esc_js( $row['current'] ); ?>,
286 ga_charts.createTooltip( '<?php echo esc_js( $row['day'] ); ?>',
287 '<?php echo esc_js( $row['current'] ); ?>'
288 )
289 ] );
290 <?php endforeach; ?>
291 ga_charts.events( data );
292 ga_charts.drawChart( data );
293 ga_loader.hide();
294
295 <?php
296 // Event Count
297 $event_count_data = array();
298 $event_count_data[0] = array(
299 __( 'Device', 'googleanalytics' ),
300 __( 'Device Breakdown', 'googleanalytics' ),
301 );
302
303 $x = 1;
304 foreach ($event_count_chart as $event_type => $amount) {
305 $event_count_data[ $x ] = array( $event_type, intval( $amount ) );
306 $x ++;
307 }
308 ?>
309 // Demographic gender chart
310 <?php
311 $demo_gender_data[0] = array( 'Gender', 'The gender of visitors' );
312
313 $x = 1;
314 foreach ( $gender_chart as $gender_type => $amount ) {
315 $demo_gender_data[ $x ] = array( ucfirst( $gender_type ), intval( $amount ) );
316 $x ++;
317 }
318 ?>
319
320 ga_charts.drawDemoGenderChart(<?php echo wp_json_encode( $demo_gender_data ); ?>);
321 ga_loader.hide();
322
323 // Demographic age chart
324 <?php
325 $demo_age_data[0] = array( 'Age', 'Average age range of visitors' );
326
327 $x = 1;
328
329 foreach ( $age_chart as $age_type => $amount ) {
330 $demo_age_data[ $x ] = array( $age_type, intval( $amount ) );
331 $x ++;
332 }
333 ?>
334 ga_charts.drawDemoAgeChart(<?php echo wp_json_encode( $demo_age_data ); ?>);
335
336 // Device chart.
337 <?php
338 $demo_device_data = array();
339 $demo_device_data[0] = array(
340 __( 'Device', 'googleanalytics' ),
341 __( 'Device Breakdown', 'googleanalytics' ),
342 );
343
344 $x = 1;
345 foreach ( $device_chart as $age_type => $amount ) {
346 $demo_device_data[ $x ] = array( $age_type, intval( $amount ) );
347 $x ++;
348 }
349 ?>
350 ga_charts.drawDemoDeviceChart(<?php echo wp_json_encode( $demo_device_data ); ?>);
351
352 ga_loader.hide();
353
354 <?php if ( Ga_Helper::are_features_enabled() && ! empty( $send_data ) && 'true' === $send_data ) : ?>
355 ga_events.sendDemoData(<?php echo esc_js( get_option( 'googleanalytics_demo_data' ) ); ?>);
356 <?php
357 update_option( 'googleanalytics_demo_date', gmdate( 'Y-m-d' ) );
358 update_option( 'googleanalytics_send_data', 'false' );
359 endif;
360 ?>
361 },
362 );
363 </script>
364 <?php
365 endif;
366 endif;
367
368 if (false !== $ga4_property) {
369 include 'templates/ga4-dashboard.php';
370 }
371
372 include 'templates/demo-popup.php';
373 ?>
374 </div>
375