Skip to content

Instantly share code, notes, and snippets.

@pke
Created May 23, 2013 12:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pke/5635602 to your computer and use it in GitHub Desktop.
Save pke/5635602 to your computer and use it in GitHub Desktop.
sample usage of google.analytics framework for Windows Modern UI apps
ApplicationView = Windows.UI.ViewManagement.ApplicationView
ApplicationViewState = Windows.UI.ViewManagement.ApplicationViewState
google.analytics.configure("UA-YOURID", someUniqueDeviceToken, "Your APP NAME", "YOUR APP VERSION")
###
EVENT LISTENERS FOR ANALYTICS REPORTING
###
#---------------------
# RESIZING / SNAPPING
#---------------------
resizeTimeoutPromise = null # to avoid quick firing when cycling through modes
window.addEventListener "resize", () ->
resizeTimeoutPromise?.cancel()
resizeTimeoutPromise = WinJS.Promise.timeout(2000)
resizeTimeoutPromise.then () ->
resizeTimeoutPromise = null
description = switch (ApplicationView.value)
when ApplicationViewState.fullScreenLandscape, ApplicationViewState.fullScreenPortrait then "fullscreen"
when ApplicationViewState.filled then "filled"
when ApplicationViewState.snapped then "snapped"
google.analytics.trackEvent("app", "resize", description)
return
#------------
# NAVIGATION
#------------
WinJS.Navigation.addEventListener "navigated", (event) ->
contentDescription = event.detail.location
google.analytics.trackAppView(contentDescription)
#-----------------------
# APPLICATION LIFECYCLE
#-----------------------
Windows.UI.WebUI.WebUIApplication.addEventListener "resuming", google.analytics.startSession
WinJS.Application.addEventListener "activated", google.analytics.startSession
Windows.UI.WebUI.WebUIApplication.addEventListener "suspending", (event) ->
deferral = event.suspendingOperation.getDeferral()
google.analytics.endSessionAsync().done () ->
deferral.complete()
, () ->
deferral.complete()
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment