Google analytics helper - aadlani/nanoc-toolbox GitHub Wiki
Helper that generates the JS code snippet used to track your site with analytics.
http://rubydoc.info/github/aadlani/nanoc-toolbox/Nanoc/Toolbox/Helpers/GoogleAnalytics
In the folder lib/helpers_.rb
add the Helper inclusion as following:
# Helpers of the nanoc-toolbox
include Nanoc::Toolbox::Helpers::GoogleAnalytics
To add the Google Analytics Tracking Code to your layout, simply add the following helper call, with you tracking code as parameter:
<%= ga_tracking_snippet("UA-XXXXXXX-X") %>
If you prefere to centralize your configuration, you could call the helper method without parameter and specify the key ga_tracking_code
in the config file
<%= ga_tracking_snippet %>
ga_tracking_code: UA-XXXXXXX-X
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-X']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>