Version Description
Download this release
Release Info
Developer | cavemonkey50 |
Plugin | Google Analyticator |
Version | 3.01 |
Comparing to | |
See all releases |
Code changes from version 3.0 to 3.01
- google-analyticator.php +88 -45
- readme.txt +1 -1
google-analyticator.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?php
|
2 |
/*
|
3 |
* Plugin Name: Google Analyticator
|
4 |
-
* Version: 3.
|
5 |
* Plugin URI: http://plugins.spiralwebconsulting.com/analyticator.html
|
6 |
* Description: Adds the necessary JavaScript code to enable <a href="http://www.google.com/analytics/">Google's Analytics</a>. After enabling this plugin visit <a href="options-general.php?page=google-analyticator.php">the settings page</a> and enter your Google Analytics' UID and enable logging.
|
7 |
* Author: Spiral Web Consulting
|
@@ -16,6 +16,7 @@ define("ga_disabled", "disabled", true);
|
|
16 |
define("key_ga_uid", "ga_uid", true);
|
17 |
define("key_ga_status", "ga_status", true);
|
18 |
define("key_ga_admin", "ga_admin_status", true);
|
|
|
19 |
define("key_ga_admin_level", "ga_admin_level", true);
|
20 |
define("key_ga_extra", "ga_extra", true);
|
21 |
define("key_ga_extra_after", "ga_extra_after", true);
|
@@ -29,6 +30,7 @@ define("key_ga_specify_http", "ga_specify_http", true);
|
|
29 |
define("ga_uid_default", "XX-XXXXX-X", true);
|
30 |
define("ga_status_default", ga_disabled, true);
|
31 |
define("ga_admin_default", ga_enabled, true);
|
|
|
32 |
define("ga_admin_level_default", 8, true);
|
33 |
define("ga_extra_default", "", true);
|
34 |
define("ga_extra_after_default", "", true);
|
@@ -43,6 +45,7 @@ define("ga_specify_http_default", "auto", true);
|
|
43 |
add_option(key_ga_status, ga_status_default, 'If Google Analytics logging in turned on or off.');
|
44 |
add_option(key_ga_uid, ga_uid_default, 'Your Google Analytics UID.');
|
45 |
add_option(key_ga_admin, ga_admin_default, 'If WordPress admins are counted in Google Analytics.');
|
|
|
46 |
add_option(key_ga_admin_level, ga_admin_level_default, 'The level to consider a user a WordPress admin.');
|
47 |
add_option(key_ga_extra, ga_extra_default, 'Addition Google Analytics tracking options');
|
48 |
add_option(key_ga_extra_after, ga_extra_after_default, 'Addition Google Analytics tracking options');
|
@@ -64,6 +67,7 @@ function ga_admin_init() {
|
|
64 |
register_setting('google-analyticator', key_ga_status, '');
|
65 |
register_setting('google-analyticator', key_ga_uid, '');
|
66 |
register_setting('google-analyticator', key_ga_admin, '');
|
|
|
67 |
register_setting('google-analyticator', key_ga_admin_level, '');
|
68 |
register_setting('google-analyticator', key_ga_extra, '');
|
69 |
register_setting('google-analyticator', key_ga_extra_after, '');
|
@@ -108,6 +112,12 @@ function ga_options_page() {
|
|
108 |
$ga_admin = ga_admin_default;
|
109 |
update_option(key_ga_admin, $ga_admin);
|
110 |
|
|
|
|
|
|
|
|
|
|
|
|
|
111 |
// Update the admin level
|
112 |
$ga_admin_level = $_POST[key_ga_admin_level];
|
113 |
if ( $ga_admin_level == '' )
|
@@ -274,6 +284,29 @@ function ga_options_page() {
|
|
274 |
?>.</p>
|
275 |
</td>
|
276 |
</tr>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
<tr>
|
278 |
<th width="30%" valign="top" style="padding-top: 10px;">
|
279 |
<label for="<?php echo key_ga_footer ?>">Footer tracking code:</label>
|
@@ -446,58 +479,62 @@ function add_google_analytics() {
|
|
446 |
// If GA is enabled and has a valid key
|
447 |
if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
|
448 |
|
449 |
-
|
450 |
-
|
451 |
-
if ( get_option(key_ga_specify_http) == 'http' ) {
|
452 |
-
echo " <script type=\"text/javascript\" src=\"http://www.google-analytics.com/ga.js\"></script>\n\n";
|
453 |
-
} elseif ( get_option(key_ga_specify_http) == 'https' ) {
|
454 |
-
echo " <script type=\"text/javascript\" src=\"https://ssl.google-analytics.com/ga.js\"></script>\n\n";
|
455 |
-
} else {
|
456 |
-
echo " <script type=\"text/javascript\">\n";
|
457 |
-
echo " var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n";
|
458 |
-
echo " document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n";
|
459 |
-
echo " </script>\n\n";
|
460 |
-
}
|
461 |
|
462 |
-
|
463 |
-
|
464 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
465 |
|
466 |
-
|
467 |
-
|
468 |
-
echo "
|
469 |
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
|
474 |
-
|
475 |
-
|
476 |
-
echo " pageTracker.
|
477 |
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
|
482 |
-
|
|
|
|
|
483 |
|
484 |
-
|
485 |
-
$extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
|
486 |
-
foreach ( $extensions AS $extension )
|
487 |
-
$ext .= "'$extension',";
|
488 |
-
$ext = substr($ext, 0, -1);
|
489 |
|
490 |
-
|
491 |
-
|
492 |
-
|
|
|
|
|
493 |
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
|
|
|
|
|
|
|
|
|
|
501 |
}
|
502 |
}
|
503 |
|
@@ -512,7 +549,13 @@ function ga_outgoing_links()
|
|
512 |
if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
|
513 |
// If outbound tracking is enabled
|
514 |
if ( get_option(key_ga_outbound) == ga_enabled ) {
|
515 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
516 |
}
|
517 |
}
|
518 |
}
|
1 |
<?php
|
2 |
/*
|
3 |
* Plugin Name: Google Analyticator
|
4 |
+
* Version: 3.01
|
5 |
* Plugin URI: http://plugins.spiralwebconsulting.com/analyticator.html
|
6 |
* Description: Adds the necessary JavaScript code to enable <a href="http://www.google.com/analytics/">Google's Analytics</a>. After enabling this plugin visit <a href="options-general.php?page=google-analyticator.php">the settings page</a> and enter your Google Analytics' UID and enable logging.
|
7 |
* Author: Spiral Web Consulting
|
16 |
define("key_ga_uid", "ga_uid", true);
|
17 |
define("key_ga_status", "ga_status", true);
|
18 |
define("key_ga_admin", "ga_admin_status", true);
|
19 |
+
define("key_ga_admin_disable", "ga_admin_disable", true);
|
20 |
define("key_ga_admin_level", "ga_admin_level", true);
|
21 |
define("key_ga_extra", "ga_extra", true);
|
22 |
define("key_ga_extra_after", "ga_extra_after", true);
|
30 |
define("ga_uid_default", "XX-XXXXX-X", true);
|
31 |
define("ga_status_default", ga_disabled, true);
|
32 |
define("ga_admin_default", ga_enabled, true);
|
33 |
+
define("ga_admin_disable_default", 'remove', true);
|
34 |
define("ga_admin_level_default", 8, true);
|
35 |
define("ga_extra_default", "", true);
|
36 |
define("ga_extra_after_default", "", true);
|
45 |
add_option(key_ga_status, ga_status_default, 'If Google Analytics logging in turned on or off.');
|
46 |
add_option(key_ga_uid, ga_uid_default, 'Your Google Analytics UID.');
|
47 |
add_option(key_ga_admin, ga_admin_default, 'If WordPress admins are counted in Google Analytics.');
|
48 |
+
add_option(key_ga_admin_disable, ga_admin_disable_default, '');
|
49 |
add_option(key_ga_admin_level, ga_admin_level_default, 'The level to consider a user a WordPress admin.');
|
50 |
add_option(key_ga_extra, ga_extra_default, 'Addition Google Analytics tracking options');
|
51 |
add_option(key_ga_extra_after, ga_extra_after_default, 'Addition Google Analytics tracking options');
|
67 |
register_setting('google-analyticator', key_ga_status, '');
|
68 |
register_setting('google-analyticator', key_ga_uid, '');
|
69 |
register_setting('google-analyticator', key_ga_admin, '');
|
70 |
+
register_setting('google-analyticator', key_ga_admin_disable, '');
|
71 |
register_setting('google-analyticator', key_ga_admin_level, '');
|
72 |
register_setting('google-analyticator', key_ga_extra, '');
|
73 |
register_setting('google-analyticator', key_ga_extra_after, '');
|
112 |
$ga_admin = ga_admin_default;
|
113 |
update_option(key_ga_admin, $ga_admin);
|
114 |
|
115 |
+
// Update the admin disable setting
|
116 |
+
$ga_admin_disable = $_POST[key_ga_admin_disable];
|
117 |
+
if ( $ga_admin_disable == '' )
|
118 |
+
$ga_admin_disable = ga_admin_disable_default;
|
119 |
+
update_option(key_ga_admin_disable, $ga_admin_disable);
|
120 |
+
|
121 |
// Update the admin level
|
122 |
$ga_admin_level = $_POST[key_ga_admin_level];
|
123 |
if ( $ga_admin_level == '' )
|
284 |
?>.</p>
|
285 |
</td>
|
286 |
</tr>
|
287 |
+
<tr>
|
288 |
+
<th width="30%" valign="top" style="padding-top: 10px;">
|
289 |
+
<label for="<?php echo key_ga_admin_disable ?>">Admin tracking disable method:</label>
|
290 |
+
</th>
|
291 |
+
<td>
|
292 |
+
<?php
|
293 |
+
echo "<select name='".key_ga_admin_disable."' id='".key_ga_admin_disable."'>\n";
|
294 |
+
|
295 |
+
echo "<option value='remove'";
|
296 |
+
if(get_option(key_ga_admin_disable) == 'remove')
|
297 |
+
echo " selected='selected'";
|
298 |
+
echo ">Remove</option>\n";
|
299 |
+
|
300 |
+
echo "<option value='admin'";
|
301 |
+
if(get_option(key_ga_admin_disable) == 'admin')
|
302 |
+
echo" selected='selected'";
|
303 |
+
echo ">Use 'admin' variable</option>\n";
|
304 |
+
|
305 |
+
echo "</select>\n";
|
306 |
+
?>
|
307 |
+
<p style="margin: 5px 10px;" class="setting-description">Selecting the "Remove" option will physically remove the tracking code from logged in admin users. Selecting the "Use 'admin' variable" option will assign a variable called 'admin' to logged in admin users. This option will allow Google Analytics' site overlay feature to work, but you will have to manually configure Google Analytics to exclude tracking from hits with the 'admin' variable.</p>
|
308 |
+
</td>
|
309 |
+
</tr>
|
310 |
<tr>
|
311 |
<th width="30%" valign="top" style="padding-top: 10px;">
|
312 |
<label for="<?php echo key_ga_footer ?>">Footer tracking code:</label>
|
479 |
// If GA is enabled and has a valid key
|
480 |
if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
|
481 |
|
482 |
+
// Display page tracking if user is not an admin
|
483 |
+
if ( ( get_option(key_ga_admin) == ga_enabled || !current_user_can('level_' . get_option(key_ga_admin_level)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' ) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
484 |
|
485 |
+
echo "<!-- Google Analytics Tracking by Google Analyticator: http://plugins.spiralwebconsulting.com/analyticator.html -->\n";
|
486 |
+
// Pick the HTTP connection
|
487 |
+
if ( get_option(key_ga_specify_http) == 'http' ) {
|
488 |
+
echo " <script type=\"text/javascript\" src=\"http://www.google-analytics.com/ga.js\"></script>\n\n";
|
489 |
+
} elseif ( get_option(key_ga_specify_http) == 'https' ) {
|
490 |
+
echo " <script type=\"text/javascript\" src=\"https://ssl.google-analytics.com/ga.js\"></script>\n\n";
|
491 |
+
} else {
|
492 |
+
echo " <script type=\"text/javascript\">\n";
|
493 |
+
echo " var gaJsHost = ((\"https:\" == document.location.protocol) ? \"https://ssl.\" : \"http://www.\");\n";
|
494 |
+
echo " document.write(unescape(\"%3Cscript src='\" + gaJsHost + \"google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E\"));\n";
|
495 |
+
echo " </script>\n\n";
|
496 |
+
}
|
497 |
|
498 |
+
echo " <script type=\"text/javascript\">\n";
|
499 |
+
echo " try {\n";
|
500 |
+
echo " var pageTracker = _gat._getTracker(\"$uid\");\n";
|
501 |
|
502 |
+
// Insert extra before tracker code
|
503 |
+
if ( '' != $extra )
|
504 |
+
echo " " . $extra . "\n";
|
505 |
|
506 |
+
// Initialize the tracker
|
507 |
+
echo " pageTracker._initData();\n";
|
508 |
+
echo " pageTracker._trackPageview();\n";
|
509 |
|
510 |
+
// Disable page tracking if admin is logged in
|
511 |
+
if ( ( get_option(key_ga_admin) == ga_disabled ) && ( current_user_can('level_' . get_option(key_ga_admin_level)) ) )
|
512 |
+
echo " pageTracker._setVar('admin');\n";
|
513 |
|
514 |
+
// Insert extra after tracker code
|
515 |
+
if ( '' != $extra_after )
|
516 |
+
echo " " . $extra_after . "\n";
|
517 |
|
518 |
+
echo " } catch(err) {}</script>\n";
|
|
|
|
|
|
|
|
|
519 |
|
520 |
+
// Include the file types to track
|
521 |
+
$extensions = explode(',', stripslashes(get_option(key_ga_downloads)));
|
522 |
+
foreach ( $extensions AS $extension )
|
523 |
+
$ext .= "'$extension',";
|
524 |
+
$ext = substr($ext, 0, -1);
|
525 |
|
526 |
+
// Include the link tracking prefixes
|
527 |
+
$outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
|
528 |
+
$downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
|
529 |
+
|
530 |
+
?>
|
531 |
+
<script type="text/javascript">
|
532 |
+
var fileTypes = [<?php echo $ext; ?>];
|
533 |
+
var outboundPrefix = '/<?php echo $outbound_prefix; ?>/';
|
534 |
+
var downloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
|
535 |
+
</script>
|
536 |
+
<?php
|
537 |
+
}
|
538 |
}
|
539 |
}
|
540 |
|
549 |
if ( (get_option(key_ga_status) != ga_disabled ) && ( $uid != "XX-XXXXX-X" )) {
|
550 |
// If outbound tracking is enabled
|
551 |
if ( get_option(key_ga_outbound) == ga_enabled ) {
|
552 |
+
// If this is not an admin page
|
553 |
+
if ( !is_admin() ) {
|
554 |
+
// Display page tracking if user is not an admin
|
555 |
+
if ( ( get_option(key_ga_admin) == ga_enabled || !current_user_can('level_' . get_option(key_ga_admin_level)) ) && get_option(key_ga_admin_disable) == 'remove' || get_option(key_ga_admin_disable) != 'remove' ) {
|
556 |
+
add_action('wp_print_scripts', 'ga_external_tracking_js');
|
557 |
+
}
|
558 |
+
}
|
559 |
}
|
560 |
}
|
561 |
}
|
readme.txt
CHANGED
@@ -3,7 +3,7 @@ Contributors: cavemonkey50, spiralwebconsulting
|
|
3 |
Tags: stats, google, analytics, tracking
|
4 |
Requires at least: 2.7
|
5 |
Tested up to: 2.7
|
6 |
-
Stable tag: 3.
|
7 |
|
8 |
Adds the necessary JavaScript code to enable Google Analytics.
|
9 |
|
3 |
Tags: stats, google, analytics, tracking
|
4 |
Requires at least: 2.7
|
5 |
Tested up to: 2.7
|
6 |
+
Stable tag: 3.01
|
7 |
|
8 |
Adds the necessary JavaScript code to enable Google Analytics.
|
9 |
|