इनाम वाला इंटरस्टीशियल विज्ञापन

प्लैटफ़ॉर्म चुनें: Android iOS Unity Flutter

इनाम वाले इंटरस्टीशियल विज्ञापन, इंसेंटिव वाले विज्ञापन फ़ॉर्मैट का एक टाइप है. इसकी मदद से, ऐप्लिकेशन में स्वाभाविक तौर पर हुए ट्रांज़िशन के दौरान दिखने वाले विज्ञापनों के लिए इनाम दिए जा सकते हैं. उपयोगकर्ताओं को इनाम वाले इंटरस्टीशियल विज्ञापन देखने के लिए, ऑप्ट-इन करना ज़रूरी नहीं होता. इनाम वाले विज्ञापनों के लिए ऐसा करना ज़रूरी है.

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

लागू करना

इनाम वाले इंटरस्टीशियल विज्ञापन इंटिग्रेट करने के लिए, यह तरीका अपनाएं:

  • विज्ञापन लोड करना
  • [ज़रूरी नहीं] एसएसवी कॉलबैक की पुष्टि करना
  • कॉलबैक के लिए रजिस्टर करना
  • विज्ञापन दिखाना और इनाम वाले इवेंट को मैनेज करना

विज्ञापन लोड करना

विज्ञापन को लोड करने के लिए, GADRewardedInterstitialAd क्लास में load(adUnitID:request) तरीके का इस्तेमाल किया जाता है.

Swift

func loadRewardedInterstitialAd() async {
  do {
    rewardedInterstitialAd = try await RewardedInterstitialAd.load(
      // Replace this ad unit ID with your own ad unit ID.
      with: "adUnitID", request: Request())
    rewardedInterstitialAd?.fullScreenContentDelegate = self
  } catch {
    print("Rewarded ad failed to load with error: \(error.localizedDescription)")
  }
}

SwiftUI

import GoogleMobileAds

class RewardedInterstitialViewModel: NSObject, ObservableObject,
  FullScreenContentDelegate
{
  @Published var coins = 0
  private var rewardedInterstitialAd: RewardedInterstitialAd?

  func loadAd() async {
    do {
      rewardedInterstitialAd = try await RewardedInterstitialAd.load(
        with: "ca-app-pub-3940256099942544/6978759866", request: Request())
      rewardedInterstitialAd?.fullScreenContentDelegate = self
    } catch {
      print(
        "Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
    }
  }

Objective-C

- (void)loadRewardedInterstitialAd {
  [GADRewardedInterstitialAd loadWithAdUnitID:"adUnitID"
                                      request:[GADRequest request]
                            completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
                              if (error) {
                                NSLog(@"Failed to load rewarded interstitial ad with error: %@",
                                      error.localizedDescription);
                                return;
                              }
                              self.rewardedInterstitialAd = ad;
                              self.rewardedInterstitialAd.fullScreenContentDelegate = self;
                            }];
}

adUnitID की जगह अपना विज्ञापन यूनिट आईडी डालें.

[ज़रूरी नहीं] सर्वर साइड से की जाने वाली पुष्टि (एसएसवी) के कॉलबैक की पुष्टि करना

जिन ऐप्लिकेशन को सर्वर-साइड वेरिफ़िकेशन कॉलबैक में अतिरिक्त डेटा की ज़रूरत होती है उन्हें इनाम वाले विज्ञापनों की कस्टम डेटा सुविधा का इस्तेमाल करना चाहिए. इनाम वाले विज्ञापन ऑब्जेक्ट पर सेट की गई कोई भी स्ट्रिंग वैल्यू, एसएसवी कॉलबैक के custom_data क्वेरी पैरामीटर को पास की जाती है. अगर कोई कस्टम डेटा वैल्यू सेट नहीं की जाती है, तो एसएसवी कॉलबैक में custom_data क्वेरी पैरामीटर वैल्यू मौजूद नहीं होगी.

नीचे दिए गए कोड सैंपल में, विज्ञापन का अनुरोध करने से पहले इनाम वाले इंटरस्टीशियल विज्ञापन ऑब्जेक्ट पर कस्टम डेटा सेट करने का तरीका बताया गया है.

Swift

private func validateServerSideVerification() async {
  do {
    rewardedInterstitialAd = try await RewardedInterstitialAd.load(
      // Replace this ad unit ID with your own ad unit ID.
      with: "adUnitID", request: Request())
    let options = ServerSideVerificationOptions()
    options.customRewardText = ""SAMPLE_CUSTOM_DATA_STRING""
    rewardedInterstitialAd?.serverSideVerificationOptions = options
  } catch {
    print("Rewarded ad failed to load with error: \(error.localizedDescription)")
  }
}

Objective-C

- (void)validateServerSideVerification {
  // Replace this ad unit ID with your own ad unit ID.
  [GADRewardedInterstitialAd loadWithAdUnitID:"adUnitID"
                                      request:[GADRequest request]
                            completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
                              if (error) {
                                NSLog(@"Rewarded interstitial ad failed to load with error: %@",
                                      error.localizedDescription);
                                return;
                              }
                              self.rewardedInterstitialAd = ad;
                              GADServerSideVerificationOptions *options =
                                  [[GADServerSideVerificationOptions alloc] init];
                              options.customRewardString = @""SAMPLE_CUSTOM_DATA_STRING"";
                              ad.serverSideVerificationOptions = options;
                            }];
}

SAMPLE_CUSTOM_DATA_STRING की जगह अपना कस्टम डेटा डालें.

कॉलबैक के लिए रजिस्टर करना

प्रज़ेंटेशन इवेंट की सूचनाएं पाने के लिए, आपको GADFullScreenContentDelegate को दिखाए गए विज्ञापन की fullScreenContentDelegate प्रॉपर्टी में असाइन करना होगा:

Swift

rewardedInterstitialAd?.fullScreenContentDelegate = self

SwiftUI

rewardedInterstitialAd?.fullScreenContentDelegate = self

Objective-C

self.rewardedInterstitialAd.fullScreenContentDelegate = self;

GADFullScreenContentDelegate प्रोटोकॉल, विज्ञापन के दिखने या न दिखने और उसे खारिज किए जाने के लिए कॉलबैक को मैनेज करता है. नीचे दिए गए कोड में, प्रोटोकॉल को लागू करने और उसे विज्ञापन को असाइन करने का तरीका बताया गया है:

Swift

func adDidRecordImpression(_ ad: FullScreenPresentingAd) {
  print("\(#function) called.")
}

func adDidRecordClick(_ ad: FullScreenPresentingAd) {
  print("\(#function) called.")
}

func adWillPresentFullScreenContent(_ ad: FullScreenPresentingAd) {
  print("\(#function) called.")
}

func adWillDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
  print("\(#function) called.")
}

func adDidDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
  print("\(#function) called.")
  // Clear the rewarded interstitial ad.
  rewardedInterstitialAd = nil
}

func ad(
  _ ad: FullScreenPresentingAd,
  didFailToPresentFullScreenContentWithError error: Error
) {
  print("\(#function) called with error: \(error.localizedDescription).")
}

SwiftUI

func adDidRecordImpression(_ ad: FullScreenPresentingAd) {
  print("\(#function) called")
}

func adDidRecordClick(_ ad: FullScreenPresentingAd) {
  print("\(#function) called")
}

func ad(
  _ ad: FullScreenPresentingAd,
  didFailToPresentFullScreenContentWithError error: Error
) {
  print("\(#function) called")
}

func adWillPresentFullScreenContent(_ ad: FullScreenPresentingAd) {
  print("\(#function) called")
}

func adWillDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
  print("\(#function) called")
}

func adDidDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
  print("\(#function) called")
  // Clear the rewarded interstitial ad.
  rewardedInterstitialAd = nil
}

Objective-C

- (void)adDidRecordImpression:(id<GADFullScreenPresentingAd>)ad {
  NSLog(@"%s called", __PRETTY_FUNCTION__);
}

- (void)adDidRecordClick:(id<GADFullScreenPresentingAd>)ad {
  NSLog(@"%s called", __PRETTY_FUNCTION__);
}

- (void)adWillPresentFullScreenContent:(id<GADFullScreenPresentingAd>)ad {
  NSLog(@"%s called", __PRETTY_FUNCTION__);
}

- (void)adWillDismissFullScreenContent:(id<GADFullScreenPresentingAd>)ad {
  NSLog(@"%s called", __PRETTY_FUNCTION__);
}

- (void)adDidDismissFullScreenContent:(id<GADFullScreenPresentingAd>)ad {
  NSLog(@"%s called", __PRETTY_FUNCTION__);
  // Clear the rewarded interstitial ad.
  self.rewardedInterstitialAd = nil;
}

- (void)ad:(id)ad didFailToPresentFullScreenContentWithError:(NSError *)error {
  NSLog(@"%s called with error: %@", __PRETTY_FUNCTION__, error.localizedDescription);
}

विज्ञापन दिखाना और इनाम वाले इवेंट को मैनेज करना

विज्ञापन दिखाते समय, आपको उपयोगकर्ता को इनाम देने के लिए GADUserDidEarnRewardHandler ऑब्जेक्ट देना होगा.

नीचे दिए गए कोड में, इनाम वाले इंटरस्टीशियल विज्ञापन दिखाने का सबसे सही तरीका बताया गया है.

Swift

func showRewardedInterstitialAd() {
  guard let rewardedInterstitialAd = rewardedInterstitialAd else {
    return print("Ad wasn't ready.")
  }

  // The UIViewController parameter is an optional.
  rewardedInterstitialAd.present(from: nil) {
    let reward = rewardedInterstitialAd.adReward
    print("Reward received with currency \(reward.amount), amount \(reward.amount.doubleValue)")
    // TODO: Reward the user.
  }
}

SwiftUI

विज्ञापन दिखाने के लिए, व्यू में यूज़र इंटरफ़ेस (यूआई) इवेंट सुनें.

var rewardedInterstitialBody: some View {
  // ...
  }
  .onChange(
    of: showAd,
    perform: { newValue in
      if newValue {
        viewModel.showAd()
      }
    }
  )

व्यू मॉडल से इनाम वाला इंटरस्टीशियल विज्ञापन दिखाएं:

func showAd() {
  guard let rewardedInterstitialAd = rewardedInterstitialAd else {
    return print("Ad wasn't ready.")
  }

  rewardedInterstitialAd.present(from: nil) {
    let reward = rewardedInterstitialAd.adReward
    print("Reward amount: \(reward.amount)")
    self.addCoins(reward.amount.intValue)
  }
}

Objective-C

- (void)showRewardedInterstitialAd {
  [self.rewardedInterstitialAd presentFromRootViewController:self
                                    userDidEarnRewardHandler:^{
                                      GADAdReward *reward = self.rewardedInterstitialAd.adReward;

                                      NSString *rewardMessage = [NSString
                                          stringWithFormat:@"Reward received with "
                                                           @"currency %@ , amount %ld",
                                                           reward.type, [reward.amount longValue]];
                                      NSLog(@"%@", rewardMessage);
                                      // TODO: Reward the user.
                                    }];
}

GitHub पर मौजूद उदाहरण

इनाम वाले इंटरस्टीशियल विज्ञापनों के सभी उदाहरण, अपनी पसंद की भाषा में देखें:

अगले चरण

उपयोगकर्ता की निजता के बारे में ज़्यादा जानें.