Tutorial: Ads and Your Windows Phone App (Part 2 – AdMob)

To begin using the AdMob control in your Windows Phone app is relatively painless and should be something that you can fully implement in less than half an hour from start to finish.

You’ll need to do a little bit of prep work by signing up at AdMob.com – this will get you into their system so that you can get *paid* – and that’s a good thing :)

  1. Download SDK from AdMob
  2. Load your Windows Phone app in Visual Studio
  3. Right-click References > Add Reference > Browse to the SDK folder where you extracted the AdMob SDK Select the Google.AdMob.Ads.WindowsPhone7.dll file to add it to your project.

Next up you’ll want to place the code on your XAML page and make sure that you can receive an ad. To do this start up a brand new “Windows Phone Portrait Page” (or just use the MainPage.xaml file in a new project which is a perfect place to try this out). Add a third Row Definition with a height of “Auto” then add a new Grid call after the ContentGrid code block and call it Grid.Row=”2″

[code lang="csharp"]
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
[/code]

Inside that tag add the google:BannerAd call – refer to the following code for details. Note: you will need to add your individual AdUnitID to this call. You can find your Ad Unit ID in the AdMob portal site by going to Sites & Apps > hover over your app and choose the Manage Settings link – your AdUnitId is on the resulting page labelled as Publisher ID — I don’t know why they can’t keep it straight between the website and the code block but that’s how it goes :)

Add the following code thereby creating the new AdGrid and placing the BannerAd inside

[code lang="csharp"]
<Grid x:Name="AdGrid" Grid.Row="2" Margin="0,0,0,0">
<google:BannerAd Name="BannerAd"
xmlns:google="clr-namespace:Google.AdMob.Ads.WindowsPhone7.WPF;
assembly=Google.AdMob.Ads.WindowsPhone7"
Visibility="Visible"
IsEnabled="True"
AdUnitID="<your AdUnitID goes here>"
Margin="-12,0,0,0" />
</Grid>
[/code]

At this point you should have a working Ad call. You should run your app in either the emulator or on the device to ensure that a test ad is served from Google. If it is then all is good – you are ready to go.

One last thing, after your app is approved by Microsoft you should return to AdMob and fill in your Zune deeplink – you can get the URL/ID directly from the App Marketplace admin where you upload and deploy your app.

Additional Links

Tutorial: Ads and Your Windows Phone App (Part 1)

Tutorial: Ads and Your Windows Phone App (Part 2) – AdMob

Tutorial: Ads and Your Windows Phone App (Part 3) – AdDuplex

Tutorial: Ads and Your Windows Phone App (Part 4) – Ad Failover Complete

AdDuplex Dcoumentation (Client Area)

Comments are closed.