Rewarded Video

Rewarded video interstitials are full-screen visuals that appear inside your application.

1. Prepare to reward the user

Next, you will need to override the TMAdListener class to receive callbacks on rewarded video adverts. Create a new file and implement it like so:

public class RewardedVideoListener extends TMAdListener {

    @Override
    public void didVerify(TDReward reward) {
        Log.i("MEDIATION-SAMPLE", String.format(Locale.ENGLISH, "didVerify: ID: %s, Tag: %s. Reward: %s. Value: %f. Valid: %b. Custom Json: %s", reward.getId(), reward.getTag(), reward.getName(), reward.getValue(), reward.isValid(), reward.getCustom_json().toString()));
    }
}

When the rewarded video has finished playing, the didVerify listener is triggered, and the user receives the reward.

didVerify will be called before the didClose callback, whether or not a reward was provided. If no reward has been provided the callback will be made with valid false flags. Note in some cases the network will fire a reward callback when the ad shows which will trigger didVerify.

For a full list of rewarded video listeners we support, see our Callbacks page.

2. Load the rewarded video

To load a rewarded video, we recommend you load them once the Tapdaq SDK has initialised.

Go back to the TapdaqInitListener you created in the Quickstart guide, and add a call to load the rewarded video, like so:

public class TapdaqInitListener extends TMInitListener {

    @Override
    public void didInitialise() {
        super.didInitialise();
        // Ads may now be requested
        Tapdaq.getInstance().loadRewardedVideo(<CurrentActivity>,  "my_rewarded_tag", new RewardedVideoListener());
    }

}

3. Display the rewarded video

We then need to display the rewarded ad to the user when they perform some action, for example tapping a button.

boolean isReady = Tapdaq.getInstance().isRewardedVideoReady(<CurrentActivity>,"my_rewarded_tag");

if (isReady) {
    Tapdaq.getInstance().showRewardedVideo(<CurrentActivity>, "my_rewarded_tag", new RewardedVideoListener());
} else {
  // Do something else
}

If you want to check a rewarded video is loaded before displaying a button the user would tap to see the reward, implement the following to the RewardedVideoListener you created earlier:

Note: TDReward.eventId is a unique identifier for every reward given to a user.

public class RewardedVideoListener extends TMAdListener {

    @Override
    public void didLoad() {
        // Rewarded video is loaded, enable your rewarded video button
    }

    @Override
    public void didVerify(TDReward reward) {
        Log.i("MEDIATION-SAMPLE", String.format(Locale.ENGLISH, "didVerify: ID: %s, Tag: %s. Reward: %s. Value: %f. Valid: %b. Custom Json: %s", reward.getId(), reward.getTag(), reward.getName(), reward.getValue(), reward.isValid(), reward.getCustom_json().toString()));
    }

}

Build and run your application to test the advert displays correctly.

4. Load another rewarded video on close

If you wish to load another rewarded video after you have shown one, implement one of the following options:

A. Auto Reload all Ads

To auto reload all ads using the same placement tag set the global config before initialising, like so:

TapdaqConfig config = new TapdaqConfig();
config.setAutoReloadAds(true);

B. Implement Override

When creating an ad listener, create a custom constructor and store the placement tag, then override didClose() and call load for the same type and placement tag.

private class AdListener extends TMAdListener {
        private String mTag;

        AdListener(String tag) {
            mTag = tag;
        }

        @Override
        public void didClose() {
            Tapdaq.getInstance().loadRewardedVideo(<CurrentActivity>, mTag, this);
        }
    }

Server Side Callbacks

Tapdaq SDK triggers server-side callbacks when a reward is provided, along with the client side didVerify callback.

Reward Id

The Reward Id is used for server-side callbacks, you can also retrieve it based on placement tags in the SDK like so:

Tapdaq.getInstance().getRewardId(tag);

The Reward Id must be enabled on the dashboard. Pre v7.0.0 this ID would be consistent across the session for the same reward, from v7.0.0 the ID will be different for each ad loaded, this getRewardId method will get the ID from the next ad that will be shown. It will return null if no ad has been loaded.

Rewarded Video User Id

A Hashed User Id can be passed into the ShowRewardedVideo method, this will then be added to our server side callback to identify users.

The String should be hashed before passed to Tapdaq SDK.

Tapdaq.getInstance().showRewardedVideo(<Activity>, "<Placement_Id>", "<Hashed_User_Id>", new TMAdListener());

Need help?

If you are having any problems integrating, feel free to contact us on [email protected] and we will be more than happy to help.

What's next?

Now that you have successfully integrated a rewarded video into your app, what would you like to do next?