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