Skip to content

Instantly share code, notes, and snippets.

@huobazi
Created November 18, 2014 06:46
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 huobazi/0cb28c2663ef2233583e to your computer and use it in GitHub Desktop.
Save huobazi/0cb28c2663ef2233583e to your computer and use it in GitHub Desktop.
app/assets/javascripts/google_analytics.js.erb:
<% if Rails.env == 'production' %>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXX-XX']);
_gaq.push(['_trackPageview']);
ga_src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
$.externalScript(ga_src).done(function(script, textStatus) {
console.log('Script loading: ' + textStatus );
if (typeof _gat != 'undefined') {
console.log('Okay. GA file loaded.');
}
else
{
console.log('Problem. GA file not loaded.');
}
});
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment