November 2, 2010

Windows Phone 7 App Analytics Now Available!

Share

Microsoft Windows Phone 7 is fast approaching, and the Windows Phone Marketplace is open for app submissions on Nov 3. With assistance from Microsoft, we are able to offer the first mobile analytics service for Windows Phone 7 applications. “We’re really excited about Localytics coming to Windows Phone 7″ said Abby Fichtner, Microsoft Developer Evangelist for Startups. “Localytics is a great example of a BizSpark company that was able to really meet the needs of developers worldwide with their real-time mobile analytics software.” In the rest of this post, we take a closer look at the Windows Phone 7 app model and how to instrument and interpret app analytics.

How Windows Phone 7 Apps Work

Windows Phone 7 apps are Silverlight packages distributed through the Windows Marketplace for Mobile. These apps are built within Visual Studio, which is available in a free express package. Visual Studio provides a complete environment that makes the development process very straightforward and quick.

Similar to the pre-iOS4 iPhone, Windows Phone 7 allows only one non-Microsoft app to run at a time. Your app may persist in the background if another app is running, but your app will not be allowed to execute code. Additionally, like other platforms, Windows Phone 7 suspends or terminates apps when certain other events occur, e.g., another app launches, a text message is received, etc. Suspension is handled by ‘tombstoning’, which allows an app to save its pre-termination state and to recover faster if the user returns to it. Microsoft has a good blog post explaining all of this in greater detail.

Measuring App Sessions in WP7

Accurately measuring app sessions can be challenging, especially if you wish to compare sessions across Android, Blackberry, iPhone, etc. The app session model differs across various platforms, but certain best practices can allow you to overcome these differences.

In Windows Phone 7, since an app is terminated when it leaves the foreground, measurement of a session should terminate at that time as well. As the goal is to measure actual engagement time, only the time an app is in the foreground of the OS is relevant. When the user relaunches the app, that should be counted as the start of a new session. (For more on accurately measuring app sessions, see our previous post on iPhone analytics with Apple iOS4.)

Writing the Code

One very nice feature of the Windows Phone 7 platform is the global application object. All apps implement App.xaml.cs, which defines a global application object that can be accessed by any page inside a running app. This object also receives callbacks when the app is launched, activated, deactivated or closed.

Similar to Android’s activity model, each screen in a Windows Phone 7 app is a new page which stacks on top of the previous page; a back button pops pages off the top of the stack in order to access previous pages.

Putting the LocalyticsSession object in the global application object makes it easy to both capture the session information and for any page to access the global application object to tag events.

Here is some sample code with further explanations:

// The only file that needs to change is App.xaml.cs
namespace Sample_App {
    public partial class App : Application
    {
         public LocalyticsSession appSession; // The object which maintains the Localytics Session.

         // Called when the application is first launched.
         // Open the session and upload it here. This also uploads any left over bits from the previous sessions.
         private void Application_Launching(object sender, LaunchingEventArgs e)
         {
             appSession = new LocalyticsSession("511a40c50cec4748efde88f-6556cfb0-d982-11de-ae9c-00412a747c4c");
             appSession.open();
             appSession.upload();
         }

         // Called if the application comes back from being deactivated.
         // The app is coming back from a terminated state so we treat this as a new session
         private void Application_Activated(object sender, ActivatedEventArgs e)
         {
             appSession = new LocalyticsSession("511a40c50cec4748efde88f-6556cfb0-d982-11de-ae9c-00412a747c4c");
             appSession.open();
             appSession.upload();
         }

         // The app is being terminated. Close the session. It is not worth it to try and upload
         // because there will not be enough time to complete it.
         private void Application_Deactivated(object sender, DeactivatedEventArgs e)
         {
             appSession.close();
         }

         // Treated the same as a deactivate event.
         private void Application_Closing(object sender, ClosingEventArgs e)
         {
             appSession.close();
         }

         // Bonus, catch any exceptions which occur and report them as an App Crash event.
         private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
         {
             Dictionary attributes = new Dictionary();
             attributes.Add("exception", e.ExceptionObject.Message);
             appSession.tagEvent("App crash", attributes);
        }
    }
}

Note, that to tag events inside your application, you can refer to the session object by doing:

((App)Application.Current).appSession.tagEvent("event_name");
Please share your thoughts on developing for Windows Phone 7 and the best practices for mobile app analytics.

More information about Localytics’ support for Windows Phone 7 and our Enterprise analytics services is available on our website.

Share this
Share
  • Mikel Gorbacep

    vimax dimana saya bisa mendapatkan window 7 anlityc ??