Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use an AdControl with multiple AdUnitIds?

Is it possible to use one AdControl in a Windows 8.1 app with multiple AdUnitIds? I followed the approach from different sources on the net to get the AdControl somewhat working, but now I've found out (after adding an event handler to the AdControls ErrorOccurred event) that the error code is NoAdAvailable, meaning that for the selected category no ads are being served (I'm in Germany). The code for my AdControl looks like this:

        AdControl adControl = new AdControl
                    {
                        ApplicationId = "a1b2c3d4-1a2a-1234-1a2a-1a2b3c4d5e6f",
                        AdUnitId = "123456",
                        HorizontalAlignment = HorizontalAlignment.Left,
                        Height = 250,
                        VerticalAlignment = VerticalAlignment.Top,
                        Width = 250
                    };
        adControl.ErrorOccurred += adControl_ErrorOccurred;

According to the information shown in Microsoft's pubCenter, the ApplicationId stays the same (as expected) when I add multiple categories for ads, but the AdUnitId changes. How would I go about using ads from multiple categories, is there a simple solution? Or would I have to try instantiating an AdControl while changing the category (and therefore the AdUnitId until I won't get an exception anymore and then use that one? What would be the best approach?

Update

You are not allowed to change the AdUnitId once it's been set, so this won't work.

Update 2

I am still not sure if everything is set up correctly - when I start my app (installed from the Windows App Store), I always get a "NoAdsAvailable" error. The category from which ads should be shown is "Games", so the error message suggests that (for my region) there are no ads from that category. When I use different apps with advertising, they show ads which must be from the games category, so somehow I fear I might not have everything set up correctly.

Does anyone have an idea?

like image 782
Gorgsenegger Avatar asked Dec 29 '14 20:12

Gorgsenegger


1 Answers

You will need to use logic to decide which AdUnitId to use at any given moment. This includes picking different values for different categories for the live application, but also picking one of the Test Mode Values for both AdUnitId and ApplicationId, seen here, for the development version. This is to prevent click fraud.

This page shows how to use a compiler pre-processor directive to ensure you only use test mode values in the debug version of your application.

Be warned! If you try and use live ad ID's in a debug app too often, especially if you click/press the adverts, your advertising id could be suspended.


For a website:

If your site involves people clicking links regularly, I'd probably just settle on generating a different AdUnitId each time the page loaded.

However if you have a page which is expected to be viewed statically for a long time, I'd use AJAX to pull in a 'page' that just has the AdControl on, and randomly select or rotate the AdUnitId, ensuring a new advert is served up every couple of minutes.

Just be careful that this is not done at an excessive rate, and that the ads are shown clearly to the user, to avoid any impression of click fraud attempts.


For a store app: (apologies, my brain misfired :)

For a store app, simply recreate a new AdControl with the next AdUnitId on a long timer, and add the control. Hide the old control, and then dispose of it properly.

like image 101
Octopoid Avatar answered Nov 20 '22 13:11

Octopoid