If you have not already done so, create a Google Analytics account
. Be sure to choose "App" instead of "Web Site" when creating your account.
Note: only newer Google Analytics properties created after March 2013 will work with this SDK.
Once you have an account and tracking ID you are ready to start using the SDK.
There are four steps to getting started with the SDK:
- Update your application manifest
- Install the NuGet package
- Modify your analytics.xml file
- Add EasyTracker methods
After completing these steps, you'll be able to measure the following with Google Analytics:
- App installations
- Active users and demographics
- Screens and user engagement
- Crashes and exceptions
1. Update your application manifest
The only capability you need to add to your application is the IDCAP
NETWORKING capability for Windows Phone or Internet (Client) capability for Windows 8 store apps. These capabilities are already selected by default but you should confirm to make sure
your app can send data over the internet.
On Windows Phone (7 & 8):
2. Install the NuGet package
Option A: From Visual Studio Nuget Package Manager
PM> Install-Package GoogleAnalyticsSDK -Pre
- Right click on your project and choose 'Manage NuGet Packages'
- Search for "GoogleAnalyticsSDK"
- Click 'Install'.
3. Modify your analytics.xml file
By default, a file called analytics.xml will be automatically added to the root of your project. This file contains configuration options that you must edit. At the very least, you should always modify your tracking ID, app name and version:
<?xml version="1.0" encoding="utf-8" ?>
<!--Replace placeholder ID with your tracking ID-->
<!--Replace placeholder name with your app name-->
<!--Replace placeholder version with your app version-->
analytics.xml parameters reference
for the complete list of parameters you can use to configure your implementation.
4. Add EasyTracker methods
Add a single line of code to your app for each event you want to track. Here are examples of the different types of activities you can track in your app:
// track a page view
// track a custom event
GoogleAnalytics.EasyTracker.GetTracker().SendEvent("test", "userclick", null, 0);
// manually track an exception
GoogleAnalytics.EasyTracker.GetTracker().SendException("oops, something went wrong", false);
// track a transaction (in app purchase)
double cost = 1.99;
long costInMicrons = (long)(cost * 1000000);
var transaction = new GoogleAnalytics.Transaction("01234", costInMicrons);
var item = new GoogleAnalytics.TransactionItem("myproduct", "My Product", costInMicrons, 1);
// track a social networking interaction
GoogleAnalytics.EasyTracker.GetTracker().SendSocial("facebook", "share", "http://googleanalyticssdk.codeplex.com");
// track a timing (how long it takes your app to run a specific task)
GoogleAnalytics.EasyTracker.GetTracker().SendTiming(DateTime.Now.Subtract(startTime), "Startup", "MainPage", "Label");
(note the case change on properties and methods):
Warning: The Google Analytics SDK for Windows 8 and Windows Phone can automatically track exceptions and application lifetime events if
// track a page view
Congratulations! Your app is now setup to send data to Google Analytics.