Unity Integration Documentation

 

1. API Key

Register your app on appmediation platform for obtaining API key

2. Download Unity package

Download latest Appmediation Unity package with all the new features and integration here

3. Integration Setup

3.1 Requirements

  • Unity 5+
  • Android API 16+
  • iOS 8.0+

3.2 Prepare your App

3.3 Import Plugin

Double click on the unity package to import it into your project. The package contains an example script inside.

[Android]: For Android, your project will probably hit ‘dex limit’ and application won’t compile. To solve this issue you will have to Enable Multidex.
[Android 2]: For Android, to add this lines to you mainTemplate.gradle file (add only lines in bold):

android {
    ....
    packagingOptions {
        pickFirst 'publicsuffixes.gz'
    }
}

3.4 SDK Initialization

3.4.1 GDPR (EU & EEA Users Only)

You need to obtain end-users’ consent from EU & EEA users before using our advertising services and refer to below options for it:

3.4.1.1 Smart Consent

By default, this feature is enabled and if you want to disable it you would have to call ‘ShowConsentMessageAutomatically(false)’ before displaying any ads. This feature checks request originating country and then displays a consent window before the first ad if its required.

3.4.1.2 Consent Window

We have developed a Consent Window option to make it easier to collect end-user consent. Each time when you’re required to collect end-user data consent call Consent Window

AMSDK.ShowConsentWindow ();

Note: You don’t need to call SetUserConsent method if you used ShowConsentWindow method.

3.4.1.3 Consent Function

Call this function to set user consent preferences and it’s highly suggested to set this method before initializing Appmediation SDK, otherwise the SDK will initialize with default false which can lead to non-personalised ads.

AMSDK.SetUserConsent (true);

3.4.2 SDK Initialization

Import namespace:

using AppMediation.Api;

Before loading ads, initialize the appmediation SDK by calling AMSDK.Init() with your app key. Your app key can be found on appmediation website inside “MY APPS” tab of your account.

AMSDK.Init (APP_KEY);

3.5 Interstitial Ads

Interstitial ads are full-screen ads that cover the interface of their host app. They can be full screen static interstitial ads or video ads.

// First create new interstitial instance, it is used to control ad behavior.
AMInterstitial interstitialAd = new AMInterstitial ();

// If you want to have more control over you ad behavior you can setup callbacks which are optional
interstitialAd.OnAdDidLoad += yourMethod1;
interstitialAd.OnAdDidFailToLoad += yourMethod2;
interstitialAd.OnAdDidShow += yourMethod3;
interstitialAd.OnAdDidClick += yourMethod4;
interstitialAd.OnAdDidClose += yourMethod5;

// Now you call call 'load' method of new ad instance to prepare new ad.
interstitialAd.Load ();

// After ad has been loaded you can call 'show' method to display it in you app.
if (interstitialAd.IsLoaded ()) {
     interstitialAd.Show ();
}

3.6 Rewarded Video

Rewarded video ads are full-screen video ads that users have the option of watching in full in exchange for in-app rewards.

// First create new rewarded video instance, it is used to control ad behavior.
AMRewardedVideo rewardedVideoAd = new AMRewardedVideo ();
// If you want to have more control over you ad behavior you can setup callbacks.
rewardedVideoAd.OnAdDidLoad += this.HandleOnAdDidLoad;
rewardedVideoAd.OnAdDidFailToLoad += this.HandleOnAdDidFailToLoad;
rewardedVideoAd.OnAdDidShow += this.HandleOnAdDidShow;
rewardedVideoAd.OnAdDidCompleteWithReward += this.HandleOnAdDidCompleteWithReward;
rewardedVideoAd.OnAdDidClick += this.HandleOnAdDidClick;
rewardedVideoAd.OnAdDidClose += this.HandleOnAdDidClose;

// Now you call call 'load' method of new ad instance to prepare new ad.
rewardedVideoAd.Load ();

// After ad has been loaded you can call 'show' method to display it in you app.
if (rewardedVideoAd.IsLoaded ()) {
     rewardedVideoAd.Show ();
}

3.6.1 Credit Reward

3.6.3.1 Client Side (SDK Callback)

When user has watched video completely then use “OnAdDidCompleteWithReward” callback to reward user.

private void HandleOnAdDidCompleteWithReward(object sender, AMRewardEventArgs args) {
    Debug.Log(": " + getAdFormatName(sender) + " OnAdDidCompleteWithReward event received: " + args.Amount + " " + args.Currency);
}

3.6.3.2 Server Side (S2S Callback)

We also support server side S2S reward callbacks to securely pass reward data. Server-to-server callbacks are sent to your server when a user has watched an ad. You can use these callbacks to reward players with virtual goods and to e.g. detect and prevent cheating.

By default its not enabled and you can enable them by following steps from here.

To use S2S Callback feature, you must set user ID by using AMSDK.SetUserIdentifier(“User#123”) method before SDK initialisation

 

3.7 Banner Ads

Banner ads are rectangular image or text ads that occupy a spot within an app’s layout. They stay on the screen while users are interacting with the app, and can refresh automatically after a certain period of time.

// First create new banner instance, it is used to control ad behavior.
AMBanner bannerAd = new AMBanner(AMBanner.Position.BOTTOM);

// If you want to have more control over you ad behavior you can setup callbacks which are optional
bannerAd.OnAdDidLoad += this.HandleOnAdDidLoad;
bannerAd.OnAdDidFailToLoad += this.HandleOnAdDidFailToLoad;
bannerAd.OnAdDidShow += this.HandleOnAdDidShow;
bannerAd.OnAdDidClick += this.HandleOnAdDidClick;

// Now you call call 'load' method of new ad instance to prepare new ad.
bannerAd.Load ();

// After ad has been loaded you can call 'show' method to display it in you app.
bannerAd.Show ();

4. Advanced Features

4.1 Test Mode

Test mode provides functionality to display test ads for integration testing and 100% fill.

AMSDK.SetTestMode (true);

4.2 Audience Data

It has the functionality to pass user data for more accurate ad targeting.

Function Name Field Type Field Description
SetGender String AMSDK.Gender
SetAge Integer User Age
SetLanguage String User Language
SetKeywords String Interests