I make an effort to never click on an ad, anywhere. As you might imagine, I don’t agree with, nor understand Google’s business model. With that said, there is obviously something to this advertising nonsense. So, how do you add ads to your: website, blog, and apps? I’ll do a series of blog posts as I learn how, myself!
I started today with adding an advertisement to the main screen of my Windows Phone 8 app. Here’s what I did…
In Visual Studio, I first added an “Ad Control” (from the Toolbox) to my main page.
What I really wanted to do was to push down the “top” of the page, and have the ad take up the top portion of the screen. So, I added a “RowDefinition” to put my ad control in row 0, and put the rest of the content into row 1. I changed this on my MainPage.xaml:
That means I can now put the main content (in this example case, a PivotTable) in row 1:
and put my ad control up in row 0:
It’s also important to note that you MUST add some new “capabilities” to your WMAppManifest.xml file. You must add (on the Capabilities tab):
Why? I don’t know. I read how to do most of this from this MSDN article, and it’s just what is needed to make this work. What does that buy us? Here is the before and after:
As you can see, the advertisement is 80px tall and takes up row 0 – and the rest of the content of this page takes up row 1.
That gets us technically-working in the app, but how do you show actual, real ads? And how do you get paid from that? Well, on the Microsoft platform for Windows Phone and Windows 8.x apps, you have to go to PubCenter:
It’s pretty self-explanatory. You create a new profile, register your app – and they give you an AdUnitId and ApplicationId. You might remember that our AdControl needs just that! So, go back into your XAML in your app, take out the sample values and point to the real thing:
Once you point to real ads, you won’t see that ad placeholder anymore in the Windows Phone Emulator. You (apparently) will only see them on an actual Windows Phone device. For this reason, I’m not sure if there are any more steps, because I can’t test without putting this on my phone first!
That’s about it! Version your app, go publish it in the Windows Phone store and you should be all set. Well, I think so at least. I just published an update my app, we’ll see if the ads actually work or not.