S2S Rewarded Callback API
此内容尚不支持你的语言。
AppLovin’s servers can make server-to-server rewarded callbacks to an external server that you define. These callbacks notify you that a user of your app completed a rewarded ad and so that user qualifies for a reward. This protects against malicious users who attempt to gain rewards without finishing rewarded ads.
Introduction
AppLovin’s servers can send callbacks to an external endpoint after the user completes a rewarded ad that is served via MAX mediation.
You define which endpoint receives these requests.
The callbacks are in the form of HTTP or HTTPS GET
requests.
AppLovin makes these callbacks soon after the ad completion, 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 callback times.
The callback request times-out if five seconds pass without a response from your endpoint. If the callback request times out, AppLovin will retry the callback up to two times.
You can configure these callbacks by setting the value of Server Side Callback URL in the Edit Ad Unit page for any of your rewarded Ad Units.
Example
https://myrewardedserver.com/rewards?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 callback URL.
The example URL above incorporates the {IDFA}
, {USER_ID}
, {EVENT_ID}
, and {EVENT_TOKEN}
macros.
AppLovin’s servers replace these macro names with accurate values when the servers make the callback to your endpoint.
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 |
{AMOUNT} | The amount of currency you choose to award the user. You set this in the Ad Unit edit page for each Ad Unit. | 100 |
{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 |
{EVENT_ID} | Unique event ID, 40 hex characters | 8dc948013d71f…b226e08 |
{EVENT_TOKEN} | sha1( EVENT_ID + Your-Event-Key ) | e000949f6d851…a43cf31 |
{EVENT_TOKEN_ALL} | sha256( All1 macros alphabetically, URL-decoded + Your-Event-Key ) | eba615583ed59…5f218702a97a |
{IDFA} | iOS IDFA or Google Advertising ID | 860635ea-…3b30b94 |
{IDFV} | IDFV | 4CD1C3C4-…9387E60 |
{IP} | User’s IP (IPv6 values are URL-encoded) | 162.1.1.1 , fe80%3A%3A…890a%0A |
{NETWORK_NAME} | MAX Ad Network Name | APPLOVIN_BIDDING |
{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 |
{TS} | Timestamp of the ad load time (integer, seconds since epoch) | 1546300800 |
{USER_ID} | Publisher-defined user ID (URL-encoded); maximum length is 8192 characters | 7634657898 |
1 Note: if EVENT_TOKEN
is one of your macros, it is omitted from the “All macros alphabetically” string
Setting an Ad Placement Name
The following code snippets show you how you can add a placement name to an ad unit.
The value of the placement name replaces the {PLACEMENT}
macro in postback requests:
ActionScript
AppLovinMAX.setBannerPlacement(«ad-unit-ID», «placement»);
AppLovinMAX.setMRecPlacement(«ad-unit-ID», «placement»);
AppLovinMAX.showInterstitial(«ad-unit-ID», «placement»);
nativeAdLoader.setPlacement(«placement»);
AppLovinMAX.showRewardedAd(«ad-unit-ID», «placement»);
Blueprint
C++
UAppLovinMAX::CreateBanner(«ad-unit-ID», «position»);UAppLovinMAX::SetBannerPlacement(«ad-unit-ID», «placement»);
UAppLovinMAX::CreateMRec(«ad-unit-ID», «position»);UAppLovinMAX::SetMRecPlacement(«ad-unit-ID», «placement»);
UAppLovinMAX::ShowInterstitial(«ad-unit-ID», «placement»);
UAppLovinMAX::ShowInterstitial(«ad-unit-ID», «placement»);
C#
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»");
Dart
AppLovinMAX.createBanner(«ad-unit-ID», «position»);AppLovinMAX.setBannerPlacement(«ad-unit-ID», «placement»);
AppLovinMAX.createMRec(«ad-unit-ID», «position»);AppLovinMAX.setMRecPlacement(«ad-unit-ID», «placement»);
AppLovinMAX.showInterstitial(«ad-unit-ID», placement: «placement»);
AppLovinMAX.showRewardedAd(«ad-unit-ID», placement: «placement»);
GDScript
AppLovinMAX.createBanner(«ad-unit-ID», «position»);AppLovinMAX.set_banner_placement(«ad-unit-ID», «placement»);
AppLovinMAX.createMRec(«ad-unit-ID», «position»);AppLovinMAX.set_mrec_placement(«ad-unit-ID», «placement»);
AppLovinMAX.show_interstitial(«ad-unit-ID», «placement»);
AppLovinMAX.show_rewarded_ad(«ad-unit-ID», «placement»);
Java
adViewAd.setPlacement( "«placement»" );
interstitial.showAd( "«placement»" );
rewardedAd.showAd( "«placement»" );
nativeAdLoader.setPlacement( "«placement»" );
MaxAdPlacerSettings settings = new MaxAdPlacerSettings( "«ad-unit-ID»" );settings.setPlacement( "«placement»" );
JavaScript (Cordova)
AppLovinMAX.createBanner(«ad-unit-ID», «position»);AppLovinMAX.setBannerPlacement(«ad-unit-ID», «placement»);
AppLovinMAX.createMRec(«ad-unit-ID», «position»);AppLovinMAX.setMRecPlacement(«ad-unit-ID», «placement»);
AppLovinMAX.showInterstitial(«ad-unit-ID», «placement»);
AppLovinMAX.showRewardedAd(«ad-unit-ID», «placement»);
JavaScript (React Native)
AppLovinMAX.createBanner(«ad-unit-ID», «position»);AppLovinMAX.setBannerPlacement(«ad-unit-ID», «placement»);
import { AdView, AdFormat } from 'react-native-applovin-max';⋮<AdView adUnitId={«ad-unit-ID»} adFormat={AdFormat.BANNER} placement={«placement»} />
import { MRecAd } from 'react-native-applovin-max';⋮MRecAd.createAd(«ad-unit-ID», «position»);MRecAd.setPlacement(«ad-unit-ID», «placement»);
import { AdView, AdFormat } from 'react-native-applovin-max';⋮<AdView adUnitId={«ad-unit-ID»} adFormat={AdFormat.MREC} placement={«placement»} />
import { InterstitialAd } from 'react-native-applovin-max';⋮InterstitialAd.showAd(«ad-unit-ID», "«placement»");
import { RewardedAd } from 'react-native-applovin-max';⋮RewardedAd.showAd(«ad-unit-ID», "«placement»");
<NativeAdView adUnitId={«ad-unit-ID»} placement="«placement»" ⋮/>
Kotlin
adView.setPlacement( "«placement»" )
interstitial.showAd( "«placement»" )
rewardedAd.showAd( "«placement»" )
nativeAdLoader.setPlacement( "«placement»" )
val settings = MaxAdPlacerSettings( "«ad-unit-ID»" )settings.placement = "«placement»"
Lua
applovin.create_banner(«ad-unit-ID», «position»)applovin.set_banner_placement(«ad-unit-ID», «placement»)
applovin.create_mrec(«ad-unit-ID», «position»)applovin.set_mrec_placement(«ad-unit-ID», «placement»)
applovin.show_interstitial(«ad-unit-ID», «placement»);
applovin.show_rewarded_ad(«ad-unit-ID», «placement»);
Objective-C
adView.placement = @"«placement»";[adView loadAd];
[interstitialAd showAdForPlacement: @"«placement»"];
[rewardedAd showAdForPlacement: @"«placement»"];
nativeAdLoader.placement = @"«placement»";
MAAdPlacerSettings *settings = [MAAdPlacerSettings settingsWithAdUnitIdentifier: @"«ad-unit-ID»"];settings.placement = @"«placement»";
Swift
adView.placement = "«placement»"adView.loadAd()
interstitial.show(forPlacement: "«placement»")
rewardedAd.show(forPlacement: "«placement»")
nativeAdLoader.placement = "«placement»"
let settings = MAAdPlacerSettings(adUnitIdentifier: "«ad-unit-ID»")settings.placement = @"«placement»"
Setting an Internal User ID
The following code snippets show how to tag users with your own internal User ID. The maximum size of the User ID string is 8192 characters.
AppLovinMAX.setUserId("«user-ID»");
MaxSdk.SetUserId("«user-ID»");
val settings = AppLovinSdk.getInstance( this ).getSettings();settings.setUserIdentifier( "«user-ID»" );
AppLovinMAX.setUserId("«user-ID»");
val settings = AppLovinSdk.getInstance( this ).settingssettings.userIdentifier = "«user-ID»"
applovin.set_user_id("«user-ID»")
ALSdkSettings *settings = [ALSdk shared].settings;settings.userIdentifier = @"«user-ID»";
let settings = ALSdk.shared().settingssettings.userIdentifier = "«user-ID»"
Accessing the Amount and Currency for a Rewarded Ad
To access the reward amount and currency, override the reward callback:
private void OnRewardedAdReceivedRewardEvent(string adUnitId, MaxSdk.Reward reward, MaxSdkBase.AdInfo adInfo){ print("Rewarded user: " + reward.Amount + " " + reward.Label);}
@Overridepublic void onUserRewarded(final MaxAd ad, final MaxReward reward){ System.out.println( "Rewarded user: " + reward.getAmount() + " " + reward.getLabel() );}
override fun onUserRewarded(ad: MaxAd?, reward: MaxReward?){ System.out.println( "Rewarded user: " + reward!!.getAmount() + " " + reward.getLabel() )}
- (void)didRewardUserForAd:(MAAd *)ad withReward:(MAReward *)reward{ NSLog(@"Rewarded user: %d %@", reward.amount, reward.label);}
func didRewardUser(for ad: MAAd, with reward: MAReward){ print("Rewarded user: \(reward.amount) \(reward.label)")}
Custom Data
The following code snippets show you how to add custom String data to postbacks.
This String data replaces the {CUSTOM_DATA}
macro in these postbacks.
AppLovin recommends that your string contain fewer than 8192 characters.
Banners & MRECs
MaxSdk.SetBannerCustomData("«ad-unit-ID»", "«custom-data»"); // BannersMaxSdk.SetMRecCustomData("«ad-unit-ID»", "«custom-data»"); // MRECs
adViewAd.setCustomData( "«custom-data»" );
BannerAd.setCustomData("«ad-unit-ID»", "«custom-data»"); // BannersMRec.setCustomData("«ad-unit-ID»", "«custom-data»"); // MRECs
adView.setCustomData( "«custom-data»" )
adView.customData = @"«custom-data»";
adView.customData = "«custom-data»"
Interstitials
MaxSdk.ShowInterstitial(«adUnitIdentifier», «placement», «custom data»);
MaxInterstitialAd.showAd(«placement», «custom data»);
InterstitialAd.showAd(interAdUnitId, "«placement»", "«custom data»");
MaxInterstitialAd.showAd(«placement», «custom data»)
-[MAInterstitialAd showAdForPlacement:customData:]
[interstitialAd showAdForPlacement: @"«placement»" customData: @"«custom-data»"];
Rewarded Ads
MaxSdk.ShowRewardedAd(«adUnitIdentifier», «placement», «custom data»);
MaxRewardedAd.showAd(«placement», «custom data»);
RewardedAd.showAd(adUnitId, "«placement»", "«custom data»");
MaxRewardedAd.showAd(«placement», «custom data»)
-[MARewardedAd showAdForPlacement:customData:]
rewardedAd.show(forPlacement: "«placement»" customData: "«custom-data»")