ইন্টারস্টিশিয়াল বিজ্ঞাপন কাস্টম ইভেন্ট

পূর্বশর্ত

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

একটি ইন্টারস্টিশিয়াল বিজ্ঞাপনের অনুরোধ করুন

কাস্টম ইভেন্ট লাইন আইটেম জলপ্রপাত মধ্যস্থতা শৃঙ্খলে পৌঁছে গেলে,the loadInterstitial:adConfiguration:completionHandler: method একটি কাস্টম ইভেন্ট তৈরি করার সময় আপনার দেওয়া ক্লাসের নামে ডাকা হয়। এই ক্ষেত্রে, সেই পদ্ধতিটি SampleCustomEvent এ রয়েছে, যা SampleCustomEventInterstitialএthe loadInterstitial:adConfiguration:completionHandler: method কল করে।

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

আমাদের কাস্টম ইভেন্টের উদাহরণে, SampleCustomEventthe GADMediationAdapter interface প্রয়োগ করে এবং তারপরSampleCustomEventInterstitialএ প্রতিনিধি করে।

সুইফট

import GoogleMobileAds

class SampleCustomEvent: NSObject, GADMediationAdapter {

  fileprivate var interstitialAd: SampleCustomEventInterstitial?
  ...

  func loadInterstitial(
    for adConfiguration: GADMediationInterstitialAdConfiguration,
    completionHandler: @escaping GADMediationInterstitialLoadCompletionHandler
  ) {
    self.interstitialAd = SampleCustomEventInterstitial()
    self.interstitialAd?.loadInterstitial(
      for: adConfiguration, completionHandler: completionHandler)
  }
}

উদ্দেশ্য গ

#import "SampleCustomEvent.h"

@implementation SampleCustomEvent

SampleCustomEventInterstitial *sampleInterstitial;

- (void)loadInterstitialForAdConfiguration:
            (GADMediationInterstitialAdConfiguration *)adConfiguration
                         completionHandler:
                             (GADMediationInterstitialLoadCompletionHandler)
                                 completionHandler {
  sampleInterstitial = [[SampleCustomEventInterstitial alloc] init];
  [sampleInterstitial loadInterstitialForAdConfiguration:adConfiguration
                                       completionHandler:completionHandler];
}

SampleCustomEventInterstitial নিম্নলিখিত কাজের জন্য দায়ী:

  • ইন্টারস্টিশিয়াল বিজ্ঞাপন লোড করা হচ্ছে এবং লোডিং শেষ হলে একটিGADMediationInterstitialAdLoadCompletionHandler method আহ্বান করা হচ্ছে

  • GADMediationInterstitialAd protocolবাস্তবায়ন করা

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

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

সুইফট

import GoogleMobileAds

class SampleCustomEventInterstitial: NSObject, GADMediationInterstitialAd {
  /// The Sample Ad Network interstitial ad.
  var interstitial: SampleInterstitial?

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

  var completionHandler: GADMediationInterstitialLoadCompletionHandler?

  func loadInterstitial(
    for adConfiguration: GADMediationInterstitialAdConfiguration,
    completionHandler: @escaping GADMediationInterstitialLoadCompletionHandler
  ) {
    interstitial = SampleInterstitial.init(
      adUnitID: adConfiguration.credentials.settings["parameter"] as? String)
    interstitial?.delegate = self
    let adRequest = SampleAdRequest()
    adRequest.testMode = adConfiguration.isTestRequest
    self.completionHandler = completionHandler
    interstitial?.fetchAd(adRequest)
  }

  func present(from viewController: UIViewController) {
    if let interstitial = interstitial, interstitial.isInterstitialLoaded {
      interstitial.show()
    }
  }
}

উদ্দেশ্য গ

#import "SampleCustomEventInterstitial.h"

@interface SampleCustomEventInterstitial () <SampleInterstitialAdDelegate,
                                             GADMediationInterstitialAd> {
  /// The sample interstitial ad.
  SampleInterstitial *_interstitialAd;

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

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

- (void)loadInterstitialForAdConfiguration:
            (GADMediationInterstitialAdConfiguration *)adConfiguration
                         completionHandler:
                             (GADMediationInterstitialLoadCompletionHandler)
                                 completionHandler {
  __block atomic_flag completionHandlerCalled = ATOMIC_FLAG_INIT;
  __block GADMediationInterstitialLoadCompletionHandler
      originalCompletionHandler = [completionHandler copy];

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

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

  NSString *adUnit = adConfiguration.credentials.settings[@"parameter"];
  _interstitialAd = [[SampleInterstitial alloc] initWithAdUnitID:adUnit];
  _interstitialAd.delegate = self;
  SampleAdRequest *adRequest = [[SampleAdRequest alloc] init];
  adRequest.testMode = adConfiguration.isTestRequest;
  [_interstitialAd fetchAd:adRequest];
}

বিজ্ঞাপনটি সফলভাবে আনা হোক বা কোনো ত্রুটির সম্মুখীন হোক, আপনি GADMediationInterstitialLoadCompletionHandler কল করবেন। সাফল্যের ক্ষেত্রে, ত্রুটির প্যারামিটারের জন্য একটি nil মান সহ GADMediationInterstitialAd প্রয়োগ করে এমন ক্লাসের মধ্য দিয়ে যান; ব্যর্থতার ক্ষেত্রে, আপনি যে ত্রুটির সম্মুখীন হয়েছেন তার মধ্য দিয়ে যান।

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

সুইফট

func interstitialDidLoad(_ interstitial: SampleInterstitial) {
  if let handler = completionHandler {
    delegate = handler(self, nil)
  }
}

func interstitial(
  _ interstitial: SampleInterstitial,
  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)interstitialDidLoad:(SampleInterstitial *)interstitial {
  _adEventDelegate = _loadCompletionHandler(self, nil);
}

- (void)interstitial:(SampleInterstitial *)interstitial
    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);
}

GADMediationInterstitialAd বিজ্ঞাপন প্রদর্শনের জন্য একটি present পদ্ধতি প্রয়োগ করতে হবে:

সুইফট

func present(from viewController: UIViewController) {
  if let interstitial = interstitial, interstitial.isInterstitialLoaded {
    interstitial.show()
  }
}

উদ্দেশ্য গ

- (void)presentFromViewController:(UIViewController *)viewController {
  if ([_interstitialAd isInterstitialLoaded]) {
    [_interstitialAd show];
  } else {
    NSError *error = SampleCustomEventErrorWithCodeAndDescription(
        SampleCustomEventErrorAdNotLoaded,
        [NSString stringWithFormat:@"The interstitial ad failed to present "
                                   @"because the ad was not loaded."]);
    [_adEventDelegate didFailToPresentWithError:error]
  }
}

মধ্যস্থতা ইভেন্টগুলি Google মোবাইল বিজ্ঞাপন SDK-এ ফরওয়ার্ড করুন

একবার আপনি একটি লোড করা বিজ্ঞাপনের সাথে GADMediationInterstitialLoadCompletionHandler কে কল করলে, ফেরত আসা GADMediationInterstitialAdEventDelegate প্রতিনিধি অবজেক্টটি অ্যাডাপ্টারের মাধ্যমে তৃতীয় পক্ষের SDK থেকে Google মোবাইল বিজ্ঞাপন SDK-তে উপস্থাপনা ইভেন্টগুলি ফরওয়ার্ড করতে ব্যবহার করা যেতে পারে। SampleCustomEventInterstitial ক্লাস নমুনা বিজ্ঞাপন নেটওয়ার্ক থেকে Google মোবাইল বিজ্ঞাপন SDK-এ কলব্যাক ফরওয়ার্ড করতে SampleInterstitialAdDelegate প্রোটোকল প্রয়োগ করে।

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

সুইফট

func interstitialWillPresentScreen(_ interstitial: SampleInterstitial) {
  delegate?.willPresentFullScreenView()
  delegate?.reportImpression()
}

func interstitialWillDismissScreen(_ interstitial: SampleInterstitial) {
  delegate?.willDismissFullScreenView()
}

func interstitialDidDismissScreen(_ interstitial: SampleInterstitial) {
  delegate?.didDismissFullScreenView()
}

func interstitialWillLeaveApplication(_ interstitial: SampleInterstitial) {
  delegate?.reportClick()
}

উদ্দেশ্য গ

- (void)interstitialWillPresentScreen:(SampleInterstitial *)interstitial {
  [_adEventDelegate willPresentFullScreenView];
  [_adEventDelegate reportImpression];
}

- (void)interstitialWillDismissScreen:(SampleInterstitial *)interstitial {
  [_adEventDelegate willDismissFullScreenView];
}

- (void)interstitialDidDismissScreen:(SampleInterstitial *)interstitial {
  [_adEventDelegate didDismissFullScreenView];
}

- (void)interstitialWillLeaveApplication:(SampleInterstitial *)interstitial {
  [_adEventDelegate reportClick];
}

এটি ইন্টারস্টিশিয়াল বিজ্ঞাপনের জন্য কাস্টম ইভেন্ট বাস্তবায়ন সম্পূর্ণ করে। সম্পূর্ণ উদাহরণ GitHub এ উপলব্ধ। আপনি এটিকে একটি বিজ্ঞাপন নেটওয়ার্কের সাথে ব্যবহার করতে পারেন যা ইতিমধ্যেই সমর্থিত বা কাস্টম ইভেন্ট ইন্টারস্টিশিয়াল বিজ্ঞাপনগুলি প্রদর্শন করতে এটিকে সংশোধন করতে পারেন৷