Rewarded Video Integration
Rewarded video ads are a great way to offer users an incentive to stay engaged in your app, while earning more ad revenue. The reward generally comes in the form of in-game currency (gold, coins, power-ups) and is distributed to the user after a successful video completion. MoPub’s mediation solution officially supports rewarded videos from popular ad networks - AdMob, AdColony, Facebook Audience Network, OnebyAOL, Unity Ads, Vungle, Chartboost, ironSource and Tapjoy.
1. Initialize Rewarded Video
```csharp MoPub.InitializeSdk() ```
2. Pre-fetch the Rewarded Video Ad
```csharp MoPub.RequestRewardedVideo(rewardedVideoAdUnit, mediationSettings, keywords, latitude, longitude, customerId); ```
3. Show the Rewarded Video
```csharp MoPub.ShowRewardedVideo(rewardedVideoAdUnit); ```
4. Configure the Callback Server
Your callback server must return a 200 HTTP response status code when it successfully receives the reward callback. If your server returns a 500 HTTP response status code, MoPub will continually call the server at increasing intervals until your server returns a 200 HTTP code or the maximum retry limit of 14 is reached. The maximum retry limit is subjected to a two-hour time limit. MoPub stops the retries when your server returns a 200 HTTP response status code.
|HTTP Response Code||Description||When Used|
|200||Successful Request||Return this response code for a successful callback|
|500||Internal Server Error||Return this response code when a callback server error occurs|
If any other HTTP response status code is used, MoPub will log the response and will not retry.
If the MoPub server detects a failure to connect, it may retry, to ensure that your server receives callbacks. Because of this, there is a slight possibility that your callback server may receive duplicate callbacks (from the same callback URL, for the same rewarded video). We recommend that you store the hash ID (the value from the
%%VERIFIER%% macro) and only give a user one reward for each unique ID.
To secure the callback sent from MoPub to your callback server, the
%%VERIFIER%% macro must be present in the callback URL. The
%%VERIFIER%% is a SHA256 hash generated from the callback’s parameter values and uses a Secret Key. You can find the Callback Secret Key in the MoPub UI Account Settings page.
Your server should use the Callback Secret Key to regenerate the SHA256 hash from the callback’s parameter values. If the hash generated on your server matches the one in the callback sent by MoPub, this signals that the callback is valid and the user should be rewarded.
To generate the hash on the reward server:
|1. Parse the callback URL and retrieve the query parameters.||Callback URL:
|2. Drop the verifier key and value from the array of parameters.||Verifier Hash:
|3. Sort the query parameters alphabetically.||Alphabetical array of query parameters (excluding the verifier)
|4. Concatenate the values in that alphabetical order.||Concatenated String:
|5. Hash the concatenated string using a HMAC SHA256 hash algorithm and the Callback Secret Key.||HMAC SHA256 the concatenated string and the Secret Key: 7dbcfd2a42134f47bfb72daa02f85ec9
* The result:
* The result matches the hash passed in the request
After generating the hash, compare the received hash with your generated hash. They should equal each other. Once verified, your server must return a 200 response code to MoPub and can reward the user.
5. [Optional] Implement the lifecycle callbacks
Here are the rewarded video-related callback handlers:
OnRewardedVideoLoadedEvent (string adUnitId) OnRewardedVideoFailedEvent (string adUnitId, string errorMsg) OnRewardedVideoExpiredEvent (string adUnitId) OnRewardedVideoShownEvent (string adUnitId) OnRewardedVideoClickedEvent (string adUnitId) OnRewardedVideoFailedToPlayEvent (string adUnitId, string errorMsg) OnRewardedVideoReceivedRewardEvent (string adUnitId, string label, float amount) OnRewardedVideoClosedEvent (string adUnitId) OnRewardedVideoLeavingApplicationEvent (string adUnitId)
- We recommend placing rewarded video ads where your users are already engaging with in-app purchases or in locations where users may be seeking an in-app reward, such as the end of a game or at currency redemption points. Once your users have finished watching the video ad, you can designate the reward they will receive.
- You can be notified that a rewarded video was fetched successfully by implementing onRewardedVideoLoaded. We highly recommend to wait for the onRewardedVideoLoaded callback before showing the rewarded video. This will ensure that the ad will have enough time to load and show as expected.
- Reward type should be in English only. Localized characters are yet to be supported.
- Concurrent ad requests using the same ad units is not supported until we make additional improvements.
Last updated April 09, 2019
TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.
© 2019 MoPub (a division of Twitter, Inc.)