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()
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/4794b308c83731fb9024b7c8c74280c7%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment