How to use Google AdMob in Windows Phone app

When it comes to monetization using in-app advertisements in Windows Phone apps, there are quite a few option like Microsoft’s Pubcenter, Mobfox, Smaato, AdDuplex, Nokia’s Inneractive and Google’s Admob. In the past two years I have tried all these ad providers and have finally struck to Google’s Admob. There was a period when Microsoft’s Pubcenter gave the best returns but gradually its fill rates started dropping and earnings dropped by around 99.5% for developers outside US. That made me try other ad providers available for WP and frankly none of them are as good as Pubcenter(the old one) but now developers don’t have a choice. In this post I will show you how you can integrate AdMob in your Windows Phone app. You can add AdMob in your app by XAML or via code in C#.


We have noticed a improved eCPM(0.2 $ to 1.1$) and fill rates(60% to 90%) for pubcenter. So you might consider using pubcenter in your windows phone app.

If you have significant traffic in India then you can give a try to Vserv for Windows Phone 8 which gives a better eCPM than AdMob.


Step 1. Getting the SDK

Firstly download Google Admob SDK for Windows Phone from the link below


Step 2. Creating an ad unit 

Go to your AdMob account and create an ad unit for your app

Note: You would need a upgraded Admob account for this purpose and the previous admob account is no longer supported. You can read more about it here.


Fill in the details to create an AdUnit as follows

  • Fill in your app name and select platform

  • You can configure analytics for your app and link it to your Google analytics account. Learn how to integrate Google analytics in your app. We will skip it for now.
  • Select the type of AdUnit and fill in the name for the AdUnit. You can customize the look of the ad whenever you want
  • Click on save and an AdUnit id would be generated.



All done you are ready setting thing up for AdMob.


Step 3. Add the GoogleAds reference to your project

Unzip the SDK files and you will find a GoogleAds.dll file in it. Create a new project and add a reference to this dll file in your project. Here’s an article explaining how to integrate a Toolkit or Third party SDK with windows phone app using NuGet Package Manager.



If the GoogleAds.dll is showing as incompatible then follow these steps

  • In the file explorer, navigate to the Google Ads.dll
  • Right click the dll file and click ‘Properties’
  • In the ‘General’ tab, at the bottom, there will be an ‘unblock’ button
  • Unblock the dll file and add it again in your project


IMPORTANT: You will need to add the following capabilities in your app for ads to appear!

  • ID_CAP_NETWORKING: Access to network services is required when requesting ads.
  • ID_CAP_WEBBROWSERCOMPONENT: Required since the AdView is a web browser.
  • ID_CAP_MEDIALIB_PLAYBACK: Provides access for currently playing media items.
  • ID_CAP_MEDIALIB_AUDIO: Provides read access to audio items in media library.


Now you can either add ads using XAML or via C#

How to add ads using XAML


Go to Toolbox in your Visual Studio and right click on general category and select Choose Items.



From the choose items dialog box tick AdView from Google Ads and click OK to include the control in the Toolbox.



Now you can view AdView control in the Common Controls list of the Toolbox. Select and drag it to place it anywhere in the page



Add the AdUnit ID you generated earlier to the control. The XAML should now look similar to this.
  If you have added the XAML code directly then a reference will be required for AdView control   xmlns:GoogleAds="clr-namespace:GoogleAds;assembly=GoogleAds"  

How to add ads using C#

  • Add the code below to display ads using C#
  • You can see the function admob(StackPanel stck ) takes a parameter which is the name of the stackpanel in which you wish to place your ad. Instead of a stackpanel you could use a Grid too.
  • Add the StackPanel in which you wish to place your ad in the XAML
  • Call the admob function in the page constructor as follows
  • The advantage of this procedure is that you could place multiple ads in different StackPanels or Grid just by changing the name of the StackPanel/Grid in the parameter


Here is how the app looks when you run it in the emulator.



Download full project Google

How to integrate Google Analytics to Windows Phone app

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:


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



<appName>Google Analytics</appName>



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




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

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



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

Supports Visual studio 2012 and 2013(Windows 8 app)


Download full project Google analytics

Supports Visual studio 2013 only(Windows 8.1 app)