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

UPDATE:

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

https://developers.google.com/mobile-ads-sdk/

 

Step 2. Creating an ad unit 

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

https://apps.admob.com/#home

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.

 

Note

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
    admob(AdGrid);
  • 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 Admob.zip

Vivek Maskara

I am pursuing BTech in Software Engineering from Delhi Technological University. I develop apps, create websites and blog about my app experiences.

  • skarun

    Thank your for the tutorial! I’ll try it out this week and than I’ll give feedback.

    • Vivek Maskara

      did you try it?

      • skarun

        Yes I integrated admob a few days ago. But it doesn’t work on the main page and on other pages you can see it only sometimes, however, GoogleAdMob says it has a fillrate about 100%…

        • I have been using AdMob for one of my apps with 5000+ daily sessions for over a month and I have been getting 100% fillrate for all my adunits. Don’t worry publish your app and once it is live, fill rates would start increasing.

  • Kazi Nafis Ishtiaque

    Hello, I have a question?? Did this admob work in windows phone 8.1 application. I have tried it but got error while building the project. I use visual studio 2013 update 2.

    • Vivek Maskara

      What error did you get? I didn’t face any problem with my WP 8.1 project. I too use the same VS version.

      • Kazi Nafis Ishtiaque

        It says “Cannot find type System.Windows.Controls.UserControl in module System.Windows.dll.”. One thing, I have built this app in app studio. Now want to add the admob.

        • i guess the problem is that google ads sdk is available for only windows phone and you are trying to build a universal app.

      • Philippe

        I get the same error “Cannot find type System.Windows.Controls.UserControl in module System.Windows.dll.” while trying to build the solution after adding the dll. For test purposes, I created a new project (Windows Phone 8.1 blank app) and added the dll immediately after that, same error :(. How did you manage to get it work with 8.1?

  • cosmickinect

    how do you add the dll in a windowsphone 8.1 (silverlight) application? it just says that they are incompatible

    • Raajit Sharma

      ok got the solution,

      – 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

  • Hristijan

    Hello i have done every step from the tutorial and its working ok. The problem is that when i run it on emulator it works perfectly but when i run it on device is not working (no adds). Pls help

    • If it is working in the emulator, ads should appear on the device once you publish it. Also you can check the error by including a message box in bannerAd_FailedToReceiveAd event handler
      MessageBox.Show(e.Message);

      • Hristijan

        I did publish it but still not working… Maybe its because of my country or smth else…

        • Hristijan

          I solved the problem in some way…. I have two phones one is nokia lumia with windows phone 8.1 the other is Samsung Ativ s with Windows phone 8…. On the nokia i get the adds on the Samsung no…..My point is that the ad control does not work under windows phone 8…Maybe there is a workaround but i don’t know… Anyway ty for the support

  • PatrickPerazz

    Just a question :
    What is the actual ecpm?

    • The ecpm varies a lot and its difficult to give you a figure. Still you can quite easily have ecpm between 0.15 and 0.2$ for most days..

  • SamRock

    Anyways I can add this to a WinJS/HTML5 based Windows Phone App? Currently seems like WP Universal app has no Ad support from MS.

    Would you share the steps to add AdMob ads to a HTML5 based project please?

    • Sorry, but I don’t have experience with WinJS/HTML5. If you succeeded in implementing it then you could share it with us. 🙂

  • zanak

    Does admob sdk support for Windows phone 8.1 app (not universal) ?

    • Windows Phone 8.1 Silverlight supports the AdMob SDK but WP 8.1 XAML apps dont have a supported SDK yet.

  • Ngugi

    Hey guys.I just followed the tutorial and added the add on my app but on running it on the emulator I cant see any ad.Is this normal?
    I am on visual studio express 2012

    • Hey you should check a few things. Check if you have added all the required capabilities and secondly if the ad unit id is correct. If everything is correct then maybe the fill rates are less in your region so ads might not be appearing. You may try publishing the app and observe the dashboard for 1-2 days.

      • Ngugi

        I have all capabilities enabled.
        I am in East Africa , Kenya.I will try your option.
        Thanks.

  • Roberto Poggi

    Hello,
    i have a 10 views in my project. Insert a 10 controls or use a static class?
    what is the best way to get more money?
    thanks

    • You could definitely try 2-3 different ad units but it won’t be good to use 10 different ad units

  • DENNIS

    Helo, Please help where can i get tutorials for icorporating google ads on windows phone …Link if possiple

  • Chishti

    Hi,

    I am using Visual Studio 2015 …
    – I don’t not see Capabilities listed in above image in my menifest file.
    – Also when I try to add AdView in Toolbox. It generates an error that this dll file does not contain any control to be added in Toolbox

    – I am getting this error

    Severity Code Description Project File Line Suppression State
    Error Cannot find type System.Windows.Controls.UserControl in module System.Windows.dll. MobileAppNative

    I am unable to resolve it.

Read more:
How to create your first Windows Phone app
How to change the App name and Tile name of your Windows phone app
Data binding in Windows Phone app – One way binding
Close