GithubHelp home page GithubHelp logo

localytics-win8's Introduction

A Windows 8 port of the Localytics instrumentation classes

Localytics does not currently provide an instrumentation library specifically for Windows 8, instead directing developers to use the HTML5 library. Unfortunately, the HTML5 library is not usable by non-HTML5 applications. This project is a port of the Windows Phone 7 instrumentation library that works in Windows 8 .NET Metro applications. It may also work in .NET Desktop applications compiled with WinRT support.

How to instrument your Windows 8 app

Setup

Instrumenting a Windows 8 app is almost identical to instrumenting a WP7 app, but the names of some methods have changed. Put these lines:

appSession = new LocalyticsSession("app key");
await appSession.Open();
appSession.Upload();

at the beginning of OnLaunched(). Yes, before you check to see if you're were already running. So it should look something like this:

protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
  appSession = new LocalyticsSession("app key");
  await appSession.Open();
  appSession.Upload();
  
  // Do not repeat app initialization when already running, just ensure that
  // the window is active
  if (args.PreviousExecutionState == ApplicationExecutionState.Running)
  {
    Window.Current.Activate();
    return;
  }
...

You'll also want to put that at the beginning of OnActivated(), if your app offers any other methods of activation (e.g. search contract, file picker).

Make sure to add a handler to the Suspending event (this has already been done on layout-aware pages as OnSuspending). You'll need to request a deferral of suspension, as well. That is to say, your OnSuspending should look like this:

private async void OnSuspending(object sender, SuspendingEventArgs e)
{
  var deferral = e.SuspendingOperation.GetDeferral();
  await appSession.Close();
  /* other suspension code */
  deferral.Complete();
}

Tagging events (optional)

To tag an event, use the following line of code:

((App)Application.Current).appSession.TagEvent("Event Name");

You can attach attributes to an event by passing a Dictionary<string, string> as a second argument to TagEvent(). For example, to collect information about unhandled exceptions, you could use the following code:

private void OnUnhandledException(object sender, UnhandledExceptionEventArgs unhandledExceptionEventArgs)
{
  if (appSession == null)
  {
    return;
  }
  var dict = new Dictionary<string, string>();
  dict.Add("Message",unhandledExceptionEventArgs.Message);
  dict.Add("Stack trace", unhandledExceptionEventArgs.Exception.StackTrace);
  ((App)Application.Current).appSession.TagEvent("Unhandled exception", dict);
  await appSession.Close();
}

Notes

  • Screen flows are not currently supported. The WP7 library lacks screen flow support, and this was a straight port. Feel free to port it over from the Android library. I may do this myself, but no promises.
  • There's no way that I can find for a Metro app to get the OS version or device information. I ended up reporting the OS version as whatever the compiled architecture target was (i.e. x86, x64, or ARM). Depending on how your code is compiled, this may report "Neutral". Additionally, it does not report the device manufacturer and claims a device model of "Computer".
  • The device UUID is a hash based on the HardwareIdentification.GetPackageSpecificToken() method and therefore may change if the hardware changes. More information is available from Microsoft.
  • The library version currently reports "windowsphone_2.2". This isn't reported to the user, instead being used by Localytics for some internal purposes, but I figured it was worth noting. I haven't had a chance to test out whether "windows8_2.0" works.
  • The code could be better in some places. I may do some cleanup later.

localytics-win8's People

Contributors

elyscape avatar

Stargazers

Suneet Shah avatar

Watchers

Suneet Shah avatar  avatar James Cloos avatar Randy Dailey avatar  avatar  avatar

Forkers

suneets

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.