I tried a bit to add Google Analytics to my Rails 4 application (see this post ).
I have a job adding the JavaScript code that Google supplies to a new file in /public/assets/google-analytics.js. As application.html.erbI turned on:
<%= javascript_include_tag 'google-analytics' if Rails.env.production? %>
This works, but I thus did not include the JavaScript file in app/assets/javascripts/and put it in a shared folder. Therefore, the JavaScript file does not compile.
Could you say this is a good Rails practice / path?
I choose this solution because otherwise I could get it to work if I added Rails.application.config.assets.precompile += ['google-analytics.js']to config / environment / production.rb (it didn't work if I added it to the assets.rb initializer). I find this a bit more messy than the above solution.
Marty source
share