Windows SDK for Google Analytics
Google Analytics is one of the most popular analytics libraries for websites and mobile apps. Google Analytics is widely used to track user sessions, screen views, events, crashes, social interactions and promotional campaigns on Android and iOS.
Today, we are excited to announce that Microsoft is launching a Windows SDK for Google Analytics, providing an easy way for Windows 10 developers to access these valuable services. The SDK can be integrated into your apps via a NuGet package. The source is hosted on GitHub.
There is a C# SDK that can be used both by Universal Windows Store apps and desktop apps, and there is also a C++ WinRT component for developers targeting UWP apps written in C++ or JavaScript. Both the C# SDK and the C++ WinRT component use the same API names, so moving between them is seamless.
The SDK is built on top of Google’s Measurement Protocol, a service that allows developers to send engagement data to the Google Analytics Servers over HTTP requests. The APIs in the Windows SDK for Google Analytics are modeled on class names and design patterns from Google’s Android SDK, to ensure maximum portability and readability for those already familiar with Google Analytics on other platforms.
Getting started
If you prefer video format, this “Getting Started with the Windows SDK for Google Analytics” demonstrates every step below.
If you prefer written form, here is how you would add the Windows SDK for Google Analytics to your project:
- Register your app for Google Analytics—when you register your property, make sure you do it as a “Mobile app” and not a website.
- Add the appropriate NuGet reference to your app:
- Last but not least, add your code to track events.
The following are a few examples for a C# app. (If you prefer to see examples written for JavaScript or C++, the GitHub project includes additional samples in these languages.)
var tracker = AnalyticsManager.Current.CreateTracker("EnterYourPropertyIdHere"); AnalyticsManager.Current.ReportUncaughtExceptions = true; //create a timing event var screenName = "MainPage"; TimeSpan timeSpanToLoad = TimeSpan.FromMilliseconds(237); // sample:) tracker.Send(HitBuilder.CreateTiming("load", screenName, timeSpanToLoad).Build()); //Send a page view tracker.ScreenName = screenName; tracker.Send(HitBuilder.CreateScreenView().Build()); // Send a userclick event tracker.Send(HitBuilder.CreateEvent("user-events-category", "click", "sharing-button", 0).Build()); // Send a social interaction tracker.Send(HitBuilder.CreateSocialInteraction("facebook", "share", "link").Build());
Roadmap, feedback and contributions
We are excited about this feature-rich first release and the new capabilities it lights up for Windows developers. We welcome your suggestions for improvements as well as reports of any issues you find on our GitHub. Finally, remember that this is an open source initiative. We invite you to contribute your own code to make the SDK even better.
Source: Windows SDK for Google Analytics
Leave a Reply