Overview
About Interstitial Ads
Interstitial ads are full-screen ads that cover the interface of your app. They are typically displayed at natural transition points in the flow of your app, such as between activities or during the pause between levels in a game. Some interstitial ads are rewarded ads.
About Rewarded Ads
Rewarded ads deliver a great user experience by offering users something of value in exchange for watching or engaging with an ad. This exchange is typically a reward within your app, such as extra lives in a game, virtual currency, or a hint in a puzzle (you determine the nature and amount of the reward). Shown at natural breaks in the app, rewarded video ads deliver high revenue, especially if you follow our recommendation to make them non-skippable.
Note that rewarded ads are in some cases referred to as incentivized ads; both terms always refer to the same kind of ad. Although "rewarded" is our preferred term, in the SDK code and in our Reporting API, we use the term 'incentivized'.
There are two ways to integrate rewarded ads: in-app rewards (recommended, and described below), or server-to-server callbacks (refer to our FAQ article on this topic). With in-app rewards, when a user successfully completes an ad view or clicks the download button, you can reward them directly in your app. The main benefit of this approach is that it's simple to implement. If you're looking for something quick, and you're not concerned with replay attacks, this should do it.
Vungle now offers a variety of ad formats with Dynamic Template ads. Unlike the traditional ad format, in which an ad play consists of a video play followed by an end card, we offer templates where the call-to-action (CTA) button is available during the video play. The users who complete the video ad, as well as those who click the button, should be rewarded.
Step 1. Complete Basic Plugin Integration
To integrate interstitial and rewarded ads in your Unity app, begin by following the instructions in the basic plugin integration article. This article contains supplementary information and assumes you have completed basic integration.
Step 2. Implement Event Handlers (Optional)
You can set up event handlers for all five Vungle SDK events surrounding ad presentation.
- The following event is fired when the SDK starts to play a video ad. This is a great place to pause gameplay, sound effects, animations, etc.
public static event Action onAdStartedEvent;
- The following event is fired when the SDK closes an ad. This is a great place to reward your users and resume gameplay, sound effects, animations, etc.
//For IOS & Android 6.9.1+
public static event Action<string> onAdEndEvent;
//For Windows. Also for IOS and Android 6.8.1 and below.public static event Action<string, AdFinishedEventArgs> onAdFinishedEvent;
- The
AdFinishedEventArgs
class consists of the following properties for you to check the result of an ad play:
public class AdFinishedEventArgs : EventArgs
{
//Represents a BOOL whether or not the user clicked the download button.
public bool WasCallToActionClicked{ get; set;}
//Represents a bool whether or not the video can be considered a completed view.
public bool IsCompletedView{ get; set;}
}
- The following event is fired when the SDK has changed ad availability status. The
isAdPlayable
boolean denotes the new playability of a specificplacementID
.
public static event Action<string, bool> adPlayableEvent;
Refer to the “Check Ad Availability for a Placement” section of this article for more details.
- The following event is fired when the SDK is initialized successfully.
public static event Action onInitializeEvent;
New Event Handlers for iOS & Android as of Unity 6.9.1.0
- The following event is fired when the ad's CTA button/action is taken.
public static event Action<string> onAdClickEvent;
- The following event is fired when the rewarded ad has completed.
public static event Action<string> onAdRewardedEvent;
- The following event is fired when an ad has finished playing and is closed
public static event Action<string> onAdEndEvent
Deprecated for iOS & Android as of Unity 6.9.1.0:
Vungle.onAdFinished(String id, boolean completed, boolean isCTAClicked);
Sample code:
void initializeEventHandlers()
{
Vungle.onAdStartedEvent += (placementID) => {
DebugLog ("Ad " + placementID + " is starting! Pause your game animation or sound here.");
};
Vungle.onAdFinishedEvent += (placementID, args) => {
DebugLog ("Ad finished - placementID " + placementID + ", was call to action clicked:" + args.WasCallToActionClicked + ", is completed view:"
+ args.IsCompletedView);
};
Vungle.adPlayableEvent += (placementID, adPlayable) => {
DebugLog ("Ad's playable state has been changed! placementID " + placementID + ". Now: " + adPlayable);
};
Vungle.onInitializeEvent += () => {
DebugLog ("SDK initialized");
};
//For iOS and Android only
Vungle.onAdClickEvent += (placementID) => {
DebugLog("onClick - Log: " + placementID);
};
//For iOS and Android only
Vungle.onAdRewardedEvent += (placementID) => {
DebugLog("onAdRewardedEvent - Log: " + placementID);
};
//For iOS and Android only
Vungle.onAdEndEvent += (placementID) => {
DebugLog("onAdEnd - Log: " + placementID);
};
}
Step 3. Load and Play an Ad
Load an Ad for a Placement
For all placements, call the loadAd()
method to load an ad.
public static void loadAd(string placementID)
Make sure that you are using the placementID
that is linked to the correct platform.
Sample code:
string placementID;
#if UNITY_IPHONE
placementID = "ios_placement_id";
#elif UNITY_ANDROID
placementID = "android_placement_id";
#elif UNITY_WSA_10_0 || UNITY_WINRT_8_1 || UNITY_METRO
placementID = "windows_placement_id";
#endif
Vungle.loadAd(placementID);
Check Ad Availability for a Placement
Once the SDK finishes caching an ad for a placement, the following event is called:
public static event Action<string, bool> adPlayableEvent;
Sample code:
Vungle.adPlayableEvent += (placementID, adPlayable) => {
if(placementID == "ios_placement_id") {
DebugLog("adPlayableEvent");
}
};
Note: For cache optimized placements, this event is called only when an ad becomes available. Optimized placements automatically attempt to fill without further action. For all other placements, this event is also called in case of “Load Failed” (adPlayable
returns false
in this case).
You can also check the ad availability for a placement with the following method:
public static bool isAdvertAvailable(string placementID);
Play an Ad
Important: Do not play an ad until the adPlayableEvent
function described above returns 'true'. If you try to play an ad before the adPlayableEvent
function returns 'true', the user experience will be adversely affected while the ad tries to load. If deploying to Android, instead use the value returned from isAdvertAvailable()
to ensure an ad is available (because the adPlayableEvent
will not return 'false' when no ad is available).
When there is an ad available for a placement, you can play the ad with the following method:
public static void playAd(string placementID);
Sample code:
Vungle.playAd(placementID);