Aller au contenu principal

Rewarded Video Ad

Integration

Step 1. Instantiate RewardedVideo Ad

You can instanstiate a RewardedVideoAd ad right after SDK finish it's initialization. You have to pass the platform specific rewarded placement id in RewardedVideoAd constructor.

public class BlueStackAdsController : MonoBehaviour
{
private RewardedVideoAd _rewardedVideoAd;

void start() {
Settings settings = new Settings(true);
BlueStackAds.Initialize("app_id", settings, HandleInitCompleteAction);
}

private void HandleInitCompleteAction(InitializationStatus initializationStatus)
{
_rewardedVideoAd = new RewardedVideoAd(placementId);
}
}

Step 2. Register event listeners

RewardedVideoAd exposes the following events through it's lifecycle.

MethodsDefinition
OnRewardedVideoLoadedAd is successfully loaded and SDK is ready to display the ad.
OnRewardedVideoAdAppearedThe ad has been displayed on the screen.
OnRewardedVideoAdErrorThe ad failed to load or display. An additional error parameter of type BlueStackError contains the reason of the failure.
OnRewardedVideoAdClickedUser has clicked the ad. Ad may open a link in browser.
OnUserRewardEarnedSDK will fire this event with an instance of RewardedItem or null depends on mediation ad network. Game can use or discard the reward value.
OnRewardedVideoAdClosedThe ad has been closed by the user.

To register for rewarded ad events, add the following code after instantiating RewardedVideoAd.

    _rewardedVideoAd.OnRewardedVideoAdLoaded += (sender, args) =>
{
Debug.Log("OnRewardedVideoAdLoaded");

};

_rewardedVideoAd.OnRewardedVideoAdError += (sender, args) =>
{
Debug.LogError("OnRewardedVideoAdError: " + args.Message);
};

_rewardedVideoAd.OnRewardedVideoAdAppeared += (sender, args) =>
{
Debug.Log("OnRewardedVideoAdAppeared");
};

_rewardedVideoAd.OnRewardedVideoAdClicked += (sender, args) =>
{
Debug.Log("OnRewardedVideoAdClicked");
};

_rewardedVideoAd.OnUserRewardEarned += (sender, args) =>
{
Debug.Log("OnUserRewardEarned reward: '" + args?.Type + "', amount: " + args?.Amount);
};

_rewardedVideoAd.OnRewardedVideoAdClosed += (sender, args) =>
{
Debug.Log("OnAdClosed");

};

attention

Make sure you only register event listener once.

Step 3. Load Rewarded Video ad

RewardedVideoAd expose two Load medthods to load ad. One takes Preference instance others emtpy parameters.

info

There must be a delay of at least 5 seconds between each reward ad Load call

  • Without Preference
_rewardedVideoAd.Load();
  • With Preference
public class BlueStackAdsController : MonoBehaviour
{
...
private RequestRewardedVideoAd() {

Preference _preference = new Preference();
Location myLocation = new Location(Location.NONE_PROVIDER)
{
Latitude = 35.757866,
Longitude = 10.810547
};
_preference.SetAge(25);
_preference.SetLanguage("en");
_preference.SetGender(Gender.Male);
_preference.SetKeyword("brand=myBrand;category=sport");
_preference.SetLocation(myLocation, 1);
_preference.SetContentUrl("https://madvertise.com/en/");

_rewardedVideoAd.Load(_preference);
}
...
}

Note : The SetLocation method takes the following parameters:

  • The Location instance.
  • The CONSENT_FLAG value (corresponds to a int : 0,1,2 or 3).
    • 0 = Not allow to send location.
    • 1 = When you managed location according to consent value.
    • 2 and 3 = Allow the SDK to managed location directly in accordance with the consent value use TCF v1 or TCF v2, see with the madvertise team it depends on your implementation.

Step 4. Display Rewarded Video ad

After loading the rewarded video you can request it to be displayed.

info

Register to OnRewardedVideoAdLoaded to make sure the ad was successfully loaded before you call Show() method

_rewardedVideoAd.Show();

Destroy Rewarded Video ad

Destroy rewarded video ad before creating a new one.

_rewardedVideoAd.Destroy();