So, you’d like to put some ads in your awesome App Studio app? No problem! I thought I would write a post to show just how easy it can be. Follow these easy steps and you’ll start earning money from ads…
Ad provider
The ad provider is the service the AdControl in your app gets the ad to display and also where you earn the revenue. As of Windows Phone 8 there is a PubCenter AdControl built into the framework, all you need to do is get an ApplicationId and an AdUnitId. You get that information from Windows Phone DevCenter, find out how to get your ApplicationId and AdUnitId in this great blog post.
If you want to use a separate Ad provider, for example AdDuplex, you’ll need to add the provider’s DLLs to your project. I’m using AdDuplex in the example below, learn how to add AdDuplex to your project here.
Step One: Enable ads in App Studio
Before generating your App Studio app, you’ll want to enable ad support. On the Publish Info tab, turn on the Enable ad client in the source code switch (see #2 in this screenshot):
Next, generate the app and download the source code.
Step Two: Open App in Visual Studio
After downloading the source code, you might need to unblock the binaries before unzipping the folder. This is a built-in security feature that prevents internet-downloaded code from running on your machine. Since we know where these files came from, it’s ok to go and unblock them. Here is how to do that:
- Right click on the downloaded zip folder
- Select “Properties“
- If you see an “Unblock” button, click it. If you do not, continue to step 4.
- Now you can safely unzip the folder
Next, drill down into the unzipped folder until you see the Visual Studio solution file. Double click to open it in Visual Studio (Note: You need Visual Studio installed. If you do not, you’ll need to download and install the Windows Phone SDK from here).
Step Three: AdControl on MainPage.xaml
Drill Down to MainPage.xaml, see this screenshot to help you find it:
Near the top of the page, you will see a commented out section of code (approximately line #50). This is the built-in AdControl. All you need to do is:
- Uncomment the AdControl (delete the <!– and –> characters before and after the AdControl)
- Replace the placeholder ApplicationId and AdUnitId with yours
In this screenshot, I demonstrate how to use an AdDuplex ad control instead of the built-in AdControl.
That’s all there is to it! Now you can do a Build and publish the generated XAP file. (If you are not familiar with how to publish an app built with Visual Studio, see this documentation)
This image shows what the published app looks like running on a phone, see for yourself and download the app.
Happy coding!
Lance
Here are some follow-up resources to help you monetize your apps:
Reblogged this on Bitdisaster and commented:
A great walk-through on how to enable Ad’s in AppStudio Apps by Lance McCarthy.
Reblogged this on Ilmiantaja.
Hey Lance: A great, to the point and detailed document!
Question: Is there a way to see your ADs before your application is published? For example, when I make uncomment out the code and add my credentials. Can I build the application to my Windows8 phone and see the ADs?
Thanks!
Barin
If you deploy the app (in release mode) to the emulator (or device) and you have your ad unit’s credentials correct, you should see the ad being served.
Hi Lance,
Since, Microsoft ads are not working in all countries. How can I enable Pubcenter Ads and another third party Ads? So that when one Add is not working another Add will display instead of? I am working on windows phone 7 app and I am facing this trouble. Could you please help?
You can use third party solutions to this, my favorite is AdRotator (you’ll want v2). It will automatically switch to the next ad provider when an ad fails. Ultimately if all ads fail, it will show a “house” ad so you can advertise your own apps.