Skip to content

Commit

Permalink
Item1159: recode using template overlay and place at end of document …
Browse files Browse the repository at this point in the history
…(very important for perceived speed)

git-svn-id: http://svn.foswiki.org/trunk/GoogleAnalyticsPlugin@2755 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
WillNorris authored and WillNorris committed Feb 27, 2009
1 parent f7bce54 commit 6851463
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
13 changes: 8 additions & 5 deletions data/System/GoogleAnalyticsPlugin.txt
Expand Up @@ -21,8 +21,14 @@ Google presents visitor data in a visually rich dashboard: %BR%
---++ Settings

* Google provides its users with a piece of html to copy-paste into pages. You only need one piece of it, the value of =_uacct=:
* Set this value in [[%SYSTEMWEB%.SitePreferences]]
* Set GOOGLESITEKEY =

* Add to your SKIN or COVER setting
* Set SKIN = googleanalytics,pattern
* Set SKIN = googleanalytics,widgets
* Set SKIN = googleanalytics,nat

* One line description, is shown in the %SYSTEMWEB%.TextFormattingRules topic:
* Set SHORTDESCRIPTION = Adds Google Analytics !JavaScript code to all pages

Expand All @@ -31,14 +37,11 @@ Google presents visitor data in a visually rich dashboard: %BR%
__Note:__ You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the Foswiki server.

* Download the ZIP file from the Plugin web (see below)
* Unzip ==%TOPIC%.zip== in your root ($FOSWIKI_ROOT) directory. Content:
| *File:* | *Description:* |
| ==data/System/GoogleAnalyticsPlugin.txt== | |

* Unzip ==%TOPIC%.zip== in your root ($FOSWIKI_ROOT) directory.
* Optionally, if it exists, run ==%TOPIC%_installer== to automatically check and install other Foswiki modules that this module depends on. You can also do this step manually.
* Alternatively, manually make sure the dependencies listed in the table below are resolved.
None
* (Dakar) Visit =configure= in your Foswiki installation, and enable the plugin in the {Plugins} section.
* Visit =configure= in your Foswiki installation, and enable the plugin in the {Plugins} section.

---++ Plugin Info

Expand Down
28 changes: 2 additions & 26 deletions lib/Foswiki/Plugins/GoogleAnalyticsPlugin.pm
Expand Up @@ -14,41 +14,17 @@ $VERSION = '$Rev$';
# of the version number in PLUGINDESCRIPTIONS.
$RELEASE = 'Dakar';

our $NO_PREFS_IN_TOPIC = 1;

$pluginName = 'GoogleAnalyticsPlugin';

################################################################################

sub initPlugin {
my( $topic, $web, $user, $installWeb ) = @_;

$debug = Foswiki::Func::getPluginPreferencesFlag( "DEBUG" );
# Get plugin preferences, variables defined by:
# * Set GOOGLESITEKEY = ...
$googleSiteKey = Foswiki::Func::getPluginPreferencesValue( "GOOGLESITEKEY" );

_addToHead();
return 1;
}

################################################################################

sub _addToHead {
my $header = q|<!-- Google Analytics script -->
<script type="text/javascript">
// <![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("|.$googleSiteKey.q|");
pageTracker._trackPageview();
} catch(err) {}
// ]]>
</script>|;

Foswiki::Func::addToHEAD('GOOGLEANALYTICSPLUGIN',$header)
}

################################################################################
1;
22 changes: 22 additions & 0 deletions templates/foswiki.googleanalytics.tmpl
@@ -0,0 +1,22 @@
%{ This is a Google Analytics template }%%TMPL:INCLUDE{"foswiki"}%

%TMPL:DEF{"googleanalytics"}%\
<!-- GOOGLEANALYTICSPLUGIN --> <!-- Google Analytics script -->
<script type="text/javascript">
// <![CDATA[
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("%GOOGLESITEKEY%");
pageTracker._trackPageview();
} catch(err) {}
// ]]>
</script> %TMPL:END%

%TMPL:DEF{"bodyend"}%
</div><!--/foswikiPage-->
xxx
%TMPL:P{"googleanalytics"}%
</body></html> %TMPL:END%

0 comments on commit 6851463

Please sign in to comment.