Using AdMob in WP7 Silverlight Applications

I recently read that Google released a beta for AdMob in WP7 apps. That was great news for developers like me that can’t use Microsoft pubCenter that is US only. So I thought as a first real post here I would write a little tutorial on getting started with the SDK.

Download and install the SDK
First you have to create an account at http://www.admob.com (or login using an existing account) and add a new WP7 app to the AdMob account. You will then be presented with the link to download the AdMob WP7 SDK.

Add references
First off, add a reference to “Google.AdMob.Ads.WindowsPhone7.dll” that came with the SDK.

Add reference

In your XAML file add the following two namespace declaration at the top:

xmlns:google="clr-namespace:Google.AdMob.Ads.WindowsPhone7.WPF;assembly=Google.AdMob.Ads.WindowsPhone7"
xmlns:sys="clr-namespace:System;assembly=mscorlib"

Add the BannerAd control
To add the Ad Control, just add the following piece of code:

<google:BannerAd Name="MyAd" AdUnitID="n50g7fd69132t92" />

The AdUnitID is your Publisher ID presented on the AdMob website. If you run the project you will now get an ad shown. (No that is not my publisher ID )

Run AdMob in test mode
But to avoid getting impression counted while developing the application you might want to use test ads, you can do that by changing the ad code to:

<google:BannerAd Name="MyAd" AdUnitID="n50g7fd69132t92">
    <google:BannerAd.TestDeviceIDs>
       <sys:String>
         DEVICE_ID
       </sys:String>
    </google:BannerAd.TestDeviceIDs>
</google:BannerAd>

(I will show how to get the Device ID in my next post.)

The result
And here is the result of our not so hard work.

AdMob in action

AdMob in action

You are now up and running with Google AdMob in your application! Now go make some money ;)