Windows 8 JS integration

Integrate your Windows 8 C# app with Localytics.

  1. In your Localytics Dashboard, create a new application and copy the application key.
  2. Download the HTML5 library.
    We distribute the library unminified for readability.
  3. Add the library to the JS folder in your project.
  4. Include the library after default.js by adding the following code to your default.html.
    <script src="/js/localytics.js"></script>
  5. Start a session when the app is launched by adding the following to app.onactivated.

    By default, the HTML5 library polls the app to see if the user is still using it, but on Windows 8 there are robust viewchange events, so this is not necessary.

    var localyticsSession = LocalyticsSession("APP_KEY");
    localyticsSession.open();
    localyticsSession.upload();
  6. Close the session when the app leaves the foreground and open a new one when it returns.
    By default, if the user is gone for less than 15 seconds, the previous session is resumed. This is done by catching the changeview notification.
    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);