בהתאם למדיניות Google בנושא הסכמת משתמשים באיחוד האירופי, עליכם להציג הודעות גילוי נאות מסוימות למשתמשים שנמצאים באזור הכלכלי האירופי (EEA) ובבריטניה. בנוסף, אתם צריכים לקבל את הסכמתם לשימוש בקובצי cookie או באמצעים אחרים לאחסון מקומי, כשהדבר נדרש על פי חוק, ולשימוש במידע אישי (כמו מזהה פרסום) כדי להציג מודעות. המדיניות הזו משקפת את הדרישות שמפורטות ב-ePrivacy Directive (הדירקטיבה בנושא פרטיות ותקשורת אלקטרונית) וב-General Data Protection Regulation (התקנה הכללית להגנה על מידע, GDPR) של האיחוד האירופי.
כדי לעזור לבעלי אפליקציות למלא את החובות שלהם במסגרת המדיניות הזו, Google מציעה את User Messaging Platform (UMP) SDK. UMP SDK עודכן כדי לתמוך בתקנים העדכניים ביותר של IAB. מעכשיו אפשר לטפל בכל ההגדרות האלו בקלות, ב Ad Manager פרטיות והודעות.
דרישות מוקדמות
- מבצעים את ההוראות במדריך לתחילת העבודה.
- אם אתם עובדים על דרישות שקשורות ל-GDPR, כדאי לקרוא את המאמר איך הדרישות של IAB משפיעות על ההודעות בנושא הסכמה באיחוד האירופי
איך יוצרים את סוג ההודעה
אפשר ליצור הודעות למשתמשים באמצעות אחד הסוגים הזמינים של הודעות למשתמשים בכרטיסייה פרטיות והודעות בחשבון Ad Manager . UMP SDK מנסה להציג הודעת משתמש שנוצרה מ- Ad Manager מזהה האפליקציה שהוגדר בפרויקט. אם לא הוגדרה הודעה לאפליקציה, ה-SDK יחזיר שגיאה.
לפרטים נוספים, ראו מידע על פרטיות והודעות
ייבוא ה-SDK
CocoaPods (מועדף)
הדרך הקלה ביותר לייבא את ה-SDK לפרויקט iOS היא באמצעות CocoaPods. פותחים את ה-Podfile של הפרויקט ומוסיפים את השורה הבאה ליעד של האפליקציה:
pod 'GoogleUserMessagingPlatform'
לאחר מכן, מריצים את הפקודה הבאה:
pod install --repo-update
אם זו הפעם הראשונה שאתם משתמשים ב-CocoaPods, ראו שימוש ב-CocoaPods כדי ללמוד איך ליצור Podfiles ולהשתמש בהם.
מנהל חבילות SWIFT
UMP SDK תומך גם ב-Swift Package Manager. מבצעים את השלבים הבאים כדי לייבא את חבילת Swift.
ב-Xcode, מתקינים את UMP SDK Swift Package על ידי מעבר אל File > Add Packages....
בהודעה שמופיעה, מחפשים את המאגר של UMP SDK Swift Package GitHub:
https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
בוחרים את הגרסה של UMP SDK Swift Package שבה רוצים להשתמש. לפרויקטים חדשים, מומלץ להשתמש ב-Up to Next Major Version.
לאחר מכן Xcode פותר את יחסי התלות של החבילות ומוריד אותם ברקע. במאמר של Apple מוסבר איך מוסיפים יחסי תלות של חבילות.
הורדה ידנית
הדרך השנייה לייבא את ה-SDK היא לעשות זאת באופן ידני.
לאחר מכן גוררים את ה-framework לפרויקט ה-Xcode ובוחרים באפשרות Copy items if required (העתקת פריטים במקרה הצורך).
לאחר מכן, אתם יכולים לכלול את ה-framework בכל קובץ שאתם צריכים באמצעות:
Swift
import UserMessagingPlatform
Objective-C
#include <UserMessagingPlatform/UserMessagingPlatform.h>
בקשה למידע על הסכמה
צריך לבקש עדכון של פרטי ההסכמה של המשתמש בכל השקת אפליקציה, באמצעות 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
. יש שני מקומות שצריך לבדוק במהלך קבלת ההסכמה:
- אחרי שהתקבלה הסכמה בסשן הנוכחי.
- מיד לאחר שהתקשרת אל
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...];
});
}
אפשרויות פרטיות
חלק מטופסי ההסכמה מחייבים את המשתמשים לשנות את ההסכמה שלהם בכל שלב. אם צריך, עליכם לפעול לפי השלבים הבאים כדי להטמיע לחצן של אפשרויות פרטיות.
לשם כך:
- מטמיעים רכיב בממשק המשתמש, כמו לחצן בדף ההגדרות של האפליקציה, שיכול להפעיל טופס של אפשרויות פרטיות.
- בסיום
loadAndPresentIfRequiredFromViewController:completionHandler:
תהליך הבדיקה, בודקיםprivacyOptionsRequirementStatus
אם להציג את הרכיב בממשק המשתמש שיכול להציג את טופס אפשרויות הפרטיות. - כשמשתמש יוצר אינטראקציה עם הרכיב בממשק המשתמש, צריך לבצע קריאה ל-
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.
}
}];
}
בדיקה
אם רוצים לבדוק את השילוב באפליקציה במהלך הפיתוח, צריך לבצע את השלבים הבאים כדי לרשום את מכשיר הבדיקה באופן פרוגרמטי. חשוב להסיר את הקוד שמגדיר את המזהים של מכשירי הבדיקה האלה לפני פרסום האפליקציה.
- התקשרות אל
requestConsentInfoUpdateWithParameters:completionHandler:
. בודקים בפלט היומן הודעה שדומה לדוגמה הבאה, שבה מוצג מזהה המכשיר ואיך מוסיפים אותו כמכשיר בדיקה:
<UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
מעתיקים את מזהה מכשיר הבדיקה ללוח.
משנים את הקוד כדי להתקשר
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];
דוגמאות ב-GitHub
דוגמאות לשילוב של UMP SDK: Swift | Objective-C