始める

Google の EU ユーザーの同意 ポリシー)を使用するには、 欧州経済領域(EEA)のユーザー向けに特定の情報を開示する Cookie またはその他のローカル ストレージを使用することについて 個人データ(AdID など)を使用して広告を配信する必要がある。 このポリシーには、EU の e プライバシー指令と 一般データ保護規則(GDPR)。

パブリッシャー様がこのポリシーで定められた義務を遂行できるよう、Google では User Messaging Platform(UMP)SDK をご利用ください。UMP SDK が更新され、 対応していますこれらすべての構成を プライバシーと AdMob 説明します。

前提条件

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

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

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

SDK をインポートする

CocoaPods(推奨)

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

pod 'GoogleUserMessagingPlatform'

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

pod install --repo-update

CocoaPods を初めて使用する場合は、CocoaPods の CocoaPods をご覧ください。 Podfile を作成して使用します。

Swift Package Manager

UMP SDK は Swift Package Manager もサポートしています。以下の手順に沿って操作してください。 Swift パッケージをインポートします。

  1. Xcode で以下に移動して、UMP SDK Swift パッケージをインストールします。 [ファイル] >Add Packages...」というメッセージが表示されます。

  2. 表示されたプロンプトで、UMP SDK Swift Package GitHub を検索します。 リポジトリ:

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

Xcode はパッケージの依存関係を解決し、パッケージにダウンロードします。 説明します。パッケージの依存関係を追加する方法について詳しくは、Apple の 記事をご覧ください。

手動ダウンロード

SDK をインポートするもう一つの方法は、手動で行う方法です。

SDK をダウンロード

次に、フレームワークを Xcode プロジェクトにドラッグし、[Copy 必要ありません

その後、次のコマンドを使用して、必要なファイルにフレームワークを含めることができます。

Swift

import UserMessagingPlatform

Objective-C

#include <UserMessagingPlatform/UserMessagingPlatform.h>

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

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

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

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

次に、UIViewController からステータスを確認する viewDidLoad() メソッドを使用します。

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
    [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];

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

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

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

最新の同意ステータスを受け取ったら、 loadAndPresentIfRequiredFromViewController:completionHandler: 日付 UMPConsentForm クラスを使用して同意フォームを読み込みます。もし 同意ステータスが必須の場合、SDK はフォームを読み込んですぐに表示します 提供されたもの view controllerから取得できます。 completion handler は フォームが閉じられた後に呼び出されます。同意が不要な場合、 completion handler は直ちに 呼び出されます。

Swift

override func viewDidLoad() {
  super.viewDidLoad()

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
    [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];

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:nil
          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()

    // Request an update for the consent information.
    UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: nil) {
      [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];

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:nil
          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 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) {
    [self startGoogleMobileAdsSDK];
  }
}

- (void)startGoogleMobileAdsSDK {
  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. アプリの設定ページのボタンなどの UI 要素を実装する プライバシー オプション フォームをトリガーできます。
  2. 完了したら loadAndPresentIfRequiredFromViewController:completionHandler: 確認 privacyOptionsRequirementStatus プライバシー オプション フォームを提示できる UI 要素です。
  3. ユーザーが UI 要素を操作すると、 presentPrivacyOptionsFormFromViewController:completionHandler: : ユーザーがフォームを表示できるように ユーザーがいつでもプライバシー オプションを更新できるようにします。

次の例は、プライバシー オプション フォームを提示する方法を示しています。 UIBarButtonItem

Swift

@IBOutlet weak var privacySettingsButton: UIBarButtonItem!

var isPrivacyOptionsRequired: Bool {
  return UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus == .required
}

override func viewDidLoad() {
  // ...

  // Request an update for the consent information.
  UMPConsentInformation.sharedInstance.requestConsentInfoUpdate(with: parameters) {
    // ...

    UMPConsentForm.loadAndPresentIfRequired(from: self) {
      //...

      // Consent has been gathered.

      // Show the button if privacy options are required.
      self.privacySettingsButton.isEnabled = isPrivacyOptionsRequired
    }
  }
  // ...
}

// Present the privacy options form when a user interacts with the
// privacy settings button.
@IBAction func privacySettingsTapped(_ sender: UIBarButtonItem) {
  UMPConsentForm.presentPrivacyOptionsForm(from: self) {
    [weak self] formError in
    guard let self, let formError else { return }

    // Handle the error.
  }
}

Objective-C

@interface ViewController ()
@property(weak, nonatomic) IBOutlet UIBarButtonItem *privacySettingsButton;
@end

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

- (void)viewDidLoad {
  // ...

  __weak __typeof__(self) weakSelf = self;
  // Request an update for the consent information.
  [UMPConsentInformation.sharedInstance
      requestConsentInfoUpdateWithParameters:parameters
          completionHandler:^(NSError *_Nullable requestConsentError) {
            // ...

            [UMPConsentForm loadAndPresentIfRequiredFromViewController:strongSelf
                completionHandler:^(NSError *loadAndPresentError) {
                  // ...

                  // Consent has been gathered.

                  // Show the button if privacy options are required.
                  strongSelf.privacySettingsButton.enabled = isPrivacyOptionsRequired;
                }];
          }];
}

// Present the privacy options form when a user interacts with your
// privacy settings button.
- (IBAction)privacySettingsTapped:(UIBarButtonItem *)sender {
  [UMPConsentForm presentPrivacyOptionsFormFromViewController:self
                                completionHandler:^(NSError *_Nullable formError) {
                                  if (formError) {
                                    // Handle the error.
                                  }
                                }];
}

テスト

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

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];

GitHub の例

UMP SDK の統合例: Swift | Objective-C