Skip to content

Instantly share code, notes, and snippets.

@kwent
Created May 17, 2014 00:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwent/4bee56914faca2c53958 to your computer and use it in GitHub Desktop.
Save kwent/4bee56914faca2c53958 to your computer and use it in GitHub Desktop.
google_analytics_js helper function for Rails
!!!
%html
%head
%title My Website
// METADATA
%meta{:charset => "utf-8"}
%meta{:content => "initial-scale=1.0", :name => "viewport"}
%meta{:content => "yes", :name => "apple-mobile-web-app-capable"}
= csrf_meta_tags
// FONTS
%link{href: "//fonts.googleapis.com/css?family=Open+Sans:400,600,300,700", rel: "stylesheet", type: "text/css"}/
// CSS
= stylesheet_link_tag "application", :media => "all"
// JS
= javascript_include_tag "application"
= google_analytics_js
def google_analytics_js
"<script type='text/javascript'>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-36991364-1']);
_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>".html_safe
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment