Hi all
In order to add visit tracking to my webgen site, i''ve written a
google analytics plugin which, given a google analytics key,
automatically includes tre required javascripts.
Requirements :
in your page template, put {googleAnalytics: key: your_google_key}
just before your <body> tag.
And that''s all.
The code is the following :
==========================================================class
GoogleAnalyticsTag < Tags::DefaultTag
infos(
:name => ''Custom/GoogleAnalytics'',
:summary => "Allows website tracking thanks to Google Analytics ga.js
code"
)
register_tag ''googleAnalytics''
param ''key'', 1, ''The Google analytics code given
at google
analytics website''
def process_tag(tag, chain)
key = param(''key'')
return <<EOT
<script type="text/javascript">
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">
var pageTracker = _gat._getTracker("#{key}");
pageTracker._initData();
pageTracker._trackPageview();
</script>
EOT
end
end
==========================================================
--
Nicolas Delsaux
N''imprimez ce mail que si vous ne savez pas le lire sur
l''?cran : les
?lectrons se recyclent bien, le papier, beaucoup moins bien.