Skip to content
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

Closed
lc0rp opened this issue Apr 2, 2015 · 3 comments
Closed

Best way to add google analytics code #209

lc0rp opened this issue Apr 2, 2015 · 3 comments
Labels

Comments

@lc0rp
Copy link

lc0rp commented Apr 2, 2015

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!

@lord lord added the question label Jun 20, 2015
@lord
Copy link
Member

lord commented Jun 20, 2015

@KayLuke sorry that this question got overlooked! If you put it in your layout.erb, you should be able to rebase your changes onto any Slate changes without too much trouble, right?

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! 😄)

@lord lord closed this as completed Jun 20, 2015
@ecaron
Copy link
Contributor

ecaron commented Nov 26, 2015

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 </head>

@lord
Copy link
Member

lord commented Nov 30, 2015

@ecaron ^ ooh, this is quite clever, thanks.

mrloop added a commit to questionr/api-docs that referenced this issue Feb 14, 2016
ketan added a commit to ketan/api.go.cd that referenced this issue Oct 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants