Unity中如何将Google AdMob UMP的Consent结果同步至其他广告平台?
问题描述
我按照Unity Messaging Platform(UMP)文档实现了用户授权弹窗,代码如下:
void Start() { ConsentRequestParameters request = new ConsentRequestParameters { TagForUnderAgeOfConsent = false, }; ConsentInformation.Update(request, OnConsentInfoUpdated); } void OnConsentInfoUpdated(FormError consentError) { ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) => { if (ConsentInformation.CanRequestAds()) { MobileAds.Initialize((InitializationStatus initstatus) => { // TODO: Request an ad. }); } }); }
发现即使用户选择“全部拒绝”,ConsentInformation.CanRequestAds()仍返回true。根据Google AdMob工作人员的说明,UMP会生成一份“TC String”,Google AdMob会自动遵循该字符串,无需额外操作。但如果同时使用IronSource或AppLovin等其他广告平台,该如何将此Consent结果同步给这些平台?
解决方案
1. 先提取UMP的核心授权信息
不要仅依赖ConsentInformation.CanRequestAds()(该方法逻辑偏向AdMob自身),需要获取更精准的授权状态:
- 通过
ConsentInformation.ConsentStatus获取用户的整体授权状态(如Obtained表示已授权,Required表示未完成授权,NotRequired表示无需授权) - 通过
ConsentInformation.TcString获取GDPR合规的TC字符串,用于同步给第三方平台
2. 同步到IronSource
在用户完成UMP授权流程后,初始化IronSource之前执行以下操作:
// 根据UMP的授权状态设置IronSource的同意状态 if (ConsentInformation.ConsentStatus == ConsentStatus.Obtained) { IronSource.Agent.setConsent(true); } else { IronSource.Agent.setConsent(false); } // 同步TC String if (!string.IsNullOrEmpty(ConsentInformation.TcString)) { IronSource.Agent.setTCData(ConsentInformation.TcString); } // 之后再初始化IronSource // IronSource.Agent.initIronSource(...);
3. 同步到AppLovin Max
同样在初始化AppLovin Max之前完成授权同步:
// 设置用户同意状态 MaxSdk.SetHasUserConsent(ConsentInformation.ConsentStatus == ConsentStatus.Obtained); // 同步TC String if (!string.IsNullOrEmpty(ConsentInformation.TcString)) { MaxSdk.SetConsentString(ConsentInformation.TcString); } // 之后再初始化AppLovin Max // MaxSdk.Initialize(...);
4. 关键注意事项
- 所有第三方广告平台的授权配置必须在SDK初始化前完成,确保启动时就遵循用户选择
- 若用户后续通过隐私设置修改授权状态,需重新拉取UMP的最新状态并同步给所有平台
- 不同平台的API可能随版本更新调整,需留意各自官方文档的最新规范
内容的提问来源于stack exchange,提问作者Dr-Bracket
相关产品推荐
相关产品推荐

