Windows Phone Integration Guide
Ten Minute Instrumentation Instructions
- 1) Go to the Localytics Registration Page and create an account if you do not already have one.
- 2) In your account, create a new application and copy the application key.
- 3) Download the Phone7 Client Class. It is distributed as source code. Please contact us if a binary is preferable.
- 4) Add the class to your project.
- 5) Add the Localytics object to the Application class in App.xaml.cs:
public LocalyticsSession appSession;
- 6) In both Application_Launching AND Application_Activated create a new instance of Localytics – then open and upload it. Note that once a session is opened, subsequent calls to open will be ignored. This is will not result in multiple sessions.
appSession = new LocalyticsSession("app key"); appSession.open(); appSession.upload(); - 7) In both Application_closing and Application_Deactivated close the application. You can’t upload here.
appSession.close();
- 8) Add the identify device capability to the WMManifest file by adding this line:
<Capability Name="ID_CAP_IDENTITY_DEVICE"/>
- 9) You can access the session object from other pages using:
((App)Application.Current).appSession.tagEvent("Event Name");TIP: Once data is uploaded it cannot be deleted. Therefore it is recommended to create a test app in Localytics and use that while you perfect your instrumentation and then switch the app key for the production app.
Events (Optional)
10) Add tags. Whenever an event happens in your application which you are interested in recording, add a call to tagEvent:
appSession.tagEvent("Event Name");
When doing this it is best to predefine your events as final static Strings for performance reasons, data actionability, and to avoid collecting any personally identifiable information. It is also highly recommended that you avoid calling this function in a loop to avoid collection of too much data. Please refer to the TAGGING SECTION of the Developer’s Integration Guide for more information.
11) Add Attributes to tags. For some events, it may be interesting to collect additional data about the event. Such as how many lives the player has, or what the last action the user took was before clicking on an advertisement. This is accomplished with the second form of tagEvent, which takes a dictionary of key/value pairs along with the event name:
Dictionary<String, String> attributes = new Dictionary<string,string>();
attributes.Add("exception", e.ExceptionObject.Message);
appSession.tagEvent("App crash", attributes);
See our introductory blog post for more information. It is recommended that you read the Event Attributes section in the Developer’s Integration Guide in order to get the most value out of your attributes.
12) Add code to the Unhandled Exception Filter to log app crashes:
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
Dictionary<String, String> attributes = new Dictionary<string,string>();
attributes.Add("exception", e.ExceptionObject.Message);
appSession.tagEvent("App crash", attributes);
}
Screen Flows (Premium)
Screen flows are not currently available for Phone7 applications.Sample Application Skeleton
To see it all at once, here is the skeleton of an instrumented Phone 7 application:
skeleton.app.cs
public partial class App : Application
{
public LocalyticsSession appSession;
/// <summary>
/// Provides easy access to the root frame of the Phone Application.
/// </summary>
/// <returns>The root frame of the Phone Application.</returns>
public PhoneApplicationFrame RootFrame { get; private set; }
public App()
{
}
private void Application_Launching(object sender, LaunchingEventArgs e)
{
appSession = new LocalyticsSession("511a40c50cec4748efde88f-6556cfb0-d982-11de-ae9c-00412a747c4c");
appSession.open();
appSession.upload();
}
private void Application_Activated(object sender, ActivatedEventArgs e)
{
appSession = new LocalyticsSession("511a40c50cec4748efde88f-6556cfb0-d982-11de-ae9c-00412a747c4c");
appSession.open();
appSession.upload();
}
private void Application_Deactivated(object sender, DeactivatedEventArgs e)
{
appSession.close();
}
private void Application_Closing(object sender, ClosingEventArgs e)
{
appSession.close();
}
private void RootFrame_NavigationFailed(object sender, NavigationFailedEventArgs e)
{
}
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
Dictionary<String, String> attributes = new Dictionary<string,string>();
attributes.Add("exception", e.ExceptionObject.Message);
appSession.tagEvent("App crash", attributes);
}
}