Opt-in Video Ad

This article will go through all the steps required to display an Opt-in Video ads in your application.

Opt-in Video Ads are skippable fullscreen videos. They allow you to reward users with in-app items for watching video ads.

Opt-in Video Ads can only be served to users who explicitly and previously chose to view a rewarded ad. You can specify the reward values associated with the Ad units in your application and set different rewards for different Ad units.

Once configuration is done, users start receiving the reward for viewing the video ads without needing to install anything on their device.

Requirements

You have registered an application on your Ogury Dashboard. If not, please refer to the Getting Started section before the next steps.

Step 1: Create Opt-in Video Ad ad units

In case you publish your application on Android and iOS, you should do the following steps twice, once for the Android application and once for the iOS application. Otherwise just select the platform you publish for.

In all the following code samples, we will refer to:

  • the Ad unit id for the Android application by using the string ANDROID_AD_UNIT_ID.

  • the Ad unit id for the iOS application by using the string IOS_AD_UNIT_ID.

Step 2: Load an Opt-in Video Ad

The Ogury SDK provides the OguryOptinVideoAd object that lets you load, display and control your Opt-in Video Ads.

Instantiate an Opt-in Video Ad

  • Declare a OguryOptinVideoAd instance variable in the Scene where you want to display an Opt-in Video Ad:

private OguryOptinVideoAd _optinVideo;
  • In the Start method of your scene, instantiate the Opt-in Ad:

void Start() {
    // ...
    _optinVideo = new OguryOptinVideoAd("ANDROID_AD_UNIT_ID", "IOS_AD_UNIT_ID");
}

OguryOptinVideoAd takes the following parameters:

  • the Ad unit id for the Android application. You can use null if your application is not available on Android.

  • the Ad unit id for the iOS application. You can use null if your application is not available on iOS.

Register an event to reward the user

To reward your users when they watched the video, you need to register to the OnAdRewarded event just after the instantiation of the OguryOptinVideoAd:

_optinVideo = new OguryOptinVideoAd("ANDROID_AD_UNIT_ID", "IOS_AD_UNIT_ID");
_optinVideo.OnAdRewarded += (ad, rewardItem) =>
{
    // reward the user here
    Debug.Log("User has received reward '" + rewardItem.Name 
            + "' with value: " + rewardItem.Value);
};

The OguryRewardItem object has two string properties:

  • name: Name

  • value: Value

You can set their values in the Reward setting section.

The Ogury SDK exposes other events to follow the lifecycle of an Opt-in Video Ad. You can find their description in the Events section.

Load an Opt-in Video Ad

To start loading an ad, call the Load method:

_optinVideo.Load();

Since it may take a few seconds to fetch the ad resources (video, image, ...) from the network, you should call the Load method as soon as possible after getting the user's consent.

Ideally, you should implement one of the two following examples depending on your use case:

  • Call the Load method right after the Initialize method in the script that also collects the consent:

using OgurySdk;
using OgurySdk.ConsentManager;

public class MyScene : MonoBehaviour {

    private OguryOptinVideoAd _optinVideo;

    void Start() {
        Ogury.Start("ANDROID_ASSET_KEY", "IOS_ASSET_KEY");
        
        _optinVideo = new OguryOptinVideoAd(
            "ANDROID_AD_UNIT_ID",
            "IOS_AD_UNIT_ID"
        );
        
        // get user consent
        OguryConsentManager.OnAskComplete += OnCMComplete;
        OguryConsentManager.OnAskError += OnCMError;
        OguryConsentManager.Ask();
    }
    
    private void OnDestroy() {
        OguryConsentManager.OnAskComplete -= OnCMComplete;
        OguryConsentManager.OnAskError -= OnCMError;
    }
    
    private void OnCMComplete() {
        PassConsentToOtherSdks();
        StartSdks();
        // load ad formats
        LoadAdFormats();
    }

    private void OnCMError(OguryError error) {
        PassConsentToOtherSdks();
        StartSdks();
        // load ad formats
        LoadAdFormats();
    }
    
    private void StartSdks() {
        Ogury.StartAds();
        // start vendors' SDKs
    }
    
    private void PassConsentToOtherSdks() {
        // pass user consent to vendors' SDKs
    }
    
    private void LoadAdFormats() {
        // load the opt-in video ad
        _optinVideo.Load();
    }
}
  • Call the Load method in the Start method of your other script:

private void Start() {
    _optinVideo = new OguryOptinVideoAd("ANDROID_AD_UNIT_ID", "IOS_AD_UNIT_ID");
    _optinVideo.Load();
}

Additionally, if you want to follow the lifecycle of the Opt-in Video Ad, you can register to events.

Step 3: Show an Opt-in Video Ad

To display the ad, call the Show method:

_optinVideo.Show();

If the method fails to show the ad, one of the following events is triggered:

  • OnAdNotLoaded: if the ad was not fully loaded when Show was called.

  • OnAdError: if another error occurred. Error codes are explained below.

Step 4: Test your integration

Ogury exclusively serves ads to users who have given consent. It is essential to have responded to a valid TCFv2 consent form before conducting any tests.

As our algorithm works with personified targeting, you may not receive any ad while testing your application.

You can test your integration by adding the suffix _test to your interstitial ad unit id, for more details go to Test your implementation page.

Note that if you have just registered your application in the Ogury Dashboard, it will take around 15 minutes until you can successfully load an ad.

If you are not able to display any Opt-in Video Ad, we recommend you to log every events on your OguryOptinVideoAd to follow the lifecycle of the Opt-in Video Ad:

  • If you encounter the OnAdError event, you can check the error codes section below to understand the error and get some advice on how to solve the issue.

  • If you encounter the OnAdNotAvailable event, you can check the test ad section to learn how to display test ads in your application.

Advanced Topics

Check if an ad is ready to be displayed

Call the following method to check if an Opt-in Video Ad is ready to be displayed:

_optinVideo.Loaded

If you want to be informed when the ad is ready to be displayed, you can also register to the OnAdLoaded event.

Events

The Ogury SDK provides events to listen to the lifecycle of an Opt-in Video Ad instance.

To register to an event, add the following code just after instantiating the OguryOptinVideoAd:

_optinVideo.OnAdLoaded += ad =>
{
    // ...
};

The OguryOptinVideoAd exposes the following events:

Methods

Definition

OnAdNotAvailable

The ad server does not have an ad to present to the user. Note that during the integration, you can force the Ogury SDK to always display a test ad. More details can be found in the test ad section.

OnAdLoaded

The SDK is ready to display the ad provided by the ad server.

OnAdNotLoaded

The ad failed to display because it was not fully loaded when theShow method was called.

OnAdDisplayed

The ad has been displayed on the screen.

OnAdImpression

The ad has triggered an impression.

OnAdClosed

The ad has been closed by the user.

OnAdError

The ad failed to load or display. An additional error parameter of type OguryError contains the reason of the failure. All error codes are detailed in the section below.

Error codes

When an ad fails to load or to be displayed, the SDK will trigger the OnAdError event with an OguryError as additional parameter. The OguryError provides the ErrorCode property to retrieve the error code:

error.ErrorCode

Error codes related to Opt-in Video Ad are defined in the OguryAdsErrorCode class:

Code

Value

Definition

NoInternetConnection

0

The device has no internet connection. Try again when the device is connected to the Internet again.

LoadFailed

2000

The ad failed to load for an unknown reason.

AdDisabled

2001

Ad serving has been disabled for this placement/application.

AdExpired

2002

The loaded ad is expired. You must call the show method within 4 hours after the load.

ProfigNotSynced

2003

An internal SDK error occurred.

SdkInitNotCalled

2004

The Start and/or StartAds methods have not been called before a call to the Load or Show methods.

SdkInitFailed

2005

An error occurred during the initialization of the SDK.

ActivityInBackground

2006

You tried to Show an ad while the application was in background. Make sure to only call theShow method when the application is visible to the user.

AnotherAdAlreadyDisplayed

2007

Another ad is already displayed on the screen.

The OguryError may provide additional details for the issue. You can access them using following property:

error.Description

Integration Sample

Checkout our sample applications in our GitHub repository :

Opt-in Video Example

Last updated