For Developers / Sample applications |
default.js
// For an introduction to the Blank template, see the following documentation: // http://go.microsoft.com/fwlink/?LinkId=232509 (function () { "use strict"; var app = WinJS.Application; var activation = Windows.ApplicationModel.Activation; WinJS.strictProcessing(); // open and close the session on visibility change events. This causes the session to be resumed if the // user is gone for less than 15 seconds, otherwise a new session is created. var onVisibilityChange = function (args) { var state = document["visibilityState"]; if (state == "visible") { localyticsSession.open(); localyticsSession.upload(); } else if (state == "hidden") { localyticsSession.close(); localyticsSession.upload(); } }; document.addEventListener("visibilitychange", onVisibilityChange, false); app.onactivated = function (args) { if (args.detail.kind === activation.ActivationKind.launch) { if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) { // TODO: This application has been newly launched. Initialize // your application here. } else { // TODO: This application has been reactivated from suspension. // Restore application state here. } args.setPromise(WinJS.UI.processAll()); var sampleButton = document.getElementById("sampleButton"); sampleButton.addEventListener("click", eventButtonHandler, false); // whenever the app is activated, initialize a localytics object. var options = { logger: true, polling: false }; var localyticsSession = LocalyticsSession("871b4e162f27f37fb8db3b0-0dcd0bf8-d040-11e1-4668-00ef75f32667", options); localyticsSession.open(); localyticsSession.upload(); } }; app.oncheckpoint = function (args) { // TODO: This application is about to be suspended. Save any state // that needs to persist across suspensions here. You might use the // WinJS.Application.sessionState object, which is automatically // saved and restored across suspension. If you need to complete an // asynchronous operation before your application is suspended, call // args.setPromise(). }; function eventButtonHandler(eventId) { var sampleInput = document.getElementById("sampleInput").value; localyticsSession.tagEvent("Button pressed", { "User input": sampleInput }); } app.start(); })();
default.html
<title>SampleLocalyticsApp</title> <!-- WinJS references --> <!-- SampleLocalyticsApp references --> <h1>This is a sample Localytics application</h1> <p>Sample input field:</p> <button id="sampleButton">Test Event</button>