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.
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.
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.
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.