Implementing the Ad Mediation in unity 3d Windows Phone 8/8.1 Games (silver light runtime)

Posted: November 24, 2014 in Uncategorized

Ad Mediation in unity 3D Windows Phone 8/8.1 Games or Apps

The Ad Mediator aims to maximize your revenue and improves the monetization by making sure you are always showing a live ad with higher fill rates. This extension enables different ad network solutions into a single project.

Mediation is a technique that enables your apps or games  to use multiple Ad-networks. This means, 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 depends on your logic.

The new ad mediation control for windows phone 8 provides a simple way to implement this capability. It offers a wide range of advantages over sticking with a single ad network, giving you control to integrate multiple Ads Networks and optimize them 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 (recommended 45-60 secs )
  • We can Pause/Resume ads
  • Disable ads option will improves the performance
  • Ad network prioritization (consider 80% for highest and 10% as low priority)
  • Ad network Optimization (can remove the unnecessary ad networks which offer low ecpm and fill rates)
  • Real time reporting
  • You are not guaranteed to get 100% fill rate
  • Simple and easy integration drag and drop
  • You can configure the rate of ads shown per provider through Dev Center

Windows ad mediation will help you:

  • Increase ad revenue through higher fill rates
  • Tailor ad experiences based on market-specific dynamics, using different ad SDKs
  • Dynamically optimize ad configuration to drive the highest yield

Step 1: Download and install the Windows Ad Mediator Extension for visual studio:

AdMediator

Microsoft Windows phone 8 Ad Mediator

First of  all, In order to set up the environment we have to install the connected service get the extension from here.

Step 2. Build the unity windows phone project by targeting windows phone 8 :

admediator_unityBuild

Unity windows phone build setting menu

Then open the generated project and right click on the project and click on the add->connected Service as follows

 

AddinMediator

Configuration for unity game (Adding ad mediator extension)

Step 3. Selecting and managing the Ads Networks :

After selecting the connected service Service Manager will be appeared and there you can set the required ads Networks if at all they are not fetched properly get them here.

AdMediatorServiceManager

Service Manager for selecting ads networks

As per the above pictorial representation choose the select ad networks option second option from top and select the required ads networks and hit OK Button you will find the following popup.

 

AddReferences

Ad Mediator Service Manager : Select ad Networks

Generally all the ads networks DLLs would be successfully added, if at all any thing is missing  they need to be added  manually.

Step 4. Add the Capabilities in the WMAppManifest file :

after adding all the required DLLs ,select the required capabilities in the WMAppManifest.xml. To do so just right click on WMAppManifest.xml file and select view code and replace the capabilities as follows:

<Capabilities>
<Capability Name="ID_CAP_IDENTITY_DEVICE" />
<Capability Name="ID_CAP_MEDIALIB_AUDIO" />
<Capability Name="ID_CAP_MEDIALIB_PLAYBACK" />
<Capability Name="ID_CAP_NETWORKING" />
<Capability Name="ID_CAP_SENSORS" />
<Capability Name="ID_CAP_WEBBROWSERCOMPONENT" />
<Capability Name="ID_CAP_IDENTITY_USER" />
<Capability Name="ID_CAP_LOCATION" />
<Capability Name="ID_CAP_MEDIALIB_PHOTO" />
<Capability Name="ID_CAP_PHONEDIALER" />
</Capabilities>

Step 5. Configure the add networks along with id and keys in service manager

As shown bellow we have to setup each and every add networks one by one,have to add the  ids and hit OK button.

Right click on project->add->Connected service->select the add network and click the configure option as follows

 

AdsmediatorConfig

Ad Mediator Configuration Settings

 

Step 6. Setup and Adding the Ad Mediator Controller by using ToolBox

Open the MainPage.xaml by double clicking on it, then open the ToolBox (short cut -> Ctrl+Alt+X)

AdmeditoControl

Ad Mediator Controller

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. 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 unity generated Windows Phone 8 Silver light application:

 <DrawingSurfaceBackgroundGrid x:Name="DrawingSurfaceBackground" Loaded="DrawingSurfaceBackground_Loaded">
 <WindowsPhone8:AdMediatorControl x:Name="CustomAdMediatorControl" HorizontalAlignment="Left" Height="80" Id="AdMediator-Id-573993CF-B98E-4430-B516-C39060D2F224" Margin="218,664,0,0" VerticalAlignment="Top" Width="480"/>
</DrawingSurfaceBackgroundGrid>

Note: I renamed the unique generated ad controller name “AdMediator_494E60” as CustomAdMediatorControl

Step 7. Handle the unhand-led exceptions  from Multiple ads networks 

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
 {
 if (e != null)
 {
 Exception exception = e.ExceptionObject;
 if ((exception is XmlException || exception is NullReferenceException) && exception.ToString().ToUpper().Contains("INNERACTIVE")) //inneractive
 {
 Debug.WriteLine("Handled Inneractive exception {0}", exception);
 e.Handled = true;
 return;
 }
 else if (exception is NullReferenceException && exception.ToString().ToUpper().Contains("SOMA")) //smato
 {
 Debug.WriteLine("Handled Smaato null reference exception {0}", exception);
 e.Handled = true;
 return;
 }
 else if ((exception is System.IO.IOException || exception is NullReferenceException) && exception.ToString().ToUpper().Contains("GOOGLE")) //Google
 {
 Debug.WriteLine("Handled Google exception {0}", exception);
 e.Handled = true;
 return;
 }
 else if (exception is ObjectDisposedException && exception.ToString().ToUpper().Contains("MOBFOX")) //mobfox
 {
 Debug.WriteLine("Handled Mobfox exception {0}", exception);
 e.Handled = true;
 return;
 }
 else if ((exception is NullReferenceException) && exception.ToString().ToUpper().Contains("MICROSOFT.ADVERTISING")) //microsoft
 {
 Debug.WriteLine("Handled Microsoft.Advertising exception {0}", exception);
 e.Handled = true;
 return;
 }

 }
 // APP SPECIFIC HANDLING HERE

 if (Debugger.IsAttached)
 {
 // An unhandled exception has occurred; break into the debugger
 Debugger.Break();
 }
 //e.Handled = true;
 }

Step 8. Finally, Call the ads to display from unity code and check them

In my previous post i mentioned about the basic communication between the unity game and native code,Here.

Now run the application will see the add on the bottom as follows

AdsScreenshot

Further, if you want to control the  adds depends on the screens just follow as bellow:


//To display the ads

CustomAdMediatorControl.Resume();

CustomAdMediatorControl.VerticalAlignment = VerticalAlignment.Top; //Display the ads on top

CustomAdMediatorControl.VerticalAlignment = VerticalAlignment.Bottom; //Display the ads on bottom

//To Hide the ads

CustomAdMediatorControl.Pause();

CustomAdMediatorControl.Visibility = Visibility.Collapsed;

//To Remove the Ads

if (CustomAdMediatorControl != null)
      CustomAdMediatorControl.Disable();//will remove the ads

Step 9. Congrats! Successfully completed,Let’s Optimize & mediate them in Dash board

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.

mediation

Add Mediation and Configuration , Dash board in Dev Center

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.

110814_0544_UsingAdMedi7

Base line Configuration & Mediation at Dev Center Dash board

 

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.

Note: Build a new app or existing app with Ad mediation and get the 500 reward point in DVLUP.

Thanks  !

Murthy Veera

Advertisements
Comments
  1. Aficionado says:

    Reblogged this on Aficionado's World and commented:
    A very nice blog on using Ad Mediation in Unity 3D

    Liked by 1 person

  2. An says:

    Great very helpful

    Liked by 1 person

  3. Daniel says:

    This looks great! Nevertheless, you are using this for small banners. What if I wanted an interstitial ad? How would you make it? Thanks!

    Like

    • murthyveera says:

      Hi Daniel,

      Use admob interstials directly for full screen ads, moreover through the admediater min you will get the $1 ecpm which is really cool than the admob banners.Send the full traffic to the pubcenter and use the admob as backup fill.For full screens in admob you will get the good ecpm min 1.5$ – 2 $

      Thanks!

      Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s