How-to integrate AdDuplex interstitial ads into a Unity game

We are seeing more and more Unity games joining our cross promotion network. Some of them are housing AdDuplex banners and some are already benefiting from the newly introduced interstitial ads.

Interstitial ads are best applicable to games, since they occupy the whole screen and are usually displayed during natural pauses in app’s flow. It is quite a trivial task to include AdDuplex Interstitial ads into a game that is created using Mono Game, XAML or some other tool that depend on a straightforward Windows Phone page manipulation in Visual Studio (or Microsoft Blend for that matter). For Unity3D developers it might not be as simple.

Below is a guide describing one of the ways to do this. It consists of two steps: configuring the Unity project and configuring the Visual Studio solution created by it.

Configuring the Unity project

  1. Register your Windows Phone app in AdDuplex system and write down your Ad unit ID and App key.
  2. In Unity create a specific C# script and name it Interop.cs. It’s purpose is to provide a public event handlers that can be used to communicate with the actual XAML code-behind.https://gist.github.com/dariusvilcinskis/bf0a5969ecd1127fe6f3.js
  3. To load and show interstitial ad in Unity script call Interop.ShowInterstitial().https://gist.github.com/dariusvilcinskis/ead0269765a78d11a800.js
  4. To pre-load interstitial ad in Unity call Interop.LoadInsterstitial(). This is not required, since Interop.ShowInterstitial() can also download an ad, but it can be used to shorten loading times. https://gist.github.com/dariusvilcinskis/39b0cc6582639ba4ff59.js
  5. Subscribe to Interop.OnInterstitialClosed event to know when the user closes the ad. Be careful for what you do in the callback, because a lot of Unity engine functionality is non thread safe.https://gist.github.com/dariusvilcinskis/84d82940f22da57ded5b.js
  6. Build the Unity project (SHIFT + CTRL + B) into a Windows Phone 8 project

Configuring the build in Visual Studio

  1. Find and open the generated Visual Studio Solution
  2. Go to Tools -> NuGet Package Manager -> Package Manager Console (or Tools -> Library Package Manager -> Package Manager Console when in Visual Studio 2012 or below)
  3. Run the following command in the console to install AdDuplex dependencies: Install-Package AdDuplexWP8 (If you are building to Windows Phone XAML 8.1 (Universal) package please refer to Windows Phone 8.1 XAML AdDuplex Interstitial Ad Installation and Usage and change the namespaces accordingly.
  4. Add the following line to the Application_Launching (or OnLaunched if you are on Windows Phone 8.1 XAML Universal build) method in the App.xaml.cs file. Don’t forget to use your real AppKey!https://gist.github.com/dariusvilcinskis/089b720a56bd37fbc34e.js
  5. Open the MainPage.xaml.cs file and create a member of InterstitialAd type.https://gist.github.com/dariusvilcinskis/87842b176e00db77701c.js
  6. Locate the constructor method public MainPage() and add some code to subscribe to Interop events.https://gist.github.com/dariusvilcinskis/a930574f5213fb625b30.js
  7. Finally add code to manage the interstitials according to Interop commands and initialize the ad control. Don’t forget to fill in your AdUnitId here.https://gist.github.com/dariusvilcinskis/0522999b9d3f29999557.js

This is it. You can now build and test the project. Here is a sample project for Unity 5 that waits for a user tap to show an ad – GitHub AdDuplexUnity sample.

If you have ideas on improving this guide or need some help just drop a comment below or contact us via support.adduplex.com

How to add an ad removal button

AdDuplex ad control allows the developers to implement ad removal buttons. These can be beneficial in a number of ways – in terms of both customer satisfaction and monetary gain. For example, developers often employ a freemium monetization model where users are offered to buy an ad free version of the app.

Normally the ad control checks whether it is covered by other elements, but there is an exception. Some space on the top-right corner of the control is dedicated for your button.  You can see it in the Visual Studio or Expression Blend Designer view if you set the IsTest property to True.

There are a few caveats with the actual button implementation. Windows Phone Silverlight apps are a breeze to work with in this regard, because of how it manages pixels. In Universal Apps it’s a lot more complicated (not for long though).

We will demonstrate how to do it properly. For the sake of simplicity our ad removal button is going to be represented by a red rectangle. Following are two solutions, each for it’s own platform.

For Windows Phone Silverlight apps

This is the easier of the two. You get a 40x40px gap. Just put your button in it. 

1. Set IsTest to true

   1: <ad:AdControl IsTest="True"/>

2. Using the Visual Studio Designer as your guide position your button where you want it. Make sure you leave out the green area. If you fail to do that, the ad control will complain about it being covered and will not log impressions.

rectanglePositionedInDesigner

For Universal Apps

Sizing in Universal apps is trickier because of the use of effective resolution. Width and height no longer is represented in mere raw pixels. If you would set your ad removal button statically, it would not behave identically on all devices. You have to be more dynamic in Universal apps. Here is how:

1. Put both ad control and the button in a Grid panel. Bind Width and Height properties of the grid to those of the ad control (since it will resize dynamically). Align the button to the top-right corner of the grid.

<Grid x:Name="advertisingGrid" 

      Width="{Binding ElementName=adControl, Path=ActualWidth}"

      Height="{Binding ElementName=adControl, Path=ActualHeight}">

    <ad:AdControl x:Name="adControl"/>

    <Rectangle x:Name="closeButton" 

               Fill="Red"

               HorizontalAlignment="Right" VerticalAlignment="Top"/>

</Grid>

2. In code behind add the following method. It will calculate the proper button size.

private Size GetCloseButtonSize()

{

    var bounds = Windows.UI.Xaml.Window.Current.Bounds;

    var orientation = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().Orientation;

    var result = new Size();

 

    switch (orientation)

    {

        case Windows.UI.ViewManagement.ApplicationViewOrientation.Landscape:

            result.Width = bounds.Height;

            result.Height = bounds.Width;

            break;

        case Windows.UI.ViewManagement.ApplicationViewOrientation.Portrait:

            result.Width = bounds.Width;

            result.Height = bounds.Height;

            break;

        default:

            result.Width = bounds.Width;

            result.Height = bounds.Height;

            break;

    }

 

    result.Height = result.Width / 6.0f;

    result.Height = 35.0f * result.Height / 80.0f;

    result.Width = 35.0f * result.Width / 480.0f;

 

    return result;

}

3. In the constructor, after this.InitializeComponent() is called, use the GetCloseButtonSize() method to resize your button:

var closeButtonSize = GetCloseButtonSize();

 

this.closeButton.Height = closeButtonSize.Height;

this.closeButton.Width = closeButtonSize.Width; 

 

That’s it.

We’ve addressed the issue that this is more complex than it could be. A better solution is in the making along with more new features that we are very excited about.

Introducing conversion tracking (attribution)

Up to now you were able to see how many times your ads are shown in other apps and how many clicks they get. Monitoring your click-through rate can give you a good idea of which ad copy attracts user attention better and optimize your ads and campaigns. But whatever happened after the click was a mystery.

You had to rely on trying to deduct the effectiveness of your ads from the changes in your download numbers and, unless you were dedicating substantial budgets, it was really difficult to distinguish between the effect of your ads and organic fluctuations.

Today I’m happy to announce the immediate availability of our conversion tracking feature.

image

As you can see from the screenshot the feature is still in beta and is only available for Windows Phone apps and campaigns running AdDuplex SDK v.2 or higher.

How does it work?

Since the Windows Phone platform doesn’t provide reliable means to track users across apps, we had to implement our own “fingerprinting” technology to match those clicks to installs they generated using a set of secondary environment factors. For this reason the system cannot be 100% accurate.

Through our internal testing over the last couple of months we observed 85-90% accuracy. Finding the balance between false positives (attributing installs to wrong clicks) and false negatives (not attributing installs to clicks that generated them for some reason) was tough and we decided that we would rather underreport the installs than attribute conversions that didn’t happen. So when you look at the conversion stats it is safe to assume that the actual number is about 10% higher.

What information can I get from these stats?

For apps you can see the number of conversions and click-to-install ratio (so called install rate or IR).

For campaigns you get the number of conversions and IR, plus you get the same for each individual ad – so you can choose a perfect ad copy easier. We will also show you your cost-per-install so you can evaluate the effectiveness of your whole user acquisition strategy.

image

OK, what do I need to do to start seeing these stats?

Well, if you are doing cross-promotion using our SDK v.2 or higher AND you are promoting the same app as the one showing the ads AND you are using AdDuplex exclusively AND you are showing AdDuplex ads on the first/main page of your app, then you are all set and you don’t have to do anything else.

If you are doing cross-promotion targeting another app you have to make sure that the target app either uses AdDuplex exclusively and shows AdDuplex ad on the first page of the app, or you have to implement our tracking code into the target app (see below for the details).

For advertising campaigns you have to implement ads OR tracking code into your target app and you have to use direct store links as your campaign targets (you can’t use shortened URLs and other 3rd party URLs for now)

Implementing the tracking code

Your target app doesn’t have to participate in the AdDuplex cross-promotion network to take advantage of the conversion tracking feature. You just have to register the app in our system and call one method when your app launches. Something like this:

AdDuplex.AdDuplexTrackingSDK.StartTracking(“YOUR_AppId_HERE”);

The actual namespace varies a little depending on the development platform. Please see our Getting started guides for each specific platform for details.

Important: you have to call this method in cross-promotion apps too if they are not 100% AdDuplex

What’s next?

We will continue improving the algorithm to get you more accurate results. We will also bring conversion tracking to the Windows side of AdDuplex.

I hope that you find this feature useful and we would love to hear your thoughts on this feature in the comments below or via email at info@adduplex.com.