根据 Google 欧盟地区用户意见征求政策,您必须向位于欧洲经济区 (EEA) 以及英国境内的用户披露相关信息,在法律要求的情况下,必须征得他们的同意才能使用 Cookie 或其他本地存储方式;此外,您必须同意他们使用个人数据(例如 AdID)来投放广告。此政策反映了欧盟《电子隐私指令》和《一般数据保护条例》(GDPR) 的要求。
为了帮助发布商履行此政策规定的职责,Google 提供了 User Messaging Platform (UMP) SDK。UMP SDK 现已更新,支持最新的 IAB 标准。所有这些配置现在都可以在“隐私权和消息”中轻松处理。 AdMob
前提条件
- 完成入门指南
- 如果您正在处理与 GDPR 相关的要求,请参阅 IAB 要求对欧盟地区用户意见征求消息的影响
创建消息类型
在您的AdMob 帐号的隐私权和消息标签页下,使用 可用的用户消息类型 来创建用户消息。UMP SDK 会尝试显示通过 AdMob 项目中设置的应用 ID 创建的用户消息。如果没有为应用配置消息,SDK 会返回错误。
如需了解详情,请参阅 隐私权和消息简介。
意见征求信息请求
每次启动应用时,您都应使用 Update()
请求更新用户的意见征求信息。这决定了您的用户是需要提供用户意见征求结果(如果尚未提供),或者用户意见征求结果已过期。
在应用启动时检查状态的示例如下:
void Start()
{
// Set tag for under age of consent.
// Here false means users are not under age of consent.
ConsentRequestParameters request = new ConsentRequestParameters
{
TagForUnderAgeOfConsent = false,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogError(consentError);
return;
}
// If the error is null, the consent information state was updated.
// You are now ready to check if a form is available.
}
根据需要加载并显示用户意见征求表单
收到最新的用户意见征求状态后,请对ConsentForm
类调用LoadAndShowConsentFormIfRequired()
以加载用户意见征求表单。如果需要提供用户意见征求状态,SDK 会加载表单,并立即显示表单。在用户关闭表单后,系统会调用 Action<FormError>
callback。如果不需要征得用户同意,系统会立即调用 Action<FormError>
callback。
void Start()
{
// Set tag for under age of consent.
// Here false means users are not under age of consent.
ConsentRequestParameters request = new ConsentRequestParameters
{
TagForUnderAgeOfConsent = false,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogError(consentError);
return;
}
// If the error is null, the consent information state was updated.
// You are now ready to check if a form is available.
ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
{
if (formError != null)
{
// Consent gathering failed.
UnityEngine.Debug.LogError(consentError);
return;
}
// Consent has been gathered.
});
}
如果您需要在用户做出选择或关闭表单后执行操作,请将相应逻辑放入表单的 Action<FormError>
callback中。
提出广告请求
在您的应用中请求广告之前,请使用 检查您是否已征得用户的同意。征求用户意见时,有两个位置需要检查:
- 在当前会话中征得用户同意后。
- 调用
Update()
后立即执行上述操作。 可能是在上一次会话中已征得用户同意。根据延迟最佳实践,我们建议您不要等待回调完成,这样您就可以在应用启动后尽快开始加载广告。
false
如果在征求用户意见的过程中发生错误,您仍应尝试请求广告。UMP SDK 会使用上一个会话的同意情况。
void Start()
{
// Set tag for under age of consent.
// Here false means users are not under age of consent.
ConsentRequestParameters request = new ConsentRequestParameters
{
TagForUnderAgeOfConsent = false,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
void OnConsentInfoUpdated(FormError consentError)
{
if (consentError != null)
{
// Handle the error.
UnityEngine.Debug.LogError(consentError);
return;
}
// If the error is null, the consent information state was updated.
// You are now ready to check if a form is available.
ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) =>
{
if (formError != null)
{
// Consent gathering failed.
UnityEngine.Debug.LogError(consentError);
return;
}
// Consent has been gathered.
if (ConsentInformation.CanRequestAds())
{
MobileAds.Initialize((InitializationStatus initstatus) =>
{
// TODO: Request an ad.
});
}
});
}
测试
如果您希望在开发过程中测试应用中的集成,请按照以下步骤以编程方式注册测试设备。
- 调用
Update()
。 检查日志输出是否存在类似于以下内容的消息,该消息会显示您的设备 ID 以及如何将其添加为测试设备:
Android
Use new ConsentDebugSettings.Builder().addTestDeviceHashedId("33BE2250B43518CCDA7DE426D04EE231") to set this as a debug device.
iOS
<UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
将测试设备 ID 复制到剪贴板。
修改代码,以调用
DebugGeography.TestDeviceHashedIds
并传入测试设备 ID 列表。
void Start()
{
var debugSettings = new ConsentDebugSettings
{
DebugGeography = DebugGeography.TestDeviceHashedIds =
new List<string>
{
"TEST-DEVICE-HASHED-ID"
}
};
// Set tag for under age of consent.
// Here false means users are not under age of consent.
ConsentRequestParameters request = new ConsentRequestParameters
{
TagForUnderAgeOfConsent = false,
ConsentDebugSettings = debugSettings,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
强制调试地理位置
UMP SDK 提供了一种方法,让您能够使用 the DebugGeography
field on ConsentDebugSettings
测试应用行为,就像设备位于欧洲经济区 (EEA) 或英国一样。请注意,调试设置仅适用于测试设备。
void Start()
{
var debugSettings = new ConsentDebugSettings
{
// Geography appears as in EEA for debug devices.
DebugGeography = DebugGeography.EEA,
TestDeviceHashedIds = new List<string>
{
"TEST-DEVICE-HASHED-ID"
}
};
// Set tag for under age of consent.
// Here false means users are not under age of consent.
ConsentRequestParameters request = new ConsentRequestParameters
{
TagForUnderAgeOfConsent = false,
ConsentDebugSettings = debugSettings,
};
// Check the current consent information status.
ConsentInformation.Update(request, OnConsentInfoUpdated);
}
重置用户同意情况
通过 UMP SDK 测试应用时,您可能会发现重置 SDK 的状态很有帮助,以便模拟用户的首次安装体验。该 SDK 提供的 Reset()
方法可实现此目的。
ConsentInformation.Reset();