Google Analyticator - Version 6.4.4.3

Version Description

  • Bug fix: Duplicate data sometimes showing
  • Bug fix: Flotr jQuery library clash with WooCommerce.
Download this release

Release Info

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

Code changes from version 6.4.3 to 6.4.4.3

Files changed (73) hide show
  1. class.analytics.stats.php +265 -264
  2. external-tracking.js +44 -43
  3. external-tracking.min.js +1 -5
  4. ga-md-ad-532.png +0 -0
  5. ga-plugin-advert.jpg +0 -0
  6. google-analyticator.php +1045 -1052
  7. google-analytics-stats-widget.php +243 -243
  8. google-analytics-summary-widget.php +652 -529
  9. google-api-php-client/src/Google_Client.php +453 -0
  10. google-api-php-client/src/auth/Google_AssertionCredentials.php +95 -0
  11. google-api-php-client/src/auth/Google_Auth.php +36 -0
  12. google-api-php-client/src/auth/Google_AuthNone.php +48 -0
  13. google-api-php-client/src/auth/Google_LoginTicket.php +63 -0
  14. google-api-php-client/src/auth/Google_OAuth2.php +444 -0
  15. google-api-php-client/src/auth/Google_P12Signer.php +70 -0
  16. google-api-php-client/src/auth/Google_PemVerifier.php +66 -0
  17. google-api-php-client/src/auth/Google_Signer.php +30 -0
  18. google-api-php-client/src/auth/Google_Verifier.php +31 -0
  19. google-api-php-client/src/cache/Google_ApcCache.php +98 -0
  20. google-api-php-client/src/cache/Google_Cache.php +55 -0
  21. google-api-php-client/src/cache/Google_FileCache.php +137 -0
  22. google-api-php-client/src/cache/Google_MemcacheCache.php +130 -0
  23. google-api-php-client/src/config.php +81 -0
  24. google-api-php-client/src/contrib/Google_AdexchangebuyerService.php +567 -0
  25. google-api-php-client/src/contrib/Google_AdsenseService.php +1140 -0
  26. google-api-php-client/src/contrib/Google_AdsensehostService.php +1378 -0
  27. google-api-php-client/src/contrib/Google_AnalyticsService.php +1887 -0
  28. google-api-php-client/src/contrib/Google_BigqueryService.php +1821 -0
  29. google-api-php-client/src/contrib/Google_BloggerService.php +1301 -0
  30. google-api-php-client/src/contrib/Google_BooksService.php +2793 -0
  31. google-api-php-client/src/contrib/Google_CalendarService.php +1931 -0
  32. google-api-php-client/src/contrib/Google_ComputeService.php +2629 -0
  33. google-api-php-client/src/contrib/Google_CustomsearchService.php +836 -0
  34. google-api-php-client/src/contrib/Google_DriveService.php +2157 -0
  35. google-api-php-client/src/contrib/Google_FreebaseService.php +89 -0
  36. google-api-php-client/src/contrib/Google_FusiontablesService.php +1326 -0
  37. google-api-php-client/src/contrib/Google_GanService.php +1605 -0
  38. google-api-php-client/src/contrib/Google_LatitudeService.php +283 -0
  39. google-api-php-client/src/contrib/Google_LicensingService.php +285 -0
  40. google-api-php-client/src/contrib/Google_ModeratorService.php +1888 -0
  41. google-api-php-client/src/contrib/Google_Oauth2Service.php +265 -0
  42. google-api-php-client/src/contrib/Google_OrkutService.php +2554 -0
  43. google-api-php-client/src/contrib/Google_PagespeedonlineService.php +474 -0
  44. google-api-php-client/src/contrib/Google_PlusMomentsService.php +567 -0
  45. google-api-php-client/src/contrib/Google_PlusService.php +1525 -0
  46. google-api-php-client/src/contrib/Google_PredictionService.php +429 -0
  47. google-api-php-client/src/contrib/Google_ShoppingService.php +1311 -0
  48. google-api-php-client/src/contrib/Google_SiteVerificationService.php +287 -0
  49. google-api-php-client/src/contrib/Google_StorageService.php +1076 -0
  50. google-api-php-client/src/contrib/Google_TaskqueueService.php +423 -0
  51. google-api-php-client/src/contrib/Google_TasksService.php +580 -0
  52. google-api-php-client/src/contrib/Google_TranslateService.php +244 -0
  53. google-api-php-client/src/contrib/Google_UrlshortenerService.php +325 -0
  54. google-api-php-client/src/contrib/Google_WebfontsService.php +130 -0
  55. google-api-php-client/src/contrib/Google_YoutubeService.php +996 -0
  56. google-api-php-client/src/external/URITemplateParser.php +214 -0
  57. google-api-php-client/src/io/Google_CacheParser.php +173 -0
  58. google-api-php-client/src/io/Google_CurlIO.php +278 -0
  59. google-api-php-client/src/io/Google_HttpRequest.php +304 -0
  60. google-api-php-client/src/io/Google_IO.php +49 -0
  61. google-api-php-client/src/io/Google_REST.php +128 -0
  62. google-api-php-client/src/io/cacerts.pem +714 -0
  63. google-api-php-client/src/local_config.php +81 -0
  64. google-api-php-client/src/service/Google_BatchRequest.php +110 -0
  65. google-api-php-client/src/service/Google_MediaFileUpload.php +244 -0
  66. google-api-php-client/src/service/Google_Model.php +115 -0
  67. google-api-php-client/src/service/Google_Service.php +22 -0
  68. google-api-php-client/src/service/Google_ServiceResource.php +196 -0
  69. google-api-php-client/src/service/Google_Utils.php +117 -0
  70. google-api-php-client/static/Credentials.png +0 -0
  71. index.png +0 -0
  72. jquery.flot.min.js +6 -0
  73. readme.txt +25 -7
class.analytics.stats.php CHANGED
@@ -1,265 +1,266 @@
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
- **/
15
- class GoogleAnalyticsStats
16
- {
17
-
18
- var $client = false;
19
- var $accountId;
20
- var $baseFeed = 'https://www.googleapis.com/analytics/v3';
21
- var $token = false;
22
-
23
-
24
- /**
25
- * Constructor
26
- *
27
- * @param token - a one-time use token to be exchanged for a real token
28
- **/
29
- function GoogleAnalyticsStats()
30
- {
31
- $this->client = new Google_Client();
32
- $this->client->setApprovalPrompt("force");
33
- $this->client->setAccessType('offline');
34
- $this->client->setClientId(GOOGLE_ANALYTICATOR_CLIENTID);
35
- $this->client->setClientSecret(GOOGLE_ANALYTICATOR_CLIENTSECRET);
36
- $this->client->setRedirectUri(GOOGLE_ANALYTICATOR_REDIRECT);
37
- $this->client->setScopes(array(GOOGLE_ANALYTICATOR_SCOPE));
38
-
39
- // Magic. Returns objects from the Analytics Service instead of associative arrays.
40
- $this->client->setUseObjects(true);
41
-
42
- try {
43
- $this->analytics = new Google_AnalyticsService($this->client);
44
- }
45
- catch (Google_ServiceException $e)
46
- {
47
- print '(cas:48) There was an Analytics API service error ' . $e->getCode() . ':' . $e->getMessage();
48
- }
49
- }
50
-
51
- function checkLogin()
52
- {
53
- $ga_google_authtoken = get_option('ga_google_authtoken');
54
-
55
- if (!empty($ga_google_authtoken))
56
- {
57
- $this->client->setAccessToken($ga_google_authtoken);
58
- }
59
- else
60
- {
61
- $authCode = get_option('ga_google_token');
62
-
63
- if (empty($authCode)) return false;
64
-
65
- try
66
- {
67
- $accessToken = $this->client->authenticate($authCode);
68
- }
69
- catch( Exception $e )
70
- {
71
- print '(cas:72) Google Analyticator was unable to authenticate you with
72
- Google using the Auth Token you pasted into the input box on the previous step. <br><br>
73
- This could mean either you pasted the token wrong, or the time/date on your server is wrong,
74
- or an SSL issue preventing Google from Authenticating. <br><br>
75
- <a href="' . admin_url('/options-general.php?page=ga_reset').'"> Try Deauthorizing &amp; Resetting Google Analyticator.</a>
76
- <br><br><strong>Tech Info </strong> ' . $e->getCode() . ':' . $e->getMessage();
77
-
78
- return false;
79
- }
80
-
81
- if($accessToken)
82
- {
83
- $this->client->setAccessToken($accessToken);
84
- update_option('ga_google_authtoken', $accessToken);
85
- }
86
- else
87
- {
88
- return false;
89
- }
90
- }
91
-
92
- $this->token = $this->client->getAccessToken();
93
- return true;
94
- }
95
-
96
- function deauthorize()
97
- {
98
- update_option('ga_google_token', '');
99
- update_option('ga_google_authtoken', '');
100
- }
101
-
102
- function getSingleProfile()
103
- {
104
- $webproperty_id = get_option('ga_uid');
105
- list($pre, $account_id, $post) = explode('-',$webproperty_id);
106
-
107
- if (empty($webproperty_id)) return false;
108
-
109
- try {
110
- $profiles = $this->analytics->management_profiles->listManagementProfiles($account_id, $webproperty_id);
111
- }
112
- catch (Google_ServiceException $e)
113
- {
114
- print 'There was an Analytics API service error ' . $e->getCode() . ': ' . $e->getMessage();
115
- return false;
116
- }
117
-
118
- $profile_id = $profiles->items[0]->id;
119
- if (empty($profile_id)) return false;
120
-
121
- $account_array = array();
122
- array_push($account_array, array('id'=>$profile_id, 'ga:webPropertyId'=>$webproperty_id));
123
- return $account_array;
124
- }
125
-
126
- function getAllProfiles()
127
- {
128
- $profile_array = array();
129
-
130
- try {
131
- $profiles = $this->analytics->management_webproperties->listManagementWebproperties('~all');
132
- }
133
- catch (Google_ServiceException $e)
134
- {
135
- print 'There was an Analytics API service error ' . $e->getCode() . ': ' . $e->getMessage();
136
- }
137
-
138
-
139
- if( !empty( $profiles->items ) )
140
- {
141
- foreach( $profiles->items as $profile )
142
- {
143
- $profile_array[ $profile->id ] = str_replace('http://','',$profile->name );
144
- }
145
- }
146
-
147
- return $profile_array;
148
- }
149
-
150
- function getAnalyticsAccounts()
151
- {
152
- $analytics = new Google_AnalyticsService($this->client);
153
- $accounts = $analytics->management_accounts->listManagementAccounts();
154
- $account_array = array();
155
-
156
- $items = $accounts->getItems();
157
-
158
- if (count($items) > 0) {
159
- foreach ($items as $key => $item)
160
- {
161
- $account_id = $item->getId();
162
-
163
- $webproperties = $analytics->management_webproperties->listManagementWebproperties($account_id);
164
-
165
- if (!empty($webproperties))
166
- {
167
- foreach ($webproperties->getItems() as $webp_key => $webp_item) {
168
- $profiles = $analytics->management_profiles->listManagementProfiles($account_id, $webp_item->id);
169
-
170
- $profile_id = $profiles->items[0]->id;
171
- array_push($account_array, array('id'=>$profile_id, 'ga:webPropertyId'=>$webp_item->id));
172
- }
173
- }
174
- }
175
-
176
- return $account_array;
177
- }
178
- return false;
179
-
180
- }
181
-
182
-
183
-
184
- /**
185
- * Sets the account id to use for queries
186
- *
187
- * @param id - the account id
188
- **/
189
- function setAccount($id)
190
- {
191
- $this->accountId = $id;
192
- }
193
-
194
-
195
- /**
196
- * Get a specific data metrics
197
- *
198
- * @param metrics - the metrics to get
199
- * @param startDate - the start date to get
200
- * @param endDate - the end date to get
201
- * @param dimensions - the dimensions to grab
202
- * @param sort - the properties to sort on
203
- * @param filter - the property to filter on
204
- * @param limit - the number of items to get
205
- * @return the specific metrics in array form
206
- **/
207
- function getMetrics($metric, $startDate, $endDate, $dimensions = false, $sort = false, $filter = false, $limit = false)
208
- {
209
- $analytics = new Google_AnalyticsService($this->client);
210
-
211
- $params = array();
212
-
213
- if ($dimensions)
214
- {
215
- $params['dimensions'] = $dimensions;
216
- }
217
- if ($sort)
218
- {
219
- $params['sort'] = $sort;
220
- }
221
- if ($filter)
222
- {
223
- $params['filters'] = $filter;
224
- }
225
- if ($limit)
226
- {
227
- $params['max-results'] = $limit;
228
- }
229
-
230
- // Just incase, the ga: is still used in the account id, strip it out to prevent it breaking
231
- $filtered_id = str_replace( 'ga:', '', $this->accountId );
232
-
233
- if(!$filtered_id){
234
- echo 'Error - Account ID is blank';
235
- return false;
236
- }
237
-
238
- return $analytics->data_ga->get(
239
- 'ga:'.$filtered_id,
240
- $startDate,
241
- $endDate,
242
- $metric,
243
- $params
244
- );
245
- }
246
-
247
-
248
-
249
-
250
-
251
- /**
252
- * Checks the date against Jan. 1 2005 because GA API only works until that date
253
- *
254
- * @param date - the date to compare
255
- * @return the correct date
256
- **/
257
- function verifyStartDate($date)
258
- {
259
- if ( strtotime($date) > strtotime('2005-01-01') )
260
- return $date;
261
- else
262
- return '2005-01-01';
263
- }
264
-
265
} // END class
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
+ **/
15
+ class GoogleAnalyticsStats
16
+ {
17
+
18
+ var $client = false;
19
+ var $accountId;
20
+ var $baseFeed = 'https://www.googleapis.com/analytics/v3';
21
+ var $token = false;
22
+
23
+
24
+ /**
25
+ * Constructor
26
+ *
27
+ * @param token - a one-time use token to be exchanged for a real token
28
+ **/
29
+ function GoogleAnalyticsStats()
30
+ {
31
+ $this->client = new Google_Client();
32
+ $this->client->setApprovalPrompt("force");
33
+ $this->client->setAccessType('offline');
34
+ $this->client->setClientId(GOOGLE_ANALYTICATOR_CLIENTID);
35
+ $this->client->setClientSecret(GOOGLE_ANALYTICATOR_CLIENTSECRET);
36
+ $this->client->setRedirectUri(GOOGLE_ANALYTICATOR_REDIRECT);
37
+
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 '(cas:48) There was an Analytics API service error ' . $e->getCode() . ':' . $e->getMessage();
49
+ }
50
+ }
51
+
52
+ function checkLogin()
53
+ {
54
+ $ga_google_authtoken = get_option('ga_google_authtoken');
55
+
56
+ if (!empty($ga_google_authtoken))
57
+ {
58
+ $this->client->setAccessToken($ga_google_authtoken);
59
+ }
60
+ else
61
+ {
62
+ $authCode = get_option('ga_google_token');
63
+
64
+ if (empty($authCode)) return false;
65
+
66
+ try
67
+ {
68
+ $accessToken = $this->client->authenticate($authCode);
69
+ }
70
+ catch( Exception $e )
71
+ {
72
+ print '(cas:72) Google Analyticator was unable to authenticate you with
73
+ Google using the Auth Token you pasted into the input box on the previous step. <br><br>
74
+ This could mean either you pasted the token wrong, or the time/date on your server is wrong,
75
+ or an SSL issue preventing Google from Authenticating. <br><br>
76
+ <a href="' . admin_url('/options-general.php?page=ga_reset').'"> Try Deauthorizing &amp; Resetting Google Analyticator.</a>
77
+ <br><br><strong>Tech Info </strong> ' . $e->getCode() . ':' . $e->getMessage();
78
+
79
+ return false;
80
+ }
81
+
82
+ if($accessToken)
83
+ {
84
+ $this->client->setAccessToken($accessToken);
85
+ update_option('ga_google_authtoken', $accessToken);
86
+ }
87
+ else
88
+ {
89
+ return false;
90
+ }
91
+ }
92
+
93
+ $this->token = $this->client->getAccessToken();
94
+ return true;
95
+ }
96
+
97
+ function deauthorize()
98
+ {
99
+ update_option('ga_google_token', '');
100
+ update_option('ga_google_authtoken', '');
101
+ }
102
+
103
+ function getSingleProfile()
104
+ {
105
+ $webproperty_id = get_option('ga_uid');
106
+ list($pre, $account_id, $post) = explode('-',$webproperty_id);
107
+
108
+ if (empty($webproperty_id)) return false;
109
+
110
+ try {
111
+ $profiles = $this->analytics->management_profiles->listManagementProfiles($account_id, $webproperty_id);
112
+ }
113
+ catch (Google_ServiceException $e)
114
+ {
115
+ print 'There was an Analytics API service error ' . $e->getCode() . ': ' . $e->getMessage();
116
+ return false;
117
+ }
118
+
119
+ $profile_id = $profiles->items[0]->id;
120
+ if (empty($profile_id)) return false;
121
+
122
+ $account_array = array();
123
+ array_push($account_array, array('id'=>$profile_id, 'ga:webPropertyId'=>$webproperty_id));
124
+ return $account_array;
125
+ }
126
+
127
+ function getAllProfiles()
128
+ {
129
+ $profile_array = array();
130
+
131
+ try {
132
+ $profiles = $this->analytics->management_webproperties->listManagementWebproperties('~all');
133
+ }
134
+ catch (Google_ServiceException $e)
135
+ {
136
+ print 'There was an Analytics API service error ' . $e->getCode() . ': ' . $e->getMessage();
137
+ }
138
+
139
+
140
+ if( !empty( $profiles->items ) )
141
+ {
142
+ foreach( $profiles->items as $profile )
143
+ {
144
+ $profile_array[ $profile->id ] = str_replace('http://','',$profile->name );
145
+ }
146
+ }
147
+
148
+ return $profile_array;
149
+ }
150
+
151
+ function getAnalyticsAccounts()
152
+ {
153
+ $analytics = new Google_AnalyticsService($this->client);
154
+ $accounts = $analytics->management_accounts->listManagementAccounts();
155
+ $account_array = array();
156
+
157
+ $items = $accounts->getItems();
158
+
159
+ if (count($items) > 0) {
160
+ foreach ($items as $key => $item)
161
+ {
162
+ $account_id = $item->getId();
163
+
164
+ $webproperties = $analytics->management_webproperties->listManagementWebproperties($account_id);
165
+
166
+ if (!empty($webproperties))
167
+ {
168
+ foreach ($webproperties->getItems() as $webp_key => $webp_item) {
169
+ $profiles = $analytics->management_profiles->listManagementProfiles($account_id, $webp_item->id);
170
+
171
+ $profile_id = $profiles->items[0]->id;
172
+ array_push($account_array, array('id'=>$profile_id, 'ga:webPropertyId'=>$webp_item->id));
173
+ }
174
+ }
175
+ }
176
+
177
+ return $account_array;
178
+ }
179
+ return false;
180
+
181
+ }
182
+
183
+
184
+
185
+ /**
186
+ * Sets the account id to use for queries
187
+ *
188
+ * @param id - the account id
189
+ **/
190
+ function setAccount($id)
191
+ {
192
+ $this->accountId = $id;
193
+ }
194
+
195
+
196
+ /**
197
+ * Get a specific data metrics
198
+ *
199
+ * @param metrics - the metrics to get
200
+ * @param startDate - the start date to get
201
+ * @param endDate - the end date to get
202
+ * @param dimensions - the dimensions to grab
203
+ * @param sort - the properties to sort on
204
+ * @param filter - the property to filter on
205
+ * @param limit - the number of items to get
206
+ * @return the specific metrics in array form
207
+ **/
208
+ function getMetrics($metric, $startDate, $endDate, $dimensions = false, $sort = false, $filter = false, $limit = false)
209
+ {
210
+ $analytics = new Google_AnalyticsService($this->client);
211
+
212
+ $params = array();
213
+
214
+ if ($dimensions)
215
+ {
216
+ $params['dimensions'] = $dimensions;
217
+ }
218
+ if ($sort)
219
+ {
220
+ $params['sort'] = $sort;
221
+ }
222
+ if ($filter)
223
+ {
224
+ $params['filters'] = $filter;
225
+ }
226
+ if ($limit)
227
+ {
228
+ $params['max-results'] = $limit;
229
+ }
230
+
231
+ // Just incase, the ga: is still used in the account id, strip it out to prevent it breaking
232
+ $filtered_id = str_replace( 'ga:', '', $this->accountId );
233
+
234
+ if(!$filtered_id){
235
+ echo 'Error - Account ID is blank';
236
+ return false;
237
+ }
238
+
239
+ return $analytics->data_ga->get(
240
+ 'ga:'.$filtered_id,
241
+ $startDate,
242
+ $endDate,
243
+ $metric,
244
+ $params
245
+ );
246
+ }
247
+
248
+
249
+
250
+
251
+
252
+ /**
253
+ * Checks the date against Jan. 1 2005 because GA API only works until that date
254
+ *
255
+ * @param date - the date to compare
256
+ * @return the correct date
257
+ **/
258
+ function verifyStartDate($date)
259
+ {
260
+ if ( strtotime($date) > strtotime('2005-01-01') )
261
+ return $date;
262
+ else
263
+ return '2005-01-01';
264
+ }
265
+
266
} // END class
external-tracking.js CHANGED
@@ -1,44 +1,45 @@
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 (typeof analyticsFileTypes != "undefined") {
19
+ // If the link is a download
20
+ if (jQuery.inArray(extension,analyticsFileTypes) != -1) {
21
+ // Mark the link as already tracked
22
+ downloadTracked = true;
23
+
24
+ // Add the tracking code
25
+ a.click(function() {
26
+ if ( analyticsEventTracking == 'enabled' ) {
27
+ _gaq.push(['_trackEvent', 'Downloads', extension.toUpperCase(), href]);
28
+ } else
29
+ _gaq.push(['_trackPageview', analyticsDownloadsPrefix + url]);
30
+ });
31
+ }
32
+ }
33
+ // If the link is external
34
+ if ( ( href.match(/^http/) ) && ( !href.match(document.domain) ) && ( downloadTracked == false ) ) {
35
+ // Add the tracking code
36
+ a.click(function() {
37
+ if ( analyticsEventTracking == 'enabled' ) {
38
+ _gaq.push(['_trackEvent', 'Outbound Traffic', href.match(/:\/\/(.[^/]+)/)[1], href]);
39
+ } else
40
+ _gaq.push(['_trackPageview', analyticsOutboundPrefix + url]);
41
+ });
42
+ }
43
+ });
44
+
45
});
external-tracking.min.js CHANGED
@@ -1,5 +1 @@
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 e=jQuery(this);var t=e.attr("href");if(t==undefined)return;var n=t.replace("http://","").replace("https://","");var r=t.split(".").reverse();var i=r[0].toLowerCase();var r=t.split("/").reverse();var s=r[2];var o=false;if(typeof analyticsFileTypes!="undefined"){if(jQuery.inArray(i,analyticsFileTypes)!=-1){o=true;e.click(function(){if(analyticsEventTracking=="enabled"){_gaq.push(["_trackEvent","Downloads",i.toUpperCase(),t])}else _gaq.push(["_trackPageview",analyticsDownloadsPrefix+n])})}}if(t.match(/^http/)&&!t.match(document.domain)&&o==false){e.click(function(){if(analyticsEventTracking=="enabled"){_gaq.push(["_trackEvent","Outbound Traffic",t.match(/:\/\/(.[^/]+)/)[1],t])}else _gaq.push(["_trackPageview",analyticsOutboundPrefix+n])})}})})
ga-md-ad-532.png ADDED
Binary file
ga-plugin-advert.jpg ADDED
Binary file
google-analyticator.php CHANGED
@@ -1,1052 +1,1045 @@
1
- <?php
2
- /*
3
- * Plugin Name: Google Analyticator
4
- * Version: 6.4.3
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.4.3');
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_annon", "ga_annon", 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
-
56
- // Create the default key and status
57
- add_option( 'ga_version', GOOGLE_ANALYTICATOR_VERSION );
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_widgets, ga_widgets_default, '');
73
- add_option(key_ga_annon, false );
74
- add_option('ga_defaults', 'yes' );
75
- add_option('ga_google_token', '', '');
76
-
77
- $useAuth = ( get_option( 'ga_google_token' ) == '' ? false : true );
78
-
79
-
80
- # Check if we have a version of WordPress greater than 2.8
81
- if ( function_exists('register_widget') ) {
82
-
83
- # Check if widgets are enabled and the auth has been set!
84
- if ( get_option(key_ga_widgets) == 'enabled' && $useAuth ) {
85
-
86
- # Include Google Analytics Stats widget
87
- require_once('google-analytics-stats-widget.php');
88
-
89
- # Include the Google Analytics Summary widget
90
- require_once('google-analytics-summary-widget.php');
91
- $google_analytics_summary = new GoogleAnalyticsSummary();
92
-
93
- }
94
-
95
- }
96
-
97
- // Create a option page for settings
98
- add_action('admin_init', 'ga_admin_init');
99
- add_action('admin_menu', 'add_ga_option_page');
100
-
101
- // Initialize the options
102
- function ga_admin_init() {
103
- # Load the localization information
104
- $plugin_dir = basename(dirname(__FILE__));
105
- load_plugin_textdomain('google-analyticator', 'wp-content/plugins/' . $plugin_dir . '/localizations', $plugin_dir . '/localizations');
106
- }
107
-
108
- # Add the core Google Analytics script, with a high priority to ensure last script for async tracking
109
- add_action('wp_head', 'add_google_analytics', 999999);
110
- add_action('login_head', 'add_google_analytics', 999999);
111
-
112
- # Initialize outbound link tracking
113
- add_action('init', 'ga_outgoing_links');
114
-
115
- // Hook in the options page function
116
- function add_ga_option_page() {
117
-
118
- $plugin_page = add_options_page(__('Google Analyticator Settings', 'google-analyticator'), 'Google Analytics', 'manage_options', basename(__FILE__), 'ga_options_page');
119
- add_action('load-'.$plugin_page, 'ga_pre_load' );
120
-
121
- $activate_page = add_submenu_page( null, 'Activation', 'Google Analytics', 'manage_options', 'ga_activate' , 'ga_activate');
122
-
123
-
124
- $reset_page = add_submenu_page(null, 'Reset', 'Reset', 'activate_plugins', 'ga_reset', 'ga_reset' );
125
- add_action('load-'.$reset_page, 'ga_do_reset' );
126
-
127
- }
128
-
129
- add_action('plugin_action_links_' . plugin_basename(__FILE__), 'ga_filter_plugin_actions');
130
-
131
- function ga_pre_load()
132
- {
133
-
134
- if( isset( $_POST['key_ga_google_token'] ) ):
135
-
136
- check_admin_referer('google-analyticator-update_settings');
137
-
138
- // Nolonger defaults
139
- update_option('ga_defaults', 'no');
140
-
141
- // Update GA Token
142
- update_option('ga_google_token', $_POST['key_ga_google_token']);
143
-
144
-
145
- endif;
146
-
147
- if( get_option('ga_defaults') == 'yes' ):
148
-
149
- wp_redirect( admin_url('options-general.php?page=ga_activate') );
150
- exit;
151
-
152
- endif;
153
- }
154
-
155
- function ga_activate()
156
- {
157
-
158
- if (! function_exists('curl_init')) {
159
- print('Google PHP API Client requires the CURL PHP extension');
160
- return;
161
- }
162
-
163
- if (! function_exists('json_decode')) {
164
- print('Google PHP API Client requires the JSON PHP extension');
165
- return;
166
- }
167
-
168
- if (! function_exists('http_build_query')) {
169
- print('Google PHP API Client requires http_build_query()');
170
- return;
171
- }
172
-
173
- $url = http_build_query( array(
174
- 'next' => admin_url('/options-general.php?page=google-analyticator.php'),
175
- 'scope' => GOOGLE_ANALYTICATOR_SCOPE,
176
- 'response_type'=>'code',
177
- 'redirect_uri'=>GOOGLE_ANALYTICATOR_REDIRECT,
178
- 'client_id'=>GOOGLE_ANALYTICATOR_CLIENTID
179
- )
180
- );
181
-
182
- ?>
183
- <div class="wrap">
184
-
185
- <h2>Activate Google Analyticator</h2>
186
-
187
- <p><strong>Google Authentication Code </strong> </p>
188
-
189
- <p>You need to sign in to Google and grant this plugin access to your Google Analytics account</p>
190
-
191
- <p>
192
- <a
193
- 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')"
194
- target="_blank"
195
- 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>
196
- </p>
197
-
198
- <div id="key">
199
-
200
- <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>
201
- <form method="post" action="<?php echo admin_url('options-general.php?page=google-analyticator.php');?>">
202
- <?php wp_nonce_field('google-analyticator-update_settings'); ?>
203
- <input type="text" name="key_ga_google_token" value="" style="width:450px;"/>
204
- <input type="submit" value="Save &amp; Continue" />
205
- </form>
206
- </div>
207
-
208
- <br /><br /><br />
209
- <hr />
210
- <br />
211
-
212
- <p><strong>I Don't Want To Authenticate Through Google </strong> </p>
213
-
214
- <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>
215
- <p>You will be asked on the next page to manually enter your Google Analytics UID.</p>
216
- <form method="post" action="<?php echo admin_url('options-general.php?page=google-analyticator.php');?>">
217
- <input type="hidden" name="key_ga_google_token" value="" />
218
- <?php wp_nonce_field('google-analyticator-update_settings'); ?>
219
- <input type="submit" value="Continue Without Authentication" />
220
- </form>
221
-
222
-
223
- </div>
224
-
225
- <?php
226
- }
227
-
228
- // Add settings option
229
- function ga_filter_plugin_actions($links) {
230
- $new_links = array();
231
-
232
- $new_links[] = '<a href="' . admin_url('options-general.php?page=google-analyticator.php').'">' . __('Settings', 'google-analyticator') . '</a>';
233
- $new_links[] = '<a href="' . admin_url('options-general.php?page=ga_reset">') . __('Reset', 'google-analyticator') . '</a>';
234
-
235
- return array_merge($new_links, $links);
236
- }
237
-
238
- function ga_do_reset()
239
- {
240
- global $wpdb;
241
-
242
- // Delete all GA options.
243
- delete_option(key_ga_status);
244
- delete_option(key_ga_uid);
245
- delete_option(key_ga_admin);
246
- delete_option(key_ga_admin_disable);
247
- delete_option(key_ga_admin_role);
248
- delete_option(key_ga_dashboard_role);
249
- delete_option(key_ga_adsense);
250
- delete_option(key_ga_extra);
251
- delete_option(key_ga_extra_after);
252
- delete_option(key_ga_event);
253
- delete_option(key_ga_outbound);
254
- delete_option(key_ga_outbound_prefix);
255
- delete_option(key_ga_downloads);
256
- delete_option(key_ga_downloads_prefix);
257
- delete_option(key_ga_widgets);
258
- delete_option(key_ga_annon);
259
- delete_option('ga_defaults');
260
- delete_option('ga_google_token');
261
- delete_option('ga_google_authtoken');
262
- delete_option('ga_profileid');
263
- delete_transient('ga_admin_stats_widget');
264
-
265
- // Need to remove cached items from GA widgets
266
- $wpdb->query( "delete from $wpdb->options where `option_name` like 'google_stats_visitsGraph_%'");
267
-
268
- wp_redirect( admin_url( 'options-general.php?page=ga_activate' ) );
269
- exit;
270
- }
271
-
272
- function ga_reset(){ /* Wont ever run. */ }
273
-
274
-
275
- function ga_options_page() {
276
-
277
- // If we are a postback, store the options
278
- if (isset($_POST['info_update'])) {
279
- # Verify nonce
280
- check_admin_referer('google-analyticator-update_settings');
281
-
282
- update_option('ga_defaults', 'no');
283
-
284
-
285
- // Update the status
286
- $ga_status = wp_filter_kses( $_POST[key_ga_status] );
287
- if (($ga_status != ga_enabled) && ($ga_status != ga_disabled))
288
- $ga_status = ga_status_default;
289
- update_option(key_ga_status, $ga_status);
290
-
291
- // Update the UID
292
- $ga_uid = wp_filter_kses( $_POST[key_ga_uid] );
293
- if ($ga_uid == '')
294
- $ga_uid = ga_uid_default;
295
- update_option(key_ga_uid, $ga_uid);
296
-
297
- // Update the admin logging
298
- $ga_admin = wp_filter_kses( $_POST[key_ga_admin] );
299
- if (($ga_admin != ga_enabled) && ($ga_admin != ga_disabled))
300
- $ga_admin = ga_admin_default;
301
- update_option(key_ga_admin, wp_filter_kses( $ga_admin ) );
302
-
303
- // Update the admin disable setting
304
- $ga_admin_disable = wp_filter_kses( $_POST[key_ga_admin_disable] );
305
- if ( $ga_admin_disable == '' )
306
- $ga_admin_disable = ga_admin_disable_default;
307
- update_option(key_ga_admin_disable, wp_filter_kses( $ga_admin_disable) );
308
-
309
- // Update the admin level
310
- if ( array_key_exists(key_ga_admin_role, $_POST) ) {
311
- $ga_admin_role = $_POST[key_ga_admin_role];
312
- } else {
313
- $ga_admin_role = "";
314
- }
315
- update_option(key_ga_admin_role, $ga_admin_role);
316
-
317
- // Update the dashboard level
318
- if ( array_key_exists(key_ga_dashboard_role, $_POST) ) {
319
- $ga_dashboard_role = $_POST[key_ga_dashboard_role];
320
- } else {
321
- $ga_dashboard_role = "";
322
- }
323
- update_option(key_ga_dashboard_role, $ga_dashboard_role );
324
-
325
- // Update the extra tracking code
326
- $ga_extra = $_POST[key_ga_extra];
327
- update_option(key_ga_extra, wp_filter_kses( $ga_extra ) );
328
-
329
- // Update the extra after tracking code
330
- $ga_extra_after = $_POST[key_ga_extra_after];
331
- update_option(key_ga_extra_after, wp_filter_kses( $ga_extra_after ));
332
-
333
- // Update the adsense key
334
- $ga_adsense = $_POST[key_ga_adsense];
335
- update_option(key_ga_adsense, wp_filter_kses( $ga_adsense ) );
336
-
337
- // Update the event tracking
338
- $ga_event = $_POST[key_ga_event];
339
- if (($ga_event != ga_enabled) && ($ga_event != ga_disabled))
340
- $ga_event = ga_event_default;
341
- update_option(key_ga_event, wp_filter_kses ( $ga_event ) );
342
-
343
- // Update the outbound tracking
344
- $ga_outbound = $_POST[key_ga_outbound];
345
- if (($ga_outbound != ga_enabled) && ($ga_outbound != ga_disabled))
346
- $ga_outbound = ga_outbound_default;
347
- update_option(key_ga_outbound, wp_filter_kses( $ga_outbound ) );
348
-
349
- // Update the outbound prefix
350
- $ga_outbound_prefix = $_POST[key_ga_outbound_prefix];
351
- if ($ga_outbound_prefix == '')
352
- $ga_outbound_prefix = ga_outbound_prefix_default;
353
- update_option(key_ga_outbound_prefix, wp_filter_kses( $ga_outbound_prefix) );
354
-
355
- // Update the download tracking code
356
- $ga_downloads = $_POST[key_ga_downloads];
357
- update_option(key_ga_downloads, wp_filter_kses( $ga_downloads ) );
358
-
359
- // Update the download prefix
360
- $ga_downloads_prefix = $_POST[key_ga_downloads_prefix];
361
- if ($ga_downloads_prefix == '')
362
- $ga_downloads_prefix = ga_downloads_prefix_default;
363
- update_option(key_ga_downloads_prefix, wp_filter_kses( $ga_downloads_prefix) );
364
-
365
- // Update the widgets option
366
- $ga_widgets = $_POST[key_ga_widgets];
367
- if (($ga_widgets != ga_enabled) && ($ga_widgets != ga_disabled))
368
- $ga_widgets = ga_widgets_default;
369
- update_option(key_ga_widgets, wp_filter_kses( $ga_widgets ) );
370
-
371
- // Update the widgets option
372
- update_option(key_ga_annon, wp_filter_kses( $_POST[key_ga_annon] ) );
373
-
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
- <form method="post" action="<?php echo admin_url('options-general.php?page=google-analyticator.php');?>">
391
- <?php
392
- # Add a nonce
393
- wp_nonce_field('google-analyticator-update_settings');
394
- ?>
395
-
396
- <?php if (get_option(key_ga_status) == ga_disabled) { ?>
397
- <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
398
- <?php _e('Google Analytics integration is currently <strong>DISABLED</strong>.', 'google-analyticator'); ?>
399
- </div>
400
- <?php } ?>
401
- <?php if ((get_option(key_ga_uid) == "XX-XXXXX-X") && (get_option(key_ga_status) != ga_disabled)) { ?>
402
- <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
403
- <?php _e('Google Analytics integration is currently enabled, but you did not enter a UID. Tracking will not occur.', 'google-analyticator'); ?>
404
- </div>
405
- <?php } ?>
406
- <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
407
-
408
- <tr>
409
- <td colspan="2">
410
- <h3><?php _e('Basic Settings', 'google-analyticator'); ?></h3>
411
- </td>
412
- </tr>
413
-
414
- <tr>
415
- <th width="30%" valign="top" style="padding-top: 10px;">
416
- <label for="<?php echo key_ga_status ?>"><?php _e('Google Analytics logging is', 'google-analyticator'); ?>:</label>
417
- </th>
418
- <td>
419
- <?php
420
- echo "<select name='".key_ga_status."' id='".key_ga_status."'>\n";
421
-
422
- echo "<option value='".ga_enabled."'";
423
- if(get_option(key_ga_status) == ga_enabled)
424
- echo " selected='selected'";
425
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
426
-
427
- echo "<option value='".ga_disabled."'";
428
- if(get_option(key_ga_status) == ga_disabled)
429
- echo" selected='selected'";
430
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
431
-
432
- echo "</select>\n";
433
- ?>
434
- </td>
435
- </tr>
436
- <tr id="ga_ajax_accounts">
437
- <th valign="top" style="padding-top: 10px;">
438
- <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics UID', 'google-analyticator'); ?>:</label>
439
- </th>
440
- <td>
441
- <?php
442
-
443
- if( $useAuth ):
444
-
445
- $uids = ga_get_analytics_accounts();
446
-
447
- echo "<select name='".key_ga_uid."'> ";
448
-
449
- $hasSelected = false; // Will be set to true once a match is found. Cant echo selected twice.
450
-
451
- foreach($uids as $id=>$domain):
452
-
453
- echo '<option value="'.$id.'"';
454
- // If set in DB.
455
- if( get_option(key_ga_uid) == $id ) { $hasSelected=true; echo ' selected="selected"'; }
456
- // Else if the domain matches the current domain & nothing set in DB.
457
- elseif( ( $_SERVER['HTTP_HOST'] == $domain ) && ( ! $hasSelected ) ) { $hasSelected=true; echo ' selected="selected"'; }
458
- echo '>'.$domain.'</option>';
459
-
460
- endforeach;
461
-
462
- echo '</select>';
463
-
464
- else:
465
-
466
- echo '<input type="text" name="'.key_ga_uid.'" value="'. get_option( key_ga_uid ) .'" />';
467
-
468
- endif;
469
- ?>
470
- </td>
471
- </tr>
472
- <tr>
473
- <td colspan="2">
474
- <h3><?php _e('Tracking Settings', 'google-analyticator'); ?></h3>
475
- </td>
476
- </tr>
477
- <tr>
478
- <th width="30%" valign="top" style="padding-top: 10px;">
479
- <label for="<?php echo key_ga_admin ?>"><?php _e('Track all logged in WordPress users', 'google-analyticator'); ?>:</label>
480
- </th>
481
- <td>
482
- <?php
483
- echo "<select name='".key_ga_admin."' id='".key_ga_admin."'>\n";
484
-
485
- echo "<option value='".ga_enabled."'";
486
- if(get_option(key_ga_admin) == ga_enabled)
487
- echo " selected='selected'";
488
- echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
489
-
490
- echo "<option value='".ga_disabled."'";
491
- if(get_option(key_ga_admin) == ga_disabled)
492
- echo" selected='selected'";
493
- echo ">" . __('No', 'google-analyticator') . "</option>\n";
494
-
495
- echo "</select>\n";
496
-
497
- ?>
498
- <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>
499
- </td>
500
- </tr>
501
- <tr>
502
- <th width="30%" valign="top" style="padding-top: 10px;">
503
- <label><?php _e('Anonymize IP Addresses', 'google-analyticator'); ?>:</label>
504
- </th>
505
- <td>
506
- <?php
507
- echo "<select name='".key_ga_annon."' id='".key_ga_annon."'>\n";
508
-
509
- echo "<option value='0'";
510
- if(get_option(key_ga_annon) == false )
511
- echo " selected='selected'";
512
- echo ">" . __('No', 'google-analyticator') . "</option>\n";
513
-
514
- echo "<option value='1'";
515
- if(get_option(key_ga_annon) == true)
516
- echo" selected='selected'";
517
- echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
518
-
519
- echo "</select>\n";
520
-
521
- ?>
522
- <p class="setting-description"><?php _e('By selecting "Yes", This tells Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage. Note that this will slightly reduce the accuracy of geographic reporting.', 'google-analyticator'); ?></p>
523
- </td>
524
- </tr>
525
- <tr>
526
- <th width="30%" valign="top" style="padding-top: 10px;">
527
- <label for="<?php echo key_ga_admin_role ?>"><?php _e('User roles to not track', 'google-analyticator'); ?>:</label>
528
- </th>
529
- <td>
530
- <?php
531
- global $wp_roles;
532
- $roles = $wp_roles->get_names();
533
- $selected_roles = get_option(key_ga_admin_role);
534
- if ( !is_array($selected_roles) ) $selected_roles = array();
535
-
536
- # Loop through the roles
537
- foreach ( $roles AS $role => $name ) {
538
- echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_admin_role . '[]"';
539
- if ( in_array($role, $selected_roles) )
540
- echo " checked='checked'";
541
- $name_pos = strpos($name, '|');
542
- $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
543
- echo ' /> ' . _x($name, 'User role') . '<br />';
544
- }
545
- ?>
546
- <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>
547
- </td>
548
- </tr>
549
- <tr>
550
- <th width="30%" valign="top" style="padding-top: 10px;">
551
- <label for="<?php echo key_ga_admin_disable ?>"><?php _e('Method to prevent tracking', 'google-analyticator'); ?>:</label>
552
- </th>
553
- <td>
554
- <?php
555
- echo "<select name='".key_ga_admin_disable."' id='".key_ga_admin_disable."'>\n";
556
-
557
- echo "<option value='remove'";
558
- if(get_option(key_ga_admin_disable) == 'remove')
559
- echo " selected='selected'";
560
- echo ">" . __('Remove', 'google-analyticator') . "</option>\n";
561
-
562
- echo "<option value='admin'";
563
- if(get_option(key_ga_admin_disable) == 'admin')
564
- echo" selected='selected'";
565
- echo ">" . __('Use \'admin\' variable', 'google-analyticator') . "</option>\n";
566
-
567
- echo "</select>\n";
568
- ?>
569
- <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>
570
- </td>
571
- </tr>
572
- <tr>
573
- <td colspan="2">
574
- <h3>Link Tracking Settings</h3>
575
- </td>
576
- </tr>
577
- <tr>
578
- <th width="30%" valign="top" style="padding-top: 10px;">
579
- <label for="<?php echo key_ga_outbound ?>"><?php _e('Outbound link tracking', 'google-analyticator'); ?>:</label>
580
- </th>
581
- <td>
582
- <?php
583
- echo "<select name='".key_ga_outbound."' id='".key_ga_outbound."'>\n";
584
-
585
- echo "<option value='".ga_enabled."'";
586
- if(get_option(key_ga_outbound) == ga_enabled)
587
- echo " selected='selected'";
588
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
589
-
590
- echo "<option value='".ga_disabled."'";
591
- if(get_option(key_ga_outbound) == ga_disabled)
592
- echo" selected='selected'";
593
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
594
-
595
- echo "</select>\n";
596
- ?>
597
- <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>
598
- </td>
599
- </tr>
600
- <tr>
601
- <th width="30%" valign="top" style="padding-top: 10px;">
602
- <label for="<?php echo key_ga_event ?>"><?php _e('Event tracking', 'google-analyticator'); ?>:</label>
603
- </th>
604
- <td>
605
- <?php
606
- echo "<select name='".key_ga_event."' id='".key_ga_event."'>\n";
607
-
608
- echo "<option value='".ga_enabled."'";
609
- if(get_option(key_ga_event) == ga_enabled)
610
- echo " selected='selected'";
611
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
612
-
613
- echo "<option value='".ga_disabled."'";
614
- if(get_option(key_ga_event) == ga_disabled)
615
- echo" selected='selected'";
616
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
617
-
618
- echo "</select>\n";
619
- ?>
620
- <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>
621
- </td>
622
- </tr>
623
- <tr>
624
- <th valign="top" style="padding-top: 10px;">
625
- <label for="<?php echo key_ga_downloads; ?>"><?php _e('Download extensions to track', 'google-analyticator'); ?>:</label>
626
- </th>
627
- <td>
628
- <?php
629
- echo "<input type='text' size='50' ";
630
- echo "name='".key_ga_downloads."' ";
631
- echo "id='".key_ga_downloads."' ";
632
- echo "value='".wp_filter_kses(get_option(key_ga_downloads))."' />\n";
633
- ?>
634
- <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>
635
- </td>
636
- </tr>
637
- <tr>
638
- <th valign="top" style="padding-top: 10px;">
639
- <label for="<?php echo key_ga_outbound_prefix; ?>"><?php _e('Prefix external links with', 'google-analyticator'); ?>:</label>
640
- </th>
641
- <td>
642
- <?php
643
- echo "<input type='text' size='50' ";
644
- echo "name='".key_ga_outbound_prefix."' ";
645
- echo "id='".key_ga_outbound_prefix."' ";
646
- echo "value='". stripslashes( wp_filter_kses(get_option(key_ga_outbound_prefix)))."' />\n";
647
- ?>
648
- <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>
649
- </td>
650
- </tr>
651
- <tr>
652
- <th valign="top" style="padding-top: 10px;">
653
- <label for="<?php echo key_ga_downloads_prefix; ?>"><?php _e('Prefix download links with', 'google-analyticator'); ?>:</label>
654
- </th>
655
- <td>
656
- <?php
657
- echo "<input type='text' size='50' ";
658
- echo "name='".key_ga_downloads_prefix."' ";
659
- echo "id='".key_ga_downloads_prefix."' ";
660
- echo "value='".stripslashes(wp_filter_kses ( get_option(key_ga_downloads_prefix) ))."' />\n";
661
- ?>
662
- <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>
663
- </td>
664
- </tr>
665
- <tr>
666
- <th valign="top" style="padding-top: 10px;">
667
- <label for="<?php echo key_ga_adsense; ?>"><?php _e('Google Adsense ID', 'google-analyticator'); ?>:</label>
668
- </th>
669
- <td>
670
- <?php
671
- echo "<input type='text' size='50' ";
672
- echo "name='".key_ga_adsense."' ";
673
- echo "id='".key_ga_adsense."' ";
674
- echo "value='".get_option(key_ga_adsense)."' />\n";
675
- ?>
676
- <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>
677
- </td>
678
- </tr>
679
- <tr>
680
- <td colspan="2">
681
- <h3>Additional Tracking Code </h3>
682
- </td>
683
- </tr>
684
- <tr>
685
- <th valign="top" style="padding-top: 10px;">
686
- <label for="<?php echo key_ga_extra; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('before tracker initialization', 'google-analyticator'); ?>):</label>
687
- </th>
688
- <td>
689
- <?php
690
- echo "<textarea cols='50' rows='8' ";
691
- echo "name='".key_ga_extra."' ";
692
- echo "id='".key_ga_extra."'>";
693
- echo stripslashes(get_option(key_ga_extra))."</textarea>\n";
694
- ?>
695
- <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>
696
- </td>
697
- </tr>
698
- <tr>
699
- <th valign="top" style="padding-top: 10px;">
700
- <label for="<?php echo key_ga_extra_after; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('after tracker initialization', 'google-analyticator'); ?>):</label>
701
- </th>
702
- <td>
703
- <?php
704
- echo "<textarea cols='50' rows='8' ";
705
- echo "name='".key_ga_extra_after."' ";
706
- echo "id='".key_ga_extra_after."'>";
707
- echo stripslashes(get_option(key_ga_extra_after))."</textarea>\n";
708
- ?>
709
- <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>
710
- </td>
711
- </tr>
712
- <tr>
713
- <td colspan="2">
714
- <h3>Admin Dashboard Widgets</h3>
715
- <?php if(!$useAuth): ?>
716
- <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
717
- <?php _e('You have not authenticated with Google - you cannot use dashboard widgets! Reset the plugin to authenticate..', 'google-analyticator'); ?>
718
- </div>
719
- <?php endif;?>
720
- </td>
721
- </tr>
722
- <tr<?php if(!$useAuth){echo ' style="display:none"';}?>>
723
- <th width="30%" valign="top" style="padding-top: 10px;">
724
- <label for="<?php echo key_ga_widgets; ?>"><?php _e('Include widgets', 'google-analyticator'); ?>:</label>
725
- </th>
726
- <td>
727
- <?php
728
- echo "<select name='".key_ga_widgets."' id='".key_ga_widgets."'>\n";
729
-
730
- echo "<option value='".ga_enabled."'";
731
- if(get_option(key_ga_widgets) == ga_enabled)
732
- echo " selected='selected'";
733
- echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
734
-
735
- echo "<option value='".ga_disabled."'";
736
- if(get_option(key_ga_widgets) == ga_disabled)
737
- echo" selected='selected'";
738
- echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
739
-
740
- echo "</select>\n";
741
- ?>
742
- <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>
743
- </td>
744
- </tr>
745
- <tr<?php if(!$useAuth){echo ' style="display:none"';}?>>
746
- <th width="30%" valign="top" style="padding-top: 10px;">
747
- <label for="<?php echo key_ga_dashboard_role ?>"><?php _e('User roles that can see the dashboard widget', 'google-analyticator'); ?>:</label>
748
- </th>
749
- <td>
750
- <?php
751
- global $wp_roles;
752
- $roles = $wp_roles->get_names();
753
- $selected_roles = get_option(key_ga_dashboard_role);
754
- if ( !is_array($selected_roles) ) $selected_roles = array();
755
-
756
- # Loop through the roles
757
- foreach ( $roles AS $role => $name ) {
758
- echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_dashboard_role . '[]"';
759
- if ( in_array($role, $selected_roles) )
760
- echo " checked='checked'";
761
- $name_pos = strpos($name, '|');
762
- $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
763
- echo ' /> ' . _x($name, 'User role') . '<br />';
764
- }
765
- ?>
766
- <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>
767
- </td>
768
- </tr>
769
-
770
- </table>
771
- <p class="submit">
772
- <input type="submit" class="button button-primary" name="info_update" value="<?php _e('Save Changes', 'google-analyticator'); ?>" />
773
- </p>
774
-
775
- <a href="<?php echo admin_url('/options-general.php?page=ga_reset'); ?>"><?php _e('Deauthorize &amp; Reset Google Analyticator.', 'google-analyticator'); ?></a>
776
-
777
- </form>
778
-
779
-
780
- <?php if (!get_option('wpm_o_user_id')): ?>
781
- <img src="<?php echo plugins_url('wlcms-plugin-advert.png', __FILE__ ); ?>" alt="Learn how to make WordPress better" />
782
- <form method="post" onsubmit="return quickValidate()" action="http://www.aweber.com/scripts/addlead.pl" target="_blank" >
783
- <div style="display: none;">
784
- <input type="hidden" name="meta_web_form_id" value="672327302" />
785
- <input type="hidden" name="meta_split_id" value="" />
786
- <input type="hidden" name="listname" value="vumpublic2" />
787
- <input type="hidden" name="redirect" value="http://www.aweber.com/thankyou-coi.htm?m=video" id="redirect_9567c93ed4b6fb0c7cd9247553c362eb" />
788
- <input type="hidden" name="meta_adtracking" value="ga-plugin" />
789
- <input type="hidden" name="meta_message" value="1" />
790
- <input type="hidden" name="meta_required" value="name,email" />
791
- <input type="hidden" name="meta_tooltip" value="" />
792
- </div>
793
- <table style="text-align:center;margin-left: 20px;">
794
- <tr>
795
- <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>
796
- <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>
797
- <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>
798
- </tr>
799
- <tr>
800
- <td colspan="3" style="padding-top: 20px;">
801
- <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>
802
- </td>
803
- </tr>
804
- </table>
805
- </form>
806
- <?php endif;?>
807
-
808
- <script type="text/javascript">
809
- function quickValidate()
810
- {
811
- if (! jQuery('#sub_name').val() )
812
- {
813
- alert('Your Name is required');
814
- return false;
815
- }
816
- if(! jQuery('#sub_email').val() )
817
- {
818
- alert('Your Email is required');
819
- return false;
820
- }
821
-
822
- return true;
823
-
824
- }
825
- </script>
826
-
827
- </div>
828
- </form>
829
-
830
- <?php
831
- }
832
-
833
- function ga_sort_account_list($a, $b) {
834
- return strcmp($a['title'],$b['title']);
835
- }
836
-
837
- /**
838
- * Checks if the WordPress API is a valid method for selecting an account
839
- *
840
- * @return a list of accounts if available, false if none available
841
- **/
842
- function ga_get_analytics_accounts()
843
- {
844
- $accounts = array();
845
-
846
- # Get the class for interacting with the Google Analytics
847
- require_once('class.analytics.stats.php');
848
-
849
- # Create a new Gdata call
850
- if ( isset($_POST['token']) && $_POST['token'] != '' )
851
- $stats = new GoogleAnalyticsStats($_POST['token']);
852
- elseif ( trim(get_option('ga_google_token')) != '' )
853
- $stats = new GoogleAnalyticsStats();
854
- else
855
- return false;
856
-
857
- # Check if Google sucessfully logged in
858
- if ( ! $stats->checkLogin() )
859
- return false;
860
-
861
- # Get a list of accounts
862
- $accounts = $stats->getAllProfiles();
863
-
864
- natcasesort ($accounts);
865
-
866
- # Return the account array if there are accounts
867
- if ( count($accounts) > 0 )
868
- return $accounts;
869
- else
870
- return false;
871
- }
872
-
873
- /**
874
- * Add http_build_query if it doesn't exist already
875
- **/
876
- if ( !function_exists('http_build_query') ) {
877
- function http_build_query($params, $key = null)
878
- {
879
- $ret = array();
880
-
881
- foreach( (array) $params as $name => $val ) {
882
- $name = urlencode($name);
883
-
884
- if ( $key !== null )
885
- $name = $key . "[" . $name . "]";
886
-
887
- if ( is_array($val) || is_object($val) )
888
- $ret[] = http_build_query($val, $name);
889
- elseif ($val !== null)
890
- $ret[] = $name . "=" . urlencode($val);
891
- }
892
-
893
- return implode("&", $ret);
894
- }
895
- }
896
-
897
- /**
898
- * Echos out the core Analytics tracking code
899
- **/
900
- function add_google_analytics()
901
- {
902
- # Fetch variables used in the tracking code
903
- $uid = stripslashes(get_option(key_ga_uid));
904
- $extra = stripslashes(get_option(key_ga_extra));
905
- $extra_after = stripslashes(get_option(key_ga_extra_after));
906
- $extensions = str_replace (",", "|", get_option(key_ga_downloads));
907
-
908
- # Determine if the GA is enabled and contains a valid UID
909
- if ( ( get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
910
- {
911
- # Determine if the user is an admin, and should see the tracking code
912
- 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' )
913
- {
914
- # Disable the tracking code on the post preview page
915
- if ( !function_exists("is_preview") || ( function_exists("is_preview") && !is_preview() ) )
916
- {
917
- # Add the notice that Google Analyticator tracking is enabled
918
- echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://www.videousermanuals.com/google-analyticator/ -->\n";
919
-
920
- # Add the Adsense data if specified
921
- if ( get_option(key_ga_adsense) != '' )
922
- echo '<script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n";
923
-
924
- # Include the file types to track
925
- $extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
926
- $ext = "";
927
- foreach ( $extensions AS $extension )
928
- $ext .= "'$extension',";
929
- $ext = substr($ext, 0, -1);
930
-
931
- # Include the link tracking prefixes
932
- $outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
933
- $downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
934
- $event_tracking = get_option(key_ga_event);
935
-
936
-
937
- $need_to_annon = get_option(key_ga_annon);
938
-
939
-
940
- ?>
941
- <script type="text/javascript">
942
- var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
943
- <?php if ( $event_tracking != 'enabled' ) { ?>
944
- var analyticsOutboundPrefix = '/<?php echo $outbound_prefix; ?>/';
945
- var analyticsDownloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
946
- <?php } ?>
947
- var analyticsEventTracking = '<?php echo $event_tracking; ?>';
948
- </script>
949
- <?php
950
- # Add the first part of the core tracking code
951
- ?>
952
- <script type="text/javascript">
953
- var _gaq = _gaq || [];
954
- _gaq.push(['_setAccount', '<?php echo $uid; ?>']);
955
- _gaq.push(['_addDevId', 'i9k95']); // Google Analyticator App ID with Google
956
- <?php if ($need_to_annon == '1' ): ?>
957
- _gaq.push(['_gat._anonymizeIp']);
958
- <?php endif; ?>
959
- <?php
960
-
961
- # Add any tracking code before the trackPageview
962
- do_action('google_analyticator_extra_js_before');
963
- if ( '' != $extra )
964
- echo " $extra\n";
965
-
966
- # Add the track pageview function
967
- echo " _gaq.push(['_trackPageview']);\n";
968
-
969
- # Disable page tracking if admin is logged in
970
- if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(key_ga_admin_role)) ) )
971
- echo " _gaq.push(['_setCustomVar', 'admin']);\n";
972
-
973
- # Add any tracking code after the trackPageview
974
- do_action('google_analyticator_extra_js_after');
975
- if ( '' != $extra_after )
976
- echo " $extra_after\n";
977
-
978
- # Add the final section of the tracking code
979
- ?>
980
-
981
- (function() {
982
- var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
983
- ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
984
- var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
985
- })();
986
- </script>
987
- <?php
988
- }
989
- } else {
990
- # Add the notice that Google Analyticator tracking is enabled
991
- echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
992
- echo " <!-- " . __('Tracking code is hidden, since the settings specify not to track admins. Tracking is occurring for non-admins.', 'google-analyticator') . " -->\n";
993
- }
994
- }
995
- }
996
-
997
- /**
998
- * Adds outbound link tracking to Google Analyticator
999
- **/
1000
- function ga_outgoing_links()
1001
- {
1002
- # Fetch the UID
1003
- $uid = stripslashes(get_option(key_ga_uid));
1004
-
1005
- # If GA is enabled and has a valid key
1006
- if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
1007
- {
1008
- # If outbound tracking is enabled
1009
- if ( get_option(key_ga_outbound) == ga_enabled )
1010
- {
1011
- # If this is not an admin page
1012
- if ( !is_admin() )
1013
- {
1014
- # Display page tracking if user is not an admin
1015
- 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' )
1016
- {
1017
- add_action('wp_print_scripts', 'ga_external_tracking_js');
1018
- }
1019
- }
1020
- }
1021
- }
1022
- }
1023
-
1024
- /**
1025
- * Adds the scripts required for outbound link tracking
1026
- **/
1027
- function ga_external_tracking_js()
1028
- {
1029
- wp_enqueue_script('ga-external-tracking', plugins_url('/google-analyticator/external-tracking.min.js'), array('jquery'), GOOGLE_ANALYTICATOR_VERSION);
1030
- }
1031
-
1032
- /**
1033
- * Determines if a specific user fits a role
1034
- **/
1035
- function ga_current_user_is($roles)
1036
- {
1037
- if ( !$roles ) return false;
1038
-
1039
- global $current_user;
1040
- get_currentuserinfo();
1041
- $user_id = intval( $current_user->ID );
1042
-
1043
- if ( !$user_id ) {
1044
- return false;
1045
- }
1046
- $user = new WP_User($user_id); // $user->roles
1047
-
1048
- foreach ( $roles as $role )
1049
- if ( in_array($role, $user->roles) ) return true;
1050
-
1051
- return false;
1052
- }
1
+ <?php
2
+ /*
3
+ * Plugin Name: Google Analyticator
4
+ * Version: 6.4.4.3
5
+ * Plugin URI: http://www.videousermanuals.com/google-analyticator/?utm_campaign=analyticator&utm_medium=plugin&utm_source=readme-txt
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 Pty Ltd
8
+ * Author URI: http://www.videousermanuals.com/?utm_campaign=analyticator&utm_medium=plugin&utm_source=readme-txt
9
+ * Text Domain: google-analyticator
10
+ */
11
+
12
+ define('GOOGLE_ANALYTICATOR_VERSION', '6.4.4.3');
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_annon", "ga_annon", 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
+
56
+ // Create the default key and status
57
+ add_option( 'ga_version', GOOGLE_ANALYTICATOR_VERSION );
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_widgets, ga_widgets_default, '');
73
+ add_option(key_ga_annon, false );
74
+ add_option('ga_defaults', 'yes' );
75
+ add_option('ga_google_token', '', '');
76
+
77
+ $useAuth = ( get_option( 'ga_google_token' ) == '' ? false : true );
78
+
79
+
80
+ # Check if we have a version of WordPress greater than 2.8
81
+ if ( function_exists('register_widget') ) {
82
+
83
+ # Check if widgets are enabled and the auth has been set!
84
+ if ( get_option(key_ga_widgets) == 'enabled' && $useAuth ) {
85
+
86
+ # Include Google Analytics Stats widget
87
+ require_once('google-analytics-stats-widget.php');
88
+
89
+ # Include the Google Analytics Summary widget
90
+ require_once('google-analytics-summary-widget.php');
91
+ $google_analytics_summary = new GoogleAnalyticsSummary();
92
+
93
+ }
94
+
95
+ }
96
+
97
+ // Create a option page for settings
98
+ add_action('admin_init', 'ga_admin_init');
99
+ add_action('admin_menu', 'add_ga_option_page');
100
+
101
+ // Initialize the options
102
+ function ga_admin_init() {
103
+ # Load the localization information
104
+ $plugin_dir = basename(dirname(__FILE__));
105
+ load_plugin_textdomain('google-analyticator', 'wp-content/plugins/' . $plugin_dir . '/localizations', $plugin_dir . '/localizations');
106
+ }
107
+
108
+ # Add the core Google Analytics script, with a high priority to ensure last script for async tracking
109
+ add_action('wp_head', 'add_google_analytics',99);
110
+ add_action('login_head', 'add_google_analytics', 999999);
111
+
112
+ # Initialize outbound link tracking
113
+ add_action('init', 'ga_outgoing_links');
114
+
115
+ // Hook in the options page function
116
+ function add_ga_option_page() {
117
+
118
+ $plugin_page = add_options_page(__('Google Analyticator Settings', 'google-analyticator'), 'Google Analytics', 'manage_options', basename(__FILE__), 'ga_options_page');
119
+ add_action('load-'.$plugin_page, 'ga_pre_load' );
120
+
121
+ $activate_page = add_submenu_page( null, 'Activation', 'Google Analytics', 'manage_options', 'ga_activate' , 'ga_activate');
122
+
123
+
124
+ $reset_page = add_submenu_page(null, 'Reset', 'Reset', 'activate_plugins', 'ga_reset', 'ga_reset' );
125
+ add_action('load-'.$reset_page, 'ga_do_reset' );
126
+
127
+ }
128
+
129
+ add_action('plugin_action_links_' . plugin_basename(__FILE__), 'ga_filter_plugin_actions');
130
+
131
+ function ga_pre_load()
132
+ {
133
+
134
+ if( isset( $_POST['key_ga_google_token'] ) ):
135
+
136
+ check_admin_referer('google-analyticator-update_settings');
137
+
138
+ // Nolonger defaults
139
+ update_option('ga_defaults', 'no');
140
+
141
+ // Update GA Token
142
+ update_option('ga_google_token', $_POST['key_ga_google_token']);
143
+
144
+
145
+ endif;
146
+
147
+ if( get_option('ga_defaults') == 'yes' ):
148
+
149
+ wp_redirect( admin_url('options-general.php?page=ga_activate') );
150
+ exit;
151
+
152
+ endif;
153
+ }
154
+
155
+ function ga_activate()
156
+ {
157
+
158
+ if (! function_exists('curl_init')) {
159
+ print('Google PHP API Client requires the CURL PHP extension');
160
+ return;
161
+ }
162
+
163
+ if (! function_exists('json_decode')) {
164
+ print('Google PHP API Client requires the JSON PHP extension');
165
+ return;
166
+ }
167
+
168
+ if (! function_exists('http_build_query')) {
169
+ print('Google PHP API Client requires http_build_query()');
170
+ return;
171
+ }
172
+
173
+ $url = http_build_query( array(
174
+ 'next' => admin_url('/options-general.php?page=google-analyticator.php'),
175
+ 'scope' => GOOGLE_ANALYTICATOR_SCOPE,
176
+ 'response_type'=>'code',
177
+ 'redirect_uri'=>GOOGLE_ANALYTICATOR_REDIRECT,
178
+ 'client_id'=>GOOGLE_ANALYTICATOR_CLIENTID
179
+ )
180
+ );
181
+
182
+ ?>
183
+ <div class="wrap">
184
+
185
+ <h2>Activate Google Analyticator</h2>
186
+
187
+ <p><strong>Google Authentication Code </strong> </p>
188
+
189
+ <p>You need to sign in to Google and grant this plugin access to your Google Analytics account</p>
190
+
191
+ <p>
192
+ <a
193
+ 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')"
194
+ target="_blank"
195
+ 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>
196
+ </p>
197
+
198
+ <div id="key">
199
+
200
+ <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>
201
+ <form method="post" action="<?php echo admin_url('options-general.php?page=google-analyticator.php');?>">
202
+ <?php wp_nonce_field('google-analyticator-update_settings'); ?>
203
+ <input type="text" name="key_ga_google_token" value="" style="width:450px;"/>
204
+ <input type="submit" value="Save &amp; Continue" />
205
+ </form>
206
+ </div>
207
+
208
+ <br /><br /><br />
209
+ <hr />
210
+ <br />
211
+
212
+ <p><strong>I Don't Want To Authenticate Through Google </strong> </p>
213
+
214
+ <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>
215
+ <p>You will be asked on the next page to manually enter your Google Analytics UID.</p>
216
+ <form method="post" action="<?php echo admin_url('options-general.php?page=google-analyticator.php');?>">
217
+ <input type="hidden" name="key_ga_google_token" value="" />
218
+ <?php wp_nonce_field('google-analyticator-update_settings'); ?>
219
+ <input type="submit" value="Continue Without Authentication" />
220
+ </form>
221
+
222
+
223
+ </div>
224
+
225
+ <?php
226
+ }
227
+
228
+ // Add settings option
229
+ function ga_filter_plugin_actions($links) {
230
+ $new_links = array();
231
+
232
+ $new_links[] = '<a href="' . admin_url('options-general.php?page=google-analyticator.php').'">' . __('Settings', 'google-analyticator') . '</a>';
233
+ $new_links[] = '<a href="' . admin_url('options-general.php?page=ga_reset">') . __('Reset', 'google-analyticator') . '</a>';
234
+
235
+ return array_merge($new_links, $links);
236
+ }
237
+
238
+ function ga_do_reset()
239
+ {
240
+ global $wpdb;
241
+
242
+ // Delete all GA options.
243
+ delete_option(key_ga_status);
244
+ delete_option(key_ga_uid);
245
+ delete_option(key_ga_admin);
246
+ delete_option(key_ga_admin_disable);
247
+ delete_option(key_ga_admin_role);
248
+ delete_option(key_ga_dashboard_role);
249
+ delete_option(key_ga_adsense);
250
+ delete_option(key_ga_extra);
251
+ delete_option(key_ga_extra_after);
252
+ delete_option(key_ga_event);
253
+ delete_option(key_ga_outbound);
254
+ delete_option(key_ga_outbound_prefix);
255
+ delete_option(key_ga_downloads);
256
+ delete_option(key_ga_downloads_prefix);
257
+ delete_option(key_ga_widgets);
258
+ delete_option(key_ga_annon);
259
+ delete_option('ga_defaults');
260
+ delete_option('ga_google_token');
261
+ delete_option('ga_google_authtoken');
262
+ delete_option('ga_profileid');
263
+ delete_transient('ga_admin_stats_widget');
264
+
265
+ // Need to remove cached items from GA widgets
266
+ $wpdb->query( "delete from $wpdb->options where `option_name` like 'google_stats_visitsGraph_%'");
267
+
268
+ wp_redirect( admin_url( 'options-general.php?page=ga_activate' ) );
269
+ exit;
270
+ }
271
+
272
+ function ga_reset(){ /* Wont ever run. */ }
273
+
274
+
275
+ function ga_options_page() {
276
+
277
+ // If we are a postback, store the options
278
+ if (isset($_POST['info_update'])) {
279
+ # Verify nonce
280
+ check_admin_referer('google-analyticator-update_settings');
281
+
282
+ update_option('ga_defaults', 'no');
283
+
284
+
285
+ // Update the status
286
+ $ga_status = wp_filter_kses( $_POST[key_ga_status] );
287
+ if (($ga_status != ga_enabled) && ($ga_status != ga_disabled))
288
+ $ga_status = ga_status_default;
289
+ update_option(key_ga_status, $ga_status);
290
+
291
+ // Update the UID
292
+ $ga_uid = wp_filter_kses( $_POST[key_ga_uid] );
293
+ if ($ga_uid == '')
294
+ $ga_uid = ga_uid_default;
295
+ update_option(key_ga_uid, $ga_uid);
296
+
297
+ // Update the admin logging
298
+ $ga_admin = wp_filter_kses( $_POST[key_ga_admin] );
299
+ if (($ga_admin != ga_enabled) && ($ga_admin != ga_disabled))
300
+ $ga_admin = ga_admin_default;
301
+ update_option(key_ga_admin, wp_filter_kses( $ga_admin ) );
302
+
303
+ // Update the admin disable setting
304
+ $ga_admin_disable = wp_filter_kses( $_POST[key_ga_admin_disable] );
305
+ if ( $ga_admin_disable == '' )
306
+ $ga_admin_disable = ga_admin_disable_default;
307
+ update_option(key_ga_admin_disable, wp_filter_kses( $ga_admin_disable) );
308
+
309
+ // Update the admin level
310
+ if ( array_key_exists(key_ga_admin_role, $_POST) ) {
311
+ $ga_admin_role = $_POST[key_ga_admin_role];
312
+ } else {
313
+ $ga_admin_role = "";
314
+ }
315
+ update_option(key_ga_admin_role, $ga_admin_role);
316
+
317
+ // Update the dashboard level
318
+ if ( array_key_exists(key_ga_dashboard_role, $_POST) ) {
319
+ $ga_dashboard_role = $_POST[key_ga_dashboard_role];
320
+ } else {
321
+ $ga_dashboard_role = "";
322
+ }
323
+ update_option(key_ga_dashboard_role, $ga_dashboard_role );
324
+
325
+ // Update the extra tracking code
326
+ $ga_extra = $_POST[key_ga_extra];
327
+ update_option(key_ga_extra, wp_filter_kses( $ga_extra ) );
328
+
329
+ // Update the extra after tracking code
330
+ $ga_extra_after = $_POST[key_ga_extra_after];
331
+ update_option(key_ga_extra_after, wp_filter_kses( $ga_extra_after ));
332
+
333
+ // Update the adsense key
334
+ $ga_adsense = $_POST[key_ga_adsense];
335
+ update_option(key_ga_adsense, wp_filter_kses( $ga_adsense ) );
336
+
337
+ // Update the event tracking
338
+ $ga_event = $_POST[key_ga_event];
339
+ if (($ga_event != ga_enabled) && ($ga_event != ga_disabled))
340
+ $ga_event = ga_event_default;
341
+ update_option(key_ga_event, wp_filter_kses ( $ga_event ) );
342
+
343
+ // Update the outbound tracking
344
+ $ga_outbound = $_POST[key_ga_outbound];
345
+ if (($ga_outbound != ga_enabled) && ($ga_outbound != ga_disabled))
346
+ $ga_outbound = ga_outbound_default;
347
+ update_option(key_ga_outbound, wp_filter_kses( $ga_outbound ) );
348
+
349
+ // Update the outbound prefix
350
+ $ga_outbound_prefix = $_POST[key_ga_outbound_prefix];
351
+ if ($ga_outbound_prefix == '')
352
+ $ga_outbound_prefix = ga_outbound_prefix_default;
353
+ update_option(key_ga_outbound_prefix, wp_filter_kses( $ga_outbound_prefix) );
354
+
355
+ // Update the download tracking code
356
+ $ga_downloads = $_POST[key_ga_downloads];
357
+ update_option(key_ga_downloads, wp_filter_kses( $ga_downloads ) );
358
+
359
+ // Update the download prefix
360
+ $ga_downloads_prefix = $_POST[key_ga_downloads_prefix];
361
+ if ($ga_downloads_prefix == '')
362
+ $ga_downloads_prefix = ga_downloads_prefix_default;
363
+ update_option(key_ga_downloads_prefix, wp_filter_kses( $ga_downloads_prefix) );
364
+
365
+ // Update the widgets option
366
+ $ga_widgets = $_POST[key_ga_widgets];
367
+ if (($ga_widgets != ga_enabled) && ($ga_widgets != ga_disabled))
368
+ $ga_widgets = ga_widgets_default;
369
+ update_option(key_ga_widgets, wp_filter_kses( $ga_widgets ) );
370
+
371
+ // Update the widgets option
372
+ update_option(key_ga_annon, wp_filter_kses( $_POST[key_ga_annon] ) );
373
+
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
+ <form method="post" action="<?php echo admin_url('options-general.php?page=google-analyticator.php');?>">
391
+ <?php
392
+ # Add a nonce
393
+ wp_nonce_field('google-analyticator-update_settings');
394
+ ?>
395
+
396
+ <?php if (get_option(key_ga_status) == ga_disabled) { ?>
397
+ <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
398
+ <?php _e('Google Analytics integration is currently <strong>DISABLED</strong>.', 'google-analyticator'); ?>
399
+ </div>
400
+ <?php } ?>
401
+ <?php if ((get_option(key_ga_uid) == "XX-XXXXX-X") && (get_option(key_ga_status) != ga_disabled)) { ?>
402
+ <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
403
+ <?php _e('Google Analytics integration is currently enabled, but you did not enter a UID. Tracking will not occur.', 'google-analyticator'); ?>
404
+ </div>
405
+ <?php } ?>
406
+ <table class="form-table" cellspacing="2" cellpadding="5" width="100%">
407
+
408
+ <tr>
409
+ <td colspan="2">
410
+ <h3><?php _e('Basic Settings', 'google-analyticator'); ?></h3>
411
+ </td>
412
+ </tr>
413
+
414
+ <tr>
415
+ <th width="30%" valign="top" style="padding-top: 10px;">
416
+ <label for="<?php echo key_ga_status ?>"><?php _e('Google Analytics logging is', 'google-analyticator'); ?>:</label>
417
+ </th>
418
+ <td>
419
+ <?php
420
+ echo "<select name='".key_ga_status."' id='".key_ga_status."'>\n";
421
+
422
+ echo "<option value='".ga_enabled."'";
423
+ if(get_option(key_ga_status) == ga_enabled)
424
+ echo " selected='selected'";
425
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
426
+
427
+ echo "<option value='".ga_disabled."'";
428
+ if(get_option(key_ga_status) == ga_disabled)
429
+ echo" selected='selected'";
430
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
431
+
432
+ echo "</select>\n";
433
+ ?>
434
+ </td>
435
+ </tr>
436
+ <tr id="ga_ajax_accounts">
437
+ <th valign="top" style="padding-top: 10px;">
438
+ <label for="<?php echo key_ga_uid; ?>"><?php _e('Google Analytics UID', 'google-analyticator'); ?>:</label>
439
+ </th>
440
+ <td>
441
+ <?php
442
+
443
+ if( $useAuth ):
444
+
445
+ $uids = ga_get_analytics_accounts();
446
+
447
+ echo "<select name='".key_ga_uid."'> ";
448
+
449
+ $hasSelected = false; // Will be set to true once a match is found. Cant echo selected twice.
450
+
451
+ foreach($uids as $id=>$domain):
452
+
453
+ echo '<option value="'.$id.'"';
454
+ // If set in DB.
455
+ if( get_option(key_ga_uid) == $id ) { $hasSelected=true; echo ' selected="selected"'; }
456
+ // Else if the domain matches the current domain & nothing set in DB.
457
+ elseif( ( $_SERVER['HTTP_HOST'] == $domain ) && ( ! $hasSelected ) ) { $hasSelected=true; echo ' selected="selected"'; }
458
+ echo '>'.$domain.'</option>';
459
+
460
+ endforeach;
461
+
462
+ echo '</select>';
463
+
464
+ else:
465
+
466
+ echo '<input type="text" name="'.key_ga_uid.'" value="'. get_option( key_ga_uid ) .'" />';
467
+
468
+ endif;
469
+ ?>
470
+ </td>
471
+ </tr>
472
+ <tr>
473
+ <td colspan="2">
474
+ <h3><?php _e('Tracking Settings', 'google-analyticator'); ?></h3>
475
+ </td>
476
+ </tr>
477
+ <tr>
478
+ <th width="30%" valign="top" style="padding-top: 10px;">
479
+ <label for="<?php echo key_ga_admin ?>"><?php _e('Track all logged in WordPress users', 'google-analyticator'); ?>:</label>
480
+ </th>
481
+ <td>
482
+ <?php
483
+ echo "<select name='".key_ga_admin."' id='".key_ga_admin."'>\n";
484
+
485
+ echo "<option value='".ga_enabled."'";
486
+ if(get_option(key_ga_admin) == ga_enabled)
487
+ echo " selected='selected'";
488
+ echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
489
+
490
+ echo "<option value='".ga_disabled."'";
491
+ if(get_option(key_ga_admin) == ga_disabled)
492
+ echo" selected='selected'";
493
+ echo ">" . __('No', 'google-analyticator') . "</option>\n";
494
+
495
+ echo "</select>\n";
496
+
497
+ ?>
498
+ <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>
499
+ </td>
500
+ </tr>
501
+ <tr>
502
+ <th width="30%" valign="top" style="padding-top: 10px;">
503
+ <label><?php _e('Anonymize IP Addresses', 'google-analyticator'); ?>:</label>
504
+ </th>
505
+ <td>
506
+ <?php
507
+ echo "<select name='".key_ga_annon."' id='".key_ga_annon."'>\n";
508
+
509
+ echo "<option value='0'";
510
+ if(get_option(key_ga_annon) == false )
511
+ echo " selected='selected'";
512
+ echo ">" . __('No', 'google-analyticator') . "</option>\n";
513
+
514
+ echo "<option value='1'";
515
+ if(get_option(key_ga_annon) == true)
516
+ echo" selected='selected'";
517
+ echo ">" . __('Yes', 'google-analyticator') . "</option>\n";
518
+
519
+ echo "</select>\n";
520
+
521
+ ?>
522
+ <p class="setting-description"><?php _e('By selecting "Yes", This tells Google Analytics to anonymize the information sent by the tracker objects by removing the last octet of the IP address prior to its storage. Note that this will slightly reduce the accuracy of geographic reporting.', 'google-analyticator'); ?></p>
523
+ </td>
524
+ </tr>
525
+ <tr>
526
+ <th width="30%" valign="top" style="padding-top: 10px;">
527
+ <label for="<?php echo key_ga_admin_role ?>"><?php _e('User roles to not track', 'google-analyticator'); ?>:</label>
528
+ </th>
529
+ <td>
530
+ <?php
531
+ global $wp_roles;
532
+ $roles = $wp_roles->get_names();
533
+ $selected_roles = get_option(key_ga_admin_role);
534
+ if ( !is_array($selected_roles) ) $selected_roles = array();
535
+
536
+ # Loop through the roles
537
+ foreach ( $roles AS $role => $name ) {
538
+ echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_admin_role . '[]"';
539
+ if ( in_array($role, $selected_roles) )
540
+ echo " checked='checked'";
541
+ $name_pos = strpos($name, '|');
542
+ $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
543
+ echo ' /> ' . _x($name, 'User role') . '<br />';
544
+ }
545
+ ?>
546
+ <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>
547
+ </td>
548
+ </tr>
549
+ <tr>
550
+ <th width="30%" valign="top" style="padding-top: 10px;">
551
+ <label for="<?php echo key_ga_admin_disable ?>"><?php _e('Method to prevent tracking', 'google-analyticator'); ?>:</label>
552
+ </th>
553
+ <td>
554
+ <?php
555
+ echo "<select name='".key_ga_admin_disable."' id='".key_ga_admin_disable."'>\n";
556
+
557
+ echo "<option value='remove'";
558
+ if(get_option(key_ga_admin_disable) == 'remove')
559
+ echo " selected='selected'";
560
+ echo ">" . __('Remove', 'google-analyticator') . "</option>\n";
561
+
562
+ echo "<option value='admin'";
563
+ if(get_option(key_ga_admin_disable) == 'admin')
564
+ echo" selected='selected'";
565
+ echo ">" . __('Use \'admin\' variable', 'google-analyticator') . "</option>\n";
566
+
567
+ echo "</select>\n";
568
+ ?>
569
+ <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>
570
+ </td>
571
+ </tr>
572
+ <tr>
573
+ <td colspan="2">
574
+ <h3>Link Tracking Settings</h3>
575
+ </td>
576
+ </tr>
577
+ <tr>
578
+ <th width="30%" valign="top" style="padding-top: 10px;">
579
+ <label for="<?php echo key_ga_outbound ?>"><?php _e('Outbound link tracking', 'google-analyticator'); ?>:</label>
580
+ </th>
581
+ <td>
582
+ <?php
583
+ echo "<select name='".key_ga_outbound."' id='".key_ga_outbound."'>\n";
584
+
585
+ echo "<option value='".ga_enabled."'";
586
+ if(get_option(key_ga_outbound) == ga_enabled)
587
+ echo " selected='selected'";
588
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
589
+
590
+ echo "<option value='".ga_disabled."'";
591
+ if(get_option(key_ga_outbound) == ga_disabled)
592
+ echo" selected='selected'";
593
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
594
+
595
+ echo "</select>\n";
596
+ ?>
597
+ <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>
598
+ </td>
599
+ </tr>
600
+ <tr>
601
+ <th width="30%" valign="top" style="padding-top: 10px;">
602
+ <label for="<?php echo key_ga_event ?>"><?php _e('Event tracking', 'google-analyticator'); ?>:</label>
603
+ </th>
604
+ <td>
605
+ <?php
606
+ echo "<select name='".key_ga_event."' id='".key_ga_event."'>\n";
607
+
608
+ echo "<option value='".ga_enabled."'";
609
+ if(get_option(key_ga_event) == ga_enabled)
610
+ echo " selected='selected'";
611
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
612
+
613
+ echo "<option value='".ga_disabled."'";
614
+ if(get_option(key_ga_event) == ga_disabled)
615
+ echo" selected='selected'";
616
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
617
+
618
+ echo "</select>\n";
619
+ ?>
620
+ <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>
621
+ </td>
622
+ </tr>
623
+ <tr>
624
+ <th valign="top" style="padding-top: 10px;">
625
+ <label for="<?php echo key_ga_downloads; ?>"><?php _e('Download extensions to track', 'google-analyticator'); ?>:</label>
626
+ </th>
627
+ <td>
628
+ <?php
629
+ echo "<input type='text' size='50' ";
630
+ echo "name='".key_ga_downloads."' ";
631
+ echo "id='".key_ga_downloads."' ";
632
+ echo "value='".wp_filter_kses(get_option(key_ga_downloads))."' />\n";
633
+ ?>
634
+ <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>
635
+ </td>
636
+ </tr>
637
+ <tr>
638
+ <th valign="top" style="padding-top: 10px;">
639
+ <label for="<?php echo key_ga_outbound_prefix; ?>"><?php _e('Prefix external links with', 'google-analyticator'); ?>:</label>
640
+ </th>
641
+ <td>
642
+ <?php
643
+ echo "<input type='text' size='50' ";
644
+ echo "name='".key_ga_outbound_prefix."' ";
645
+ echo "id='".key_ga_outbound_prefix."' ";
646
+ echo "value='". stripslashes( wp_filter_kses(get_option(key_ga_outbound_prefix)))."' />\n";
647
+ ?>
648
+ <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>
649
+ </td>
650
+ </tr>
651
+ <tr>
652
+ <th valign="top" style="padding-top: 10px;">
653
+ <label for="<?php echo key_ga_downloads_prefix; ?>"><?php _e('Prefix download links with', 'google-analyticator'); ?>:</label>
654
+ </th>
655
+ <td>
656
+ <?php
657
+ echo "<input type='text' size='50' ";
658
+ echo "name='".key_ga_downloads_prefix."' ";
659
+ echo "id='".key_ga_downloads_prefix."' ";
660
+ echo "value='".stripslashes(wp_filter_kses ( get_option(key_ga_downloads_prefix) ))."' />\n";
661
+ ?>
662
+ <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>
663
+ </td>
664
+ </tr>
665
+ <tr>
666
+ <th valign="top" style="padding-top: 10px;">
667
+ <label for="<?php echo key_ga_adsense; ?>"><?php _e('Google Adsense ID', 'google-analyticator'); ?>:</label>
668
+ </th>
669
+ <td>
670
+ <?php
671
+ echo "<input type='text' size='50' ";
672
+ echo "name='".key_ga_adsense."' ";
673
+ echo "id='".key_ga_adsense."' ";
674
+ echo "value='".get_option(key_ga_adsense)."' />\n";
675
+ ?>
676
+ <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>
677
+ </td>
678
+ </tr>
679
+ <tr>
680
+ <td colspan="2">
681
+ <h3>Additional Tracking Code </h3>
682
+ </td>
683
+ </tr>
684
+ <tr>
685
+ <th valign="top" style="padding-top: 10px;">
686
+ <label for="<?php echo key_ga_extra; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('before tracker initialization', 'google-analyticator'); ?>):</label>
687
+ </th>
688
+ <td>
689
+ <?php
690
+ echo "<textarea cols='50' rows='8' ";
691
+ echo "name='".key_ga_extra."' ";
692
+ echo "id='".key_ga_extra."'>";
693
+ echo stripslashes(get_option(key_ga_extra))."</textarea>\n";
694
+ ?>
695
+ <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>
696
+ </td>
697
+ </tr>
698
+ <tr>
699
+ <th valign="top" style="padding-top: 10px;">
700
+ <label for="<?php echo key_ga_extra_after; ?>"><?php _e('Additional tracking code', 'google-analyticator'); ?><br />(<?php _e('after tracker initialization', 'google-analyticator'); ?>):</label>
701
+ </th>
702
+ <td>
703
+ <?php
704
+ echo "<textarea cols='50' rows='8' ";
705
+ echo "name='".key_ga_extra_after."' ";
706
+ echo "id='".key_ga_extra_after."'>";
707
+ echo stripslashes(get_option(key_ga_extra_after))."</textarea>\n";
708
+ ?>
709
+ <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>
710
+ </td>
711
+ </tr>
712
+ <tr>
713
+ <td colspan="2">
714
+ <h3>Admin Dashboard Widgets</h3>
715
+ <?php if(!$useAuth): ?>
716
+ <div style="margin:10px auto; border:3px #f00 solid; background-color:#fdd; color:#000; padding:10px; text-align:center;">
717
+ <?php _e('You have not authenticated with Google - you cannot use dashboard widgets! Reset the plugin to authenticate..', 'google-analyticator'); ?>
718
+ </div>
719
+ <?php endif;?>
720
+ </td>
721
+ </tr>
722
+ <tr<?php if(!$useAuth){echo ' style="display:none"';}?>>
723
+ <th width="30%" valign="top" style="padding-top: 10px;">
724
+ <label for="<?php echo key_ga_widgets; ?>"><?php _e('Include widgets', 'google-analyticator'); ?>:</label>
725
+ </th>
726
+ <td>
727
+ <?php
728
+ echo "<select name='".key_ga_widgets."' id='".key_ga_widgets."'>\n";
729
+
730
+ echo "<option value='".ga_enabled."'";
731
+ if(get_option(key_ga_widgets) == ga_enabled)
732
+ echo " selected='selected'";
733
+ echo ">" . __('Enabled', 'google-analyticator') . "</option>\n";
734
+
735
+ echo "<option value='".ga_disabled."'";
736
+ if(get_option(key_ga_widgets) == ga_disabled)
737
+ echo" selected='selected'";
738
+ echo ">" . __('Disabled', 'google-analyticator') . "</option>\n";
739
+
740
+ echo "</select>\n";
741
+ ?>
742
+ <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>
743
+ </td>
744
+ </tr>
745
+ <tr<?php if(!$useAuth){echo ' style="display:none"';}?>>
746
+ <th width="30%" valign="top" style="padding-top: 10px;">
747
+ <label for="<?php echo key_ga_dashboard_role ?>"><?php _e('User roles that can see the dashboard widget', 'google-analyticator'); ?>:</label>
748
+ </th>
749
+ <td>
750
+ <?php
751
+ global $wp_roles;
752
+ $roles = $wp_roles->get_names();
753
+ $selected_roles = get_option(key_ga_dashboard_role);
754
+ if ( !is_array($selected_roles) ) $selected_roles = array();
755
+
756
+ # Loop through the roles
757
+ foreach ( $roles AS $role => $name ) {
758
+ echo '<input type="checkbox" value="' . $role . '" name="' . key_ga_dashboard_role . '[]"';
759
+ if ( in_array($role, $selected_roles) )
760
+ echo " checked='checked'";
761
+ $name_pos = strpos($name, '|');
762
+ $name = ( $name_pos ) ? substr($name, 0, $name_pos) : $name;
763
+ echo ' /> ' . _x($name, 'User role') . '<br />';
764
+ }
765
+ ?>
766
+ <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>
767
+ </td>
768
+ </tr>
769
+
770
+ </table>
771
+ <p class="submit">
772
+ <input type="submit" class="button button-primary" name="info_update" value="<?php _e('Save Changes', 'google-analyticator'); ?>" />
773
+ </p>
774
+
775
+ <a href="<?php echo admin_url('/options-general.php?page=ga_reset'); ?>"><?php _e('Deauthorize &amp; Reset Google Analyticator.', 'google-analyticator'); ?></a>
776
+
777
+ </form>
778
+
779
+ </form>
780
+
781
+
782
+ <?php if (!get_option('wpm_o_user_id')): ?>
783
+ <img src="<?php echo plugins_url('ga-plugin-advert.jpg', __FILE__ ); ?>" alt="Google Analytics Getting It Right" />
784
+ <form accept-charset="utf-8" action="https://app.getresponse.com/add_contact_webform.html" method="post" onsubmit="return quickValidate()" target="_blank">
785
+ <div style="display: none;">
786
+ <input type="hidden" name="webform_id" value="416798" />
787
+ </div>
788
+ <table style="text-align:center;margin-left: 20px;">
789
+ <tr>
790
+ <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>
791
+ <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>
792
+ <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>
793
+ </tr>
794
+ <tr>
795
+ <td colspan="3" style="padding-top: 20px;">
796
+ <a title="Privacy Policy" href="http://www.getresponse.com/permission-seal?lang=en" target="_blank"><img src="<?php echo plugins_url('privacy.png', __FILE__); ?>" alt="" title="" /></a>
797
+ </td>
798
+ </tr>
799
+ </table>
800
+ </form>
801
+
802
+ <script type="text/javascript">
803
+ function quickValidate()
804
+ {
805
+ if (! jQuery('#sub_name').val() )
806
+ {
807
+ alert('Your Name is required');
808
+ return false;
809
+ }
810
+ if(! jQuery('#sub_email').val() )
811
+ {
812
+ alert('Your Email is required');
813
+ return false;
814
+ }
815
+
816
+ return true;
817
+ }
818
+ </script>
819
+ <?php endif;?>
820
+
821
+
822
+ <?php
823
+ }
824
+
825
+ function ga_sort_account_list($a, $b) {
826
+ return strcmp($a['title'],$b['title']);
827
+ }
828
+
829
+ /**
830
+ * Checks if the WordPress API is a valid method for selecting an account
831
+ *
832
+ * @return a list of accounts if available, false if none available
833
+ **/
834
+ function ga_get_analytics_accounts()
835
+ {
836
+ $accounts = array();
837
+
838
+ # Get the class for interacting with the Google Analytics
839
+ require_once('class.analytics.stats.php');
840
+
841
+ # Create a new Gdata call
842
+ if ( isset($_POST['token']) && $_POST['token'] != '' )
843
+ $stats = new GoogleAnalyticsStats($_POST['token']);
844
+ elseif ( trim(get_option('ga_google_token')) != '' )
845
+ $stats = new GoogleAnalyticsStats();
846
+ else
847
+ return false;
848
+
849
+ # Check if Google sucessfully logged in
850
+ if ( ! $stats->checkLogin() )
851
+ return false;
852
+
853
+ # Get a list of accounts
854
+ $accounts = $stats->getAllProfiles();
855
+
856
+ natcasesort ($accounts);
857
+
858
+ # Return the account array if there are accounts
859
+ if ( count($accounts) > 0 )
860
+ return $accounts;
861
+ else
862
+ return false;
863
+ }
864
+
865
+ /**
866
+ * Add http_build_query if it doesn't exist already
867
+ **/
868
+ if ( !function_exists('http_build_query') ) {
869
+ function http_build_query($params, $key = null)
870
+ {
871
+ $ret = array();
872
+
873
+ foreach( (array) $params as $name => $val ) {
874
+ $name = urlencode($name);
875
+
876
+ if ( $key !== null )
877
+ $name = $key . "[" . $name . "]";
878
+
879
+ if ( is_array($val) || is_object($val) )
880
+ $ret[] = http_build_query($val, $name);
881
+ elseif ($val !== null)
882
+ $ret[] = $name . "=" . urlencode($val);
883
+ }
884
+
885
+ return implode("&", $ret);
886
+ }
887
+ }
888
+
889
+ /**
890
+ * Echos out the core Analytics tracking code
891
+ **/
892
+ function add_google_analytics()
893
+ {
894
+ # Fetch variables used in the tracking code
895
+ $uid = stripslashes(get_option(key_ga_uid));
896
+ $extra = stripslashes(get_option(key_ga_extra));
897
+ $extra_after = stripslashes(get_option(key_ga_extra_after));
898
+ $extensions = str_replace (",", "|", get_option(key_ga_downloads));
899
+
900
+ # Determine if the GA is enabled and contains a valid UID
901
+ if ( ( get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
902
+ {
903
+ # Determine if the user is an admin, and should see the tracking code
904
+ 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' )
905
+ {
906
+ # Disable the tracking code on the post preview page
907
+ if ( !function_exists("is_preview") || ( function_exists("is_preview") && !is_preview() ) )
908
+ {
909
+ # Add the notice that Google Analyticator tracking is enabled
910
+ echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://www.videousermanuals.com/google-analyticator/ -->\n";
911
+
912
+ # Add the Adsense data if specified
913
+ if ( get_option(key_ga_adsense) != '' )
914
+ echo '<script type="text/javascript">window.google_analytics_uacct = "' . get_option(key_ga_adsense) . "\";</script>\n";
915
+
916
+ # Include the file types to track
917
+ $extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
918
+ $ext = "";
919
+ foreach ( $extensions AS $extension )
920
+ $ext .= "'$extension',";
921
+ $ext = substr($ext, 0, -1);
922
+
923
+ # Include the link tracking prefixes
924
+ $outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
925
+ $downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
926
+ $event_tracking = get_option(key_ga_event);
927
+
928
+
929
+ $need_to_annon = get_option(key_ga_annon);
930
+
931
+
932
+ ?>
933
+ <script type="text/javascript">
934
+ var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
935
+ <?php if ( $event_tracking != 'enabled' ) { ?>
936
+ var analyticsOutboundPrefix = '/<?php echo $outbound_prefix; ?>/';
937
+ var analyticsDownloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
938
+ <?php } ?>
939
+ var analyticsEventTracking = '<?php echo $event_tracking; ?>';
940
+ </script>
941
+ <?php
942
+ # Add the first part of the core tracking code
943
+ ?>
944
+ <script type="text/javascript">
945
+ var _gaq = _gaq || [];
946
+ _gaq.push(['_setAccount', '<?php echo $uid; ?>']);
947
+ _gaq.push(['_addDevId', 'i9k95']); // Google Analyticator App ID with Google
948
+ <?php if ($need_to_annon == '1' ): ?>
949
+ _gaq.push(['_gat._anonymizeIp']);
950
+ <?php endif; ?>
951
+ <?php
952
+
953
+ # Add any tracking code before the trackPageview
954
+ do_action('google_analyticator_extra_js_before');
955
+ if ( '' != $extra )
956
+ echo " $extra\n";
957
+
958
+ # Add the track pageview function
959
+ echo " _gaq.push(['_trackPageview']);\n";
960
+
961
+ # Disable page tracking if admin is logged in
962
+ if ( ( get_option(key_ga_admin) == ga_disabled ) && ( ga_current_user_is(get_option(key_ga_admin_role)) ) )
963
+ echo " _gaq.push(['_setCustomVar', 'admin']);\n";
964
+
965
+ # Add any tracking code after the trackPageview
966
+ do_action('google_analyticator_extra_js_after');
967
+ if ( '' != $extra_after )
968
+ echo " $extra_after\n";
969
+
970
+ # Add the final section of the tracking code
971
+ ?>
972
+
973
+ (function() {
974
+ var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
975
+ ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
976
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
977
+ })();
978
+ </script>
979
+ <?php
980
+ }
981
+ } else {
982
+ # Add the notice that Google Analyticator tracking is enabled
983
+ echo "<!-- Google Analytics Tracking by Google Analyticator " . GOOGLE_ANALYTICATOR_VERSION . ": http://ronaldheft.com/code/analyticator/ -->\n";
984
+ echo " <!-- " . __('Tracking code is hidden, since the settings specify not to track admins. Tracking is occurring for non-admins.', 'google-analyticator') . " -->\n";
985
+ }
986
+ }
987
+ }
988
+
989
+ /**
990
+ * Adds outbound link tracking to Google Analyticator
991
+ **/
992
+ function ga_outgoing_links()
993
+ {
994
+ # Fetch the UID
995
+ $uid = stripslashes(get_option(key_ga_uid));
996
+
997
+ # If GA is enabled and has a valid key
998
+ if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" ) )
999
+ {
1000
+ # If outbound tracking is enabled
1001
+ if ( get_option(key_ga_outbound) == ga_enabled )
1002
+ {
1003
+ # If this is not an admin page
1004
+ if ( !is_admin() )
1005
+ {
1006
+ # Display page tracking if user is not an admin
1007
+ 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' )
1008
+ {
1009
+ add_action('wp_print_scripts', 'ga_external_tracking_js',99999);
1010
+ }
1011
+ }
1012
+ }
1013
+ }
1014
+ }
1015
+
1016
+ /**
1017
+ * Adds the scripts required for outbound link tracking
1018
+ **/
1019
+ function ga_external_tracking_js()
1020
+ {
1021
+ $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
1022
+ wp_enqueue_script('ga-external-tracking', plugins_url("/google-analyticator/external-tracking{$suffix}.js"), array('jquery'), GOOGLE_ANALYTICATOR_VERSION);
1023
+ }
1024
+
1025
+ /**
1026
+ * Determines if a specific user fits a role
1027
+ **/
1028
+ function ga_current_user_is($roles)
1029
+ {
1030
+ if ( !$roles ) return false;
1031
+
1032
+ global $current_user;
1033
+ get_currentuserinfo();
1034
+ $user_id = intval( $current_user->ID );
1035
+
1036
+ if ( !$user_id ) {
1037
+ return false;
1038
+ }
1039
+ $user = new WP_User($user_id); // $user->roles
1040
+
1041
+ foreach ( $roles as $role )
1042
+ if ( in_array($role, $user->roles) ) return true;
1043
+
1044
+ return false;
1045
+ }
google-analytics-stats-widget.php CHANGED
@@ -1,243 +1,243 @@
1
- <?php
2
-
3
- /**
4
- * The Google Analytics Stats Widget
5
- *
6
- * Now using widget API available in WordPress 2.8
7
- * @author Spiral Web Consulting
8
- **/
9
- class GoogleStatsWidget extends WP_Widget
10
- {
11
- function GoogleStatsWidget() {
12
- $widget_ops = array('classname' => 'widget_google_stats', 'description' => __("Displays Stat Info From Google Analytics", 'google-analyticator') );
13
- $control_ops = array('width' => 400, 'height' => 400);
14
- $this->WP_Widget('googlestats', __('Google Analytics Stats', 'google-analyticator'), $widget_ops, $control_ops);
15
- }
16
-
17
- function widget($args, $instance) {
18
- extract($args);
19
- $title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
20
- $acnt = false;
21
- $timeFrame = empty($instance['timeFrame']) ? '1' : $instance['timeFrame'];
22
- $pageBg = empty($instance['pageBg']) ? 'fff' : $instance['pageBg'];
23
- $widgetBg = empty($instance['widgetBg']) ? '999' : $instance['widgetBg'];
24
- $innerBg = empty($instance['innerBg']) ? 'fff' : $instance['innerBg'];
25
- $font = empty($instance['font']) ? '333' : $instance['font'];
26
- $line1 = empty($instance['line1']) ? 'Unique' : $instance['line1'];
27
- $line2 = empty($instance['line2']) ? 'Visitors' : $instance['line2'];
28
-
29
- # Before the widget
30
- echo $before_widget;
31
-
32
- # The title
33
- if ( $title )
34
- echo $before_title . $title . $after_title;
35
-
36
- # Make the stats chicklet
37
- echo '<!-- Data gathered from last ' . number_format($timeFrame) . ' days using Google Analyticator -->';
38
- $this->initiateBackground($pageBg, $font);
39
- $this->beginWidget($font, $widgetBg);
40
- $this->widgetInfo($this->getUniqueVisitors($acnt, $timeFrame), $line1, $line2, $innerBg, $font);
41
- $this->endWidget();
42
-
43
- # After the widget
44
- echo $after_widget;
45
- }
46
-
47
- function update($new_instance, $old_instance) {
48
- $instance = $old_instance;
49
- $instance['title'] = strip_tags(stripslashes($new_instance['title']));
50
- $instance['account'] = strip_tags(stripslashes($new_instance['account']));
51
- $instance['timeFrame'] = strip_tags(stripslashes($new_instance['timeFrame']));
52
- $instance['pageBg'] = strip_tags(stripslashes($new_instance['pageBg']));
53
- $instance['widgetBg'] = strip_tags(stripslashes($new_instance['widgetBg']));
54
- $instance['innerBg'] = strip_tags(stripslashes($new_instance['innerBg']));
55
- $instance['font'] = strip_tags(stripslashes($new_instance['font']));
56
- $instance['line1'] = strip_tags(stripslashes($new_instance['line1']));
57
- $instance['line2'] = strip_tags(stripslashes($new_instance['line2']));
58
-
59
- return $instance;
60
- }
61
-
62
- function form($instance) {
63
- //Defaults
64
- $instance = wp_parse_args( (array) $instance, array('title'=>'', 'account'=>'', 'timeFrame'=>'1', 'pageBg'=>'fff', 'widgetBg'=>'999', 'innerBg'=>'fff', 'font'=>'333', 'line1'=>'Unique', 'line2'=>'Visitors') );
65
-
66
- $title = htmlspecialchars($instance['title']);
67
- $acnt = htmlspecialchars($instance['account']);
68
- $timeFrame = htmlspecialchars($instance['timeFrame']);
69
- $pageBg = htmlspecialchars($instance['pageBg']);
70
- $widgetBg = htmlspecialchars($instance['widgetBg']);
71
- $innerBg = htmlspecialchars($instance['innerBg']);
72
- $font = htmlspecialchars($instance['font']);
73
- $line1 = htmlspecialchars($instance['line1']);
74
- $line2 = htmlspecialchars($instance['line2']);
75
-
76
- $accounts = array();
77
-
78
- # Get the current memory limit
79
- $current_mem_limit = substr(ini_get('memory_limit'), 0, -1);
80
-
81
- # Check if this limit is less than 96M, if so, increase it
82
- if ( $current_mem_limit < 96 || $current_mem_limit == '' ) {
83
- if ( function_exists('memory_get_usage') )
84
- @ini_set('memory_limit', '96M');
85
- }
86
-
87
- # Get the class for interacting with the Google Analytics
88
- require_once('class.analytics.stats.php');
89
-
90
- # Create a new Gdata call
91
- $stats = new GoogleAnalyticsStats();
92
-
93
- # Check if Google sucessfully logged in
94
- $login = $stats->checkLogin();
95
-
96
- if( !$login )
97
- return false;
98
-
99
- # Get a list of accounts
100
- //$accounts = $stats->getAnalyticsAccounts();
101
- $accounts = $stats->getSingleProfile();
102
-
103
-
104
-
105
- # Output the options
106
- echo '<p style="text-align:right;"><label for="' . $this->get_field_name('title') . '">' . __('Title', 'google-analyticator') . ': <input style="width: 250px;" id="' . $this->get_field_id('title') . '" name="' . $this->get_field_name('title') . '" type="text" value="' . $title . '" /></label></p>';
107
- # Time frame
108
-