Skip to content
This repository has been archived by the owner on Dec 23, 2020. It is now read-only.

Commit

Permalink
Move over to using the Universal Analytics snippet
Browse files Browse the repository at this point in the history
Deprecate the old classic GA snippet in favor of using the universal
snippet. The new universal snippet also contains commented out
features such as display features and enhanced link attribution.

The snippet has been tested against a website that pulled in 400
million page views over the course of a month, it also had custom
event tracking implemented.

Snippet provided courtesy of @rmarescu, which originated here:
reed/turbolinks-compatibility#41
  • Loading branch information
nickjj committed Dec 17, 2014
1 parent 967c40b commit e6f7c3b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
1 change: 0 additions & 1 deletion lib/orats/templates/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ def add_layout_partials
gsub_file 'app/views/layouts/_footer.html.erb', 'app_name', app_name

orats_to_local 'app/views/layouts/_google_analytics_snippet.html.erb'
orats_to_local 'app/views/layouts/_google_analytics_tracker.html.erb'

orats_to_local 'app/views/layouts/_disqus_comments_snippet.html.erb'
orats_to_local 'app/views/layouts/_disqus_count_snippet.html.erb'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
<script type="text/javascript">
var _gaq = _gaq || [];
<% if ENV['GOOGLE_ANALYTICS_UA'].present? %>
_gaq.push(['_setAccount', '<%= ENV["GOOGLE_ANALYTICS_UA"] %>']);
(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);
})();
<% end %>
<% if ENV['GOOGLE_ANALYTICS_UA'].present? %>
<script data-turbolinks-eval="false">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', '<%= ENV["GOOGLE_ANALYTICS_UA"] %>', 'auto');
</script>

<script>
// Enable 'Demographics and interest reports' in your analytics settings
// ga('require', 'displayfeatures');

// Enable 'Use enhanced link attribution' in your analytics settings
// ga('require', 'linkid', 'linkid.js');

ga('set', 'location', location.href.split('#')[0]);
ga('send', 'pageview', { 'title': document.title });
</script>
<% end %>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
<script
src="//cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.js"></script>
<![endif]-->
<%= render 'layouts/google_analytics_snippet' %>
</head>

<body>
<%= render 'layouts/google_analytics_tracker' %>
<%= render 'layouts/google_analytics_snippet' %>
<header>
<%= render 'layouts/navigation' %>
</header>
Expand Down

0 comments on commit e6f7c3b

Please sign in to comment.