Skip to content

Instantly share code, notes, and snippets.

@rob-bar
Last active December 26, 2015 23:19
Show Gist options
  • Save rob-bar/7230047 to your computer and use it in GitHub Desktop.
Save rob-bar/7230047 to your computer and use it in GitHub Desktop.
base #coffeescript #jquery
helper =
track_event: (category, label, value) ->
try
# console.log "track: category: #{category} - label: #{label} - value: #{value}"
if label? and value?
_gaq.push ['_trackEvent', category, label, value]
else if label?
_gaq.push ['_trackEvent', category, label]
else
_gaq.push ['_trackEvent', category]
catch err
# console.log "couldn't track event: category: #{category} - label: #{label} - value: #{value}"
track_page: (frag) ->
# console.log "track: page: frag: #{frag}"
_gaq = window._gaq || []
_gaq.push(['_trackPageview', "/#{frag}"])
site =
page: $('body').attr 'data-page'
index: () ->
if typeof site[site.page] is "function"
do site[site.page]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment