Mobile Zone is brought to you in partnership with:

I am a mother of four kids with a passion for languages, writing and programming. I try to cover everything a beginner should know. After all, I am a beginner. If there is anybody out there, thinking I missed something, or if somebody wants other topics, please feel free to contact me. Andrea is a DZone MVB and is not an employee of DZone and has posted 28 posts at DZone. You can read more from them at their website. View Full User Profile

Adding Ads to Your Windows Phone Application

03.22.2012
| 2383 views |
  • submit to reddit

Why ads to begin with?

I have a few apps in the Marketplace that can be purchased. The average end user though is not going to purchase anything that they haven’t tested. Therefore it makes sense to have a trial version of the app. The trial version usually has some limitations. Either you limit the functionality of the app, or, like I am doing in my apps, the trial version is ad-driven.

To add ads to your Windows Phone App you just need to follow a few steps.

1. Make sure you have the latest tools. You can find them here.

Although that ships with the Advertising SDK, it is recommended to download the latest version of the Advertising SDK as well.

2. Add a Reference:

1

2

Since I am developing my apps in Silverlight, this is the one I need.

3. In the root element of my XAML file I need to add this:

xmlns="clr-namespace:Microsoft.Advertising.Mobile.UI;assembly=Microsoft.Advertising.Mobile.UI"

In the Layout root of my XAML file I create my AdControl:

<my:AdControl ApplicationId="test_client"
              AdUnitId="Image480_80"
              Height="80"
              Width="480" />

Of all the properties of the AdControl, ApplicationId and AdUnitId are the most critical. The example uses special values intended for testing. Let’s see how that looks:

1 

Even though the SDK lists several different sizes for supported ads, only two have test images, that you specify through the AdUnitId property. For a 480×80 image, I use Image480_80 and for a 300×50 image, I use Image300_50. For a Windows Phone application it is recommended to use a 480×80 image.

One more property that is important to know is the RotationEnabled property, which by default is set to true. This means that a new ad will periodically and automatically be shown.

4. Get ApplicationId and AdUnitId at the Microsoft Advertising pubCenter. For every application you have ads for, you need to get an application ID. Each application can have multiple ad Units. If you are visiting the pubCenter for the first time, click the ‘Get Started’ button, otherwise sign in.

At the top there are two rows of tabs. First click the ‘Setup’ tab in the first row, and then ‘Sites and Apps’ in the second row. Click ‘Create a new application’:

1

Now you need to specify a name for your application. With clicking “add”, the Application ID will be assigned.

Once you have that, you can click on ‘Ad Units’ in the second tabs row. Click on ‘Create a new Application Ad Unit’. Now you need to select up to three categories per Ad Unit. This specifies the kinds of ads you want to be shown in your application

5. Now you need to set the assigned values to the ApplicationId and AdUnitId properties of your AdControl.

In order to get real ads, you need to set the static TestMode property to false in the constructor:

public MainPage()
{
    InitializeComponent();
    Microsoft.Advertising.Mobile.UI.AdControl.TestMode = false;
}

Here you can find more information.

 

To be continued…

 

Published at DZone with permission of Andrea Haubner, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)