Rewarded Ads

Loading a Rewarded Ad

The following code shows you how to attach listeners and load the first rewarded ad:

#if UNITY_IOS
string adUnitId = "ios_ad_unit_ID";
#else // UNITY_ANDROID
string adUnitId = "android_ad_unit_ID";
#endif
int retryAttempt; public void InitializeRewardedAds() { // Attach callback MaxSdkCallbacks.Rewarded.OnAdLoadedEvent += OnRewardedAdLoadedEvent; MaxSdkCallbacks.Rewarded.OnAdLoadFailedEvent += OnRewardedAdLoadFailedEvent; MaxSdkCallbacks.Rewarded.OnAdDisplayedEvent += OnRewardedAdDisplayedEvent; MaxSdkCallbacks.Rewarded.OnAdClickedEvent += OnRewardedAdClickedEvent; MaxSdkCallbacks.Rewarded.OnAdRevenuePaidEvent += OnRewardedAdRevenuePaidEvent; MaxSdkCallbacks.Rewarded.OnAdHiddenEvent += OnRewardedAdHiddenEvent; MaxSdkCallbacks.Rewarded.OnAdDisplayFailedEvent += OnRewardedAdFailedToDisplayEvent; MaxSdkCallbacks.Rewarded.OnAdReceivedRewardEvent += OnRewardedAdReceivedRewardEvent; // Load the first rewarded ad LoadRewardedAd(); } private void LoadRewardedAd() { MaxSdk.LoadRewardedAd(adUnitId); } private void OnRewardedAdLoadedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) { // Rewarded ad is ready for you to show. MaxSdk.IsRewardedAdReady(adUnitId) now returns 'true'. // Reset retry attempt retryAttempt = 0; } private void OnRewardedAdLoadFailedEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo) { // Rewarded ad failed to load // AppLovin recommends that you retry with exponentially higher delays, up to a maximum delay (in this case 64 seconds). retryAttempt++; double retryDelay = Math.Pow(2, Math.Min(6, retryAttempt)); Invoke("LoadRewardedAd", (float) retryDelay); } private void OnRewardedAdDisplayedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {} private void OnRewardedAdFailedToDisplayEvent(string adUnitId, MaxSdkBase.ErrorInfo errorInfo, MaxSdkBase.AdInfo adInfo) { // Rewarded ad failed to display. AppLovin recommends that you load the next ad. LoadRewardedAd(); } private void OnRewardedAdClickedEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) {} private void OnRewardedAdHiddenEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) { // Rewarded ad is hidden. Pre-load the next ad LoadRewardedAd(); } private void OnRewardedAdReceivedRewardEvent(string adUnitId, MaxSdk.Reward reward, MaxSdkBase.AdInfo adInfo) { // The rewarded ad displayed and the user should receive the reward. } private void OnRewardedAdRevenuePaidEvent(string adUnitId, MaxSdkBase.AdInfo adInfo) { // Ad revenue paid. Use this callback to track user revenue. }

Showing a Rewarded Ad

To show a rewarded ad, call ShowRewardedAd():

if (MaxSdk.IsRewardedAdReady(adUnitId))
{
  MaxSdk.ShowRewardedAd(adUnitId);
}

Accessing the Amount and Currency for a Rewarded Ad

To access the reward amount and currency, override the OnRewardedAdReceivedRewardEvent() callback:

private void OnRewardedAdReceivedRewardEvent(string adUnitId, MaxSdk.Reward reward, MaxSdkBase.AdInfo adInfo)
{
  print("Rewarded user: " + reward.Amount + " " + reward.Label);
}

S2S Rewarded Callbacks

Impression-level revenue data helps you better understand your users, calculate ROI precisely, and build accurate LTV models. MAX gives you revenue information associated with each impression, as well as information about the demand source and the creative served for supported networks.

You can either process the data directly yourself, or work with any of our supported analytics providers, which are listed in the “MMP Integration: MAX to MMP” section of this page.

Direct Integration: MAX to You

There are three ways you can get user-level revenue data:

User Revenue API
Use this API to retrieve user-level revenue data on a daily basis. You can retrieve this data aggregated for a particular user or with one row per impression. Data is available eight hours after UTC day end. Read more about it on the User Revenue API documentation page.
Client-Side
Starting in SDK version 10.3.0+, you can access impression-level user revenue data on the client side in real-time. You can find integration instructions in the Advanced Settings page.
Server-to-Server
If you want to access real-time revenue data on the server side, you can provide an impression postback to track impression-level user ad revenue data. Please contact your account team or the support team to enable this feature. This feature and the macros that the impression postback supports are described in the “Server-to-Server Impression Revenue API” section of this page.

MMP Integration: MAX to MMP

MAX partners with various analytics solutions to help you easily access your data in a single dashboard. You can work with any of our supported partners such as Adjust, GameAnalytics, AppsFlyer, or Singular to access impression-level ad revenue or aggregated ad revenue data. Please refer to the documentation pages maintained by those partners for more information.

Server-to-Server Impression Revenue API

Please contact your account team or the support team to enable this feature.

AppLovin can send (HTTP or HTTPS) GET requests, from its servers to an external endpoint that you define, whenever a MAX impression is recorded. AppLovin makes these postbacks soon after the impression, but they may be delayed by up to a few minutes. You can use an impression timestamp macro to reconcile any delay between the impression and the postback times.

If the postback receives a non-200 response code, AppLovin will retry the postback up to three more times: twice right away and then once more about 60 seconds later. The postback request will timeout if five seconds pass without a response.

Example

https://myimpressionserver.com/impression?idfa={IDFA}&user_id={USER_ID}&event={EVENT_ID}&token={EVENT_TOKEN}

Available Macros

You can incorporate any of the macros in the following table into your postback URL (as in the example URL above). AppLovin’s servers will replace these macro names with accurate values at the time it makes the postback to your server.

Name Description Example
{AD_UNIT_ID} MAX Ad Unit ID (16 hex characters) 9ad0816ac071552a
{AD_UNIT_NAME} Ad Unit name (URL-encoded) My%20App%20Banners
{AD_UNIT_TEST_NAME} Name of the ad unit test, URL-encoded Control
{ALL_REVENUE} Estimated revenue, including FB Bidding estimates 0.0121, 5.74466e-05
{CC} Two-letter country code of the user gb
{CURRENCY} The type of currency you choose to award the user (URL-encoded). You set this in the Ad Unit edit page for each Ad Unit. coins
{CUSTOM_DATA} Custom data passed in from the integration (URL-encoded). AppLovin recommends that you keep the size of the string under 8192 characters. my%20custom%20data
{DEVICE_TYPE} User’s device type. Tablet
{EVENT_ID} Unique event ID, 40 hex characters 8dc948013d71f04264b8e5c1c61933154b226e08
{EVENT_TOKEN} sha1( EVENT_ID + Your_Event_Key ) e000949f6d851c1f34adae08e6ef1076ba43cf31
{EVENT_TOKEN_ALL} sha256( All macros alphabetically, URL-decoded + Your_Event_Key )

If EVENT_TOKEN is one of your macros, it is omitted from the “All macros alphabetically” string.

eba615583ed59bc679a495ec58439f4b82b5460d822348eff6be5f218702a97a
{FORMAT} Ad Unit format reward, banner, inter
{IDFA} iOS IDFA or Google Advertising ID 860635ea-65bc-eaed-d355-1b5283b30b94
{IDFV} Identifier for Vendor 4CD1C3C4-3FD7-00F5-1635-7BC6D9387E60
{IP} User’s IP address (IPv6 values are URL-encoded) 162.1.1.1, fe80%3A%3A1ff%3Afe23%3A4567%3A890a%0A
{NETWORK} Name of the ad network that served the impression. Names should match the names used in the ManagementAPI. APPLOVIN_NETWORK
{NETWORK_PLACEMENT} Placement name of the external ad network ca-app-pub-12345678%2F0987654321
{PACKAGE_NAME} App Package Name (Android) or Bundle ID (iOS). URL-encoded. com.test.app
{PLACEMENT} Publisher-defined MAX ad placement name (URL-encoded) Launch%20Screen
{PLATFORM} Platform android, ios
{PRECISION} Information on how precise the revenue value is. Options are:
publisher_defined
if revenue is the price assigned to the line item by the publisher
exact
if revenue is the resulting price of a real-time auction
estimated
if the revenue amount is based on Auto CPM or FB Bidding estimates
undefined
if no line item amount is defined and there is not enough data to estimate
exact
{REVENUE} Estimated revenue. Set to 0 when FB Bidding. 0.0121, 5.74466e-05
{TS} Timestamp of impression (integer, seconds since epoch) 1546300800
{USER_ID} Publisher-defined, URL-encoded, user ID; maximum length is 8192 characters 7634657898
{WATERFALL_NAME} The name of the Ad Unit waterfall LAT

Setting the Reward Amount and Currency

To set the reward amount and currency, click Add S2S Reward Callback in your Edit Ad Unit page:

Ad Type: ☐App Open, ☐Banner, ☐Interstitial, ☐MREC, ☐Native, ☑Rewarded. Add S2S Reward Callback.

Add the Server Side Callback URL, Reward Amount, and Rewarded Currency Name:

Ad Type: ☐App Open, ☐Banner, ☐Interstitial, ☐MREC, ☐Native, ☑Rewarded. Hide Callback Settings. Server Side Callback URL form field. Reward Amount form field. Rewarded Currency Name form field. AppLovin Event Key form field.

Setting an Ad Placement Name

  • MaxSdk.CreateBanner(ad-unit-id, position);
    MaxSdk.SetBannerPlacement(ad-unit-id, "placement");
  • MaxSdk.CreateMRec(ad-unit-id, position);
    MaxSdk.SetMRecPlacement(ad-unit-id, "placement");
  • MaxSdk.ShowInterstitial(ad-unit-id, "placement");
  • MaxSdk.ShowRewardedAd(ad-unit-id, "placement");

Setting an Internal User ID

If you want to tag users with your own internal User ID, do so with code like the following. The maximum size of the User ID string is 8192 characters.

MaxSdk.SetUserId("user-id");

Custom Data

Starting in SDK version 11.0.0, you can tag data/postbacks with custom string data. Do this with the code like the following. AppLovin recommends that you keep the size of the string under 8192 characters.

You must set custom data before you load a banner or MREC ad. Otherwise that data will not appear in the postbacks associated with the ad.

Banners

  • MaxSdk.SetBannerCustomData(adUnitId, "custom data");
  • MaxSdk.SetMRecCustomData(adUnitId, "custom data");
  • MaxSdk.ShowInterstitial(adUnitIdentifier, placement, custom data);
  • MaxSdk.ShowRewardedAd(adUnitIdentifier, placement, custom data);