-
Notifications
You must be signed in to change notification settings - Fork 22k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best way to add google analytics code #209
Comments
@KayLuke sorry that this question got overlooked! If you put it in your If you managed to find a better solution, I'd be interested in knowing what it is! (Closing because it's a question, but feel free to discuss! 😄) |
As of 2015-11-26, here's the code we're using to track page loads & nav link interactions: <script>
//This is Google's default GA code
(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', 'UA-YOURKEY', 'auto');
ga('send', 'pageview');
//This does hash-click tracking (inspired by http://stackoverflow.com/a/4813223)
$(document).ready(function() {
$('.tocify-item a').on('click', function(){
ga('send', 'pageview', {'page': location.pathname + location.search + location.hash});
});
});
</script> Put this in your layout.erb file before the |
@ecaron ^ ooh, this is quite clever, thanks. |
Updated PUT environment
What's the best, most sustainable way to add google analytics functionality without overwriting it with every build or whenever we're merging in the latest code?
We could edit our fork to always add the google analytics code to index.html during the build process, but I wanted to see what others are doing first.
Thanks!
The text was updated successfully, but these errors were encountered: