This project is read-only.

Windows Phone Unified Ad Control

With support for:
- PubCenter
- AdMob
- Smaato
- MobFox
- AdDuplex
- InnerActive (expiremental)
- MillenialMedia (experimental)
- None
- GenericAdProviderForXaml


The best way to install the Unified Ad Control is through NuGet.

To install Unified Ad Control for Windows Phone, run the following command in the Package Manager Console

PM> Install-Package wpunifiedad

Wait there’s much more…

Just pick the ad providers you would like to use and fill in the provided values like AdUnit and Publisher for that provider. You no longer need to know the inner workings of the specific AdProvider. It’s hidden by the unified ad control.

So you want the ad providers in testmode? Just set IsTest to true on the unified AdControl. This though every ad provider has it’s own way of implementing IsTest, like clearing AdUnit or using a specific Publisher or even adding the DeviceID to a specific collection. You no longer need to know how.

So you want to know if an ad is engaged (clicked)? Just listen to the AdEngaged event on the unified AdControl, you will get the name of the ad provider in the AdEventArgs. This works across all ad providers even though each of them have different events that you have to listen to, the unified AdControl helps out. You no longer need to know how.

So you want to know if an new ad is shown? Just listen to the NewAd event on the unified AdControl, you will get the name of the ad provider in the AdEventArgs.

So you want to provide the country to the ad providers such that they show local ads? By default the country is retrieved from the phones culture and passed to the different ad provider implementations. But you’re still able to override it, or even tell it to not use the country at all.

But what if I only use for example MobFox and Smaato, do I have to ship all the other AdProviders? No not at all, you’ll only ship what’s required.


Because the ad provider market isn’t standing still, new ad providers will be available in the future. If you want to use such a new ad provider, you can either implement it yourself by implementing IAdProvider (or BaseAdProvider), or leave a little bit of feedback and I’ll implement it.

Ad Provider Choosing strategies

The UnifiedAdControl supports two choosing strategies. The default strategy is a basic strategy that rotates between the adproviders. Once an adprovider isn’t providing an Ad it will rotate to the next AdProvider.

A more advanced strategy is the RemoteAdProviderStrategy which reads an xml configuration to choose the AdProviders to rotate between, but all selected by Country. This enables different adproviders for different countries to get the best revenue for you. Further more you can ad a local Xml Configuration and a remote Xml Configuration. The remote Xml Configuration will enable you to change the AdProviders to choose per Country without publishing to the marketplace.

Enabling the RemoteAdProviderStrategy is done like this:

<Ads:AdControl x:Name="AdWithLocalXmlAndRemoteXml"




        <!--the configuration of all the adproviders-->



        <Strategy:RemoteAdProviderStrategy LocalProviderSettingsUri="Ads/AdSettings.xml"

            RemoteProviderSettingsUri="" />



The structure of the configuration file is similar to wp7adrotator but a little bit different because only the ISO country codes are used during configuration.

<?xml version="1.0" encoding="utf-8" ?>



    <AdCountryDescriptor Country="US">

      <Probability Value="70" AdProvider="None" />

      <Probability Value="10" AdProvider="AdMob" />

      <Probability Value="10" AdProvider="MobFox" />

      <Probability Value="10" AdProvider="AdDuplex" />


    <AdCountryDescriptor Country="GB">

      <Probability Value="50" AdProvider="None" />

      <Probability Value="50" AdProvider="MobFox" />>



      <Probability Value="20" AdProvider="PubCenter" />

      <Probability Value="20" AdProvider="AdMob" />

      <Probability Value="20" AdProvider="AdDuplex" />

      <Probability Value="20" AdProvider="Smaato" />

      <Probability Value="20" AdProvider="MobFox" />




In case you already have settings in place for the wp7adrotator you can use these configuration files as well.

If you have a very different way of choosing ad providers you can implement your own AdProviderStrategy.

Ad Rotation with “None”-AdProvider

If you want true ad rotation you would probably want to rotate between the different ad providers when a particular ad provider doesn’t provide ads for the moment. Even though you could for example say that in 50% of the chances you don’t want to show an ad, after a minute there should again be a 50% chance for not showing an ad, but also 50% chance of showing an ad. To support this, the None ad provider is essentially an ad provider that fires a NoAd event after 60 seconds. Currently the wp7adrotator doesn’t show any ads after the None is selected until the application is restarted because it’s not implemented as an Ad Provider.

Generic AdProvider to show Xaml

Quite often you will want to put in your own ad when none of the other ads have anything to show. That’s where the GenericAdProviderForXaml comes in. You can set the XamlUri to some place on the internet where the Xaml can be downloaded. The Xaml can’t have  a codebehind but you can reference the standard Theme Resources for Windows Phone. If you want to navigate to a url you can use the NavigateUri of an HyperlinkButton, though normally the HyperlinkButton doesn’t support any external urls, it does in this GenericAdProvider.

Example remote xaml:

<Grid xmlns=""



      Background="{StaticResource PhoneBackgroundBrush}">

    <Border BorderBrush="{StaticResource PhoneAccentBrush}"



            <TextBlock Text="WP Unified Ad"

                       Foreground="{StaticResource PhoneAccentBrush}" Margin="0"

                       VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="35"/>

            <HyperlinkButton NavigateUri=""







To get this working upload xaml like the above to a website and add the following AdProvider to the AdProviders collection of the AdControl. Don’t forget to set the XamlUri to the correct location.

<Provider:GenericAdProviderForXaml XamlUri=""/>

If you want to provide alternative content in case the content can’t be fetched (no internet connection for example) you can also set the FallBackContent property of the GenericAdProvider to different xaml. By default no ad will be shown. If you ad the string-argument {0}, it will be filled with the ProductID, this will help you create serverside code that makes sure not to show particular ads in this app.

Last edited Jun 22, 2012 at 7:37 AM by mkamonster, version 11