February 10, 2017 8:51 am

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:

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

Updated February 13, 2017 12:11 pm

Join the conversation

  1. Does it support Xamarin?
    I have been using the following SDK for a while with UWP apps now. How does this one compare to that?

    • Hi Akshay, I just clicked through and the C# SDK is actually the windows-sdk-for-google-analytics available from GitHub.
      According to the description: “SDK to connect to Google Analytics from Windows Store (UWP) Apps, Windows desktop apps written with .NET, and Xamarin Apps ” so I think it would be safe to assume you can use it.

  2. I have tried this tutorial, but I am unable to get it to work, I even downloaded the sample and put in my tracking ID UA-102555648-1 but too no avail. Is there a way I can debug and see what exactly is happening?

  3. In the video there is reference to “GoogleAnalytics.Core (Source) .NET Library for Windows Forms”, Is that available and how do we get it?

  4. It appears that Google Analytics is now forcing an attribution to Firebase in order to create a mobile property. However, Firebase does not support Windows applications from what I can tell. This seems to leave us unable to create any new Windows app properties. Is there a resolution or workaround for this?

  5. The video says that the Xamarin Nuget will be available in cpl of weeks. That was in February. Now it is November, and I cannot find it.
    I am writing Xamarin.Forms UWP app, do I need the Xamarin.Forms Nuget (which is missing) (GoogleAnalytics.Core) or the UWP.SDKforGoogleAnalytics.Managed nuget?

  6. The GitHub sample app is not building, throws error

    Severity Code Description Project File Line Suppression State
    Error Type universe cannot resolve assembly: Windows.Foundation.UniversalApiContract, Version=, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime. GoogleAnalytics.UnitTests C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v14.0\8.2\Microsoft.Windows.UI.Xaml.Common.targets 264

    Severity Code Description Project File Line Suppression State
    Error Cannot resolve Assembly or Windows Metadata file ‘Windows.Foundation.UniversalApiContract.winmd’ GoogleAnalytics.UnitTests C:\Users\user-name\Desktop\work\googleanalytics\windows-sdk-for-google-analytics\src\Managed\GoogleAnalytics.UnitTests\GoogleAnalytics.UnitTests.csproj

    In addition, GoogleAnalytics.Core is nowhere to find but it is in References and has the yellow warning triangle.