PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.5.3
ShareThis Dashboard for Google Analytics v2.5.3
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 4 years ago ga_accounts_selector.php 4 years ago ga_auth_button.php 9 years ago ga_code.php 4 years ago ga_dashboard_widget.php 4 years ago ga_debug_modal.php 6 years ago ga_googleanalytics_loader.php 7 years ago ga_notice.php 4 years ago ga_oauth_notice.php 4 years ago ga_wp_notice.php 9 years ago page.php 5 years ago statistics.php 6 years ago stats.php 4 years ago trending.php 8 years ago
stats.php
256 lines
1 <?php
2 $account_data = json_decode(get_option('googleanalytics_account_data', true), true);
3 $selected_data = json_decode(get_option('googleanalytics_selected_account', true), true);
4
5 foreach ( $account_data as $properties ) {
6 if ( $properties['id'] === $selected_data[0] ) {
7 foreach ( $properties['webProperties'] as $web_property ) {
8 if ( $web_property['webPropertyId'] === $selected_data[1] ) {
9 $internal_prop = $web_property['internalWebPropertyId'];
10 }
11 }
12 }
13 }
14
15 $demo_enabled = get_option('googleanalytics_demographic');
16 $demo_enabled = !empty($demo_enabled) && $demo_enabled ? true: false;
17 $selectedpage = isset($_GET['ts']) ? '' : 'selected';
18 $selectedsource = isset($_GET['ts']) ? 'selected' : '';
19 $report_url = 'https://analytics.google.com/analytics/web/#/report/content-pages/a' . $selected_data[0] . 'w' . $internal_prop . 'p' . $selected_data[2];
20 $source_page_url = isset($_GET['ts']) ? str_replace('content-pages', 'trafficsources-all-traffic', $report_url) : $report_url;
21 $demographic_page_url = str_replace('content-pages', 'visitors-demographics-overview', $report_url);
22 $type_label = isset($_GET['ts']) ? 'Traffic Sources' : 'Pages/Posts';
23 $source_url = 'admin.php?page=googleanalytics&ts';
24 $send_data = get_option('googleanalytics_send_data');
25 $need_account_demo_enable = [] === $gender_chart && [] === $age_chart;
26
27 // Filter GA Action.
28 $ga_action = filter_input( INPUT_GET, 'ga_action', FILTER_SANITIZE_STRING );
29
30 $date_range = Ga_Helper::getDateRangeFromRequest();
31
32 $days_in_english = Ga_Helper::getPeriodInDaysWords($date_range['from'], $date_range['to']);
33 ?>
34 <?php if (!$demo_enabled) {
35 echo Ga_Helper::ga_wp_notice(
36 __( 'Visualize gender and age data with our new demographic feature.' ),
37 'warning',
38 false,
39 [
40 'url' => Ga_Helper::create_url( Ga_Helper::get_current_url(), array( Ga_Controller_Core::ACTION_PARAM_NAME => 'demo-ad' ) ),
41 'label' => __( 'Access Now', 'googleanalytics' ),
42 ]
43 );
44 } ?>
45 <div class="wrap ga-wrap" id="ga-stats-container" data-scroll="<?php echo esc_attr($ga_action); ?>">
46 <?php if ( ! empty( $chart ) ) : ?>
47 <div class="filter-choices">
48 <div>
49 <?php Ga_Template::load( 'templates/date_custom_range_filter', [
50 'date_from' => $date_range['from'],
51 'date_to' => $date_range['to']
52 ] ); ?>
53 </div>
54 </div>
55 <div class="ga-panel ga-panel-default">
56 <div class="ga-panel-heading">
57 <strong>
58 <?php echo 'Pageviews - ' . $days_in_english; ?>
59 </strong>
60 </div>
61 <div class="ga-panel-body ga-chart">
62 <div id="chart_div" style="width: 100%;"></div>
63 <div class="ga-loader-wrapper stats-page">
64 <div class="ga-loader stats-page-loader"></div>
65 </div>
66 </div>
67 </div>
68 <?php endif; ?>
69
70 <?php if ( ! empty( $boxes ) ) : ?>
71 <div class="ga-panel ga-panel-default">
72 <div class="ga-panel-heading"><strong><?php echo 'Comparison - ' . $days_in_english; ?></strong>
73 </div>
74 <div class="ga-panel-body">
75 <div class="ga-row">
76 <?php foreach ( $boxes as $box ) : ?>
77 <div class="ga-box">
78 <div class="ga-panel ga-panel-default">
79 <div class="ga-panel-body ga-box-centered">
80 <div class="ga-box-label"><?php echo esc_html( $box['label'] ); ?></div>
81 <div class="ga-box-diff" style="color: <?php echo esc_attr( $box['color'] ); ?>;">
82 <?php echo Ga_Helper::format_percent( $box['diff'] ); ?>
83 </div>
84 <div class="ga-box-comparison"><?php echo $box['comparison']; ?></div>
85 </div>
86 </div>
87 </div>
88 <?php endforeach; ?>
89 </div>
90 </div>
91 </div>
92 <?php
93 endif;
94
95 include plugin_dir_path(__FILE__) . '/templates/demographic-chart.php';
96
97 if ( ! empty( $sources ) ) : ?>
98 <div class="filter-choices">
99 <a href="<?php echo get_admin_url('', 'admin.php?page=googleanalytics'); ?>" class="<?php echo esc_attr( $selectedpage ); ?>">
100 Page View
101 </a>
102 <a href="<?php echo get_admin_url('', 'admin.php?page=googleanalytics&ts'); ?>" class="<?php echo esc_attr( $selectedsource ); ?>">
103 Traffic Source
104 </a>
105 </div>
106 <div class="ga-panel ga-panel-default">
107 <div class="ga-panel-heading"><strong><?php _e( "Top 10 " . $type_label . " by page views" ); ?></strong>
108 </div>
109 <div class="ga-panel-body">
110
111 <div id="table-container">
112 <table class="ga-table">
113 <tr>
114 <td colspan="2">
115 </td>
116 <th style="text-align: right;">
117 <?php _e( 'Pageviews' ); ?>
118 </th>
119 <th style="text-align: right;">
120 <?php echo '%'; ?>
121 </th>
122 </tr>
123 <tr>
124 <td colspan="2"></td>
125 <td class="ga-col-pageviews" style="text-align: right">
126 <div style="font-size: 16px;"><?php echo $sources['total'] ?></div>
127 <div style="color: grey; font-size: 10px;">% of
128 Total: <?php echo Ga_Helper::format_percent( ( ! empty( $sources['total'] ) ) ? number_format( $sources['sum'] / $sources['total'] * 100,
129 2, '.', ' ' ) : 100 );
130 ?>
131 (<?php echo $sources['sum'] ?>)
132 </div>
133 </td>
134 <td class="ga-col-progressbar" style="text-align: right">
135 <div style="font-size: 16px;"><?php echo $sources['total'] ?></div>
136 <div style="color: grey; font-size: 10px;">% of
137 Total: <?php echo Ga_Helper::format_percent( ( ! empty( $sources['total'] ) ) ? number_format( $sources['sum'] / $sources['total'] * 100,
138 2, '.', ' ' ) : 100 );
139 ?>
140 (<?php echo $sources['sum'] ?>)
141 </div>
142 </td>
143 </tr>
144 <?php foreach ( $sources['rows'] as $key => $source ): ?>
145 <tr>
146 <td style="width: 5%;text-align: right"><?php echo $key ?>.</td>
147 <td class="ga-col-name">
148 <?php if ( $source['name'] != '(direct) / (none)' ) :
149
150 $single_breakdown = isset($_GET['ts']) ? '/explorer-table.plotKeys=%5B%5D&_r.drilldown=analytics.sourceMedium:' : '/explorer-table.plotKeys=%5B%5D&_r.drilldown=analytics.pagePath:';
151
152 ?>
153 <a class="ga-source-name" href="<?php echo esc_url( $source_page_url . $single_breakdown . str_replace( '+', '%20', str_replace( '2F', '~2F', str_replace( '%', '', urlencode( $source['url'] ) ) ) ) ); ?>/"
154 target="_blank"><?php echo $source['name'] ?></a>
155 <?php else: ?>
156 <?php echo $source['name'] ?>
157 <?php endif; ?>
158 </td>
159 <td style="text-align: right"><?php echo $source['number'] ?></td>
160 <td>
161 <div class="progress">
162 <div class="progress-bar" role="progressbar"
163 aria-valuenow="<?php echo $source['percent'] ?>" aria-valuemin="0"
164 aria-valuemax="100"
165 style="width: <?php echo $source['percent'] ?>%;"></div>
166 <span style="margin-left: 10px;"><?php echo Ga_Helper::format_percent( $source['percent'] ); ?></span>
167 </div>
168 </td>
169 </tr>
170 <?php endforeach; ?>
171 </table>
172 </div>
173 <a href="<?php echo esc_url( $source_page_url ); ?>/" class="view-report" target="_blank">
174 <?php echo esc_html__('View Full Report' ); ?>
175 </a>
176 </div>
177 </div>
178 <?php endif; ?>
179
180 <?php if ( ! empty( $chart ) ) :
181 ?>
182 <script type="text/javascript">
183
184 ga_charts.init(function () {
185
186 var data = new google.visualization.DataTable();
187 var demoGenderData = new google.visualization.DataTable();
188 var demoAgeData = new google.visualization.DataTable();
189
190 data.addColumn('string', '<?php echo esc_js( __( 'Day', 'googleanalytics' ) ); ?>');
191 data.addColumn('number', '<?php echo esc_js( __( 'Pageviews', 'googleanalytics' ) ); ?>');
192 data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
193
194 <?php foreach ( $chart as $row ) : ?>
195 data.addRow(['<?php echo $row['day'] ?>', <?php echo $row['current'] ?>, ga_charts.createTooltip('<?php echo $row['day'] ?>', '<?php echo $row['current'] ?>')]);
196 <?php endforeach; ?>
197 ga_charts.events(data);
198 ga_charts.drawChart(data);
199 ga_loader.hide();
200
201 // Demographic gender chart
202 <?php
203 $demoGenderData[0] = ['Gender', 'The gender of visitors'];
204 $x = 1;
205 foreach ( $gender_chart as $type => $amount ) {
206 $demoGenderData[$x] = [ucfirst($type), intval($amount)];
207 $x++;
208 } ?>
209
210 ga_charts.drawDemoGenderChart(<?php echo json_encode($demoGenderData); ?>);
211 ga_loader.hide();
212
213 // Demographic age chart
214 <?php
215 $demoAgeData[0] = ['Age', 'Average age range of visitors'];
216 $x = 1;
217 foreach ( $age_chart as $type => $amount ) {
218 $demoAgeData[$x] = [$type, intval($amount)];
219 $x++;
220 } ?>
221 ga_charts.drawDemoAgeChart(<?php echo json_encode($demoAgeData); ?>);
222
223 // Device chart.
224 <?php
225 $demoDeviceData = array();
226 $demoDeviceData[0] = array(
227 __( 'Device', 'googleanalytics' ),
228 __( 'Device Breakdown', 'googleanalytics' ),
229 );
230
231 $x = 1;
232 foreach( $device_chart as $type => $amount ) {
233 $demoDeviceData[$x] = array($type, intval($amount));
234 $x++;
235 }
236 ?>
237 ga_charts.drawDemoDeviceChart(<?php echo json_encode($demoDeviceData); ?>);
238
239 ga_loader.hide();
240
241 <?php if (Ga_Helper::are_features_enabled() && !empty($send_data) && "true" === $send_data) : ?>
242 ga_events.sendDemoData(<?php echo get_option('googleanalytics_demo_data'); ?>);
243 <?php
244 update_option('googleanalytics_demo_date', date("Y-m-d"));
245 update_option('googleanalytics_send_data', "false");
246 endif;
247 ?>
248 }
249 );
250 </script>
251 <?php endif;
252 include 'templates/demo-popup.php';
253 ?>
254
255 </div>
256