使ってみる

Google User Messaging Platform(UMP)SDK は、プライバシーに関するユーザー設定の管理に役立つプライバシーとメッセージに関するツールです。詳しくは、プライバシーとメッセージについてをご覧ください。UMP SDK を使用した IMA の実装例については、Objective-C または Swift の UMP サンプルアプリをご覧ください。

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

Ad Manager アカウントの [プライバシーとメッセージ] タブで、利用可能なユーザー向けメッセージの種類のいずれかを使用してユーザー向けメッセージを作成していること。UMP SDK は、プロジェクトで設定されたインタラクティブ メディア広告アプリケーション ID から作成されたプライバシー メッセージを表示しようとします。

詳しくは、プライバシーとメッセージについてをご覧ください。

SDK をインポートする

UMP SDK は IMA SDK の依存関係として含まれていないため、明示的に追加する必要があります。

CocoaPods(推奨)

iOS プロジェクトに SDK を簡単にインポートするには、CocoaPods を使う方法がおすすめです。プロジェクトの Podfile を開き、アプリのターゲットに次の行を追加します。

pod 'GoogleUserMessagingPlatform'

次のコマンドを実行します。

pod install --repo-update

CocoaPods を初めてご利用の場合は、CocoaPods の使用についての記事で Podfile の作成方法と使用方法をご確認ください。

Swift Package Manager

UMP SDK は Swift Package Manager にも対応しています。Swift パッケージをインポートする手順は次のとおりです。

  1. Xcode で File > Add Packages... を開き、UMP SDK の Swift パッケージをインストールします。

  2. 表示されたプロンプトで、UMP SDK の Swift パッケージの GitHub リポジトリ(下記)を検索します。

    https://github.com/googleads/swift-package-manager-google-user-messaging-platform.git
    
  3. 使用する UMP SDK Swift パッケージのバージョンを選択します。新しいプロジェクトの場合は [Up to Next Major Version] を選択することをおすすめします。

Xcode は、パッケージの依存関係を解決し、バックグラウンドでダウンロードします。パッケージの依存関係の追加について詳しくは、Apple の記事を参照してください。

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

アプリケーション ID は、アド マネージャーの UI で確認できます。次のコード スニペットを使用して、ID を Info.plist に追加します。

<key>UMPApplicationIdentifier</key>
<string>ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy</string>

requestConsentInfoUpdateWithParameters:completionHandler: を使用して、アプリの起動ごとにユーザーの同意情報の更新をリクエストする必要があります。このリクエストは、次のことを確認します。

  • 同意が必要かどうか。たとえば、同意が初めて必要になった場合や、以前の同意の決定の有効期限が切れた場合などです。
  • プライバシー オプションのエントリ ポイントが必要かどうか。一部のプライバシー メッセージでは、アプリでユーザーがいつでもプライバシー オプションを変更できるようにする必要があります。

Swift


// Requesting an update to consent information should be called on every app launch.
ConsentInformation.shared.requestConsentInfoUpdate(with: parameters) {
  requestConsentError in
  // ...
}

Objective-C


// Requesting an update to consent information should be called on every app launch.
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                         completionHandler:^(NSError *_Nullable requestConsentError) {
                           // ...
                         }];

プライバシー メッセージ フォームを読み込んで表示する

最新の同意ステータスを取得したら、 loadAndPresentIfRequiredFromViewController:completionHandler: を呼び出して、ユーザーの同意を得るために必要なフォームを読み込みます。読み込み後、フォームがすぐに表示されます。

Swift


try await ConsentForm.loadAndPresentIfRequired(from: viewController)

Objective-C


[UMPConsentForm
    loadAndPresentIfRequiredFromViewController:viewController
                             completionHandler:^(NSError *_Nullable loadAndPresentError) {
                                 // Consent gathering process is complete.
                                }];

プライバシー オプション

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

プライバシー オプションのエントリ ポイントが必要かどうかを確認する

requestConsentInfoUpdateWithParameters:completionHandler: を呼び出した後、 UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus をチェックして、アプリにプライバシー オプションのエントリ ポイントが必要かどうかを判断します。エントリ ポイントが必要な場合は、プライバシー オプション フォームを表示する、表示可能で操作可能な UI 要素をアプリに追加します。プライバシー エントリ ポイントが不要な場合は、UI 要素が非表示で操作可能になるように構成します。

Swift


var isPrivacyOptionsRequired: Bool {
  return ConsentInformation.shared.privacyOptionsRequirementStatus == .required
}

Objective-C


- (BOOL)isPrivacyOptionsRequired {
  return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus ==
         UMPPrivacyOptionsRequirementStatusRequired;
}

- (void)gatherConsentFromConsentPresentationViewController:(UIViewController *)viewController
                                  consentGatheringComplete:
                                      (void (^)(NSError *_Nullable))consentGatheringComplete {
  UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
  // Set tag for under age of consent. Use NO constant to indicate that the user is not under age.
  parameters.tagForUnderAgeOfConsent = NO;

  UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
  // Uncomment the following line to simulate a consent request from users in the
  // European Economic Area (EEA) for testing purposes.
  // debugSettings.geography = UMPDebugGeographyEEA;
  parameters.debugSettings = debugSettings;

  // Requesting an update to consent information should be called on every app launch.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
                           completionHandler:^(NSError *_Nullable requestConsentError) {
                             // ...
                           }];
}

- (void)loadAndPresentIfRequiredFromViewController:(UIViewController *)viewController
                           completionHandler:(void (^)(NSError *_Nullable))completionHandler {
  [UMPConsentForm
      loadAndPresentIfRequiredFromViewController:viewController
                               completionHandler:^(NSError *_Nullable loadAndPresentError) {
                                   // Consent gathering process is complete.
                                  }];
}

- (void)presentPrivacyOptionsFormFromViewController:(UIViewController *)viewController
                                  completionHandler:
                                      (void (^)(NSError *_Nullable))completionHandler {
  [UMPConsentForm presentPrivacyOptionsFormFromViewController:viewController
                                            completionHandler:completionHandler];
}

@end

プライバシー オプションの要件ステータスの完全なリストについては、 UMPPrivacyOptionsRequirementStatus をご覧ください。

プライバシー オプション フォームを表示する

ユーザーが要素を操作したときに、プライバシー オプションのフォームを表示します。

Swift


ConsentForm.presentPrivacyOptionsForm(
  from: viewController, completionHandler: completionHandler)

Objective-C


[UMPConsentForm presentPrivacyOptionsFormFromViewController:viewController
                                          completionHandler:completionHandler];

ユーザーの同意を得て広告をリクエストする

広告をリクエストする前に、 UMPConsentInformation.sharedInstance.canRequestAds を使用してユーザーの同意を得ているかどうかを確認します。

Swift

ConsentInformation.shared.canRequestAds

Objective-C

UMPConsentInformation.sharedInstance.canRequestAds;

同意を取得しながら広告をリクエストできるかどうかを確認する場所は次のとおりです。

同意取得プロセス中にエラーが発生した場合は、広告をリクエストできるかどうかを確認します。UMP SDK は、前回のアプリ セッションの同意ステータスを使用します。

重複する広告リクエストの作業を防ぐ

同意を取得した後、および requestConsentInfoUpdateWithParameters:completionHandler: を呼び出した後に UMPConsentInformation.sharedInstance.canRequestAds を確認する際は、両方のチェックで true が返される可能性のある冗長な広告リクエストをロジックで防ぐようにしてください。たとえば、ブール変数を使用します。

テスト

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

  1. requestConsentInfoUpdateWithParameters:completionHandler:までお電話ください。
  2. ログ出力で次のようなメッセージを確認します。ここには、デバイス ID とテストデバイスとしてデバイスを追加する方法が示されています。

    <UMP SDK>To enable debug mode for this device, set: UMPDebugSettings.testDeviceIdentifiers = @[2077ef9a63d2b398840261c8221a0c9b]
    
  3. テストデバイスの ID をクリップボードにコピーします。

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

    Swift

    let parameters = RequestParameters()
    let debugSettings = DebugSettings()
    
    debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
    parameters.debugSettings = debugSettings
    
    // Include the UMPRequestParameters in your consent request.
    ConsentInformation.shared.requestConsentInfoUpdate(
        with: parameters,
        completionHandler: { error in
          // ...
        })
    

    Objective-C

    UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
    UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];
    
    debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ];
    parameters.debugSettings = debugSettings;
    
    // Include the UMPRequestParameters in your consent request.
    [UMPConsentInformation.sharedInstance
        requestConsentInfoUpdateWithParameters:parameters
                            completionHandler:^(NSError *_Nullable error){
                              // ...
    }];
    

地域を強制的に適用する

UMP SDK では、 UMPDebugGeography を使用して、デバイスが EEA や英国などのさまざまな地域にあるかのようにアプリの動作をテストできます。デバッグ設定はテスト用デバイスでのみ機能します。

Swift

let parameters = RequestParameters()
let debugSettings = DebugSettings()

debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
debugSettings.geography = .EEA
parameters.debugSettings = debugSettings

// Include the UMPRequestParameters in your consent request.
ConsentInformation.shared.requestConsentInfoUpdate(
    with: parameters,
    completionHandler: { error in
      // ...
    })

Objective-C

UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
UMPDebugSettings *debugSettings = [[UMPDebugSettings alloc] init];

debugSettings.testDeviceIdentifiers = @[ @"TEST-DEVICE-HASHED-ID" ];
debugSettings.geography = UMPDebugGeographyEEA;
parameters.debugSettings = debugSettings;

// Include the UMPRequestParameters in your consent request.
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                         completionHandler:^(NSError *_Nullable error){
                           // ...
}];

UMP SDK でアプリをテストする際、ユーザーの初回インストール エクスペリエンスをシミュレーションできるように、SDK の状態をリセットすると便利な場合があります。SDK には、これを行う reset メソッドが用意されています。

Swift

ConsentInformation.shared.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];

GitHub の例

このページで説明する UMP SDK の統合の完全な例については、 Swift UmpExample Objective-C UmpExample をご覧ください。