שנתחיל?

בהתאם למדיניות Google בנושא הסכמת משתמשים באיחוד האירופי, עליכם להציג הודעות גילוי נאות מסוימות למשתמשים שנמצאים באזור הכלכלי האירופי (EEA) ובבריטניה. בנוסף, אתם צריכים לקבל את הסכמתם לשימוש בקובצי cookie או באמצעים אחרים לאחסון מקומי, כשהדבר נדרש על פי חוק, ולשימוש במידע אישי (כמו מזהה פרסום) כדי להציג מודעות. המדיניות הזו משקפת את הדרישות שמפורטות ב-ePrivacy Directive (הדירקטיבה בנושא פרטיות ותקשורת אלקטרונית) וב-General Data Protection Regulation (התקנה הכללית להגנה על מידע, GDPR) של האיחוד האירופי.

כדי לעזור לבעלי אפליקציות למלא את החובות שלהם במסגרת המדיניות הזו, Google מציעה את User Messaging Platform (UMP) SDK. UMP SDK עודכן כדי לתמוך בתקנים העדכניים ביותר של IAB. מעכשיו אפשר לטפל בכל ההגדרות האלו בקלות, ב Interactive Media Ads פרטיות והודעות.

אפשר לראות איך הטמעה תקינה של IMA עם UMP SDK באפליקציות לדוגמה Objective-C או Swift שמופיעות ב-UMP.

דרישות מוקדמות

איך יוצרים את סוג ההודעה

אפשר ליצור הודעות למשתמשים באמצעות אחד הסוגים הזמינים של הודעות למשתמשים בכרטיסייה פרטיות והודעות בחשבון Ad Manager . UMP SDK מנסה להציג הודעת משתמש שנוצרה מ- Interactive Media Ads מזהה האפליקציה שהוגדר בפרויקט. אם לא הוגדרה הודעה לאפליקציה, ה-SDK יחזיר שגיאה.

לפרטים נוספים, ראו מידע על פרטיות והודעות

ייבוא ה-SDK

ה-UMP SDK לא נכלל כתלות ב-IMA SDK, ולכן עליכם להוסיף אותו באופן מפורש.

CocoaPods (מועדף)

הדרך הקלה ביותר לייבא את ה-SDK לפרויקט iOS היא באמצעות CocoaPods. פותחים את ה-Podfile של הפרויקט ומוסיפים את השורה הבאה ליעד של האפליקציה:

pod 'GoogleUserMessagingPlatform'

לאחר מכן, מריצים את הפקודה הבאה:

pod install --repo-update

אם זו הפעם הראשונה שאתם משתמשים ב-CocoaPods, ראו שימוש ב-CocoaPods כדי ללמוד איך ליצור Podfiles ולהשתמש בהם.

מנהל חבילות SWIFT

UMP SDK תומך גם ב-Swift Package Manager. מבצעים את השלבים הבאים כדי לייבא את חבילת Swift.

  1. ב-Xcode, מתקינים את UMP SDK Swift Package על ידי מעבר אל File > Add Packages....

  2. בהודעה שמופיעה, מחפשים את המאגר של UMP SDK Swift Package GitHub:

    https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
    
  3. בוחרים את הגרסה של UMP SDK Swift Package שבה רוצים להשתמש. לפרויקטים חדשים, מומלץ להשתמש ב-Up to Next Major Version.

לאחר מכן 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 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 ולהעביר רשימה של מזהי מכשירי הבדיקה.

    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 אפשר לבדוק את התנהגות האפליקציה כאילו המכשיר נמצא ב-EEA או בבריטניה באמצעות 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];