Google analytics integration

I want to track all the data and user interactions through google
analytics for my entire website which is built with rails.

I added a script that I found online that looks like it works but I dont
know how to certainly validate that. In my google analytics dashboard
it shows visitors coming to my page but never leaving the index page. I
think its only tracking that page and no others because I went on my
page the other day and clicked through some of my other pages just to
test the analytics out.

does any one have a resource on how to implement this correctly?

Below is the script file I have in assets/javascript

class @GoogleAnalytics

@load: ->
# Google Analytics depends on a global _gaq array. window is the
global scope.
window._gaq = []
window._gaq.push ["_setAccount", GoogleAnalytics.analyticsId()]

# Create a script element and insert it in the DOM
ga = document.createElement("script")
ga.type = "text/javascript"
ga.async = true
ga.src = ((if "https:" is document.location.protocol then

https://ssl” else “http://www”)) + “.google-analytics.com/ga.js”
firstScript = document.getElementsByTagName(“script”)[0]
firstScript.parentNode.insertBefore ga, firstScript

# 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()

@trackPageview: (url) ->
unless GoogleAnalytics.isLocalRequest()
if url
window._gaq.push ["_trackPageview", url]
else
window._gaq.push ["_trackPageview"]
window._gaq.push ["_trackPageLoadTime"]

@isLocalRequest: ->
GoogleAnalytics.documentDomainIncludes “local”

@documentDomainIncludes: (str) ->
document.domain.indexOf(str) isnt -1

@analyticsId: ->
# your google analytics ID(s) here…
‘MY_GOOGLE_ANALYTICS_ID’

GoogleAnalytics.load()

On Tue, Jan 5, 2016 at 4:29 AM, Travis E. [email protected]
wrote:

I want to track all the data and user interactions through google
analytics for my entire website which is built with rails.

does any one have a resource on how to implement this correctly?

Caveat: I didn’t bother to read all your JS - I just put the analytics
JS snippet in a partial and include it in the footer of my layout.

FWIW,

Hassan S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

There is a gem to add google analytics. Check google-analytics-rails.
May be a little old but old and new GA works almost in the same way.