Visual Studio App Center Analytics is the next generation of Xamarin Insights! Read the blog post.

Tracking Events

PDF for offline use
Related Links:

Let us know how you feel about this

Translation Quality


0/250

In addition to reporting exceptions, Xamarin Insights can also be used to track application events, such as when the user enters a given feature or to track the amount of time required to execute a feature. This information can be useful to see how users are interacting with the application, or if certain features are never being used or are hard to find.

In the following sections we'll look at adding event and time tracking to an application.

Implementing Event Tracking

If there is a feature or function of an application to track an event for in Xamarin Insights, we can use the Insights.Track method to send this information to the service.

If an application played music, for example, the following lines could be used to create a event when a particular song was played:

Insights.Track("MusicTrackPlayed", new Dictionary <string,string>{
    {"Song Name", "Shake It Off"},
    {"Length", "183"}
});

Where "MusicTrackPlayed" is a track event name for the event and the Dictionary provides detailed information about the song being played. Using this method, we can send any type of event to the service.

In the Xamarin.Forms sample, the following code was used to create a Track, and log the time that it occurred:

private void Track ()
{
    numTracks += 1;

    Xamarin.Insights.Track(string.Format("Track {0}", numTracks), new Dictionary <string, string> { 
        {"track-local-time", DateTime.Now.ToString()}
    });
}

These events can then be analyzed in the Events section, and also under the Sessions tab of the User Details Panel, as illustrated below:

Implementing Time Tracking

The amount of time that a given task takes in an application can have a drastic effect on how the end user perceives it. For example, if the application takes a long time to complete a task, the user might think the application has frozen or is broken.

We can report the amount of time that a given task takes to run in an application by using the following code:

using (var handle = Insights.TrackTime("TimeToLogin")) {
    await SubmitLoginInformation("myuserid", "mypassword");
    // ... more code goes here ...
}

Here we've included the code to track the time from inside an Insights.TrackTime task.

Optionally, we could have written the above as:

var handle = Insights.TrackTime("TimeToLogin");
handle.Start();
await SubmitLoginInformation("myuserid", "mypassword");
// ... more code goes here ...
handle.Stop();

No matter which method we use, when the task completes, the time log will be sent to Xamarin Insights.

Note: There is a limit to the number if unique track event names that can be sent to Xamarin Insights within your application: 250 for Enterprise and Business customers, and 50 for Basic and Trial customers. The maximum amount of data that can be sent in a single Insights.Track or Insights.TrackTime call is:

  • 100 characters for a TrackID length
  • 100 characters for the key length
  • 125 characters for the value length
In addition, a maximum of 20 properties can be sent with each Track.
Anything beyond this limit will be ignored and not reported.

Difference between Track and TrackTime

The difference between Track and TrackTime is at the server level. While the two methods look the same, Track is used purely for tracking analytical processes, whereas TrackTime allows for time graphing facilities when viewing the log data on the Xamarin Insights Dashboard.

TrackTime should be used when tracking server response times, performance monitoring within an application, or something as simple as a response timer within a game.

Communication Preferences

For information on communicating with the Insights server, refer to the Communicating with Insights guide.

Xamarin Workbook

If it's not already installed, install the Xamarin Workbooks app first. The workbook file should download automatically, but if it doesn't, just click to start the workbook download manually.