In my last post, I went over some of the tooling I’m using to develop my first software offering completely on my own. One of those tools is the Google Analytics Measurement Protocol. Like many website owners, I use Google Analytics to track hits and behavior on my site. I’ve hooked Analytics into the Google Search Console for additional insight into search terms used to find my site. I’ve also configured some conversion metrics to track how valuable those hits are. In this post, we’ll look at how to use the Google Analytics Measurement Protocol to collect data about a desktop app.

About the Measurement Protocol

Signing up for Google Analytics is free and just requires a snippet of JavaScript to be inserted into the main layout of your website. You can register multiple properties under a single account. I have several properties I collect data on. Using a special tracking cookie, Google can evaluate the entire session a user spends on your site to provide data like Bounce Rate, Time on Site, Pages visited etc.

But Google Analytics isn’t just for website data. You can also track hits on any service that can send an HTTP web request. The Google Analytics Measurement Protocol is a very simple to implement solution to gather analytics from anywhere. The Measurement Protocol can be used to track all the data that website-based tracking accomplishes along with additional data about your application. This can include events with categories, actions and values, exceptions, timing and social interactions, to name a few. In my implementation, I’m only taking advantage of event data to track which features my users are using.

Getting started with the Measurement Protocol

In order to send hits to Google, you simply need to perform an HTTP POST to Within the body of the POST you can include all the information necessary to send hits to your Google Analytics property as form data. One caveat is that you MUST provide the user with a way to opt out of the service and present that option when installing your software. You may only send none identifiable data to the Google service.

Each hit type requires a protocol version and a tracking ID or web property ID. Your web property ID is listed in Google Analytics. From there, you need to specify the hit type and any parameters required by that hit type. All the parameter help is found on Google’s documentation site.

Sending Your First Hit

For my purposes, I used the event hit type. In my events I simply specify an event category and an event action. The cid parameter is the client ID and it’s used to associate the client with the event. This allows for multiple events to be correlated together to establish metrics like behavior flow.

In the simplest implementation in .NET, you could use a WebClient to upload the POST data to Google.

Once you’ve instrumented your code with analytics. You can begin tracking user interactions with your software. It works in both real time and historically; just like website analytics.

And now I can see what features people are really interested in. I added some other event types for licensing and package load that I put in a different category to filter out in whatever report I may generate.


Overall, I’d say that the Google Analytics Measurement Protocol is very easy to implement and you can’t beat free. It provides exactly what I was looking for and only took a little bit of work on my end.

If you want a library, check out CSharpAnalytics. I haven’t used it myself but it looks to accomplish what is describe above and more.