शुरू करें

Google की ईयू उपयोगकर्ता की सहमति से जुड़ी नीति के तहत, आपको यूके के साथ-साथ, यूरोपियन इकनॉमिक एरिया (ईईए) में अपने उपयोगकर्ताओं को कुछ जानकारी देनी होगी. साथ ही, जहां कानूनी तौर पर ज़रूरी है वहां कुकी या अन्य लोकल स्टोरेज का इस्तेमाल करने और विज्ञापन दिखाने के लिए निजी डेटा (जैसे कि AdID) का इस्तेमाल करने के लिए उनकी सहमति लेनी होगी. इस नीति में, ईयू के ई-निजता निर्देश और जनरल डेटा प्रोटेक्शन रेगुलेशन (जीडीपीआर) की ज़रूरी शर्तों के बारे में बताया गया है.

Google, User Messaging Platform (UMP) SDK टूल की सुविधा देता है, ताकि इस नीति के तहत अपनी ज़िम्मेदारी पूरी करने में पब्लिशर की मदद की जा सके. UMP SDK को IAB के नए मानकों के हिसाब से अपडेट किया गया है. ये सभी कॉन्फ़िगरेशन अब निजता और मैसेज सेवा में आसानी से मैनेज किए जा सकते हैं. Interactive Media Ads

UMP SDK टूल के साथ, IMA लागू करने की प्रोसेस को Objective-C या Swift सैंपल ऐप्लिकेशन में देखा जा सकता है.

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

मैसेज का टाइप बनाएं

किसी एक उपलब्ध उपयोगकर्ता मैसेज के टाइप अपने Ad Manager खाते के निजता और मैसेज सेवा टैब में जाएं. UMP SDK आपके प्रोजेक्ट में सेट किए गए Interactive Media Ads ऐप्लिकेशन आईडी से बनाए गए उपयोगकर्ता मैसेज को दिखाने की कोशिश करता है. अगर आपके ऐप्लिकेशन के लिए कोई मैसेज कॉन्फ़िगर नहीं किया गया है, तो SDK टूल एक गड़बड़ी दिखाएगा.

ज़्यादा जानकारी के लिए, निजता और मैसेज सेवा के बारे में जानकारी.

SDK टूल इंपोर्ट करें

UMP SDK को IMA SDK की डिपेंडेंसी के तौर पर शामिल नहीं किया जाता. इसलिए, आपको इसे खुद ही जोड़ना होगा.

CocoaPods (पसंदीदा)

CocoaPods का इस्तेमाल करके, SDK टूल को iOS प्रोजेक्ट में आसानी से इंपोर्ट किया जा सकता है. अपने प्रोजेक्ट की Podfile खोलें और इस लाइन को अपने ऐप्लिकेशन के टारगेट में जोड़ें:

pod 'GoogleUserMessagingPlatform'

इसके बाद, नीचे दिया गया कमांड चलाएं:

pod install --repo-update

अगर आपने CocoaPods का इस्तेमाल पहले कभी नहीं किया है, तो Podफ़ाइल बनाने और इस्तेमाल करने का तरीका जानने के लिए, CocoaPods का इस्तेमाल करना देखें.

Swift पैकेज मैनेजर

UMP SDK टूल का इस्तेमाल Swift पैकेज मैनेजर के साथ भी किया जा सकता है. Swift पैकेज इंपोर्ट करने के लिए यह तरीका अपनाएं.

  1. Xcode में, UMP SDK Swift Package को इंस्टॉल करने के लिए, फ़ाइल > पैकेज जोड़ें... पर जाएं.

  2. स्क्रीन पर दिख रहे प्रॉम्प्ट में, UMP SDK Swift पैकेज GitHub डेटा स्टोर करने की जगह खोजें:

    https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
    
  3. UMP SDK Swift पैकेज का वह वर्शन चुनें जिसका आपको इस्तेमाल करना है. नए प्रोजेक्ट के लिए, हम अगला मेजर वर्शन इस्तेमाल करने का सुझाव देते हैं.

इसके बाद, Xcode आपकी पैकेज डिपेंडेंसी का समाधान करता है और उन्हें बैकग्राउंड में डाउनलोड कर देता है. पैकेज डिपेंडेंसी जोड़ने के तरीके के बारे में ज़्यादा जानने के लिए, Apple का लेख पढ़ें.

आपको हर ऐप्लिकेशन लॉन्च के समय, requestConsentInfoUpdateWithParameters:completionHandler:का इस्तेमाल करके उपयोगकर्ता की सहमति से जुड़ी जानकारी को अपडेट करने का अनुरोध करना चाहिए. इससे यह तय होता है कि आपके उपयोगकर्ता को सहमति देने की ज़रूरत है या नहीं, अगर उसने अब तक ऐसा नहीं किया है या उसकी सहमति की समयसीमा खत्म हो गई है.

viewDidLoad() तरीके में UIViewController से स्टेटस की जांच करने का तरीका यहां बताया गया है.

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
    [weak self] requestConsentError in
    guard let self else { return }

    if let consentError = requestConsentError {
      // Consent gathering failed.
      return print("Error: \(consentError.localizedDescription)")
    }

    // TODO: Load and present the consent form.
  }
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:nil
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }

            // TODO: Load and present the consent form.
          }];
}

अगर ज़रूरी हो, तो सहमति फ़ॉर्म लोड करें और उसे प्रज़ेंट करें

सहमति का अप-टू-डेट स्टेटस मिलने के बाद, सहमति फ़ॉर्म लोड करने के लिए,UMPConsentForm क्लास मेंloadAndPresentIfRequiredFromViewController:completionHandler: को कॉल करें. अगर सहमति की स्थिति ज़रूरी है, तो SDK टूल एक फ़ॉर्म लोड करता है और तुरंत उसे दिए गए view controllerमें से दिखाता है. फ़ॉर्म खारिज होने के बाद, completion handler कॉल किया जाता है. अगर सहमति ज़रूरी नहीं है, तो completion handler . इसे तुरंत कॉल कर दिया जाता है.

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
    [weak self] requestConsentError in
    guard let self else { return }

    if let consentError = requestConsentError {
      // Consent gathering failed.
      return print("Error: \(consentError.localizedDescription)")
    }

    UMPConsentForm.loadAndPresentIfRequired(from: self) {
      [weak self] loadAndPresentError in
      guard let self else { return }

      if let consentError = loadAndPresentError {
        // Consent gathering failed.
        return print("Error: \(consentError.localizedDescription)")
      }

      // Consent has been gathered.
    }
  }
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:nil
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }

            __strong __typeof__(self) strongSelf = weakSelf;
            if (!strongSelf) {
              return;
            }

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  if (loadAndPresentError) {
                    // Consent gathering failed.
                    NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
                    return;
                  }

                  // Consent has been gathered.
                }];
          }];
}

अगर उपयोगकर्ता के चुने गए या फ़ॉर्म को खारिज करने के बाद, आपको कोई कार्रवाई करनी है, तो उस लॉजिक को अपने फ़ॉर्म के completion handler में डालें.

विज्ञापन जोड़ने का अनुरोध करें

अपने ऐप्लिकेशन में विज्ञापनों का अनुरोध करने से पहले, देख लें कि आपने UMPConsentInformation.sharedInstance.canRequestAdsका इस्तेमाल करके, उपयोगकर्ता से सहमति ली है या नहीं. सहमति इकट्ठा करते समय, इन दो बातों पर ध्यान देना ज़रूरी है:

  1. मौजूदा सेशन के लिए सहमति लेने के बाद.
  2. आपके कॉल करने के तुरंत बाद requestConsentInfoUpdateWithParameters:completionHandler:. ऐसा हो सकता है कि सहमति पिछले सेशन में ली गई हो. इंतज़ार का समय सबसे सही तरीका यह है कि हमारा सुझाव है कि कॉलबैक पूरा होने का इंतज़ार न करें, ताकि ऐप्लिकेशन लॉन्च होने के बाद, जितनी जल्दी हो सके विज्ञापन लोड हो सकें.

अगर सहमति इकट्ठा करने की प्रोसेस के दौरान कोई गड़बड़ी होती है, तब भी आपको विज्ञापनों का अनुरोध करने की कोशिश करनी चाहिए. UMP SDK टूल, पिछले सेशन की सहमति की स्थिति का इस्तेमाल करता है.

Swift

class ViewController: UIViewController {

  override func viewDidLoad() {
    super.viewDidLoad()

    // Request an update for the consent information.
    UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
      [weak self] requestConsentError in
      guard let self else { return }

      if let consentError = requestConsentError {
        // Consent gathering failed.
        return print("Error: \(consentError.localizedDescription)")
      }

      UMPConsentForm.loadAndPresentIfRequired(from: self) {
        [weak self] loadAndPresentError in
        guard let self else { return }

        if let consentError = loadAndPresentError {
          // Consent gathering failed.
          return print("Error: \(consentError.localizedDescription)")
        }

        // Consent has been gathered.
        if UMPConsentInformation.sharedInstance.canRequestAds {
          self.startImaSdk()
        }
      }
    }
    
    // Check if you can initialize the IMA SDK in parallel
    // while checking for new consent information. Consent obtained in
    // the previous session can be used to request ads.
    if UMPConsentInformation.sharedInstance.canRequestAds {
      startImaSdk()
    }
  }
  
  private func startImaSdk() {
    // Create an IMAAdsLoader instance.
    adsLoader = IMAAdsLoader(settings: nil)

    // TODO: Create an IMAAdDisplayContainer and IMAAdsRequest, then make
    // a request for ads.
  }
}

Objective-C

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:nil
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }
            __strong __typeof__(self) strongSelf = weakSelf;
            if (!strongSelf) {
              return;
            }

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  if (loadAndPresentError) {
                    // Consent gathering failed.
                    NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
                    return;
                  }

                  // Consent has been gathered.
                  __strong __typeof__(self) strongSelf = weakSelf;
                  if (!strongSelf) {
                    return;
                  }

                  if (UMPConsentInformation.sharedInstance.canRequestAds) {
                    [strongSelf startImaSdk];
                  }
                }];
          }];

  // Check if you can initialize the Google IMA SDK in parallel
  // while checking for new consent information. Consent obtained in
  // the previous session can be used to request ads.
  if (UMPConsentInformation.sharedInstance.canRequestAds) {
    [self startImaSdk];
  }
}

- (void)startImaSdk {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    // Create an IMAAdsLoader instance.
    self.adsLoader = [[IMAAdsLoader alloc] init];

    // TODO: Create an IMAAdDisplayContainer and IMAAdsRequest, then make
    // a request for ads.
  });
}

निजता के विकल्प

कुछ सहमति फ़ॉर्म के लिए, उपयोगकर्ता को किसी भी समय अपनी सहमति में बदलाव करना होता है. अगर ज़रूरी हो, तो निजता के विकल्प वाले बटन को लागू करने के लिए, यहां दिया गया तरीका अपनाएं.

इसके लिए:

  1. अपने ऐप्लिकेशन के सेटिंग पेज पर एक बटन जैसा यूज़र इंटरफ़ेस (यूआई) एलिमेंट लागू करें, जो निजता के विकल्पों वाले फ़ॉर्म को ट्रिगर कर सके.
  2. loadAndPresentIfRequiredFromViewController:completionHandler: पूरा होने के बाद,privacyOptionsRequirementStatus देखें कि आपको वह यूज़र इंटरफ़ेस (यूआई) एलिमेंट दिखाना है या नहीं जो निजता विकल्प वाला फ़ॉर्म दिखा सकता है.
  3. जब कोई उपयोगकर्ता आपके यूज़र इंटरफ़ेस (यूआई) एलिमेंट से इंटरैक्ट करता है, तो फ़ॉर्म दिखाने के लिएpresentPrivacyOptionsFormFromViewController:completionHandler: को कॉल करें, ताकि उपयोगकर्ता जब चाहे अपनी निजता सेटिंग को अपडेट कर सके.

यहां दिए गए उदाहरण में, UIBarButtonItem से निजता के विकल्पों वाला फ़ॉर्म दिखाने का तरीका बताया गया है.

Swift

@IBOutlet weak var privacySettingsButton: UIBarButtonItem!

var isPrivacyOptionsRequired: Bool {
  return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus == .required
}

override func viewDidLoad() {
  // ...

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
    // ...

    UMPConsentForm.loadAndPresentIfRequired(from: self) {
      //...

      // Consent has been gathered.

      // Show the button if privacy options are required.
      self.privacySettingsButton.isEnabled = isPrivacyOptionsRequired
    }
  }
  // ...
}

// Present the privacy options form when a user interacts with the
// privacy settings button.
@IBAction func privacySettingsTapped(_ sender: UIBarButtonItem) {
  UMPConsentForm.presentPrivacyOptionsForm(from: self) {
    [weak self] formError in
    guard let self, let formError else { return }

    // Handle the error.
  }
}

Objective-C

@interface ViewController ()
@property(weak, nonatomic) IBOutlet UIBarButtonItem *privacySettingsButton;
@end

- (BOOL)isPrivacyOptionsRequired {
  return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
         UMPPrivacyOptionsRequirementStatusRequired;
}

- (void)viewDidLoad {
  // ...

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            // ...

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  // ...

                  // Consent has been gathered.

                  // Show the button if privacy options are required.
                  strongSelf.privacySettingsButton.enabled = isPrivacyOptionsRequired;
                }];
          }];
}

// Present the privacy options form when a user interacts with your
// privacy settings button.
- (IBAction)privacySettingsTapped:(UIBarButtonItem *)sender {
  [UMPConsentForm presentPrivacyOptionsFormFromViewController:self
                                completionHandler:^(NSError *_Nullable formError) {
                                  if (formError) {
                                    // Handle the error.
                                  }
                                }];
}

टेस्ट करना

अगर आपको अपने ऐप्लिकेशन में इंटिग्रेशन की जांच करनी है, तो अपने टेस्ट डिवाइस को प्रोग्राम के हिसाब से रजिस्टर करें. इसके लिए, यह तरीका अपनाएं. अपने ऐप्लिकेशन को रिलीज़ करने से पहले, इन टेस्ट डिवाइस आईडी को सेट करने वाले कोड को ज़रूर हटा दें.

  1. requestConsentInfoUpdateWithParameters:completionHandler:पर कॉल करें.
  2. नीचे दिए गए उदाहरण से मिलते-जुलते मैसेज के लिए लॉग आउटपुट देखें. इसमें आपका डिवाइस आईडी और उसे टेस्ट डिवाइस के तौर पर जोड़ने का तरीका बताया गया है:

    <UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
    
  3. अपने टेस्ट डिवाइस आईडी को क्लिपबोर्ड पर कॉपी करें.

  4. अपने कोड में बदलाव करें, ताकि उसे कॉलUMPDebugSettings().testDeviceIdentifiers पर सेट किया जा सके और उसे टेस्ट डिवाइस आईडी की सूची को पास किया जा सके.UMPDebugSettings().testDeviceIdentifiers

    Swift

    let parameters = UMPRequestParameters()
    let debugSettings = UMPDebugSettings()
    debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
    parameters.debugSettings = debugSettings
    // Include the UMPRequestParameters in your consent request.
    UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
        with: parameters,
        completionHandler: { error in
          ...
        })
    

    Objective-C

    UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
    UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
    debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ];
    parameters.debugSettings = debugSettings;
    // Include the UMPRequestParameters in your consent request.
    [UMPConsentInformation.sharedInstance
        requestConsentInfoUpdateWithParameters:parameters
                            completionHandler:^(NSError *_Nullable error){
                              ...
    }];
    

जगह के हिसाब से कॉन्टेंट बनाना

UMP SDK टूल की मदद से, ऐप्लिकेशन के काम करने का तरीका टेस्ट किया जा सकता है. इससे यह समझने में मदद मिलती है कि the debugGeography property of type UMPDebugGeography on UMPDebugSettingsका इस्तेमाल करके, डिवाइस ईईए या यूके में मौजूद है या नहीं. ध्यान दें कि डीबग सेटिंग सिर्फ़ टेस्ट डिवाइसों पर काम करती हैं.

Swift

let parameters = UMPRequestParameters()
let debugSettings = UMPDebugSettings()
debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
debugSettings.geography = .EEA
parameters.debugSettings = debugSettings
// Include the UMPRequestParameters in your consent request.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
    with: parameters,
    completionHandler: { error in
      ...
    })

Objective-C

UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ];
debugSettings.geography = UMPDebugGeographyEEA;
parameters.debugSettings = debugSettings;
// Include the UMPRequestParameters in your consent request.
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                         completionHandler:^(NSError *_Nullable error){
                           ...
}];

UMP SDK टूल से अपने ऐप्लिकेशन की जांच करते समय, SDK टूल की स्थिति को रीसेट करने से आपको मदद मिल सकती है. इससे, उपयोगकर्ता के पहली बार इंस्टॉल करने के अनुभव को सिम्युलेट किया जा सकता है. यह काम करने के लिए, SDK टूल reset तरीका उपलब्ध कराता है.

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];