Version Description
Download this release
Release Info
Developer | cavemonkey50 |
Plugin | Google Analyticator |
Version | 4.2 |
Comparing to | |
See all releases |
Code changes from version 4.1.1 to 4.2
- google-analyticator.php +10 -4
- google-analytics-stats-widget.php +241 -0
- readme.txt +1 -1
google-analyticator.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
* Plugin Name: Google Analyticator
|
4 |
-
* Version: 4.
|
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
|
@@ -10,8 +10,14 @@
|
|
10 |
|
11 |
# Include Google Analytics Stats widget
|
12 |
if ( function_exists('curl_init') ) {
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
}
|
16 |
|
17 |
// Constants for enabled/disabled state
|
@@ -534,8 +540,8 @@ function add_ga_adsense() {
|
|
534 |
if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
|
535 |
// Display page tracking if user is not an admin
|
536 |
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' ) {
|
537 |
-
echo "<!-- Google Analytics Tracking by Google Analyticator: http://plugins.spiralwebconsulting.com/analyticator.html -->\n";
|
538 |
if ( get_option(key_ga_adsense) != '' ) {
|
|
|
539 |
echo ' <script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n\n";
|
540 |
}
|
541 |
}
|
1 |
<?php
|
2 |
/*
|
3 |
* Plugin Name: Google Analyticator
|
4 |
+
* Version: 4.2
|
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
|
10 |
|
11 |
# Include Google Analytics Stats widget
|
12 |
if ( function_exists('curl_init') ) {
|
13 |
+
|
14 |
+
# Check if we have a version of WordPress greater than 2.8
|
15 |
+
if ( substr( get_bloginfo('version'), 0, strpos(get_bloginfo('version'), '-') ) >= '2.8' )
|
16 |
+
require_once('google-analytics-stats-widget.php');
|
17 |
+
else {
|
18 |
+
require_once('google-analytics-stats.php');
|
19 |
+
$google_analytics_stats = new GoogleStatsWidget();
|
20 |
+
}
|
21 |
}
|
22 |
|
23 |
// Constants for enabled/disabled state
|
540 |
if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
|
541 |
// Display page tracking if user is not an admin
|
542 |
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' ) {
|
|
|
543 |
if ( get_option(key_ga_adsense) != '' ) {
|
544 |
+
echo "<!-- Google Analytics Tracking by Google Analyticator: http://plugins.spiralwebconsulting.com/analyticator.html -->\n";
|
545 |
echo ' <script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n\n";
|
546 |
}
|
547 |
}
|
google-analytics-stats-widget.php
ADDED
@@ -0,0 +1,241 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* The Google Analytics Stats Widget
|
5 |
+
*
|
6 |
+
* Now using widget API available in WordPress 2.8
|
7 |
+
* @author Spiral Web Consulting
|
8 |
+
**/
|
9 |
+
class GoogleStatsWidget extends WP_Widget
|
10 |
+
{
|
11 |
+
function GoogleStatsWidget() {
|
12 |
+
$widget_ops = array('classname' => 'widget_google_stats', 'description' => __( "Displays Stat Info From Google Analytics") );
|
13 |
+
$control_ops = array('width' => 400, 'height' => 400);
|
14 |
+
$this->WP_Widget('googlestats', __('Google Analytics Stats'), $widget_ops, $control_ops);
|
15 |
+
}
|
16 |
+
|
17 |
+
function widget($args, $instance) {
|
18 |
+
extract($args);
|
19 |
+
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
|
20 |
+
$acnt = $instance['account'];
|
21 |
+
$timeFrame = empty($instance['timeFrame']) ? '1' : $instance['timeFrame'];
|
22 |
+
$pageBg = empty($instance['pageBg']) ? 'fff' : $instance['pageBg'];
|
23 |
+
$widgetBg = empty($instance['widgetBg']) ? '999' : $instance['widgetBg'];
|
24 |
+
$innerBg = empty($instance['innerBg']) ? 'fff' : $instance['innerBg'];
|
25 |
+
$font = empty($instance['font']) ? '333' : $instance['font'];
|
26 |
+
$line1 = empty($instance['line1']) ? 'Unique' : $instance['line1'];
|
27 |
+
$line2 = empty($instance['line2']) ? 'Visitors' : $instance['line2'];
|
28 |
+
|
29 |
+
# Before the widget
|
30 |
+
echo $before_widget;
|
31 |
+
|
32 |
+
# The title
|
33 |
+
if ( $title )
|
34 |
+
echo $before_title . $title . $after_title;
|
35 |
+
|
36 |
+
# Make the stats chicklet
|
37 |
+
$this->initiateBackground($pageBg, $font);
|
38 |
+
$this->beginWidget($font, $widgetBg);
|
39 |
+
$this->widgetInfo($this->getUniqueVisitors($acnt, $timeFrame), $line1, $line2, $innerBg, $font);
|
40 |
+
$this->endWidget();
|
41 |
+
|
42 |
+
# After the widget
|
43 |
+
echo $after_widget;
|
44 |
+
}
|
45 |
+
|
46 |
+
function update($new_instance, $old_instance) {
|
47 |
+
$instance = $old_instance;
|
48 |
+
$instance['title'] = strip_tags(stripslashes($new_instance['title']));
|
49 |
+
$instance['account'] = strip_tags(stripslashes($new_instance['account']));
|
50 |
+
$instance['timeFrame'] = strip_tags(stripslashes($new_instance['timeFrame']));
|
51 |
+
$instance['pageBg'] = strip_tags(stripslashes($new_instance['pageBg']));
|
52 |
+
$instance['widgetBg'] = strip_tags(stripslashes($new_instance['widgetBg']));
|
53 |
+
$instance['innerBg'] = strip_tags(stripslashes($new_instance['innerBg']));
|
54 |
+
$instance['font'] = strip_tags(stripslashes($new_instance['font']));
|
55 |
+
$instance['line1'] = strip_tags(stripslashes($new_instance['line1']));
|
56 |
+
$instance['line2'] = strip_tags(stripslashes($new_instance['line2']));
|
57 |
+
|
58 |
+
return $instance;
|
59 |
+
}
|
60 |
+
|
61 |
+
function form($instance) {
|
62 |
+
//Defaults
|
63 |
+
$instance = wp_parse_args( (array) $instance, array('title'=>'', 'account'=>'', 'timeFrame'=>'1', 'pageBg'=>'fff', 'widgetBg'=>'999', 'innerBg'=>'fff', 'font'=>'333', 'line1'=>'Unique', 'line2'=>'Visitors') );
|
64 |
+
|
65 |
+
$title = htmlspecialchars($instance['title']);
|
66 |
+
$acnt = htmlspecialchars($instance['account']);
|
67 |
+
$timeFrame = htmlspecialchars($instance['timeFrame']);
|
68 |
+
$pageBg = htmlspecialchars($instance['pageBg']);
|
69 |
+
$widgetBg = htmlspecialchars($instance['widgetBg']);
|
70 |
+
$innerBg = htmlspecialchars($instance['innerBg']);
|
71 |
+
$font = htmlspecialchars($instance['font']);
|
72 |
+
$line1 = htmlspecialchars($instance['line1']);
|
73 |
+
$line2 = htmlspecialchars($instance['line2']);
|
74 |
+
|
75 |
+
$accounts = array();
|
76 |
+
|
77 |
+
# Check if a username has been set
|
78 |
+
if ( get_option('google_stats_user') != '' ) {
|
79 |
+
|
80 |
+
# Get the class for interacting with the Google Analytics
|
81 |
+
require_once('class.analytics.stats.php');
|
82 |
+
|
83 |
+
# Create a new Gdata call
|
84 |
+
$stats = new GoogleAnalyticsStats(stripslashes(get_option('google_stats_user')), stripslashes(get_option('google_stats_password')), true);
|
85 |
+
|
86 |
+
# Get a list of accounts
|
87 |
+
$accounts = $stats->getAnalyticsAccounts();
|
88 |
+
|
89 |
+
}
|
90 |
+
|
91 |
+
# Output the options
|
92 |
+
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('title') . '">' . __('Title:') . ' <input style="width: 250px;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>';
|
93 |
+
# The list of accounts
|
94 |
+
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('account') . '">' . __('Analytics account: ');
|
95 |
+
echo '<select name="' . $this->get_field_name('account') . '" id="' . $this->get_field_id('account') . '" style="margin-top: -3px; margin-bottom: 10px;">';
|
96 |
+
if ( count($accounts) > 0 )
|
97 |
+
foreach ( $accounts AS $account ) { $select = ( $acnt == $account['id'] ) ? ' selected="selected"' : ''; echo '<option value="' . $account['id'] . '"' . $select . '>' . $account['title'] . '</option>'; }
|
98 |
+
else
|
99 |
+
echo '<option value="">No accounts. Set user/pass in settings.</option>';
|
100 |
+
echo '</select>';
|
101 |
+
# Time frame
|
102 |
+
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('timeFrame') . '">' . __('Days of data to get:') . ' <input style="width: 150px;" id="' . $this->get_field_id('timeFrame') . '" name="' . $this->get_field_name('timeFrame') . '" type="text" value="' . $timeFrame . '" /></label></p>';
|
103 |
+
# Page background
|
104 |
+
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('pageBg') . '">' . __('Page background:') . ' <input style="width: 150px;" id="' . $this->get_field_id('pageBg') . '" name="' . $this->get_field_name('pageBg') . '" type="text" value="' . $pageBg . '" /></label></p>';
|
105 |
+
# Widget background
|
106 |
+
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('widgetBg') . '">' . __('Widget background:') . ' <input style="width: 150px;" id="' . $this->get_field_id('widgetBg') . '" name="' . $this->get_field_name('widgetBg') . '" type="text" value="' . $widgetBg . '" /></label></p>';
|
107 |
+
# Inner background
|
108 |
+
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('innerBg') . '">' . __('Inner background:') . ' <input style="width: 150px;" id="' . $this->get_field_id('innerBg') . '" name="' . $this->get_field_name('innerBg') . '" type="text" value="' . $innerBg . '" /></label></p>';
|
109 |
+
# Font color
|
110 |
+
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('font') . '">' . __('Font color:') . ' <input style="width: 150px;" id="' . $this->get_field_id('font') . '" name="' . $this->get_field_name('font') . '" type="text" value="' . $font . '" /></label></p>';
|
111 |
+
# Text line 1
|
112 |
+
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('line1') . '">' . __('Line 1 text:') . ' <input style="width: 200px;" id="' . $this->get_field_id('line1') . '" name="' . $this->get_field_name('line1') . '" type="text" value="' . $line1 . '" /></label></p>';
|
113 |
+
# Text line 2
|
114 |
+
echo '<p style="text-align:right;"><label for="' . $this->get_field_name('line2') . '">' . __('Line 2 text:') . ' <input style="width: 200px;" id="' . $this->get_field_id('line2') . '" name="' . $this->get_field_name('line2') . '" type="text" value="' . $line2 . '" /></label></p>';
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* This function is used to display the background color behind the widget. This is necessary
|
119 |
+
* for the Google Analytics text to have the same background color as the page.
|
120 |
+
*
|
121 |
+
* @param $font_color - Hexadecimal value for the font color used within the Widget (does not effect "Powered By Google Analytics Text"). This effects border color as well.
|
122 |
+
* @param $page_background_color - Hexadecimal value for the page background color
|
123 |
+
* @return void
|
124 |
+
**/
|
125 |
+
function initiateBackground($page_background_color = 'FFF', $font_color = '000')
|
126 |
+
{
|
127 |
+
echo '<br />';
|
128 |
+
echo '<div style="background:#' . $page_background_color . ';font-size:12px;color:#' . $font_color . ';font-family:"Lucida Grande",Helvetica,Verdana,Sans-Serif;">';
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* This function starts the widget. The font color and widget background color are customizable.
|
133 |
+
*
|
134 |
+
* @param $font_color - Hexadecimal value for the font color used within the Widget (does not effect "Powered By Google Analytics Text"). This effects border color as well.
|
135 |
+
* @param $widget_background_color - Hexadecimal value for the widget background color.
|
136 |
+
* @return void
|
137 |
+
**/
|
138 |
+
function beginWidget($font_color = '000', $widget_background_color = 'FFF')
|
139 |
+
{
|
140 |
+
echo '<table style="width:auto!important;border-width:2px;border-color:#' . $font_color . ';border-style:solid;background:#' . $widget_background_color . ';"><tr">';
|
141 |
+
}
|
142 |
+
|
143 |
+
/**
|
144 |
+
* This function encases the text that appears on the right hand side of the widget.
|
145 |
+
* Both lines of text are customizable by each individual user.
|
146 |
+
*
|
147 |
+
* It also displays the visitor count that was pulled from the user's Google Analytics account.
|
148 |
+
*
|
149 |
+
* @param $visitor_count - Number of unique visits to the site pulled from the user's Google Analytics account.
|
150 |
+
* @param $line_one - First line of text displayed on the right hand side of the widget.
|
151 |
+
* @param $line_two - Second line of text displayed on the right hand side of the widget.
|
152 |
+
* @param $inner_background_color - Hexadecimal value for the background color that surrounds the Visitor Count.
|
153 |
+
* @param $font_color - Hexadecimal value for the font color used within the Widget (does not effect "Powered By Google Analytics Text"). This effects border color as well
|
154 |
+
* @return void
|
155 |
+
**/
|
156 |
+
function widgetInfo($visitor_count, $line_one = 'Unique', $line_two = 'Visitors', $inner_background_color = 'FFF', $font_color = '000')
|
157 |
+
{
|
158 |
+
|
159 |
+
echo '<td style="width:auto!important;border-width:1px;border-color:#' . $font_color . ';border-style:solid;padding:0px 5px 0px 5px;text-align:right;background:#' . $inner_background_color . ';min-width:80px;*width:80px!important;"><div style="min-width:80px;">'. $visitor_count . '</div></td>';
|
160 |
+
|
161 |
+
echo '<td style="width:auto!important;padding:0px 5px 0px 5px;text-align:center;font-size:11px;">' . $line_one . '<br />' . $line_two . '</td>';
|
162 |
+
|
163 |
+
}
|
164 |
+
|
165 |
+
/**
|
166 |
+
* The function is used strictly for visual appearance. It also displays the Google Analytics text.
|
167 |
+
*
|
168 |
+
* @return void
|
169 |
+
**/
|
170 |
+
function endWidget()
|
171 |
+
{
|
172 |
+
// This closes off the widget.
|
173 |
+
echo '</tr></table>';
|
174 |
+
|
175 |
+
// The following is used to displayed the "Powered By Google Anayltics" text.
|
176 |
+
echo '<div style="font-size:9px;color:#666666;margin-top:0px;font-family:Verdana;">Powered By <a href="http://google.com/analytics/" alt="Google Analytics" style="text-decoration:none;"><img src="' . plugins_url('/google-analyticator/ga_logo.png') . '" alt="Google Analytics" style="border:0px;position:relative;top:4px;" /></a></div></div>';
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Grabs the cached value of the unique visits for the previous day
|
181 |
+
*
|
182 |
+
* @param account - the account to get the unique visitors from
|
183 |
+
* @param time - the amount of days to get
|
184 |
+
* @return void
|
185 |
+
**/
|
186 |
+
function getUniqueVisitors($account, $time = 1)
|
187 |
+
{
|
188 |
+
# Get the value from the database
|
189 |
+
$visits = unserialize(get_option('google_stats_visits_' . $account));
|
190 |
+
|
191 |
+
# Check to make sure the timeframe is an int and greater than one
|
192 |
+
$time = (int) $time;
|
193 |
+
if ( $time < 1 )
|
194 |
+
$time = 1;
|
195 |
+
|
196 |
+
# Check if the call has been made before
|
197 |
+
if ( is_array($visits) ) {
|
198 |
+
|
199 |
+
# Check if the last time called was within two hours, if so, return that
|
200 |
+
if ( $visits['lastcalled'] > ( time() - 7200 ) )
|
201 |
+
return $visits['unique'];
|
202 |
+
|
203 |
+
}
|
204 |
+
|
205 |
+
# If here, the call has not been made or it is expired
|
206 |
+
|
207 |
+
# Get the class for interacting with the Google Analytics
|
208 |
+
require_once('class.analytics.stats.php');
|
209 |
+
|
210 |
+
# Create a new Gdata call
|
211 |
+
$stats = new GoogleAnalyticsStats(stripslashes(get_option('google_stats_user')), stripslashes(get_option('google_stats_password')), true);
|
212 |
+
|
213 |
+
# Set the account to the one requested
|
214 |
+
$stats->setAccount($account);
|
215 |
+
|
216 |
+
# Get the latest stats
|
217 |
+
$before = date('Y-m-d', strtotime('-' . $time . ' days'));
|
218 |
+
$yesterday = date('Y-m-d', strtotime('-1 day'));
|
219 |
+
$uniques = number_format($stats->getMetric('ga:visitors', $before, $yesterday));
|
220 |
+
|
221 |
+
# Make the array for database storage
|
222 |
+
$visit = serialize(array('unique'=>$uniques, 'lastcalled'=>time()));
|
223 |
+
|
224 |
+
# Store the array
|
225 |
+
update_option('google_stats_visits_' . $account, $visit);
|
226 |
+
|
227 |
+
# Return the visits
|
228 |
+
return $uniques;
|
229 |
+
}
|
230 |
+
|
231 |
+
}// END class
|
232 |
+
|
233 |
+
/**
|
234 |
+
* Register Google Analytics Stat Widget.
|
235 |
+
*/
|
236 |
+
function GoogleStatsWidget_init() {
|
237 |
+
register_widget('GoogleStatsWidget');
|
238 |
+
}
|
239 |
+
|
240 |
+
add_action('widgets_init', 'GoogleStatsWidget_init');
|
241 |
+
?>
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: cavemonkey50, spiralwebconsulting
|
|
3 |
Tags: stats, google, analytics, tracking
|
4 |
Requires at least: 2.7
|
5 |
Tested up to: 2.8
|
6 |
-
Stable tag: 4.
|
7 |
|
8 |
Adds the necessary JavaScript code to enable Google Analytics.
|
9 |
|
3 |
Tags: stats, google, analytics, tracking
|
4 |
Requires at least: 2.7
|
5 |
Tested up to: 2.8
|
6 |
+
Stable tag: 4.2
|
7 |
|
8 |
Adds the necessary JavaScript code to enable Google Analytics.
|
9 |
|