Adrotator / AdrotatorV2

A highly customizable ad rotator component for Windows Phone and Windows 8 platforms, supporting the XAML, WinJS, Silverlight, XNA and Monogame frameworks.
24 stars 22 forks source link

User Control utilising multiple Ad-size and secondary Id's #48

Open PythonesqueSpam opened 9 years ago

PythonesqueSpam commented 9 years ago

I'm developing a Windows 8.1 Store App and would like to implement a single user-control containing AdRotator and have it use multiple Ad-sizes and secondary Id's as provided by Microsoft pubCenter and AdDuplex. With the scarcity of updated online documentation for AdRotator V2, would someone please give me some pointers on how to achieve this.

UPDATE - Got it working just the way I needed...

To get AdRotator working the way I wanted to in my app I needed two things: 1 Multiple Ads per page. 2 Ads of various sizes.

After a great deal of testing I managed to get both working as follows:

Firstly I created a User Control:

<UserControl x:Name="MyUserControl"
    x:Class="Project.UserControls.Advert"
    ...
    xmlns:adRotator="using:AdRotator"
    mc:Ignorable="d">
    <adRotator:AdRotatorControl x:Name="MyAdRotatorControl" Background="DarkMagenta"
        Height="{Binding ElementName=MyUserControl, Path=Height}" 
        Width="{Binding ElementName=MyUserControl, Path=Width}"
        AdHeight="{Binding ElementName=MyUserControl, Path=Height}"
        AdWidth="{Binding ElementName=MyUserControl, Path=Width}"
        LocalSettingsLocation="{Binding ElementName=MyUserControl, Path=LocalSettingsLocation}"
        SlidingAdDirection="{Binding ElementName=MyUserControl, Path=SlidingAdDirection}"
        AdRetrievalMode="Stepped" IsAdRotatorEnabled="True" 
        AutoStartAds="True" HorizontalAlignment="Center" VerticalAlignment="Center" IsTest="True"/>
</UserControl>

In its Code behind I had:

public sealed partial class Advert : UserControl
{
    public static DependencyProperty LocalSettingsLocationProperty = DependencyProperty.Register("LocalSettingsLocation",
        typeof(string), typeof(Advert), new PropertyMetadata(new PropertyChangedCallback((s, e) => { })));
    public string LocalSettingsLocation
    {
        get { return (string)base.GetValue(LocalSettingsLocationProperty); }
        set { base.SetValue(LocalSettingsLocationProperty, value); }
    }

    public static DependencyProperty SlidingAdDirectionProperty = DependencyProperty.Register("SlidingAdDirection",
        typeof(AdSlideDirection), typeof(Advert), new PropertyMetadata(new PropertyChangedCallback((s, e) => { })));
    public AdSlideDirection SlidingAdDirection
    {
        get { return (AdSlideDirection)base.GetValue(SlidingAdDirectionProperty); }
        set { base.SetValue(SlidingAdDirectionProperty, value); }
    }

    public Advert()
    {
        this.InitializeComponent();
    }

    public void RegisterPlatformAdProviderComponents()
    {
        MyAdRotatorControl.PlatformAdProviderComponents.Add(AdRotator.Model.AdType.PubCenter, typeof(Microsoft.Advertising.WinRT.UI.AdControl));
        MyAdRotatorControl.PlatformAdProviderComponents.Add(AdRotator.Model.AdType.AdDuplex, typeof(AdDuplex.Universal.Controls.Win.XAML.AdControl));
    }

    public void DeRegisterPlatformAdProviderComponents()
    {
        MyAdRotatorControl.PlatformAdProviderComponents.Remove(AdRotator.Model.AdType.PubCenter);
        MyAdRotatorControl.PlatformAdProviderComponents.Remove(AdRotator.Model.AdType.AdDuplex);
    }

    public void Refresh()
    {
        MyAdRotatorControl.Invalidate(null);
    }
}

Each Ad can have it's own Settings File with Secondary Id's for different Ad Sizes. The LocalSettingsLocationProperty is used to specify the AdSettings file for each Ad and the Register, Deregister and Refresh methods can be used to, in effect, turn an Ad off and on again as required.

This works intermittently in my App with pubCenter and AdDuplex. The ads display dependent upon how often each page is re-viewed. I suspect it has something to do with the Ad replenish rate. Please can you advise on improvements on how best to engineer this?

SimonDarksideJ commented 9 years ago

First, all the documentation for AdRotator is on the http://GetAdRotator.com site :dancer: Additionally there is a full featured readme included with the NuGet package.

Right, the way AdRotator currently works is that each instance is intended to work with a single AdSize (purely a limitation at the moment with the way Ads are requested)

Other implementations have set up several instances of AdRotator for different sized ads from different providers (usually as different tiles).

If you have a more specific implementation idea we'd love to hear it in more detail and we'll see what we can do to help.

PythonesqueSpam commented 9 years ago

Hi Simon, You are of course correct and there is documentation on the site you referenced on how setup single Ads in an App and I downloaded and analysed the sample provided which shows how to get Ads of the same size on separate pages. I'm hoping to go a little more sophisticated with AdRotator and so ideally need more details on the control properties and events and the XML nomenclature for the Ad-settings. I looked at all online resources I could find but found that for v2, there appears to be some stuff missing (e.g AdGroups?). Maybe I missed it? Any help you provide is greatly appreciated and well done on a great project. Regards Stuart

SimonDarksideJ commented 9 years ago

Sorry for the delay in getting back to you @frontrunnersoftware

AdGroups is a place holder for future functionality (we standardised the configu XML with the features we want to add in V2, so we wouldn't introduce any breaking changes :D)

The rest of the config XML was described in some of the later posts on the AdRotator site (granted, we also need to include all that on the Wiki here, time willing :s

Have you made progress since your last message?