Posted over 7 years ago. Visible to the public.

Embed Google Analytics code for some environments only

When you use google analytics to track your visitors interactions, you should ensure that it runs on your production site only. Otherwise it will spoil your statistics. To prevent this, test for the right environment and place the JS-code afterwards:

Copy
- if Rails.env.production? :javascript var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']); _gaq.push(['_trackPageview']); ...
Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Avatar
Alexander Maiburg
Last edit:
about 7 years ago
Keywords:
rails
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Alexander Maiburg to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more