Skip to main content

Ads

Introduction


Plankton's advertising functionality allows you to effortlessly incorporate ads into your Unity games, facilitating game monetization and improving user engagement. In the latest Plankton release, ads can be displayed through two mediation options: AdMob Mediation and AppLovin MAX.

These mediations let you serve ads to your games from multiple sources, so they will maximize your fill rate and increase your monetization by sending ad requests to multiple networks to ensure you find the best available network to serve ads.

Supported Ad Formats:

  • Banner
  • Interstitial
  • Rewarded

Before you begin


Prerequisites

  • Complete the Plankton setup
  • For Android
    • Set Target API Level to 33 or higher
    • Set Minimum Api Level to 21 or higher
  • For iOS
    • Set Target Minimum iOS Version to 15.0 or higher
note

You can change Minimum and Target versions in Unity from Edit > Project Settings > Player > Other Settings

Set up your mediation account

Create and set up an account for each ad mediation you want to use.

AdMob

Set up your game in your AdMob account and create your desired ad units. After finishing the setup, you will have a unique AdMob App ID that is needed later in this guide.

AppLovin MAX

Set up your game in your AppLovin account and create your desired ad units. After finishing the setup, you will have a unique AppLovin SDK Key that is needed later in this guide.

info

You can use both of these mediations together in your game. For example you can show interstitial ads from AdMob, but show rewarded ads from AppLovin MAX.

Be aware that this multi-mediation feature is only applicable for different ad types, so it's not possible to use two mediations for the same ad type.

Confiure Plankton settings


  1. Open plankton settings by going to Edit > Project Settings > Plankton.
  2. Select the checkbox of your ad mediation. Below each mediation, there is an App Id field and several ad networks.
  3. Fill the App Id field with your AdMob App ID or AppLovin SDK Key
  4. Select ad networks that you have enabled in your mediation account. See available ad networks.

Implementation


Now it's time to write a few lines of code. Always import the Plankton package in your scripts.

using Plankton;

Initialize

Before starting to show ads, you have to initialize the Plankton.Ad class with your ad unit ids. For each ad format, you should pass a provider enum of type Ad.Provider along with a unit id string. Pass the values in the order demonstrated below:

var bannerProvider = Ad.Provider.Admob; // or Ad.Provider.AppLovin
var bannerUnitId = "<YOUR_BANNER_UNIT_ID>";

var interstitialProvider = Ad.Provider.Admob;
var interstitialUnitId = "<YOUR_INTERSTITIAL_UNIT_ID>";

var rewardedProvider = Ad.Provider.Admob;
var rewardedUnitId = "<YOUR_REWARDED_UNIT_ID>";

Ad.Initialize(bannerProvider, bannerUnitId, interstitialProvider, interstitialUnitId, rewardedProvider, rewardedUnitId);
note

If you don't use an ad format, pass an empty string for its unit id.

info

After calling initialize, Plankton will take care of the loading and preparation of ads, so you don't have to. Just show ads whenever you want. Plankton takes care of the technical details behind the scenes.

Banner ads are rectangular ads that occupy a small portion of an app's layout and are fixed at the bottom of the screen. They stay on screen while users are interacting with the app and refresh automatically after a certain period of time.

You can show and hide a banner ad by toggling the Ad.Banner value. The initial value is false.

To show a banner:

Ad.Banner = true;

and to hide it:

Ad.Banner = false;

That's all it takes!

Interstitial Ads

Interstitial ads are full-screen ads that are typically displayed at natural transition points or breaks in the flow of an app. When an app displays an interstitial ad, users can either tap on it to proceed or close it to return to the app.

Here's a sample code that shows how to display an interstitial ad:

Ad.Place adPlace = new Ad.Place(Ad.Type.Interstitial, "<AD_PLACEMENT>");
Action onAdClosed = () => {
Debug.Log(Debug.Log("Interstitial ad closed"));
};

Ad.ShowInterstitial(adPlace, onAdClosed);

The Ad.ShowInterstitial method takes two arguments:

  • An Ad.Place which specifies the type and the placement of the ad.

  • An Action which is called after the ad is closed. It means that either the user watched the ad and closed it or the ad was not displayed at all.

What is a placement?

A placement is a short string specifying the location of the ad being displayed. Placements are usually used for data analysis or user attribution purposes.

Common interstitial ad placements include:

  • When a player reaches the end of a level: for example end_of_level

Common rewarded ad placements include:

  • When a player watches an ad to get free coins: for example free_coins
  • When a player watches an ad to unlock a bonus item: for example unlock_bonus
tip

Interstitial ads should be displayed during natural pauses in the flow of an app. Between levels of a game is a good example, or after the user completes a task.

Rewarded Ads

Rewarded ads are full-screen ads that allow you to reward users with in-app items for interacting with video ads, playable ads, and surveys.

Here's how you can display a rewarded ad:

Ad.Place adPlace = new Ad.Place(Ad.Type.Rewarded, "<AD_PLACEMENT>");
Action<bool> onAdClosed = rewardEarned => {
Debug.Log($"Rewarded Ad Closed. User earned reward: {rewardEarned}");
};

Ad.ShowRewarded(adPlace, onAdClosed);

The Ad.ShowRewarded method takes two arguments:

  • An Ad.Place which specifies the type and placement of the ad.

  • An Action<bool> with a boolean input which is called after the ad is closed. It means that either the user watched the ad and closed it or the ad was not displayed at all. The boolean value indicates whether the user has earned the reward or not.

Check if an ad is ready to show

To ensure the ad is loaded before showing interstitial and rewarded ads, you can call Ad.IsLoaded.

bool isInterstitialLoaded = Ad.IsLoaded(Ad.Type.Interstitial)

bool isRewardedLoaded = Ad.IsLoaded(Ad.Type.Rewarded)
tip

Plankton loads and prepares interstitial and rewarded ads automatically. Before attempting to display the ad, it's best to check if the ad is loaded as the loading process can take a few seconds.

Test and debug


Both AdMob and AppLovin provide their own debugging tools which can be used at runtime to test and debug the advertisement feature.

Admob Ad Inspector

AdMob's Ad Inspector is an in-app overlay that enables authorized devices to perform real-time analysis of test ad requests directly within a mobile app.

To display it in your game, make the following call:

Ad.OpenAdMobDebugger();

You can read more about AdMob's Ad Inspector.

AppLovin Mediation Debugger

AppLovin's Mediation Debugger is a suite of testing tools that help you integrate and launch faster with MAX. You can use them to confirm the validity of network integrations. This ensures that you can successfully load and show ads, among other things.

To display it in your game, make the following call:

Ad.OpenAppLovinMaxDebugger();

Available Ad networks


AdMob mediation

  • Android

    • AppLovin
    • Chartboost
    • DT Exchange (Fyber)
    • ironSource
    • Liftoff (Vungle)
    • Meta (Facebook)
    • Mintegral
    • Pangle
    • Premium Ads
    • Unity Ads
  • iOS

    • AppLovin
    • ironSource
    • Liftoff (Vungle)
    • Meta (Facebook)
    • Mintegral
    • Pangle
    • Premium Ads
    • Unity Ads

AppLovin MAX mediation

  • Android

    • AdMob
    • DT Exchange (Fyber)
    • ironSource
    • Liftoff (Vungle)
    • Meta (Facebook)
    • Mintegral
    • Pangle
    • Premium Ads
    • Unity Ads
  • iOS

    • AdMob
    • Google Ad Manager
    • ironSource
    • Liftoff (Vungle)
    • Meta (Facebook)
    • Mintegral
    • Pangle
    • Premium Ads
    • Unity Ads
Need other networks?

If you need other ad networks that are missing in our list, please let us know at our Discord server or via Email.

API Refrences


Defined Types

In this section, we will discuss the enumerated types, variables, and classes associated with this feature:

Enums

Ad.Provider
ValuesDescriptionUsage
AdmobYou can use Admob mediation as an ad mediation SDK in your game.Ad.Provider.Admob
AppLovinYou can use AppLovin Max as an ad mediation SDK in your game.Ad.Provider.AppLovin
Ad.Type
ValuesDescriptionUsage
NullSpecifies no ads.Ad.Type.Null
InterstitialSpecifies full-screen ads that appear at natural breaks or transition points within an app.Ad.Type.Interstitial
RewardedSpecifies ads that offer users a reward, such as in-app currency or extra content, in exchange for engaging with the ad.Ad.Type.Rewarded
BannerSpecifies small, rectangular ads displayed at the bottom of an app's interface.Ad.Type.Banner

Classes

Ad.Place
Field NameField TypeDefault ValueField Description
typeAd.TypeAd.Type.NullSpecifies the type of the ad
namestringstring.EmptySpecifies the name of the ad place

Properties and Delegates

Properties
NameTypeDefault ValueDescription
Bannerbool falseWe use this to show and hide the banner ad.
FreezTimeWhenShowingAd bool trueYou can use this property to freeze time when showing ads.
IsOnline bool trueUse this to check if the user is online.
Delegates
NameTypeDefault ValueDescription
CanShow Func<Place, bool>nullSet additional logic for an Ad.Place to show

Methods Summaries

MethodArgumentsReturn TypeDescription
InitializeProvider bannerProvider,string bannerZoonId,Provider interstitialProvider,string interstitialZoonId,Provider rewardedProvider,string rewardedZoonIdvoidYou have to initialize “Ad” before trying to show ads. Call this function before any attempt to request ads.
IsLoadedType adTypeboolThis method checks if an ad is loaded and can be shown.
ShowRewardedPlace adPlace,Action<bool> onAdClosed = nullvoidThis method shows a rewarded ad and gets a callback which is called when the ad is closed and has a bool as an argument that tells you if the user has earned the reward.
ShowInterstitialPlace adPlace,Action onAdClosed = nullvoidThis method shows an interstitial ad and gets a callback which is called when the ad is closed.
OpenAdMobDebugger(no arguments)voidIt opens Admob Ad Inspector for debugging Admob.
OpenAppLovinMaxDebugger(no arguments)voidIt opens Applovin Max Mediation Debugger for debugging Applovin Max.