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

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

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

नेटिव विज्ञापन का अनुरोध करें

वॉटरफ़ॉल मीडिएशन चेन में, कस्टम इवेंट के लाइन आइटम तक पहुंचने पर, loadNativeAd:adConfiguration:completionHandler: तरीके को क्लास का वह नाम जो आपने कस्टम प्रॉपर्टी बनाते समय दिया था इवेंट. इस मामले में, वह तरीका SampleCustomEvent में है. इससे loadNativeAd:adConfiguration:completionHandler: तरीका SampleCustomEventNative.

नेटिव विज्ञापन का अनुरोध करने के लिए, लागू करने वाली क्लास बनाएं या उसमें बदलाव करें GADMediationAdapter और loadNativeAd:adConfiguration:completionHandler:. अगर आपने GADMediationAdapter का विस्तार करने वाली क्लास पहले से मौजूद है, लागू करें loadNativeAd:adConfiguration:completionHandler:. इसके अलावा, GADMediationNativeAd लागू करने के लिए नई क्लास.

हमारे कस्टम इवेंट के उदाहरण में, SampleCustomEvent लागू करता है GADMediationAdapter इंटरफ़ेस और फिर इसे ऐक्सेस कर सकता है SampleCustomEventNative.

Swift

import GoogleMobileAds

class SampleCustomEvent: NSObject, GADMediationAdapter {

  fileprivate var nativeAd: SampleCustomEventNativeAd?

  func loadNativeAd(
    for adConfiguration: GADMediationNativeAdConfiguration,
    completionHandler: @escaping GADMediationNativeAdLoadCompletionHandler
  ) {
    self.nativeAd = SampleCustomEventNativeAd()
    self.nativeAd?.loadNativeAd(
      for: adConfiguration, completionHandler: completionHandler)
  }
}

Objective-C

#import "SampleCustomEvent.h"

@implementation SampleCustomEvent

SampleCustomEventNativeAd *sampleNativeAd;

- (void)loadNativeAdForAdConfiguration:
            (GADMediationNativeAdConfiguration *)adConfiguration
                     completionHandler:
                         (GADMediationNativeAdLoadCompletionHandler)
                             completionHandler {
  sampleNative = [[SampleCustomEventNativeAd alloc] init];
  [sampleNative loadNativeAdForAdConfiguration:adConfiguration
                             completionHandler:completionHandler];
}

नमूना कस्टम इवेंट नेटिव` इन कामों के लिए ज़िम्मेदार है:

  • नेटिव विज्ञापन लोड हो रहा है

  • GADMediationNativeAd प्रोटोकॉल लागू किया जा रहा है.

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

AdMob के यूज़र इंटरफ़ेस (यूआई) में तय किया गया वैकल्पिक पैरामीटर यह है विज्ञापन कॉन्फ़िगरेशन में शामिल किया गया है. पैरामीटर को इसके ज़रिए ऐक्सेस किया जा सकता है adConfiguration.credentials.settings[@"parameter"]. यह पैरामीटर आम तौर पर, ऐसा विज्ञापन यूनिट आइडेंटिफ़ायर जिसकी ज़रूरत किसी विज्ञापन नेटवर्क SDK टूल को होती है किसी विज्ञापन ऑब्जेक्ट को इंस्टैंशिएट करना.

Swift

class SampleCustomEventNativeAd: NSObject, GADMediationNativeAd {
  /// The Sample Ad Network native ad.
  var nativeAd: SampleNativeAd?

  /// The ad event delegate to forward ad rendering events to the Google Mobile
  /// Ads SDK.
  var delegate: GADMediationNativeAdEventDelegate?

  /// Completion handler called after ad load
  var completionHandler: GADMediationNativeLoadCompletionHandler?

  func loadNativeAd(
    for adConfiguration: GADMediationNativeAdConfiguration,
    completionHandler: @escaping GADMediationNativeLoadCompletionHandler
  ) {
    let adLoader = SampleNativeAdLoader()
    let sampleRequest = SampleNativeAdRequest()

    // The Google Mobile Ads SDK requires the image assets to be downloaded
    // automatically unless the publisher specifies otherwise by using the
    // GADNativeAdImageAdLoaderOptions object's disableImageLoading property. If
    // your network doesn't have an option like this and instead only ever
    // returns URLs for images (rather than the images themselves), your adapter
    // should download image assets on behalf of the publisher. This should be
    // done after receiving the native ad object from your network's SDK, and
    // before calling the connector's adapter:didReceiveMediatedNativeAd: method.
    sampleRequest.shouldDownloadImages = true
    sampleRequest.preferredImageOrientation = NativeAdImageOrientation.any
    sampleRequest.shouldRequestMultipleImages = false
    let options = adConfiguration.options
    for loaderOptions: GADAdLoaderOptions in options {
      if let imageOptions = loaderOptions as? GADNativeAdImageAdLoaderOptions {
        sampleRequest.shouldRequestMultipleImages =
          imageOptions.shouldRequestMultipleImages
        // If the GADNativeAdImageAdLoaderOptions' disableImageLoading property is
        // YES, the adapter should send just the URLs for the images.
        sampleRequest.shouldDownloadImages = !imageOptions.disableImageLoading
      } else if let mediaOptions = loaderOptions
        as? GADNativeAdMediaAdLoaderOptions
      {
        switch mediaOptions.mediaAspectRatio {
        case GADMediaAspectRatio.landscape:
          sampleRequest.preferredImageOrientation =
            NativeAdImageOrientation.landscape
        case GADMediaAspectRatio.portrait:
          sampleRequest.preferredImageOrientation =
            NativeAdImageOrientation.portrait
        default:
          sampleRequest.preferredImageOrientation = NativeAdImageOrientation.any
        }
      }
    }
    // This custom event uses the server parameter to carry an ad unit ID, which
    // is the most common use case.
    adLoader.delegate = self
    adLoader.adUnitID =
      adConfiguration.credentials.settings["parameter"] as? String
    self.completionHandler = completionHandler
    adLoader.fetchAd(sampleRequest)
  }
}

Objective-C

#import "SampleCustomEventNativeAd.h"

@interface SampleCustomEventNativeAd () <SampleNativeAdDelegate,
                                         GADMediationNativeAd> {
  /// The sample native ad.
  SampleNativeAd *_nativeAd;

  /// The completion handler to call when the ad loading succeeds or fails.
  GADMediationNativeLoadCompletionHandler _loadCompletionHandler;

  /// The ad event delegate to forward ad rendering events to the Google Mobile
  /// Ads SDK.
  id<GADMediationNativeAdEventDelegate> _adEventDelegate;
}
@end

- (void)loadNativeAdForAdConfiguration:
            (GADMediationNativeAdConfiguration *)adConfiguration
                     completionHandler:(GADMediationNativeLoadCompletionHandler)
                                           completionHandler {
  __block atomic_flag completionHandlerCalled = ATOMIC_FLAG_INIT;
  __block GADMediationNativeLoadCompletionHandler originalCompletionHandler =
      [completionHandler copy];

  _loadCompletionHandler = ^id<GADMediationNativeAdEventDelegate>(
      _Nullable id<GADMediationNativeAd> ad, NSError *_Nullable error) {
    // Only allow completion handler to be called once.
    if (atomic_flag_test_and_set(&completionHandlerCalled)) {
      return nil;
    }

    id<GADMediationNativeAdEventDelegate> delegate = nil;
    if (originalCompletionHandler) {
      // Call original handler and hold on to its return value.
      delegate = originalCompletionHandler(ad, error);
    }

    // Release reference to handler. Objects retained by the handler will also
    // be released.
    originalCompletionHandler = nil;

    return delegate;
  };

  SampleNativeAdLoader *adLoader = [[SampleNativeAdLoader alloc] init];
  SampleNativeAdRequest *sampleRequest = [[SampleNativeAdRequest alloc] init];

  // The Google Mobile Ads SDK requires the image assets to be downloaded
  // automatically unless the publisher specifies otherwise by using the
  // GADNativeAdImageAdLoaderOptions object's disableImageLoading property. If
  // your network doesn't have an option like this and instead only ever returns
  // URLs for images (rather than the images themselves), your adapter should
  // download image assets on behalf of the publisher. This should be done after
  // receiving the native ad object from your network's SDK, and before calling
  // the connector's adapter:didReceiveMediatedNativeAd: method.
  sampleRequest.shouldDownloadImages = YES;

  sampleRequest.preferredImageOrientation = NativeAdImageOrientationAny;
  sampleRequest.shouldRequestMultipleImages = NO;
  sampleRequest.testMode = adConfiguration.isTestRequest;

  for (GADAdLoaderOptions *loaderOptions in adConfiguration.options) {
    if ([loaderOptions isKindOfClass:[GADNativeAdImageAdLoaderOptions class]]) {
      GADNativeAdImageAdLoaderOptions *imageOptions =
          (GADNativeAdImageAdLoaderOptions *)loaderOptions;
      sampleRequest.shouldRequestMultipleImages =
          imageOptions.shouldRequestMultipleImages;

      // If the GADNativeAdImageAdLoaderOptions' disableImageLoading property is
      // YES, the adapter should send just the URLs for the images.
      sampleRequest.shouldDownloadImages = !imageOptions.disableImageLoading;
    } else if ([loaderOptions
                   isKindOfClass:[GADNativeAdMediaAdLoaderOptions class]]) {
      GADNativeAdMediaAdLoaderOptions *mediaOptions =
          (GADNativeAdMediaAdLoaderOptions *)loaderOptions;
      switch (mediaOptions.mediaAspectRatio) {
        case GADMediaAspectRatioLandscape:
          sampleRequest.preferredImageOrientation =
              NativeAdImageOrientationLandscape;
          break;
        case GADMediaAspectRatioPortrait:
          sampleRequest.preferredImageOrientation =
              NativeAdImageOrientationPortrait;
          break;
        default:
          sampleRequest.preferredImageOrientation = NativeAdImageOrientationAny;
          break;
      }
    } else if ([loaderOptions isKindOfClass:[GADNativeAdViewAdOptions class]]) {
      _nativeAdViewAdOptions = (GADNativeAdViewAdOptions *)loaderOptions;
    }
  }

  // This custom event uses the server parameter to carry an ad unit ID, which
  // is the most common use case.
  NSString *adUnit = adConfiguration.credentials.settings[@"parameter"];
  adLoader.adUnitID = adUnit;
  adLoader.delegate = self;

  [adLoader fetchAd:sampleRequest];
}

विज्ञापन को फ़ेच कर लिया गया है या उसे कोई गड़बड़ी मिली है, GADMediationNativeAdLoadCompletionHandler पर कॉल करेगा. अगर आपका चैनल सफल होता है, nil वैल्यू के साथ GADMediationNativeAd को लागू करने वाली क्लास से गुजरें पैरामीटर के लिए; अगर उल्लंघन होता है, तो उस गड़बड़ी को ठीक करें मिला.

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

Swift

func adLoader(
  _ adLoader: SampleNativeAdLoader, didReceive nativeAd: SampleNativeAd
) {
  extraAssets = [
    SampleCustomEventConstantsSwift.awesomenessKey: nativeAd.degreeOfAwesomeness
      ?? ""
  ]

  if let image = nativeAd.image {
    images = [GADNativeAdImage(image: image)]
  } else {
    let imageUrl = URL(fileURLWithPath: nativeAd.imageURL)
    images = [GADNativeAdImage(url: imageUrl, scale: nativeAd.imageScale)]
  }
  if let mappedIcon = nativeAd.icon {
    icon = GADNativeAdImage(image: mappedIcon)
  } else {
    let iconURL = URL(fileURLWithPath: nativeAd.iconURL)
    icon = GADNativeAdImage(url: iconURL, scale: nativeAd.iconScale)
  }

  adChoicesView = SampleAdInfoView()
  self.nativeAd = nativeAd
  if let handler = completionHandler {
    delegate = handler(self, nil)
  }
}

func adLoader(
  _ adLoader: SampleNativeAdLoader,
  didFailToLoadAdWith errorCode: SampleErrorCode
) {
  let error =
    SampleCustomEventUtilsSwift.SampleCustomEventErrorWithCodeAndDescription(
      code: SampleCustomEventErrorCodeSwift
        .SampleCustomEventErrorAdLoadFailureCallback,
      description:
        "Sample SDK returned an ad load failure callback with error code: \(errorCode)"
    )
  if let handler = completionHandler {
    delegate = handler(nil, error)
  }
}

Objective-C

- (void)adLoader:(SampleNativeAdLoader *)adLoader
    didReceiveNativeAd:(SampleNativeAd *)nativeAd {
  if (nativeAd.image) {
    _images = @[ [[GADNativeAdImage alloc] initWithImage:nativeAd.image] ];
  } else {
    NSURL *imageURL = [[NSURL alloc] initFileURLWithPath:nativeAd.imageURL];
    _images = @[ [[GADNativeAdImage alloc] initWithURL:imageURL
                                                 scale:nativeAd.imageScale] ];
  }

  if (nativeAd.icon) {
    _icon = [[GADNativeAdImage alloc] initWithImage:nativeAd.icon];
  } else {
    NSURL *iconURL = [[NSURL alloc] initFileURLWithPath:nativeAd.iconURL];
    _icon = [[GADNativeAdImage alloc] initWithURL:iconURL
                                            scale:nativeAd.iconScale];
  }

  // The sample SDK provides an AdChoices view (SampleAdInfoView). If your SDK
  // provides image and click through URLs for its AdChoices icon instead of an
  // actual UIView, the adapter is responsible for downloading the icon image
  // and creating the AdChoices icon view.
  _adChoicesView = [[SampleAdInfoView alloc] init];
  _nativeAd = nativeAd;

  _adEventDelegate = _loadCompletionHandler(self, nil);
}

- (void)adLoader:(SampleNativeAdLoader *)adLoader
    didFailToLoadAdWithErrorCode:(SampleErrorCode)errorCode {
  NSError *error = SampleCustomEventErrorWithCodeAndDescription(
      SampleCustomEventErrorAdLoadFailureCallback,
      [NSString stringWithFormat:@"Sample SDK returned an ad load failure "
                                 @"callback with error code: %@",
                                 errorCode]);
  _adEventDelegate = _loadCompletionHandler(nil, error);
}

नेटिव विज्ञापनों को मैप करें

नेटिव विज्ञापनों के लिए, अलग-अलग SDK टूल के अपने यूनीक फ़ॉर्मैट होते हैं. एक वापस आ सकता है "टाइटल" वाले ऑब्जेक्ट फ़ील्ड में डाल सकते हैं, जबकि किसी अन्य में "हेडलाइन" पाएं. इसके अलावा, इंप्रेशन और प्रोसेस को ट्रैक करने में इस्तेमाल की गई विधियों अलग-अलग SDK टूल को मिले क्लिक में अंतर हो सकता है.

इन समस्याओं को हल करने के लिए, जब किसी कस्टम इवेंट को इसका मीडिएशन SDK टूल है, तो इसे ऐसी क्लास का इस्तेमाल करना चाहिए जो GADMediationNativeAd को लागू करती हो, जैसे SampleCustomEventNativeAd, से "मैप" में मीडिएशन वाले SDK टूल का नेटिव विज्ञापन ऑब्जेक्ट इसलिए यह Google Mobile Ads SDK के इंटरफ़ेस से मैच करता है.

अब हम इन विज्ञापनों के लिए लागू करने से जुड़ी जानकारी SampleCustomEventNativeAd.

अपनी मैपिंग सेव करें

GADMediationNativeAd से कुछ ऐसी प्रॉपर्टी लागू की जा सकती हैं जो अन्य SDK टूल की प्रॉपर्टी से मैप किया गया हो:

Swift

var nativeAd: SampleNativeAd?

var headline: String? {
  return nativeAd?.headline
}

var images: [GADNativeAdImage]?

var body: String? {
  return nativeAd?.body
}

var icon: GADNativeAdImage?

var callToAction: String? {
  return nativeAd?.callToAction
}

var starRating: NSDecimalNumber? {
  return nativeAd?.starRating
}

var store: String? {
  return nativeAd?.store
}

var price: String? {
  return nativeAd?.price
}

var advertiser: String? {
  return nativeAd?.advertiser
}

var extraAssets: [String: Any]? {
  return [
    SampleCustomEventConstantsSwift.awesomenessKey:
      nativeAd?.degreeOfAwesomeness
      ?? ""
  ]
}

var adChoicesView: UIView?

var mediaView: UIView? {
  return nativeAd?.mediaView
}

Objective-C

/// Used to store the ad's images. In order to implement the
/// GADMediationNativeAd protocol, we use this class to return the images
/// property.
NSArray<GADNativeAdImage *> *_images;

/// Used to store the ad's icon. In order to implement the GADMediationNativeAd
/// protocol, we use this class to return the icon property.
GADNativeAdImage *_icon;

/// Used to store the ad's ad choices view. In order to implement the
/// GADMediationNativeAd protocol, we use this class to return the adChoicesView
/// property.
UIView *_adChoicesView;

- (nullable NSString *)headline {
  return _nativeAd.headline;
}

- (nullable NSArray<GADNativeAdImage *> *)images {
  return _images;
}

- (nullable NSString *)body {
  return _nativeAd.body;
}

- (nullable GADNativeAdImage *)icon {
  return _icon;
}

- (nullable NSString *)callToAction {
  return _nativeAd.callToAction;
}

- (nullable NSDecimalNumber *)starRating {
  return _nativeAd.starRating;
}

- (nullable NSString *)store {
  return _nativeAd.store;
}

- (nullable NSString *)price {
  return _nativeAd.price;
}

- (nullable NSString *)advertiser {
  return _nativeAd.advertiser;
}

- (nullable NSDictionary<NSString *, id> *)extraAssets {
  return
      @{SampleCustomEventExtraKeyAwesomeness : _nativeAd.degreeOfAwesomeness};
}

- (nullable UIView *)adChoicesView {
  return _adChoicesView;
}

- (nullable UIView *)mediaView {
  return _nativeAd.mediaView;
}

- (BOOL)hasVideoContent {
  return self.mediaView != nil;
}

कुछ मीडिएशन नेटवर्क, ऐसेट, Google मोबाइल विज्ञापन SDK टूल. GADMediationNativeAd प्रोटोकॉल में एक तरीका शामिल है extraAssets कहते हैं. Google Mobile Ads SDK इनमें से किसी भी एक आइटम को ये "अतिरिक्त" आपके मैपर से एसेट.

इमेज ऐसेट को मैप करें

इमेज ऐसेट को मैप करना, आसान डेटा को मैप करने के मुकाबले ज़्यादा मुश्किल है NSString या double जैसे टाइप. इमेज अपने-आप डाउनलोड हो सकती हैं या URL मानों के रूप में दिखाई जाती है. इनकी पिक्सल सघनता भी अलग-अलग हो सकती है.

इन जानकारी को मैनेज करने में आपकी मदद के लिए, Google Mobile Ads SDK GADNativeAdImage क्लास. इमेज एसेट की जानकारी (चाहे वह असल UIImage हो ऑब्जेक्ट या सिर्फ़ NSURL मान) को Google Mobile Ads SDK में लौटाया जाना चाहिए इस क्लास का इस्तेमाल कर रहे हैं.

यहां बताया गया है कि किस तरह मैपर क्लास,GADNativeAdImage आइकन चित्र:

Swift

if let image = nativeAd.image {
  images = [GADNativeAdImage(image: image)]
} else {
  let imageUrl = URL(fileURLWithPath: nativeAd.imageURL)
  images = [GADNativeAdImage(url: imageUrl, scale: nativeAd.imageScale)]
}

Objective-C

if (nativeAd.image) {
  _images = @[ [[GADNativeAdImage alloc] initWithImage:nativeAd.image] ];
} else {
  NSURL *imageURL = [[NSURL alloc] initFileURLWithPath:nativeAd.imageURL];
  _images = @[ [[GADNativeAdImage alloc] initWithURL:imageURL
                                               scale:nativeAd.imageScale] ];
}

इंप्रेशन और क्लिक इवेंट

Google Mobile Ads SDK और मीडिएशन वाले SDK टूल, दोनों को यह जानने की ज़रूरत होती है कि इंप्रेशन या क्लिक मिलता है, लेकिन इन इवेंट को सिर्फ़ एक SDK टूल ट्रैक करता है. यह लीजिए कस्टम इवेंट दो अलग-अलग तरीकों का इस्तेमाल कर सकते हैं. यह इस बात पर निर्भर करता है कि मीडिएशन SDK टूल, इंप्रेशन और क्लिक को खुद ट्रैक करने की सुविधा देता है.

Google Mobile Ads SDK की मदद से क्लिक और इंप्रेशन ट्रैक करें

अगर मीडिएशन वाला SDK टूल खुद के इंप्रेशन और क्लिक ट्रैकिंग का इस्तेमाल नहीं करता है, लेकिन क्लिक और इंप्रेशन रिकॉर्ड करने के तरीके उपलब्ध कराता है. Google Mobile Ads SDK इन इवेंट को ट्रैक करता है और अडैप्टर को सूचित करता है. GADMediationNativeAd प्रोटोकॉल इसमें दो तरीके शामिल होते हैं: didRecordImpression: और didRecordClickOnAssetWithName:view:viewController: कि कस्टम इवेंट ये काम कर सकते हैं मीडिएशन वाले नेटिव विज्ञापन ऑब्जेक्ट पर, उससे जुड़े तरीके को कॉल करने के लिए लागू करें:

Swift

func didRecordImpression() {
  nativeAd?.recordImpression()
}

func didRecordClickOnAsset(
  withName assetName: GADUnifiedNativeAssetIdentifier,
  view: UIView,
  wController: UIViewController
) {
  nativeAd?.handleClick(on: view)
}

Objective-C

- (void)didRecordImpression {
  if (self.nativeAd) {
    [self.nativeAd recordImpression];
  }
}

- (void)didRecordClickOnAssetWithName:(GADUnifiedNativeAssetIdentifier)assetName
                                 view:(UIView *)view
                       viewController:(UIViewController *)viewController {
  if (self.nativeAd) {
    [self.nativeAd handleClickOnView:view];
  }
}

क्योंकि GADMediationNativeAd को लागू करने वाली क्लास प्रोटोकॉल में सैंपल SDK टूल के नेटिव विज्ञापन ऑब्जेक्ट का रेफ़रंस होता है. यह उस ऑब्जेक्ट पर क्लिक या इंप्रेशन की रिपोर्ट करने का सही तरीका बताता है. ध्यान दें कि didRecordClickOnAssetWithName:view:viewController: तरीका एक बार पैरामीटर: नेटिव विज्ञापन की ऐसेट से जुड़ा View ऑब्जेक्ट क्लिक.

मीडिएशन वाले SDK टूल की मदद से, क्लिक और इंप्रेशन ट्रैक करें

मीडिएशन वाले कुछ SDK टूल, क्लिक और इंप्रेशन को खुद ही ट्रैक करना पसंद करते हैं. तय सीमा में उस मामले में, आपको handlesUserClicks और handlesUserImpressions तरीके हैं, जो नीचे स्निपेट में दिखाए गए हैं. वापस लौटने पर YES, आप बताते हैं कि कस्टम इवेंट, ट्रैकिंग की ज़िम्मेदारी लेता है इन इवेंट को एक्सपोर्ट करने के साथ-साथ, इन इवेंट के होने पर Google Mobile Ads SDK को इसकी सूचना देगा.

क्लिक और इंप्रेशन ट्रैकिंग को बदलने वाले कस्टम इवेंट, इन रणनीतियों का इस्तेमाल कर सकते हैं नेटिव विज्ञापन के व्यू को मध्यस्थ SDK टूल को पास करने के लिए didRenderInView: मैसेज नेटिव विज्ञापन ऑब्जेक्ट की मदद से, मीडिएशन वाले SDK टूल को असल में ट्रैक करने की अनुमति देता है. सैंपल हमारे कस्टम इवेंट के उदाहरण प्रोजेक्ट का SDK टूल (जिससे इस गाइड के कोड स्निपेट) लिया गया है) इस तरीके का इस्तेमाल नहीं करता' अगर ऐसा हुआ है, तो कस्टम इवेंट कोड setNativeAdView:view: तरीके को कॉल करेगा, जैसा कि नीचे स्निपेट में दिखाया गया है:

Swift

func handlesUserClicks() -> Bool {
  return true
}
func handlesUserImpressions() -> Bool {
  return true
}

func didRender(
  in view: UIView, clickableAssetViews: [GADNativeAssetIdentifier: UIView],
  nonclickableAssetViews: [GADNativeAssetIdentifier: UIView],
  viewController: UIViewController
) {
  // This method is called when the native ad view is rendered. Here you would pass the UIView
  // back to the mediated network's SDK.
  self.nativeAd?.setNativeAdView(view)
}

Objective-C

- (BOOL)handlesUserClicks {
  return YES;
}

- (BOOL)handlesUserImpressions {
  return YES;
}

- (void)didRenderInView:(UIView *)view
       clickableAssetViews:(NSDictionary<GADNativeAssetIdentifier, UIView *> *)
                               clickableAssetViews
    nonclickableAssetViews:(NSDictionary<GADNativeAssetIdentifier, UIView *> *)
                               nonclickableAssetViews
            viewController:(UIViewController *)viewController {
  // This method is called when the native ad view is rendered. Here you would
  // pass the UIView back to the mediated network's SDK. Playing video using
  // SampleNativeAd's playVideo method
  [_nativeAd setNativeAdView:view];
}

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

कॉल करने के बाद GADMediationNativeLoadCompletionHandler लोड किए गए विज्ञापन के साथ, लौटाया गया GADMediationNativeAdEventDelegate प्रतिनिधि तो अडैप्टर से प्रेज़ेंटेशन इवेंट को फ़ॉरवर्ड करने के लिए, ऑब्जेक्ट का इस्तेमाल किया जा सकता है तीसरे पक्ष के SDK टूल को Google Mobile Ads SDK में जोड़ा जा सकता है.

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

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