Did you read the previous parts?
Part 1 – Introduction
Part 2 – Basic Usage
Done? Let’s continue with Part 3, configure the Ad Providers from a remote location.
Step 1, Add the RemoteAdProviderStrategy
Okay, let’s forget about the default AdProviderStrategy. The default just rotates between the different AdProviders, we want more. First we set the AdProviderStrategy property of the AdControl. Just like this.
<Ads:AdControl.AdProviderStrategy>
<Strategy:RemoteAdProviderStrategy xmlns:Strategy="clr-namespace:MC.Phone.Ads.Strategy;assembly=MC.Phone.Ads" />
</Ads:AdControl.AdProviderStrategy>
Step 2, Create a configuration file
It could very well be that you already have a functional configuration file. When you for example made use of Windows Phone 7 Ad Rotator you already have a configuration file that’s fully compatible with the Unfied Ad. But if you want the full power of the Unified Ad you have to use a different configuration file structure. Xml files explain best by showing an example file.
<?xml version="1.0" encoding="utf-8" ?>
<AdSettings>
<CountryDescriptors>
<AdCountryDescriptor Country="US, GB">
<Probability Value="70" AdProvider="None" />
<Probability Value="10" AdProvider="AdMob" />
<Probability Value="10" AdProvider="MobFox" />
<Probability Value="10" AdProvider="AdDuplex" />
</AdCountryDescriptor>
<AdCountryDescriptor Country="DE">
<Probability Value="15" AdProvider="PubCenter" />
<Probability Value="15" AdProvider="AdMob" />
<Probability Value="20" AdProvider="AdDuplex" />
<Probability Value="50" AdProvider="None" />
</AdCountryDescriptor>
<AdCountryDescriptor>
<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" />
</AdCountryDescriptor>
</CountryDescriptors>
</AdSettings>
Let examine the last AdCountryDescriptor element lines 16-22. Because this AdCountryDescriptor element doesn’t have a Country property this will be the default configuration to fall back to when there isn’t any other that matches the country of the user.
Inside the AdCountryDescriptor elements there are Probabilty elements, they consist of two values: a probability and an AdProvider name. You can best compare the Probabilty with the chance in percentage that the specific Ad Provider is chosen during AdRotation. If you don’t want an AdProvider to be shown during rotation you either put the probability to 0, but better just remove the element. The AdProvider property is the name of the AdProvider that has to be filled in. Currently that would be one of these AdProviders: AdMob, MobFox, AdDuplex, PubCenter, Smaato, InnerActive, None and GenericAdProviderForXaml.
If you want no ads to be displayed for a certain percentage of the time you should use the None AdProvider. In a future post we will discuss the GenericAdProviderForXaml, for now just see it as a remote location where you put some Xaml that will be displayed as an Ad.
So we now have a default configuration, what about specific country configurations? Yes important of course, by specifying the Country attribute of the AdCountryDescriptor element you can specify to which countries a specific configuration belongs. Which could be one country, or multiple countries. Each country is only allowed once in the configuration but you can specify multiple countries for one configuration by separating the country-codes by a “,”. For the country-codes make sure you use the two-letter codes from the ISO_3166-1, so for the UK this is GB.
Step 3, Where to put this configuration file?
Put it somewhere on a webserver where it’s accessible through http or https. Though if you don’t want to configure it remotely but ship this Xml file as part of your application that’s fine as well. But be aware that the only way to change your shipped configuration file is by shipping a new version of your application. But to have local configuration file makes sense even if you have a remote configuration file. When for example your remote config file cannot be accessed (could be any reason) the RemoteAdProviderStrategy will fallback to the local configuration file. So let’s configure the strategy accordingly.
<Ads:AdControl.AdProviderStrategy>
<Strategy:RemoteAdProviderStrategy xmlns:Strategy="clr-namespace:MC.Phone.Ads.Strategy;assembly=MC.Phone.Ads"
LocalProviderSettingsUri="Ads/AdSettings.xml"
RemoteProviderSettingsUri="http://someurlinthewild.com/ads.xml" />
</Ads:AdControl.AdProviderStrategy>
The RemoteProviderSettingsUri needs to be filled with the remote location url. So put the file somewhere on an internet website, your own is probably the best so that you can easily change it when you want to. The local provider settings can be used as alternative to the remote location in case you don’t want to remotely configure your ads but it could also be used as fallback when the remote url is not available for some reason. For the LocalProviderSettingsUri you need to be aware that it’s an ResourceUri, not an internet Uri. This means that if your xml file has a BuildAction “Content” you can put a simple relative Uri in there, like in the above example. If you would add the Xml file with BuildAction “Resource” you would have to use an Uri like this “/MC.Phone.Ads.Example;component/Ads/AdSettings.xml”.
Hope this explains the Remote Ad Provider configuration a little bit. Please post any questions.