Google Analyticator - Version 5.3

Version Description

  • Converts API data call to AJAX to reduce the memory needed on page loads.
  • Removes memory_limit alterations, since the default amount should be enough now.
  • Disables the summary dashboard widget for non-admins, as defined by the admin level setting on Google Analyticator's settings page.
Download this release

Release Info

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

Code changes from version 5.2.1 to 5.3

google-analyticator.php CHANGED
@@ -1,7 +1,7 @@
1
<?php
2
/*
3
* Plugin Name: Google Analyticator
4
- * Version: 5.2.1
5
* Plugin URI: http://plugins.spiralwebconsulting.com/analyticator.html
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: Spiral Web Consulting
@@ -9,7 +9,7 @@
9
* Text Domain: google-analyticator
10
*/
11
12
- define('GOOGLE_ANALYTICATOR_VERSION', '5.2.1');
13
14
// Constants for enabled/disabled state
15
define("ga_enabled", "enabled", true);
@@ -73,35 +73,15 @@ add_option('ga_compatibility', 'off', 'Transport compatibility options');
73
# Check if we have a version of WordPress greater than 2.8
74
if ( function_exists('register_widget') ) {
75
76
- # Get the current memory limit
77
- $current_mem_limit = substr(ini_get('memory_limit'), 0, -1);
78
-
79
- # Check if this limit is less than 96M, if so, increase it
80
- if ( $current_mem_limit < 96 || $current_mem_limit == '' ) {
81
- if ( function_exists('memory_get_usage') )
82
- @ini_set('memory_limit', '96M');
83
- }
84
-
85
# Check if widgets are enabled
86
if ( get_option(key_ga_widgets) == 'enabled' ) {
87
-
88
- # Get the current memory limit, after the update
89
- $current_mem_limit = substr(ini_get('memory_limit'), 0, -1);
90
-
91
- # Check again if the memory limit is fine
92
- # If the memory limit did not increase, disable the widgets
93
- if ( $current_mem_limit < 96 && $current_mem_limit != '' ) {
94
- update_option(key_ga_widgets, 'disabled');
95
- } else {
96
97
- # Include Google Analytics Stats widget
98
- require_once('google-analytics-stats-widget.php');
99
100
- # Include the Google Analytics Summary widget
101
- require_once('google-analytics-summary-widget.php');
102
- $google_analytics_summary = new GoogleAnalyticsSummary();
103
-
104
- }
105
106
}
107
@@ -142,7 +122,10 @@ add_action('init', 'ga_outgoing_links');
142
143
// Hook in the options page function
144
function add_ga_option_page() {
145
- add_options_page(__('Google Analyticator Settings', 'google-analyticator'), 'Google Analytics', 8, basename(__FILE__), 'ga_options_page');
146
}
147
148
add_action('plugin_action_links_' . plugin_basename(__FILE__), 'ga_filter_plugin_actions');
@@ -332,77 +315,44 @@ function ga_options_page() {
332
</td>
333
</tr>
334
<?php
335
- # Get the current memory limit, after the update
336
- $current_mem_limit = substr(ini_get('memory_limit'), 0, -1);
337
# Check if we have a version of WordPress greater than 2.8, and check if we have the memory to use the api
338
- if ( function_exists('register_widget') && ( $current_mem_limit >= 96 || $current_mem_limit == '' ) ) {
339
- ?>
340
- <?php
341
- # Get the list of accounts if available
342
- $ga_accounts = ga_get_analytics_accounts();
343
?>
344
<tr>
345
<th width="30%" valign="top" style="padding-top: 10px;">
346
<label><?php _e('Authenticate with Google', 'google-analyticator'); ?>:</label>
347
</th>
348
<td>
349
- <?php if ( trim(get_option('ga_google_token')) == '' ) { ?>
350
<p style="margin-top: 7px;"><a href="https://www.google.com/accounts/AuthSubRequest?<?php echo http_build_query(array( 'next' => admin_url('/options-general.php?page=google-analyticator.php'),
351
'scope' => 'https://www.google.com/analytics/feeds/',
352
'secure' => 0,
353
'session' => 1,
354
'hd' => 'default'
355
)); ?>"><?php _e('Click here to login to Google, thus authenticating Google Analyticator with your Analytics account.', 'google-analyticator'); ?></a></p>
356
- <?php if ( isset($_GET['token']) && $_GET['token'] != 'deauth' && $ga_accounts == false ) { ?>
357
- <p style="color: red;"><?php _e('Failed to authenticate with Google. Try using the compatibility options at the bottom of this page. If you are still unable to authenticate, contact your host, informing them you are experiencing errors with outbound SSL connections.', 'google-analyticator'); ?></p>
358
- <?php } ?>
359
<?php } else { ?>
360
<p style="margin-top: 7px;"><?php _e('Currently authenticated with Google.', 'google-analyticator'); ?> <a href="<?php echo admin_url('/options-general.php?page=google-analyticator.php&token=deauth'); ?>"><?php _e('Deauthorize Google Analyticator.', 'google-analyticator'); ?></a></p>
361
<?php } ?>
362
<p style="margin: 5px 10px;" class="setting-description"><?php _e('Clicking the above link will authenticate Google Analyticator with Google. Authentication with Google is needed for use with the stats widget. In addition, authenticating will enable you to select your Analytics account through a drop-down instead of searching for your UID. If you are not going to use the stat widget, <strong>authenticating with Google is optional</strong>.', 'google-analyticator'); ?></p>
363
</td>
364
</tr>
365
- <?php } else { $ga_accounts = false; } ?>
366
- <tr>
367
- <?php
368
-
369
- # If we have a accounts, create a list, if not, use input box
370
- if ( $ga_accounts !== false ) :
371
- ?>
372
- <th valign="top" style="padding-top: 10px;">
373
- <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics account', 'google-analyticator'); ?>:</label>
374
- </th>
375
- <td>
376
- <?php
377
- # Create a select box
378
- echo '<select name="' . key_ga_uid . '" id="' . key_ga_uid . '">';
379
- echo '<option value="XX-XXXXX-X">' . __('Select an Account', 'google-analyticator') . '</option>';
380
-
381
- # The list of accounts
382
- foreach ( $ga_accounts AS $account ) {
383
- $select = ( get_option(key_ga_uid) == $account['ga:webPropertyId'] ) ? ' selected="selected"' : '';
384
- echo '<option value="' . $account['ga:webPropertyId'] . '"' . $select . '>' . $account['title'] . '</option>';
385
- }
386
-
387
- # Close the select box
388
- echo '</select>';
389
- ?>
390
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Select the Analytics account you wish to enable tracking for. An account must be selected for tracking to occur.', 'google-analyticator'); ?></p>
391
- </td>
392
- <?php else: ?>
393
- <th valign="top" style="padding-top: 10px;">
394
- <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics UID', 'google-analyticator'); ?>:</label>
395
- </th>
396
- <td>
397
- <?php
398
- echo "<input type='text' size='50' ";
399
- echo "name='".key_ga_uid."' ";
400
- echo "id='".key_ga_uid."' ";
401
- echo "value='".get_option(key_ga_uid)."' />\n";
402
- ?>
403
- <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>
404
- </td>
405
- <?php endif; ?>
406
</tr>
407
</table>
408
<h3><?php _e('Advanced Settings', 'google-analyticator'); ?></h3>
@@ -731,6 +681,83 @@ function ga_options_page() {
731
<?php
732
}
733
734
/**
735
* Checks if the WordPress API is a valid method for selecting an account
736
*
@@ -744,10 +771,12 @@ function ga_get_analytics_accounts()
744
require_once('class.analytics.stats.php');
745
746
# Create a new Gdata call
747
- if ( isset($_GET['token']) )
748
- $stats = new GoogleAnalyticsStats($_GET['token']);
749
- else
750
$stats = new GoogleAnalyticsStats();
751
752
# Check if Google sucessfully logged in
753
if ( ! $stats->checkLogin() )
1
<?php
2
/*
3
* Plugin Name: Google Analyticator
4
+ * Version: 5.3
5
* Plugin URI: http://plugins.spiralwebconsulting.com/analyticator.html
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: Spiral Web Consulting
9
* Text Domain: google-analyticator
10
*/
11
12
+ define('GOOGLE_ANALYTICATOR_VERSION', '5.3');
13
14
// Constants for enabled/disabled state
15
define("ga_enabled", "enabled", true);
73
# Check if we have a version of WordPress greater than 2.8
74
if ( function_exists('register_widget') ) {
75
76
# Check if widgets are enabled
77
if ( get_option(key_ga_widgets) == 'enabled' ) {
78
79
+ # Include Google Analytics Stats widget
80
+ require_once('google-analytics-stats-widget.php');
81
82
+ # Include the Google Analytics Summary widget
83
+ require_once('google-analytics-summary-widget.php');
84
+ $google_analytics_summary = new GoogleAnalyticsSummary();
85
86
}
87
122
123
// Hook in the options page function
124
function add_ga_option_page() {
125
+ $plugin_page = add_options_page(__('Google Analyticator Settings', 'google-analyticator'), 'Google Analytics', 8, basename(__FILE__), 'ga_options_page');
126
+
127
+ # Include javascript on the GA settings page
128
+ add_action('admin_head-' . $plugin_page, 'ga_admin_ajax');
129
}
130
131
add_action('plugin_action_links_' . plugin_basename(__FILE__), 'ga_filter_plugin_actions');
315
</td>
316
</tr>
317
<?php
318
# Check if we have a version of WordPress greater than 2.8, and check if we have the memory to use the api
319
+ if ( function_exists('register_widget') ) {
320
?>
321
<tr>
322
<th width="30%" valign="top" style="padding-top: 10px;">
323
<label><?php _e('Authenticate with Google', 'google-analyticator'); ?>:</label>
324
</th>
325
<td>
326
+ <?php if ( ( trim(get_option('ga_google_token')) == '' && !isset($_GET['token']) ) || ( isset($_GET['token']) && $_GET['token'] == 'deauth' ) ) { ?>
327
<p style="margin-top: 7px;"><a href="https://www.google.com/accounts/AuthSubRequest?<?php echo http_build_query(array( 'next' => admin_url('/options-general.php?page=google-analyticator.php'),
328
'scope' => 'https://www.google.com/analytics/feeds/',
329
'secure' => 0,
330
'session' => 1,
331
'hd' => 'default'
332
)); ?>"><?php _e('Click here to login to Google, thus authenticating Google Analyticator with your Analytics account.', 'google-analyticator'); ?></a></p>
333
<?php } else { ?>
334
<p style="margin-top: 7px;"><?php _e('Currently authenticated with Google.', 'google-analyticator'); ?> <a href="<?php echo admin_url('/options-general.php?page=google-analyticator.php&token=deauth'); ?>"><?php _e('Deauthorize Google Analyticator.', 'google-analyticator'); ?></a></p>
335
+ <?php if ( isset($_GET['token']) && $_GET['token'] != 'deauth' ) { ?>
336
+ <p style="color: red; display: none;" id="ga_connect_error"><?php _e('Failed to authenticate with Google. Try using the compatibility options at the bottom of this page. If you are still unable to authenticate, contact your host, informing them you are experiencing errors with outbound SSL connections.', 'google-analyticator'); ?></p>
337
+ <?php } ?>
338
<?php } ?>
339
<p style="margin: 5px 10px;" class="setting-description"><?php _e('Clicking the above link will authenticate Google Analyticator with Google. Authentication with Google is needed for use with the stats widget. In addition, authenticating will enable you to select your Analytics account through a drop-down instead of searching for your UID. If you are not going to use the stat widget, <strong>authenticating with Google is optional</strong>.', 'google-analyticator'); ?></p>
340
</td>
341
</tr>
342
+ <?php } ?>
343
+ <tr id="ga_ajax_accounts">
344
+ <th valign="top" style="padding-top: 10px;">
345
+ <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics UID', 'google-analyticator'); ?>:</label>
346
+ </th>
347
+ <td>
348
+ <?php
349
+ echo "<input type='text' size='50' ";
350
+ echo "name='".key_ga_uid."' ";
351
+ echo "id='".key_ga_uid."' ";
352
+ echo "value='".get_option(key_ga_uid)."' />\n";
353
+ ?>
354
+ <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>
355
+ </td>
356
</tr>
357
</table>
358
<h3><?php _e('Advanced Settings', 'google-analyticator'); ?></h3>
681
<?php
682
}
683
684
+ /**
685
+ * Adds AJAX to the GA settings page
686
+ **/
687
+ function ga_admin_ajax()
688
+ {
689
+ ?>
690
+ <script type="text/javascript">
691
+
692
+ jQuery(document).ready(function(){
693
+
694
+ // Grab the widget data
695
+ jQuery.ajax({
696
+ type: 'post',
697
+ url: 'admin-ajax.php',
698
+ data: {
699
+ action: 'ga_ajax_accounts',
700
+ _ajax_nonce: '<?php echo wp_create_nonce("ga_ajax_accounts"); ?>'<?php if ( isset($_GET['token']) ) { ?>,
701
+ token: '<?php echo $_GET["token"]; ?>'
702
+ <?php } ?>
703
+ },
704
+ success: function(html) {
705
+ if ( html != '' )
706
+ jQuery('#ga_ajax_accounts').html(html);
707
+ else
708
+ jQuery('#ga_connect_error').show();
709
+ }
710
+ });
711
+
712
+ });
713
+
714
+ </script>
715
+ <?php
716
+ }
717
+
718
+ # Look for the ajax list call
719
+ add_action('wp_ajax_ga_ajax_accounts', 'ga_ajax_accounts');
720
+
721
+ /**
722
+ * An AJAX function to get a list of accounts in a drop down
723
+ **/
724
+ function ga_ajax_accounts()
725
+ {
726
+ # Check the ajax widget
727
+ check_ajax_referer('ga_ajax_accounts');
728
+
729
+ # Get the list of accounts if available
730
+ $ga_accounts = ga_get_analytics_accounts();
731
+
732
+ if ( $ga_accounts !== false ) {
733
+ ?>
734
+
735
+ <th valign="top" style="padding-top: 10px;">
736
+ <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics account', 'google-analyticator'); ?>:</label>
737
+ </th>
738
+ <td>
739
+ <?php
740
+ # Create a select box
741
+ echo '<select name="' . key_ga_uid . '" id="' . key_ga_uid . '">';
742
+ echo '<option value="XX-XXXXX-X">' . __('Select an Account', 'google-analyticator') . '</option>';
743
+
744
+ # The list of accounts
745
+ foreach ( $ga_accounts AS $account ) {
746
+ $select = ( get_option(key_ga_uid) == $account['ga:webPropertyId'] ) ? ' selected="selected"' : '';
747
+ echo '<option value="' . $account['ga:webPropertyId'] . '"' . $select . '>' . $account['title'] . '</option>';
748
+ }
749
+
750
+ # Close the select box
751
+ echo '</select>';
752
+ ?>
753
+ <p style="margin: 5px 10px;" class="setting-description"><?php _e('Select the Analytics account you wish to enable tracking for. An account must be selected for tracking to occur.', 'google-analyticator'); ?></p>
754
+ </td>
755
+
756
+ <?php
757
+ }
758
+ die();
759
+ }
760
+
761
/**
762
* Checks if the WordPress API is a valid method for selecting an account
763
*
771
require_once('class.analytics.stats.php');
772
773
# Create a new Gdata call
774
+ if ( isset($_POST['token']) && $_POST['token'] != '' )
775
+ $stats = new GoogleAnalyticsStats($_POST['token']);
776
+ elseif ( trim(get_option('ga_google_token')) != '' )
777
$stats = new GoogleAnalyticsStats();
778
+ else
779
+ return false;
780
781
# Check if Google sucessfully logged in
782
if ( ! $stats->checkLogin() )
google-analytics-stats-widget.php CHANGED
@@ -75,6 +75,15 @@ class GoogleStatsWidget extends WP_Widget
75
76
$accounts = array();
77
78
# Get the class for interacting with the Google Analytics
79
require_once('class.analytics.stats.php');
80
@@ -204,6 +213,15 @@ class GoogleStatsWidget extends WP_Widget
204
}
205
206
# If here, the call has not been made or it is expired
207
208
# Get the class for interacting with the Google Analytics
209
require_once('class.analytics.stats.php');
75
76
$accounts = array();
77
78
+ # Get the current memory limit
79
+ $current_mem_limit = substr(ini_get('memory_limit'), 0, -1);
80
+
81
+ # Check if this limit is less than 96M, if so, increase it
82
+ if ( $current_mem_limit < 96 || $current_mem_limit == '' ) {
83
+ if ( function_exists('memory_get_usage') )
84
+ @ini_set('memory_limit', '96M');
85
+ }
86
+
87
# Get the class for interacting with the Google Analytics
88
require_once('class.analytics.stats.php');
89
213
}
214
215
# If here, the call has not been made or it is expired
216
+
217
+ # Get the current memory limit
218
+ $current_mem_limit = substr(ini_get('memory_limit'), 0, -1);
219
+
220
+ # Check if this limit is less than 96M, if so, increase it
221
+ if ( $current_mem_limit < 96 || $current_mem_limit == '' ) {
222
+ if ( function_exists('memory_get_usage') )
223
+ @ini_set('memory_limit', '96M');
224
+ }
225
226
# Get the class for interacting with the Google Analytics
227
require_once('class.analytics.stats.php');
google-analytics-summary-widget.php CHANGED
@@ -18,6 +18,7 @@ class GoogleAnalyticsSummary
18
add_action('wp_dashboard_setup', array($this, 'addDashboardWidget'));
19
add_action('admin_print_scripts-index.php', array($this, 'addJavascript'));
20
add_action('admin_head-index.php', array($this, 'addTopJs'));
21
}
22
23
/**
@@ -25,11 +26,10 @@ class GoogleAnalyticsSummary
25
**/
26
function addDashboardWidget()
27
{
28
- # Attempt to login and get the current account
29
- $this->id = $this->getAnalyticsAccount();
30
- $this->api->setAccount($this->id);
31
-
32
- wp_add_dashboard_widget('google-analytics-summary', __('Google Analytics Summary', 'google-analyticator'), array($this, 'widget'));
33
}
34
35
/**
@@ -51,17 +51,34 @@ class GoogleAnalyticsSummary
51
52
jQuery(document).ready(function(){
53
54
- if ( navigator.appName != 'Microsoft Internet Explorer' ) {
55
-
56
- jQuery('.ga_visits').sparkline(ga_visits, { type:'line', width:'100%', height:'75px', lineColor:'#aaa', fillColor:'#f0f0f0', spotColor:false, minSpotColor:false, maxSpotColor:false, chartRangeMin:0 });
57
-
58
- } else {
59
-
60
- // Hide the widget graph
61
- jQuery('.ga_visits_title').remove();
62
- jQuery('.ga_visits').remove();
63
-
64
- }
65
66
});
67
@@ -74,19 +91,34 @@ class GoogleAnalyticsSummary
74
**/
75
function widget()
76
{
77
# Check that we can display the widget before continuing
78
if ( $this->id == false ) {
79
# Output error message
80
- echo '<p>' . __('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>';
81
-
82
# Add Javascript variable to prevent breaking the Javascript
83
echo '<script type="text/javascript">var ga_visits = [];</script>';
84
-
85
- return false;
86
}
87
88
# Add the header information for the visits graph
89
- echo '<p class="ga_visits_title" style="font-style: italic; font-family: Georgia, \'Times New Roman\', \'Bitstream Charter\', Times, serif; margin-top: -5px; color: #777; font-size: 13px;">' . __('Visits Over the Past 30 Days', 'google-analyticator') . '</p>';
90
91
# Add the sparkline for the past 30 days
92
$this->getVisitsGraph();
@@ -123,6 +155,8 @@ class GoogleAnalyticsSummary
123
124
# Close the table
125
echo '</td></tr></table>';
126
}
127
128
/**
@@ -206,7 +240,7 @@ class GoogleAnalyticsSummary
206
$max = 0;
207
208
# Check the size of the stats array
209
- if ( count($stats) <= 0 || !is_array($stats) ) {
210
$data = '0,0';
211
} else {
212
foreach ( $stats AS $stat ) {
@@ -225,6 +259,10 @@ class GoogleAnalyticsSummary
225
$data = substr($data, 0, -1);
226
}
227
228
# Output the graph
229
echo '<script type="text/javascript">var ga_visits = [' . $data . '];</script>';
230
echo '<span class="ga_visits" title="' . sprintf(__('The most visits on a single day was %d. Yesterday there were %d visits.', 'google-analyticator'), $max, $stat['ga:visits']) . '"></span>';
18
add_action('wp_dashboard_setup', array($this, 'addDashboardWidget'));
19
add_action('admin_print_scripts-index.php', array($this, 'addJavascript'));
20
add_action('admin_head-index.php', array($this, 'addTopJs'));
21
+ add_action('wp_ajax_ga_stats_widget', array($this, 'ajaxWidget'));
22
}
23
24
/**
26
**/
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
}
34
35
/**
51
52
jQuery(document).ready(function(){
53
54
+ // Grab the widget data
55
+ jQuery.ajax({
56
+ type: 'post',
57
+ url: 'admin-ajax.php',
58
+ data: {
59
+ action: 'ga_stats_widget',
60
+ _ajax_nonce: '<?php echo wp_create_nonce("ga_stats_widget"); ?>'
61
+ },
62
+ success: function(html) {
63
+ // Hide the loading message
64
+ jQuery('#google-analytics-summary .inside').hide();
65
+
66
+ // Place the widget data in the area
67
+ jQuery('#google-analytics-summary .inside').html(html);
68
+
69
+ // Display the widget data
70
+ jQuery('#google-analytics-summary .inside').slideDown();
71
+
72
+ // Handle displaying the graph
73
+ if ( navigator.appName != 'Microsoft Internet Explorer' ) {
74
+ jQuery('.ga_visits').sparkline(ga_visits, { type:'line', width:'100%', height:'75px', lineColor:'#aaa', fillColor:'#f0f0f0', spotColor:false, minSpotColor:false, maxSpotColor:false, chartRangeMin:0 });
75
+ } else {
76
+ // Hide the widget graph
77
+ jQuery('.ga_visits_title').remove();
78
+ jQuery('.ga_visits').remove();
79
+ }
80
+ }
81
+ });
82
83
});
84
91
**/
92
function widget()
93
{
94
+ echo '<small>' . __('Loading') . '...</small>';
95
+ }
96
+
97
+ /**
98
+ * AJAX data for the widget
99
+ **/
100
+ function ajaxWidget()
101
+ {
102
+ # Check the ajax widget
103
+ check_ajax_referer('ga_stats_widget');
104
+
105
+ # Attempt to login and get the current account
106
+ $this->id = $this->getAnalyticsAccount();
107
+ $this->api->setAccount($this->id);
108
+
109
# Check that we can display the widget before continuing
110
if ( $this->id == false ) {
111
# Output error message
112
+ 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>';
113
+
114
# Add Javascript variable to prevent breaking the Javascript
115
echo '<script type="text/javascript">var ga_visits = [];</script>';
116
+
117
+ die();
118
}
119
120
# Add the header information for the visits graph
121
+ 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>';
122
123
# Add the sparkline for the past 30 days
124
$this->getVisitsGraph();
155
156
# Close the table
157
echo '</td></tr></table>';
158
+
159
+ die();
160
}
161
162
/**
240
$max = 0;
241
242
# Check the size of the stats array
243
+ if ( !isset($stats) || !is_array($stats) || count($stats) <= 0 ) {
244
$data = '0,0';
245
} else {
246
foreach ( $stats AS $stat ) {
259
$data = substr($data, 0, -1);
260
}
261
262
+ # Add a fake stat if need be
263
+ if ( !isset($stat['ga:visits']) )
264
+ $stat['ga:visits'] = 0;
265
+
266
# Output the graph
267
echo '<script type="text/javascript">var ga_visits = [' . $data . '];</script>';
268
echo '<span class="ga_visits" title="' . sprintf(__('The most visits on a single day was %d. Yesterday there were %d visits.', 'google-analyticator'), $max, $stat['ga:visits']) . '"></span>';
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: cavemonkey50, jesse_altman, spiralwebconsulting
3
Donate link: http://plugins.spiralwebconsulting.com/analyticator.html#donate
4
Tags: stats, statistics, google, analytics, google analytics, tracking, widget
5
Requires at least: 2.7
6
- Tested up to: 2.8.2
7
- Stable tag: 5.2.1
8
9
Adds the necessary JavaScript code to enable Google Analytics. Includes widgets for Analytics data display.
10
@@ -52,6 +52,11 @@ Please visit [Spiral Web Consulting's forum](http://plugins.spiralwebconsulting.
52
53
== Changelog ==
54
55
= 5.2.1 =
56
* Corrects a potential html sanitation vulnerability with text retrieved from the Google Analytics API.
57
3
Donate link: http://plugins.spiralwebconsulting.com/analyticator.html#donate
4
Tags: stats, statistics, google, analytics, google analytics, tracking, widget
5
Requires at least: 2.7
6
+ Tested up to: 2.8.3
7
+ Stable tag: 5.3
8
9
Adds the necessary JavaScript code to enable Google Analytics. Includes widgets for Analytics data display.
10
52
53
== Changelog ==
54
55
+ = 5.3 =
56
+ * Converts API data call to AJAX to reduce the memory needed on page loads.
57
+ * Removes memory_limit alterations, since the default amount should be enough now.
58
+ * Disables the summary dashboard widget for non-admins, as defined by the admin level setting on Google Analyticator's settings page.
59
+
60
= 5.2.1 =
61
* Corrects a potential html sanitation vulnerability with text retrieved from the Google Analytics API.
62