בהתאם למדיניות של Google בנושא הסכמת משתמשים באיחוד האירופי, עליכם להציג הודעות גילוי נאות מסוימות למשתמשים שנמצאים באזור הכלכלי האירופי (EEA) ובבריטניה, ולקבל את הסכמתם לשימוש בקובצי cookie או באמצעים אחרים לאחסון מקומי, היכן שהדבר נדרש על פי חוק, וכדי להשתמש במידע אישי (כמו מזהה פרסום) לצורך הצגת מודעות. המדיניות הזו משקפת את הדרישות שמפורטות בהנחיה בנושא פרטיות ותקשורת אלקטרונית ובתקנת General Data Protection Regulation (התקנה הכללית להגנה על מידע (GDPR)) של האיחוד האירופי.
כדי לעזור לבעלי תוכן דיגיטלי למלא את חובותיהם במסגרת המדיניות הזו, Google מציעה את ה-User Messaging Platform (UMP) SDK. ה-UMP SDK עודכן כדי לתמוך בתקנים העדכניים ביותר של IAB. עכשיו אפשר לטפל בכל ההגדרות האלה ב AdMob 'פרטיות והודעות' בצורה נוחה.
דרישות מוקדמות
- משלימים את המדריך לתחילת העבודה
- אם אתם עובדים על דרישות שקשורות ל-GDPR, כדאי לקרוא את איך הדרישות של IAB משפיעות על הודעות בנושא הסכמה באיחוד האירופי
יצירת סוג הודעה
יצירת הודעות למשתמשים באמצעות אחד הסוגים הזמינים של הודעות למשתמשים בכרטיסייה פרטיות והודעות בחשבון AdMob שלך. ה-UMP SDK מנסה להציג הודעה למשתמש שנוצרה ממזהה האפליקציה AdMob שהוגדר בפרויקט שלכם. אם לא מוגדרת הודעה לאפליקציה, ה-SDK יחזיר הודעת שגיאה.
פרטים נוספים זמינים במאמר מידע על פרטיות והודעות.
ייבוא ה-SDK
CocoaPods (מועדף)
ה-UMP SDK נכלל בהתאם לרצף של Google Mobile Ads SDK שמתחיל ב-Google Mobile Ads SDK 7.64.0.
הדרך הקלה ביותר לייבא את ה-SDK לפרויקט ל-iOS היא באמצעות CocoaPods. פותחים את ה-Podfile של הפרויקט ומוסיפים את השורה הבאה ליעד של האפליקציה:
pod 'Google-Mobile-Ads-SDK'
לאחר מכן, מריצים את הפקודה הבאה:
pod install --repo-update
אם זו הפעם הראשונה שאתם משתמשים ב-CocoaPods, תוכלו לקרוא את המאמר שימוש ב-CocoaPods כדי להבין איך ליצור קבצים ואיך להשתמש בהם.
הורדה ידנית
הדרך השנייה לייבא את ה-SDK היא לעשות זאת באופן ידני.
לאחר מכן גוררים את ה-framework לפרויקט ה-Xcode, ומקפידים לבחור באפשרות Copy items if needed.
לאחר מכן אפשר לכלול את ה-framework בכל קובץ שדרוש לכם באמצעות:
Swift
import UserMessagingPlatform
Objective-C
#include <UserMessagingPlatform/UserMessagingPlatform.h>
בקשה לפרטי הסכמה
צריך לבקש עדכון של פרטי ההסכמה של המשתמש בכל השקה של האפליקציה, באמצעות requestConsentInfoUpdateWithParameters:completionHandler:
. אפשרות זו קובעת אם המשתמש צריך להביע הסכמה אם הוא עדיין לא עשה זאת, או אם פג התוקף של ההסכמה שלו.
הנה דוגמה לבדיקת הסטטוס של UIViewController
בשיטה viewDidLoad()
.
Swift
override func viewDidLoad() {
super.viewDidLoad()
// Create a UMPRequestParameters object.
let parameters = UMPRequestParameters()
// Set tag for under age of consent. false means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = false
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
[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];
// Create a UMPRequestParameters object.
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
// Set tag for under age of consent. NO means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = NO;
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
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()
// Create a UMPRequestParameters object.
let parameters = UMPRequestParameters()
// Set tag for under age of consent. false means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = false
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
[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];
// Create a UMPRequestParameters object.
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
// Set tag for under age of consent. NO means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = NO;
__weak __typeof__(self) weakSelf = self;
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
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()
// Create a UMPRequestParameters object.
let parameters = UMPRequestParameters()
// Set tag for under age of consent. false means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = false
// Request an update for the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
[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];
// Create a UMPRequestParameters object.
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
// Set tag for under age of consent. NO means users are not under age
// of consent.
parameters.tagForUnderAgeOfConsent = NO;
__weak __typeof__(self) weakSelf = self;
// Request an update for the consent information.
[UMPConsentInformation.sharedInstance
requestConsentInfoUpdateWithParameters:parameters
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 startGoogleMobileAdsSDKOnce];
}
}];
}];
// 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 startGoogleMobileAdsSDKOnce];
}
}
- (void)startGoogleMobileAdsSDKOnce {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
// Initialize the Google Mobile Ads SDK.
[GADMobileAds.sharedInstance startWithCompletionHandler:nil];
// TODO: Request an ad.
// [GADInterstitialAd loadWithAdUnitID...];
});
}
בדיקה
אם אתם רוצים לבדוק את השילוב באפליקציה בזמן הפיתוח, פעלו לפי השלבים הבאים כדי לרשום את מכשיר הבדיקה באופן פרוגרמטי.
- התקשרות אל
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];