Windows 8 C# Integration Guide
Ten Minute Instrumentation Instructions
- 1) Log into your Localytics account or 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 Windows 8 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) 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.
Screen Flows (Premium)
Screen flows are coming soon!
Sample Application Skeleton
To see it all at once, here is the skeleton of an instrumented Windows 8 application:
skeleton.app.cs
public App()
{
this.InitializeComponent();
this.Suspending += new SuspendingEventHandler(OnSuspending);
this.Resuming += new EventHandler<Object>(OnResuming);
}
async void OnSuspending(object sender, SuspendingEventArgs args)
{
SuspendingDeferral deferral = args.SuspendingOperation.GetDeferral();
await SuspensionManager.SaveAsync();
appSession.Close();
appSession.Upload();
deferral.Complete();
}
void OnResuming(object sender, Object args)
{
appSession.Open();
appSession.Upload();
}
/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used when the application is launched to open a specific file, to display
/// search results, and so forth.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
async protected override void OnLaunched(LaunchActivatedEventArgs args)
{
appSession = new LocalyticsSession("YOUR APP KEY GOES HERE");.
appSession.Open();
appSession.Upload();
this.LaunchArgs = args;
Frame rootFrame = null;
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
// Do an asynchronous restore
await SuspensionManager.RestoreAsync();
}
if (Window.Current.Content == null)
{
rootFrame = new Frame();
rootFrame.Navigate(typeof(MainPage));
//SuspensionManager.RegisterFrame(rootFrame, "appFrame");
Window.Current.Content = rootFrame;
}
Window.Current.Activate();
}
}
Common Mistakes
Ready to ship? Check our list of common integration mistakes to ensure you get the best reporting experience possible.