تحت خطمشی رضایت کاربر اتحادیه اروپا Google، شما باید اطلاعات مشخصی را برای کاربران خود در منطقه اقتصادی اروپا (EEA) همراه با بریتانیا انجام دهید و رضایت آنها را برای استفاده از کوکیها یا سایر فضای ذخیرهسازی محلی، در صورت نیاز قانونی، و استفاده از دادههای شخصی کسب کنید ( مانند AdID) برای ارائه تبلیغات. این سیاست منعکس کننده الزامات دستورالعمل حریم خصوصی الکترونیک اتحادیه اروپا و مقررات عمومی حفاظت از داده ها (GDPR) است.
برای حمایت از ناشران در انجام وظایف خود تحت این خطمشی، Google پلتفرم پیامرسانی کاربر (UMP) SDK را ارائه میدهد. UMP SDK برای پشتیبانی از آخرین استانداردهای IAB به روز شده است. همه این پیکربندیها اکنون میتوانند به راحتی در حریم خصوصی و پیامرسانی AdMob مدیریت شوند.
پیش نیازها
- راهنمای شروع را کامل کنید
- اگر روی الزامات مربوط به GDPR کار می کنید،چگونه الزامات IAB بر پیام های رضایت اتحادیه اروپا تأثیر می گذاردالزامات IAB بر پیام های رضایت اتحادیه اروپا تأثیر می گذارد
یک نوع پیام ایجاد کنید
پیامهای کاربری را با یکی از انواع پیام کاربرموجوددر برگه حریم خصوصی و پیامرسانیAdMobManager106 خود ایجاد کنید. UMP SDK سعی می کند یک پیام کاربری ایجاد شده از شناسه برنامه AdMob در پروژه شما نمایش دهد. اگر هیچ پیامی برای برنامه شما پیکربندی نشده باشد، SDK یک خطا برمیگرداند.
برای جزئیات بیشتر،درباره حریم خصوصی و پیامرسانی را ببینید.
SDK را وارد کنید
CocoaPods (ترجیحا)
ساده ترین راه برای وارد کردن SDK به پروژه iOS استفاده از CocoaPods است. Podfile پروژه خود را باز کنید و این خط را به هدف برنامه خود اضافه کنید:
pod 'GoogleUserMessagingPlatform'
سپس دستور زیر را اجرا کنید:
pod install --repo-update
اگر با CocoaPods تازه کار هستید، برای جزئیات بیشتر در مورد نحوه ایجاد و استفاده از Podfiles به استفاده از CocoaPods مراجعه کنید.
مدیر بسته سوئیفت
UMP SDK همچنین از مدیریت بسته Swift پشتیبانی می کند. برای وارد کردن بسته سوئیفت این مراحل را دنبال کنید.
در Xcode، بسته UMP SDK Swift را با رفتن به File > Add Packages... نصب کنید.
در اعلان ظاهر شده، مخزن UMP SDK Swift Package GitHub را جستجو کنید:
https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
نسخه UMP SDK Swift Package را که می خواهید استفاده کنید انتخاب کنید. برای پروژههای جدید، توصیه میکنیم از نسخه اصلی تا بعدی استفاده کنید.
سپس Xcode وابستگی های بسته شما را برطرف می کند و آنها را در پس زمینه دانلود می کند. برای جزئیات بیشتر در مورد نحوه افزودن وابستگی های بسته، به مقاله اپل مراجعه کنید.
دانلود دستی
راه دیگر وارد کردن SDK این است که آن را به صورت دستی انجام دهید.
سپس، چارچوب را به پروژه Xcode خود بکشید و مطمئن شوید که در صورت نیاز موارد کپی را انتخاب کنید.
سپس می توانید چارچوب را در هر فایلی که نیاز دارید با استفاده از:
سریع
import UserMessagingPlatform
هدف-C
#include <UserMessagingPlatform/UserMessagingPlatform.h>
درخواست اطلاعات رضایت
باید در هر راهاندازی برنامه، با استفاده از requestConsentInfoUpdateWithParameters:completionHandler:
درخواست بهروزرسانی اطلاعات رضایت کاربر را بدهید. این تعیین می کند که آیا کاربر شما باید رضایت خود را ارائه دهد، اگر قبلاً این کار را نکرده است یا اینکه رضایت او منقضی شده است.
در اینجا مثالی از نحوه بررسی وضعیت از طریق UIViewController
در متد viewDidLoad()
آورده شده است.
سریع
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.
}
}
هدف-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.
}];
}
در صورت نیاز فرم رضایت نامه را بارگیری و ارائه دهید
مهم: API های زیر با UMP SDK نسخه 2.1.0 یا بالاتر سازگار هستند. پس از دریافت به روزترین وضعیت رضایت، باloadAndPresentIfRequiredFromViewController:completionHandler:
در کلاسUMPConsentForm
تماس بگیرید تا فرم رضایت بارگیری شود. اگر وضعیت رضایت مورد نیاز باشد، SDK فرمی را بارگیری میکند و بلافاصله آن را از view controllerارائه شده ارائه میکند. completion handlerپس از رد شدن فرم نامیده می شود. اگر رضایت لازم نباشد، completion handlerبلافاصله نامیده می شود.
سریع
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.
}
}
}
هدف-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 از وضعیت رضایت جلسه قبل استفاده می کند.
سریع
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(...)
}
}
}
هدف-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
را بررسی کنید تا مشخص شود که آیا عنصر UI که می تواند فرم گزینه های حریم خصوصی را ارائه دهد، نمایش داده شود. - هنگامی که کاربر با عنصر UI شما تعامل می کند، با
presentPrivacyOptionsFormFromViewController:completionHandler:
تماس بگیرید تا فرم را نشان دهد تا کاربر بتواند گزینه های حریم خصوصی خود را در هر زمانی به روز کند.
مثال زیر نحوه ارائه فرم گزینه های حریم خصوصی را از یک UIBarButtonItem
نشان می دهد.
سریع
@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.
}
}
هدف-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
تماس بگیرید و لیستی از شناسه های دستگاه آزمایشی خود را در ارسال کنید.سریع
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 ... })
هدف-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
قرار دارد. توجه داشته باشید که تنظیمات اشکال زدایی فقط در دستگاه های آزمایشی کار می کند.
سریع
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
...
})
هدف-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
برای انجام این کار ارائه می دهد.
سریع
UMPConsentInformation.sharedInstance.reset()
هدف-C
[UMPConsentInformation.sharedInstance reset];
نمونه هایی در GitHub
نمونه های ادغامUMP SDK: Swift | نمونه های ادغام Objective-C