スタートガイド

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

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

Prerequisites

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

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

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

SDK をインポートする

CocoaPods(推奨)

UMP SDK は、Google Mobile Ads SDK 7.64.0 以降の Google Mobile Ads SDK pod の依存関係として含まれています。

iOS プロジェクトに SDK を簡単にインポートするには、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>

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

viewDidLoad() メソッドの UIViewController からステータスを確認する方法の例を次に示します。

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Create a UMPRequestParameters object.
  let parameters = UMPRequestParameters()
  // Set tag for under age of consent. false means users are not under age
  // of consent.
  parameters.tagForUnderAgeOfConsent = false

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
    [weak self] requestConsentError in
    guard let self else { return }

    if let consentError = requestConsentError {
      // Consent gathering failed.
      return print("Error: \(consentError.localizedDescription)")
    }

    // TODO: Load and present the consent form.
  }
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

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

  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }

            // TODO: Load and present the consent form.
          }];
}

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

最新の同意ステータスを取得したら、UMPConsentForm クラスのloadAndPresentIfRequiredFromViewController:completionHandler: を呼び出して同意フォームを読み込みます。同意ステータスが必須の場合、SDK はフォームを読み込み、 指定された view controllerからすぐに表示します。 completion handlerは、フォームが閉じられた後に呼び出されます。同意が不要な場合は、すぐに completion handlerが呼び出されます。

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Create a UMPRequestParameters object.
  let parameters = UMPRequestParameters()
  // Set tag for under age of consent. false means users are not under age
  // of consent.
  parameters.tagForUnderAgeOfConsent = false

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
    [weak self] requestConsentError in
    guard let self else { return }

    if let consentError = requestConsentError {
      // Consent gathering failed.
      return print("Error: \(consentError.localizedDescription)")
    }

    UMPConsentForm.loadAndPresentIfRequired(from: self) {
      [weak self] loadAndPresentError in
      guard let self else { return }

      if let consentError = loadAndPresentError {
        // Consent gathering failed.
        return print("Error: \(consentError.localizedDescription)")
      }

      // Consent has been gathered.
    }
  }
}

Objective-C

- (void)viewDidLoad {
  [super viewDidLoad];

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

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }

            __strong __typeof__(self) strongSelf = weakSelf;
            if (!strongSelf) {
              return;
            }

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  if (loadAndPresentError) {
                    // Consent gathering failed.
                    NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
                    return;
                  }

                  // Consent has been gathered.
                }];
          }];
}

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

広告をリクエスト

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

  1. 現在のセッションで同意が取得された後。
  2. requestConsentInfoUpdateWithParameters:completionHandler:を呼び出した直後。前回のセッションで同意を得ている可能性があります。アプリの起動後すぐに広告の読み込みを開始できるように、遅延に関するベスト プラクティスとして、コールバックの完了を待たないことをおすすめします。

同意取得の処理中にエラーが発生した場合でも、広告のリクエストを行う必要があります。UMP SDK は前のセッションの同意ステータスを使用します。

Swift

class ViewController: UIViewController {

  // Use a boolean to initialize the Google Mobile Ads SDK and load ads once.
  private var isMobileAdsStartCalled = false

  override func viewDidLoad() {
    super.viewDidLoad()

    // Create a UMPRequestParameters object.
    let parameters = UMPRequestParameters()
    // Set tag for under age of consent. false means users are not under age
    // of consent.
    parameters.tagForUnderAgeOfConsent = false

    // Request an update for the consent information.
    UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
      [weak self] requestConsentError in
      guard let self else { return }

      if let consentError = requestConsentError {
        // Consent gathering failed.
        return print("Error: \(consentError.localizedDescription)")
      }

      UMPConsentForm.loadAndPresentIfRequired(from: self) {
        [weak self] loadAndPresentError in
        guard let self else { return }

        if let consentError = loadAndPresentError {
          // Consent gathering failed.
          return print("Error: \(consentError.localizedDescription)")
        }

        // Consent has been gathered.
        if UMPConsentInformation.sharedInstance.canRequestAds {
          self.startGoogleMobileAdsSDK()
        }
      }
    }

    // Check if you can initialize the Google Mobile Ads SDK in parallel
    // while checking for new consent information. Consent obtained in
    // the previous session can be used to request ads.
    if UMPConsentInformation.sharedInstance.canRequestAds {
      startGoogleMobileAdsSDK()
    }
  }

  private func startGoogleMobileAdsSDK() {
    DispatchQueue.main.async {
      guard !self.isMobileAdsStartCalled else { return }

      self.isMobileAdsStartCalled = true

      // Initialize the Google Mobile Ads SDK.
      GADMobileAds.sharedInstance().start()

      // TODO: Request an ad.
      // GADInterstitialAd.load(...)
    }
  }
}

Objective-C

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

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

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            if (requestConsentError) {
              // Consent gathering failed.
              NSLog(@"Error: %@", requestConsentError.localizedDescription);
              return;
            }
            __strong __typeof__(self) strongSelf = weakSelf;
            if (!strongSelf) {
              return;
            }

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  if (loadAndPresentError) {
                    // Consent gathering failed.
                    NSLog(@"Error: %@", loadAndPresentError.localizedDescription);
                    return;
                  }

                  // Consent has been gathered.
                  __strong __typeof__(self) strongSelf = weakSelf;
                  if (!strongSelf) {
                    return;
                  }

                  if (UMPConsentInformation.sharedInstance.canRequestAds) {
                    [strongSelf startGoogleMobileAdsSDKOnce];
                  }
                }];
          }];

  // Check if you can initialize the Google Mobile Ads SDK in parallel
  // while checking for new consent information. Consent obtained in
  // the previous session can be used to request ads.
  if (UMPConsentInformation.sharedInstance.canRequestAds) {
    [self startGoogleMobileAdsSDKOnce];
  }
}

- (void)startGoogleMobileAdsSDKOnce {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    // Initialize the Google Mobile Ads SDK.
    [GADMobileAds.sharedInstance startWithCompletionHandler:nil];

    // TODO: Request an ad.
    // [GADInterstitialAd loadWithAdUnitID...];
  });
}

テスト

開発中にアプリとの統合をテストする場合は、次の手順に沿って、テストデバイスをプログラムで登録します。

  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 = UMPRequestParameters()
let debugSettings = UMPDebugSettings()
debugSettings.testDeviceIdentifiers = ["TEST-DEVICE-HASHED-ID"]
parameters.debugSettings = debugSettings
// Include the UMPRequestParameters in your consent request.
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" ];
parameters.debugSettings = debugSettings;
// Include the UMPRequestParameters in your consent request.
[UMPConsentInformation.sharedInstance
    requestConsentInfoUpdateWithParameters:parameters
                        completionHandler:^(NSError *_Nullable error){
                          ...
}];

地域を強制的に適用する

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

Swift

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

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

Swift

UMPConsentInformation.sharedInstance.reset()

Objective-C

[UMPConsentInformation.sharedInstance reset];