Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjschreifels/4705260 to your computer and use it in GitHub Desktop.
Save pjschreifels/4705260 to your computer and use it in GitHub Desktop.
#analytics #coffeescript Google Analytics code in coffeescript for rails projects.
# See http://stackoverflow.com/questions/4214731/coffeescript-global-variables
root = exports ? this
root._gaq = [['_setAccount', 'UA-xxxxxxxx-y'], ['_trackPageview']]
insertGAScript = ->
ga = document.createElement 'script'
ga.type = 'text/javascript'
ga.async = true
proto = document.location.protocol
proto = if (proto is 'https:') then 'https://ssl' else 'http://www'
ga.src = "#{proto}.google-analytics.com/ga.js"
s = document.getElementsByTagName 'script'
s[0].parentNode.insertBefore ga, s
insertGAScript()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment