PluginProbe ʕ •ᴥ•ʔ
ShareThis Dashboard for Google Analytics / 2.4.0
ShareThis Dashboard for Google Analytics v2.4.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
243 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 ?>
32 <div class="wrap ga-wrap" id="ga-stats-container">
33 <?php if ( ! empty( $chart ) ) : ?>
34 <div class="filter-choices">
35 <a href="<?php echo get_admin_url('', $seven_url ); ?>" class="<?php echo esc_attr( $selected7 ); ?>">
36 7 days
37 </a>
38 <a href="<?php echo get_admin_url('', $thirty_url ); ?>" class="<?php echo esc_attr( $selected30 ); ?>">
39 30 days
40 </a>
41 </div>
42 <div class="ga-panel ga-panel-default">
43 <div class="ga-panel-heading">
44 <strong>
45 <?php echo 'Pageviews - Last ' . esc_html( $sevenorthirty ) . ' days'; ?>
46 </strong>
47 </div>
48 <div class="ga-panel-body ga-chart">
49 <div id="chart_div" style="width: 100%;"></div>
50 <div class="ga-loader-wrapper stats-page">
51 <div class="ga-loader stats-page-loader"></div>
52 </div>
53 </div>
54 </div>
55 <?php endif; ?>
56
57 <?php if ( ! empty( $boxes ) ) : ?>
58 <div class="ga-panel ga-panel-default">
59 <div class="ga-panel-heading"><strong><?php echo 'Comparison - Last ' . esc_html( $sevenorthirty ) . ' days vs previous ' . esc_html( $sevenorthirty ) . ' days'; ?></strong>
60 </div>
61 <div class="ga-panel-body">
62 <div class="ga-row">
63 <?php foreach ( $boxes as $box ) : ?>
64 <div class="ga-box">
65 <div class="ga-panel ga-panel-default">
66 <div class="ga-panel-body ga-box-centered">
67 <div class="ga-box-label"><?php echo esc_html( $box['label'] ); ?></div>
68 <div class="ga-box-diff" style="color: <?php echo esc_attr( $box['color'] ); ?>;">
69 <?php echo Ga_Helper::format_percent( $box['diff'] ); ?>
70 </div>
71 <div class="ga-box-comparison"><?php echo $box['comparison']; ?></div>
72 </div>
73 </div>
74 </div>
75 <?php endforeach; ?>
76 </div>
77 </div>
78 </div>
79 <?php
80 endif;
81
82 include plugin_dir_path(__FILE__) . '/templates/demographic-chart.php';
83
84 if ( ! empty( $sources ) ) : ?>
85 <div class="filter-choices">
86 <a href="<?php echo get_admin_url('', $page_view_url); ?>" class="<?php echo esc_attr( $selectedpage ); ?>">
87 Page View
88 </a>
89 <a href="<?php echo get_admin_url('', $source_url); ?>" class="<?php echo esc_attr( $selectedsource ); ?>">
90 Traffic Source
91 </a>
92 </div>
93 <div class="ga-panel ga-panel-default">
94 <div class="ga-panel-heading"><strong><?php _e( "Top 10 " . $type_label . " by page views" ); ?></strong>
95 </div>
96 <div class="ga-panel-body">
97
98 <div id="table-container">
99 <table class="ga-table">
100 <tr>
101 <td colspan="2">
102 </td>
103 <th style="text-align: right;">
104 <?php _e( 'Pageviews' ); ?>
105 </th>
106 <th style="text-align: right;">
107 <?php echo '%'; ?>
108 </th>
109 </tr>
110 <tr>
111 <td colspan="2"></td>
112 <td class="ga-col-pageviews" style="text-align: right">
113 <div style="font-size: 16px;"><?php echo $sources['total'] ?></div>
114 <div style="color: grey; font-size: 10px;">% of
115 Total: <?php echo Ga_Helper::format_percent( ( ! empty( $sources['total'] ) ) ? number_format( $sources['sum'] / $sources['total'] * 100,
116 2, '.', ' ' ) : 100 );
117 ?>
118 (<?php echo $sources['sum'] ?>)
119 </div>
120 </td>
121 <td class="ga-col-progressbar" style="text-align: right">
122 <div style="font-size: 16px;"><?php echo $sources['total'] ?></div>
123 <div style="color: grey; font-size: 10px;">% of
124 Total: <?php echo Ga_Helper::format_percent( ( ! empty( $sources['total'] ) ) ? number_format( $sources['sum'] / $sources['total'] * 100,
125 2, '.', ' ' ) : 100 );
126 ?>
127 (<?php echo $sources['sum'] ?>)
128 </div>
129 </td>
130 </tr>
131 <?php foreach ( $sources['rows'] as $key => $source ): ?>
132 <tr>
133 <td style="width: 5%;text-align: right"><?php echo $key ?>.</td>
134 <td class="ga-col-name">
135 <?php if ( $source['name'] != '(direct) / (none)' ) :
136
137 $single_breakdown = isset($_GET['ts']) ? '/explorer-table.plotKeys=%5B%5D&_r.drilldown=analytics.sourceMedium:' : '/explorer-table.plotKeys=%5B%5D&_r.drilldown=analytics.pagePath:';
138
139 ?>
140 <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'] ) ) ) ) ); ?>/"
141 target="_blank"><?php echo $source['name'] ?></a>
142 <?php else: ?>
143 <?php echo $source['name'] ?>
144 <?php endif; ?>
145 </td>
146 <td style="text-align: right"><?php echo $source['number'] ?></td>
147 <td>
148 <div class="progress">
149 <div class="progress-bar" role="progressbar"
150 aria-valuenow="<?php echo $source['percent'] ?>" aria-valuemin="0"
151 aria-valuemax="100"
152 style="width: <?php echo $source['percent'] ?>%;"></div>
153 <span style="margin-left: 10px;"><?php echo Ga_Helper::format_percent( $source['percent'] ); ?></span>
154 </div>
155 </td>
156 </tr>
157 <?php endforeach; ?>
158 </table>
159 </div>
160 <a href="<?php echo esc_url( $source_page_url ); ?>/" class="view-report" target="_blank">
161 <?php echo esc_html__('View Full Report' ); ?>
162 </a>
163 </div>
164 </div>
165 <?php endif; ?>
166
167 <?php if ( ! empty( $chart ) ) :
168
169 $label_count = isset($_GET['th']) ? $labels['thisMonth'] : $labels['thisWeek'];
170
171 ?>
172 <script type="text/javascript">
173
174 ga_charts.init(function () {
175
176 var data = new google.visualization.DataTable();
177 var demoGenderData = new google.visualization.DataTable();
178 var demoAgeData = new google.visualization.DataTable();
179
180 data.addColumn('string', 'Day');
181 data.addColumn('number', '<?php echo $label_count ?>');
182 data.addColumn({type: 'string', role: 'tooltip', 'p': {'html': true}});
183
184 <?php foreach ( $chart as $row ) : ?>
185 data.addRow(['<?php echo $row['day'] ?>', <?php echo $row['current'] ?>, ga_charts.createTooltip('<?php echo $row['day'] ?>', '<?php echo $row['current'] ?>')]);
186 <?php endforeach; ?>
187 ga_charts.events(data);
188 ga_charts.drawChart(data);
189 ga_loader.hide();
190
191 // Demographic gender chart
192 <?php
193 $demoGenderData[0] = ['Gender', 'The gender of visitors'];
194 $x = 1;
195 foreach ( $gender_chart as $type => $amount ) {
196 $demoGenderData[$x] = [ucfirst($type), intval($amount)];
197 $x++;
198 } ?>
199
200 ga_charts.drawDemoGenderChart(<?php echo json_encode($demoGenderData); ?>);
201 ga_loader.hide();
202
203 // Demographic age chart
204 <?php
205 $demoAgeData[0] = ['Age', 'Average age range of visitors'];
206 $x = 1;
207 foreach ( $age_chart as $type => $amount ) {
208 $demoAgeData[$x] = [$type, intval($amount)];
209 $x++;
210 } ?>
211 ga_charts.drawDemoAgeChart(<?php echo json_encode($demoAgeData); ?>);
212 ga_loader.hide();
213
214 <?php if (Ga_Helper::are_features_enabled() && !empty($send_data) && "true" === $send_data) : ?>
215 ga_events.sendDemoData(<?php echo get_option('googleanalytics_demo_data'); ?>);
216 <?php
217 update_option('googleanalytics_demo_date', date("Y-m-d"));
218 update_option('googleanalytics_send_data', "false");
219 endif;
220 ?>
221 }
222 );
223 </script>
224 <?php endif; ?>
225 <div class="demo-enable-popup">
226 <p>
227 We are deploying additional data from your Google Analytics account to your WordPress dashboard
228 as a free service to assist you in operating your WordPress site.
229 This will result in Google Analytics having access to data collected from Your site(s)
230 and subject to Google’s privacy policies as described in the <a
231 href="http://www.sharethis.com/publisher-terms-of-use/" target="_blank">ShareThis Publisher TOU</a>.
232 We will also use the aggregate demographic data related to your site for analytic purposes.
233 We will not sell or transfer any of the demographic data relating to your site to any other party.
234 For more information, please visit the <a
235 href="http://www.sharethis.com/news/2016/12/sharethis-adds-analytics-plugin-to-suite-of-tools/"
236 target="_blank">ShareThis Privacy Policy</a> and <a
237 href="http://www.sharethis.com/publisher-terms-of-use/" target="_blank">Publisher TOU</a>.
238 </p>
239 <button id="enable-demographic">I accept</button>
240 <button class="close-demo-modal">Decline</button>
241 </div>
242 </div>
243