शुरू करें

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

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

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

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

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

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

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

CocoaPods (पसंदीदा)

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

pod 'GoogleUserMessagingPlatform'

इसके बाद, इस कमांड को चलाएं:

pod install --repo-update

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

स्विफ़्ट पैकेज मैनेजर

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

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

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

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

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

मैन्युअल डाउनलोड

SDK टूल को इंपोर्ट करने का एक और तरीका है, इसे मैन्युअल तरीके से इंपोर्ट करना.

SDK टूल डाउनलोड करना

इसके बाद, फ़्रेमवर्क को अपने Xcode प्रोजेक्ट में खींचें और पक्का करें कि आपने ज़रूरी होने पर आइटम कॉपी करें को चुना हो.

इसके बाद, इस्तेमाल की जाने वाली किसी भी फ़ाइल में फ़्रेमवर्क शामिल किया जा सकता है:

Swift

import UserMessagingPlatform

Objective-C

#include <UserMessagingPlatform/UserMessagingPlatform.h>

आपको 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.
          }];
}

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

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

सहमति की स्थिति की अप-टू-डेट जानकारी मिलने के बाद, सहमति फ़ॉर्म लोड करने के लिए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 {

  // Use a boolean to initialize the Google Mobile Ads SDK and load ads once.
  private var isMobileAdsStartCalled = false

  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.startGoogleMobileAdsSDK()
        }
      }
    }
    
    // Check if you can initialize the Google Mobile Ads 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 {
      startGoogleMobileAdsSDK()
    }
  }
  
  private func startGoogleMobileAdsSDK() {
    DispatchQueue.main.async {
      guard !self.isMobileAdsStartCalled else { return }

      self.isMobileAdsStartCalled = true

      // Initialize the Google Mobile Ads SDK.
      GADMobileAds.sharedInstance().start()

      // TODO: Request an ad.
      // GADInterstitialAd.load(...)
    }
  }
}

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 startGoogleMobileAdsSDK];
                  }
                }];
          }];

  // Check if you can initialize the Google Mobile Ads 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 startGoogleMobileAdsSDK];
  }
}

- (void)startGoogleMobileAdsSDK {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    // Initialize the Google Mobile Ads SDK.
    [GADMobileAds.sharedInstance startWithCompletionHandler:nil];

    // TODO: Request an ad.
    // [GADInterstitialAd loadWithAdUnitID...];
  });
}

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

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

इसके लिए:

  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 सेट करें और पास करें .

    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];

GitHub पर उदाहरण

UMP SDK टूल इंटिग्रेशन के उदाहरण: Swift | Objective-C