使ってみる

Google の EU ユーザーの同意ポリシーに基づき、広告主様は、欧州経済領域(EEA)および英国のユーザーに対して特定の開示を行い、法律で義務付けられている場合に Cookie またはその他のローカル ストレージを使用すること、および広告配信に個人データ(AdID など)を使用することについてユーザーの同意を得る必要があります。このポリシーには、EU の e プライバシー指令と一般データ保護規則(GDPR)の要件が反映されています。

パブリッシャー様がこのポリシーで定められた義務を遂行できるよう、Google は User Messaging Platform(UMP)SDK を提供しています。最新の IAB 標準に対応するように UMP SDK が更新されました。これらの設定はすべて、[プライバシーとメッセージ] で Ad Manager 簡単に処理できるようになりました。

前提条件

メッセージ タイプを作成する

アド マネージャー アカウントの [プライバシーとメッセージ] タブで、 使用可能なユーザー メッセージ タイプ のいずれかを使用してユーザー メッセージを作成します。UMP SDK は、プロジェクトに設定されたアプリケーション ID から作成されたユーザー メッセージを表示しようとします。 Ad Manager アプリケーションにメッセージが構成されていない場合、SDK はエラーを返します。

詳しくは、 プライバシーとメッセージについて

アプリが起動されるたびに、 requestConsentInfoUpdate()を使用してユーザーの同意情報の更新をリクエストする必要があります。これにより、ユーザーがまだ同意していない場合に、または同意の有効期限が切れている場合に、同意を提示する必要があるかどうかを判断します。

アプリ起動時のステータスの確認方法の例を次に示します。

@override
void initState() {
  super.initState();

  // Create a ConsentRequestParameters object.
  final params = ConsentRequestParameters();

  // Request an update for the consent information.
  ConsentInformation.instance.requestConsentInfoUpdate(
    params,
    () async {
      // TODO: Load and present the consent form.
    },
    (FormError error) {
      // Handle the error.
    },
  );
}

必要に応じて同意フォームを読み込んで表示する

最新の同意ステータスを取得したら、ConsentForm クラスでloadAndShowConsentFormIfRequired() を呼び出して同意フォームを読み込みます。同意ステータスが必須の場合、SDK はフォームを読み込み、 指定された からすぐに表示します。 callback は、フォームが閉じられた後に 呼び出されます。同意が不要な場合は、すぐに callback が 呼び出されます。

@override
void initState() {
  super.initState();

  // Create a ConsentRequestParameters object.
  final params = ConsentRequestParameters();

  // Request an update for the consent information.
  ConsentInformation.instance.requestConsentInfoUpdate(
    params,
    () async {
      ConsentForm.loadAndShowConsentFormIfRequired((loadAndShowError) {
        if (loadAndShowError != null) {
          // Consent gathering failed.
        }

        // Consent has been gathered.
      });
    },
    (FormError error) {
      // Handle the error.
    },
  );
}

ユーザーが選択を行ったりフォームを閉じたりした後になんらかのアクションを行う必要がある場合は、そのロジックをフォームの callbackに配置します。

広告をリクエスト

アプリで広告をリクエストする前に、 canRequestAds()を使用してユーザーから同意を得ているかどうかを確認してください。同意を取得する際には、次の 2 つの場所を確認します。

  1. 現在のセッションで同意が取得された後。
  2. requestConsentInfoUpdate()を呼び出した直後。前回のセッションで同意が得られた可能性があります。遅延を考慮すると、コールバックの完了を待たずに、アプリの起動後すぐに広告の読み込みを開始できるようにすることをおすすめします。

同意取得プロセスでエラーが発生した場合でも、広告のリクエストをお試しください。UMP SDK は前のセッションの同意ステータスを使用します。

class AppExampleState extends State<AppExample> {

  // Use a bool to initialize the Mobile Ads SDK and load ads once.
  var _isMobileAdsInitializeCalled = false;

  @override
  void initState() {
    super.initState();

    // Create a ConsentRequestParameters object.
    final params = ConsentRequestParameters();

    // Request an update for the consent information.
    ConsentInformation.instance.requestConsentInfoUpdate(
      params,
      () async {
        ConsentForm.loadAndShowConsentFormIfRequired((loadAndShowError) {
          if (loadAndShowError != null) {
            // Consent gathering failed.
          }

          // Consent has been gathered.
          _initializeMobileAdsSDK();
        });
      },
      (FormError error) {
        // Handle the error.
      },
    );

    // Check if you can initialize the Mobile Ads SDK in parallel while
    // checking for new consent information. Consent obtained in the
    // previous session can be used to request ads.
    _initializeMobileAdsSDK();
  }

  void _initializeMobileAdsSDK() async {
    if (_isMobileAdsInitializeCalled) {
      return;
    }

    // Initialize the Mobile Ads SDK if the SDK has gathered consent aligned with
    // the app's configured messages.
    var canRequestAds = await ConsentInformation.instance.canRequestAds();
    if (canRequestAds) {
      setState(() {
        _isMobileAdsInitializeCalled = true;
      });

      // Initialize the Mobile Ads SDK.
      MobileAds.instance.initialize();

      // TODO: Request an ad.
    }
  }
}

プライバシー設定

一部の同意フォームでは、ユーザーがいつでも同意内容を変更する必要があります。必要に応じて、次の手順に沿ってプライバシー オプション ボタンを実装します。

手順は次のとおりです。

  1. プライバシー設定ページのボタンなど、プライバシー オプション フォームをトリガーできる UI 要素を実装します。
  2. loadAndShowConsentFormIfRequired() が完了したら、getPrivacyOptionsRequirementStatus() をチェックして、プライバシー オプション フォームを表示できる UI 要素を表示するかどうかを決定します。
  3. ユーザーが UI 要素を操作したら、showPrivacyOptionsForm() を呼び出してフォームを表示して、ユーザーがいつでもプライバシー オプションを更新できるようにします。
class AppExampleState extends State<AppExample> {
  static const _privacySettingsText = 'Privacy Settings';

  // Use a bool to initialize the Mobile Ads SDK and load ads once.
  var _isMobileAdsInitializeCalled = false;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'App Example',
      home: Scaffold(
          appBar: AppBar(
            title: const Text('App Example'),
            actions: _isMobileAdsSDKInitialized
                // Regenerate the options menu to include a privacy setting.
                ? _privacySettingsAppBarAction()
                : null
          ),
          body: // ...
      ),
    );
  }

  List<Widget> _privacySettingsAppBarAction() {
    return <Widget>[
      FutureBuilder(
          future: ConsentInformation.instance.isPrivacyOptionsRequired(),
          builder: (context, snapshot) {
            final bool visibility = snapshot.data ?? false;
            return Visibility(
                visible: visibility,
                child: PopupMenuButton<String>(
                  onSelected: (String result) {
                    if (result == _privacySettingsText) {
                      ConsentForm.showPrivacyOptionsForm((formError) {
                        if (formError != null) {
                          debugPrint(
                              "${formError.errorCode}: ${formError.message}");
                        }
                      });
                    }
                  },
                  itemBuilder: (BuildContext context) =>
                      <PopupMenuEntry<String>>[
                    const PopupMenuItem<String>(
                        value: _privacySettingsText,
                        child: Text(_privacySettingsText))
                  ],
                ));
          })
    ];
  }
}

テスト

開発中にアプリとの統合をテストする場合は、次の手順に沿ってプログラムでテストデバイスを登録します。アプリをリリースする前に、これらのテストデバイス ID を設定するコードを必ず削除してください。

  1. requestConsentInfoUpdate()を呼び出します。
  2. ログ出力で、デバイス 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]
    
  3. テストデバイス ID をクリップボードにコピーします。

  4. コードを変更して、 呼び出し ConsentDebugSettings.testIdentifiers 、 テストデバイス ID のリストを渡します。

    ConsentDebugSettings debugSettings = ConsentDebugSettings(
      testIdentifiers: ["TEST-DEVICE-HASHED-ID"],
    );
    
    ConsentRequestParameters params =
        ConsentRequestParameters(consentDebugSettings: debugSettings);
    
    ConsentInformation.instance.requestConsentInfoUpdate(params, () async {
      // ...
    };
    

地域を強制的に適用する

UMP SDK では、 the DebugGeography field on ConsentDebugSettingsを使用して、デバイスが EEA または英国にあるかのようにアプリの動作をテストできます。デバッグ設定はテストデバイスでのみ機能します。

ConsentDebugSettings debugSettings = ConsentDebugSettings(
  debugGeography: DebugGeography.debugGeographyEea,
  testIdentifiers: ["TEST-DEVICE-HASHED-ID"],
);

ConsentRequestParameters params =
    ConsentRequestParameters(consentDebugSettings: debugSettings);

ConsentInformation.instance.requestConsentInfoUpdate(params, () async {
  // ...
};

UMP SDK を使用してアプリをテストする場合、SDK の状態をリセットすると、ユーザーの最初のインストール操作をシミュレートできます。SDK には、これを行うための reset() メソッドが用意されています。

ConsentInformation.instance.reset();