Embed Google Analytics code for some environments only

Updated . Posted . Visible to the public.

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:

- if Rails.env.production?
  :javascript
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
    _gaq.push(['_trackPageview']);
    ...
Last edit
Keywords
rails
License
Source code in this card is licensed under the MIT License.
Posted to makandra dev (2011-12-05 12:39)