There is always a clash between Google and Microsoft be it apps, APIs or operating system. When it comes to website analytics, Microsoft hasn’t got a solution and most websites rely on Google Analytics to keep a track on its usage. Google hasn’t released its official apps for Windows phone and likewise it doesn’t have an official SDK for analytics on windows phone but thanks to some excellent 3rd party SDKs its very simple to add it to your app. Here are four simple steps that would integrate Google analytics to your app.



Step 1. Create a account and get your tracking id.

If ever you have used google analytics for websites then this step would be quite simple. Just create a new account for your apps.



Heres the link for managing your account: http://www.google.com/analytics







Fill in the details and click on Get Tracking ID.







On the next screen you will be able to see the tracking ID and options to download SDKs for android and iOS . For windows phone we will be using a 3rd party SDK.We don’t need to download them.



Step 2. Install Google Analytics SDK for Windows Phone.



You can add Google analytics SDK for Windows 8 and Windows Phone using NuGet package manager. Here’s an article explaining how you could integrate a toolkit or third party SDK using with your Windows Phone app using Nuget Package Manager.





Step 3. Setup Google Analytics SDK to work with your tracking code by editing analytics.xml file

After the installation complete you will see that a file called analytics.xml has been added to your project.

Open analytics.xml and uncomment the lines corresponding to app name and app version. Also insert the tracking ID you generated earlier



<trackingId>UA-52075301-1</trackingId>



<appName>Google Analytics</appName>



<appVersion>1.0.0.0</appVersion>



Step 4. Now you can track Various events, Page views and Exceptions of your app.



Page view:

In the loaded event handler or the constructor of the page add the code given below to track pageviews



GoogleAnalytics.EasyTracker.GetTracker().SendView(“MainPage”);

Event:

To track events add the following code in the event handler for that event



GoogleAnalytics.EasyTracker.GetTracker().SendEvent(“Button clicks”, “Upload picture”, null, 0);

Exceptions:

To track exceptions add the following code in the catch part of a try catch statement or anywhere you intend to catch an exception



GoogleAnalytics.EasyTracker.GetTracker().SendException(exc.Message, false);

Heres the screen shot of the app with a click me button. The constructor for the page has the code to track page view and the click event handler has the code to track events. Also it can catch exceptions and report it.







Heres the screen shot of the app with a click me button. The constructor for the page has the code to track page view and the click event handler has the code to track events. Also it can catch exceptions and report it.









You can get the full source code of the project from the link given below.

Download full project Googleanalyticsforwindowsphone8.zip

Supports Visual studio 2012 and 2013(Windows 8 app)

Download full project Google analytics 8.1.zip

Supports Visual studio 2013 only(Windows 8.1 app)