You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

谷歌CMP合规要求下,如何在Ionic中集成UMP SDK?

在Ionic中集成谷歌UMP SDK的步骤

自2024年1月16日起,谷歌将要求所有向欧洲经济区(EEA)和英国(UK)用户投放广告的发布商使用谷歌认证的同意管理平台(CMP)。您可使用任意谷歌认证的CMP,包括谷歌自身的同意管理解决方案。若您有意使用谷歌的同意管理解决方案,请先设置GDPR提示信息并集成UMP SDK。

针对基于Ionic框架的应用,以下是集成UMP SDK的具体步骤:

1. 安装适配的Capacitor插件

使用社区维护的支持UMP的AdMob插件,执行以下命令安装:

npm install @capacitor-community/admob
npx cap sync

2. 配置平台权限

  • iOS:打开ios/App/App/Info.plist,添加用户追踪权限描述:
    <key>NSUserTrackingUsageDescription</key>
    <string>我们需要获取广告标识符以提供个性化广告服务</string>
    
  • Android:在android/app/src/main/AndroidManifest.xml中确认网络权限已添加:
    <uses-permission android:name="android.permission.INTERNET" />
    

3. 初始化SDK并请求用户同意

在应用初始化逻辑中(如app.component.ts)添加以下代码:

import { AdMob } from '@capacitor-community/admob';

async initializeApp() {
  // 初始化AdMob及UMP SDK
  await AdMob.initialize({
    requestTrackingAuthorization: true,
    initializeForTesting: false, // 测试环境可设为true强制触发提示
  });

  // 检查并请求App Tracking Transparency授权(iOS)
  const trackingStatus = await AdMob.trackingAuthorizationStatus();
  if (trackingStatus === 'notDetermined') {
    await AdMob.requestTrackingAuthorization();
  }

  // 加载并展示GDPR同意表单(针对EEA/UK用户)
  const consentInfo = await AdMob.getConsentInfo();
  if (consentInfo.isConsentFormAvailable) {
    await AdMob.showConsentForm();
  }
}

4. 验证集成效果

  • 测试时可开启initializeForTesting: true,强制展示同意弹窗。
  • 使用谷歌提供的测试设备ID,模拟不同地区用户的场景,确认同意流程正常触发。

5. 广告展示前检查同意状态

在展示AdMob广告前,确保已获取用户同意:

async showInterstitialAd() {
  const consentStatus = await AdMob.getConsentStatus();
  if (consentStatus === 'granted') {
    await AdMob.showInterstitial({
      adId: 'ca-app-pub-你的广告ID/广告单元ID',
    });
  }
}

内容的提问来源于stack exchange,提问作者good_evening

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 12:52:21