google admob GDPR

最近接到需求,接入google admob 的 (GDPR) 要求。

一、GDPR 是什么?                                                                                                                         

                   《一般数据保护条例》(GDPR) 是 2018 年 5 月生效的一部新的欧洲数据保护法,虽然 GDPR 是一部欧洲法规,但很多使用在线广告服务的非欧洲实体也会受到影响。根据 Google《欧盟地区用户意见征求政策》,必须向位于欧洲经济区 (EEA) 和英国的用户披露某些信息,在法律有相应要求的情况下,并获得用户同意,才能使用个人数据(如 AdID)来投放广告。此政策反映了欧盟《电子隐私指令》和《一般数据保护条例》(GDPR) 的要求。为了商履行此政策规定,提供了 User Messaging Platform (UMP) SDK 支持 IAB 标准。Interactive Advertising Bureau,缩写为IAB。 

二、使用步骤

 1.在 app 下 build.gradle 引入库​​​​​​​​​​​​​​

dependencies {
  implementation 'com.google.android.ump:user-messaging-platform:2.1.0'
  implementation 'com.google.android.gms:play-services-ads:22.2.0'
}

2.工程 root 目录下的 build.gradle 配置

buildscript {
    repositories {
        google()
        mavenCentral()
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

3.添加admob app ID 到工程 AndroidManifest.xml 文件 id 在 google 控制台获取应用自己的 id

<manifest>
    <application>
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    </application>
</manifest>

4. 如果您的应用使用 Google 移动广告 SDK 20.4.0或更高版本,则您可以跳过此步骤,因为 SDK 会自动声明权限 com.google.android.gms.permission.AD_ID,并且能够在广告 ID 可用时访问该权限。

对于使用 Google 移动广告 SDK 版本 20.3.0 或更低版本且面向 Android 13 的应用,您必须 com.google.android.gms.permission.AD_ID 在 AndroidManifest.xml文件中添加 Google 移动广告 SDK 访问广告 ID 的权限

        <uses-permission android:name="com.google.android.gms.permission.AD_ID"/>

5.代码请求获取最新的用户意见征求信息,检查表单是否可用,如果有,则加载表单

    // UMP 接入 实例化 ConsentForm 和 ConsentInformation
    private static ConsentForm mConsentForm;
    private static ConsentInformation mConsentInformation;

 ConsentRequestParameters params = new ConsentRequestParameters
        .Builder()
        .setTagForUnderAgeOfConsent(false)
        .build();
 mConsentInformation = UserMessagingPlatform.getConsentInformation(mContext);
        //requestConsentInfoUpdate 请求最新的同意信息
        mConsentInformation.requestConsentInfoUpdate((Activity) mContext, params, new ConsentInformation.OnConsentInfoUpdateSuccessListener() {
            @Override
            public void onConsentInfoUpdateSuccess() {
                // 同意信息更新成功,isConsentFormAvailable 检测表单是否可用
                if(mConsentInformation.isConsentFormAvailable()){
                    LogD(" ~ 表单可用加载并展示 ~ ");
                    //loadAndShowConsentFormIfRequired 加载用户意见征求表单并展示
                    UserMessagingPlatform.loadAndShowConsentFormIfRequired((Activity) mContext, new ConsentForm.OnConsentFormDismissedListener() {
                        @Override
                        public void onConsentFormDismissed(@Nullable FormError formError) {
                            if (null != formError) {
                                // 表单加载失败或者无法显示
                                Log.w(LOG_TAG, "loadAndShowError" + String.format("%s: %s",
                                        formError.getErrorCode(),
                                        formError.getMessage()));
                            }
                            // canRequestAds 检查是否已征得用户同意
                            Log.e(LOG_TAG, "征得同意" + mConsentInformation.canRequestAds());
                        }
                    });
                }
            }
        }, new ConsentInformation.OnConsentInfoUpdateFailureListener() {
            @Override
            public void onConsentInfoUpdateFailure(@NonNull FormError formError) {
                // 当同意信息更新失败时调用。
                if(null != formError){
                    Log.w(LOG_TAG, "presentForm requestConsentInfoUpdate--->"+String.format("%s: %s",
                            formError.getErrorCode(),
                            formError.getMessage()));
                }
            }
        });

6. 为应用创建 GDPR 消息(admob 后台创建,我们这边发行负责创建)

7. 用户撤销意见,是“隐私权和消息”用户意见征求计划的一项要求。所以必须在应用的菜单中提供一个按钮,然后重新向他们显示用户意见征求消息。

  UserMessagingPlatform.loadConsentForm((Activity) mContext, new UserMessagingPlatform.OnConsentFormLoadSuccessListener() {
            @Override
            public void onConsentFormLoadSuccess(@NonNull ConsentForm consentForm) {
                Log.d(LOG_TAG, "onConsentFormLoadSuccess: " + mConsentInformation.getConsentStatus());
                mConsentForm = consentForm;
                mConsentForm.show((Activity) mContext, new ConsentForm.OnConsentFormDismissedListener() {
                    @Override
                    public void onConsentFormDismissed(@Nullable FormError formError) {
                        if (null != formError) {
                            Log.d(LOG_TAG, "onConsentFormDismissed: " + formError.getErrorCode() + "--->" + formError.getMessage());
                        }
                    }
                });
            }
        }, new UserMessagingPlatform.OnConsentFormLoadFailureListener() {
            @Override
            public void onConsentFormLoadFailure(@NonNull FormError formError) {
                // Handle the error.
                if (null != formError) {
                    Log.w(LOG_TAG, "loadForm onConsentFormLoadFailure--->" + String.format("%s: %s",
                            formError.getErrorCode(),
                            formError.getMessage()));
                }
            }
        });

总结

     

  •  ① 每次用户启动应用时加载表单,以便在用户想要更改同意设置时可以显示表单。
  • ② 在用户从应用菜单中选择相应链接时,显示表单。

  • 注:因为我们接入的是三方聚合平台广告 applovin,所以没有在应用的初始化ads

  经测试:

             如果属于欧盟地区,首次安装包会展示表单,然后点击按钮,每次都展示表单;

             如果不属于欧盟地区,首次安装包不会展示表单,表单按钮也不需要展示了,按钮根据ConsentStatus.NOT_REQUIRED 判断是否展示;

  if (null == mConsentInformation) {
            mConsentInformation = UserMessagingPlatform.getConsentInformation(mContext);
        }
        Log.d(LOG_TAG, " isSupportGDPR ConsentStatus: " + mConsentInformation.getConsentStatus());
        /**
         * 表单四种状态:
         * ①ConsentStatus.UNKNOWN 未知的同意状态
         * ②ConsentStatus.REQUIRED 需要但尚未获得用户同意
         * ③ConsentStatus.NOT_REQUIRED:不需要用户同意。例如,用户不在欧洲经济区或英国
         * ④ConsentStatus.OBTAINED:已获得用户同意。个性化未定义。
         */
        if (mConsentInformation.getConsentStatus() == ConsentInformation.ConsentStatus.NOT_REQUIRED) {
          //不展示按钮
        } else {
          //展示按钮
        }


猜你喜欢

转载自blog.csdn.net/u010207898/article/details/132181803