الأحداث المخصّصة للإعلانات المدمجة مع المحتوى

المتطلبات الأساسية

أكمِل إعداد الأحداث المخصّصة.

طلب إعلان مدمج مع المحتوى

عند الوصول إلى عنصر سعر الحدث المخصّص في سلسلة توسّط العرض الإعلاني بدون انقطاع، يتم استدعاء الطريقة 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, MediationAdapter {

  fileprivate var nativeAd: SampleCustomEventNativeAd?

  func loadNativeAd(
    for adConfiguration: MediationNativeAdConfiguration,
    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];
}

تتولّى السمة SampleCustomEventNative` المهام التالية:

  • تحميل الإعلان المدمج مع المحتوى

  • تنفيذ بروتوكول GADMediationNativeAd

  • تلقّي عمليات ردّ الاتصال الخاصة بأحداث الإعلانات وإعداد تقارير عنها في حزمة "SDK لإعلانات Google على الأجهزة الجوّالة"

يتم تضمين المَعلمة الاختيارية المحدّدة في واجهة مستخدم AdMob ضمن إعدادات الإعلان. يمكن الوصول إلى المَعلمة من خلال adConfiguration.credentials.settings[@"parameter"]. تكون هذه المَعلمة عادةً معرّف وحدة إعلانية تتطلّبه حزمة تطوير البرامج (SDK) التابعة لشبكة إعلانية عند إنشاء مثيل لكائن إعلان.

Swift

class SampleCustomEventNativeAd: NSObject, MediationNativeAd {
  /// 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: MediationNativeAdEventDelegate?

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

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

    // 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: AdLoaderOptions in options {
      if let imageOptions = loaderOptions as? NativeAdImageAdLoaderOptions {
        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? NativeAdMediaAdLoaderOptions
      {
        switch mediaOptions.mediaAspectRatio {
        case MediaAspectRatio.landscape:
          sampleRequest.preferredImageOrientation =
            NativeAdImageOrientation.landscape
        case MediaAspectRatio.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];

  // 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. في حال النجاح، مرِّر الفئة التي تنفّذ GADMediationNativeAd مع قيمة nil لمَعلمة الخطأ. وفي حال التعذّر، مرِّر الخطأ الذي واجهته.

عادةً، يتم تنفيذ هذه الطرق داخل عمليات ردّ الاتصال من حزمة تطوير البرامج (SDK) التابعة لجهة خارجية التي ينفّذها المحوّل. في هذا المثال، تحتوي حزمة تطوير البرامج (SDK) النموذجية على SampleNativeAdDelegate مع عمليات رد اتصال ذات صلة:

Swift

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

  if let image = nativeAd.image {
    images = [NativeAdImage(image: image)]
  } else {
    let imageUrl = URL(fileURLWithPath: nativeAd.imageURL)
    images = [NativeAdImage(url: imageUrl, scale: nativeAd.imageScale)]
  }
  if let mappedIcon = nativeAd.icon {
    icon = NativeAdImage(image: mappedIcon)
  } else {
    let iconURL = URL(fileURLWithPath: nativeAd.iconURL)
    icon = NativeAdImage(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);
}

الإعلانات المدمجة مع المحتوى على "خرائط Google"

تتضمّن حِزم تطوير البرامج (SDK) المختلفة أشكالاً فريدة خاصة بها للإعلانات المدمجة مع المحتوى. قد يعرض أحدهما عناصر تحتوي على حقل "العنوان" مثلاً، بينما قد يعرض الآخر "العنوان الرئيسي". بالإضافة إلى ذلك، يمكن أن تختلف الطرق المستخدَمة لتتبُّع مرّات الظهور ومعالجة النقرات من حزمة SDK إلى أخرى.

لحلّ هذه المشاكل، عندما يتلقّى حدث مخصّص عنصر إعلان مدمج مع المحتوى من حزمة SDK الخاصة بالوسيط، يجب أن يستخدم فئة تنفّذ GADMediationNativeAd، مثل SampleCustomEventNativeAd، من أجل "ربط" عنصر الإعلان المدمج مع المحتوى الخاص بحزمة SDK الخاصة بالوسيط لكي يتطابق مع الواجهة التي تتوقّعها "حزمة تطوير البرامج SDK لإعلانات Google على الأجهزة الجوّالة".

سنتناول الآن تفاصيل التنفيذ الخاصة بـ SampleCustomEventNativeAd.

تخزين عمليات الربط

من المتوقّع أن تنفّذ GADMediationNativeAd بعض السمات التي يتم ربطها بسمات حِزم SDK الأخرى:

Swift

var nativeAd: SampleNativeAd?

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

var images: [NativeAdImage]?

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

var icon: NativeAdImage?

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;
}

يمكن أن توفّر بعض الشبكات المستخدِمة للتوسّط مواد عرض إضافية بخلاف تلك المحدّدة من خلال حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة. يتضمّن البروتوكول GADMediationNativeAd طريقة تُسمّى extraAssets تستخدمها حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة لاسترداد أيّ من مواد العرض "الإضافية" هذه من أداة الربط.

مواد عرض الصور الخاصة بالخرائط

تكون عملية ربط مواد عرض الصور أكثر تعقيدًا من ربط أنواع البيانات الأبسط مثل NSString أو double. قد يتم تنزيل الصور تلقائيًا أو عرضها كقيم عناوين URL. ويمكن أن تختلف كثافة البكسل فيها أيضًا.

لمساعدتك في إدارة هذه التفاصيل، توفّر حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة الفئة GADNativeAdImage. يجب عرض معلومات مواد عرض الصور (سواء كانت UIImage كائنات فعلية أو مجرد قيم NSURL) في حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة باستخدام هذه الفئة.

في ما يلي كيفية تعامل فئة أداة الربط مع إنشاء GADNativeAdImage لاحتواء صورة الرمز:

Swift

if let image = nativeAd.image {
  images = [NativeAdImage(image: image)]
} else {
  let imageUrl = URL(fileURLWithPath: nativeAd.imageURL)
  images = [NativeAdImage(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] ];
}

أحداث الظهور والنقر

يجب أن تعرف كلّ من &quot;حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة&quot; و&quot;حزمة تطوير البرامج (SDK) للوساطة&quot; وقت حدوث مرّة ظهور أو نقرة، ولكن يجب أن تتتبّع إحدى الحزمتين فقط هذه الأحداث. هناك طريقتان مختلفتان يمكن أن تستخدمهما الأحداث المخصّصة، وذلك حسب ما إذا كان حزمة تطوير البرامج (SDK) الخاصة بالوساطة تتيح تتبُّع مرّات الظهور والنقرات من تلقاء نفسها.

تتبُّع النقرات ومرّات الظهور باستخدام "SDK لإعلانات Google على الأجهزة الجوّالة"

إذا كانت حزمة SDK الخاصة بالوساطة لا تتتبّع مرّات الظهور والنقرات، ولكنّها توفّر طرقًا لتسجيل النقرات ومرّات الظهور، يمكن لحزمة "SDK لإعلانات Google على الأجهزة الجوّالة" تتبُّع هذه الأحداث وإرسال إشعار إلى أداة الربط. يتضمّن بروتوكول 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، تشير إلى أنّ الحدث المخصّص يتحمّل مسؤولية تتبُّع هذه الأحداث، وسيُعلم حزمة "SDK لإعلانات Google على الأجهزة الجوّالة" عند وقوعها.

يمكن للأحداث المخصّصة التي تتجاوز تتبُّع النقرات ومرّات الظهور استخدام الرسالة didRenderInView: لتمرير طريقة عرض الإعلان المدمج مع المحتوى إلى عنصر الإعلان المدمج مع المحتوى في حزمة SDK الخاصة بالوساطة، ما يتيح لحزمة 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];
}

إعادة توجيه أحداث الوساطة إلى حزمة "SDK لإعلانات Google على الأجهزة الجوّالة"

بعد طلب GADMediationNativeLoadCompletionHandler باستخدام إعلان تم تحميله، يمكن للمحوّل استخدام عنصر GADMediationNativeAdEventDelegate الذي تم عرضه لإعادة توجيه أحداث العرض من حزمة SDK التابعة لجهة خارجية إلى حزمة SDK لإعلانات Google على الأجهزة الجوّالة.

من المهم أن يعيد توجيه الحدث المخصّص أكبر عدد ممكن من عمليات معاودة الاتصال هذه، لكي يتلقّى تطبيقك الأحداث المكافئة من حزمة تطوير البرامج (SDK) لإعلانات Google على الأجهزة الجوّالة. في ما يلي مثال على استخدام عمليات معاودة الاتصال:

بهذا نكون قد أكملنا عملية تنفيذ الأحداث المخصّصة للإعلانات المدمجة مع المحتوى. يتوفّر المثال الكامل على GitHub.