Google Analyticator - Version 6.1

Version Description

  • Prepares Google Analyticator for WordPress 3.0 compatibility.
  • Updates the async tracking snippet to the latest version provided by Google. This new update solves issues with IE7 and IE6, and fixes all problems related to the snippet being placed in the section of a page. You can rest easy knowing that async tracking in the is completely compatible with IE now.
  • Adds an html comment to the page header when tracking code is hidden due to the user admin level. This should make is less confusing for new Google Analyticator users, wondering if their tracking code is visible to the world.
  • Adds a setting to specify a specific profile ID. This will help users with multiple Analytics profiles, by allowing them to specify which profile to use with the dashboard widget.
  • Revamps the disable tracking settings. Now uses user roles and provides more fine grain control. If you use something other than the default, be sure to visit the settings page to ensure your settings are correct.
  • Adds a new setting providing fine grain control over who can see the dashboard widget.
  • Fixes the disappearing UID box bug when not authenticated.
Download this release

Release Info

Developer cavemonkey50
Plugin Icon 128x128 Google Analyticator
Version 6.1
Comparing to
See all releases

Code changes from version 6.0.2 to 6.1

google-analyticator.php CHANGED
@@ -1,7 +1,7 @@
1
<?php
2
/*
3
* Plugin Name: Google Analyticator
4
- * Version: 6.0.2
5
* Plugin URI: http://ronaldheft.com/code/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 visit <a href="options-general.php?page=google-analyticator.php">the settings page</a> and enter your Google Analytics' UID and enable logging.
7
* Author: Ronald Heft
@@ -9,7 +9,7 @@
9
* Text Domain: google-analyticator
10
*/
11
12
- define('GOOGLE_ANALYTICATOR_VERSION', '6.0.2');
13
14
// Constants for enabled/disabled state
15
define("ga_enabled", "enabled", true);
@@ -20,7 +20,8 @@ define("key_ga_uid", "ga_uid", true);
20
define("key_ga_status", "ga_status", true);
21
define("key_ga_admin", "ga_admin_status", true);
22
define("key_ga_admin_disable", "ga_admin_disable", true);
23
- define("key_ga_admin_level", "ga_admin_level", true);
24
define("key_ga_adsense", "ga_adsense", true);
25
define("key_ga_extra", "ga_extra", true);
26
define("key_ga_extra_after", "ga_extra_after", true);
@@ -35,7 +36,6 @@ define("ga_uid_default", "XX-XXXXX-X", true);
35
define("ga_status_default", ga_disabled, true);
36
define("ga_admin_default", ga_enabled, true);
37
define("ga_admin_disable_default", 'remove', true);
38
- define("ga_admin_level_default", 8, true);
39
define("ga_adsense_default", "", true);
40
define("ga_extra_default", "", true);
41
define("ga_extra_after_default", "", true);
@@ -51,7 +51,8 @@ add_option(key_ga_status, ga_status_default, 'If Google Analytics logging in tur
51
add_option(key_ga_uid, ga_uid_default, 'Your Google Analytics UID.');
52
add_option(key_ga_admin, ga_admin_default, 'If WordPress admins are counted in Google Analytics.');
53
add_option(key_ga_admin_disable, ga_admin_disable_default, '');
54
- add_option(key_ga_admin_level, ga_admin_level_default, 'The level to consider a user a WordPress admin.');
55
add_option(key_ga_adsense, ga_adsense_default, '');
56
add_option(key_ga_extra, ga_extra_default, 'Addition Google Analytics tracking options');
57
add_option(key_ga_extra_after, ga_extra_after_default, 'Addition Google Analytics tracking options');
@@ -60,6 +61,7 @@ add_option(key_ga_outbound, ga_outbound_default, 'Add tracking of outbound links
60
add_option(key_ga_outbound_prefix, ga_outbound_prefix_default, 'Add tracking of outbound links');
61
add_option(key_ga_downloads, ga_downloads_default, 'Download extensions to track with Google Analyticator');
62
add_option(key_ga_downloads_prefix, ga_downloads_prefix_default, 'Download extensions to track with Google Analyticator');
63
add_option(key_ga_widgets, ga_widgets_default, 'If the widgets are enabled or disabled');
64
add_option('ga_google_token', '', 'The token used to authenticate with Google');
65
add_option('ga_compatibility', 'off', 'Transport compatibility options');
@@ -163,10 +165,12 @@ function ga_options_page() {
163
update_option(key_ga_admin_disable, $ga_admin_disable);
164
165
// Update the admin level
166
- $ga_admin_level = $_POST[key_ga_admin_level];
167
- if ( $ga_admin_level == '' )
168
- $ga_admin_level = ga_admin_level_default;
169
- update_option(key_ga_admin_level, $ga_admin_level);
170
171
// Update the extra tracking code
172
$ga_extra = $_POST[key_ga_extra];
@@ -208,6 +212,9 @@ function ga_options_page() {
208
$ga_downloads_prefix = ga_downloads_prefix_default;
209
update_option(key_ga_downloads_prefix, $ga_downloads_prefix);
210
211
// Update the widgets option
212
$ga_widgets = $_POST[key_ga_widgets];
213
if (($ga_widgets != ga_enabled) && ($ga_widgets != ga_disabled))
@@ -310,7 +317,7 @@ function ga_options_page() {
310
echo "id='".key_ga_uid."' ";
311
echo "value='".get_option(key_ga_uid)."' />\n";
312
?>
313
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter your Google Analytics\' UID in this box (<a href="http://plugins.spiralwebconsulting.com/forums/viewtopic.php?f=5&amp;t=6">where can I find my UID?</a>). The UID is needed for Google Analytics to log your website stats.', 'google-analyticator'); ?> <strong><?php if ( function_exists('register_widget') ) _e('If you are having trouble finding your UID, authenticate with Google in the above field. After returning from Google, you will be able to select your account through a drop-down box.', 'google-analyticator'); ?></strong></p>
314
</td>
315
</tr>
316
</table>
@@ -318,7 +325,7 @@ function ga_options_page() {
318
<table class="form-table" cellspacing="2" cellpadding="5" width="100%">
319
<tr>
320
<th width="30%" valign="top" style="padding-top: 10px;">
321
- <label for="<?php echo key_ga_admin ?>"><?php _e('WordPress admin logging', 'google-analyticator'); ?>:</label>
322
</th>
323
<td>
324
<?php
@@ -327,51 +334,42 @@ function ga_options_page() {
327
echo "<option value='".ga_enabled."'";
328
if(get_option(key_ga_admin) == ga_enabled)
329
echo " selected='selected'";
330
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
331
332
echo "<option value='".ga_disabled."'";
333
if(get_option(key_ga_admin) == ga_disabled)
334
echo" selected='selected'";
335
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
336
337
echo "</select>\n";
338
339
- # Generate the user level box
340
- $level = "<input type='text' size='2' ";
341
- $level .= "name='".key_ga_admin_level."' ";
342
- $level .= "id='".key_ga_admin_level."' ";
343
- $level .= "value='".stripslashes(get_option(key_ga_admin_level))."' />\n";
344
345
- # Output the current user level
346
- if ( current_user_can('level_10') )
347
- $user = '10';
348
- elseif ( current_user_can('level_9') )
349
- $user = '9';
350
- elseif ( current_user_can('level_8') )
351
- $user = '8';
352
- elseif ( current_user_can('level_7') )
353
- $user = '7';
354
- elseif ( current_user_can('level_6') )
355
- $user = '6';
356
- elseif ( current_user_can('level_5') )
357
- $user = '5';
358
- elseif ( current_user_can('level_4') )
359
- $user = '4';
360
- elseif ( current_user_can('level_3') )
361
- $user = '3';
362
- elseif ( current_user_can('level_2') )
363
- $user = '2';
364
- elseif ( current_user_can('level_1') )
365
- $user = '1';
366
- else
367
- $user = '0';
368
?>
369
- <p style="margin: 5px 10px;" class="setting-description"><?php printf(__('Disabling this option will prevent all logged in WordPress admins from showing up on your Google Analytics reports. A WordPress admin is defined as a user with a level %s or higher. Your user level is %d.', 'google-analyticator'), $level, $user); ?></p>
370
</td>
371
</tr>
372
<tr>
373
<th width="30%" valign="top" style="padding-top: 10px;">
374
- <label for="<?php echo key_ga_admin_disable ?>"><?php _e('Admin tracking disable method', 'google-analyticator'); ?>:</label>
375
</th>
376
<td>
377
<?php
@@ -389,7 +387,7 @@ function ga_options_page() {
389
390
echo "</select>\n";
391
?>
392
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Selecting the "Remove" option will physically remove the tracking code from logged in admin users. Selecting the "Use \'admin\' variable" option will assign a variable called \'admin\' to logged in admin users. This option will allow Google Analytics\' site overlay feature to work, but you will have to manually configure Google Analytics to exclude tracking from hits with the \'admin\' variable.', 'google-analyticator'); ?></p>
393
</td>
394
</tr>
395
<tr>
@@ -491,7 +489,7 @@ function ga_options_page() {
491
echo "id='".key_ga_adsense."' ";
492
echo "value='".get_option(key_ga_adsense)."' />\n";
493
?>
494
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter your Google Adsense ID assigned by Google Analytics in this box. This enables Analytics tracking of Adsense information if your Adsense and Analytics accounts are linked. Note: Google recommends the Analytics tracking code is placed in the header with this option enabled, however, a fix is included in this plugin. To follow the official specs, do not enable footer tracking.', 'google-analyticator'); ?></p>
495
</td>
496
</tr>
497
<tr>
@@ -526,6 +524,40 @@ function ga_options_page() {
526
# Check if we have a version of WordPress greater than 2.8
527
if ( function_exists('register_widget') ) {
528
?>
529
<tr>
530
<th width="30%" valign="top" style="padding-top: 10px;">
531
<label for="<?php echo key_ga_widgets; ?>"><?php _e('Include widgets', 'google-analyticator'); ?>:</label>
@@ -594,33 +626,37 @@ function ga_options_page() {
594
function ga_admin_ajax()
595
{
596
if ( function_exists('register_widget') ) {
597
- ?>
598
- <script type="text/javascript">
599
600
- jQuery(document).ready(function(){
601
602
- // Grab the widget data
603
- jQuery.ajax({
604
- type: 'post',
605
- url: 'admin-ajax.php',
606
- data: {
607
- action: 'ga_ajax_accounts',
608
- _ajax_nonce: '<?php echo wp_create_nonce("google-analyticator-accounts_get"); ?>'<?php if ( isset($_GET['token']) ) { ?>,
609
- token: '<?php echo $_GET["token"]; ?>'
610
- <?php } ?>
611
- },
612
- success: function(html) {
613
- if ( html != '' )
614
- jQuery('#ga_ajax_accounts').html(html);
615
- else
616
- jQuery('#ga_connect_error').show();
617
- }
618
- });
619
620
- });
621
622
- </script>
623
- <?php
624
}
625
}
626
@@ -740,7 +776,7 @@ function add_google_analytics()
740
if ( ( get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
741
{
742
# Determine if the user is an admin, and should see the tracking code
743
- if ( ( get_option(key_ga_admin) == ga_enabled || !current_user_can('level_' . get_option(key_ga_admin_level)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
744
{
745
# Add the notice that Google Analyticator tracking is enabled
746
echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
@@ -786,7 +822,7 @@ function add_google_analytics()
786
echo " _gaq.push(['_trackPageview']);\n";
787
788
# Disable page tracking if admin is logged in
789
- if ( ( get_option(key_ga_admin) == ga_disabled ) && ( current_user_can('level_' . get_option(key_ga_admin_level)) ) )
790
echo " _gaq.push(['_setVar', 'admin']);\n";
791
792
# Add any tracking code after the trackPageview
@@ -799,10 +835,14 @@ function add_google_analytics()
799
(function() {
800
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
801
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
802
- (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
803
})();
804
</script>
805
<?php
806
}
807
}
808
}
@@ -825,7 +865,7 @@ function ga_outgoing_links()
825
if ( !is_admin() )
826
{
827
# Display page tracking if user is not an admin
828
- if ( ( get_option(key_ga_admin) == ga_enabled || !current_user_can('level_' . get_option(key_ga_admin_level)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
829
{
830
add_action('wp_print_scripts', 'ga_external_tracking_js');
831
}
@@ -842,6 +882,28 @@ function ga_external_tracking_js()
842
wp_enqueue_script('ga-external-tracking', plugins_url('/google-analyticator/external-tracking.min.js'), array('jquery'), GOOGLE_ANALYTICATOR_VERSION);
843
}
844
845
/**
846
* EXPERIMENTAL: Retrieve Google's visits for the given page
847
* More work needs to be done. Needs caching, needs to be less resource intensive, and
1
<?php
2
/*
3
* Plugin Name: Google Analyticator
4
+ * Version: 6.1
5
* Plugin URI: http://ronaldheft.com/code/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 visit <a href="options-general.php?page=google-analyticator.php">the settings page</a> and enter your Google Analytics' UID and enable logging.
7
* Author: Ronald Heft
9
* Text Domain: google-analyticator
10
*/
11
12
+ define('GOOGLE_ANALYTICATOR_VERSION', '6.1');
13
14
// Constants for enabled/disabled state
15
define("ga_enabled", "enabled", true);
20
define("key_ga_status", "ga_status", true);
21
define("key_ga_admin", "ga_admin_status", true);
22
define("key_ga_admin_disable", "ga_admin_disable", true);
23
+ define("key_ga_admin_role", "ga_admin_role", true);
24
+ define("key_ga_dashboard_role", "ga_dashboard_role", true);
25
define("key_ga_adsense", "ga_adsense", true);
26
define("key_ga_extra", "ga_extra", true);
27
define("key_ga_extra_after", "ga_extra_after", true);
36
define("ga_status_default", ga_disabled, true);
37
define("ga_admin_default", ga_enabled, true);
38
define("ga_admin_disable_default", 'remove', true);
39
define("ga_adsense_default", "", true);
40
define("ga_extra_default", "", true);
41
define("ga_extra_after_default", "", true);
51
add_option(key_ga_uid, ga_uid_default, 'Your Google Analytics UID.');
52
add_option(key_ga_admin, ga_admin_default, 'If WordPress admins are counted in Google Analytics.');
53
add_option(key_ga_admin_disable, ga_admin_disable_default, '');
54
+ add_option(key_ga_admin_role, array('administrator'), 'The level to consider a user a WordPress admin.');
55
+ add_option(key_ga_dashboard_role, array('administrator'), 'The level to consider the dashboard widget available to users.');
56
add_option(key_ga_adsense, ga_adsense_default, '');
57
add_option(key_ga_extra, ga_extra_default, 'Addition Google Analytics tracking options');
58
add_option(key_ga_extra_after, ga_extra_after_default, 'Addition Google Analytics tracking options');
61
add_option(key_ga_outbound_prefix, ga_outbound_prefix_default, 'Add tracking of outbound links');
62
add_option(key_ga_downloads, ga_downloads_default, 'Download extensions to track with Google Analyticator');
63
add_option(key_ga_downloads_prefix, ga_downloads_prefix_default, 'Download extensions to track with Google Analyticator');
64
+ add_option('ga_profileid', '', 'The specific profile id');
65
add_option(key_ga_widgets, ga_widgets_default, 'If the widgets are enabled or disabled');
66
add_option('ga_google_token', '', 'The token used to authenticate with Google');
67
add_option('ga_compatibility', 'off', 'Transport compatibility options');
165
update_option(key_ga_admin_disable, $ga_admin_disable);
166
167
// Update the admin level
168
+ $ga_admin_role = $_POST[key_ga_admin_role];
169
+ update_option(key_ga_admin_role, $ga_admin_role);
170
+
171
+ // Update the dashboard level
172
+ $ga_dashboard_role = $_POST[key_ga_dashboard_role];
173
+ update_option(key_ga_dashboard_role, $ga_dashboard_role);
174
175
// Update the extra tracking code
176
$ga_extra = $_POST[key_ga_extra];
212
$ga_downloads_prefix = ga_downloads_prefix_default;
213
update_option(key_ga_downloads_prefix, $ga_downloads_prefix);
214
215
+ // Update the profile id
216
+ update_option('ga_profileid', $_POST['ga_profileid']);
217
+
218
// Update the widgets option
219
$ga_widgets = $_POST[key_ga_widgets];
220
if (($ga_widgets != ga_enabled) && ($ga_widgets != ga_disabled))
317
echo "id='".key_ga_uid."' ";
318
echo "value='".get_option(key_ga_uid)."' />\n";
319
?>
320
+ <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter your Google Analytics\' UID in this box (<a href="http://forums.ronaldheft.com/viewtopic.php?f=5&amp;t=6">where can I find my UID?</a>). The UID is needed for Google Analytics to log your website stats.', 'google-analyticator'); ?> <strong><?php if ( function_exists('register_widget') ) _e('If you are having trouble finding your UID, authenticate with Google in the above field. After returning from Google, you will be able to select your account through a drop-down box.', 'google-analyticator'); ?></strong></p>
321
</td>
322
</tr>
323
</table>
325
<table class="form-table" cellspacing="2" cellpadding="5" width="100%">
326
<tr>
327
<th width="30%" valign="top" style="padding-top: 10px;">
328
+ <label for="<?php echo key_ga_admin ?>"><?php _e('Track all logged in WordPress users', 'google-analyticator'); ?>:</label>
329
</th>
330
<td>
331
<?php
334
echo "<option value='".ga_enabled."'";
335
if(get_option(key_ga_admin) == ga_enabled)
336
echo " selected='selected'";
337
+ echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
338
339
echo "<option value='".ga_disabled."'";
340
if(get_option(key_ga_admin) == ga_disabled)
341
echo" selected='selected'";
342
+ echo ">" . __('No', 'google-analyticator') . "</option>\n";
343
344
echo "</select>\n";
345
346
+ ?>
347
+ <p style="margin: 5px 10px;" class="setting-description"><?php _e('Selecting "no" to this option will prevent logged in WordPress users from showing up on your Google Analytics reports. This setting will prevent yourself or other users from showing up in your Analytics reports. Use the next setting to determine what user groups to exclude.', 'google-analyticator'); ?></p>
348
+ </td>
349
+ </tr>
350
+ <tr>
351
+ <th width="30%" valign="top" style="padding-top: 10px;">
352
+ <label for="<?php echo key_ga_admin_role ?>"><?php _e('User roles to not track', 'google-analyticator'); ?>:</label>
353
+ </th>
354
+ <td>
355
+ <?php
356
+ global $wp_roles;
357
+ $roles = $wp_roles->get_names();
358
359
+ # Loop through the roles
360
+ foreach ( $roles AS $role => $name ) {
361
+ echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_admin_role . '[]"';
362
+ if ( in_array($role, get_option(key_ga_admin_role)) )
363
+ echo " checked='checked'";
364
+ echo ' /> ' . $name . '<br />';
365
+ }
366
?>
367
+ <p style="margin: 5px 10px;" class="setting-description"><?php _e('Specifies the user roles to not include in your WordPress Analytics report. If a user is logged into WordPress with one of these roles, they will not show up in your Analytics report.', 'google-analyticator'); ?></p>
368
</td>
369
</tr>
370
<tr>
371
<th width="30%" valign="top" style="padding-top: 10px;">
372
+ <label for="<?php echo key_ga_admin_disable ?>"><?php _e('Method to prevent tracking', 'google-analyticator'); ?>:</label>
373
</th>
374
<td>
375
<?php
387
388
echo "</select>\n";
389
?>
390
+ <p style="margin: 5px 10px;" class="setting-description"><?php _e('Selecting the "Remove" option will physically remove the tracking code from logged in users. Selecting the "Use \'admin\' variable" option will assign a variable called \'admin\' to logged in users. This option will allow Google Analytics\' site overlay feature to work, but you will have to manually configure Google Analytics to exclude tracking from pageviews with the \'admin\' variable.', 'google-analyticator'); ?></p>
391
</td>
392
</tr>
393
<tr>
489
echo "id='".key_ga_adsense."' ";
490
echo "value='".get_option(key_ga_adsense)."' />\n";
491
?>
492
+ <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter your Google Adsense ID assigned by Google Analytics in this box. This enables Analytics tracking of Adsense information if your Adsense and Analytics accounts are linked.', 'google-analyticator'); ?></p>
493
</td>
494
</tr>
495
<tr>
524
# Check if we have a version of WordPress greater than 2.8
525
if ( function_exists('register_widget') ) {
526
?>
527
+ <tr>
528
+ <th valign="top" style="padding-top: 10px;">
529
+ <label for="ga_profileid"><?php _e('Google Analytics profile ID', 'google-analyticator'); ?>:</label>
530
+ </th>
531
+ <td>
532
+ <?php
533
+ echo "<input type='text' size='50' ";
534
+ echo "name='ga_profileid' ";
535
+ echo "id='ga_profileid' ";
536
+ echo "value='".get_option('ga_profileid')."' />\n";
537
+ ?>
538
+ <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter your Google Analytics\' profile ID in this box. Entering your profile ID is optional, and is only useful if you have multiple profiles associated with a single UID. By entering your profile ID, the dashboard widget will display stats based on the profile ID you specify.', 'google-analyticator'); ?></p>
539
+ </td>
540
+ </tr>
541
+ <tr>
542
+ <th width="30%" valign="top" style="padding-top: 10px;">
543
+ <label for="<?php echo key_ga_dashboard_role ?>"><?php _e('User roles that can see the dashboard widget', 'google-analyticator'); ?>:</label>
544
+ </th>
545
+ <td>
546
+ <?php
547
+ global $wp_roles;
548
+ $roles = $wp_roles->get_names();
549
+
550
+ # Loop through the roles
551
+ foreach ( $roles AS $role => $name ) {
552
+ echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_dashboard_role . '[]"';
553
+ if ( in_array($role, get_option(key_ga_dashboard_role)) )
554
+ echo " checked='checked'";
555
+ echo ' /> ' . $name . '<br />';
556
+ }
557
+ ?>
558
+ <p style="margin: 5px 10px;" class="setting-description"><?php _e('Specifies the user roles that can see the dashboard widget. If a user is not in one of these role groups, they will not see the dashboard widget.', 'google-analyticator'); ?></p>
559
+ </td>
560
+ </tr>
561
<tr>
562
<th width="30%" valign="top" style="padding-top: 10px;">
563
<label for="<?php echo key_ga_widgets; ?>"><?php _e('Include widgets', 'google-analyticator'); ?>:</label>
626
function ga_admin_ajax()
627
{
628
if ( function_exists('register_widget') ) {
629
+
630
+ # Only attempt to replace code if we're authenticated or attempting to authenticate
631
+ if ( ( isset($_REQUEST['token']) && $_REQUEST['token'] != '' ) || ( trim(get_option('ga_google_token')) != '' ) ) {
632
+ ?>
633
+ <script type="text/javascript">
634
635
+ jQuery(document).ready(function(){
636
637
+ // Grab the widget data
638
+ jQuery.ajax({
639
+ type: 'post',
640
+ url: 'admin-ajax.php',
641
+ data: {
642
+ action: 'ga_ajax_accounts',
643
+ _ajax_nonce: '<?php echo wp_create_nonce("google-analyticator-accounts_get"); ?>'<?php if ( isset($_GET['token']) ) { ?>,
644
+ token: '<?php echo $_GET["token"]; ?>'
645
+ <?php } ?>
646
+ },
647
+ success: function(html) {
648
+ if ( html != '' )
649
+ jQuery('#ga_ajax_accounts').html(html);
650
+ else
651
+ jQuery('#ga_connect_error').show();
652
+ }
653
+ });
654
655
+ });
656
657
+ </script>
658
+ <?php
659
+ }
660
}
661
}
662
776
if ( ( get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
777
{
778
# Determine if the user is an admin, and should see the tracking code
779
+ if ( ( get_option(key_ga_admin) == ga_enabled || !ga_current_user_is(get_option(ga_admin_role)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
780
{
781
# Add the notice that Google Analyticator tracking is enabled
782
echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
822
echo " _gaq.push(['_trackPageview']);\n";
823
824
# Disable page tracking if admin is logged in
825
+ if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(ga_admin_role)) ) )
826
echo " _gaq.push(['_setVar', 'admin']);\n";
827
828
# Add any tracking code after the trackPageview
835
(function() {
836
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
837
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
838
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
839
})();
840
</script>
841
<?php
842
+ } else {
843
+ # Add the notice that Google Analyticator tracking is enabled
844
+ echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
845
+ echo " <!-- " . __('Tracking code is hidden, since the settings specify not to track admins. Tracking is occurring for non-admins.', 'google-analyticator') . " -->\n";
846
}
847
}
848
}
865
if ( !is_admin() )
866
{
867
# Display page tracking if user is not an admin
868
+ if ( ( get_option(key_ga_admin) == ga_enabled || !ga_current_user_is(get_option(ga_admin_role)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
869
{
870
add_action('wp_print_scripts', 'ga_external_tracking_js');
871
}
882
wp_enqueue_script('ga-external-tracking', plugins_url('/google-analyticator/external-tracking.min.js'), array('jquery'), GOOGLE_ANALYTICATOR_VERSION);
883
}
884
885
+ /**
886
+ * Determines if a specific user fits a role
887
+ **/
888
+ function ga_current_user_is($roles)
889
+ {
890
+ if ( !$roles ) return false;
891
+
892
+ global $current_user;
893
+ get_currentuserinfo();
894
+ $user_id = intval( $current_user->ID );
895
+
896
+ if ( !$user_id ) {
897
+ return false;
898
+ }
899
+ $user = new WP_User($user_id); // $user->roles
900
+
901
+ foreach ( $roles as $role )
902
+ if ( in_array($role, $user->roles) ) return true;
903
+
904
+ return false;
905
+ }
906
+
907
/**
908
* EXPERIMENTAL: Retrieve Google's visits for the given page
909
* More work needs to be done. Needs caching, needs to be less resource intensive, and
google-analytics-stats-widget.php CHANGED
@@ -196,7 +196,7 @@ class GoogleStatsWidget extends WP_Widget
196
function getUniqueVisitors($account, $time = 1)
197
{
198
# Get the value from the database
199
- $visits = unserialize(get_option('google_stats_visits_' . $account));
200
201
# Check to make sure the timeframe is an int and greater than one
202
$time = (int) $time;
@@ -237,11 +237,8 @@ class GoogleStatsWidget extends WP_Widget
237
$yesterday = date('Y-m-d', strtotime('-1 day'));
238
$uniques = number_format($stats->getMetric('ga:visitors', $before, $yesterday));
239
240
- # Make the array for database storage
241
- $visit = serialize(array('unique'=>$uniques, 'lastcalled'=>time()));
242
-
243
# Store the array
244
- update_option('google_stats_visits_' . $account, $visit);
245
246
# Return the visits
247
return $uniques;
196
function getUniqueVisitors($account, $time = 1)
197
{
198
# Get the value from the database
199
+ $visits = maybe_unserialize(get_option('google_stats_visits_' . $account));
200
201
# Check to make sure the timeframe is an int and greater than one
202
$time = (int) $time;
237
$yesterday = date('Y-m-d', strtotime('-1 day'));
238
$uniques = number_format($stats->getMetric('ga:visitors', $before, $yesterday));
239
240
# Store the array
241
+ update_option('google_stats_visits_' . $account, array('unique'=>$uniques, 'lastcalled'=>time()));
242
243
# Return the visits
244
return $uniques;
google-analytics-summary-widget.php CHANGED
@@ -27,7 +27,7 @@ class GoogleAnalyticsSummary
27
function addDashboardWidget()
28
{
29
# Check if the user is an admin
30
- if ( current_user_can('level_' . get_option(key_ga_admin_level)) ) {
31
wp_add_dashboard_widget('google-analytics-summary', __('Google Analytics Summary', 'google-analyticator'), array($this, 'widget'));
32
}
33
}
@@ -108,6 +108,9 @@ class GoogleAnalyticsSummary
108
109
# Attempt to login and get the current account
110
$this->id = $this->getAnalyticsAccount();
111
$this->api->setAccount($this->id);
112
113
# Check that we can display the widget before continuing
@@ -211,7 +214,7 @@ class GoogleAnalyticsSummary
211
function getVisitsGraph()
212
{
213
# Get the value from the database
214
- $cached = unserialize(get_option('google_stats_visitsGraph_' . $this->id));
215
$updated = false;
216
217
# Check if the call has been made before
@@ -234,8 +237,7 @@ class GoogleAnalyticsSummary
234
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:date', 'ga:date');
235
236
# Store the serialized stats in the database
237
- $newStats = serialize(array('stats'=>$stats, 'lastcalled'=>time()));
238
- update_option('google_stats_visitsGraph_' . $this->id, $newStats);
239
240
}
241
@@ -278,7 +280,7 @@ class GoogleAnalyticsSummary
278
function getSiteUsage()
279
{
280
# Get the value from the database
281
- $cached = unserialize(get_option('google_stats_siteUsage_' . $this->id));
282
$updated = false;
283
284
# Check if the call has been made before
@@ -301,8 +303,7 @@ class GoogleAnalyticsSummary
301
$stats = $this->api->getMetrics('ga:visits,ga:bounces,ga:entrances,ga:pageviews,ga:timeOnSite,ga:newVisits', $before, $yesterday);
302
303
# Store the serialized stats in the database
304
- $newStats = serialize(array('stats'=>$stats, 'lastcalled'=>time()));
305
- update_option('google_stats_siteUsage_' . $this->id, $newStats);
306
307
}
308
@@ -353,7 +354,7 @@ class GoogleAnalyticsSummary
353
function getTopPages()
354
{
355
# Get the value from the database
356
- $cached = unserialize(get_option('google_stats_topPages_' . $this->id));
357
$updated = false;
358
359
# Check if the call has been made before
@@ -376,8 +377,7 @@ class GoogleAnalyticsSummary
376
$stats = $this->api->getMetrics('ga:pageviews', $before, $yesterday, 'ga:pageTitle,ga:pagePath', '-ga:pageviews', 'ga:pagePath!%3D%2F', '10');
377
378
# Store the serialized stats in the database
379
- $newStats = serialize(array('stats'=>$stats, 'lastcalled'=>time()));
380
- update_option('google_stats_topPages_' . $this->id, $newStats);
381
382
}
383
@@ -447,7 +447,7 @@ class GoogleAnalyticsSummary
447
function getTopReferrers()
448
{
449
# Get the value from the database
450
- $cached = unserialize(get_option('google_stats_topReferrers_' . $this->id));
451
$updated = false;
452
453
# Check if the call has been made before
@@ -470,8 +470,7 @@ class GoogleAnalyticsSummary
470
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:source,ga:medium', '-ga:visits', 'ga:medium%3D%3Dreferral', '5');
471
472
# Store the serialized stats in the database
473
- $newStats = serialize(array('stats'=>$stats, 'lastcalled'=>time()));
474
- update_option('google_stats_topReferrers_' . $this->id, $newStats);
475
476
}
477
@@ -498,7 +497,7 @@ class GoogleAnalyticsSummary
498
function getTopSearches()
499
{
500
# Get the value from the database
501
- $cached = unserialize(get_option('google_stats_topSearches_' . $this->id));
502
$updated = false;
503
504
# Check if the call has been made before
@@ -521,8 +520,7 @@ class GoogleAnalyticsSummary
521
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:keyword', '-ga:visits', 'ga:keyword!%3D(not%20set)', '5');
522
523
# Store the serialized stats in the database
524
- $newStats = serialize(array('stats'=>$stats, 'lastcalled'=>time()));
525
- update_option('google_stats_topSearches_' . $this->id, $newStats);
526
527
}
528
27
function addDashboardWidget()
28
{
29
# Check if the user is an admin
30
+ if ( ga_current_user_is(get_option(key_ga_dashboard_role)) ) {
31
wp_add_dashboard_widget('google-analytics-summary', __('Google Analytics Summary', 'google-analyticator'), array($this, 'widget'));
32
}
33
}
108
109
# Attempt to login and get the current account
110
$this->id = $this->getAnalyticsAccount();
111
+ $profile_id = get_option('ga_profileid');
112
+ if ( trim($profile_id) != '' )
113
+ $this->id = 'ga:' . $profile_id;
114
$this->api->setAccount($this->id);
115
116
# Check that we can display the widget before continuing
214
function getVisitsGraph()
215
{
216
# Get the value from the database
217
+ $cached = maybe_unserialize(get_option('google_stats_visitsGraph_' . $this->id));
218
$updated = false;
219
220
# Check if the call has been made before
237
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:date', 'ga:date');
238
239
# Store the serialized stats in the database
240
+ update_option('google_stats_visitsGraph_' . $this->id, array('stats'=>$stats, 'lastcalled'=>time()));
241
242
}
243
280
function getSiteUsage()
281
{
282
# Get the value from the database
283
+ $cached = maybe_unserialize(get_option('google_stats_siteUsage_' . $this->id));
284
$updated = false;
285
286
# Check if the call has been made before
303
$stats = $this->api->getMetrics('ga:visits,ga:bounces,ga:entrances,ga:pageviews,ga:timeOnSite,ga:newVisits', $before, $yesterday);
304
305
# Store the serialized stats in the database
306
+ update_option('google_stats_siteUsage_' . $this->id, array('stats'=>$stats, 'lastcalled'=>time()));
307
308
}
309
354
function getTopPages()
355
{
356
# Get the value from the database
357
+ $cached = maybe_unserialize(get_option('google_stats_topPages_' . $this->id));
358
$updated = false;
359
360
# Check if the call has been made before
377
$stats = $this->api->getMetrics('ga:pageviews', $before, $yesterday, 'ga:pageTitle,ga:pagePath', '-ga:pageviews', 'ga:pagePath!%3D%2F', '10');
378
379
# Store the serialized stats in the database
380
+ update_option('google_stats_topPages_' . $this->id, array('stats'=>$stats, 'lastcalled'=>time()));
381
382
}
383
447
function getTopReferrers()
448
{
449
# Get the value from the database
450
+ $cached = maybe_unserialize(get_option('google_stats_topReferrers_' . $this->id));
451
$updated = false;
452
453
# Check if the call has been made before
470
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:source,ga:medium', '-ga:visits', 'ga:medium%3D%3Dreferral', '5');
471
472
# Store the serialized stats in the database
473
+ update_option('google_stats_topReferrers_' . $this->id, array('stats'=>$stats, 'lastcalled'=>time()));
474
475
}
476
497
function getTopSearches()
498
{
499
# Get the value from the database
500
+ $cached = maybe_unserialize(get_option('google_stats_topSearches_' . $this->id));
501
$updated = false;
502
503
# Check if the call has been made before
520
$stats = $this->api->getMetrics('ga:visits', $before, $yesterday, 'ga:keyword', '-ga:visits', 'ga:keyword!%3D(not%20set)', '5');
521
522
# Store the serialized stats in the database
523
+ update_option('google_stats_topSearches_' . $this->id, array('stats'=>$stats, 'lastcalled'=>time()));
524
525
}
526
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: cavemonkey50
3
Donate link: http://ronaldheft.com/code/donate/
4
Tags: stats, statistics, google, analytics, google analytics, tracking, widget
5
Requires at least: 2.7
6
- Tested up to: 2.9
7
- Stable tag: 6.0.2
8
9
Adds the necessary JavaScript code to enable Google Analytics. Includes widgets for Analytics data display.
10
@@ -49,6 +49,15 @@ Please visit [Google Analyticator's support forum](http://forums.ronaldheft.com/
49
50
== Changelog ==
51
52
= 6.0.2 =
53
* Updates the async tracking snippet to the latest version provided by Google.
54
* Improves the error message when failing to authenticate with Google, pointing users to a FAQ article to resolve their issues.
@@ -283,4 +292,10 @@ Please visit [Google Analyticator's support forum](http://forums.ronaldheft.com/
283
* Added an option to add any additional tracking code that Google has.
284
285
= 1.0 =
286
- * Initial release.
3
Donate link: http://ronaldheft.com/code/donate/
4
Tags: stats, statistics, google, analytics, google analytics, tracking, widget
5
Requires at least: 2.7
6
+ Tested up to: 3.0
7
+ Stable tag: 6.1
8
9
Adds the necessary JavaScript code to enable Google Analytics. Includes widgets for Analytics data display.
10
49
50
== Changelog ==
51
52
+ = 6.1 =
53
+ * Prepares Google Analyticator for WordPress 3.0 compatibility.
54
+ * Updates the async tracking snippet to the latest version provided by Google. This new update solves issues with IE7 and IE6, and fixes all problems related to the snippet being placed in the <head> section of a page. You can rest easy knowing that async tracking in the <head> is completely compatible with IE now.
55
+ * Adds an html comment to the page header when tracking code is hidden due to the user admin level. This should make is less confusing for new Google Analyticator users, wondering if their tracking code is visible to the world.
56
+ * Adds a setting to specify a specific profile ID. This will help users with multiple Analytics profiles, by allowing them to specify which profile to use with the dashboard widget.
57
+ * Revamps the disable tracking settings. Now uses user roles and provides more fine grain control. If you use something other than the default, be sure to visit the settings page to ensure your settings are correct.
58
+ * Adds a new setting providing fine grain control over who can see the dashboard widget.
59
+ * Fixes the disappearing UID box bug when not authenticated.
60
+
61
= 6.0.2 =
62
* Updates the async tracking snippet to the latest version provided by Google.
63
* Improves the error message when failing to authenticate with Google, pointing users to a FAQ article to resolve their issues.
292
* Added an option to add any additional tracking code that Google has.
293
294
= 1.0 =
295
+ * Initial release.
296
+
297
+ == Upgrade Notice ==
298
+
299
+ = 6.1 =
300
+
301
+ Recommended update. Highlights include WordPress 3.0 support, updated async tracking code, dashboard stats by Analytics profile, more control over who gets tracked, and more control over who can see the dashboard widget. Settings have changed, so revisit the settings to verify.