Tag events in Windows 8 C# and Windows Phone 7

When an interesting event occurs in your Windows 8 C# or Windows Phone 7 application, tag it using these instructions.

You may want to collect additional data about some events, such as how many lives a player has or the last action a user took before clicking on an advertisement. Collect this additional data with the second form of tagEvent, which takes a dictionary of key/value pairs, or attributes, along with the event name.
  1. Tag a single event with no attributes by adding the following line of code, where “Options Saved” is a string describing the event.
    appSession.tagEvent("Options Saved");
  2. If you want to add attributes, modify the tag to include a dictionary of key/value pairs.
    Dictionary<String, String> attributes = new Dictionary<string,string>();
    attributes.Add("exception", e.ExceptionObject.Message);
    appSession.tagEvent("App crash", attributes);
  3. Note: Windows Phone 7 only
    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);
    }