始める

Google User Messaging Platform(UMP)SDK は、プライバシーとメッセージを保護するためのツールで、 プライバシーに関する選択を管理できます詳細については、次をご覧ください: プライバシーと説明します。

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

ユーザー メッセージは、いずれかの 利用可能なユーザー メッセージの種類 [プライバシーと[メッセージ] タブを AdMob あります。UMP SDK は、 アプリケーション ID から AdMob 作成されたプライバシー メッセージ 必要があります。

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

アプリケーション ID を追加する

アプリケーション ID は、 AdMob 管理画面: ID を これを次のコード スニペットに置き換えます。

アプリごとにユーザーの同意情報の更新をリクエストする必要があります 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 privacy message form.
    },
    (FormError error) {
      // Handle the error.
    },
  );
}

必要に応じてプライバシー メッセージ フォームを読み込んで表示する

最新の同意ステータスを受け取ったら、 loadAndShowConsentFormIfRequired() して、タスクに必要なフォームを読み込みます。 ユーザーの同意を取得します。読み込み後、フォームがすぐに表示されます。

@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に配置します。 選択します。

プライバシー設定

一部のプライバシー メッセージのフォームは、パブリッシャーがレンダリングするプライバシーから表示されます オプションのエントリ ポイントを用意し、ユーザーがいつでもプライバシー オプションを管理できるようにしました。 ユーザーに表示されるメッセージについて詳しくは、プライバシー オプションをご覧ください 参照できます。詳しくは、 利用可能なユーザー メッセージの種類

プライバシー オプションのエントリ ポイントを実装する手順は次のとおりです。

  1. getPrivacyOptionsRequirementStatus()をご確認ください。
  2. プライバシー オプションのエントリ ポイントが 表示可能で操作可能な UI 要素をアプリに追加します。
  3. 以下を使用してプライバシー オプション フォームをトリガーします。 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))
                  ],
                ));
          })
    ];
  }
}

広告をリクエスト

アプリで広告をリクエストする前に、同意を得ているかどうかを確認してください canRequestAds()を使用してユーザーから取得できます。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.
    }
  }
}

テスト

開発中にアプリで統合をテストする場合は、 テストデバイスをプログラムで登録します。必ず テストデバイス 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 を使用すると、デバイスが別のデバイスで動作しているかのようにアプリの動作をテストできます。 EEA または英国に居住している( the DebugGeography field on ConsentDebugSettingsを使用)注: デバッグ設定はテストデバイスでのみ機能します。

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();

GitHub の例