Google Analytics for your WinRT app
I have looked into how to use Google Analytics in a WinRT app and would like to share my findings.
Google Analytics (GA)
GA is a service offered by Google that generates detailed statistics about the visits to a website. I use StatCounter for my own purpose and there exist a lot of similar services but GA is probably the most used. I will not dig deep into how GA works but provide enough info to get started and setup what you need to use the frameworks presented later in this post..
1: Create a new Google account or use an existing one to login at GA:s homepage.
2: Click “Sign up”
3: I tested setting up an “App” account without success. My advice is to instead use “Web Site”. Fill out the form and finish by clicking on the “Get Tracking ID”-button.
4: You will now be presented with the, for this post, important GA Tracking ID.
You can either use the Google Analytics Tracking API directly or communicate with GA via a framework. My search engine found four alternatives where the two first matched my requirements best:
Google Analytics for WinRT (Windows 8 “Metro” apps) – http://w8ga.codeplex.com/
“It’s basically ported to Windows 8 and a simplified version of Microsoft Silverlight Analytics Framework.”
Nascent Google Analytics for WinRT – http://gawinrt.codeplex.com/
“A simple but powerful Google Analytics client library for Windows Store apps.”
MarkedUp – http://markedup.com/
“Easy-to-setup analytics and actionable insights on how consumers are using your Windows 8 apps.”
This one has a free beta at the moment.
GoogleAnalyticsTracker – http://github.com/maartenba/GoogleAnalyticsTracker
“GoogleAnalyticsTracker was created to have a means of tracking specific URL’s directly from C#. For example, when creating an API using the ASP.NET MVC framework, GoogleAnalyticsTracker enables you to track usage of the API by calling directly into Google Analytics.”
Read more about the framework at the creators blog.
Google Analytics for WinRT (Windows 8 “Metro” apps)
This framework can be downloaded at http://w8ga.codeplex.com/ or via a Nuget package. The download variant include a sample project. The current version support the following GA features:
- Pageviews tracking using AnalyticsHelper.TrackPageView method
- Event tracking with AnalyticsHelper.TrackPageView method
- Custom variables
- Device manufacturer tracking
- Device model tracking
You can read more about the latest release here. I decided to use the Nuget variant and created a test project:
1: Create a Windows Store Grid App Project in Visual Studio. (Yes, I use the Visual Studio 2012 Color Theme Editor as you can see)
2: Install the Nuget package by searching for “w8ga”
3: (Version 2.2 of the Nuget package has a bug with a missing generic.xaml file. You can get it by copy it from codeplex but Alex, the creator of the framework, fixed this problem in a 2.3 version just a few minutes after I pointed out the problem to him in a mail)
4: Follow the instructions at http://w8ga.codeplex.com/wikipage?title=Howto and use the GA Tracking ID you created previously.
5: Run the application and see how it feeds GA with tracking info.
“Google Analytics for WinRT” does not support multiple web property tracking within a single application out of the box but you can solve this by altering the source code and making the AnalyticsHelper non-static.
Now it’s up to you to apply this in your real application.
Nascent Google Analytics for WinRT
This framework can be downloaded at http://gawinrt.codeplex.com/. It has no Nuget package or documentation yet, but is easy to use. The current version support the following GA features:
- Realtime analytics support
- Page view tracking
- Event tracking, including label and value support
- Custom variable support
- Analytics session persistence via ApplicationData
- Supports multiple web property tracking within a single application
with the planned future features:
- A working sample application and tutorial
- Improved “audience” support (e.g. screen size, client size, platform, etc.)
- Offline tracking support
- Campaign tracking support
- Nuget package.
I created a test project in the same way as described above for the “Google Analytics for WinRT “-framework. I also used the same places in App.xaml.cs to setup and use the trackers.
sealed partial class App : Application
// two AnalyticsTrackers to test the multiple web property tracking feature.
static AnalyticsTracker AnalyticsTracker1;
static AnalyticsTracker AnalyticsTracker2;
protected override async void OnLaunched(LaunchActivatedEventArgs args)
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
rootFrame = new Frame();
AnalyticsTracker1 = AnalyticsTracker.GetInstance("UA-xxxxxxxx-x");
AnalyticsTracker2 = AnalyticsTracker.GetInstance("UA-yyyyyyyy-y");
rootFrame.Navigated += rootFrame_Navigated;
static void rootFrame_Navigated(object sender, NavigationEventArgs e)
if (e.Uri == null)
if (e.SourcePageType != null)
string uri = "/" + e.SourcePageType.FullName;
This worked perfectly and tracking info showed up in both my Web GA accounts.
The “Nascent Google Analytics for WinRT”-framework does not yet support user tracking for things like ISP and screen resolution, but on the other hand it supports multiple web property tracking within a single application out of the box.