البدء

بموجب سياسة موافقة المستخدم في الاتحاد الأوروبي التي تتّبعها Google، يجب الإفصاح عن معلومات معيّنة للمستخدمين في المنطقة الاقتصادية الأوروبية (EEA) والمملكة المتحدة والحصول على موافقتهم على استخدام ملفات تعريف الارتباط أو غير ذلك من البيانات المحفوظة على أجهزتهم المحلية حسب ما يقتضيه القانون، وعلى استخدام البيانات الشخصية (مثل AdID) لعرض الإعلانات. تعكس هذه السياسة شروط "التوجيه الأوروبي بشأن الخصوصية الإلكترونية" و"اللائحة العامة لحماية البيانات" (GDPR).

لدعم الناشرين في الوفاء بالتزاماتهم بموجب هذه السياسة، تقدّم Google حزمة تطوير البرامج (SDK) لمنصّة User Messaging Platform (UMP). تم تحديث حزمة تطوير البرامج لمنصة UMP لتتوافق مع أحدث معايير IAB. يمكن الآن التعامل مع كل هذه الإعدادات بسهولة في Interactive Media Ads الخصوصية والمراسلة.

يمكنك الاطّلاع على تنفيذ إعلانات الوسائط التفاعلية في الوقت الفعلي باستخدام حزمة تطوير البرامج لمنصّة UMP إما في نموذج تطبيقات UMP أو Objective-C أو Swift.

المتطلّبات الأساسية

إنشاء نوع رسالة

يمكنك إنشاء رسائل المستخدمين باستخدام أحد أنواع رسائل المستخدمين المتوفرة ضمن علامة تبويب الخصوصية والمراسلة في مدير الإعلانات . تحاول حزمة تطوير البرامج لمنصة UMP عرض رسالة مستخدم تم إنشاؤها من Interactive Media Ads معرّف التطبيق المحدّد في مشروعك. وفي حال عدم إعداد أي رسالة لتطبيقك، ستعرض حزمة تطوير البرامج (SDK) رسالة خطأ.

لمزيد من التفاصيل، يُرجى الاطّلاع على لمحة عن الخصوصية والمراسلة

استيراد حزمة تطوير البرامج (SDK)

لم يتم تضمين حزمة تطوير البرامج لمنصة UMP كملحق لحزمة تطوير البرامج لإعلانات الوسائط التفاعلية، لذا يجب عليك إضافتها بنفسك صراحةً.

CocoaPods (الخيار المفضّل)

أسهل طريقة لاستيراد حزمة تطوير البرامج (SDK) إلى مشروع iOS هي استخدام CocoaPods. افتح ملف Podfile الخاص بمشروعك وأضف هذا السطر إلى هدف تطبيقك:

pod 'GoogleUserMessagingPlatform'

بعد ذلك، شغِّل الأمر التالي:

pod install --repo-update

إذا كنت مستخدمًا جديدًا لـ CocoaPods، يمكنك الاطّلاع على استخدام CocoaPods للحصول على تفاصيل حول كيفية إنشاء ملفات Podfiles واستخدامها.

مدير حزم Swift

تدعم حزمة تطوير البرامج لمنصّة UMP أيضًا أداة "إدارة حزم Swift". اتبع هذه الخطوات لاستيراد حزمة Swift.

  1. في Xcode، ثبِّت حزمة UMP SDK Swift من خلال الانتقال إلى ملف > إضافة حِزم....

  2. في المطالبة التي تظهر، ابحث عن مستودع UMP SDK Swift Package GitHub:

    https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
    
  3. اختَر إصدار حزمة UMP SDK Swift الذي تريد استخدامه. وبالنسبة إلى المشاريع الجديدة، ننصح باستخدام الإصدار الرئيسي التالي.

يقوم Xcode بعد ذلك بحل تبعيات الحزمة الخاصة بك وتنزيلها في الخلفية. لمزيد من التفاصيل حول كيفية إضافة تبعيات الحزمة، راجع مقالة Apple.

يجب طلب تعديل لمعلومات موافقة المستخدم في كل مرة يتم فيها تشغيل التطبيق، وذلك باستخدام 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 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.
          }];
}
.

تحميل نموذج موافقة وتقديمه إذا لزم الأمر

بعد تلقّي أحدث حالة للموافقة، يمكنك الاتصال loadAndPresentIfRequiredFromViewController:completionHandler: في UMPConsentForm الفئة لتحميل نموذج موافقة. إذا كانت حالة الموافقة مطلوبة، تُحمِّل حزمة تطوير البرامج (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 حالة الموافقة من الجلسة السابقة.

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 واجتياز قائمة بأرقام تعريف أجهزة الاختبار.

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

فرض موقع جغرافي

توفّر حزمة تطوير البرامج (SDK) لمنصّة UMP وسيلة لاختبار سلوك تطبيقك كما لو كان الجهاز يقع في المنطقة الاقتصادية الأوروبية أو المملكة المتحدة باستخدام 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){
                           ...
}];

أثناء اختبار تطبيقك باستخدام حزمة تطوير البرامج (SDK) لمنصّة UMP، قد يكون من المفيد إعادة ضبط حالة حزمة تطوير البرامج (SDK) كي تتمكّن من محاكاة تجربة التثبيت الأولى للمستخدم. وتوفّر حزمة تطوير البرامج (SDK) الطريقة reset لإجراء ذلك.

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];