Created
May 27, 2014 12:55
-
-
Save jameslafa/8504a2a14ece4306c75d to your computer and use it in GitHub Desktop.
Rails 4 - Google analytics with Turbolinks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/assets/javascripts/analytics.js.coffee | |
if window.history?.pushState and window.history.replaceState | |
document.addEventListener 'page:change', (event) => | |
# Google Analytics | |
if window.ga != undefined | |
ga('set', 'location', location.href.split('#')[0]) | |
ga('send', 'pageview') | |
else if window._gaq != undefined | |
_gaq.push(['_trackPageview']) | |
else if window.pageTracker != undefined | |
pageTracker._trackPageview(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- app/views/layouts/application.html.erb --> | |
... | |
<div class="container"> | |
<%= render 'layouts/messages' %> | |
<%= yield %> | |
<footer> | |
<%= render 'layouts/footer' %> | |
</footer> | |
</div> | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍