Skip to content

Instantly share code, notes, and snippets.

@spaced
Last active May 25, 2016 04:48
Show Gist options
  • Save spaced/34544395414404b8036a to your computer and use it in GitHub Desktop.
Save spaced/34544395414404b8036a to your computer and use it in GitHub Desktop.
Small Scalajs facade for google analytics events
object EventTracker {
def isScriptLoaded=js.Dynamic.global.ga.isInstanceOf[js.Function]
def sendEvent(category:String,action:String,label:String):Unit={
if (isScriptLoaded) GoogleAnalytics.ga("send","event",category,action,label)
}
def sendEvent(category:String,action:String,label:String,value:String):Unit={
if (isScriptLoaded) GoogleAnalytics.ga("send","event",category,action,label,value)
}
}
@js.native
object GoogleAnalytics extends js.GlobalScope {
def ga(send:String,event:String,category:String,action:String,label:String ): Unit = js.native
def ga(send:String,event:String,category:String,action:String,label:String,value:js.Any ): Unit = js.native
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment