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 the 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 an Opt-in Video Ad ad unit
In all the following code samples, we will refer to this Ad unit id by using the string YOUR_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 an
OguryOptinVideoAd
instance variable in theActivity
where you want to display an ad:
In the
onCreate
method of theActivity
, instantiate the Opt-in Video:
OguryOptinVideoAd
takes the following parameters:
a reference to any kind of Context.
the Ad unit id of the Opt-in Video Ad. If you do not have one yet, you can refer to the first step to create it.
Register a listener to reward the user
To reward your users for watching a video, you need to register an OguryOptinVideoAdListener
listener just after the instantiation of the OguryOptinVideoAd
:
The OguryReward
object has two String attributes:
name:
getName()
value:
getValue()
You can set their attributes in the Reward setting section of the Ogury Dashboard.
The OguryOptinVideoAdListener
exposes other methods to follow the lifecycle of an Opt-in Video Ad. You can find their description in the Listener section.
Load an Opt-in Video Ad
To start loading an ad, call the load
method:
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.
Ideally, you should implement one of the two following examples depending on your use case:
Call the
load
method right after theOgury.start()
method in theActivity
:
Call the
load
method in theonCreate
method of your otherActivity
:
Step 3: Show an Opt-in Video Ad
To display the ad, call the show
method:
If the method fails to show the ad, the onAdError
callback is called.
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 callbacks of the OguryOptinVideoAdListener
interface to follow the lifecycle of the Opt-in Video Ad. If you encounter the onAdError
callback, you can check the Error codes section below to understand the error and get some advice on how to solve the issue.
Additionally, you can follow the integration logs to get useful information on your integration status and any issue that might occur when displaying ads.
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:
If you want to be informed when the ad is ready to be displayed, you can also register a listener and override the onAdLoaded
method.
Server-side reward callback
Additionally to calling the onAdRewarded
callback, Ogury can notify your server when a user must be rewarded. As an example, it can be used to secure your rewarding logic if the user receives a reward equivalent to your in-app purchase currency.
In this case, the Ogury servers send an HTTP GET request to a callback URL when the user has to be rewarded. The next section goes through the configuration of the callback URL in the Ogury Dashboard.
Configure the callback
To configure the callback in the Ogury Dashboard:
Go to your Asset list and select your Asset in the list.
Click on the Monetization settings line in the left-menu.
Select your Ad unit to edit it.
Click on the toggle on the right of the Callback settings to enable the server-side callback.
Put the URL that must be called in the CALLBACK URL field.
In the URL, you can place one or more of the following templates. They will be replaced by their corresponding value by the Ogury server.
Example:
Set user id
You can configure the value that will be sent to the server inside the #[APP_USER_ID]
parameter for the current user by calling the following method:
Secure the server-side callback
If you want to ensure that all the calls to the callback are originated from the Ogury servers, you can:
enable the SECURE CALLBACK option in the Callback settings of your Ad unit.
include the
#[TIMESTAMP]
,#[ADVERT_ID]
and#[VERIFIER]
templates in your CALLBACK URL.
Once the SECURE CALLBACK option is enabled, the Dashboard will show your secure key. The value of the #[VERIFIER]
template will be computed using HMAC SHA-256 with the following parameters:
secret key: the secure key associated to your Ad unit.
message: concatenation of the
#[ADVERT_ID]
and the#[TIMESTAMP]
templates.
By computing this value on your side, you will be able to verify that both server shares the same secure key and therefore that the calls come from the Ogury servers.
The following snippet will help you to implement the computation of the verifier depending of the technology used by your server:
Listeners
Listen to the lifecycle of ads
The Ogury SDK provides the OguryOptinVideoAdListener
interface to listen to the lifecycle of an Opt-in Video Ad instance.
You should already have registered an OguryOptinVideoAdListener
in the step 2. Otherwise, you can add the following code just after instantiating the OguryOptinVideoAd
to do so:
The OguryOptinVideoAdListener
exposes the following method in addition to the onAdRewarded
method:
Listen to the ad impressions
The Ogury SDK also provides the OguryAdImpressionListener
interface to listen and count the ad impressions.
To register an OguryAdImpressionListener
, add the following code before calling the show
method:
The OguryAdImpressionListener
exposes the following method:
Error codes
When an ad fails to load or to be displayed, the SDK calls the onAdError
callback with an OguryError
object. The OguryError
object contains the cause of the failure. You can get the error code by calling the getErrorCode
method and a more explicit message by calling the getMessage
method.
The error codes that you can encounter are defined in the OguryAdFormatErrorCode
object:
Last updated