[Basic for Absolute Beginner] – [Part 5] – Analytics for your apps

Analyzing user behavior is absolutely necessary and important for improving the quality of your app.

And this time we’ll lean on the most terrifying user tracking and analytics tool in the world: Google Analytics

That’s right — Windows Phone and Windows 8 using the “competitor’s” Analytics service. Weird, isn’t it :3

In the same series:

[Basic for Absolute Beginner] – [Part 1] – Layout with XAML 1

[Basic for Absolute Beginner] – [Part 2] – Layout with XAML 2

[Basic for Absolute Beginner] – [Part 3] – App’s Structure and how to customize it

[Basic for Absolute Beginner] – [Part 4] – Basic Steps for a new app

[Basic for Absolute Beginner] – [Part 5] – Analytics for your apps

[Basic for Absolute Beginner] - [Part 6] - Source Control

Table of contents

1. In the Project

1.1. Installing the SDK

Open your project, go to Tools > NuGet Package Manager > Package Manager Console

A cute little box shows up; type the following command

Install-Package GoogleAnalyticsSDK

Wait a moment for it to run

1.2. Filling in the information

Once it finishes, your Project has a few new things in it

The analytics.xml file

This file holds the settings Google Analytics needs to track your app.

The file has extremely thorough comments in it; you can comment them out and fill in the settings you want

The analytics.xsd file

This is the compiled version of the file above; you don’t need to care about it

2. On Google Analytics

Go to this link: Google Analytics Account

Click the Sign in button

Pick the Admin tab

Create a new property

Pick the right settings. Note that for “What would you like to track”, pick Mobile app

After that you get a tracking ID in the form UA-#######-##; copy that string and paste it into the analytics.xml file in your project

3. Setting up tracking

Basically you can track a lot of things, including:

  • App screens: which screen users use the most
  • Event: which button gets clicked the most, which event happens the most
  • Exception: which error gets caught the most
  • Transaction: payments, purchases, In-app Purchase
  • Social: sharing on social networks
  • Timing: how long the app takes to run some task

And of course you get these numbers:

  • Number of users
  • New users who installed it that day
  • Users currently using the app (Realtime)
  • Loyalty
  • App exit rate
  • App version (this one has to be configured in the XML file)

3.1. Coding

In the RootFrame_NavigationFailed event, add the following code

GoogleAnalytics.EasyTracker.GetTracker().SendException(e.Exception.Message, false);

This code tracks the Exceptions from failed page navigation

In the Application_UnhandledException event, add the following code:

GoogleAnalytics.EasyTracker.GetTracker().SendException(e.ExceptionObject.Message, false);

This code tracks the Exceptions for all other errors

In the InitializePhoneApplication() method, declare an Event Handler:

csharp // Track Navigation RootFrame.Navigated += RootFrame_Navigated;

In the Event Handler, add the following code:

csharp if (e.Content != null) { GoogleAnalytics.EasyTracker.GetTracker().SendView(e.Content.ToString()); }

4. Viewing the Analytics

Viewing the Analytics results is quite interesting, because it shows you a lot of information — the nicest one is probably the number of users currently using the app

You can explore more in your own Google Analytics page.

Note that only an app with many users and network access will show you any Analytics.