コンテンツにスキップ

リワード広告

リワード広告をロード

以下のコードは、リスナーを付与して最初のリワード広告をロードする方法を示しています。

#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.
}

リワード広告を表示

リワード広告を表示するには、ShowRewardedAd()を呼び出します。

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

リワード広告の金額と通貨の設定

リワード額と通貨にアクセスするには、OnRewardedAdReceivedRewardEvent() コールバックをオーバーライドします。

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

S2S Rewarded Callbacks

通貨サーバーへのコールバックを受け取ることができます。 設定方法については、MAX S2S Rewarded CallbackAPIガイドをご覧ください。 次に、Edit Ad UnitページにてServer Side Callback URLをアップデートしてください。

リワード広告の金額と通貨の設定

リワードの金額と通貨を設定する方法:

  1. Edit Ad UnitページにてAdd S2S Reward Callbackをクリックします:Ad Type: ☐App Open, ☐Banner, ☐Interstitial, ☐MRec, ☐Native, ☑Rewarded. Add S2S Reward Callback.
  2. Server Side Callback URLReward Amountおよび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.