Google Analyticator - Version 4.3

Version Description

Download this release

Release Info

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

Code changes from version 4.2.3 to 4.3

external-tracking.js CHANGED
@@ -10,21 +10,33 @@ jQuery(document).ready(function() {
10
11
var url = href.replace('http://','').replace('https://','');
12
var hrefArray = href.split('.').reverse();
13
- var extension = hrefArray[0];
14
-
15
- // If the link is external
16
- if ( ( href.match(/^http/) ) && ( !href.match(document.domain) ) ) {
17
- // Add the tracking code
18
- a.click(function() {
19
- pageTracker._trackPageview(outboundPrefix + url);
20
- });
21
- }
22
23
// If the link is a download
24
- if (jQuery.inArray(extension,fileTypes) != -1) {
25
// Add the tracking code
26
a.click(function() {
27
- pageTracker._trackPageview(downloadsPrefix + url);
28
});
29
}
30
});
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
+ pageTracker._trackEvent("Downloads", extension.toUpperCase(), href);
27
+ } else
28
+ pageTracker._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
+ pageTracker._trackEvent("Outbound Traffic", href.match(/:\/\/(.[^/]+)/)[1], href);
38
+ } else
39
+ pageTracker._trackPageview(analyticsOutboundPrefix + url);
40
});
41
}
42
});
external-tracking.min.js ADDED
@@ -0,0 +1,5 @@
1
+ jQuery(document).ready(function(){jQuery('a').each(function(){var a=jQuery(this);var href=a.attr('href');if(href==undefined)
2
+ return;var url=href.replace('http://','').replace('https://','');var hrefArray=href.split('.').reverse();var extension=hrefArray[0].toLowerCase();var hrefArray=href.split('/').reverse();var domain=hrefArray[2];var downloadTracked=false;if(jQuery.inArray(extension,analyticsFileTypes)!=-1){downloadTracked=true;a.click(function(){if(analyticsEventTracking=='enabled'){pageTracker._trackEvent("Downloads",extension.toUpperCase(),href);}else
3
+ pageTracker._trackPageview(analyticsDownloadsPrefix+url);});}
4
+ if((href.match(/^http/))&&(!href.match(document.domain))&&(downloadTracked==false)){a.click(function(){if(analyticsEventTracking=='enabled'){pageTracker._trackEvent("Outbound Traffic",href.match(/:\/\/(.[^/]+)/)[1],href);}else
5
+ pageTracker._trackPageview(analyticsOutboundPrefix+url);});}});});
google-analyticator.php CHANGED
@@ -1,14 +1,14 @@
1
<?php
2
/*
3
* Plugin Name: Google Analyticator
4
- * Version: 4.2.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
8
* Author URI: http://spiralwebconsulting.com/
9
*/
10
11
- define('GOOGLE_ANALYTICATOR_VERSION', '4.2.3');
12
13
# Include Google Analytics Stats widget
14
if ( function_exists('curl_init') ) {
@@ -35,6 +35,7 @@ define("key_ga_admin_level", "ga_admin_level", true);
35
define("key_ga_adsense", "ga_adsense", true);
36
define("key_ga_extra", "ga_extra", true);
37
define("key_ga_extra_after", "ga_extra_after", true);
38
define("key_ga_outbound", "ga_outbound", true);
39
define("key_ga_outbound_prefix", "ga_outbound_prefix", true);
40
define("key_ga_downloads", "ga_downloads", true);
@@ -50,6 +51,7 @@ define("ga_admin_level_default", 8, true);
50
define("ga_adsense_default", "", true);
51
define("ga_extra_default", "", true);
52
define("ga_extra_after_default", "", true);
53
define("ga_outbound_default", ga_enabled, true);
54
define("ga_outbound_prefix_default", 'outgoing', true);
55
define("ga_downloads_default", "", true);
@@ -66,6 +68,7 @@ add_option(key_ga_admin_level, ga_admin_level_default, 'The level to consider a
66
add_option(key_ga_adsense, ga_adsense_default, '');
67
add_option(key_ga_extra, ga_extra_default, 'Addition Google Analytics tracking options');
68
add_option(key_ga_extra_after, ga_extra_after_default, 'Addition Google Analytics tracking options');
69
add_option(key_ga_outbound, ga_outbound_default, 'Add tracking of outbound links');
70
add_option(key_ga_outbound_prefix, ga_outbound_prefix_default, 'Add tracking of outbound links');
71
add_option(key_ga_downloads, ga_downloads_default, 'Download extensions to track with Google Analyticator');
@@ -89,6 +92,7 @@ function ga_admin_init() {
89
register_setting('google-analyticator', key_ga_adsense, '');
90
register_setting('google-analyticator', key_ga_extra, '');
91
register_setting('google-analyticator', key_ga_extra_after, '');
92
register_setting('google-analyticator', key_ga_outbound, '');
93
register_setting('google-analyticator', key_ga_outbound_prefix, '');
94
register_setting('google-analyticator', key_ga_downloads, '');
@@ -107,6 +111,15 @@ function add_ga_option_page() {
107
add_options_page('Google Analyticator Settings', 'Google Analytics', 8, basename(__FILE__), 'ga_options_page');
108
}
109
110
function ga_options_page() {
111
// If we are a postback, store the options
112
if (isset($_POST['info_update'])) {
@@ -153,6 +166,12 @@ function ga_options_page() {
153
// Update the adsense key
154
$ga_adsense = $_POST[key_ga_adsense];
155
update_option(key_ga_adsense, $ga_adsense);
156
157
// Update the outbound tracking
158
$ga_outbound = $_POST[key_ga_outbound];
@@ -266,7 +285,7 @@ function ga_options_page() {
266
</th>
267
<td>
268
<input type="text" size="40" name="google_stats_user" id="google_stats_user" value="<?php echo stripslashes(get_option('google_stats_user')); ?>" />
269
- <br /><span class="setting-description">Your Google Analytics account's username. This is needed to authenticate with Google for use with the stats widget.</span>
270
</td>
271
</tr>
272
<tr valign="top">
@@ -275,7 +294,7 @@ function ga_options_page() {
275
</th>
276
<td>
277
<input type="password" size="40" name="google_stats_password" id="google_stats_password" value="<?php echo stripslashes(get_option('google_stats_password')); ?>" />
278
- <br /><span class="setting-description">Your Google Analytics account's password. This is needed to authenticate with Google for use with the stats widget.</span>
279
</td>
280
</tr>
281
<?php } ?>
@@ -400,17 +419,26 @@ function ga_options_page() {
400
</td>
401
</tr>
402
<tr>
403
- <th valign="top" style="padding-top: 10px;">
404
- <label for="<?php echo key_ga_outbound_prefix; ?>">Prefix external links with:</label>
405
</th>
406
<td>
407
<?php
408
- echo "<input type='text' size='50' ";
409
- echo "name='".key_ga_outbound_prefix."' ";
410
- echo "id='".key_ga_outbound_prefix."' ";
411
- echo "value='".stripslashes(get_option(key_ga_outbound_prefix))."' />\n";
412
?>
413
- <p style="margin: 5px 10px;" class="setting-description">Enter a name for the section tracked external links will appear under.</em></p>
414
</td>
415
</tr>
416
<tr>
@@ -427,6 +455,20 @@ function ga_options_page() {
427
<p style="margin: 5px 10px;" class="setting-description">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></p>
428
</td>
429
</tr>
430
<tr>
431
<th valign="top" style="padding-top: 10px;">
432
<label for="<?php echo key_ga_downloads_prefix; ?>">Prefix download links with:</label>
@@ -438,7 +480,7 @@ function ga_options_page() {
438
echo "id='".key_ga_download_sprefix."' ";
439
echo "value='".stripslashes(get_option(key_ga_downloads_prefix))."' />\n";
440
?>
441
- <p style="margin: 5px 10px;" class="setting-description">Enter a name for the section tracked download links will appear under.</em></p>
442
</td>
443
</tr>
444
<tr>
@@ -614,12 +656,14 @@ function add_google_analytics() {
614
// Include the link tracking prefixes
615
$outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
616
$downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
617
618
?>
619
<script type="text/javascript">
620
- var fileTypes = [<?php echo $ext; ?>];
621
- var outboundPrefix = '/<?php echo $outbound_prefix; ?>/';
622
- var downloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
623
</script>
624
<?php
625
}
@@ -628,8 +672,6 @@ function add_google_analytics() {
628
629
/**
630
* Adds outbound link tracking to Google Analyticator
631
- *
632
- * @author Ronald Heft
633
**/
634
function ga_outgoing_links()
635
{
@@ -650,13 +692,11 @@ function ga_outgoing_links()
650
651
/**
652
* Adds the scripts required for outbound link tracking
653
- *
654
- * @author Ronald Heft
655
**/
656
function ga_external_tracking_js()
657
{
658
- wp_enqueue_script('jquery');
659
- wp_enqueue_script('ga-external-tracking', plugins_url('/google-analyticator/external-tracking.js'));
660
}
661
662
?>
1
<?php
2
/*
3
* Plugin Name: Google Analyticator
4
+ * Version: 4.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
8
* Author URI: http://spiralwebconsulting.com/
9
*/
10
11
+ define('GOOGLE_ANALYTICATOR_VERSION', '4.3');
12
13
# Include Google Analytics Stats widget
14
if ( function_exists('curl_init') ) {
35
define("key_ga_adsense", "ga_adsense", true);
36
define("key_ga_extra", "ga_extra", true);
37
define("key_ga_extra_after", "ga_extra_after", true);
38
+ define("key_ga_event", "ga_event", true);
39
define("key_ga_outbound", "ga_outbound", true);
40
define("key_ga_outbound_prefix", "ga_outbound_prefix", true);
41
define("key_ga_downloads", "ga_downloads", true);
51
define("ga_adsense_default", "", true);
52
define("ga_extra_default", "", true);
53
define("ga_extra_after_default", "", true);
54
+ define("ga_event_default", ga_enable, true);
55
define("ga_outbound_default", ga_enabled, true);
56
define("ga_outbound_prefix_default", 'outgoing', true);
57
define("ga_downloads_default", "", true);
68
add_option(key_ga_adsense, ga_adsense_default, '');
69
add_option(key_ga_extra, ga_extra_default, 'Addition Google Analytics tracking options');
70
add_option(key_ga_extra_after, ga_extra_after_default, 'Addition Google Analytics tracking options');
71
+ add_option(key_ga_event, ga_event_default, '');
72
add_option(key_ga_outbound, ga_outbound_default, 'Add tracking of outbound links');
73
add_option(key_ga_outbound_prefix, ga_outbound_prefix_default, 'Add tracking of outbound links');
74
add_option(key_ga_downloads, ga_downloads_default, 'Download extensions to track with Google Analyticator');
92
register_setting('google-analyticator', key_ga_adsense, '');
93
register_setting('google-analyticator', key_ga_extra, '');
94
register_setting('google-analyticator', key_ga_extra_after, '');
95
+ register_setting('google-analyticator', key_ga_event, '');
96
register_setting('google-analyticator', key_ga_outbound, '');
97
register_setting('google-analyticator', key_ga_outbound_prefix, '');
98
register_setting('google-analyticator', key_ga_downloads, '');
111
add_options_page('Google Analyticator Settings', 'Google Analytics', 8, basename(__FILE__), 'ga_options_page');
112
}
113
114
+ add_action('plugin_action_links_' . plugin_basename(__FILE__), 'ga_filter_plugin_actions');
115
+
116
+ // Adds FAQ and changelog options
117
+ function ga_filter_plugin_actions($links) {
118
+ $links[] = '<a href="http://plugins.spiralwebconsulting.com/forums/viewforum.php?f=5">FAQ</a>';
119
+
120
+ return $links;
121
+ }
122
+
123
function ga_options_page() {
124
// If we are a postback, store the options
125
if (isset($_POST['info_update'])) {
166
// Update the adsense key
167
$ga_adsense = $_POST[key_ga_adsense];
168
update_option(key_ga_adsense, $ga_adsense);
169
+
170
+ // Update the event tracking
171
+ $ga_event = $_POST[key_ga_event];
172
+ if (($ga_event != ga_enabled) && ($ga_event != ga_disabled))
173
+ $ga_event = ga_event_default;
174
+ update_option(key_ga_event, $ga_event);
175
176
// Update the outbound tracking
177
$ga_outbound = $_POST[key_ga_outbound];
285
</th>
286
<td>
287
<input type="text" size="40" name="google_stats_user" id="google_stats_user" value="<?php echo stripslashes(get_option('google_stats_user')); ?>" />
288
+ <p style="margin: 5px 10px;" class="setting-description">Your Google Analytics account's username. This is needed to authenticate with Google for use with the stats widget.</p>
289
</td>
290
</tr>
291
<tr valign="top">
294
</th>
295
<td>
296
<input type="password" size="40" name="google_stats_password" id="google_stats_password" value="<?php echo stripslashes(get_option('google_stats_password')); ?>" />
297
+ <p style="margin: 5px 10px;" class="setting-description">Your Google Analytics account's password. This is needed to authenticate with Google for use with the stats widget.</p>
298
</td>
299
</tr>
300
<?php } ?>
419
</td>
420
</tr>
421
<tr>
422
+ <th width="30%" valign="top" style="padding-top: 10px;">
423
+ <label for="<?php echo key_ga_event ?>">Event tracking:</label>
424
</th>
425
<td>
426
<?php
427
+ echo "<select name='".key_ga_event."' id='".key_ga_event."'>\n";
428
+
429
+ echo "<option value='".ga_enabled."'";
430
+ if(get_option(key_ga_event) == ga_enabled)
431
+ echo " selected='selected'";
432
+ echo ">Enabled</option>\n";
433
+
434
+ echo "<option value='".ga_disabled."'";
435
+ if(get_option(key_ga_event) == ga_disabled)
436
+ echo" selected='selected'";
437
+ echo ">Disabled</option>\n";
438
+
439
+ echo "</select>\n";
440
?>
441
+ <p style="margin: 5px 10px;" class="setting-description">Enabling this option will treat outbound links and downloads as events instead of pageviews. Since the introduction of <a href="http://code.google.com/apis/analytics/docs/tracking/eventTrackerOverview.html">event tracking in Analytics</a>, this is the recommended way to track these types of actions. Only disable this option if you must use the old pageview tracking method.</p>
442
</td>
443
</tr>
444
<tr>
455
<p style="margin: 5px 10px;" class="setting-description">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></p>
456
</td>
457
</tr>
458
+ <tr>
459
+ <th valign="top" style="padding-top: 10px;">
460
+ <label for="<?php echo key_ga_outbound_prefix; ?>">Prefix external links with:</label>
461
+ </th>
462
+ <td>
463
+ <?php
464
+ echo "<input type='text' size='50' ";
465
+ echo "name='".key_ga_outbound_prefix."' ";
466
+ echo "id='".key_ga_outbound_prefix."' ";
467
+ echo "value='".stripslashes(get_option(key_ga_outbound_prefix))."' />\n";
468
+ ?>
469
+ <p style="margin: 5px 10px;" class="setting-description">Enter a name for the section tracked external links will appear under. This option has no effect if event tracking is enabled.</em></p>
470
+ </td>
471
+ </tr>
472
<tr>
473
<th valign="top" style="padding-top: 10px;">
474
<label for="<?php echo key_ga_downloads_prefix; ?>">Prefix download links with:</label>
480
echo "id='".key_ga_download_sprefix."' ";
481
echo "value='".stripslashes(get_option(key_ga_downloads_prefix))."' />\n";
482
?>
483
+ <p style="margin: 5px 10px;" class="setting-description">Enter a name for the section tracked download links will appear under. This option has no effect if event tracking is enabled.</em></p>
484
</td>
485
</tr>
486
<tr>
656
// Include the link tracking prefixes
657
$outbound_prefix = stripslashes(get_option(key_ga_outbound_prefix));
658
$downloads_prefix = stripslashes(get_option(key_ga_downloads_prefix));
659
+ $event_tracking = get_option(key_ga_event);
660
661
?>
662
<script type="text/javascript">
663
+ var analyticsFileTypes = [<?php echo strtolower($ext); ?>];
664
+ var analyticsOutboundPrefix = '/<?php echo $outbound_prefix; ?>/';
665
+ var analyticsDownloadsPrefix = '/<?php echo $downloads_prefix; ?>/';
666
+ var analyticsEventTracking = '<?php echo $event_tracking; ?>';
667
</script>
668
<?php
669
}
672
673
/**
674
* Adds outbound link tracking to Google Analyticator
675
**/
676
function ga_outgoing_links()
677
{
692
693
/**
694
* Adds the scripts required for outbound link tracking
695
**/
696
function ga_external_tracking_js()
697
{
698
+ // wp_enqueue_script('jquery');
699
+ wp_enqueue_script('ga-external-tracking', plugins_url('/google-analyticator/external-tracking.min.js'), array('jquery'), GOOGLE_ANALYTICATOR_VERSION);
700
}
701
702
?>
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: cavemonkey50, spiralwebconsulting
3
Tags: stats, google, analytics, tracking
4
Requires at least: 2.7
5
Tested up to: 2.8
6
- Stable tag: 4.2.3
7
8
Adds the necessary JavaScript code to enable Google Analytics.
9
@@ -11,16 +11,19 @@ Adds the necessary JavaScript code to enable Google Analytics.
11
12
Google Analyticator adds the necessary JavaScript code to enable Google Analytics logging on any WordPress blog. This eliminates the need to edit your template code to begin logging.
13
14
*Google Analyticator is brought to you for free by [Spiral Web Consulting](http://spiralwebconsulting.com/). Spiral Web Consulting is a small web development firm specializing in PHP development. Visit our website to learn more, and don't hesitate to ask us to develop your next big WordPress plugin idea.*
15
16
= Features =
17
18
Google Analyticator Has the Following Features:
19
20
- - **NEW:** Google Analytics API support. Includes a stats widget showing yesterday's visitors. More stats to come!
21
- Standard Google Analytics tracking support
22
- External link tracking of all links on the page, including links not managed by WordPress
23
- Download link tracking
24
- Support for hiding Administrator visits without effecting Google Analytics' site overlay feature
25
- Support for any advanced tracking code Google provides
26
- Easily installable only requiring the user knows their UID
3
Tags: stats, google, analytics, tracking
4
Requires at least: 2.7
5
Tested up to: 2.8
6
+ Stable tag: 4.3
7
8
Adds the necessary JavaScript code to enable Google Analytics.
9
11
12
Google Analyticator adds the necessary JavaScript code to enable Google Analytics logging on any WordPress blog. This eliminates the need to edit your template code to begin logging.
13
14
+ View the [current release notes](http://plugins.spiralwebconsulting.com/analyticator.html#history) on our website.
15
+
16
*Google Analyticator is brought to you for free by [Spiral Web Consulting](http://spiralwebconsulting.com/). Spiral Web Consulting is a small web development firm specializing in PHP development. Visit our website to learn more, and don't hesitate to ask us to develop your next big WordPress plugin idea.*
17
18
= Features =
19
20
Google Analyticator Has the Following Features:
21
22
- Standard Google Analytics tracking support
23
+ - Provides a widget that can be used to display visitor stat information on the front-end
24
- External link tracking of all links on the page, including links not managed by WordPress
25
- Download link tracking
26
+ - **NEW!** Support for event tracking with outbound links / downloads instead of the old pageview tracking method
27
- Support for hiding Administrator visits without effecting Google Analytics' site overlay feature
28
- Support for any advanced tracking code Google provides
29
- Easily installable only requiring the user knows their UID