始める

コレクションでコンテンツを整理 必要に応じて、コンテンツの保存と分類を行います。

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

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

Prerequisites

  • スタートガイドを完了している。
  • AdMob アカウントの [プライバシーとメッセージ] タブでメッセージを設定します。詳しくは、 プライバシーとメッセージについて
  • GDPR 関連の要件に取り組んでいる場合は、IAB の要件が EU ユーザー向け同意メッセージに与える影響をご確認ください。

ユーザーへのメッセージの種類

ユーザー メッセージのタイプ サポートされているメッセージの一覧については、各メッセージ タイプの実装手順については、左側のナビゲーション バーをご覧ください。

SDK をインポートする

CocoaPods(推奨)

UMP SDK は、Google Mobile Ads SDK 7.64.0 以降の Google Mobile Ads SDK Pod の依存関係として組み込まれています。

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

pod 'Google-Mobile-Ads-SDK'

そのうえで、次のコマンドを実行します。

pod install --repo-update

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

手動ダウンロード

SDK をインポートする別の方法は、手動で行うことです。

SDK をダウンロード

次に、フレームワークを Xcode プロジェクトにドラッグし、[Copy items if needed] を選択します。

その後、必要なファイルにフレームワークを含めることができます。

Swift

import UserMessagingPlatform

Objective-C

#include <UserMessagingPlatform/UserMessagingPlatform.h>

Info.plist を更新する

アプリ ID を確認する これを Info.plist に追加します。

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

メッセージを表示する必要があるかどうかを判断する

フォームを読み込む前に、 requestConsentInfoUpdateWithParameters:completionHandler: を使用して、アプリの起動ごとにユーザーの同意情報の更新をリクエストする必要があります。これにより、ユーザーがまだ同意していない場合や同意の有効期限が切れた場合に、同意を提示する必要があるかどうかを判断できます。

必要に応じて、後からフォームを共有できます。

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

Swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
   // Create a UMPRequestParameters object.
   let parameters = UMPRequestParameters()
   // Set tag for under age of consent. Here false means users are not under age.
   parameters.tagForUnderAgeOfConsent = false

   // Request an update to the consent information.
   UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
      with: parameters,
      completionHandler: { error in
        if error != nil {
           // Handle the error.
        } else {
           // The consent information state was updated.
           // You are now ready to check if a form is
           // available.
        }
       })
}

Objective-C

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

// Create a UMPRequestParameters object.
UMPRequestParameters *parameters = [[UMPRequestParameters alloc] init];
// Set tag for under age of consent. Here NO means users are not under age.
parameters.tagForUnderAgeOfConsent = NO;

// Request an update to the consent information.
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                         completionHandler:^(NSError *_Nullable error) {
                           if (error) {
                             // Handle the error.
                           } else {
                             // The consent information state was updated.
                             // You are now ready to check if a form is
                             // available.
                           }
                         }];
}

利用可能な場合はフォームを読み込む

フォームを表示する前に、利用可能なフォームがあるかどうかを判断する必要があります。利用できないフォームは、ユーザーが制限付きの広告トラッキングを有効にしているか、同意年齢に満たないタグを設定している可能性があります。

利用可能なフォームをチェックするには、先ほど作成したthe formStatus property on the UMPConsentInformation instance を使用します。

次に、フォームを読み込むラッパー メソッドを追加します。

Swift

// Request an update to the consent information.
UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(
    withParameters: parameters,
    completionHandler: { [self] error in

      // The consent information has updated.
      if error != nil {
        // Handle the error.
      } else {
        // The consent information state was updated.
        // You are now ready to see if a form is available.
        let formStatus = UMPConsentInformation.sharedInstance.formStatus
        if formStatus == UMPFormStatus.available {
          loadForm()
        }
      }
    })
...
func loadForm() {

}

Objective-C

// Request an update to the consent information.
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                         completionHandler:^(NSError* _Nullable error) {

                           // The consent information has updated.
                           if (error) {
                             // Handle the error.
                           } else {
                             // The consent information state was updated.
                             // You are now ready to see if a form is available.
                             UMPFormStatus formStatus =
                                 UMPConsentInformation.sharedInstance
                                     .formStatus;
                             if (formStatus == UMPFormStatusAvailable) {
                               [self loadForm];
                             }
                           }
                         }];
...
- (void) loadForm {

}

フォームを読み込むには、 the static loadWithCompletionHandler: method on the UMPConsentForm classを使用します。

Swift

func loadForm() {
  // Loads a consent form. Must be called on the main thread.
  UMPConsentForm.load(
      withCompletionHandler: { form, loadError in
        if loadError != nil {
          // Handle the error
        } else {
          // Present the form
        }
      })
}

Objective-C

- (void)loadForm {
  [UMPConsentForm
      loadWithCompletionHandler:^(UMPConsentForm *form, NSError *loadError) {
        if (loadError) {
          // Handle the error
        } else {
          // Present the form
        }
      }];
}

必要に応じてフォームを提示します。

フォームが使用可能であることを確認して読み込みが完了したら、UMPConsentForm インスタンスのpresentFromViewController:completionHandler: メソッドを使用してフォームを表示します。

前述のUMPConsentInformation オブジェクトを使用してconsent status を確認し、loadForm メソッドを更新します。

Swift

func loadForm() {
  UMPConsentForm.load(withCompletionHandler: { form, loadError in
    if loadError != nil {
      // Handle the error.
    } else {
      // Present the form. You can also hold on to the reference to present
      // later.
      if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.required {
        form?.present(
            from: self,
            completionHandler: { dismissError in
              if UMPConsentInformation.sharedInstance.consentStatus == UMPConsentStatus.obtained {
                // App can start requesting ads.
              }
                // Handle dismissal by reloading form.
                loadForm();
            })
      } else {
        // Keep the form available for changes to user consent.
      }
    }
  })
}

Objective-C

- (void)loadForm {
  [UMPConsentForm loadWithCompletionHandler:^(UMPConsentForm *form,
                                              NSError *loadError) {
    if (loadError) {
      // Handle the error.
    } else {
      // Present the form. You can also hold on to the reference to present
      // later.
      if (UMPConsentInformation.sharedInstance.consentStatus ==
          UMPConsentStatusRequired) {
        [form
            presentFromViewController:self
                    completionHandler:^(NSError *_Nullable dismissError) {
                      if (UMPConsentInformation.sharedInstance.consentStatus ==
                          UMPConsentStatusObtained) {
                        // App can start requesting ads.
                      }
                        // Handle dismissal by reloading form.
                        [self loadForm];
                    }];
      } else {
        // Keep the form available for changes to user consent.
      }
    }
  }];
}

ユーザーがフォームを選択または拒否した後になんらかのアクションを行う必要がある場合は、そのロジックをフォームの入力ハンドラまたはコールバックに配置します。

テスト

地域を適用する

UMP SDK を使用すると、 the debugGeography property of type UMPDebugGeography on UMPDebugSettingsを使用して、デバイスが EEA または英国にあるかのようにアプリの動作をテストできます。

デバッグ機能を使用するには、アプリのデバッグ設定でテストデバイスのハッシュ ID を指定する必要があります。この値を設定せずにrequestConsentInfoUpdateWithParameters:completionHandler: を呼び出すと、実行時に必要な ID ハッシュがログに記録されます。

Swift

let parameters = UMPRequestParameters()
let debugSettings = UMPDebugSettings()
debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
debugSettings.geography = UMPDebugGeography.EEA
parameters.debugSettings = debugSettings
UMPConsentInformation.sharedInstance.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;
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                         completionHandler:^(NSError *_Nullable error){
                           ...
}];

UMPDebugGeographyを使用すると、地域を次のいずれかのオプションに強制できます。

Debuggeography 説明
UMPDebugGeographyDisabled デバッグ対象が無効です。
UMPDebugGeographyEEA デバッグデバイスの場合、地域は EEA で表示されます。
UMPDebugGeographyNotEEA デバッグ用デバイスの EEA に地域が表示されないようです。

デバッグ設定はテストデバイスでのみ機能します。エミュレータはデフォルトでテストが有効になっているため、デバイス ID リストに追加する必要はありません。

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

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];

UMP SDK をプロジェクトから完全に削除する場合は、 reset も呼び出す必要があります。