Using Ad Mediation in Windows Phone 8 app

Ad mediation is an algorithm that enables your app to use multiple SDKs. This means that with the mediation code in place, your app will make a call to one ad control, and if that ad control cannot serve an ad, the app will then call a second ad control, then a third, and so on. The new ad mediation control provides a simple way to implement this capability in your apps. It offers several advantages over using a single ad network, giving you control to integrate multiple ad SDKs and optimize use based on performance. The highest revenue return can be achieved by choosing the ad network with highest eCPM first, then serving the unfilled ads from other ad networks. Here are some attractive features offered by Ad Mediation for Windows Phone

  • App level configuration
  • Global and optional market-specific configuration
  • Ad refresh rate
  • Pause/Resume ads
  • Ad network prioritization (e.g. specific network first, equal distribution, back-up only)
  • Ad network exclusion (do not use this ad network, globally or in a specific market)
  • Fill rate reporting by ad network and by market

Windows ad mediation capabilities are initially launching for Windows Phone 8.0, 8.1 Silverlight and 8.1 XAML. Currently you can use Microsoft Advertising, AdDuplex, Inneractive, Smaato, AdMob, InMobi and MobFox with Ad Mediation. You will need to set up an account on each of the ad providers that you plan to use and create an ad unit in it. Here are the steps to use Ad Mediation in your Windows Phone 8 app.

Step 1. Download and install the Windows Ad Mediator Extension

Before you can use Ad Mediator in your apps, you need to download and install Ad Mediator Extension. The Ad Mediation control will appear in the toolbox next time you open Visual Studio.


Step 2. Add the Ad Mediation control

From the Toolbox, drag a new AdMediatorControl into the designer. Position the control in the location where you’d like your ads to display. You can add multiple controls if you want to display ads in more than one area of your app. Be sure to drag the control into the designer, not into your XAML code. Code will be generated for the control, including a unique ID and a name for the control. Here is how it can be done in a Windows Phone 8 Silverlight application:

  The Name element will help you to identify the specific control in your app when you configure your ad mediation. You can change this to whatever you’d like, but be sure not to change or duplicate the Id element. This Id must be unique for each control within your app.

Step 3. Configure the controls

Once you’ve added all the controls you’d like, you’re ready to configure them through Connected Services. Note that if you add an additional AdMediatorControl later, you’ll need to configure it through Connected Services again. Otherwise, the new control will not be able to use ad mediation. To configure the controls, right-click the name of the project in Solution Explorer, click Add, and then click Connected Service… to launch the Services Manager window. By default, the Microsoft Advertising DLLs will be added, and Microsoft Advertising will be enabled. If you don’t want to use this ad network, you can remove it in the next step. For each of the selected ad networks, click on configure hyperlink to set the ad unit id for that ad provider. Even if you don’t configure the Ad Controls in the app, it can be done in the Windows Phone Developer Portal without needing to update the app again.

Step 4. Add or remove Ad Networks

To add and remove ad networks, click Select ad networks. You’ll see a list of all the ad networks that are supported for your project. Check the boxes of the ad networks you want to use. After you’ve selected your ad networks, click OK. The control will attempt to retrieve the DLLs for each ad network. You’ll see the progress and result of this process. Click OK, and you’ll be able to see which DLLs were successfully fetched.

Note: In some cases, you may see that certain DLLs were not fetched (for example AdMob as it is not available on Nuget). In this case, you’ll need to add them manually. For links to download individual assemblies, see Selecting and managing your ad networks.



If you decide to add another ad network after doing this configuration, you’ll need to open the Services Manager window again, select the network, and ensure the DLLs are added.

Step 5. Add the required capabilities

Each ad network may require certain app capabilities. These are shown by each provider in the Services Manager window. Be sure to declare all of the required capabilities in your app’s manifest so that the ads are properly displayed.

Step 6. Handle unhandled exceptions from Ad Networks

As part of our testing, we’ve identified a number of unhandled exceptions from specific ad networks that must be handled within the app to avoid app crashes related to these exceptions. We highly recommend that you copy and paste the code sample below to your App.xaml.cs file. Code for Windows Phone 8 Silverlight application

Code for Windows Phone 8.1 XAML application

Step 7. Test the application

Running your app in the Windows Phone Emulator is a good first step. When you do so, test metadata will be used, so you can test your app and make sure it’s coded correctly before you’ve even entered your ad network required parameters. When you run your app in the emulator, the ad networks will rotate in sequential order, with one network displayed after another for equal amounts of time. Be sure to wait long enough to run through a few cycles so you can view all ad networks and reduce the chance of any temporary connectivity issues which may occur. Test ads will be displayed (for ad networks which support them).


Step 8. Submit the app and configure ad mediation

Once you’ve built your app to include all of the ad networks you may want to use, and tested it to ensure everything’s working, you’re ready to submit the app. During the submission process, you can configure the ad mediation behavior you’d like to see. You’ll be able to adjust this later without having to make code changes or submit new packages.
When you upload your packages, Dev Center automatically detects that you’re using ad mediation and identifies which ad networks you’re using. On the package upload page, you’ll see an Ad mediation configuration section. This is where you’ll configure your mediation logic. The first time you submit your app, you’ll create a baseline configuration. After that’s set up, you can add market-specific configurations to take advantage of specific ad networks’ strengths in different markets.

If you want to adjust your ad mediation for a specific app, you can do so at any time without having to resubmit the app. This is useful if you’ve already added ad networks into your app that you hadn’t previously set up accounts for, or if you’re finding that one ad network is not able to fill ads reliably in specific markets.

To make changes, view the app details page in Dev Center and click Ad mediation. You can make changes to your baseline configuration as well as to market-specific configurations. You can also add or remove market-specific configurations if desired.

You can download the project source code and use it as an reference.
Download full project

Using AdDuplex in Universal Windows Apps

AdDuplex offers an universal app SDK in addition to its existing SDK for Windows Phone 7.8 and Windows Phone 8. This universal app SDK can be used with either universal Windows apps or standalone Windows 8.1 or Windows Phone 8.1 XAML apps.

Step 1. Register for a publisher account on AdDuplex

First thing first. If you don’t have an adduplex account, register on


Step 2. Register a new app from your dashboard

Click on New App button in the dashboard to register a new app. We are building a Universal app which will run on both Windows Phone 8.1 and Windows 8.1. So we will need to register two new apps here, one for phone and other for desktop.



Enter the details for the app and choose an appropriate platform.


Once you create the app, note down the App ID which we will need while developing the application.


Step 3. Create a new Universal App project

The SDK can be used for either an universal app or standalone Windows 8.1 or Windows Phone 8.1 XAML apps. So in your Visual Studio Choose a Blank Universal app from the installed templates.



Step 4. Download the SDK from Visual Studio Gallery website

You can get the SDK from Visual Studio Gallery’s website. I am not sure if its available on Nuget too.


Adding AdDuplex to Windows 8.1 app


Step 5. Add a Reference to AdDuplex SDK for Windows 8.1

In your Windows 8.1 project add a reference to AdDuplex SDK for Windows 8.1. From the Solution Explorer window, right click References…, and select Add New Reference…


Step 6. Add the namespace for AdDuplex in MainPage.xaml

Next, add a namespace for adduplex on the page where you wish to display ads.


Step 7. Add the AdDuplex adcontrol in your page

Finally add the code for adduplex’s AdControl in your page. Use the app id which you generated earlier while registering the app on adduplex’s website.

Note: Make sure the whole AdControl is visible by verifying that it’s not obstructed by any other objects on your page. We recommend setting the Canvas.ZIndex property to a high value to make sure the AdControl is not being covered.



That’s it. You can run the Windows 8.1 app on the local machine and hopefully an ad will appear.


Adding AdDuplex to Windows Phone 8.1 XAML App


Step 8. Add a reference to Windows Phone 8.1 XAML SDK

Similar to the Windows 8.1 app, you need to add a reference to AdDuplex SDK for Windows Phone 8.1(XAML) in your project for Windows Phone 8.1


Step 9. Add the namespace and adcontrol for AdDuplex in MainPage.xaml

Just like the Windows 8.1 app add the namespace and adcontrol to your page. Use the app id which you generated earlier while registering the app on adduplex’s website.


That’s it. You can run the Windows Phone 8.1 app on the emulator and hopefully an ad will appear.


Download full project

Using AdDuplex for Windows Phone 8 Silverlight app

AdDuplex is a cross-promotion network specifically targeted at Windows 8 and Windows Phone apps and games. You add our AdControl to your application and start serving ads for other apps. They serve ads for your app in return. The ratio is 8:10. This means for each 10 ads displayed in your app 8 of your ads will be displayed in other apps. The remaining 2 ads will be sold to support the service. The advantage of using adduplex is that it has a 100% fill rate. So it is often used as a secondary option to fill ad space if the primary ad network fails to deliver an ad.

You may consider using these as your primary ad networks

Here’s how you could use AdDuplex in your app.

Step 1. Register for a publisher account on AdDuplex

First thing first. If you don’t have an adduplex account, register on


Step 2. Register a new app from your dashboard

Click on New App button in the dashboard to register a new app. We are building a Windows Phone 8 Silverlight application.


Enter the details for the app and choose an appropriate platform.


Once you create the app, note down the App ID which we will need while developing the application.


Step 3. Create a new Windows Phone 8 Silverlight app

Choose a Blank Windows Phone Silverlight template from installed templates and create a project.



Step 4. Add AdDuplex SDK to your project using Nuget

Next, add AdDuplex SDK to your project using Nuget package installer. You might want to see

How to integrate a Toolkit or Third party SDK with windows phone app using NuGet Package Manager



Step 5. Add the namespace for using AdDuplex in MainPage.xaml

Add the namespace for AdDuplex on pages where you wish to display ads


Step 6. Add the adcontrol in your page

Now add the adcontrol in your page. Use the App id which you generated earlier.



  • You can preview your own exchange ad by setting IsTest property to true.
  • Make sure the whole AdControl is visible by verifying that it’s not obstructed by any other objects on your page.

Download full project

Adding Microsoft pubcenter ads in Windows Phone 8 apps

Recently lots of developers are seen facing problems with pubcenter ads. The impressions are at an all-time low still for some developers ads never show up (not even the test ads). There’s a little thing that developers should be mindful of and pubcenter will again start working for them. Heres a tutorial explaining how you could integrate pubcenter advertisements in your Windows Phone 8 apps.

Step 1. Visit pubcenter website and add a new application in it

Visit pubcenter website to create a new application and its ad unit



Note down the application ID and the ad unit ID which you just created.

Step 2. Add a reference to Microsoft.Advertising.Mobile.UI

Right click on the name of the project in solution explorer and choose Add>Reference. From the dialog box that appears choose Microsoft.Advertising.Mobile.UI and Microsoft.Advertising.Mobile and add it to your project. These references will enable you to use Microsoft’s pubcenter ads in your app. Instead of adding the reference you could have dragged and dropped the AdControl from Toolbox.



Step 3. Crucial step- Add the following capabilities carefully

Not adding all the required capabilities is main reason behind ads not showing up from pubcenter. Not choosing the right capabilities doesn’t lead to a syntax error and no error is reported while deploying the app. The following ID_CAP capabilities must be included in the manifest of the advertising-enabled app.


Go to Solution Explorer> Properties> WMAPPManifest.xml and move over to capabilities tab. From there choose the following capabilities. You may require other capabilities based on the type of application you are building but these will be required for pubcenter.


Step 4. Add a reference to the page where you want to display ads

Add the following reference to the page where you wish to display ads from pubcenter.



Step 5. Add the AdControl to your page

Add the AdControl to your page and insert the app id and ad unit id in it. If you are unsure where to put the code then have a look at the screen shot below. Also notice that the app id and ad unit id are set to test_client and Image480_80 respectively which is the default value. Also we have added an error occurred event handler.

Note: While debugging the app on emulator ads won’t show up if you are using a real app id and ad unit id. Instead if you use test values then a default ad will be visible    

Step 6. Add the error occurred event handler in code behind

You could use this event handler while debugging to know the reason for ads not appearing in the app. Most of the times if the ad control is correctly configured the reason for ads not appearing is low fill rates. Also you could use this event handler to load ads from another provider if ads from pubcenter fails. The code snippet show how you could add Google Admob’s ads when pubcenter fails to get an ad.

Here’s an article explaining how you could add Google AdMob in your Windows Phone 8 app.



A few users have claimed that they can’t find this event trigger in their ad control. They might not be using the latest Ad SDK.

When you run the app in the emulator ads should now appear. Here’s a screenshot of the sample app i built.



Get the full source code of the app here,

Download full project source code

Using in App purchase to implement `Block Ads’ Feature in Windows Phone app

In my last blog post I explained how to add in app purchase in Windows Phone app. In this post I will show how IAP can be used to implement `Block Ads’ feature. Suppose you have a free app in the marketplace with in app advertisements. Most likely you wish to keep the app free so that it gets the most number of downloads. Still the advertisements may be annoying to some users and it would be great if you let your users remove those ads by making an in app purchase. Similar feature can also be achieved by implementing trial functionality in your app. I believe IAP is easier to implement and provides much more flexibility than trial apps. You have already seen how to set up IAP in your app so I will don’t discuss it again. Here is how you can implement the `Block Ads’ functionality

Step 1. Follow the following tutorial to set up in app purchase in your app

Step 2. Set up in app advertising in your app

If you haven’t added in app ads in your app then you could follow this tutorial to add Google Admob in your app.

Step 3. Create a public Class AppSettings global to the project

Define a public class AppSettings which is global to the whole project with two public data variables DISPLAYADS and ISADBLOCKERACTIVE. You can define a public class by placing it just below the namespace of the project. In the sample provided I have defined it in App.xaml.cs just below the namespace of my project WAT_Test.

Step 4. Code to assign values to DISPLAYADS and ISADBLOCKERACTIVE

We will update the values of these variables when the app is launched and check whether the user has purchased the IAP to remove ads. If he has purchased it then ISADBLOCKERACTIVE will be set to true and DISPLAYADS will be set to false.


When I discussed how to use google admob in an app, I showed that it can be done through XAML or using C# code. So here too I will discuss how to block ads when it has been placed using XAML or via C#.

Blocking ads that were placed using XAML

  • Add a reference to your project in App.xaml as shown below in file reference.xaml
  • Add a new application resource ApplicationSettings which will use the AppSettings class in the section of Application.Resources as shown below in file local.xaml


  • Add a value converter class in App.xaml.cs named BooleanToVisibilityConvertor. This class implements IValueConverter converts a boolean value to an equivalent visibility and vice-versa.
  • Add a new application resource BooleanToVisibilityConverter in Application.Resources as shown in local.xaml file below
  • Now you can modify your AdView code for Admob to place a visibility condition as shown in the code adview.xaml


Blocking ads that were placed using C#

This is much simpler and you just need to check whether DISPLAYADS is true or false before calling admob() function.

These screen shots show that earlier ads were being displayed in the app but after IAP they didn’t appear. Be assured it wasn’t coincidence as I have getting 100% fill rate for Google Admob for the past few days.

Download full project

How to implement trial functionality in windows phone app

This topic describes how to implement a trial experience in your Windows Phone app.
The purpose of a trial experience is to give the user an opportunity to try your app before they commit to buying it. In a trial experience, you typically offer a limited version of your app, for example, by disabling features, by disabling levels in a game, or by setting a time limit on using the app. The limitation you choose for your app is entirely up to you.


I will be demonstrating this with the help of an example. Suppose there are two pages in an application out of which only one can be opened in trial version that is first page .

In full version of the application you can open both the pages that is first page and second page.

The steps to followed to implement trail functionality are


1. First create a blank project and name it Trialapp.

2. Then open App.xaml.cs and add the following using directive to the top of the page

  3. In the App class, declare the following local static variable. The LicenseInformation class enables an app to determine if it is running under a trial license.
4. In the same App class in App.xaml.cs, add the following read-only property and local variable. This property is used to cache the license information while the app is running. The app uses the property whenever the current license information needs to be checked.


5.In the following sections, the license information will be checked in the Application_Launching and Application_Activated event handlers. Since this logic is used in two locations, we wrap it for convenience into its own method. In the App class located in App.xaml.cs, add the following method.    


6. Then open the MainPage.xaml and remove the XAML code for the Grid named LayoutRoot and replace it with the following code.



7. Then add two more pages to the application and name it Firstpage.xaml and Secondpage.xaml.



8. Open the Page Firstpage.xaml and change the application name to trial app and page name to first page. Similarly do it for Secondpage.xaml and change the page name to Second page.



9. In the MainPage.xaml.cs  code-behind file, add the following methods.


10. Now run the application in debug state you will see that the app runs in trial mode as the value of _isTrial in App.xaml.cs is true. The following screen will appear before you and the second button will be disabled.



11. Now when you will change the value of _isTrial to false the app will run as full version.



12. While submitting the app to store you need to tick the checkbox of trial functionality in your app. You can do this easily. Go to your dashboard. Select your app. Go to the app info page and check the checkbox.




Note: If you forget to check this checkbox you app will be available in full version to all the users in the marketplace.


13. You can download the Project zip file from the link given below.


Download full project


Add in app purchases in your Windows Phone App

In app purchases is an excellent way to increase your revenues from your Windows Phone app. It lets you distribute your app for free and then charge the users for some added features or service. I will show you how you can easily add it in your app. You would need an active Windows Phone developer account for this tutorial as even for testing purposes you need to create a product for your app.

Step 1. Start off with submitting your app as beta version in the marketplace or if your app is already live then skip this step

Go to Windows Phone developer portal and submit a new app at


Go to App Info and fill in the details. Reserve your app’s name and choose its category.


Go down to More Options and choose distribution channel as Beta. Add the live account email ids of your beta testers.



Browse and upload the XAP package for the project that you compiled earlier. You will need to fill in all the mandatory fields and upload the app icon and screenshot too.


Submit the app and go to App details page and note down the App ID from there.


Step 2. Update App ID and Publisher GUID in WMAppManifest.xml of your project


Step 3. Add a product to your app in Windows Phone Developer portal


Products can be of two types, consumable and durable. Consumable products need to be re-bought once used where as durable products need to bought only once. Fill in the details of your product and save it.


Add title, description and product icon.


We have successfully created a beta app and have also added an in app product for it. Now we need to move to the coding part.

Step 4. In app product listing

  1. The file in_app_purchase.xaml shows the XAML that could be used to list the in app products. Copy and paste in in the ControlPanel of your app.
  2. Next a clss ProductItem has been defined in file product_item.cs which is will contain the information about the product. Copy and paste it above the constructor in the MainPage.cs
  3. Lastly place the code in in_app_purchase.cs in MainPage.cs which will populate the products for the current app.

Step 5. Buy an Item ButtonBuyNow_Clicked is the event handler on click of Buy now button. It takes the user to his wallet where he can purchase the product.
The screenshot shows the product listed in the app.

Remove ads

That’s all you need to do to let the user buy any in app product from your app. I have posted another tutorial where I will show how IAP can be used to implement blocking ads in your app. That way you can offer the app free with advertisements to your users and let them make an IAP if they wish to remove the ads

Download full project

How to use Google AdMob in Windows Phone app

When it comes to monetization using in-app advertisements in Windows Phone apps, there are quite a few option like Microsoft’s Pubcenter, Mobfox, Smaato, AdDuplex, Nokia’s Inneractive and Google’s Admob. In the past two years I have tried all these ad providers and have finally struck to Google’s Admob. There was a period when Microsoft’s Pubcenter gave the best returns but gradually its fill rates started dropping and earnings dropped by around 99.5% for developers outside US. That made me try other ad providers available for WP and frankly none of them are as good as Pubcenter(the old one) but now developers don’t have a choice. In this post I will show you how you can integrate AdMob in your Windows Phone app. You can add AdMob in your app by XAML or via code in C#.


We have noticed a improved eCPM(0.2 $ to 1.1$) and fill rates(60% to 90%) for pubcenter. So you might consider using pubcenter in your windows phone app.

If you have significant traffic in India then you can give a try to Vserv for Windows Phone 8 which gives a better eCPM than AdMob.


Step 1. Getting the SDK

Firstly download Google Admob SDK for Windows Phone from the link below


Step 2. Creating an ad unit 

Go to your AdMob account and create an ad unit for your app

Note: You would need a upgraded Admob account for this purpose and the previous admob account is no longer supported. You can read more about it here.


Fill in the details to create an AdUnit as follows

  • Fill in your app name and select platform

  • You can configure analytics for your app and link it to your Google analytics account. Learn how to integrate Google analytics in your app. We will skip it for now.
  • Select the type of AdUnit and fill in the name for the AdUnit. You can customize the look of the ad whenever you want
  • Click on save and an AdUnit id would be generated.



All done you are ready setting thing up for AdMob.


Step 3. Add the GoogleAds reference to your project

Unzip the SDK files and you will find a GoogleAds.dll file in it. Create a new project and add a reference to this dll file in your project. Here’s an article explaining how to integrate a Toolkit or Third party SDK with windows phone app using NuGet Package Manager.



If the GoogleAds.dll is showing as incompatible then follow these steps

  • In the file explorer, navigate to the Google Ads.dll
  • Right click the dll file and click ‘Properties’
  • In the ‘General’ tab, at the bottom, there will be an ‘unblock’ button
  • Unblock the dll file and add it again in your project


IMPORTANT: You will need to add the following capabilities in your app for ads to appear!

  • ID_CAP_NETWORKING: Access to network services is required when requesting ads.
  • ID_CAP_WEBBROWSERCOMPONENT: Required since the AdView is a web browser.
  • ID_CAP_MEDIALIB_PLAYBACK: Provides access for currently playing media items.
  • ID_CAP_MEDIALIB_AUDIO: Provides read access to audio items in media library.


Now you can either add ads using XAML or via C#

How to add ads using XAML


Go to Toolbox in your Visual Studio and right click on general category and select Choose Items.



From the choose items dialog box tick AdView from Google Ads and click OK to include the control in the Toolbox.



Now you can view AdView control in the Common Controls list of the Toolbox. Select and drag it to place it anywhere in the page



Add the AdUnit ID you generated earlier to the control. The XAML should now look similar to this.
  If you have added the XAML code directly then a reference will be required for AdView control   xmlns:GoogleAds="clr-namespace:GoogleAds;assembly=GoogleAds"  

How to add ads using C#

  • Add the code below to display ads using C#
  • You can see the function admob(StackPanel stck ) takes a parameter which is the name of the stackpanel in which you wish to place your ad. Instead of a stackpanel you could use a Grid too.
  • Add the StackPanel in which you wish to place your ad in the XAML
  • Call the admob function in the page constructor as follows
  • The advantage of this procedure is that you could place multiple ads in different StackPanels or Grid just by changing the name of the StackPanel/Grid in the parameter


Here is how the app looks when you run it in the emulator.



Download full project Google