Integrating Marked Up analytics with Caliburn.Micro

Posted by: Nigel Sampson | 05 April 2013

Marked Up is a fantastic tool for user analytics with Windows 8 apps and with Caliburn Micro really easy to setup. For the sake of this blog post I’m going to assume you already have an app up and running with Caliburn Micro and are looking to integrate Marked Up analytics into your app.

First pull in the MarkedUp client from Nuget, nice and easy! We then need to set up the client in the Configure override of your application in App.xaml.cs.

protected override void Configure()
{
    MarkedUp.AnalyticClient.Initialize("00000000-0000-0000-0000-000000000000");

    container = new WinRTContainer();
    container.RegisterWinRTServices();
}

We then want to hook into the lifecycle methods of the application in App.xaml.cs. In particular we want to override the following methods. Some you will most likely already have implemented.

  1. OnLaunched.
  2. OnSuspending.
  3. OnResuming.
  4. OnUnhandledException
  5. PreviewViewFirst (if you are using a view first approach).

We can then hook the appropriate methods into the Marked Up client. The really useful one if you’re using a view first approach is as you’re registering the navigation service in Caliburn Micro is to register it with the Marked Up client so that all app page navigations are recorded.

protected override void OnLaunched(LaunchActivatedEventArgs args)
{
    MarkedUp.AnalyticClient.AppStart();

    DisplayRootView<MenuView>();
}

protected override void OnSuspending(object sender, SuspendingEventArgs e)
{
    MarkedUp.AnalyticClient.AppSuspend();
}

protected override void OnResuming(object sender, object e)
{
    MarkedUp.AnalyticClient.AppResume();
}

protected override void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
    MarkedUp.AnalyticClient.Error(e.Message, e.Exception);
}

protected override void PrepareViewFirst(Frame rootFrame)
{
    MarkedUp.AnalyticClient.RegisterNavigationFrame(rootFrame);

    container.RegisterNavigationService(rootFrame);
}

And we’re done! Couldn’t get much easier.

Want to get started?

We would love to help with your next app or game, please do get in touch.