इनाम वाले विज्ञापनों के कस्टम इवेंट

ज़रूरी शर्तें

कस्टम इवेंट का सेटअप पूरा करें.

इनाम वाले विज्ञापन का अनुरोध करना

वॉटरफ़ॉल मीडिएशन चेन में, कस्टम इवेंट के लाइन आइटम तक पहुंचने पर, loadRewardedAd() तरीका को उस क्लास के नाम पर कॉल किया जाता है तब प्रदान किया जाता है, जब आप कोई कस्टम मॉड्यूल बनाते हैं इवेंट. इस मामले में, वह तरीका SampleCustomEvent में है, जो loadRewardedAd() को कॉल करता है SampleRewardedCustomEventLoader में तरीका.

इनाम वाले विज्ञापन का अनुरोध करने के लिए, ऐसी क्लास बनाएं या उसमें बदलाव करें जो Adapter तक loadRewardedAd() लागू करें. इसके अलावा, लागू करने के लिए एक नई क्लास बनाएं MediationRewardedAd.

हमारे कस्टम इवेंट के उदाहरण में, SampleCustomEvent, Adapter क्लास को बढ़ाता है और फिर इससे डेलिगेट के लिए अनुरोध करता है SampleRewardedCustomEventLoader.

Java

package com.google.ads.mediation.sample.customevent;

import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.MediationRewardedAdConfiguration;
import com.google.android.gms.ads.mediation.MediationAdConfiguration;
import com.google.android.gms.ads.mediation.MediationAdLoadCallback;
import com.google.android.gms.ads.mediation.MediationRewardedAd;
import com.google.android.gms.ads.mediation.MediationRewardedAdCallback;
...

public class SampleCustomEvent extends Adapter {

  private SampleNativeCustomEventLoader nativeLoader;

  @Override
  public void loadRewardedAd(
      @NonNull MediationRewardedAdConfiguration mediationRewardedAdConfiguration,
      @NonNull
          MediationAdLoadCallback<MediationRewardedAd, MediationRewardedAdCallback>
              mediationAdLoadCallback) {
    rewardedLoader =
        new SampleRewardedCustomEventLoader(
            mediationRewardedAdConfiguration, mediationAdLoadCallback);
    rewardedLoader.loadAd();
  }
}

SampleRewardedCustomEventLoader इन टास्क के लिए ज़िम्मेदार है:

  • इनाम वाला विज्ञापन लोड हो रहा है

  • MediationRewardedAd इंटरफ़ेस को लागू करना.

  • Google Mobile Ads SDK में, विज्ञापन इवेंट कॉलबैक पाना और उनकी रिपोर्ट करना

Ad Manager यूज़र इंटरफ़ेस (यूआई) में तय किया गया वैकल्पिक पैरामीटर यह है विज्ञापन कॉन्फ़िगरेशन में शामिल किया गया है. पैरामीटर को इसके ज़रिए ऐक्सेस किया जा सकता है adConfiguration.getServerParameters().getString(MediationConfiguration.CUSTOM_EVENT_SERVER_PARAMETER_FIELD). यह पैरामीटर आम तौर पर एक विज्ञापन यूनिट आइडेंटिफ़ायर होता है. यह विज्ञापन नेटवर्क कंपनी का SDK टूल होता है की आवश्यकता होती है.

Java

package com.google.ads.mediation.sample.customevent;

import com.google.android.gms.ads.mediation.Adapter;
import com.google.android.gms.ads.mediation.MediationRewardedAdConfiguration;
import com.google.android.gms.ads.mediation.MediationAdLoadCallback;
import com.google.android.gms.ads.mediation.MediationRewardedAd;
import com.google.android.gms.ads.mediation.MediationRewardedAdCallback;
...

public class SampleRewardedCustomEventLoader extends SampleRewardedAdListener
    implements MediationRewardedAd {

  /** Configuration for requesting the rewarded ad from the third-party network. */
  private final MediationRewardedAdConfiguration mediationRewardedAdConfiguration;

  /**
   * A {@link MediationAdLoadCallback} that handles any callback when a Sample
   * rewarded ad finishes loading.
   */
  private final MediationAdLoadCallback<MediationRewardedAd, MediationRewardedAdCallback>
      mediationAdLoadCallback;

  /** Callback for rewarded ad events. */
  private MediationRewardedAdCallback rewardedAdCallback;

  /** Constructor. */
  public SampleRewardedCustomEventLoader(
      @NonNull MediationRewardedAdConfiguration mediationRewardedAdConfiguration,
      @NonNull MediationAdLoadCallback<MediationRewardedAd, MediationRewardedAdCallback>
              mediationAdLoadCallback) {
    this.mediationRewardedAdConfiguration = mediationRewardedAdConfiguration;
    this.mediationAdLoadCallback = mediationAdLoadCallback;
  }

  /** Loads the rewarded ad from the third-party ad network. */
  public void loadAd() {
    // All custom events have a server parameter named "parameter" that returns
    // back the parameter entered into the AdMob UI when defining the custom event.
    Log.i("RewardedCustomEvent", "Begin loading rewarded ad.");
    String serverParameter = mediationRewardedAdConfiguration
        .getServerParameters()
        .getString(MediationConfiguration
        .CUSTOM_EVENT_SERVER_PARAMETER_FIELD);
    Log.d("RewardedCustomEvent", "Received server parameter.");
    SampleAdRequest request = createSampleRequest(mediationRewardedAdConfiguration);
    sampleRewardedAd = new SampleRewardedAd(serverParameter);
    sampleRewardedAd.setListener(this);
    Log.i("RewardedCustomEvent", "Start fetching rewarded ad.");
    sampleRewardedAd.loadAd(request);
  }

  public SampleAdRequest createSampleRequest(
      MediationAdConfiguration mediationAdConfiguration) {
    SampleAdRequest request = new SampleAdRequest();
    request.setTestMode(mediationAdConfiguration.isTestRequest());
    request.setKeywords(mediationAdConfiguration.getMediationExtras().keySet());
    return request;
  }
}

विज्ञापन फ़ेच हुआ या नहीं या उसमें कोई गड़बड़ी हुई, इसके आधार पर आपको या तो, onSuccess() या onFailure(). onSuccess() को लागू करने वाली क्लास का एक इंस्टेंस पास करके कॉल किया जाता है MediationRewardedAd.

आम तौर पर, इन तरीकों को तीसरे पक्ष का SDK टूल, जिसे आपका अडैप्टर लागू करता है. उदाहरण के लिए, SDK टूल का सैंपल इसमें काम के कॉलबैक वाला SampleAdListener मौजूद है:

Java

@Override
public void onRewardedAdLoaded() {
  rewardedAdCallback = mediationAdLoadCallback.onSuccess(this);
}

@Override
public void onRewardedAdFailedToLoad(SampleErrorCode errorCode) {
    mediationAdLoadCallback.onFailure(SampleCustomEventError.createSampleSdkError(errorCode));
}

MediationRewardedAd को दिखाने के लिए, showAd() तरीका लागू करना ज़रूरी है विज्ञापन:

Java

@Override
public void showAd(Context context) {
  if (!(context instanceof Activity)) {
    rewardedAdCallback.onAdFailedToShow(
        SampleCustomEventError.createCustomEventNoActivityContextError());
    return;
  }
  Activity activity = (Activity) context;

  if (!sampleRewardedAd.isAdAvailable()) {
    rewardedAdCallback.onAdFailedToShow(
        SampleCustomEventError.createCustomEventAdNotAvailableError());
    return;
  }
  sampleRewardedAd.showAd(activity);
}

Google Mobile Ads SDK पर मीडिएशन इवेंट फ़ॉरवर्ड करना

onSuccess() को कॉल करने के बाद, लौटाए गए MediationRewardedAdCallback तो अडैप्टर से प्रेज़ेंटेशन इवेंट को फ़ॉरवर्ड करने के लिए, ऑब्जेक्ट का इस्तेमाल किया जा सकता है तीसरे पक्ष के SDK टूल को Google Mobile Ads SDK में जोड़ा जा सकता है. कॉन्टेंट बनाने SampleRewardedCustomEventLoader क्लास SampleAdListener को बढ़ाती है सैंपल विज्ञापन नेटवर्क से कॉलबैक फ़ॉरवर्ड करने के लिए इंटरफ़ेस Google Ads SDK टूल.

यह ज़रूरी है कि आपका कस्टम इवेंट इनमें से ज़्यादा से ज़्यादा कॉलबैक फ़ॉरवर्ड करे ताकि आपके ऐप्लिकेशन को Google की तरफ़ से इसी तरह के इवेंट मिल सकें मोबाइल विज्ञापन SDK टूल. यहां कॉलबैक का इस्तेमाल करने का एक उदाहरण दिया गया है:

Java

@Override
public void onAdRewarded(final String rewardType, final int amount) {
  RewardItem rewardItem =
      new RewardItem() {
        @Override
        public String getType() {
          return rewardType;
        }

        @Override
        public int getAmount() {
          return amount;
        }
      };
  rewardedAdCallback.onUserEarnedReward(rewardItem);
}

@Override
public void onAdClicked() {
  rewardedAdCallback.reportAdClicked();
}

@Override
public void onAdFullScreen() {
  rewardedAdCallback.onAdOpened();
  rewardedAdCallback.onVideoStart();
  rewardedAdCallback.reportAdImpression();
}

@Override
public void onAdClosed() {
  rewardedAdCallback.onAdClosed();
}

@Override
public void onAdCompleted() {
  rewardedAdCallback.onVideoComplete();
}

इससे, इनाम वाले विज्ञापनों के लिए कस्टम इवेंट लागू करने की प्रोसेस पूरी हो जाती है. पूरा उदाहरण यहां उपलब्ध है GitHub. इसका इस्तेमाल, पहले से काम करने वाली विज्ञापन नेटवर्क कंपनी के साथ किया जा सकता है. इसके अलावा, इसमें बदलाव भी किया जा सकता है डिसप्ले कस्टम इवेंट वाले इनाम वाले विज्ञापन.