Google Analyticator - Version 6.3.3

Version Description

  • Using the admin_url() function for internal links. Should help people with WP installed in a sub directory.
  • Added all vars to reset function to delete / deauthorize from Google.
Download this release

Release Info

Developer VideoUserManuals
Plugin Icon 128x128 Google Analyticator
Version 6.3.3
Comparing to
See all releases

Code changes from version 6.2 to 6.3.3

Files changed (43) hide show
  1. class.analytics.stats.php +249 -360
  2. download-button.png +0 -0
  3. external-tracking.js +43 -43
  4. external-tracking.min.js +4 -4
  5. google-analyticator.php +1049 -1036
  6. google-analytics-stats-widget.php +254 -256
  7. google-analytics-summary-widget.php +617 -603
  8. google-api-php-client/src/Google_Client.php +465 -0
  9. google-api-php-client/src/auth/Google_AssertionCredentials.php +95 -0
  10. google-api-php-client/src/auth/Google_Auth.php +36 -0
  11. google-api-php-client/src/auth/Google_AuthNone.php +48 -0
  12. google-api-php-client/src/auth/Google_LoginTicket.php +63 -0
  13. google-api-php-client/src/auth/Google_OAuth2.php +444 -0
  14. google-api-php-client/src/auth/Google_P12Signer.php +66 -0
  15. google-api-php-client/src/auth/Google_PemVerifier.php +66 -0
  16. google-api-php-client/src/auth/Google_Signer.php +30 -0
  17. google-api-php-client/src/auth/Google_Verifier.php +31 -0
  18. google-api-php-client/src/cache/Google_ApcCache.php +98 -0
  19. google-api-php-client/src/cache/Google_Cache.php +55 -0
  20. google-api-php-client/src/cache/Google_FileCache.php +137 -0
  21. google-api-php-client/src/cache/Google_MemcacheCache.php +130 -0
  22. google-api-php-client/src/config.php +81 -0
  23. google-api-php-client/src/contrib/Google_AdsenseService.php +1144 -0
  24. google-api-php-client/src/contrib/Google_AnalyticsService.php +1887 -0
  25. google-api-php-client/src/contrib/Google_Oauth2Service.php +265 -0
  26. google-api-php-client/src/external/URITemplateParser.php +213 -0
  27. google-api-php-client/src/io/Google_CacheParser.php +173 -0
  28. google-api-php-client/src/io/Google_CurlIO.php +278 -0
  29. google-api-php-client/src/io/Google_HttpRequest.php +304 -0
  30. google-api-php-client/src/io/Google_IO.php +49 -0
  31. google-api-php-client/src/io/Google_REST.php +128 -0
  32. google-api-php-client/src/io/cacerts.pem +714 -0
  33. google-api-php-client/src/service/Google_BatchRequest.php +110 -0
  34. google-api-php-client/src/service/Google_MediaFileUpload.php +244 -0
  35. google-api-php-client/src/service/Google_Model.php +115 -0
  36. google-api-php-client/src/service/Google_Service.php +22 -0
  37. google-api-php-client/src/service/Google_ServiceResource.php +196 -0
  38. google-api-php-client/src/service/Google_Utils.php +117 -0
  39. google-api-php-client/static/Credentials.png +0 -0
  40. jquery.sparkline.min.js +84 -84
  41. privacy.png +0 -0
  42. readme.txt +40 -10
  43. wlcms-plugin-advert.png +0 -0
class.analytics.stats.php CHANGED
@@ -1,360 +1,249 @@
1
- <?php
2
-
3
- # Include SimplePie if it doesn't exist
4
- if ( !class_exists('SimplePie') ) {
5
- require_once (ABSPATH . WPINC . '/class-feed.php');
6
- }
7
-
8
- /**
9
- * Handles interactions with Google Analytics' Stat API
10
- *
11
- * @author Spiral Web Consulting
12
- **/
13
- class GoogleAnalyticsStats
14
- {
15
-
16
- # Class variables
17
- var $baseFeed = 'https://www.google.com/analytics/feeds';
18
- var $accountId;
19
- var $token = false;
20
- var $responseHash = array();
21
- var $responseCode = '';
22
-
23
- /**
24
- * Constructor
25
- *
26
- * @param token - a one-time use token to be exchanged for a real token
27
- **/
28
- function GoogleAnalyticsStats($token = false)
29
- {
30
- # If we need to request a permanent token
31
- if ( $token ) {
32
-
33
- # Check if we're deauthorizing an account
34
- if ( $token == 'deauth' ) {
35
-
36
- # Get the current token
37
- $this->token = get_option('ga_google_token');
38
-
39
- # Revoke the current token
40
- $response = $this->http('https://www.google.com/accounts/AuthSubRevokeToken');
41
-
42
- # Remove the current token
43
- update_option('ga_google_token', '');
44
-
45
- return '';
46
-
47
- }
48
-
49
- $this->token = $token;
50
-
51
- # Request authentication with Google
52
- $response = $this->http('https://www.google.com/accounts/AuthSubSessionToken');
53
-
54
- # Get the authentication token
55
- $this->token = substr(strstr($response, "Token="), 6);
56
-
57
- # Save the token for future use
58
- update_option('ga_google_token', $this->token);
59
-
60
- # Remove the old username and password fields if they still exists
61
- delete_option('google_stats_user');
62
- delete_option('google_stats_password');
63
-
64
- } else {
65
- $this->token = get_option('ga_google_token');
66
- }
67
- }
68
-
69
- /**
70
- * Connects using the WordPress HTTP API to get data
71
- *
72
- * @param url - url to request
73
- * @param post - post data to pass through WordPress
74
- * @return the raw http response
75
- **/
76
- function http($url, $post = false)
77
- {
78
- # Return false if the token has not been set
79
- if ( trim($this->token) == '' )
80
- return '';
81
-
82
- # Set the arguments to pass to WordPress
83
- $args = array(
84
- 'sslverify' => false
85
- );
86
-
87
- # Add the optional post values
88
- if ( $post ) {
89
- $post .= '&service=analytics&source=google-analyticator-' . GOOGLE_ANALYTICATOR_VERSION;
90
- $args['body'] = $post;
91
- }
92
-
93
- # Set the content to form data
94
- $args['headers'] = array('Content-Type' => 'application/x-www-form-urlencoded');
95
-
96
- # Add the token information
97
- if ( $this->token ) {
98
- $args['headers']['Authorization'] = 'AuthSub token="' . $this->token . '"';
99
- }
100
-
101
- # Disable the fopen transport since it doesn't work with the Google API
102
- add_filter('use_fopen_transport', create_function('$a', 'return false;'));
103
-
104
- # Check compatibility mode settings
105
- if ( get_option('ga_compatibility') == 'level1' ) {
106
- add_filter('use_curl_transport', create_function('$a', 'return false;'));
107
- } elseif ( get_option('ga_compatibility') == 'level2' ) {
108
- add_filter('use_curl_transport', create_function('$a', 'return false;'));
109
- add_filter('use_streams_transport', create_function('$a', 'return false;'));
110
- }
111
-
112
- # Make the connection
113
- if ( $post )
114
- $response = wp_remote_post($url, $args);
115
- else
116
- $response = wp_remote_get($url, $args);
117
-
118
- # Check for WordPress error
119
- if ( is_wp_error($response) ) {
120
- $this->responseHash['error'] = __('WordPress HTTP error.', 'google-analyticator');
121
- return '';
122
- }
123
-
124
- # Set the message response
125
- $this->responseCode = $response['response']['code'];
126
-
127
- # Build an array of messages
128
- foreach( explode("\n", $response['body']) as $line ) {
129
- if ( trim($line) != '' ) {
130
- $pos = strpos($line, '=');
131
- if ( $pos !== false ) {
132
- $this->responseHash[strtolower(substr($line, 0, $pos))] = substr($line, $pos+1);
133
- }
134
- }
135
- }
136
-
137
- # Return the body of the response
138
- return $response['body'];
139
- }
140
-
141
- /**
142
- * Checks if the username and password worked by looking at the token
143
- *
144
- * @return Boolean if the login details worked
145
- **/
146
- function checkLogin()
147
- {
148
- if ( $this->token != false )
149
- return true;
150
- else
151
- return false;
152
- }
153
-
154
- /**
155
- * Sets the account id to use for queries
156
- *
157
- * @param id - the account id
158
- **/
159
- function setAccount($id)
160
- {
161
- $this->accountId = $id;
162
- }
163
-
164
- /**
165
- * Get a list of Analytics accounts
166
- *
167
- * @return a list of analytics accounts
168
- **/
169
- function getAnalyticsAccounts()
170
- {
171
- # Request the list of accounts
172
- $response = $this->http($this->baseFeed . '/accounts/default');
173
-
174
- # Check if the response received exists, else stop processing now
175
- if ( $response == '' || $this->responseCode != '200' )
176
- return false;
177
-
178
- # Parse the XML using SimplePie
179
- $simplePie = new SimplePie();
180
- $simplePie->set_raw_data($response);
181
- $simplePie->init();
182
- $simplePie->handle_content_type();
183
- $accounts = $simplePie->get_items();
184
-
185
- # Make an array of the accounts
186
- $ids = array();
187
- foreach ( $accounts AS $account ) {
188
- $id = array();
189
-
190
- # Get the list of properties
191
- $properties = $account->get_item_tags('http://schemas.google.com/analytics/2009', 'property');
192
-
193
- # Loop through the properties
194
- foreach ( $properties AS $property ) {
195
-
196
- # Get the property information
197
- $name = $property['attribs']['']['name'];
198
- $value = $property['attribs']['']['value'];
199
-
200
- # Add the propery data to the id array
201
- $id[$name] = $value;
202
-
203
- }
204
-
205
- # Add the backward compatibility array items
206
- $id['title'] = $account->get_title();
207
- $id['id'] = 'ga:' . $id['ga:profileId'];
208
-
209
- $ids[] = $id;
210
- }
211
-
212
- return $ids;
213
- }
214
-
215
- /**
216
- * Get a specific data metric
217
- *
218
- * @param metric - the metric to get
219
- * @param startDate - the start date to get
220
- * @param endDate - the end date to get
221
- * @return the specific metric
222
- **/
223
- function getMetric($metric, $startDate, $endDate)
224
- {
225
- # Ensure the start date is after Jan 1 2005
226
- $startDate = $this->verifyStartDate($startDate);
227
-
228
- # Request the metric data
229
- $response = $this->http($this->baseFeed . "/data?ids=$this->accountId&start-date=$startDate&end-date=$endDate&metrics=$metric");
230
-
231
- # Check if the response received exists, else stop processing now
232
- if ( $response == '' || $this->responseCode != '200' )
233
- return false;
234
-
235
- # Parse the XML using SimplePie
236
- $simplePie = new SimplePie();
237
- $simplePie->set_raw_data($response);
238
- $simplePie->init();
239
- $simplePie->handle_content_type();
240
- $datas = $simplePie->get_items();
241
-
242
- # Read out the data until the metric is found
243
- foreach ( $datas AS $data ) {
244
- $data_tag = $data->get_item_tags('http://schemas.google.com/analytics/2009', 'metric');
245
- return $data_tag[0]['attribs']['']['value'];
246
- }
247
- }
248
-
249
- /**
250
- * Get a specific data metrics
251
- *
252
- * @param metrics - the metrics to get
253
- * @param startDate - the start date to get
254
- * @param endDate - the end date to get
255
- * @param dimensions - the dimensions to grab
256
- * @param sort - the properties to sort on
257
- * @param filter - the property to filter on
258
- * @param limit - the number of items to get
259
- * @return the specific metrics in array form
260
- **/
261
- function getMetrics($metric, $startDate, $endDate, $dimensions = false, $sort = false, $filter = false, $limit = false)
262
- {
263
- # Ensure the start date is after Jan 1 2005
264
- $startDate = $this->verifyStartDate($startDate);
265
-
266
- # Build the query url
267
- $url = $this->baseFeed . "/data?ids=$this->accountId&start-date=$startDate&end-date=$endDate&metrics=$metric";
268
-
269
- # Add optional dimensions
270
- if ( $dimensions )
271
- $url .= "&dimensions=$dimensions";
272
-
273
- # Add optional sort
274
- if ( $sort )
275
- $url .= "&sort=$sort";
276
-
277
- # Add optional filter
278
- if ( $filter )
279
- $url .= "&filters=$filter";
280
-
281
- # Add optional limit
282
- if ( $limit )
283
- $url .= "&max-results=$limit";
284
-
285
- # Request the metric data
286
- $response = $this->http($url);
287
-
288
- # Check if the response received exists, else stop processing now
289
- if ( $response == '' || $this->responseCode != '200' )
290
- return false;
291
-
292
- # Parse the XML using SimplePie
293
- $simplePie = new SimplePie();
294
- $simplePie->set_raw_data($response);
295
- $simplePie->enable_order_by_date(false);
296
- $simplePie->init();
297
- $simplePie->handle_content_type();
298
- $datas = $simplePie->get_items();
299
-
300
- $ids = array();
301
-
302
- # Read out the data until the metric is found
303
- foreach ( $datas AS $data ) {
304
- $metrics = $data->get_item_tags('http://schemas.google.com/analytics/2009', 'metric');
305
- $dimensions = $data->get_item_tags('http://schemas.google.com/analytics/2009', 'dimension');
306
- $id = array();
307
-
308
- $id['title'] = $data->get_title();
309
-
310
- # Loop through the dimensions
311
- if ( is_array($dimensions) ) {
312
- foreach ( $dimensions AS $property ) {
313
-
314
- # Get the property information
315
- $name = $property['attribs']['']['name'];
316
- $value = $property['attribs']['']['value'];
317
-
318
- # Add the propery data to the id array
319
- $id[$name] = $value;
320
-
321
- }
322
- }
323
-
324
- # Loop through the metrics
325
- if ( is_array($metrics) ) {
326
- foreach ( $metrics AS $property ) {
327
-
328
- # Get the property information
329
- $name = $property['attribs']['']['name'];
330
- $value = $property['attribs']['']['value'];
331
-
332
- # Add the propery data to the id array
333
- $id[$name] = $value;
334
-
335
- }
336
- }
337
-
338
- $ids[] = $id;
339
- }
340
-
341
- return $ids;
342
- }
343
-
344
- /**
345
- * Checks the date against Jan. 1 2005 because GA API only works until that date
346
- *
347
- * @param date - the date to compare
348
- * @return the correct date
349
- **/
350
- function verifyStartDate($date)
351
- {
352
- if ( strtotime($date) > strtotime('2005-01-01') )
353
- return $date;
354
- else
355
- return '2005-01-01';
356
- }
357
-
358
- } // END class
359
-
360
- ?>
1
+ <?php
2
+
3
+ # Include SimplePie if it doesn't exist
4
+ if ( !class_exists('SimplePie') ) {
5
+ require_once (ABSPATH . WPINC . '/class-feed.php');
6
+ }
7
+
8
+ require_once 'google-api-php-client/src/Google_Client.php';
9
+ require_once 'google-api-php-client/src/contrib/Google_AnalyticsService.php';
10
+
11
+ /**
12
+ * Handles interactions with Google Analytics' Stat API
13
+ *
14
+ * @author http://www.codebyjeff.com
15
+ **/
16
+ class GoogleAnalyticsStats
17
+ {
18
+
19
+ var $client = false;
20
+ var $accountId;
21
+ var $baseFeed = 'https://www.googleapis.com/analytics/v3';
22
+ var $token = false;
23
+
24
+
25
+ /**
26
+ * Constructor
27
+ *
28
+ * @param token - a one-time use token to be exchanged for a real token
29
+ **/
30
+ function GoogleAnalyticsStats()
31
+ {
32
+
33
+ $this->client = new Google_Client();
34
+
35
+ $this->client->setClientId(GOOGLE_ANALYTICATOR_CLIENTID);
36
+ $this->client->setClientSecret(GOOGLE_ANALYTICATOR_CLIENTSECRET);
37
+ $this->client->setRedirectUri(GOOGLE_ANALYTICATOR_REDIRECT);
38
+ $this->client->setScopes(array(GOOGLE_ANALYTICATOR_SCOPE));
39
+
40
+ // Magic. Returns objects from the Analytics Service instead of associative arrays.
41
+ $this->client->setUseObjects(true);
42
+
43
+ try {
44
+ $this->analytics = new Google_AnalyticsService($this->client);
45
+ }
46
+ catch (Google_ServiceException $e)
47
+ {
48
+ print 'There was an Analytics API service error ' . $e->getCode() . ':' . $e->getMessage();
49
+
50
+ }
51
+
52
+ }
53
+
54
+ function checkLogin()
55
+ {
56
+ $ga_google_authtoken = get_option('ga_google_authtoken');
57
+
58
+ if (!empty($ga_google_authtoken))
59
+ {
60
+ $this->client->setAccessToken($ga_google_authtoken);
61
+ }
62
+ else
63
+ {
64
+ $authCode = get_option('ga_google_token');
65
+
66
+ if (empty($authCode)) return false;
67
+
68
+
69
+ $accessToken = $this->client->authenticate($authCode);
70
+
71
+ if($accessToken)
72
+ {
73
+ $this->client->setAccessToken($accessToken);
74
+ update_option('ga_google_authtoken', $accessToken);
75
+ }
76
+ else
77
+ {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ $this->token = $this->client->getAccessToken();
83
+ return true;
84
+ }
85
+
86
+ function deauthorize()
87
+ {
88
+ update_option('ga_google_token', '');
89
+ update_option('ga_google_authtoken', '');
90
+ }
91
+
92
+ function getSingleProfile()
93
+ {
94
+
95
+ $webproperty_id = get_option('ga_uid');
96
+ list($pre, $account_id, $post) = explode('-',$webproperty_id);
97
+
98
+ if (empty($webproperty_id)) return false;
99
+
100
+ try {
101
+ $profiles = $this->analytics->management_profiles->listManagementProfiles($account_id, $webproperty_id);
102
+ }
103
+ catch (Google_ServiceException $e)
104
+ {
105
+ print 'There was an Analytics API service error ' . $e->getCode() . ': ' . $e->getMessage();
106
+ return false;
107
+ }
108
+
109
+ $profile_id = $profiles->items[0]->id;
110
+ if (empty($profile_id)) return false;
111
+
112
+ $account_array = array();
113
+ array_push($account_array, array('id'=>$profile_id, 'ga:webPropertyId'=>$webproperty_id));
114
+ return $account_array;
115
+
116
+ }
117
+
118
+ function getAllProfiles()
119
+ {
120
+ $profile_array = array();
121
+
122
+ try {
123
+ $profiles = $this->analytics->management_webproperties->listManagementWebproperties('~all');
124
+ }
125
+ catch (Google_ServiceException $e)
126
+ {
127
+ print 'There was an Analytics API service error ' . $e->getCode() . ': ' . $e->getMessage();
128
+ }
129
+
130
+
131
+ if( !empty( $profiles->items ) )
132
+ {
133
+ foreach( $profiles->items as $profile )
134
+ {
135
+ $profile_array[ $profile->id ] = str_replace('http://','',$profile->name );
136
+ }
137
+ }
138
+
139
+ return $profile_array;
140
+ }
141
+
142
+ function getAnalyticsAccounts()
143
+ {
144
+ $analytics = new Google_AnalyticsService($this->client);
145
+ $accounts = $analytics->management_accounts->listManagementAccounts();
146
+ $account_array = array();
147
+
148
+ $items = $accounts->getItems();
149
+
150
+ if (count($items) > 0) {
151
+ foreach ($items as $key => $item)
152
+ {
153
+ $account_id = $item->getId();
154
+
155
+ $webproperties = $analytics->management_webproperties->listManagementWebproperties($account_id);
156
+
157
+ if (!empty($webproperties))
158
+ {
159
+ foreach ($webproperties->getItems() as $webp_key => $webp_item) {
160
+ $profiles = $analytics->management_profiles->listManagementProfiles($account_id, $webp_item->id);
161
+
162
+ $profile_id = $profiles->items[0]->id;
163
+ array_push($account_array, array('id'=>$profile_id, 'ga:webPropertyId'=>$webp_item->id));
164
+ }
165
+ }
166
+ }
167
+
168
+ return $account_array;
169
+ }
170
+ return false;
171
+
172
+ }
173
+
174
+
175
+
176
+ /**
177
+ * Sets the account id to use for queries
178
+ *
179
+ * @param id - the account id
180
+ **/
181
+ function setAccount($id)
182
+ {
183
+ $this->accountId = $id;
184
+ }
185
+
186
+
187
+ /**
188
+ * Get a specific data metrics
189
+ *
190
+ * @param metrics - the metrics to get
191
+ * @param startDate - the start date to get
192
+ * @param endDate - the end date to get
193
+ * @param dimensions - the dimensions to grab
194
+ * @param sort - the properties to sort on
195
+ * @param filter - the property to filter on
196
+ * @param limit - the number of items to get
197
+ * @return the specific metrics in array form
198
+ **/
199
+ function getMetrics($metric, $startDate, $endDate, $dimensions = false, $sort = false, $filter = false, $limit = false)
200
+ {
201
+ $analytics = new Google_AnalyticsService($this->client);
202
+
203
+ $params = array();
204
+
205
+ if ($dimensions)
206
+ {
207
+ $params['dimensions'] = $dimensions;
208
+ }
209
+ if ($sort)
210
+ {
211
+ $params['sort'] = $sort;
212
+ }
213
+ if ($filter)
214
+ {
215
+ $params['filters'] = $filter;
216
+ }
217
+ if ($limit)
218
+ {
219
+ $params['max-results'] = $limit;
220
+ }
221
+
222
+ return $analytics->data_ga->get(
223
+ 'ga:' . $this->accountId,
224
+ $startDate,
225
+ $endDate,
226
+ $metric,
227
+ $params
228
+ );
229
+ }
230
+
231
+
232
+
233
+
234
+
235
+ /**
236
+ * Checks the date against Jan. 1 2005 because GA API only works until that date
237
+ *
238
+ * @param date - the date to compare
239
+ * @return the correct date
240
+ **/
241
+ function verifyStartDate($date)
242
+ {
243
+ if ( strtotime($date) > strtotime('2005-01-01') )
244
+ return $date;
245
+ else
246
+ return '2005-01-01';
247
+ }
248
+
249
+ } // END class
download-button.png ADDED
Binary file
external-tracking.js CHANGED
@@ -1,44 +1,44 @@
1
- jQuery(document).ready(function() {
2
-
3
- jQuery('a').each(function() {
4
- var a = jQuery(this);
5
- var href = a.attr('href');
6
-
7
- // Check if the a tag has a href, if not, stop for the current link
8
- if ( href == undefined )
9
- return;
10
-
11
- var url = href.replace('http://','').replace('https://','');
12
- var hrefArray = href.split('.').reverse();
13
- var extension = hrefArray[0].toLowerCase();
14
- var hrefArray = href.split('/').reverse();
15
- var domain = hrefArray[2];
16
- var downloadTracked = false;
17
-
18
- // If the link is a download
19
- if (jQuery.inArray(extension,analyticsFileTypes) != -1) {
20
- // Mark the link as already tracked
21
- downloadTracked = true;
22
-
23
- // Add the tracking code
24
- a.click(function() {
25
- if ( analyticsEventTracking == 'enabled' ) {
26
- _gaq.push(['_trackEvent', 'Downloads', extension.toUpperCase(), href]);
27
- } else
28
- _gaq.push(['_trackPageview', analyticsDownloadsPrefix + url]);
29
- });
30
- }
31
-
32
- // If the link is external
33
- if ( ( href.match(/^http/) ) && ( !href.match(document.domain) ) && ( downloadTracked == false ) ) {
34
- // Add the tracking code
35
- a.click(function() {
36
- if ( analyticsEventTracking == 'enabled' ) {
37
- _gaq.push(['_trackEvent', 'Outbound Traffic', href.match(/:\/\/(.[^/]+)/)[1], href]);
38
- } else
39
- _gaq.push(['_trackPageview', analyticsOutboundPrefix + url]);
40
- });
41
- }
42
- });
43
-
44
});
1
+ jQuery(document).ready(function() {
2
+
3
+ jQuery('a').each(function() {
4
+ var a = jQuery(this);
5
+ var href = a.attr('href');
6
+
7
+ // Check if the a tag has a href, if not, stop for the current link
8
+ if ( href == undefined )
9
+ return;
10
+
11
+ var url = href.replace('http://','').replace('https://','');
12
+ var hrefArray = href.split('.').reverse();
13
+ var extension = hrefArray[0].toLowerCase();
14
+ var hrefArray = href.split('/').reverse();
15
+ var domain = hrefArray[2];
16
+ var downloadTracked = false;
17
+
18
+ // If the link is a download
19
+ if (jQuery.inArray(extension,analyticsFileTypes) != -1) {
20
+ // Mark the link as already tracked
21
+ downloadTracked = true;
22
+
23
+ // Add the tracking code
24
+ a.click(function() {
25
+ if ( analyticsEventTracking == 'enabled' ) {
26
+ _gaq.push(['_trackEvent', 'Downloads', extension.toUpperCase(), href]);
27
+ } else
28
+ _gaq.push(['_trackPageview', analyticsDownloadsPrefix + url]);
29
+ });
30
+ }
31
+
32
+ // If the link is external
33
+ if ( ( href.match(/^http/) ) && ( !href.match(document.domain) ) && ( downloadTracked == false ) ) {
34
+ // Add the tracking code
35
+ a.click(function() {
36
+ if ( analyticsEventTracking == 'enabled' ) {
37
+ _gaq.push(['_trackEvent', 'Outbound Traffic', href.match(/:\/\/(.[^/]+)/)[1], href]);
38
+ } else
39
+ _gaq.push(['_trackPageview', analyticsOutboundPrefix + url]);
40
+ });
41
+ }
42
+ });
43
+
44
});
external-tracking.min.js CHANGED
@@ -1,5 +1,5 @@
1
- jQuery(document).ready(function(){jQuery('a').each(function(){var a=jQuery(this);var href=a.attr('href');if(href==undefined)
2
- return;var url=href.replace('http://','').replace('https://','');var hrefArray=href.split('.').reverse();var extension=hrefArray[0].toLowerCase();var hrefArray=href.split('/').reverse();var domain=hrefArray[2];var downloadTracked=false;if(jQuery.inArray(extension,analyticsFileTypes)!=-1){downloadTracked=true;a.click(function(){if(analyticsEventTracking=='enabled'){_gaq.push(['_trackEvent','Downloads',extension.toUpperCase(),href]);}else
3
- _gaq.push(['_trackPageview',analyticsDownloadsPrefix+url]);});}
4
- if((href.match(/^http/))&&(!href.match(document.domain))&&(downloadTracked==false)){a.click(function(){if(analyticsEventTracking=='enabled'){_gaq.push(['_trackEvent','Outbound Traffic',href.match(/:\/\/(.[^/]+)/)[1],href]);}else
5
_gaq.push(['_trackPageview',analyticsOutboundPrefix+url]);});}});});
1
+ jQuery(document).ready(function(){jQuery('a').each(function(){var a=jQuery(this);var href=a.attr('href');if(href==undefined)
2
+ return;var url=href.replace('http://','').replace('https://','');var hrefArray=href.split('.').reverse();var extension=hrefArray[0].toLowerCase();var hrefArray=href.split('/').reverse();var domain=hrefArray[2];var downloadTracked=false;if(jQuery.inArray(extension,analyticsFileTypes)!=-1){downloadTracked=true;a.click(function(){if(analyticsEventTracking=='enabled'){_gaq.push(['_trackEvent','Downloads',extension.toUpperCase(),href]);}else
3
+ _gaq.push(['_trackPageview',analyticsDownloadsPrefix+url]);});}
4
+ if((href.match(/^http/))&&(!href.match(document.domain))&&(downloadTracked==false)){a.click(function(){if(analyticsEventTracking=='enabled'){_gaq.push(['_trackEvent','Outbound Traffic',href.match(/:\/\/(.[^/]+)/)[1],href]);}else
5
_gaq.push(['_trackPageview',analyticsOutboundPrefix+url]);});}});});
google-analyticator.php CHANGED
@@ -1,1037 +1,1050 @@
1
- <?php
2
- /*
3
- * Plugin Name: Google Analyticator
4
- * Version: 6.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
8
- * Author URI: http://ronaldheft.com/
9
- * Text Domain: google-analyticator
10
- */
11
-
12
- define('GOOGLE_ANALYTICATOR_VERSION', '6.2');
13
-
14
- // Constants for enabled/disabled state
15
- define("ga_enabled", "enabled", true);
16
- define("ga_disabled", "disabled", true);
17
-
18
- // Defaults, etc.
19
- 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_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);
28
- define("key_ga_event", "ga_event", true);
29
- define("key_ga_outbound", "ga_outbound", true);
30
- define("key_ga_outbound_prefix", "ga_outbound_prefix", true);
31
- define("key_ga_downloads", "ga_downloads", true);
32
- define("key_ga_downloads_prefix", "ga_downloads_prefix", true);
33
- define("key_ga_widgets", "ga_widgets", true);
34
- define("key_ga_sitespeed", "ga_sitespeed", true);
35
-
36
- define("ga_uid_default", "XX-XXXXX-X", true);
37
- define("ga_status_default", ga_disabled, true);
38
- define("ga_admin_default", ga_enabled, true);
39
- define("ga_admin_disable_default", 'remove', true);
40
- define("ga_adsense_default", "", true);
41
- define("ga_extra_default", "", true);
42
- define("ga_extra_after_default", "", true);
43
- define("ga_event_default", ga_enabled, true);
44
- define("ga_outbound_default", ga_enabled, true);
45
- define("ga_outbound_prefix_default", 'outgoing', true);
46
- define("ga_downloads_default", "", true);
47
- define("ga_downloads_prefix_default", "download", true);
48
- define("ga_widgets_default", ga_enabled, true);
49
- define("ga_sitespeed_default", ga_enabled, true);
50
-
51
- // Create the default key and status
52
- add_option(key_ga_status, ga_status_default, '');
53
- add_option(key_ga_uid, ga_uid_default, '');
54
- add_option(key_ga_admin, ga_admin_default, '');
55
- add_option(key_ga_admin_disable, ga_admin_disable_default, '');
56
- add_option(key_ga_admin_role, array('administrator'), '');
57
- add_option(key_ga_dashboard_role, array('administrator'), '');
58
- add_option(key_ga_adsense, ga_adsense_default, '');
59
- add_option(key_ga_extra, ga_extra_default, '');
60
- add_option(key_ga_extra_after, ga_extra_after_default, '');
61
- add_option(key_ga_event, ga_event_default, '');
62
- add_option(key_ga_outbound, ga_outbound_default, '');
63
- add_option(key_ga_outbound_prefix, ga_outbound_prefix_default, '');
64
- add_option(key_ga_downloads, ga_downloads_default, '');
65
- add_option(key_ga_downloads_prefix, ga_downloads_prefix_default, '');
66
- add_option('ga_profileid', '', '');
67
- add_option(key_ga_widgets, ga_widgets_default, '');
68
- add_option('ga_google_token', '', '');
69
- add_option('ga_compatibility', 'off', '');
70
- add_option(key_ga_sitespeed, ga_sitespeed_default, '');
71
-
72
- # Check if we have a version of WordPress greater than 2.8
73
- if ( function_exists('register_widget') ) {
74
-
75
- # Check if widgets are enabled
76
- if ( get_option(key_ga_widgets) == 'enabled' ) {
77
-
78
- # Include Google Analytics Stats widget
79
- require_once('google-analytics-stats-widget.php');
80
-
81
- # Include the Google Analytics Summary widget
82
- require_once('google-analytics-summary-widget.php');
83
- $google_analytics_summary = new GoogleAnalyticsSummary();
84
-
85
- }
86
-
87
- }
88
-
89
- // Create a option page for settings
90
- add_action('admin_init', 'ga_admin_init');
91
- add_action('admin_menu', 'add_ga_option_page');
92
-
93
- // Initialize the options
94
- function ga_admin_init() {
95
- # Load the localization information
96
- $plugin_dir = basename(dirname(__FILE__));
97
- load_plugin_textdomain('google-analyticator', 'wp-content/plugins/' . $plugin_dir . '/localizations', $plugin_dir . '/localizations');
98
- }
99
-
100
- # Add the core Google Analytics script, with a high priority to ensure last script for async tracking
101
- add_action('wp_head', 'add_google_analytics', 999999);
102
- add_action('login_head', 'add_google_analytics', 999999);
103
-
104
- # Initialize outbound link tracking
105
- add_action('init', 'ga_outgoing_links');
106
-
107
- // Hook in the options page function
108
- function add_ga_option_page() {
109
- $plugin_page = add_options_page(__('Google Analyticator Settings', 'google-analyticator'), 'Google Analytics', 'manage_options', basename(__FILE__), 'ga_options_page');
110
-
111
- # Include javascript on the GA settings page
112
- add_action('admin_head-' . $plugin_page, 'ga_admin_ajax');
113
- }
114
-
115
- add_action('plugin_action_links_' . plugin_basename(__FILE__), 'ga_filter_plugin_actions');
116
-
117
- // Add settings option
118
- function ga_filter_plugin_actions($links) {
119
- $new_links = array();
120
-
121
- $new_links[] = '<a href="options-general.php?page=google-analyticator.php">' . __('Settings', 'google-analyticator') . '</a>';
122
-
123
- return array_merge($new_links, $links);
124
- }
125
-
126
- add_filter('plugin_row_meta', 'ga_filter_plugin_links', 10, 2);
127
-
128
- // Add FAQ and support information
129
- function ga_filter_plugin_links($links, $file)
130
- {
131
- if ( $file == plugin_basename(__FILE__) )
132
- {
133
- $links[] = '<a href="http://forums.ronaldheft.com/viewforum.php?f=5">' . __('FAQ', 'google-analyticator') . '</a>';
134
- $links[] = '<a href="http://forums.ronaldheft.com/viewforum.php?f=6">' . __('Support', 'google-analyticator') . '</a>';
135
- $links[] = '<a href="http://ronaldheft.com/code/donate/">' . __('Donate', 'google-analyticator') . '</a>';
136
- }
137
-
138
- return $links;
139
- }
140
-
141
- function ga_options_page() {
142
- // If we are a postback, store the options
143
- if (isset($_POST['info_update'])) {
144
- # Verify nonce
145
- check_admin_referer('google-analyticator-update_settings');
146
-
147
- // Update the status
148
- $ga_status = $_POST[key_ga_status];
149
- if (($ga_status != ga_enabled) && ($ga_status != ga_disabled))
150
- $ga_status = ga_status_default;
151
- update_option(key_ga_status, $ga_status);
152
-
153
- // Update the UID
154
- $ga_uid = $_POST[key_ga_uid];
155
- if ($ga_uid == '')
156
- $ga_uid = ga_uid_default;
157
- update_option(key_ga_uid, $ga_uid);
158
-
159
- // Update the admin logging
160
- $ga_admin = $_POST[key_ga_admin];
161
- if (($ga_admin != ga_enabled) && ($ga_admin != ga_disabled))
162
- $ga_admin = ga_admin_default;
163
- update_option(key_ga_admin, $ga_admin);
164
-
165
- // Update the admin disable setting
166
- $ga_admin_disable = $_POST[key_ga_admin_disable];
167
- if ( $ga_admin_disable == '' )
168
- $ga_admin_disable = ga_admin_disable_default;
169
- update_option(key_ga_admin_disable, $ga_admin_disable);
170
-
171
- // Update the admin level
172
- if ( array_key_exists(key_ga_admin_role, $_POST) ) {
173
- $ga_admin_role = $_POST[key_ga_admin_role];
174
- } else {
175
- $ga_admin_role = "";
176
- }
177
- update_option(key_ga_admin_role, $ga_admin_role);
178
-
179
- // Update the dashboard level
180
- if ( array_key_exists(key_ga_dashboard_role, $_POST) ) {
181
- $ga_dashboard_role = $_POST[key_ga_dashboard_role];
182
- } else {
183
- $ga_dashboard_role = "";
184
- }
185
- update_option(key_ga_dashboard_role, $ga_dashboard_role);
186
-
187
- // Update the extra tracking code
188
- $ga_extra = $_POST[key_ga_extra];
189
- update_option(key_ga_extra, $ga_extra);
190
-
191
- // Update the extra after tracking code
192
- $ga_extra_after = $_POST[key_ga_extra_after];
193
- update_option(key_ga_extra_after, $ga_extra_after);
194
-
195
- // Update the adsense key
196
- $ga_adsense = $_POST[key_ga_adsense];
197
- update_option(key_ga_adsense, $ga_adsense);
198
-
199
- // Update the event tracking
200
- $ga_event = $_POST[key_ga_event];
201
- if (($ga_event != ga_enabled) && ($ga_event != ga_disabled))
202
- $ga_event = ga_event_default;
203
- update_option(key_ga_event, $ga_event);
204
-
205
- // Update the outbound tracking
206
- $ga_outbound = $_POST[key_ga_outbound];
207
- if (($ga_outbound != ga_enabled) && ($ga_outbound != ga_disabled))
208
- $ga_outbound = ga_outbound_default;
209
- update_option(key_ga_outbound, $ga_outbound);
210
-
211
- // Update the outbound prefix
212
- $ga_outbound_prefix = $_POST[key_ga_outbound_prefix];
213
- if ($ga_outbound_prefix == '')
214
- $ga_outbound_prefix = ga_outbound_prefix_default;
215
- update_option(key_ga_outbound_prefix, $ga_outbound_prefix);
216
-
217
- // Update the download tracking code
218
- $ga_downloads = $_POST[key_ga_downloads];
219
- update_option(key_ga_downloads, $ga_downloads);
220
-
221
- // Update the download prefix
222
- $ga_downloads_prefix = $_POST[key_ga_downloads_prefix];
223
- if ($ga_downloads_prefix == '')
224
- $ga_downloads_prefix = ga_downloads_prefix_default;
225
- update_option(key_ga_downloads_prefix, $ga_downloads_prefix);
226
-
227
- // Update the profile id
228
- update_option('ga_profileid', $_POST['ga_profileid']);
229
-
230
- // Update the widgets option
231
- $ga_widgets = $_POST[key_ga_widgets];
232
- if (($ga_widgets != ga_enabled) && ($ga_widgets != ga_disabled))
233
- $ga_widgets = ga_widgets_default;
234
- update_option(key_ga_widgets, $ga_widgets);
235
-
236
- // Update the compatibility options
237
- $ga_compatibility = $_POST['ga_compatibility'];
238
- if ( $ga_compatibility == '' )
239
- $ga_compatibility = 'off';
240
- update_option('ga_compatibility', $ga_compatibility);
241
-
242
- // Update the sitespeed option
243
- $ga_sitespeed = $_POST[key_ga_sitespeed];
244
- if (($ga_sitespeed != ga_enabled) && ($ga_sitespeed != ga_disabled))
245
- $ga_sitespeed = ga_widgets_default;
246
- update_option(key_ga_sitespeed, $ga_sitespeed);
247
-
248
- // Give an updated message
249
- echo "<div class='updated fade'><p><strong>" . __('Google Analyticator settings saved.', 'google-analyticator') . "</strong></p></div>";
250
- }
251
-
252
- // Output the options page
253
- ?>
254
-
255
- <div class="wrap">
256
-
257
- <h2><?php _e('Google Analyticator Settings', 'google-analyticator'); ?></h2>
258
-
259
- <p><em>Like Google Analyticator? Help support it <a href="http://ronaldheft.com/code/donate/">by donating to the developer</a>. This helps cover the cost of maintaining the plugin and development time toward new features. Every donation, no matter how small, is appreciated.</em></p>
260
-
261
- <form method="post" action="options-general.php?page=google-analyticator.php">
262
- <?php
263
- # Add a nonce
264
- wp_nonce_field('google-analyticator-update_settings');
265
- ?>
266
-
267
- <h3><?php _e('Basic Settings', 'google-analyticator'); ?></h3>
268
- <?php if (get_option(key_ga_status) == ga_disabled) { ?>
269
- <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
270
- <?php _e('Google Analytics integration is currently <strong>DISABLED</strong>.', 'google-analyticator'); ?>
271
- </div>
272
- <?php } ?>
273
- <?php if ((get_option(key_ga_uid) == "XX-XXXXX-X") && (get_option(key_ga_status) != ga_disabled)) { ?>
274
- <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
275
- <?php _e('Google Analytics integration is currently enabled, but you did not enter a UID. Tracking will not occur.', 'google-analyticator'); ?>
276
- </div>
277
- <?php } ?>
278
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
279
- <tr>
280
- <th width="30%" valign="top" style="padding-top: 10px;">
281
- <label for="<?php echo key_ga_status ?>"><?php _e('Google Analytics logging is', 'google-analyticator'); ?>:</label>
282
- </th>
283
- <td>
284
- <?php
285
- echo "<select name='".key_ga_status."' id='".key_ga_status."'>\n";
286
-
287
- echo "<option value='".ga_enabled."'";
288
- if(get_option(key_ga_status) == ga_enabled)
289
- echo " selected='selected'";
290
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
291
-
292
- echo "<option value='".ga_disabled."'";
293
- if(get_option(key_ga_status) == ga_disabled)
294
- echo" selected='selected'";
295
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
296
-
297
- echo "</select>\n";
298
- ?>
299
- </td>
300
- </tr>
301
- <?php
302
- # Check if we have a version of WordPress greater than 2.8, and check if we have the memory to use the api
303
- if ( function_exists('register_widget') ) {
304
- ?>
305
- <tr>
306
- <th width="30%" valign="top" style="padding-top: 10px;">
307
- <label><?php _e('Authenticate with Google', 'google-analyticator'); ?>:</label>
308
- </th>
309
- <td>
310
- <?php if ( ( trim(get_option('ga_google_token')) == '' && !isset($_GET['token']) ) || ( isset($_GET['token']) && $_GET['token'] == 'deauth' ) ) { ?>
311
- <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'),
312
- 'scope' => 'https://www.google.com/analytics/feeds/',
313
- 'secure' => 0,
314
- 'session' => 1,
315
- 'hd' => 'default'
316
- )); ?>"><?php _e('Click here to login to Google, thus authenticating Google Analyticator with your Analytics account.', 'google-analyticator'); ?></a></p>
317
- <?php } else { ?>
318
- <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>
319
- <?php if ( isset($_GET['token']) && $_GET['token'] != 'deauth' ) { ?>
320
- <p style="color: red; display: none;" id="ga_connect_error"><?php _e('Failed to authenticate with Google. <a href="http://forums.ronaldheft.com/viewtopic.php?f=5&t=851">Read this support article</a> on Analyticator\'s support forums for help.', 'google-analyticator'); ?></p>
321
- <?php } ?>
322
- <?php } ?>
323
- <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>
324
- </td>
325
- </tr>
326
- <?php } ?>
327
- <tr id="ga_ajax_accounts">
328
- <th valign="top" style="padding-top: 10px;">
329
- <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics UID', 'google-analyticator'); ?>:</label>
330
- </th>
331
- <td>
332
- <?php
333
- echo "<input type='text' size='50' ";
334
- echo "name='".key_ga_uid."' ";
335
- echo "id='".key_ga_uid."' ";
336
- echo "value='".get_option(key_ga_uid)."' />\n";
337
- ?>
338
- <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>
339
- </td>
340
- </tr>
341
- </table>
342
- <h3><?php _e('Advanced Settings', 'google-analyticator'); ?></h3>
343
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
344
- <tr>
345
- <th width="30%" valign="top" style="padding-top: 10px;">
346
- <label for="<?php echo key_ga_admin ?>"><?php _e('Track all logged in WordPress users', 'google-analyticator'); ?>:</label>
347
- </th>
348
- <td>
349
- <?php
350
- echo "<select name='".key_ga_admin."' id='".key_ga_admin."'>\n";
351
-
352
- echo "<option value='".ga_enabled."'";
353
- if(get_option(key_ga_admin) == ga_enabled)
354
- echo " selected='selected'";
355
- echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
356
-
357
- echo "<option value='".ga_disabled."'";
358
- if(get_option(key_ga_admin) == ga_disabled)
359
- echo" selected='selected'";
360
- echo ">" . __('No', 'google-analyticator') . "</option>\n";
361
-
362
- echo "</select>\n";
363
-
364
- ?>
365
- <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>
366
- </td>
367
- </tr>
368
- <tr>
369
- <th width="30%" valign="top" style="padding-top: 10px;">
370
- <label for="<?php echo key_ga_admin_role ?>"><?php _e('User roles to not track', 'google-analyticator'); ?>:</label>
371
- </th>
372
- <td>
373
- <?php
374
- global $wp_roles;
375
- $roles = $wp_roles->get_names();
376
- $selected_roles = get_option(key_ga_admin_role);
377
- if ( !is_array($selected_roles) ) $selected_roles = array();
378
-
379
- # Loop through the roles
380
- foreach ( $roles AS $role => $name ) {
381
- echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_admin_role . '[]"';
382
- if ( in_array($role, $selected_roles) )
383
- echo " checked='checked'";
384
- $name_pos = strpos($name, '|');
385
- $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
386
- echo ' /> ' . _x($name, 'User role') . '<br />';
387
- }
388
- ?>
389
- <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>
390
- </td>
391
- </tr>
392
- <tr>
393
- <th width="30%" valign="top" style="padding-top: 10px;">
394
- <label for="<?php echo key_ga_admin_disable ?>"><?php _e('Method to prevent tracking', 'google-analyticator'); ?>:</label>
395
- </th>
396
- <td>
397
- <?php
398
- echo "<select name='".key_ga_admin_disable."' id='".key_ga_admin_disable."'>\n";
399
-
400
- echo "<option value='remove'";
401
- if(get_option(key_ga_admin_disable) == 'remove')
402
- echo " selected='selected'";
403
- echo ">" . __('Remove', 'google-analyticator') . "</option>\n";
404
-
405
- echo "<option value='admin'";
406
- if(get_option(key_ga_admin_disable) == 'admin')
407
- echo" selected='selected'";
408
- echo ">" . __('Use \'admin\' variable', 'google-analyticator') . "</option>\n";
409
-
410
- echo "</select>\n";
411
- ?>
412
- <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>
413
- </td>
414
- </tr>
415
- <tr>
416
- <th width="30%" valign="top" style="padding-top: 10px;">
417
- <label for="<?php echo key_ga_sitespeed ?>"><?php _e('Site speed tracking', 'google-analyticator'); ?>:</label>
418
- </th>
419
- <td>
420
- <?php
421
- echo "<select name='".key_ga_sitespeed."' id='".key_ga_sitespeed."'>\n";
422
-
423
- echo "<option value='".ga_enabled."'";
424
- if(get_option(key_ga_sitespeed) == ga_enabled)
425
- echo " selected='selected'";
426
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
427
-
428
- echo "<option value='".ga_disabled."'";
429
- if(get_option(key_ga_sitespeed) == ga_disabled)
430
- echo" selected='selected'";
431
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
432
-
433
- echo "</select>\n";
434
- ?>
435
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Disabling this option will turn off the tracking required for <a href="http://www.google.com/support/analyticshelp/bin/answer.py?hl=en&answer=1205784&topic=1120718&utm_source=gablog&utm_medium=blog&utm_campaign=newga-blog&utm_content=sitespeed">Google Analytics\' Site Speed tracking report</a>.', 'google-analyticator'); ?></p>
436
- </td>
437
- </tr>
438
- <tr>
439
- <th width="30%" valign="top" style="padding-top: 10px;">
440
- <label for="<?php echo key_ga_outbound ?>"><?php _e('Outbound link tracking', 'google-analyticator'); ?>:</label>
441
- </th>
442
- <td>
443
- <?php
444
- echo "<select name='".key_ga_outbound."' id='".key_ga_outbound."'>\n";
445
-
446
- echo "<option value='".ga_enabled."'";
447
- if(get_option(key_ga_outbound) == ga_enabled)
448
- echo " selected='selected'";
449
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
450
-
451
- echo "<option value='".ga_disabled."'";
452
- if(get_option(key_ga_outbound) == ga_disabled)
453
- echo" selected='selected'";
454
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
455
-
456
- echo "</select>\n";
457
- ?>
458
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Disabling this option will turn off the tracking of outbound links. It\'s recommended not to disable this option unless you\'re a privacy advocate (now why would you be using Google Analytics in the first place?) or it\'s causing some kind of weird issue.', 'google-analyticator'); ?></p>
459
- </td>
460
- </tr>
461
- <tr>
462
- <th width="30%" valign="top" style="padding-top: 10px;">
463
- <label for="<?php echo key_ga_event ?>"><?php _e('Event tracking', 'google-analyticator'); ?>:</label>
464
- </th>
465
- <td>
466
- <?php
467
- echo "<select name='".key_ga_event."' id='".key_ga_event."'>\n";
468
-
469
- echo "<option value='".ga_enabled."'";
470
- if(get_option(key_ga_event) == ga_enabled)
471
- echo " selected='selected'";
472
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
473
-
474
- echo "<option value='".ga_disabled."'";
475
- if(get_option(key_ga_event) == ga_disabled)
476
- echo" selected='selected'";
477
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
478
-
479
- echo "</select>\n";
480
- ?>
481
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enabling this option will treat outbound links and downloads as events instead of pageviews. Since the introduction of <a href="http://code.google.com/apis/analytics/docs/tracking/eventTrackerOverview.html">event tracking in Analytics</a>, this is the recommended way to track these types of actions. Only disable this option if you must use the old pageview tracking method.', 'google-analyticator'); ?></p>
482
- </td>
483
- </tr>
484
- <tr>
485
- <th valign="top" style="padding-top: 10px;">
486
- <label for="<?php echo key_ga_downloads; ?>"><?php _e('Download extensions to track', 'google-analyticator'); ?>:</label>
487
- </th>
488
- <td>
489
- <?php
490
- echo "<input type='text' size='50' ";
491
- echo "name='".key_ga_downloads."' ";
492
- echo "id='".key_ga_downloads."' ";
493
- echo "value='".stripslashes(get_option(key_ga_downloads))."' />\n";
494
- ?>
495
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter any extensions of files you would like to be tracked as a download. For example to track all MP3s and PDFs enter <strong>mp3,pdf</strong>. <em>Outbound link tracking must be enabled for downloads to be tracked.</em>', 'google-analyticator'); ?></p>
496
- </td>
497
- </tr>
498
- <tr>
499
- <th valign="top" style="padding-top: 10px;">
500
- <label for="<?php echo key_ga_outbound_prefix; ?>"><?php _e('Prefix external links with', 'google-analyticator'); ?>:</label>
501
- </th>
502
- <td>
503
- <?php
504
- echo "<input type='text' size='50' ";
505
- echo "name='".key_ga_outbound_prefix."' ";
506
- echo "id='".key_ga_outbound_prefix."' ";
507
- echo "value='".stripslashes(get_option(key_ga_outbound_prefix))."' />\n";
508
- ?>
509
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter a name for the section tracked external links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator'); ?></em></p>
510
- </td>
511
- </tr>
512
- <tr>
513
- <th valign="top" style="padding-top: 10px;">
514
- <label for="<?php echo key_ga_downloads_prefix; ?>"><?php _e('Prefix download links with', 'google-analyticator'); ?>:</label>
515
- </th>
516
- <td>
517
- <?php
518
- echo "<input type='text' size='50' ";
519
- echo "name='".key_ga_downloads_prefix."' ";
520
- echo "id='".key_ga_downloads_prefix."' ";
521
- echo "value='".stripslashes(get_option(key_ga_downloads_prefix))."' />\n";
522
- ?>
523
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter a name for the section tracked download links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator'); ?></em></p>
524
- </td>
525
- </tr>
526
- <tr>
527
- <th valign="top" style="padding-top: 10px;">
528
- <label for="<?php echo key_ga_adsense; ?>"><?php _e('Google Adsense ID', 'google-analyticator'); ?>:</label>
529
- </th>
530
- <td>
531
- <?php
532
- echo "<input type='text' size='50' ";
533
- echo "name='".key_ga_adsense."' ";
534
- echo "id='".key_ga_adsense."' ";
535
- echo "value='".get_option(key_ga_adsense)."' />\n";
536
- ?>
537
- <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>
538
- </td>
539
- </tr>
540
- <tr>
541
- <th valign="top" style="padding-top: 10px;">
542
- <label for="<?php echo key_ga_extra; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('before tracker initialization', 'google-analyticator'); ?>):</label>
543
- </th>
544
- <td>
545
- <?php
546
- echo "<textarea cols='50' rows='8' ";
547
- echo "name='".key_ga_extra."' ";
548
- echo "id='".key_ga_extra."'>";
549
- echo stripslashes(get_option(key_ga_extra))."</textarea>\n";
550
- ?>
551
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>before</strong> the Google Analytics tracker is initialized. Read <a href="http://www.google.com/analytics/InstallingGATrackingCode.pdf">Google Analytics tracker manual</a> to learn what code goes here and how to use it.', 'google-analyticator'); ?></p>
552
- </td>
553
- </tr>
554
- <tr>
555
- <th valign="top" style="padding-top: 10px;">
556
- <label for="<?php echo key_ga_extra_after; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('after tracker initialization', 'google-analyticator'); ?>):</label>
557
- </th>
558
- <td>
559
- <?php
560
- echo "<textarea cols='50' rows='8' ";
561
- echo "name='".key_ga_extra_after."' ";
562
- echo "id='".key_ga_extra_after."'>";
563
- echo stripslashes(get_option(key_ga_extra_after))."</textarea>\n";
564
- ?>
565
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>after</strong> the Google Analytics tracker is initialized. Read <a href="http://www.google.com/analytics/InstallingGATrackingCode.pdf">Google Analytics tracker manual</a> to learn what code goes here and how to use it.', 'google-analyticator'); ?></p>
566
- </td>
567
- </tr>
568
- <?php
569
- # Check if we have a version of WordPress greater than 2.8
570
- if ( function_exists('register_widget') ) {
571
- ?>
572
- <tr>
573
- <th valign="top" style="padding-top: 10px;">
574
- <label for="ga_profileid"><?php _e('Google Analytics profile ID', 'google-analyticator'); ?>:</label>
575
- </th>
576
- <td>
577
- <?php
578
- echo "<input type='text' size='50' ";
579
- echo "name='ga_profileid' ";
580
- echo "id='ga_profileid' ";
581
- echo "value='".get_option('ga_profileid')."' />\n";
582
- ?>
583
- <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>
584
- </td>
585
- </tr>
586
- <tr>
587
- <th width="30%" valign="top" style="padding-top: 10px;">
588
- <label for="<?php echo key_ga_dashboard_role ?>"><?php _e('User roles that can see the dashboard widget', 'google-analyticator'); ?>:</label>
589
- </th>
590
- <td>
591
- <?php
592
- global $wp_roles;
593
- $roles = $wp_roles->get_names();
594
- $selected_roles = get_option(key_ga_dashboard_role);
595
- if ( !is_array($selected_roles) ) $selected_roles = array();
596
-
597
- # Loop through the roles
598
- foreach ( $roles AS $role => $name ) {
599
- echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_dashboard_role . '[]"';
600
- if ( in_array($role, $selected_roles) )
601
- echo " checked='checked'";
602
- $name_pos = strpos($name, '|');
603
- $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
604
- echo ' /> ' . _x($name, 'User role') . '<br />';
605
- }
606
- ?>
607
- <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>
608
- </td>
609
- </tr>
610
- <tr>
611
- <th width="30%" valign="top" style="padding-top: 10px;">
612
- <label for="<?php echo key_ga_widgets; ?>"><?php _e('Include widgets', 'google-analyticator'); ?>:</label>
613
- </th>
614
- <td>
615
- <?php
616
- echo "<select name='".key_ga_widgets."' id='".key_ga_widgets."'>\n";
617
-
618
- echo "<option value='".ga_enabled."'";
619
- if(get_option(key_ga_widgets) == ga_enabled)
620
- echo " selected='selected'";
621
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
622
-
623
- echo "<option value='".ga_disabled."'";
624
- if(get_option(key_ga_widgets) == ga_disabled)
625
- echo" selected='selected'";
626
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
627
-
628
- echo "</select>\n";
629
- ?>
630
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('Disabling this option will completely remove the Dashboard Summary widget and the theme Stats widget. Use this option if you would prefer to not see the widgets.', 'google-analyticator'); ?></p>
631
- </td>
632
- </tr>
633
- <tr>
634
- <th width="30%" valign="top" style="padding-top: 10px;">
635
- <label for="ga_compatibility"><?php _e('Authentication compatibility', 'google-analyticator'); ?>:</label>
636
- </th>
637
- <td>
638
- <?php
639
- echo "<select name='ga_compatibility' id='ga_compatibility'>\n";
640
-
641
- echo "<option value='off'";
642
- if(get_option('ga_compatibility') == 'off')
643
- echo " selected='selected'";
644
- echo ">" . __('Off', 'google-analyticator') . "</option>\n";
645
-
646
- echo "<option value='level1'";
647
- if(get_option('ga_compatibility') == 'level1')
648
- echo " selected='selected'";
649
- echo ">" . __('Disable cURL', 'google-analyticator') . "</option>\n";
650
-
651
- echo "<option value='level2'";
652
- if(get_option('ga_compatibility') == 'level2')
653
- echo " selected='selected'";
654
- echo ">" . __('Disable cURL and PHP Streams', 'google-analyticator') . "</option>\n";
655
-
656
- echo "</select>\n";
657
- ?>
658
- <p style="margin: 5px 10px;" class="setting-description"><?php _e('If you\'re having trouble authenticating with Google for use with the stats widgets, try setting these compatibility modes. Try disabling cURL first and re-authenticate. If that fails, try disabling cURL and PHP Streams.', 'google-analyticator'); ?></p>
659
- </td>
660
- </tr>
661
- <?php } ?>
662
- </table>
663
- <p class="submit">
664
- <input type="submit" name="info_update" value="<?php _e('Save Changes', 'google-analyticator'); ?>" />
665
- </p>
666
- </div>
667
- </form>
668
-
669
- <?php
670
- }
671
-
672
- /**
673
- * Adds AJAX to the GA settings page
674
- **/
675
- function ga_admin_ajax()
676
- {
677
- if ( function_exists('register_widget') ) {
678
-
679
- # Only attempt to replace code if we're authenticated or attempting to authenticate
680
- if ( ( isset($_REQUEST['token']) && $_REQUEST['token'] != '' ) || ( trim(get_option('ga_google_token')) != '' ) ) {
681
- ?>
682
- <script type="text/javascript">
683
-
684
- jQuery(document).ready(function(){
685
-
686
- // Grab the widget data
687
- jQuery.ajax({
688
- type: 'post',
689
- url: 'admin-ajax.php',
690
- data: {
691
- action: 'ga_ajax_accounts',
692
- _ajax_nonce: '<?php echo wp_create_nonce("google-analyticator-accounts_get"); ?>'<?php if ( isset($_GET['token']) ) { ?>,
693
- token: '<?php echo esc_js($_GET["token"]); ?>'
694
- <?php } ?>
695
- },
696
- success: function(html) {
697
- if ( html != '' )
698
- jQuery('#ga_ajax_accounts').html(html);
699
- else
700
- jQuery('#ga_connect_error').show();
701
- }
702
- });
703
-
704
- });
705
-
706
- </script>
707
- <?php
708
- }
709
- }
710
- }
711
-
712
- # Look for the ajax list call
713
- add_action('wp_ajax_ga_ajax_accounts', 'ga_ajax_accounts');
714
-
715
- /**
716
- * An AJAX function to get a list of accounts in a drop down
717
- **/
718
- function ga_ajax_accounts()
719
- {
720
- # Check the ajax widget
721
- check_ajax_referer('google-analyticator-accounts_get');
722
-
723
- # Get the list of accounts if available
724
- $ga_accounts = ga_get_analytics_accounts();
725
-
726
- if ( $ga_accounts !== false ) {
727
- ?>
728
-
729
- <th valign="top" style="padding-top: 10px;">
730
- <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics account', 'google-analyticator'); ?>:</label>
731
- </th>
732
- <td>
733
- <?php
734
- // sort the $ga_accounts array by ga:accountName and then title
735
- $sorted_ga_accounts = array();
736
- foreach ($ga_accounts as $ga_account) {
737
- $sorted_ga_accounts[$ga_account['ga:accountName']][] = $ga_account;
738
- }
739
- foreach( $sorted_ga_accounts as $id => $sorted_ga_account) {
740
- usort($sorted_ga_accounts[$id], 'ga_sort_account_list');
741
- }
742
-
743
- # Create a select box
744
- echo '<select name="' . key_ga_uid . '" id="' . key_ga_uid . '">';
745
- echo '<option value="XX-XXXXX-X">' . __('Select an Account', 'google-analyticator') . '</option>';
746
-
747
- # The list of accounts
748
- foreach ( $sorted_ga_accounts AS $account_name => $account_list ) {
749
- echo "<optgroup label='".htmlentities($account_name)."'>\n";
750
- foreach( $account_list as $account) {
751
- $select = ( get_option(key_ga_uid) == $account['ga:webPropertyId'] ) ? ' selected="selected"' : '';
752
- echo '<option value="' . $account['ga:webPropertyId'] . '"' . $select . '>' . $account['title'] . '</option>';
753
- }
754
- echo "</optgroup>\n";
755
- }
756
-
757
- # Close the select box
758
- echo '</select>';
759
- ?>
760
- <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>
761
- </td>
762
-
763
- <?php
764
- }
765
- die();
766
- }
767
-
768
- function ga_sort_account_list($a, $b) {
769
- return strcmp($a['title'],$b['title']);
770
- }
771
-
772
- /**
773
- * Checks if the WordPress API is a valid method for selecting an account
774
- *
775
- * @return a list of accounts if available, false if none available
776
- **/
777
- function ga_get_analytics_accounts()
778
- {
779
- $accounts = array();
780
-
781
- # Get the class for interacting with the Google Analytics
782
- require_once('class.analytics.stats.php');
783
-
784
- # Create a new Gdata call
785
- if ( isset($_POST['token']) && $_POST['token'] != '' )
786
- $stats = new GoogleAnalyticsStats($_POST['token']);
787
- elseif ( trim(get_option('ga_google_token')) != '' )
788
- $stats = new GoogleAnalyticsStats();
789
- else
790
- return false;
791
-
792
- # Check if Google sucessfully logged in
793
- if ( ! $stats->checkLogin() )
794
- return false;
795
-
796
- # Get a list of accounts
797
- $accounts = $stats->getAnalyticsAccounts();
798
-
799
- # Return the account array if there are accounts
800
- if ( count($accounts) > 0 )
801
- return $accounts;
802
- else
803
- return false;
804
- }
805
-
806
- /**
807
- * Add http_build_query if it doesn't exist already
808
- **/
809
- if ( !function_exists('http_build_query') ) {
810
- function http_build_query($params, $key = null)
811
- {
812
- $ret = array();
813
-
814
- foreach( (array) $params as $name => $val ) {
815
- $name = urlencode($name);
816
-
817
- if ( $key !== null )
818
- $name = $key . "[" . $name . "]";
819
-
820
- if ( is_array($val) || is_object($val) )
821
- $ret[] = http_build_query($val, $name);
822
- elseif ($val !== null)
823
- $ret[] = $name . "=" . urlencode($val);
824
- }
825
-
826
- return implode("&", $ret);
827
- }
828
- }
829
-
830
- /**
831
- * Echos out the core Analytics tracking code
832
- **/
833
- function add_google_analytics()
834
- {
835
- # Fetch variables used in the tracking code
836
- $uid = stripslashes(get_option(key_ga_uid));
837
- $extra = stripslashes(get_option(key_ga_extra));
838
- $extra_after = stripslashes(get_option(key_ga_extra_after));
839
- $extensions = str_replace (",", "|", get_option(key_ga_downloads));
840
-
841
- # Determine if the GA is enabled and contains a valid UID
842
- if ( ( get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
843
- {
844
- # Determine if the user is an admin, and should see the tracking code
845
- if ( ( get_option(key_ga_admin) == ga_enabled || !ga_current_user_is(get_option(key_ga_admin_role)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
846
- {
847
- # Disable the tracking code on the post preview page
848
- if ( !function_exists("is_preview") || ( function_exists("is_preview") && !is_preview() ) )
849
- {
850
- # Add the notice that Google Analyticator tracking is enabled
851
- echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
852
-
853
- # Add the Adsense data if specified
854
- if ( get_option(key_ga_adsense) != '' )
855
- echo '<script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n";
856
-
857
- # Include the file types to track
858
- $extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
859
- $ext = "";
860
- foreach ( $extensions AS $extension )
861
- $ext .= "'$extension',";
862
- $ext = substr($ext, 0, -1);
863
-
864
- # Include the link tracking prefixes
865
- $outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
866
- $downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
867
- $event_tracking = get_option(key_ga_event);
868
-
869
- ?>
870
- <script type="text/javascript">
871
- var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
872
- <?php if ( $event_tracking != 'enabled' ) { ?>
873
- var analyticsOutboundPrefix = '/<?php echo $outbound_prefix; ?>/';
874
- var analyticsDownloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
875
- <?php } ?>
876
- var analyticsEventTracking = '<?php echo $event_tracking; ?>';
877
- </script>
878
- <?php
879
- # Add the first part of the core tracking code
880
- ?>
881
- <script type="text/javascript">
882
- var _gaq = _gaq || [];
883
- _gaq.push(['_setAccount', '<?php echo $uid; ?>']);
884
- <?php
885
-
886
- # Add any tracking code before the trackPageview
887
- do_action('google_analyticator_extra_js_before');
888
- if ( '' != $extra )
889
- echo " $extra\n";
890
-
891
- # Add the track pageview function
892
- echo " _gaq.push(['_trackPageview']);\n";
893
-
894
- # Add the site speed tracking
895
- if ( get_option(key_ga_sitespeed) == ga_enabled )
896
- echo " _gaq.push(['_trackPageLoadTime']);\n";
897
-
898
- # Disable page tracking if admin is logged in
899
- if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(key_ga_admin_role)) ) )
900
- echo " _gaq.push(['_setCustomVar', 'admin']);\n";
901
-
902
- # Add any tracking code after the trackPageview
903
- do_action('google_analyticator_extra_js_after');
904
- if ( '' != $extra_after )
905
- echo " $extra_after\n";
906
-
907
- # Add the final section of the tracking code
908
- ?>
909
-
910
- (function() {
911
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
912
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
913
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
914
- })();
915
- </script>
916
- <?php
917
- }
918
- } else {
919
- # Add the notice that Google Analyticator tracking is enabled
920
- echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
921
- echo " <!-- " . __('Tracking code is hidden, since the settings specify not to track admins. Tracking is occurring for non-admins.', 'google-analyticator') . " -->\n";
922
- }
923
- }
924
- }
925
-
926
- /**
927
- * Adds outbound link tracking to Google Analyticator
928
- **/
929
- function ga_outgoing_links()
930
- {
931
- # Fetch the UID
932
- $uid = stripslashes(get_option(key_ga_uid));
933
-
934
- # If GA is enabled and has a valid key
935
- if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
936
- {
937
- # If outbound tracking is enabled
938
- if ( get_option(key_ga_outbound) == ga_enabled )
939
- {
940
- # If this is not an admin page
941
- if ( !is_admin() )
942
- {
943
- # Display page tracking if user is not an admin
944
- if ( ( get_option(key_ga_admin) == ga_enabled || !ga_current_user_is(get_option(key_ga_admin_role)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
945
- {
946
- add_action('wp_print_scripts', 'ga_external_tracking_js');
947
- }
948
- }
949
- }
950
- }
951
- }
952
-
953
- /**
954
- * Adds the scripts required for outbound link tracking
955
- **/
956
- function ga_external_tracking_js()
957
- {
958
- wp_enqueue_script('ga-external-tracking', plugins_url('/google-analyticator/external-tracking.min.js'), array('jquery'), GOOGLE_ANALYTICATOR_VERSION);
959
- }
960
-
961
- /**
962
- * Determines if a specific user fits a role
963
- **/
964
- function ga_current_user_is($roles)
965
- {
966
- if ( !$roles ) return false;
967
-
968
- global $current_user;
969
- get_currentuserinfo();
970
- $user_id = intval( $current_user->ID );
971
-
972
- if ( !$user_id ) {
973
- return false;
974
- }
975
- $user = new WP_User($user_id); // $user->roles
976
-
977
- foreach ( $roles as $role )
978
- if ( in_array($role, $user->roles) ) return true;
979
-
980
- return false;
981
- }
982
-
983
- /**
984
- * EXPERIMENTAL: Retrieve Google's visits for the given page
985
- * More work needs to be done. Needs caching, needs to be less resource intensive, and
986
- * needs an automated way to determine the page.
987
- * Function may/will change in future releases. Only use if you know what you're doing.
988
- *
989
- * @param url - the page url, missing the domain information
990
- * @param days - the number of days to get
991
- * @return the number of visits
992
- **/
993
- function get_analytics_visits_by_page($page, $days = 31)
994
- {
995
- require_once('class.analytics.stats.php');
996
-
997
- # Create a new API object
998
- $api = new GoogleAnalyticsStats();
999
-
1000
- # Get the current accounts accounts
1001
- $accounts = ga_get_analytics_accounts();
1002
-
1003
- # Verify accounts exist
1004
- if ( count($accounts) <= 0 )
1005
- return 0;
1006
-
1007
- # Loop throught the account and return the current account
1008
- foreach ( $accounts AS $account )
1009
- {
1010
- # Check if the UID matches the selected UID
1011
- if ( $account['ga:webPropertyId'] == get_option('ga_uid') )
1012
- {
1013
- $api->setAccount($account['id']);
1014
- break;
1015
- }
1016
- }
1017
-
1018
- # Encode the page url
1019
- $page = urlencode($page);
1020
-
1021
- # Get the metric information from Google
1022
- $before = date('Y-m-d', strtotime('-' . $days . ' days'));
1023
- $yesterday = date('Y-m-d', strtotime('-1 day'));
1024
- $stats = $api->getMetrics('ga:visits', $before, $yesterday, 'ga:pagePath', false, 'ga:pagePath%3D%3D' . $page, 1);
1025
-
1026
- # Check the size of the stats array
1027
- if ( count($stats) <= 0 || !is_array($stats) ) {
1028
- return 0;
1029
- } else {
1030
- # Loop through each stat for display
1031
- foreach ( $stats AS $stat ) {
1032
- return $stat['ga:visits'];
1033
- }
1034
- }
1035
- }
1036
-
1037
?>
1
+ <?php
2
+ /*
3
+ * Plugin Name: Google Analyticator
4
+ * Version: 6.3.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
8
+ * Author URI: http://www.videousermanuals.com
9
+ * Text Domain: google-analyticator
10
+ */
11
+
12
+ define('GOOGLE_ANALYTICATOR_VERSION', '6.3.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
16
+ define('GOOGLE_ANALYTICATOR_REDIRECT', 'urn:ietf:wg:oauth:2.0:oob');
17
+ define('GOOGLE_ANALYTICATOR_SCOPE', 'https://www.googleapis.com/auth/analytics.readonly');
18
+
19
+ // Constants for enabled/disabled state
20
+ define("ga_enabled", "enabled", true);
21
+ define("ga_disabled", "disabled", true);
22
+
23
+ // Defaults, etc.
24
+ define("key_ga_uid", "ga_uid", true);
25
+ define("key_ga_status", "ga_status", true);
26
+ define("key_ga_admin", "ga_admin_status", true);
27
+ define("key_ga_admin_disable", "ga_admin_disable", true);
28
+ define("key_ga_admin_role", "ga_admin_role", true);
29
+ define("key_ga_dashboard_role", "ga_dashboard_role", true);
30
+ define("key_ga_adsense", "ga_adsense", true);
31
+ define("key_ga_extra", "ga_extra", true);
32
+ define("key_ga_extra_after", "ga_extra_after", true);
33
+ define("key_ga_event", "ga_event", true);
34
+ define("key_ga_outbound", "ga_outbound", true);
35
+ define("key_ga_outbound_prefix", "ga_outbound_prefix", true);
36
+ define("key_ga_downloads", "ga_downloads", true);
37
+ define("key_ga_downloads_prefix", "ga_downloads_prefix", true);
38
+ define("key_ga_widgets", "ga_widgets", true);
39
+ define("key_ga_sitespeed", "ga_sitespeed", true);
40
+
41
+ define("ga_uid_default", "UA-XXXXXXXX-X", true);
42
+ define("ga_google_token_default", "", true);
43
+ define("ga_status_default", ga_disabled, true);
44
+ define("ga_admin_default", ga_enabled, true);
45
+ define("ga_admin_disable_default", 'remove', true);
46
+ define("ga_adsense_default", "", true);
47
+ define("ga_extra_default", "", true);
48
+ define("ga_extra_after_default", "", true);
49
+ define("ga_event_default", ga_enabled, true);
50
+ define("ga_outbound_default", ga_enabled, true);
51
+ define("ga_outbound_prefix_default", 'outgoing', true);
52
+ define("ga_downloads_default", "", true);
53
+ define("ga_downloads_prefix_default", "download", true);
54
+ define("ga_widgets_default", ga_enabled, true);
55
+ define("ga_sitespeed_default", ga_enabled, true);
56
+
57
+ // Create the default key and status
58
+ add_option(key_ga_status, ga_status_default, '');
59
+ add_option(key_ga_uid, ga_uid_default, '');
60
+ add_option(key_ga_admin, ga_admin_default, '');
61
+ add_option(key_ga_admin_disable, ga_admin_disable_default, '');
62
+ add_option(key_ga_admin_role, array('administrator'), '');
63
+ add_option(key_ga_dashboard_role, array('administrator'), '');
64
+ add_option(key_ga_adsense, ga_adsense_default, '');
65
+ add_option(key_ga_extra, ga_extra_default, '');
66
+ add_option(key_ga_extra_after, ga_extra_after_default, '');
67
+ add_option(key_ga_event, ga_event_default, '');
68
+ add_option(key_ga_outbound, ga_outbound_default, '');
69
+ add_option(key_ga_outbound_prefix, ga_outbound_prefix_default, '');
70
+ add_option(key_ga_downloads, ga_downloads_default, '');
71
+ add_option(key_ga_downloads_prefix, ga_downloads_prefix_default, '');
72
+ add_option(key_ga_sitespeed, ga_sitespeed_default, '');
73
+ add_option(key_ga_widgets, ga_widgets_default, '');
74
+ add_option('ga_defaults', 'yes' );
75
+ add_option('ga_google_token', '', '');
76
+
77
+
78
+ $useAuth = ( get_option( 'ga_google_token' ) == '' ? false : true );
79
+
80
+
81
+ # Check if we have a version of WordPress greater than 2.8
82
+ if ( function_exists('register_widget') ) {
83
+
84
+ # Check if widgets are enabled and the auth has been set!
85
+ if ( get_option(key_ga_widgets) == 'enabled' && $useAuth ) {
86
+
87
+ # Include Google Analytics Stats widget
88
+ require_once('google-analytics-stats-widget.php');
89
+
90
+ # Include the Google Analytics Summary widget
91
+ require_once('google-analytics-summary-widget.php');
92
+ $google_analytics_summary = new GoogleAnalyticsSummary();
93
+
94
+ }
95
+
96
+ }
97
+
98
+ // Create a option page for settings
99
+ add_action('admin_init', 'ga_admin_init');
100
+ add_action('admin_menu', 'add_ga_option_page');
101
+
102
+ // Initialize the options
103
+ function ga_admin_init() {
104
+ # Load the localization information
105
+ $plugin_dir = basename(dirname(__FILE__));
106
+ load_plugin_textdomain('google-analyticator', 'wp-content/plugins/' . $plugin_dir . '/localizations', $plugin_dir . '/localizations');
107
+ }
108
+
109
+ # Add the core Google Analytics script, with a high priority to ensure last script for async tracking
110
+ add_action('wp_head', 'add_google_analytics', 999999);
111
+ add_action('login_head', 'add_google_analytics', 999999);
112
+
113
+ # Initialize outbound link tracking
114
+ add_action('init', 'ga_outgoing_links');
115
+
116
+ // Hook in the options page function
117
+ function add_ga_option_page() {
118
+
119
+ $plugin_page = add_options_page(__('Google Analyticator Settings', 'google-analyticator'), 'Google Analytics', 'manage_options', basename(__FILE__), 'ga_options_page');
120
+ add_action('load-'.$plugin_page, 'ga_pre_load' );
121
+
122
+ $activate_page = add_submenu_page( null, 'Activation', 'Google Analytics', 'manage_options', 'ga_activate' , 'ga_activate');
123
+
124
+
125
+ $reset_page = add_submenu_page(null, 'Reset', 'Reset', 'activate_plugins', 'ga_reset', 'ga_reset' );
126
+ add_action('load-'.$reset_page, 'ga_do_reset' );
127
+
128
+ }
129
+
130
+ add_action('plugin_action_links_' . plugin_basename(__FILE__), 'ga_filter_plugin_actions');
131
+
132
+ function ga_pre_load()
133
+ {
134
+
135
+ if( isset( $_POST['key_ga_google_token'] ) ):
136
+
137
+ check_admin_referer('google-analyticator-update_settings');
138
+
139
+ // Nolonger defaults
140
+ update_option('ga_defaults', 'no');
141
+
142
+ // Update GA Token
143
+ update_option('ga_google_token', $_POST['key_ga_google_token']);
144
+
145
+
146
+ endif;
147
+
148
+ if( get_option('ga_defaults') == 'yes' ):
149
+
150
+ wp_redirect( admin_url('options-general.php?page=ga_activate') );
151
+ exit;
152
+
153
+ endif;
154
+ }
155
+
156
+ function ga_activate()
157
+ {
158
+
159
+ if (! function_exists('curl_init')) {
160
+ print('Google PHP API Client requires the CURL PHP extension');
161
+ return;
162
+ }
163
+
164
+ if (! function_exists('json_decode')) {
165
+ print('Google PHP API Client requires the JSON PHP extension');
166
+ return;
167
+ }
168
+
169
+ if (! function_exists('http_build_query')) {
170
+ print('Google PHP API Client requires http_build_query()');
171
+ return;
172
+ }
173
+
174
+ $url = http_build_query( array(
175
+ 'next' => admin_url('/options-general.php?page=google-analyticator.php'),
176
+ 'scope' => GOOGLE_ANALYTICATOR_SCOPE,
177
+ 'response_type'=>'code',
178
+ 'redirect_uri'=>GOOGLE_ANALYTICATOR_REDIRECT,
179
+ 'client_id'=>GOOGLE_ANALYTICATOR_CLIENTID
180
+ )
181
+ );
182
+
183
+ ?>
184
+ <div class="wrap">
185
+
186
+ <h2>Activate Google Analyticator</h2>
187
+
188
+ <p><strong>Google Authentication Code </strong> </p>
189
+
190
+ <p>You need to sign in to Google and grant this plugin access to your Google Analytics account</p>
191
+
192
+ <p>
193
+ <a
194
+ onclick="window.open('https://accounts.google.com/o/oauth2/auth?<?php echo $url ?>', 'activate','width=700, height=600, menubar=0, status=0, location=0, toolbar=0')"
195
+ target="_blank"
196
+ href="javascript:void(0);"> Click Here </a> - <small> Or <a target="_blank" href="https://accounts.google.com/o/oauth2/auth?<?php echo $url ?>">here</a> if you have popups blocked</small>
197
+ </p>
198
+
199
+ <div id="key">
200
+
201
+ <p>Enter your Google Authentication Code in this box. This code will be used to get an Authentication Token so you can access your website stats.</p>
202
+ <form method="post" action="<?php echo admin_url('options-general.php?page=google-analyticator.php');?>">
203
+ <?php wp_nonce_field('google-analyticator-update_settings'); ?>
204
+ <input type="text" name="key_ga_google_token" value="" style="width:450px;"/>
205
+ <input type="submit" value="Save &amp; Continue" />
206
+ </form>
207
+ </div>
208
+
209
+ <br /><br /><br />
210
+ <hr />
211
+ <br />
212
+
213
+ <p><strong>I Don't Want To Authenticate Through Google </strong> </p>
214
+
215
+ <p>If you don't want to authenticate through Google and only use the tracking capability of the plugin (<strong><u>not the dashboard functionality</u></strong>), you can do this by clicking the button below. </p>
216
+ <p>You will be asked on the next page to manually enter your Google Analytics UID.</p>
217
+ <form method="post" action="<?php echo admin_url('options-general.php?page=google-analyticator.php');?>">
218
+ <input type="hidden" name="key_ga_google_token" value="" />
219
+ <?php wp_nonce_field('google-analyticator-update_settings'); ?>
220
+ <input type="submit" value="Continue Without Authentication" />
221
+ </form>
222
+
223
+
224
+ </div>
225
+
226
+ <?php
227
+ }
228
+
229
+ // Add settings option
230
+ function ga_filter_plugin_actions($links) {
231
+ $new_links = array();
232
+
233
+ $new_links[] = '<a href="' . admin_url('options-general.php?page=google-analyticator.php').'">' . __('Settings', 'google-analyticator') . '</a>';
234
+ $new_links[] = '<a href="' . admin_url('options-general.php?page=ga_reset">') . __('Reset', 'google-analyticator') . '</a>';
235
+
236
+ return array_merge($new_links, $links);
237
+ }
238
+
239
+ function ga_do_reset()
240
+ {
241
+ // Delete all GA options.
242
+ delete_option(key_ga_status);
243
+ delete_option(key_ga_uid);
244
+ delete_option(key_ga_admin);
245
+ delete_option(key_ga_admin_disable);
246
+ delete_option(key_ga_admin_role);
247
+ delete_option(key_ga_dashboard_role);
248
+ delete_option(key_ga_adsense);
249
+ delete_option(key_ga_extra);
250
+ delete_option(key_ga_extra_after);
251
+ delete_option(key_ga_event);
252
+ delete_option(key_ga_outbound);
253
+ delete_option(key_ga_outbound_prefix);
254
+ delete_option(key_ga_downloads);
255
+ delete_option(key_ga_downloads_prefix);
256
+ delete_option(key_ga_sitespeed);
257
+ delete_option(key_ga_widgets);
258
+ delete_option('ga_defaults');
259
+ delete_option('ga_google_token');
260
+ delete_option('ga_google_authtoken');
261
+ delete_option('ga_profileid');
262
+
263
+
264
+
265
+ wp_redirect( admin_url( 'options-general.php?page=ga_activate' ) );
266
+ exit;
267
+ }
268
+
269
+ function ga_reset(){ /* Wont ever run. */ }
270
+
271
+
272
+ function ga_options_page() {
273
+
274
+ // If we are a postback, store the options
275
+ if (isset($_POST['info_update'])) {
276
+ # Verify nonce
277
+ check_admin_referer('google-analyticator-update_settings');
278
+
279
+ update_option('ga_defaults', 'no');
280
+
281
+
282
+ // Update the status
283
+ $ga_status = $_POST[key_ga_status];
284
+ if (($ga_status != ga_enabled) && ($ga_status != ga_disabled))
285
+ $ga_status = ga_status_default;
286
+ update_option(key_ga_status, $ga_status);
287
+
288
+ // Update the UID
289
+ $ga_uid = $_POST[key_ga_uid];
290
+ if ($ga_uid == '')
291
+ $ga_uid = ga_uid_default;
292
+ update_option(key_ga_uid, $ga_uid);
293
+
294
+ // Update the admin logging
295
+ $ga_admin = $_POST[key_ga_admin];
296
+ if (($ga_admin != ga_enabled) && ($ga_admin != ga_disabled))
297
+ $ga_admin = ga_admin_default;
298
+ update_option(key_ga_admin, $ga_admin);
299
+
300
+ // Update the admin disable setting
301
+ $ga_admin_disable = $_POST[key_ga_admin_disable];
302
+ if ( $ga_admin_disable == '' )
303
+ $ga_admin_disable = ga_admin_disable_default;
304
+ update_option(key_ga_admin_disable, $ga_admin_disable);
305
+
306
+ // Update the admin level
307
+ if ( array_key_exists(key_ga_admin_role, $_POST) ) {
308
+ $ga_admin_role = $_POST[key_ga_admin_role];
309
+ } else {
310
+ $ga_admin_role = "";
311
+ }
312
+ update_option(key_ga_admin_role, $ga_admin_role);
313
+
314
+ // Update the dashboard level
315
+ if ( array_key_exists(key_ga_dashboard_role, $_POST) ) {
316
+ $ga_dashboard_role = $_POST[key_ga_dashboard_role];
317
+ } else {
318
+ $ga_dashboard_role = "";
319
+ }
320
+ update_option(key_ga_dashboard_role, $ga_dashboard_role);
321
+
322
+ // Update the extra tracking code
323
+ $ga_extra = $_POST[key_ga_extra];
324
+ update_option(key_ga_extra, $ga_extra);
325
+
326
+ // Update the extra after tracking code
327
+ $ga_extra_after = $_POST[key_ga_extra_after];
328
+ update_option(key_ga_extra_after, $ga_extra_after);
329
+
330
+ // Update the adsense key
331
+ $ga_adsense = $_POST[key_ga_adsense];
332
+ update_option(key_ga_adsense, $ga_adsense);
333
+
334
+ // Update the event tracking
335
+ $ga_event = $_POST[key_ga_event];
336
+ if (($ga_event != ga_enabled) && ($ga_event != ga_disabled))
337
+ $ga_event = ga_event_default;
338
+ update_option(key_ga_event, $ga_event);
339
+
340
+ // Update the outbound tracking
341
+ $ga_outbound = $_POST[key_ga_outbound];
342
+ if (($ga_outbound != ga_enabled) && ($ga_outbound != ga_disabled))
343
+ $ga_outbound = ga_outbound_default;
344
+ update_option(key_ga_outbound, $ga_outbound);
345
+
346
+ // Update the outbound prefix
347
+ $ga_outbound_prefix = $_POST[key_ga_outbound_prefix];
348
+ if ($ga_outbound_prefix == '')
349
+ $ga_outbound_prefix = ga_outbound_prefix_default;
350
+ update_option(key_ga_outbound_prefix, $ga_outbound_prefix);
351
+
352
+ // Update the download tracking code
353
+ $ga_downloads = $_POST[key_ga_downloads];
354
+ update_option(key_ga_downloads, $ga_downloads);
355
+
356
+ // Update the download prefix
357
+ $ga_downloads_prefix = $_POST[key_ga_downloads_prefix];
358
+ if ($ga_downloads_prefix == '')
359
+ $ga_downloads_prefix = ga_downloads_prefix_default;
360
+ update_option(key_ga_downloads_prefix, $ga_downloads_prefix);
361
+
362
+ // Update the widgets option
363
+ $ga_widgets = $_POST[key_ga_widgets];
364
+ if (($ga_widgets != ga_enabled) && ($ga_widgets != ga_disabled))
365
+ $ga_widgets = ga_widgets_default;
366
+ update_option(key_ga_widgets, $ga_widgets);
367
+
368
+
369
+ // Update the sitespeed option
370
+ $ga_sitespeed = $_POST[key_ga_sitespeed];
371
+ if (($ga_sitespeed != ga_enabled) && ($ga_sitespeed != ga_disabled))
372
+ $ga_sitespeed = ga_widgets_default;
373
+ update_option(key_ga_sitespeed, $ga_sitespeed);
374
+
375
+ // Give an updated message
376
+ echo "<div class='updated fade'><p><strong>" . __('Google Analyticator settings saved.', 'google-analyticator') . "</strong></p></div>";
377
+ }
378
+
379
+
380
+ // Are we using the auth system?
381
+ $useAuth = ( get_option( 'ga_google_token' ) == '' ? false : true );
382
+
383
+
384
+ // Output the options page
385
+ ?>
386
+
387
+ <div class="wrap">
388
+
389
+ <h2><?php _e('Google Analyticator Settings', 'google-analyticator'); ?></h2>
390
+
391
+ <form method="post" action="<?php echo admin_url('options-general.php?page=google-analyticator.php');?>">
392
+ <?php
393
+ # Add a nonce
394
+ wp_nonce_field('google-analyticator-update_settings');
395
+ ?>
396
+
397
+ <?php if (get_option(key_ga_status) == ga_disabled) { ?>
398
+ <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
399
+ <?php _e('Google Analytics integration is currently <strong>DISABLED</strong>.', 'google-analyticator'); ?>
400
+ </div>
401
+ <?php } ?>
402
+ <?php if ((get_option(key_ga_uid) == "XX-XXXXX-X") && (get_option(key_ga_status) != ga_disabled)) { ?>
403
+ <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
404
+ <?php _e('Google Analytics integration is currently enabled, but you did not enter a UID. Tracking will not occur.', 'google-analyticator'); ?>
405
+ </div>
406
+ <?php } ?>
407
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
408
+
409
+ <tr>
410
+ <td colspan="2">
411
+ <h3><?php _e('Basic Settings', 'google-analyticator'); ?></h3>
412
+ </td>
413
+ </tr>
414
+
415
+ <tr>
416
+ <th width="30%" valign="top" style="padding-top: 10px;">
417
+ <label for="<?php echo key_ga_status ?>"><?php _e('Google Analytics logging is', 'google-analyticator'); ?>:</label>
418
+ </th>
419
+ <td>
420
+ <?php
421
+ echo "<select name='".key_ga_status."' id='".key_ga_status."'>\n";
422
+
423
+ echo "<option value='".ga_enabled."'";
424
+ if(get_option(key_ga_status) == ga_enabled)
425
+ echo " selected='selected'";
426
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
427
+
428
+ echo "<option value='".ga_disabled."'";
429
+ if(get_option(key_ga_status) == ga_disabled)
430
+ echo" selected='selected'";
431
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
432
+
433
+ echo "</select>\n";
434
+ ?>
435
+ </td>
436
+ </tr>
437
+ <tr id="ga_ajax_accounts">
438
+ <th valign="top" style="padding-top: 10px;">
439
+ <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics UID', 'google-analyticator'); ?>:</label>
440
+ </th>
441
+ <td>
442
+ <?php
443
+
444
+ if( $useAuth ):
445
+
446
+ $uids = ga_get_analytics_accounts();
447
+
448
+ echo "<select name='".key_ga_uid."'> ";
449
+
450
+ foreach($uids as $id=>$domain):
451
+
452
+ echo '<option value="'.$id.'"';
453
+ // If set in DB.
454
+ if( get_option(key_ga_uid) == $id ) { echo ' selected="selected"'; }
455
+ // Else if the domain matches the current domain & nothing set in DB.
456
+ elseif( $_SERVER['HTTP_HOST'] == $domain && ( get_option(key_ga_uid) != '' ) ) { echo ' selected="selected"'; }
457
+ echo '>'.$domain.'</option>';
458
+
459
+ endforeach;
460
+
461
+ echo '</select>';
462
+
463
+ else:
464
+
465
+ echo '<input type="text" name="'.key_ga_uid.'" value="'. get_option( key_ga_uid ) .'" />';
466
+
467
+ endif;
468
+ ?>
469
+ </td>
470
+ </tr>
471
+ <tr>
472
+ <td colspan="2">
473
+ <h3><?php _e('Tracking Settings', 'google-analyticator'); ?></h3>
474
+ </td>
475
+ </tr>
476
+ <tr>
477
+ <th width="30%" valign="top" style="padding-top: 10px;">
478
+ <label for="<?php echo key_ga_admin ?>"><?php _e('Track all logged in WordPress users', 'google-analyticator'); ?>:</label>
479
+ </th>
480
+ <td>
481
+ <?php
482
+ echo "<select name='".key_ga_admin."' id='".key_ga_admin."'>\n";
483
+
484
+ echo "<option value='".ga_enabled."'";
485
+ if(get_option(key_ga_admin) == ga_enabled)
486
+ echo " selected='selected'";
487
+ echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
488
+
489
+ echo "<option value='".ga_disabled."'";
490
+ if(get_option(key_ga_admin) == ga_disabled)
491
+ echo" selected='selected'";
492
+ echo ">" . __('No', 'google-analyticator') . "</option>\n";
493
+
494
+ echo "</select>\n";
495
+
496
+ ?>
497
+ <p 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>
498
+ </td>
499
+ </tr>
500
+ <tr>
501
+ <th width="30%" valign="top" style="padding-top: 10px;">
502
+ <label for="<?php echo key_ga_admin_role ?>"><?php _e('User roles to not track', 'google-analyticator'); ?>:</label>
503
+ </th>
504
+ <td>
505
+ <?php
506
+ global $wp_roles;
507
+ $roles = $wp_roles->get_names();
508
+ $selected_roles = get_option(key_ga_admin_role);
509
+ if ( !is_array($selected_roles) ) $selected_roles = array();
510
+
511
+ # Loop through the roles
512
+ foreach ( $roles AS $role => $name ) {
513
+ echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_admin_role . '[]"';
514
+ if ( in_array($role, $selected_roles) )
515
+ echo " checked='checked'";
516
+ $name_pos = strpos($name, '|');
517
+ $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
518
+ echo ' /> ' . _x($name, 'User role') . '<br />';
519
+ }
520
+ ?>
521
+ <p 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>
522
+ </td>
523
+ </tr>
524
+ <tr>
525
+ <th width="30%" valign="top" style="padding-top: 10px;">
526
+ <label for="<?php echo key_ga_admin_disable ?>"><?php _e('Method to prevent tracking', 'google-analyticator'); ?>:</label>
527
+ </th>
528
+ <td>
529
+ <?php
530
+ echo "<select name='".key_ga_admin_disable."' id='".key_ga_admin_disable."'>\n";
531
+
532
+ echo "<option value='remove'";
533
+ if(get_option(key_ga_admin_disable) == 'remove')
534
+ echo " selected='selected'";
535
+ echo ">" . __('Remove', 'google-analyticator') . "</option>\n";
536
+
537
+ echo "<option value='admin'";
538
+ if(get_option(key_ga_admin_disable) == 'admin')
539
+ echo" selected='selected'";
540
+ echo ">" . __('Use \'admin\' variable', 'google-analyticator') . "</option>\n";
541
+
542
+ echo "</select>\n";
543
+ ?>
544
+ <p 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>
545
+ </td>
546
+ </tr>
547
+ <tr>
548
+ <th width="30%" valign="top" style="padding-top: 10px;">
549
+ <label for="<?php echo key_ga_sitespeed ?>"><?php _e('Site speed tracking', 'google-analyticator'); ?>:</label>
550
+ </th>
551
+ <td>
552
+ <?php
553
+ echo "<select name='".key_ga_sitespeed."' id='".key_ga_sitespeed."'>\n";
554
+
555
+ echo "<option value='".ga_enabled."'";
556
+ if(get_option(key_ga_sitespeed) == ga_enabled)
557
+ echo " selected='selected'";
558
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
559
+
560
+ echo "<option value='".ga_disabled."'";
561
+ if(get_option(key_ga_sitespeed) == ga_disabled)
562
+ echo" selected='selected'";
563
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
564
+
565
+ echo "</select>\n";
566
+ ?>
567
+ <p class="setting-description"><?php _e('Disabling this option will turn off the tracking required for <a href="http://www.google.com/support/analyticshelp/bin/answer.py?hl=en&answer=1205784&topic=1120718&utm_source=gablog&utm_medium=blog&utm_campaign=newga-blog&utm_content=sitespeed">Google Analytics\' Site Speed tracking report</a>.', 'google-analyticator'); ?></p>
568
+ </td>
569
+ </tr>
570
+ <tr>
571
+ <td colspan="2">
572
+ <h3>Link Tracking Settings</h3>
573
+ </td>
574
+ </tr>
575
+ <tr>
576
+ <th width="30%" valign="top" style="padding-top: 10px;">
577
+ <label for="<?php echo key_ga_outbound ?>"><?php _e('Outbound link tracking', 'google-analyticator'); ?>:</label>
578
+ </th>
579
+ <td>
580
+ <?php
581
+ echo "<select name='".key_ga_outbound."' id='".key_ga_outbound."'>\n";
582
+
583
+ echo "<option value='".ga_enabled."'";
584
+ if(get_option(key_ga_outbound) == ga_enabled)
585
+ echo " selected='selected'";
586
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
587
+
588
+ echo "<option value='".ga_disabled."'";
589
+ if(get_option(key_ga_outbound) == ga_disabled)
590
+ echo" selected='selected'";
591
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
592
+
593
+ echo "</select>\n";
594
+ ?>
595
+ <p class="setting-description"><?php _e('Disabling this option will turn off the tracking of outbound links. It\'s recommended not to disable this option unless you\'re a privacy advocate (now why would you be using Google Analytics in the first place?) or it\'s causing some kind of weird issue.', 'google-analyticator'); ?></p>
596
+ </td>
597
+ </tr>
598
+ <tr>
599
+ <th width="30%" valign="top" style="padding-top: 10px;">
600
+ <label for="<?php echo key_ga_event ?>"><?php _e('Event tracking', 'google-analyticator'); ?>:</label>
601
+ </th>
602
+ <td>
603
+ <?php
604
+ echo "<select name='".key_ga_event."' id='".key_ga_event."'>\n";
605
+
606
+ echo "<option value='".ga_enabled."'";
607
+ if(get_option(key_ga_event) == ga_enabled)
608
+ echo " selected='selected'";
609
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
610
+
611
+ echo "<option value='".ga_disabled."'";
612
+ if(get_option(key_ga_event) == ga_disabled)
613
+ echo" selected='selected'";
614
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
615
+
616
+ echo "</select>\n";
617
+ ?>
618
+ <p class="setting-description"><?php _e('Enabling this option will treat outbound links and downloads as events instead of pageviews. Since the introduction of <a href="https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide">event tracking in Analytics</a>, this is the recommended way to track these types of actions. Only disable this option if you must use the old pageview tracking method.', 'google-analyticator'); ?></p>
619
+ </td>
620
+ </tr>
621
+ <tr>
622
+ <th valign="top" style="padding-top: 10px;">
623
+ <label for="<?php echo key_ga_downloads; ?>"><?php _e('Download extensions to track', 'google-analyticator'); ?>:</label>
624
+ </th>
625
+ <td>
626
+ <?php
627
+ echo "<input type='text' size='50' ";
628
+ echo "name='".key_ga_downloads."' ";
629
+ echo "id='".key_ga_downloads."' ";
630
+ echo "value='".stripslashes(get_option(key_ga_downloads))."' />\n";
631
+ ?>
632
+ <p class="setting-description"><?php _e('Enter any extensions of files you would like to be tracked as a download. For example to track all MP3s and PDFs enter <strong>mp3,pdf</strong>. <em>Outbound link tracking must be enabled for downloads to be tracked.</em>', 'google-analyticator'); ?></p>
633
+ </td>
634
+ </tr>
635
+ <tr>
636
+ <th valign="top" style="padding-top: 10px;">
637
+ <label for="<?php echo key_ga_outbound_prefix; ?>"><?php _e('Prefix external links with', 'google-analyticator'); ?>:</label>
638
+ </th>
639
+ <td>
640
+ <?php
641
+ echo "<input type='text' size='50' ";
642
+ echo "name='".key_ga_outbound_prefix."' ";
643
+ echo "id='".key_ga_outbound_prefix."' ";
644
+ echo "value='".stripslashes(get_option(key_ga_outbound_prefix))."' />\n";
645
+ ?>
646
+ <p class="setting-description"><?php _e('Enter a name for the section tracked external links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator'); ?></em></p>
647
+ </td>
648
+ </tr>
649
+ <tr>
650
+ <th valign="top" style="padding-top: 10px;">
651
+ <label for="<?php echo key_ga_downloads_prefix; ?>"><?php _e('Prefix download links with', 'google-analyticator'); ?>:</label>
652
+ </th>
653
+ <td>
654
+ <?php
655
+ echo "<input type='text' size='50' ";
656
+ echo "name='".key_ga_downloads_prefix."' ";
657
+ echo "id='".key_ga_downloads_prefix."' ";
658
+ echo "value='".stripslashes(get_option(key_ga_downloads_prefix))."' />\n";
659
+ ?>
660
+ <p class="setting-description"><?php _e('Enter a name for the section tracked download links will appear under. This option has no effect if event tracking is enabled.', 'google-analyticator'); ?></em></p>
661
+ </td>
662
+ </tr>
663
+ <tr>
664
+ <th valign="top" style="padding-top: 10px;">
665
+ <label for="<?php echo key_ga_adsense; ?>"><?php _e('Google Adsense ID', 'google-analyticator'); ?>:</label>
666
+ </th>
667
+ <td>
668
+ <?php
669
+ echo "<input type='text' size='50' ";
670
+ echo "name='".key_ga_adsense."' ";
671
+ echo "id='".key_ga_adsense."' ";
672
+ echo "value='".get_option(key_ga_adsense)."' />\n";
673
+ ?>
674
+ <p 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>
675
+ </td>
676
+ </tr>
677
+ <tr>
678
+ <td colspan="2">
679
+ <h3>Additional Tracking Code </h3>
680
+ </td>
681
+ </tr>
682
+ <tr>
683
+ <th valign="top" style="padding-top: 10px;">
684
+ <label for="<?php echo key_ga_extra; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('before tracker initialization', 'google-analyticator'); ?>):</label>
685
+ </th>
686
+ <td>
687
+ <?php
688
+ echo "<textarea cols='50' rows='8' ";
689
+ echo "name='".key_ga_extra."' ";
690
+ echo "id='".key_ga_extra."'>";
691
+ echo stripslashes(get_option(key_ga_extra))."</textarea>\n";
692
+ ?>
693
+ <p class="setting-description"><?php _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>before</strong> the Google Analytics tracker is initialized.', 'google-analyticator'); ?></p>
694
+ </td>
695
+ </tr>
696
+ <tr>
697
+ <th valign="top" style="padding-top: 10px;">
698
+ <label for="<?php echo key_ga_extra_after; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('after tracker initialization', 'google-analyticator'); ?>):</label>
699
+ </th>
700
+ <td>
701
+ <?php
702
+ echo "<textarea cols='50' rows='8' ";
703
+ echo "name='".key_ga_extra_after."' ";
704
+ echo "id='".key_ga_extra_after."'>";
705
+ echo stripslashes(get_option(key_ga_extra_after))."</textarea>\n";
706
+ ?>
707
+ <p class="setting-description"><?php _e('Enter any additional lines of tracking code that you would like to include in the Google Analytics tracking script. The code in this section will be displayed <strong>after</strong> the Google Analytics tracker is initialized.', 'google-analyticator'); ?></p>
708
+ </td>
709
+ </tr>
710
+ <tr>
711
+ <td colspan="2">
712
+ <h3>Admin Dashboard Widgets</h3>
713
+ <?php if(!$useAuth): ?>
714
+ <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
715
+ <?php _e('You have not authenticated with Google - you cannot use dashboard widgets! Reset the plugin to authenticate..', 'google-analyticator'); ?>
716
+ </div>
717
+ <?php endif;?>
718
+ </td>
719
+ </tr>
720
+ <tr<?php if(!$useAuth){echo ' style="display:none"';}?>>
721
+ <th width="30%" valign="top" style="padding-top: 10px;">
722
+ <label for="<?php echo key_ga_widgets; ?>"><?php _e('Include widgets', 'google-analyticator'); ?>:</label>
723
+ </th>
724
+ <td>
725
+ <?php
726
+ echo "<select name='".key_ga_widgets."' id='".key_ga_widgets."'>\n";
727
+
728
+ echo "<option value='".ga_enabled."'";
729
+ if(get_option(key_ga_widgets) == ga_enabled)
730
+ echo " selected='selected'";
731
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
732
+
733
+ echo "<option value='".ga_disabled."'";
734
+ if(get_option(key_ga_widgets) == ga_disabled)
735
+ echo" selected='selected'";
736
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
737
+
738
+ echo "</select>\n";
739
+ ?>
740
+ <p class="setting-description"><?php _e('Disabling this option will completely remove the Dashboard Summary widget and the theme Stats widget. Use this option if you would prefer to not see the widgets.', 'google-analyticator'); ?></p>
741
+ </td>
742
+ </tr>
743
+ <tr<?php if(!$useAuth){echo ' style="display:none"';}?>>
744
+ <th width="30%" valign="top" style="padding-top: 10px;">
745
+ <label for="<?php echo key_ga_dashboard_role ?>"><?php _e('User roles that can see the dashboard widget', 'google-analyticator'); ?>:</label>
746
+ </th>
747
+ <td>
748
+ <?php
749
+ global $wp_roles;
750
+ $roles = $wp_roles->get_names();
751
+ $selected_roles = get_option(key_ga_dashboard_role);
752
+ if ( !is_array($selected_roles) ) $selected_roles = array();
753
+
754
+ # Loop through the roles
755
+ foreach ( $roles AS $role => $name ) {
756
+ echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_dashboard_role . '[]"';
757
+ if ( in_array($role, $selected_roles) )
758
+ echo " checked='checked'";
759
+ $name_pos = strpos($name, '|');
760
+ $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
761
+ echo ' /> ' . _x($name, 'User role') . '<br />';
762
+ }
763
+ ?>
764
+ <p 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>
765
+ </td>
766
+ </tr>
767
+
768
+ </table>
769
+ <p class="submit">
770
+ <input type="submit" name="info_update" value="<?php _e('Save Changes', 'google-analyticator'); ?>" />
771
+ </p>
772
+
773
+ <a href="<?php echo admin_url('/options-general.php?page=ga_reset'); ?>"><?php _e('Deauthorize &amp; Reset Google Analyticator.', 'google-analyticator'); ?></a>
774
+
775
+ </form>
776
+
777
+
778
+ <?php if (!get_option('wpm_o_user_id')): ?>
779
+ <img src="<?php echo plugins_url('wlcms-plugin-advert.png', __FILE__ ); ?>" alt="Learn how to make WordPress better" />
780
+ <form method="post" onsubmit="return quickValidate()" action="http://www.aweber.com/scripts/addlead.pl" target="_blank" >
781
+ <div style="display: none;">
782
+ <input type="hidden" name="meta_web_form_id" value="672327302" />
783
+ <input type="hidden" name="meta_split_id" value="" />
784
+ <input type="hidden" name="listname" value="vumpublic2" />
785
+ <input type="hidden" name="redirect" value="http://www.aweber.com/thankyou-coi.htm?m=video" id="redirect_9567c93ed4b6fb0c7cd9247553c362eb" />
786
+ <input type="hidden" name="meta_adtracking" value="ga-plugin" />
787
+ <input type="hidden" name="meta_message" value="1" />
788
+ <input type="hidden" name="meta_required" value="name,email" />
789
+ <input type="hidden" name="meta_tooltip" value="" />
790
+ </div>
791
+ <table style="text-align:center;margin-left: 20px;">
792
+ <tr>
793
+ <td><label class="previewLabel" for="awf_field-37978044"><strong>Name: </strong></label><input id="sub_name" type="text" name="name" class="text" tabindex="500" value="" /></td>
794
+ <td><label class="previewLabel" for="awf_field-37978045"><strong>Email: </strong></label> <input class="text" id="sub_email" type="text" name="email" tabindex="501" value="" /></td>
795
+ <td><span class="submit"><input name="submit" type="image" alt="submit" tabindex="502" src="<?php echo plugins_url('download-button.png', __FILE__); ?>" width="157" height="40" style="background: none; border: 0;" /></span></td>
796
+ </tr>
797
+ <tr>
798
+ <td colspan="3" style="padding-top: 20px;">
799
+ <a title="Privacy Policy" href="http://www.aweber.com/permission.htm" target="_blank"><img src="<?php echo plugins_url('privacy.png', __FILE__); ?>" alt="" title="" /></a>
800
+ </td>
801
+ </tr>
802
+ </table>
803
+ </form>
804
+ <?php endif;?>
805
+
806
+ <script type="text/javascript">
807
+ function quickValidate()
808
+ {
809
+ if (! jQuery('#sub_name').val() )
810
+ {
811
+ alert('Your Name is required');
812
+ return false;
813
+ }
814
+ if(! jQuery('#sub_email').val() )
815
+ {
816
+ alert('Your Email is required');
817
+ return false;
818
+ }
819
+
820
+ return true;
821
+
822
+ }
823
+ </script>
824
+
825
+ </div>
826
+ </form>
827
+
828
+ <?php
829
+ }
830
+
831
+ function ga_sort_account_list($a, $b) {
832
+ return strcmp($a['title'],$b['title']);
833
+ }
834
+
835
+ /**
836
+ * Checks if the WordPress API is a valid method for selecting an account
837
+ *
838
+ * @return a list of accounts if available, false if none available
839
+ **/
840
+ function ga_get_analytics_accounts()
841
+ {
842
+ $accounts = array();
843
+
844
+ # Get the class for interacting with the Google Analytics
845
+ require_once('class.analytics.stats.php');
846
+
847
+ # Create a new Gdata call
848
+ if ( isset($_POST['token']) && $_POST['token'] != '' )
849
+ $stats = new GoogleAnalyticsStats($_POST['token']);
850
+ elseif ( trim(get_option('ga_google_token')) != '' )
851
+ $stats = new GoogleAnalyticsStats();
852
+ else
853
+ return false;
854
+
855
+ # Check if Google sucessfully logged in
856
+ if ( ! $stats->checkLogin() )
857
+ return false;
858
+
859
+ # Get a list of accounts
860
+ $accounts = $stats->getAllProfiles();
861
+
862
+ natcasesort ($accounts);
863
+
864
+ # Return the account array if there are accounts
865
+ if ( count($accounts) > 0 )
866
+ return $accounts;
867
+ else
868
+ return false;
869
+ }
870
+
871
+ /**
872
+ * Add http_build_query if it doesn't exist already
873
+ **/
874
+ if ( !function_exists('http_build_query') ) {
875
+ function http_build_query($params, $key = null)
876
+ {
877
+ $ret = array();
878
+
879
+ foreach( (array) $params as $name => $val ) {
880
+ $name = urlencode($name);
881
+
882
+ if ( $key !== null )
883
+ $name = $key . "[" . $name . "]";
884
+
885
+ if ( is_array($val) || is_object($val) )
886
+ $ret[] = http_build_query($val, $name);
887
+ elseif ($val !== null)
888
+ $ret[] = $name . "=" . urlencode($val);
889
+ }
890
+
891
+ return implode("&", $ret);
892
+ }
893
+ }
894
+
895
+ /**
896
+ * Echos out the core Analytics tracking code
897
+ **/
898
+ function add_google_analytics()
899
+ {
900
+ # Fetch variables used in the tracking code
901
+ $uid = stripslashes(get_option(key_ga_uid));
902
+ $extra = stripslashes(get_option(key_ga_extra));
903
+ $extra_after = stripslashes(get_option(key_ga_extra_after));
904
+ $extensions = str_replace (",", "|", get_option(key_ga_downloads));
905
+
906
+ # Determine if the GA is enabled and contains a valid UID
907
+ if ( ( get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
908
+ {
909
+ # Determine if the user is an admin, and should see the tracking code
910
+ if ( ( get_option(key_ga_admin) == ga_enabled || !ga_current_user_is(get_option(key_ga_admin_role)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' )
911
+ {
912
+ # Disable the tracking code on the post preview page
913
+ if ( !function_exists("is_preview") || ( function_exists("is_preview") && !is_preview() ) )
914
+ {
915
+ # Add the notice that Google Analyticator tracking is enabled
916
+ echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://www.videousermanuals.com/google-analyticator/ -->\n";
917
+
918
+ # Add the Adsense data if specified
919
+ if ( get_option(key_ga_adsense) != '' )
920
+ echo '<script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n";
921
+
922
+ # Include the file types to track
923
+ $extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
924
+ $ext = "";
925
+ foreach ( $extensions AS $extension )
926
+ $ext .= "'$extension',";
927
+ $ext = substr($ext, 0, -1);
928
+
929
+ # Include the link tracking prefixes
930
+ $outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
931
+ $downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
932
+ $event_tracking = get_option(key_ga_event);
933
+
934
+ ?>
935
+ <script type="text/javascript">
936
+ var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
937
+ <?php if ( $event_tracking != 'enabled' ) { ?>
938
+ var analyticsOutboundPrefix = '/<?php echo $outbound_prefix; ?>/';
939
+ var analyticsDownloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
940
+ <?php } ?>
941
+ var analyticsEventTracking = '<?php echo $event_tracking; ?>';
942
+ </script>
943
+ <?php
944
+ # Add the first part of the core tracking code
945
+ ?>
946
+ <script type="text/javascript">
947
+ var _gaq = _gaq || [];
948
+ _gaq.push(['_setAccount', '<?php echo $uid; ?>']);
949
+ _gaq.push(['_addDevId', 'i9k95']); // Google Analyticator App ID with Google
950
+ <?php
951
+
952
+ # Add any tracking code before the trackPageview
953
+ do_action('google_analyticator_extra_js_before');
954
+ if ( '' != $extra )
955
+ echo " $extra\n";
956
+
957
+ # Add the track pageview function
958
+ echo " _gaq.push(['_trackPageview']);\n";
959
+
960
+ # Add the site speed tracking
961
+ if ( get_option(key_ga_sitespeed) == ga_enabled )
962
+ echo " _gaq.push(['_trackPageLoadTime']);\n";
963
+
964
+ # Disable page tracking if admin is logged in
965
+ if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(key_ga_admin_role)) ) )
966
+ echo " _gaq.push(['_setCustomVar', 'admin']);\n";
967
+
968
+ # Add any tracking code after the trackPageview
969
+ do_action('google_analyticator_extra_js_after');
970
+ if ( '' != $extra_after )
971
+ echo " $extra_after\n";
972
+
973
+ # Add the final section of the tracking code
974
+ ?>
975
+
976
+ (function() {
977
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
978
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
979
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
980
+ })();
981
+ </script>
982 </