पुरस्कृत मध्यवर्ती

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

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

लागू करने का तरीका

इनाम वाले इंटरस्टीशियल विज्ञापनों को इंटिग्रेट करने के मुख्य चरण इस तरह हैं:

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

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

विज्ञापन को GADRewardedInterstitialAd क्लास पर स्टैटिक loadWithAdUnitID:request:completionHandler: तरीके से लोड किया जाता है. लोड करने के तरीके के लिए, आपका विज्ञापन यूनिट आईडी, GADRequest ऑब्जेक्ट, और पूरा होने वाले हैंडलर की ज़रूरत होती है. विज्ञापन लोड होने या न होने पर, इस हैंडलर को कॉल किया जाता है. लोड किया गया GADRewardedInterstitialAd ऑब्जेक्ट, पूरा होने वाले हैंडलर में पैरामीटर के तौर पर दिया जाता है. नीचे दिए गए उदाहरण में, ViewController क्लास में GADRewardedInterstitialAd को लोड करने का तरीका बताया गया है.

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController {

  private var rewardedInterstitialAd: GADRewardedInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()

    do {
      rewardedInterstitialAd = try await GADRewardedInterstitialAd.load(
        withAdUnitID: "ca-app-pub-3940256099942544/6978759866", request: GADRequest())
    } catch {
      print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
    }
  }
}

Objective-C

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic, strong) GADRewardedInterstitialAd* rewardedInterstitialAd;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  [GADRewardedInterstitialAd
      loadWithAdUnitID:@"<var label='the ad unit ID'>ca-app-pub-3940256099942544/6978759866</var>"
                request:[GADRequest request]
      completionHandler:^(
          GADRewardedInterstitialAd* _Nullable rewardedInterstitialAd,
          NSError* _Nullable error) {
        if (!error) {
          self.rewardedInterstitialAd = rewardedInterstitialAd;
        }
      }
  ];
}

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

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

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

Swift

do {
  rewardedInterstitialAd = try await GADRewardedInterstitialAd.load(
    withAdUnitID: "ca-app-pub-3940256099942544/6978759866", request: GADRequest())
  let options = GADServerSideVerificationOptions()
  options.customRewardString = "SAMPLE_CUSTOM_DATA_STRING"
  rewardedInterstitialAd.serverSideVerificationOptions = options
} catch {
  print("Rewarded ad failed to load with error: \(error.localizedDescription)")
}

Objective-C

[GADRewardedInterstitialAd
    loadWithAdUnitID:@"ca-app-pub-3940256099942544/6978759866"
              request:GADRequest
    completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
      if (error) {
        // Handle Error
        return;
      }
      self.rewardedInterstitialAd = ad;
      GADServerSideVerificationOptions *options =
          [[GADServerSideVerificationOptions alloc] init];
      options.customRewardString = @"SAMPLE_CUSTOM_DATA_STRING";
      ad.serverSideVerificationOptions = options;
    }];

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

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

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADFullScreenContentDelegate {

  private var rewardedInterstitialAd: GADRewardedInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()

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

  /// Tells the delegate that the ad failed to present full screen content.
  func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
    print("Ad did fail to present full screen content.")
  }

  /// Tells the delegate that the ad will present full screen content.
  func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad will present full screen content.")
  }

  /// Tells the delegate that the ad dismissed full screen content.
  func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad did dismiss full screen content.")
  }
}

Objective-C

@interface ViewController () <GADFullScreenContentDelegate>
@property(nonatomic, strong) GADRewardedInterstitialAd *rewardedInterstitialAd;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.

  [GADRewardedInterstitialAd
      loadWithAdUnitID:@"ca-app-pub-3940256099942544/6978759866"
                request:[GADRequest request]
      completionHandler:^(
          GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd,
          NSError *_Nullable error) {
        if (!error) {
          self.rewardedInterstitialAd = rewardedInterstitialAd;
          self.rewardedInterstitialAd.fullScreenContentDelegate = self;
        }
      }];
}

/// Tells the delegate that the ad failed to present full screen content.
- (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad
didFailToPresentFullScreenContentWithError:(nonnull NSError *)error {
    NSLog(@"Ad did fail to present full screen content.");
}

/// Tells the delegate that the ad will present full screen content.
- (void)adWillPresentFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {

    NSLog(@"Ad will present full screen content.");
}

/// Tells the delegate that the ad dismissed full screen content.
- (void)adDidDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
  NSLog(@"Ad did dismiss full screen content.");
}

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

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

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

Swift

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

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

Objective-C

- (void)show {
  // The UIViewController parameter is nullable.
  [_rewardedInterstitialAd presentFromRootViewController:nil
                                userDidEarnRewardHandler:^{

                                  GADAdReward *reward =
                                      self.rewardedInterstitialAd.adReward;
                                  // TODO: Reward the user.
                                }];
}

अगले चरण

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