Skip to content

Instantly share code, notes, and snippets.

@fahim
Created January 5, 2012 16:04
Show Gist options
  • Save fahim/1565874 to your computer and use it in GitHub Desktop.
Save fahim/1565874 to your computer and use it in GitHub Desktop.
_google_analytics.html.erb
<% if Rails.env.production? %>
<script type="text/javascript">
/*
Doc for special functions & to record custom variables
http://code.google.com/apis/analytics/docs/gaJS/gaJSApiBasicConfiguration.html#_gat.GA_Tracker_._setCustomVar
*/
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24979565-1']);
_gaq.push(['_setDomainName', '.chloeandisabel.com']);
<% if current_user %>
_gaq.push(['_setCustomVar', 1, 'User Type', '<%= user_type %>', 2]);
<% end %>
_gaq.push(['_setCustomVar', 2, 'App Type', '<%= @app_type %>', 3]);
<% if defined?(@view_logged) %>
_gaq.push(['_setCustomVar', 3, 'View Logged', 'Yes', 3]);
<% end %>
_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>
<%= content_for(:google_analytics) %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment