Skip to content

Instantly share code, notes, and snippets.

@xwmx
Created March 13, 2011 03:51
Show Gist options
  • Save xwmx/867847 to your computer and use it in GitHub Desktop.
Save xwmx/867847 to your computer and use it in GitHub Desktop.
module GoogleAnalyticsHelper
def google_analytics_for(account, domain)
unless account.blank?
<<-ANALYTICS
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '#{account}']);
_gaq.push(['_setDomainName', '#{domain}']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script');
ga.src = ('https:' == document.location.protocol ? 'https://ssl' :
'http://www') + '.google-analytics.com/ga.js';
ga.setAttribute('async', 'true');
document.documentElement.firstChild.appendChild(ga);
})();
</script>
ANALYTICS
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment