কাস্টম ইভেন্ট লাইন আইটেম জলপ্রপাত মধ্যস্থতা শৃঙ্খলে পৌঁছে গেলে, loadBanner:adConfiguration:completionHandler: পদ্ধতিটি একটি কাস্টম ইভেন্ট তৈরি করার সময় আপনার দেওয়া ক্লাসের নামে ডাকা হয়। এই ক্ষেত্রে, সেই পদ্ধতিটি SampleCustomEvent এ রয়েছে, যা পরে SampleCustomEventBanner এ loadBanner:adConfiguration:completionHandler: পদ্ধতিকে কল করে।
একটি ব্যানার বিজ্ঞাপনের জন্য অনুরোধ করতে, একটি ক্লাস তৈরি বা সংশোধন করুন যা GADMediationAdapter এবং loadBanner:adConfiguration:completionHandler: প্রয়োগ করে। যদি GADMediationAdapter প্রসারিত করে এমন একটি ক্লাস ইতিমধ্যেই বিদ্যমান থাকে, loadBanner:adConfiguration:completionHandler: সেখানে প্রয়োগ করুন। উপরন্তু, GADMediationBannerAd বাস্তবায়নের জন্য একটি নতুন ক্লাস তৈরি করুন।
আমাদের কাস্টম ইভেন্ট উদাহরণে, SampleCustomEventGADMediationAdapter ইন্টারফেস প্রয়োগ করে এবং তারপর SampleCustomEventBanner এ প্রতিনিধি করে।
Google মোবাইল বিজ্ঞাপন SDK-এ বিজ্ঞাপন ইভেন্ট কলব্যাক গ্রহণ এবং প্রতিবেদন করা।
অ্যাড ম্যানেজার UI-তে সংজ্ঞায়িত ঐচ্ছিক প্যারামিটার বিজ্ঞাপন কনফিগারেশনে অন্তর্ভুক্ত করা হয়েছে। প্যারামিটারটি adConfiguration.credentials.settings[@"parameter"] এর মাধ্যমে অ্যাক্সেস করা যেতে পারে। এই প্যারামিটারটি সাধারণত একটি বিজ্ঞাপন ইউনিট শনাক্তকারী যা একটি বিজ্ঞাপন অবজেক্ট ইনস্ট্যান্ট করার সময় একটি বিজ্ঞাপন নেটওয়ার্ক SDK-এর প্রয়োজন হয়।
বিজ্ঞাপনটি সফলভাবে আনা হোক বা কোনো ত্রুটির সম্মুখীন হোক, আপনি GADMediationBannerLoadCompletionHandler কল করবেন। সাফল্যের ক্ষেত্রে, ত্রুটির প্যারামিটারের জন্য একটি nil মান সহ GADMediationBannerAd প্রয়োগ করে এমন ক্লাসের মধ্য দিয়ে যান; ব্যর্থতার ক্ষেত্রে, আপনি যে ত্রুটির সম্মুখীন হয়েছেন তার মধ্য দিয়ে যান।
সাধারণত, এই পদ্ধতিগুলি আপনার অ্যাডাপ্টার প্রয়োগ করে তৃতীয় পক্ষের SDK থেকে কলব্যাকের ভিতরে প্রয়োগ করা হয়। এই উদাহরণের জন্য, নমুনা SDK-তে প্রাসঙ্গিক কলব্যাক সহ একটি SampleBannerAdDelegate আছে:
মধ্যস্থতা ইভেন্টগুলি Google মোবাইল বিজ্ঞাপন SDK-এ ফরওয়ার্ড করুন
একবার আপনি একটি লোড করা বিজ্ঞাপনের সাথে GADMediationBannerLoadCompletionHandler কল করলে, ফেরত আসা GADMediationBannerAdEventDelegate প্রতিনিধি বস্তুটি অ্যাডাপ্টারের মাধ্যমে তৃতীয় পক্ষের SDK থেকে Google মোবাইল বিজ্ঞাপন SDK-তে উপস্থাপনা ইভেন্টগুলি ফরওয়ার্ড করতে ব্যবহার করা যেতে পারে৷ SampleCustomEventBanner ক্লাস নমুনা বিজ্ঞাপন নেটওয়ার্ক থেকে Google মোবাইল বিজ্ঞাপন SDK-এ কলব্যাক ফরওয়ার্ড করতে SampleBannerAdDelegate প্রোটোকল প্রয়োগ করে।
এটি গুরুত্বপূর্ণ যে আপনার কাস্টম ইভেন্ট যতটা সম্ভব এই কলব্যাকগুলিকে ফরওয়ার্ড করে, যাতে আপনার অ্যাপ Google মোবাইল বিজ্ঞাপন SDK থেকে এই সমতুল্য ইভেন্টগুলি পায়৷ এখানে কলব্যাক ব্যবহার করার একটি উদাহরণ:
এটি ব্যানার বিজ্ঞাপনের জন্য কাস্টম ইভেন্ট বাস্তবায়ন সম্পূর্ণ করে। সম্পূর্ণ উদাহরণ GitHub এ উপলব্ধ। আপনি এটিকে একটি বিজ্ঞাপন নেটওয়ার্কের সাথে ব্যবহার করতে পারেন যা ইতিমধ্যেই সমর্থিত বা কাস্টম ইভেন্ট ব্যানার বিজ্ঞাপনগুলি প্রদর্শন করতে এটি সংশোধন করতে পারেন৷
[[["সহজে বোঝা যায়","easyToUnderstand","thumb-up"],["আমার সমস্যার সমাধান হয়েছে","solvedMyProblem","thumb-up"],["অন্যান্য","otherUp","thumb-up"]],[["এতে আমার প্রয়োজনীয় তথ্য নেই","missingTheInformationINeed","thumb-down"],["খুব জটিল / অনেক ধাপ","tooComplicatedTooManySteps","thumb-down"],["পুরনো","outOfDate","thumb-down"],["অনুবাদ সংক্রান্ত সমস্যা","translationIssue","thumb-down"],["নমুনা / কোড সংক্রান্ত সমস্যা","samplesCodeIssue","thumb-down"],["অন্যান্য","otherDown","thumb-down"]],["2025-09-02 UTC-তে শেষবার আপডেট করা হয়েছে।"],[[["\u003cp\u003eTo request a banner ad within a custom event, create a class that implements \u003ccode\u003eGADMediationAdapter\u003c/code\u003e and the \u003ccode\u003eloadBanner:adConfiguration:completionHandler:\u003c/code\u003e method.\u003c/p\u003e\n"],["\u003cp\u003eA separate class implementing \u003ccode\u003eGADMediationBannerAd\u003c/code\u003e should handle loading the ad, reporting events to the Google Mobile Ads SDK, and providing a \u003ccode\u003eUIView\u003c/code\u003e property for display.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eGADMediationBannerLoadCompletionHandler\u003c/code\u003e is called upon ad load success or failure, passing the \u003ccode\u003eGADMediationBannerAd\u003c/code\u003e instance or an error, respectively.\u003c/p\u003e\n"],["\u003cp\u003eForward relevant ad events (like clicks) from the third-party ad network SDK to the Google Mobile Ads SDK using the \u003ccode\u003eGADMediationBannerAdEventDelegate\u003c/code\u003e received from the \u003ccode\u003eGADMediationBannerLoadCompletionHandler\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eRefer to the complete custom event example on GitHub for implementation details and guidance.\u003c/p\u003e\n"]]],["To request a banner ad via custom events, implement `GADMediationAdapter` and `loadBanner:adConfiguration:completionHandler:`, delegating to a class that implements `GADMediationBannerAd`. This class is responsible for loading the banner, implementing `GADMediationBannerAd`, and reporting ad event callbacks. The `loadBanner:` method within this class fetches the ad, and then invokes a completion handler (`GADMediationBannerLoadCompletionHandler`) whether loading succeeds or fails, passing the banner ad or an error, respectively. Finally, use `GADMediationBannerAdEventDelegate` to forward presentation events.\n"],null,["Prerequisites\n\nComplete the [custom events setup](/ad-manager/mobile-ads-sdk/ios/custom-events/setup).\n\nRequest a banner ad\n\nWhen the custom event line item is reached in the waterfall mediation chain,\nthe `loadBanner:adConfiguration:completionHandler:` method is called on the\nclass name you provided when [creating a custom\nevent](/ad-manager/mobile-ads-sdk/ios/custom-events/setup#create). In this case,\nthat method is in `SampleCustomEvent`, which then calls\nthe `loadBanner:adConfiguration:completionHandler:` method in\n`SampleCustomEventBanner`.\n\nTo request a banner ad, create or modify a class that implements\n`GADMediationAdapter` and `loadBanner:adConfiguration:completionHandler:`. If a\nclass that extends `GADMediationAdapter` already exists, implement\n`loadBanner:adConfiguration:completionHandler:` there. Additionally, create a\nnew class to implement `GADMediationBannerAd`.\n\nIn our custom event example,\n[`SampleCustomEvent`](//github.com/googleads/googleads-mobile-ios-mediation/blob/main/example/CustomEvent/SampleCustomEvent.m) implements\nthe `GADMediationAdapter` interface and then delegates to\n`SampleCustomEventBanner`. \n\nSwift \n\n```swift\nimport GoogleMobileAds\n\nclass SampleCustomEvent: NSObject, MediationAdapter {\n\n fileprivate var bannerAd: SampleCustomEventBanner?\n ...\n\n func loadBanner(\n for adConfiguration: MediationBannerAdConfiguration,\n completionHandler: @escaping GADMediationBannerLoadCompletionHandler\n ) {\n self.bannerAd = SampleCustomEventBanner()\n self.bannerAd?.loadBanner(\n for: adConfiguration, completionHandler: completionHandler)\n }\n}\n```\n\nObjective-C \n\n```objective-c\n#import \"SampleCustomEvent.h\"\n\n@implementation SampleCustomEvent\n...\n\nSampleCustomEventBanner *sampleBanner;\n\n- (void)loadBannerForAdConfiguration:\n (GADMediationBannerAdConfiguration *)adConfiguration\n completionHandler:(GADMediationBannerLoadCompletionHandler)\n completionHandler {\n sampleBanner = [[SampleCustomEventBanner alloc] init];\n [sampleBanner loadBannerForAdConfiguration:adConfiguration\n completionHandler:completionHandler];\n}\n```\n\n`SampleCustomEventBanner` is responsible for the following tasks:\n\n- Loading the banner ad and invoking a\n [`GADMediationBannerLoadCompletionHandler`](/ad-manager/mobile-ads-sdk/ios/api/reference/Protocols/GADMediationAdapter) method once\n loading completes.\n\n- Implementing the `GADMediationBannerAd` protocol.\n\n- Receiving and reporting ad event callbacks to Google Mobile Ads SDK.\n\nThe optional parameter defined in the Ad Manager UI is\nincluded in the ad configuration.\nThe parameter can be accessed through\n`adConfiguration.credentials.settings[@\"parameter\"]`. This parameter is\ntypically an ad unit identifier that an ad network SDK requires when\ninstantiating an ad object. \n\nSwift \n\n```swift\nclass SampleCustomEventBanner: NSObject, MediationBannerAd {\n /// The Sample Ad Network banner ad.\n var bannerAd: SampleBanner?\n\n /// The ad event delegate to forward ad rendering events to Google Mobile Ads SDK.\n var delegate: MediationBannerAdEventDelegate?\n\n /// Completion handler called after ad load\n var completionHandler: GADMediationBannerLoadCompletionHandler?\n\n func loadBanner(\n for adConfiguration: MediationBannerAdConfiguration,\n completionHandler: @escaping GADMediationBannerLoadCompletionHandler\n ) {\n // Create the bannerView with the appropriate size.\n let adSize = adConfiguration.adSize\n bannerAd = SampleBanner(\n frame: CGRect(x: 0, y: 0, width: adSize.size.width, height: adSize.size.height))\n bannerAd?.delegate = self\n bannerAd?.adUnit = adConfiguration.credentials.settings[\"parameter\"] as? String\n let adRequest = SampleAdRequest()\n adRequest.testMode = adConfiguration.isTestRequest\n self.completionHandler = completionHandler\n bannerAd?.fetchAd(adRequest)\n }\n}\n```\n\nObjective-C \n\n```objective-c\n#import \"SampleCustomEventBanner.h\"\n\n@interface SampleCustomEventBanner () \u003cSampleBannerAdDelegate,\n GADMediationBannerAd\u003e {\n /// The sample banner ad.\n SampleBanner *_bannerAd;\n\n /// The completion handler to call when the ad loading succeeds or fails.\n GADMediationBannerLoadCompletionHandler _loadCompletionHandler;\n\n /// The ad event delegate to forward ad rendering events to the Google Mobile\n /// Ads SDK.\n id \u003cGADMediationBannerAdEventDelegate\u003e _adEventDelegate;\n}\n@end\n\n@implementation SampleCustomEventBanner\n\n- (void)loadBannerForAdConfiguration:\n (GADMediationBannerAdConfiguration *)adConfiguration\n completionHandler:(GADMediationBannerLoadCompletionHandler)\n completionHandler {\n __block atomic_flag completionHandlerCalled = ATOMIC_FLAG_INIT;\n __block GADMediationBannerLoadCompletionHandler originalCompletionHandler =\n [completionHandler copy];\n\n _loadCompletionHandler = ^id\u003cGADMediationBannerAdEventDelegate\u003e(\n _Nullable id\u003cGADMediationBannerAd\u003e ad, NSError *_Nullable error) {\n // Only allow completion handler to be called once.\n if (atomic_flag_test_and_set(&completionHandlerCalled)) {\n return nil;\n }\n\n id\u003cGADMediationBannerAdEventDelegate\u003e delegate = nil;\n if (originalCompletionHandler) {\n // Call original handler and hold on to its return value.\n delegate = originalCompletionHandler(ad, error);\n }\n\n // Release reference to handler. Objects retained by the handler will also\n // be released.\n originalCompletionHandler = nil;\n\n return delegate;\n };\n\n NSString *adUnit = adConfiguration.credentials.settings[@\"parameter\"];\n _bannerAd = [[SampleBanner alloc]\n initWithFrame:CGRectMake(0, 0, adConfiguration.adSize.size.width,\n adConfiguration.adSize.size.height)];\n _bannerAd.adUnit = adUnit;\n _bannerAd.delegate = self;\n SampleAdRequest *adRequest = [[SampleAdRequest alloc] init];\n adRequest.testMode = adConfiguration.isTestRequest;\n [_bannerAd fetchAd:adRequest];\n}\n```\n\nWhether the ad is successfully fetched or encounters an error, you\nwould call `GADMediationBannerLoadCompletionHandler`. In the event of success,\npass through the class that implements `GADMediationBannerAd` with a `nil` value\nfor the error parameter; in the event of failure, pass through the error you\nencountered.\n\nTypically, these methods are implemented inside callbacks from the\nthird-party SDK your adapter implements. For this example, the Sample SDK\nhas a `SampleBannerAdDelegate` with relevant callbacks: \n\nSwift \n\n```swift\nfunc bannerDidLoad(_ banner: SampleBanner) {\n if let handler = completionHandler {\n delegate = handler(self, nil)\n }\n}\n\nfunc banner(\n _ banner: SampleBanner, didFailToLoadAdWith errorCode: SampleErrorCode\n) {\n let error =\n SampleCustomEventUtilsSwift.SampleCustomEventErrorWithCodeAndDescription(\n code: SampleCustomEventErrorCodeSwift\n .SampleCustomEventErrorAdLoadFailureCallback,\n description:\n \"Sample SDK returned an ad load failure callback with error code: \\(errorCode)\"\n )\n if let handler = completionHandler {\n delegate = handler(nil, error)\n }\n}\n```\n\nObjective-C \n\n```objective-c\n- (void)bannerDidLoad:(SampleBanner *)banner {\n _adEventDelegate = _loadCompletionHandler(self, nil);\n}\n\n- (void)banner:(SampleBanner *)banner\n didFailToLoadAdWithErrorCode:(SampleErrorCode)errorCode {\n NSError *error = SampleCustomEventErrorWithCodeAndDescription(\n SampleCustomEventErrorAdLoadFailureCallback,\n [NSString stringWithFormat:@\"Sample SDK returned an ad load failure \"\n @\"callback with error code: %@\",\n errorCode]);\n _adEventDelegate = _loadCompletionHandler(nil, error);\n}\n```\n\n`GADMediationBannerAd` requires implementing a `UIView` property: \n\nSwift \n\n```swift\nvar view: UIView {\n return bannerAd ?? UIView()\n}\n```\n\nObjective-C \n\n```objective-c\n- (nonnull UIView *)view {\n return _bannerAd;\n}\n```\n\nForward mediation events to Google Mobile Ads SDK\n\nOnce you've called `GADMediationBannerLoadCompletionHandler` with a loaded ad,\nthe returned `GADMediationBannerAdEventDelegate` delegate object can then be\nused by the adapter to forward presentation events from the third-party SDK to\nGoogle Mobile Ads SDK. The `SampleCustomEventBanner` class implements the\n`SampleBannerAdDelegate` protocol to forward callbacks from the sample ad\nnetwork to Google Mobile Ads SDK.\n\nIt's important that your custom event forwards as many of these callbacks as\npossible, so that your app receives these equivalent events from Google Mobile Ads SDK.\nHere's an example of using callbacks: \n\nSwift \n\n```swift\nfunc bannerWillLeaveApplication(_ banner: SampleBanner) {\n delegate?.reportClick()\n}\n```\n\nObjective-C \n\n```objective-c\n- (void)bannerWillLeaveApplication:(SampleBanner *)banner {\n [_adEventDelegate reportClick];\n}\n```\n\nThis completes the custom events implementation for banner ads. The full example\nis available on\n[GitHub](//github.com/googleads/googleads-mobile-ios-mediation/tree/main/example/CustomEvent).\nYou can use it with an ad network that is already supported or modify it to\ndisplay custom event banner ads."]]