Created
May 23, 2013 12:03
-
-
Save pke/5635602 to your computer and use it in GitHub Desktop.
sample usage of google.analytics framework for Windows Modern UI apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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