Version Description
- Re-wrote caching on admin dashboard panel. Caches results for 6 hours, and speeds up display significantly using WordPress caching.
- Added prevention on URI Class (Google) clashing.
Download this release
Release Info
Developer | VideoUserManuals |
Plugin | ![]() |
Version | 6.4.1 |
Comparing to | |
See all releases |
Code changes from version 6.4 to 6.4.1
- google-analyticator.php +2 -2
- google-analytics-summary-widget.php +194 -338
- google-api-php-client/src/external/URITemplateParser.php +5 -0
- readme.txt +5 -1
google-analyticator.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
* Plugin Name: Google Analyticator
|
4 |
-
* Version: 6.4
|
5 |
* Plugin URI: http://wordpress.org/extend/plugins/google-analyticator/
|
6 |
* Description: Adds the necessary JavaScript code to enable <a href="http://www.google.com/analytics/">Google's Analytics</a>. After enabling this plugin you need to authenticate with Google, then select your domain and you're set.
|
7 |
* Author: Video User Manuals
|
@@ -9,7 +9,7 @@
|
|
9 |
* Text Domain: google-analyticator
|
10 |
*/
|
11 |
|
12 |
-
define('GOOGLE_ANALYTICATOR_VERSION', '6.4');
|
13 |
|
14 |
define('GOOGLE_ANALYTICATOR_CLIENTID', '1007949979410.apps.googleusercontent.com');
|
15 |
define('GOOGLE_ANALYTICATOR_CLIENTSECRET', 'q06U41XDXtzaXD14E-KO1hti'); //don't worry - this don't need to be secret in our case
|
1 |
<?php
|
2 |
/*
|
3 |
* Plugin Name: Google Analyticator
|
4 |
+
* Version: 6.4.1
|
5 |
* Plugin URI: http://wordpress.org/extend/plugins/google-analyticator/
|
6 |
* Description: Adds the necessary JavaScript code to enable <a href="http://www.google.com/analytics/">Google's Analytics</a>. After enabling this plugin you need to authenticate with Google, then select your domain and you're set.
|
7 |
* Author: Video User Manuals
|
9 |
* Text Domain: google-analyticator
|
10 |
*/
|
11 |
|
12 |
+
define('GOOGLE_ANALYTICATOR_VERSION', '6.4.1');
|
13 |
|
14 |
define('GOOGLE_ANALYTICATOR_CLIENTID', '1007949979410.apps.googleusercontent.com');
|
15 |
define('GOOGLE_ANALYTICATOR_CLIENTSECRET', 'q06U41XDXtzaXD14E-KO1hti'); //don't worry - this don't need to be secret in our case
|
google-analytics-summary-widget.php
CHANGED
@@ -27,10 +27,8 @@ class GoogleAnalyticsSummary
|
|
27 |
$this,
|
28 |
'addTopJs'
|
29 |
));
|
30 |
-
|
31 |
-
|
32 |
-
'ajaxWidget'
|
33 |
-
));
|
34 |
}
|
35 |
|
36 |
/**
|
@@ -120,63 +118,79 @@ class GoogleAnalyticsSummary
|
|
120 |
{
|
121 |
# Check the ajax widget
|
122 |
check_ajax_referer('google-analyticator-statsWidget_get');
|
|
|
123 |
|
124 |
-
#
|
125 |
-
$
|
126 |
-
|
127 |
-
$this->id = $account;
|
128 |
-
|
129 |
-
$this->api->setAccount($this->id);
|
130 |
-
|
131 |
-
# Check that we can display the widget before continuing
|
132 |
-
if ($account == false || $this->id == false) {
|
133 |
-
# Output error message
|
134 |
-
echo '<p style="margin: 0;">' . __('No Analytics account selected. Double check you are authenticated with Google on Google Analyticator\'s settings page and make sure an account is selected.', 'google-analyticator') . '</p>';
|
135 |
|
136 |
-
|
137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
138 |
|
139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
}
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
# Add the sparkline for the past 30 days
|
146 |
-
$this->getVisitsGraph();
|
147 |
-
|
148 |
-
# Add the summary header
|
149 |
-
echo '<p style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; color: #777; font-size: 13px;">' . __('Site Usage', 'google-analyticator') . '</p>';
|
150 |
-
|
151 |
-
# Add the visitor summary
|
152 |
-
$this->getSiteUsage();
|
153 |
-
|
154 |
-
# Add the top 5 posts header
|
155 |
-
echo '<p style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; color: #777; font-size: 13px;">' . __('Top Pages', 'google-analyticator') . '</p>';
|
156 |
-
|
157 |
-
# Add the top 5 posts
|
158 |
-
$this->getTopPages();
|
159 |
-
|
160 |
-
# Add the tab information
|
161 |
-
echo '<table width="100%"><tr><td width="50%" valign="top">';
|
162 |
-
|
163 |
-
# Add the top 5 referrers header
|
164 |
-
echo '<p style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; color: #777; font-size: 13px;">' . __('Top Referrers', 'google-analyticator') . '</p>';
|
165 |
-
|
166 |
-
# Add the referrer information
|
167 |
-
$this->getTopReferrers();
|
168 |
-
|
169 |
-
# Add the second column
|
170 |
-
echo '</td><td valign="top">';
|
171 |
-
|
172 |
-
# Add the top 5 search header
|
173 |
-
echo '<p style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; color: #777; font-size: 13px;">' . __('Top Searches', 'google-analyticator') . '</p>';
|
174 |
-
|
175 |
-
# Add the search information
|
176 |
-
$this->getTopSearches();
|
177 |
-
|
178 |
-
# Close the table
|
179 |
-
echo '</td></tr></table>';
|
180 |
|
181 |
die();
|
182 |
}
|
@@ -227,59 +241,54 @@ class GoogleAnalyticsSummary
|
|
227 |
**/
|
228 |
function getVisitsGraph()
|
229 |
{
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
}
|
264 |
-
|
265 |
-
$yesterday_count = $rows[count($rows) - 1][1];
|
266 |
-
|
267 |
-
# Shorten the string to remove the last comma
|
268 |
-
$data = substr($data, 0, -1);
|
269 |
}
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
# Output the graph
|
276 |
-
$output = '<script type="text/javascript">var ga_visits = [' . $data . '];</script>';
|
277 |
-
$output .= '<span class="ga_visits" title="' . sprintf(__('The most visits on a single day was %d. Yesterday there were %d visits.', 'google-analyticator'), $max, $yesterday_count) . '"></span>';
|
278 |
-
|
279 |
-
# Save output for 12 hours.
|
280 |
-
set_transient('ga_admin_stats_widget', $output, 60 * 60 * 12);
|
281 |
}
|
282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
283 |
echo $output;
|
284 |
}
|
285 |
|
@@ -288,124 +297,51 @@ class GoogleAnalyticsSummary
|
|
288 |
**/
|
289 |
function getSiteUsage()
|
290 |
{
|
291 |
-
# Get the
|
292 |
-
$
|
293 |
-
$
|
294 |
-
|
295 |
-
|
296 |
-
if (is_array($cached)) {
|
297 |
-
# Check if the last time called was within two hours, if so, mark to not retrieve and grab the stats array
|
298 |
-
if ($cached['lastcalled'] > (time() - 7200)) {
|
299 |
-
$updated = true;
|
300 |
-
$stats = $cached['stats'];
|
301 |
-
}
|
302 |
-
|
303 |
-
}
|
304 |
-
|
305 |
-
# If the stats need to be updated
|
306 |
-
if (!$updated) {
|
307 |
-
# Get the metrics needed to build the usage table
|
308 |
-
$before = date('Y-m-d', strtotime('-31 days'));
|
309 |
-
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
310 |
-
$stats = $this->api->getMetrics('ga:visits,ga:bounces,ga:entrances,ga:pageviews,ga:timeOnSite,ga:newVisits', $before, $yesterday);
|
311 |
-
|
312 |
-
# Store the serialized stats in the database
|
313 |
-
update_option('google_stats_siteUsage_' . $this->id, array(
|
314 |
-
'stats' => $stats,
|
315 |
-
'lastcalled' => time()
|
316 |
-
));
|
317 |
-
|
318 |
-
}
|
319 |
-
|
320 |
# Create the site usage table
|
321 |
-
if (isset($stats->totalsForAllResults)) {
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
?></td>
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
} else {
|
361 |
-
?>
|
362 |
-
<td><strong><?php
|
363 |
-
echo $this->sec2Time($stats->totalsForAllResults['ga:timeOnSite'] / $stats->totalsForAllResults['ga:visits']);
|
364 |
-
?></strong></td>
|
365 |
-
<?php
|
366 |
-
}
|
367 |
-
?>
|
368 |
-
<td><?php
|
369 |
-
_e('Avg. Time on Site', 'google-analyticator');
|
370 |
-
?></td>
|
371 |
-
</tr>
|
372 |
-
<tr>
|
373 |
-
<?php
|
374 |
-
if ($stats->totalsForAllResults['ga:visits'] <= 0) {
|
375 |
-
?>
|
376 |
-
<td><strong>0.00</strong></td>
|
377 |
-
<?php
|
378 |
-
} else {
|
379 |
-
?>
|
380 |
-
<td><strong><?php
|
381 |
-
echo number_format(round($stats->totalsForAllResults['ga:pageviews'] / $stats->totalsForAllResults['ga:visits'], 2), 2);
|
382 |
-
?></strong></td>
|
383 |
-
<?php
|
384 |
-
}
|
385 |
-
?>
|
386 |
-
<td><?php
|
387 |
-
_e('Pages/Visit', 'google-analyticator');
|
388 |
-
?></td>
|
389 |
-
<?php
|
390 |
-
if ($stats->totalsForAllResults['ga:visits'] <= 0) {
|
391 |
-
?>
|
392 |
-
<td><strong>0.00%</strong></td>
|
393 |
-
<?php
|
394 |
-
} else {
|
395 |
-
?>
|
396 |
-
<td><strong><?php
|
397 |
-
echo number_format(round(($stats->totalsForAllResults['ga:newVisits'] / $stats->totalsForAllResults['ga:visits']) * 100, 2), 2);
|
398 |
-
?>%</strong></td>
|
399 |
-
<?php
|
400 |
-
}
|
401 |
-
?>
|
402 |
-
<td><?php
|
403 |
-
_e('% New Visits', 'google-analyticator');
|
404 |
-
?></td>
|
405 |
-
</tr>
|
406 |
-
</table>
|
407 |
-
<?php
|
408 |
-
}
|
409 |
}
|
410 |
|
411 |
/**
|
@@ -413,48 +349,23 @@ class GoogleAnalyticsSummary
|
|
413 |
**/
|
414 |
function getTopPages()
|
415 |
{
|
416 |
-
# Get the
|
417 |
-
$
|
418 |
-
$
|
419 |
-
|
420 |
-
# Check if the call has been made before
|
421 |
-
if (is_array($cached)) {
|
422 |
-
# Check if the last time called was within two hours, if so, mark to not retrieve and grab the stats array
|
423 |
-
if ($cached['lastcalled'] > (time() - 7200)) {
|
424 |
-
$updated = true;
|
425 |
-
$stats = $cached['stats'];
|
426 |
-
}
|
427 |
-
|
428 |
-
}
|
429 |
-
|
430 |
-
# If the stats need to be updated
|
431 |
-
if (!$updated) {
|
432 |
-
# Get the metrics needed to build the top pages
|
433 |
-
$before = date('Y-m-d', strtotime('-31 days'));
|
434 |
-
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
435 |
-
$stats = $this->api->getMetrics('ga:pageviews', $before, $yesterday, 'ga:pageTitle,ga:pagePath', '-ga:pageviews', 'ga:pagePath!=/', 10); //'ga:pagePath!%3D%2F'
|
436 |
-
|
437 |
-
# Store the serialized stats in the database
|
438 |
-
update_option('google_stats_topPages_' . $this->id, array(
|
439 |
-
'stats' => $stats,
|
440 |
-
'lastcalled' => time()
|
441 |
-
));
|
442 |
-
|
443 |
-
}
|
444 |
-
|
445 |
$rows = $stats->getRows();
|
446 |
-
|
447 |
# Check the size of the stats array
|
448 |
if (count($rows) <= 0 || !is_array($rows)) {
|
449 |
-
|
450 |
} else {
|
451 |
# Build the top pages list
|
452 |
-
|
453 |
-
|
454 |
# Set variables needed to correct (not set) bug
|
455 |
$new_stats = array();
|
456 |
$notset_stats = array();
|
457 |
-
|
458 |
# Loop through each stat and create a new array
|
459 |
foreach ($rows AS $stat) {
|
460 |
# If the stat is not set
|
@@ -466,7 +377,7 @@ class GoogleAnalyticsSummary
|
|
466 |
$new_stats[$stat[1]] = $stat;
|
467 |
}
|
468 |
}
|
469 |
-
|
470 |
# Loop through all the (not set) stats and attempt to add them to their correct stat
|
471 |
foreach ($notset_stats AS $stat) {
|
472 |
# If the stat has a "partner"
|
@@ -477,34 +388,35 @@ class GoogleAnalyticsSummary
|
|
477 |
# Stat goes to the ether since we couldn't find a partner (if anyone reads this and has a suggestion to improve, let me know)
|
478 |
}
|
479 |
}
|
480 |
-
|
481 |
# Renew new_stats back to stats
|
482 |
$stats = $new_stats;
|
483 |
-
|
484 |
# Sort the stats array, since adding the (not set) items may have changed the order
|
485 |
usort($stats, array(
|
486 |
$this,
|
487 |
'statSort'
|
488 |
));
|
489 |
-
|
490 |
# Since we can no longer rely on the API as a limiter, we need to keep track of this ourselves
|
491 |
$stat_count = 0;
|
492 |
-
|
493 |
# Loop through each stat for display
|
494 |
foreach ($stats AS $stat) {
|
495 |
-
|
496 |
-
|
497 |
# Increase the stat counter
|
498 |
$stat_count++;
|
499 |
-
|
500 |
# Stop at 5
|
501 |
if ($stat_count >= 5)
|
502 |
break;
|
503 |
}
|
504 |
-
|
505 |
# Finish the list
|
506 |
-
|
507 |
}
|
|
|
508 |
}
|
509 |
|
510 |
/**
|
@@ -512,49 +424,24 @@ class GoogleAnalyticsSummary
|
|
512 |
**/
|
513 |
function getTopReferrers()
|
514 |
{
|
515 |
-
# Get the
|
516 |
-
$
|
517 |
-
$
|
518 |
-
|
519 |
-
# Check if the call has been made before
|
520 |
-
if (is_array($cached)) {
|
521 |
-
# Check if the last time called was within two hours, if so, mark to not retrieve and grab the stats array
|
522 |
-
if ($cached['lastcalled'] > (time() - 7200)) {
|
523 |
-
$updated = true;
|
524 |
-
$stats = $cached['stats'];
|
525 |
-
}
|
526 |
-
|
527 |
-
}
|
528 |
-
|
529 |
-
# If the stats need to be updated
|
530 |
-
if (!$updated) {
|
531 |
-
# Get the metrics needed to build the top referrers
|
532 |
-
$before = date('Y-m-d', strtotime('-31 days'));
|
533 |
-
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
534 |
-
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:source,ga:medium', '-ga:visits', 'ga:medium==referral', '5');
|
535 |
-
|
536 |
-
# Store the serialized stats in the database
|
537 |
-
update_option('google_stats_topReferrers_' . $this->id, array(
|
538 |
-
'stats' => $stats,
|
539 |
-
'lastcalled' => time()
|
540 |
-
));
|
541 |
-
|
542 |
-
}
|
543 |
-
|
544 |
$rows = $stats->getRows();
|
545 |
-
|
546 |
# Check the size of the stats array
|
547 |
if (count($rows) <= 0 || !is_array($rows)) {
|
548 |
echo '<p>' . __('There is no data for view.', 'google-analyticator') . '</p>';
|
549 |
} else {
|
550 |
# Build the top pages list
|
551 |
echo '<ol>';
|
552 |
-
|
553 |
# Loop through each stat
|
554 |
foreach ($rows AS $stat) {
|
555 |
echo '<li><strong>' . esc_html($stat[0]) . '</strong> - ' . number_format($stat[2]) . ' ' . __('Visits', 'google-analyticator') . '</li>';
|
556 |
}
|
557 |
-
|
558 |
# Finish the list
|
559 |
echo '</ol>';
|
560 |
}
|
@@ -565,49 +452,22 @@ class GoogleAnalyticsSummary
|
|
565 |
**/
|
566 |
function getTopSearches()
|
567 |
{
|
568 |
-
# Get the
|
569 |
-
$
|
570 |
-
$
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
# Check if the last time called was within two hours, if so, mark to not retrieve and grab the stats array
|
575 |
-
if ($cached['lastcalled'] > (time() - 7200)) {
|
576 |
-
$updated = true;
|
577 |
-
$stats = $cached['stats'];
|
578 |
-
}
|
579 |
-
|
580 |
-
}
|
581 |
-
|
582 |
-
# If the stats need to be updated
|
583 |
-
if (!$updated) {
|
584 |
-
# Get the metrics needed to build the top searches
|
585 |
-
$before = date('Y-m-d', strtotime('-31 days'));
|
586 |
-
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
587 |
-
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:keyword', '-ga:visits', 'ga:keyword!=(not set)', '5'); //'ga:keyword!=(not_set)'
|
588 |
-
|
589 |
-
# Store the serialized stats in the database
|
590 |
-
update_option('google_stats_topSearches_' . $this->id, array(
|
591 |
-
'stats' => $stats,
|
592 |
-
'lastcalled' => time()
|
593 |
-
));
|
594 |
-
|
595 |
-
}
|
596 |
-
|
597 |
-
$rows = $stats->getRows();
|
598 |
-
|
599 |
# Check the size of the stats array
|
600 |
if (count($rows) <= 0 || !is_array($rows)) {
|
601 |
echo '<p>' . __('There is no data for view.', 'google-analyticator') . '</p>';
|
602 |
} else {
|
603 |
# Build the top pages list
|
604 |
echo '<ol>';
|
605 |
-
|
606 |
# Loop through each stat
|
607 |
foreach ($rows AS $stat) {
|
608 |
echo '<li><strong>' . esc_html($stat[0]) . '</strong> - ' . number_format($stat[1]) . ' ' . __('Visits', 'google-analyticator') . '</li>';
|
609 |
}
|
610 |
-
|
611 |
# Finish the list
|
612 |
echo '</ol>';
|
613 |
}
|
@@ -666,8 +526,4 @@ class GoogleAnalyticsSummary
|
|
666 |
return false;
|
667 |
}
|
668 |
}
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
} // END class
|
27 |
$this,
|
28 |
'addTopJs'
|
29 |
));
|
30 |
+
|
31 |
+
add_action( 'wp_ajax_ga_stats_widget', array( $this, 'ajaxWidget' ), -1000000 );
|
|
|
|
|
32 |
}
|
33 |
|
34 |
/**
|
118 |
{
|
119 |
# Check the ajax widget
|
120 |
check_ajax_referer('google-analyticator-statsWidget_get');
|
121 |
+
$doing_transient = false;
|
122 |
|
123 |
+
# If WP_DEBUG is true,.
|
124 |
+
if ( ( defined('WP_DEBUG') && WP_DEBUG ) || ( false === ( $ga_output = get_transient( 'ga_admin_dashboard_'. GOOGLE_ANALYTICATOR_VERSION ) ) ) ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
+
ob_start();
|
127 |
+
|
128 |
+
# Attempt to login and get the current account
|
129 |
+
$account = $this->getAnalyticsAccount();
|
130 |
+
|
131 |
+
$this->id = $account;
|
132 |
+
|
133 |
+
$this->api->setAccount($this->id);
|
134 |
+
|
135 |
+
# Check that we can display the widget before continuing
|
136 |
+
if ($account == false || $this->id == false) {
|
137 |
+
# Output error message
|
138 |
+
echo '<p style="margin: 0;">' . __('No Analytics account selected. Double check you are authenticated with Google on Google Analyticator\'s settings page and make sure an account is selected.', 'google-analyticator') . '</p>';
|
139 |
+
# Add Javascript variable to prevent breaking the Javascript
|
140 |
+
echo '<script type="text/javascript">var ga_visits = [];</script>';
|
141 |
+
die;
|
142 |
+
}
|
143 |
|
144 |
+
# Add the header information for the visits graph
|
145 |
+
echo '<p class="ga_visits_title" style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; margin-top: 0px; color: #777; font-size: 13px;">' . __('Visits Over the Past 30 Days', 'google-analyticator') . '</p>';
|
146 |
+
|
147 |
+
# Add the sparkline for the past 30 days
|
148 |
+
$this->getVisitsGraph();
|
149 |
+
|
150 |
+
# Add the summary header
|
151 |
+
echo '<p style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; color: #777; font-size: 13px;">' . __('Site Usage', 'google-analyticator') . '</p>';
|
152 |
+
|
153 |
+
# Add the visitor summary
|
154 |
+
$this->getSiteUsage();
|
155 |
+
|
156 |
+
# Add the top 5 posts header
|
157 |
+
echo '<p style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; color: #777; font-size: 13px;">' . __('Top Pages', 'google-analyticator') . '</p>';
|
158 |
+
|
159 |
+
# Add the top 5 posts
|
160 |
+
$this->getTopPages();
|
161 |
+
|
162 |
+
# Add the tab information
|
163 |
+
echo '<table width="100%"><tr><td width="50%" valign="top">';
|
164 |
+
|
165 |
+
# Add the top 5 referrers header
|
166 |
+
echo '<p style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; color: #777; font-size: 13px;">' . __('Top Referrers', 'google-analyticator') . '</p>';
|
167 |
+
|
168 |
+
# Add the referrer information
|
169 |
+
$this->getTopReferrers();
|
170 |
+
|
171 |
+
# Add the second column
|
172 |
+
echo '</td><td valign="top">';
|
173 |
+
|
174 |
+
# Add the top 5 search header
|
175 |
+
echo '<p style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; color: #777; font-size: 13px;">' . __('Top Searches', 'google-analyticator') . '</p>';
|
176 |
+
|
177 |
+
# Add the search information
|
178 |
+
$this->getTopSearches();
|
179 |
+
|
180 |
+
# Close the table
|
181 |
+
echo '</td></tr></table>';
|
182 |
+
|
183 |
+
# Grab the above outputs and cache it!
|
184 |
+
$ga_output = ob_get_flush();
|
185 |
+
|
186 |
+
// Cache the admin dashboard for 6 hours at a time.
|
187 |
+
set_transient( 'ga_admin_dashboard_'. GOOGLE_ANALYTICATOR_VERSION , $ga_output, 60*60*6 );
|
188 |
+
$doing_transient = true;
|
189 |
+
|
190 |
}
|
191 |
+
|
192 |
+
if( $doing_transient == false )
|
193 |
+
echo $ga_output;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
194 |
|
195 |
die();
|
196 |
}
|
241 |
**/
|
242 |
function getVisitsGraph()
|
243 |
{
|
244 |
+
# Get the metrics needed to build the visits graph
|
245 |
+
$before = date('Y-m-d', strtotime('-31 days'));
|
246 |
+
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
247 |
+
|
248 |
+
try {
|
249 |
+
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:date', 'ga:date');
|
250 |
+
}
|
251 |
+
catch (Exception $e) {
|
252 |
+
print 'GA Summary Widget - there was a service error ' . $e->getCode() . ':' . $e->getMessage();
|
253 |
+
}
|
254 |
+
|
255 |
+
# Create a list of the data points for graphing
|
256 |
+
$data = '';
|
257 |
+
$max = 0;
|
258 |
+
|
259 |
+
$rows = $stats->getRows();
|
260 |
+
|
261 |
+
# Check the size of the stats array
|
262 |
+
if (!isset($rows) || !is_array($rows) || count($rows) <= 0) {
|
263 |
+
$data = '0,0';
|
264 |
+
} else {
|
265 |
+
foreach ($rows AS $stat) {
|
266 |
+
# Verify the number is numeric
|
267 |
+
if (is_numeric($stat[1]))
|
268 |
+
$data .= $stat[1] . ',';
|
269 |
+
else
|
270 |
+
$data .= '0,';
|
271 |
+
|
272 |
+
# Update the max value if greater
|
273 |
+
if ($max < $stat[1])
|
274 |
+
$max = $stat[1];
|
275 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
276 |
}
|
277 |
+
|
278 |
+
$yesterday_count = $rows[count($rows) - 1][1];
|
279 |
+
|
280 |
+
# Shorten the string to remove the last comma
|
281 |
+
$data = substr($data, 0, -1);
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
}
|
283 |
+
|
284 |
+
# Add a fake stat if need be
|
285 |
+
if (!isset($stat[1]))
|
286 |
+
$stat[1] = 0;
|
287 |
+
|
288 |
+
# Output the graph
|
289 |
+
$output = '<script type="text/javascript">var ga_visits = [' . $data . '];</script>';
|
290 |
+
$output .= '<span class="ga_visits" title="' . sprintf(__('The most visits on a single day was %d. Yesterday there were %d visits.', 'google-analyticator'), $max, $yesterday_count) . '"></span>';
|
291 |
+
|
292 |
echo $output;
|
293 |
}
|
294 |
|
297 |
**/
|
298 |
function getSiteUsage()
|
299 |
{
|
300 |
+
# Get the metrics needed to build the usage table
|
301 |
+
$before = date('Y-m-d', strtotime('-31 days'));
|
302 |
+
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
303 |
+
$stats = $this->api->getMetrics('ga:visits,ga:bounces,ga:entrances,ga:pageviews,ga:timeOnSite,ga:newVisits', $before, $yesterday);
|
304 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
305 |
# Create the site usage table
|
306 |
+
if (isset($stats->totalsForAllResults)) { ?>
|
307 |
+
<table width="100%">
|
308 |
+
<tr>
|
309 |
+
<td width=""><strong><?php echo number_format($stats->totalsForAllResults['ga:visits']); ?></strong></td>
|
310 |
+
<td width=""><?php _e('Visits', 'google-analyticator'); ?></td>
|
311 |
+
<?php if ($stats->totalsForAllResults['ga:entrances'] <= 0) { ?>
|
312 |
+
<td width="20%"><strong>0.00%</strong></td>
|
313 |
+
<?php } else { ?>
|
314 |
+
<td width="20%"><strong><?php echo number_format(round(($stats->totalsForAllResults['ga:bounces'] / $stats->totalsForAllResults['ga:entrances']) * 100, 2), 2); ?>%</strong></td>
|
315 |
+
<?php } ?>
|
316 |
+
<td width="30%"><?php _e('Bounce Rate', 'google-analyticator'); ?></td>
|
317 |
+
</tr>
|
318 |
+
<tr>
|
319 |
+
<td><strong><?php echo number_format($stats->totalsForAllResults['ga:pageviews']); ?></strong></td>
|
320 |
+
<td><?php _e('Pageviews', 'google-analyticator'); ?></td>
|
321 |
+
<?php if ($stats->totalsForAllResults['ga:visits'] <= 0) { ?>
|
322 |
+
<td><strong>00:00:00</strong></td>
|
323 |
+
<?php } else { ?>
|
324 |
+
<td><strong><?php echo $this->sec2Time($stats->totalsForAllResults['ga:timeOnSite'] / $stats->totalsForAllResults['ga:visits']); ?></strong></td>
|
325 |
+
<?php } ?>
|
326 |
+
<td><?php _e('Avg. Time on Site', 'google-analyticator'); ?></td>
|
327 |
+
</tr>
|
328 |
+
<tr>
|
329 |
+
<?php if ($stats->totalsForAllResults['ga:visits'] <= 0) { ?>
|
330 |
+
<td><strong>0.00</strong></td>
|
331 |
+
<?php } else { ?>
|
332 |
+
<td><strong><?php echo number_format(round($stats->totalsForAllResults['ga:pageviews'] / $stats->totalsForAllResults['ga:visits'], 2), 2); ?></strong></td>
|
333 |
+
<?php } ?>
|
334 |
+
<td><?php _e('Pages/Visit', 'google-analyticator'); ?></td>
|
335 |
+
<?php if ($stats->totalsForAllResults['ga:visits'] <= 0) { ?>
|
336 |
+
<td><strong>0.00%</strong></td>
|
337 |
+
<?php } else { ?>
|
338 |
+
<td><strong><?php echo number_format(round(($stats->totalsForAllResults['ga:newVisits'] / $stats->totalsForAllResults['ga:visits']) * 100, 2), 2); ?>%</strong></td>
|
339 |
+
<td><?php _e('% New Visits', 'google-analyticator'); ?></td>
|
340 |
+
<?php } ?>
|
341 |
+
</tr>
|
342 |
+
</table>
|
343 |
+
<?php }
|
344 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
345 |
}
|
346 |
|
347 |
/**
|
349 |
**/
|
350 |
function getTopPages()
|
351 |
{
|
352 |
+
# Get the metrics needed to build the top pages
|
353 |
+
$before = date('Y-m-d', strtotime('-31 days'));
|
354 |
+
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
355 |
+
$stats = $this->api->getMetrics('ga:pageviews', $before, $yesterday, 'ga:pageTitle,ga:pagePath', '-ga:pageviews', 'ga:pagePath!=/', 10); //'ga:pagePath!%3D%2F'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
356 |
$rows = $stats->getRows();
|
357 |
+
|
358 |
# Check the size of the stats array
|
359 |
if (count($rows) <= 0 || !is_array($rows)) {
|
360 |
+
$return = '<p>' . __('There is no data for view.', 'google-analyticator') . '</p>';
|
361 |
} else {
|
362 |
# Build the top pages list
|
363 |
+
$return = '<ol>';
|
364 |
+
|
365 |
# Set variables needed to correct (not set) bug
|
366 |
$new_stats = array();
|
367 |
$notset_stats = array();
|
368 |
+
|
369 |
# Loop through each stat and create a new array
|
370 |
foreach ($rows AS $stat) {
|
371 |
# If the stat is not set
|
377 |
$new_stats[$stat[1]] = $stat;
|
378 |
}
|
379 |
}
|
380 |
+
|
381 |
# Loop through all the (not set) stats and attempt to add them to their correct stat
|
382 |
foreach ($notset_stats AS $stat) {
|
383 |
# If the stat has a "partner"
|
388 |
# Stat goes to the ether since we couldn't find a partner (if anyone reads this and has a suggestion to improve, let me know)
|
389 |
}
|
390 |
}
|
391 |
+
|
392 |
# Renew new_stats back to stats
|
393 |
$stats = $new_stats;
|
394 |
+
|
395 |
# Sort the stats array, since adding the (not set) items may have changed the order
|
396 |
usort($stats, array(
|
397 |
$this,
|
398 |
'statSort'
|
399 |
));
|
400 |
+
|
401 |
# Since we can no longer rely on the API as a limiter, we need to keep track of this ourselves
|
402 |
$stat_count = 0;
|
403 |
+
|
404 |
# Loop through each stat for display
|
405 |
foreach ($stats AS $stat) {
|
406 |
+
$return .= '<li><a href="' . esc_url($stat[1]) . '">' . esc_html($stat[0]) . '</a> - ' . number_format($stat[2]) . ' ' . __('Views', 'google-analyticator') . '</li>';
|
407 |
+
|
408 |
# Increase the stat counter
|
409 |
$stat_count++;
|
410 |
+
|
411 |
# Stop at 5
|
412 |
if ($stat_count >= 5)
|
413 |
break;
|
414 |
}
|
415 |
+
|
416 |
# Finish the list
|
417 |
+
$return .= '</ol>';
|
418 |
}
|
419 |
+
echo $return;
|
420 |
}
|
421 |
|
422 |
/**
|
424 |
**/
|
425 |
function getTopReferrers()
|
426 |
{
|
427 |
+
# Get the metrics needed to build the top referrers
|
428 |
+
$before = date('Y-m-d', strtotime('-31 days'));
|
429 |
+
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
430 |
+
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:source,ga:medium', '-ga:visits', 'ga:medium==referral', '5');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
431 |
$rows = $stats->getRows();
|
432 |
+
|
433 |
# Check the size of the stats array
|
434 |
if (count($rows) <= 0 || !is_array($rows)) {
|
435 |
echo '<p>' . __('There is no data for view.', 'google-analyticator') . '</p>';
|
436 |
} else {
|
437 |
# Build the top pages list
|
438 |
echo '<ol>';
|
439 |
+
|
440 |
# Loop through each stat
|
441 |
foreach ($rows AS $stat) {
|
442 |
echo '<li><strong>' . esc_html($stat[0]) . '</strong> - ' . number_format($stat[2]) . ' ' . __('Visits', 'google-analyticator') . '</li>';
|
443 |
}
|
444 |
+
|
445 |
# Finish the list
|
446 |
echo '</ol>';
|
447 |
}
|
452 |
**/
|
453 |
function getTopSearches()
|
454 |
{
|
455 |
+
# Get the metrics needed to build the top searches
|
456 |
+
$before = date('Y-m-d', strtotime('-31 days'));
|
457 |
+
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
458 |
+
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:keyword', '-ga:visits', 'ga:keyword!=(not set)', '5'); //'ga:keyword!=(not_set)'
|
459 |
+
$rows = $stats->getRows();
|
460 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
461 |
# Check the size of the stats array
|
462 |
if (count($rows) <= 0 || !is_array($rows)) {
|
463 |
echo '<p>' . __('There is no data for view.', 'google-analyticator') . '</p>';
|
464 |
} else {
|
465 |
# Build the top pages list
|
466 |
echo '<ol>';
|
|
|
467 |
# Loop through each stat
|
468 |
foreach ($rows AS $stat) {
|
469 |
echo '<li><strong>' . esc_html($stat[0]) . '</strong> - ' . number_format($stat[1]) . ' ' . __('Visits', 'google-analyticator') . '</li>';
|
470 |
}
|
|
|
471 |
# Finish the list
|
472 |
echo '</ol>';
|
473 |
}
|
526 |
return false;
|
527 |
}
|
528 |
}
|
|
|
|
|
|
|
|
|
529 |
} // END class
|
google-api-php-client/src/external/URITemplateParser.php
CHANGED
@@ -27,6 +27,9 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
27 |
* Blogpost: http://lab.kevburnsjr.com/php-uri-template-parser
|
28 |
* Source: http://github.com/KevBurnsJr/php-uri-template-parser
|
29 |
*/
|
|
|
|
|
|
|
30 |
class URI_Template_Parser {
|
31 |
|
32 |
public static $operators = array('+', ';', '?', '/', '.');
|
@@ -207,3 +210,5 @@ class URI_Template_Parser {
|
|
207 |
return $this->template;
|
208 |
}
|
209 |
}
|
|
|
|
27 |
* Blogpost: http://lab.kevburnsjr.com/php-uri-template-parser
|
28 |
* Source: http://github.com/KevBurnsJr/php-uri-template-parser
|
29 |
*/
|
30 |
+
|
31 |
+
if( !class_exists( 'URI_Template_Parser' ) ){
|
32 |
+
|
33 |
class URI_Template_Parser {
|
34 |
|
35 |
public static $operators = array('+', ';', '?', '/', '.');
|
210 |
return $this->template;
|
211 |
}
|
212 |
}
|
213 |
+
|
214 |
+
} // End class check if exists.
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: VideoUserManuals
|
|
3 |
Tags: stats, statistics, google, analytics, google analytics, tracking, widget
|
4 |
Requires at least: 3.2
|
5 |
Tested up to: 3.5
|
6 |
-
Stable tag: 6.4
|
7 |
|
8 |
Adds the necessary JavaScript code to enable Google Analytics. Includes widgets for Analytics data display.
|
9 |
|
@@ -59,6 +59,10 @@ For any support issues, please use the official WordPress support forums.
|
|
59 |
|
60 |
== Changelog ==
|
61 |
|
|
|
|
|
|
|
|
|
62 |
= 6.4 =
|
63 |
* Added better caching of dashboard widget.
|
64 |
* Added better error handling with Google API calls. Prevents breaking widget section if an error is found.
|
3 |
Tags: stats, statistics, google, analytics, google analytics, tracking, widget
|
4 |
Requires at least: 3.2
|
5 |
Tested up to: 3.5
|
6 |
+
Stable tag: 6.4.1
|
7 |
|
8 |
Adds the necessary JavaScript code to enable Google Analytics. Includes widgets for Analytics data display.
|
9 |
|
59 |
|
60 |
== Changelog ==
|
61 |
|
62 |
+
= 6.4.1 =
|
63 |
+
* Re-wrote caching on admin dashboard panel. Caches results for 6 hours, and speeds up display significantly using WordPress caching.
|
64 |
+
* Added prevention on URI Class (Google) clashing.
|
65 |
+
|
66 |
= 6.4 =
|
67 |
* Added better caching of dashboard widget.
|
68 |
* Added better error handling with Google API calls. Prevents breaking widget section if an error is found.
|