Google analytics with rails 4

后端 未结 6 1287
后悔当初
后悔当初 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 11:57

    I removed Turbolinks, and used the RailsProjects script, provided here:

    http://railsapps.github.io/rails-google-analytics.html

    Worked for me no problems. It detected it, and after a little while I could see the real time users so I know it is working.

    Edit: The script appears to support Turbolinks on or off which is great.

    # If Turbolinks is supported, set up a callback to track pageviews on page:change.
        # If it isn't supported, just track the pageview now.
        if typeof Turbolinks isnt 'undefined' and Turbolinks.supported
          document.addEventListener "page:change", (->
            GoogleAnalytics.trackPageview()
          ), true
        else
          GoogleAnalytics.trackPageview()
    

提交回复
热议问题