शुरू करें

Google User Messaging Platform (UMP) SDK टूल, निजता और मैसेज सेवा के लिए इस्तेमाल किया जाने वाला एक टूल है. निजता से जुड़े विकल्पों को मैनेज करने में आपको मदद मिलती है. ज़्यादा जानकारी के लिए, यह देखें निजता और सुरक्षा के बारे में जानकारी मैसेज सेवा. UMP SDK टूल की मदद से, IMA लागू करने की प्रोसेस को इनमें से किसी एक मकसद-सी या स्विफ़्ट UMP के सैंपल ऐप्लिकेशन.

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

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

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

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

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

CocoaPods (पसंदीदा)

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

pod 'GoogleUserMessagingPlatform'

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

pod install --repo-update

अगर आप CocoaPods के लिए नए हैं, तो CocoaPods Podfiles बनाना और इस्तेमाल करना.

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

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

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

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

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

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

ऐप्लिकेशन आईडी जोड़ें

आप यहां अपना ऐप्लिकेशन आईडी देख सकते हैं: Ad Manager का यूज़र इंटरफ़ेस (यूआई). आईडी को अपने Info.plist के लिए यहां दिए गए कोड स्निपेट का इस्तेमाल करें:

<key>UMPApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>

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

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

यहां एक उदाहरण दिया गया है किUIViewController viewDidLoad() तरीका.

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 privacy message 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 privacy message form.
          }];
}

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

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

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 को भी डाउनलोड करें.

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

निजता से जुड़े कुछ मैसेज फ़ॉर्म, पब्लिशर की रेंडर की गई निजता से दिखाए जाते हैं विकल्प एंट्री पॉइंट, जिससे उपयोगकर्ता अपनी निजता के विकल्पों को किसी भी समय मैनेज कर सकते हैं. निजता से जुड़े विकल्पों पर जाकर, इस बारे में ज़्यादा जानें कि आपके उपयोगकर्ताओं को कौनसा मैसेज दिखता है एंट्री पॉइंट, देखें उपयोगकर्ता के लिए उपलब्ध मैसेज के टाइप.

निजता के विकल्प वाला एंट्री पॉइंट लागू करने के लिए, इन चरणों को पूरा करें:

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

कोड के इस उदाहरण में, इन चरणों को दिखाया गया है:

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

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

अपने ऐप्लिकेशन में विज्ञापनों का अनुरोध करने से पहले, देख लें कि आपको सहमति मिली है या नहीं UMPConsentInformation.sharedInstance.canRequestAdsका इस्तेमाल कर रहे हैं. दो सहमति लेते समय चेक करने के लिए स्थान:

  • मौजूदा सेशन में सहमति लेने के बाद.
  • आपके कॉल करने के तुरंत बाद 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. 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 टूल reset तरीका उपलब्ध कराता है.

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];

GitHub पर उदाहरण

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