Google analytics with rails 4

后端 未结 6 1292
后悔当初
后悔当初 2020-12-07 11:39

I am having a bit of difficulty implementing google analytics to my rails 4 project. I included the tracking code to the bottom of my layouts file and have even tried to rem

6条回答
  •  广开言路
    2020-12-07 12:02

    I used this gem and was very easy to set up. No extra .js file creation. Rails 3 helpers to manage google analytics tracking. Mostly intended for small to medium websites.

    Just install the gem:

    gem 'google-analytics-rails', '1.1.0'
    

    Then run:

    bundle install
    

    Finally, this goes @ the production environment configuration:

    Production only config/environments/production.rb:

    # replace this with your tracker code
    GA.tracker = "UA-112233-4"
    

    app/views/layout/application.html.erb, in the tag :

    <%= analytics_init if GoogleAnalytics.valid_tracker? %>
    

    I saw results immediately after pushing to Heroku.

提交回复
热议问题