নেটিভ বিজ্ঞাপন কাস্টম ইভেন্ট

প্ল্যাটফর্ম নির্বাচন করুন: অ্যান্ড্রয়েড আইওএস

পূর্বশর্ত

কাস্টম ইভেন্ট সেটআপ সম্পূর্ণ করুন।

একটি নেটিভ বিজ্ঞাপনের অনুরোধ করুন

যখন ওয়াটারফল মেডিয়েশন চেইনে কাস্টম ইভেন্ট লাইন আইটেমটি পৌঁছানো হয়, তখন কাস্টম ইভেন্ট তৈরি করার সময় আপনার দেওয়া ক্লাসের নামের উপর loadNativeAd:adConfiguration:completionHandler: পদ্ধতিটি কল করা হয়। এই ক্ষেত্রে, সেই পদ্ধতিটি SampleCustomEvent এ থাকে, যা পরে SampleCustomEventNativeloadNativeAd:adConfiguration:completionHandler: পদ্ধতিটিকে কল করে।

একটি নেটিভ বিজ্ঞাপনের অনুরোধ করতে, এমন একটি ক্লাস তৈরি বা পরিবর্তন করুন যা GADMediationAdapter এবং loadNativeAd:adConfiguration:completionHandler: প্রয়োগ করে। যদি GADMediationAdapter প্রসারিত করে এমন একটি ক্লাস ইতিমধ্যেই বিদ্যমান থাকে, তাহলে সেখানে loadNativeAd:adConfiguration:completionHandler: প্রয়োগ করুন। অতিরিক্তভাবে, GADMediationNativeAd বাস্তবায়নের জন্য একটি নতুন ক্লাস তৈরি করুন।

আমাদের কাস্টম ইভেন্ট উদাহরণে, SampleCustomEvent GADMediationAdapter ইন্টারফেস প্রয়োগ করে এবং তারপর SampleCustomEventNative এ ডেলিগেট করে।

সুইফট

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

অবজেক্টিভ-সি

#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 প্রোটোকল বাস্তবায়ন করা।

  • Google মোবাইল বিজ্ঞাপন SDK-তে বিজ্ঞাপন ইভেন্ট কলব্যাক গ্রহণ এবং রিপোর্ট করা।

বিজ্ঞাপন ম্যানেজার UI-তে সংজ্ঞায়িত ঐচ্ছিক প্যারামিটারটি বিজ্ঞাপন কনফিগারেশনে অন্তর্ভুক্ত থাকে। প্যারামিটারটি adConfiguration.credentials.settings[@"parameter"] এর মাধ্যমে অ্যাক্সেস করা যেতে পারে। এই প্যারামিটারটি সাধারণত একটি বিজ্ঞাপন ইউনিট শনাক্তকারী যা একটি বিজ্ঞাপন নেটওয়ার্ক SDK-এর জন্য একটি বিজ্ঞাপন বস্তু ইনস্ট্যান্টিয়েট করার সময় প্রয়োজন হয়।

সুইফট

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

অবজেক্টিভ-সি

#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 কল করবেন। সফল হলে, ত্রুটি প্যারামিটারের জন্য nil মান সহ GADMediationNativeAd প্রয়োগকারী ক্লাসটি পাস করুন; ব্যর্থ হলে, আপনার সম্মুখীন ত্রুটিটি পাস করুন।

সাধারণত, এই পদ্ধতিগুলি আপনার অ্যাডাপ্টার দ্বারা প্রয়োগ করা তৃতীয়-পক্ষের SDK থেকে কলব্যাকের ভিতরে প্রয়োগ করা হয়। এই উদাহরণের জন্য, Sample SDK-তে প্রাসঙ্গিক কলব্যাক সহ একটি SampleNativeAdDelegate রয়েছে:

সুইফট

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

অবজেক্টিভ-সি

- (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-তে পরিবর্তিত হতে পারে।

এই সমস্যাগুলি সমাধানের জন্য, যখন একটি কাস্টম ইভেন্ট তার মধ্যস্থতাকৃত SDK থেকে একটি নেটিভ বিজ্ঞাপন অবজেক্ট গ্রহণ করে, তখন এটিকে এমন একটি ক্লাস ব্যবহার করা উচিত যা GADMediationNativeAd প্রয়োগ করে, যেমন SampleCustomEventNativeAd , মধ্যস্থতাকৃত SDK এর নেটিভ বিজ্ঞাপন অবজেক্টটিকে "ম্যাপ" করার জন্য যাতে এটি Google মোবাইল বিজ্ঞাপন SDK দ্বারা প্রত্যাশিত ইন্টারফেসের সাথে মেলে।

আমরা এখন SampleCustomEventNativeAd এর বাস্তবায়নের বিশদটি ঘনিষ্ঠভাবে দেখব।

আপনার ম্যাপিং সংরক্ষণ করুন

GADMediationNativeAd অন্যান্য SDK এর বৈশিষ্ট্য থেকে ম্যাপ করা কিছু বৈশিষ্ট্য বাস্তবায়ন করবে বলে আশা করা হচ্ছে:

সুইফট

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
}

অবজেক্টিভ-সি

/// 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 Mobile Ads SDK দ্বারা নির্ধারিত সম্পদের বাইরেও অতিরিক্ত সম্পদ সরবরাহ করতে পারে। GADMediationNativeAd প্রোটোকলে extraAssets নামক একটি পদ্ধতি রয়েছে যা Google Mobile Ads SDK আপনার ম্যাপার থেকে এই "অতিরিক্ত" সম্পদগুলির যেকোনো একটি পুনরুদ্ধার করতে ব্যবহার করে।

মানচিত্রের চিত্র সম্পদ

NSString অথবা double মতো সহজ ডেটা টাইপ ম্যাপিংয়ের চেয়ে ছবির সম্পদ ম্যাপিং করা আরও জটিল। ছবিগুলি স্বয়ংক্রিয়ভাবে ডাউনলোড হতে পারে অথবা URL মান হিসাবে ফেরত পাঠানো হতে পারে। তাদের পিক্সেল ঘনত্বও পরিবর্তিত হতে পারে।

এই বিবরণগুলি পরিচালনা করতে আপনাকে সাহায্য করার জন্য, Google Mobile Ads SDK GADNativeAdImage ক্লাস প্রদান করে। ছবির সম্পদের তথ্য (সেটি প্রকৃত UIImage অবজেক্ট হোক বা কেবল NSURL মান) এই ক্লাস ব্যবহার করে Google Mobile Ads SDK-তে ফেরত পাঠানো উচিত।

আইকন ইমেজ ধরে রাখার জন্য ম্যাপার ক্লাস কীভাবে একটি GADNativeAdImage তৈরি করে তা এখানে দেখানো হয়েছে:

সুইফট

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

অবজেক্টিভ-সি

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 মোবাইল বিজ্ঞাপন SDK এবং মধ্যস্থতাকারী SDK উভয়কেই জানতে হবে কখন কোন ইম্প্রেশন বা ক্লিক হয়, কিন্তু এই ইভেন্টগুলি ট্র্যাক করার জন্য শুধুমাত্র একটি SDK-এর প্রয়োজন। মধ্যস্থতাকারী SDK ইম্প্রেশন এবং ক্লিকগুলি ট্র্যাক করার জন্য নিজে থেকে সমর্থন করে কিনা তার উপর নির্ভর করে কাস্টম ইভেন্ট দুটি ভিন্ন পদ্ধতি ব্যবহার করতে পারে।

Google মোবাইল বিজ্ঞাপন SDK ব্যবহার করে ক্লিক এবং ইম্প্রেশন ট্র্যাক করুন

যদি মধ্যস্থতাকারী SDK নিজস্ব ইম্প্রেশন এবং ক্লিক ট্র্যাকিং না করে কিন্তু ক্লিক এবং ইম্প্রেশন রেকর্ড করার পদ্ধতি প্রদান করে, তাহলে Google মোবাইল বিজ্ঞাপন SDK এই ইভেন্টগুলি ট্র্যাক করতে পারে এবং অ্যাডাপ্টারকে অবহিত করতে পারে। GADMediationNativeAd প্রোটোকলে দুটি পদ্ধতি রয়েছে: didRecordImpression: এবং didRecordClickOnAssetWithName:view:viewController: যা কাস্টম ইভেন্টগুলি মধ্যস্থতাকারী নেটিভ বিজ্ঞাপন অবজেক্টে সংশ্লিষ্ট পদ্ধতি কল করার জন্য প্রয়োগ করতে পারে:

সুইফট

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

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

অবজেক্টিভ-সি

- (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 প্রোটোকল প্রয়োগকারী ক্লাসটি Sample SDK এর নেটিভ বিজ্ঞাপন অবজেক্টের একটি রেফারেন্স ধারণ করে, তাই এটি ক্লিক বা ইম্প্রেশন রিপোর্ট করার জন্য সেই অবজেক্টের উপর উপযুক্ত পদ্ধতিটি কল করতে পারে। মনে রাখবেন যে didRecordClickOnAssetWithName:view:viewController: পদ্ধতিটি একটি একক প্যারামিটার নেয়: ক্লিকটি প্রাপ্ত নেটিভ বিজ্ঞাপন অ্যাসেটের সাথে সম্পর্কিত View অবজেক্ট।

মধ্যস্থতাকারী SDK ব্যবহার করে ক্লিক এবং ইম্প্রেশন ট্র্যাক করুন

কিছু মধ্যস্থতাকারী SDK নিজেরাই ক্লিক এবং ইম্প্রেশন ট্র্যাক করতে পছন্দ করতে পারে। সেক্ষেত্রে, আপনার নীচের স্নিপেটে দেখানো handlesUserClicks এবং handlesUserImpressions পদ্ধতিগুলি প্রয়োগ করা উচিত। YES ফেরত দেওয়ার মাধ্যমে, আপনি ইঙ্গিত দিচ্ছেন যে কাস্টম ইভেন্ট এই ইভেন্টগুলি ট্র্যাক করার দায়িত্ব নেয় এবং এই ইভেন্টগুলি ঘটলে Google Mobile Ads SDK কে অবহিত করবে।

ক্লিক এবং ইম্প্রেশন ট্র্যাকিংকে ওভাররাইড করে এমন কাস্টম ইভেন্টগুলি didRenderInView: বার্তা ব্যবহার করে নেটিভ বিজ্ঞাপনের ভিউ মধ্যস্থতাকারী SDK-এর নেটিভ বিজ্ঞাপন অবজেক্টে প্রেরণ করতে পারে যাতে মধ্যস্থতাকারী SDK প্রকৃত ট্র্যাকিং করতে পারে। আমাদের কাস্টম ইভেন্ট উদাহরণ প্রকল্পের নমুনা SDK (যা থেকে এই নির্দেশিকার কোড স্নিপেট নেওয়া হয়েছে) এই পদ্ধতি ব্যবহার করে না 'কিন্তু যদি এটি করে, তাহলে কাস্টম ইভেন্ট কোডটি setNativeAdView:view: পদ্ধতিকে কল করবে যেমনটি নীচের স্নিপেটে দেখানো হয়েছে:

সুইফট

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

অবজেক্টিভ-সি

- (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 মোবাইল বিজ্ঞাপন SDK-তে ফরোয়ার্ড করুন

একবার আপনি GADMediationNativeLoadCompletionHandler এ লোড করা বিজ্ঞাপন কল করলে, ফেরত আসা GADMediationNativeAdEventDelegate ডেলিগেট অবজেক্টটি অ্যাডাপ্টার দ্বারা তৃতীয় পক্ষের SDK থেকে Google মোবাইল বিজ্ঞাপন SDK-তে উপস্থাপনা ইভেন্ট ফরোয়ার্ড করতে ব্যবহার করা যেতে পারে।

আপনার কাস্টম ইভেন্টটি যতটা সম্ভব এই কলব্যাকগুলিকে ফরোয়ার্ড করা গুরুত্বপূর্ণ, যাতে আপনার অ্যাপটি Google Mobile Ads SDK থেকে এই সমতুল্য ইভেন্টগুলি গ্রহণ করে। কলব্যাক ব্যবহারের একটি উদাহরণ এখানে দেওয়া হল:

এটি নেটিভ বিজ্ঞাপনের জন্য কাস্টম ইভেন্ট বাস্তবায়ন সম্পূর্ণ করে। সম্পূর্ণ উদাহরণটি GitHub- এ উপলব্ধ।