プライバシーと Messaging JavaScript API

はじめに

この API は、[プライバシーとメッセージ] タブで提供されるメッセージを操作するためのツールを提供します。Metrics Explorer では次の作業を行うことができます。

使用できます。

これらのツールを使用して、業界標準のプロトコルでユーザーの同意を収集することもできます。

このような場合、同意ステータスはこれらの API を介して伝達されます。

サイトにユーザー メッセージ機能を追加するには、次の 2 つの方法があります。

  1. ほとんどの場合、タグを再設定する必要はありません。既存の Google パブリッシャー タグまたは AdSense タグは、関連するサービスでメッセージが公開されると、ユーザー メッセージを 1 回だけ配信します。
  2. 広告ブロックによる損失収益の回復メッセージを使用する場合は、広告ブロックタグをページに明示的に追加する必要があります。詳しくは、Ad ManagerAdSense のタグ設定手順をご覧ください。

googlefc は、ユーザー メッセージ機能が JavaScript Window の API に使用するグローバル名前空間です。

フィールドの概要

名前 タイプ 定義
googlefc.controlledMessagingFunction function(!Object) メッセージングを続行するかどうかを判断する関数。この機能は、すべてのメッセージ タイプでサポートされています。
googlefc.callbackQueue !Array<!Object<string, function()>> | !Array<function()> | !googlefc.CallbackQueue ユーザー メッセージング クエリの非同期実行用のコールバック キューへの参照。
googlefc.CallbackQueue !Object コールバック キュー オブジェクトの型。
googlefc.AdBlockerStatusEnum !Object<string, number> ユーザーの広告ブロッカーの状態を表す列挙型。
googlefc.AllowAdsStatusEnum !Object<string, number> ユーザーの広告許可状態を表す列挙型。
googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum !Object<string, number> ユーザーの米国の州の初期オプトアウト ステータスを表す列挙型。この場合、ユーザーが居住する米国の州が考慮されます。
googlefc.GoogleFcConsentModeUserStatus !Object googlefc.getGoogleConsentModeValues の戻り値の型。
googlefc.ConsentModePurposeStatusEnum !Object<string, number> 同意モードの目的に対するエンドユーザーの決定を表す列挙型。
googlefc.usstatesoptout.overrideDnsLink undefined|boolean 独自のカスタムの販売または共有の停止リンクを使用する場合は、true に設定できるブール値。
googlefc.ccpa.InitialCcpaStatusEnum

レガシー。googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum を優先します。
!Object<string, number> ユーザーの米国の州規制の初期ステータスを表す列挙型。
googlefc.ccpa.overrideDnsLink

レガシー。googlefc.usstatesoptout.overrideDnsLink を優先します。
undefined|boolean 独自のカスタムの販売または共有の停止リンクを使用する場合は、true に設定できるブール値。

メソッドの概要

名前 戻り値の型 定義
googlefc.showRevocationMessage() 未定義 同意レコードをクリアし、googlefc スクリプトを再読み込みして、ユーザーに該当する同意メッセージを表示します。
googlefc.getAdBlockerStatus() 数値 ユーザーの広告ブロック ステータスに応じて AdBlockerStatusEnum の値を返します。
googlefc.getAllowAdsStatus() 数値 ユーザーの広告許可ステータスに応じて AllowAdsStatusEnum の値を返します。
googlefc.usstatesoptout.getInitialUsStatesOptOutStatus() 数値 ユーザーの米国の州規制に関する初期のオプトアウト ステータスに応じて、InitialUsStatesOptOutStatusEnum の値を返します。これは、ユーザーの現在地に基づいてユーザーに適用される規制を考慮したものです。
googlefc.usstatesoptout.openConfirmationDialog(function(boolean)) 未定義 デフォルトの「販売、共有しない」リンクがオーバーライドされている場合、米国の州規制のオプトアウト確認ダイアログを開きます。
googlefc.getGoogleConsentModeValues() !Object ユーザーの現在の同意モードの値を含む googlefc.GoogleFcConsentModeUserStatus オブジェクトを返します。利用可能な同意モードの目的ごとに 1 つの値が返されます。
googlefc.ccpa.getInitialCcpaStatus()

レガシー。googlefc.usstatesoptout.getInitialUsStatesOptOutStatus() を優先します。
数値 ユーザーの米国の州規制の初期オプトアウト ステータスに応じて、InitialCcpaStatusEnum の値を返します。
googlefc.ccpa.openConfirmationDialog(function(boolean))

レガシー。googlefc.usstatesoptout.openConfirmationDialog() を優先します。
未定義 デフォルトの「販売、共有しない」リンクがオーバーライドされている場合、米国の州規制のオプトアウト確認ダイアログを開きます。

サイトでのテストとデバッグ

プライバシーとメッセージには、実際のサイトで特定のメッセージ、メッセージのサブタイプ、メッセージの組み合わせがどのように表示されるかを確認できるデバッグ機能とテスト機能が用意されています。

前提条件:

  • プレビューするメッセージは、テスト対象のサイトで公開されている必要があります。

次のデバッグ URL パラメータを使用すると、サイトのライブ プレビューを確認できます。

デバッグ パラメータ 使用できる値
fc alwaysshow(デバッグ/プレビュー モードをトリガーするため)
fctype ab(広告ブロック メッセージ)、ccpa(米国の州の規制に基づくオプトアウト メッセージ)、gdpr(GDPR 同意メッセージ)、monetization(オファーウォール メッセージ)、usfl(米国の州の規制に基づくオプトアウト メッセージ、フロリダ州固有)、usnat(米国の州の規制に基づくオプトアウト メッセージ、フロリダ州を除くすべてのサポート対象州。ccpa と同等)

この機能を使用してサイト(foo.com)でプレビューを行う方法の例を次に示します。

  • 米国の州規制のオプトアウト メッセージをテストする -- http://foo.com/?fc=alwaysshow&fctype=ccpa
  • GDPR メッセージをテストする - http://foo.com/?fc=alwaysshow&fctype=gdpr

フィールド: 説明と例

googlefc.controlledMessagingFunction {function(!Object)}

メッセージを表示するかどうかを判断する関数。この API を使用して、パブリッシャーが指定した条件(購読者のステータスやページの URL など)に基づいてメッセージのレンダリングを制御できます。

他のスクリプトが読み込まれる前に Window で googlefc.controlledMessagingFunction を定義すると、message.proceed(boolean) を呼び出すまでメッセージは表示されません。message.proceed(true) を呼び出すと、メッセージは通常どおりに処理されます。一方、message.proceed(false) を呼び出すと、ページビューでメッセージが表示されなくなります。

例: ログインしているユーザーが購読者かどうかを確認する非同期関数 determineIfUserIsSubscriber() を定義するスクリプトがページにあるとします。

<head>
  <script>
    window.isSubscriber = undefined;
    function determineIfUserIsSubscriber() {
      if (isSubscriber !== undefined) {
        return isSubscriber;
      }
      return new Promise(resolve => {
        setTimeout(() => {
          // Change this to true if you want to test what subscribers would see.
          window.isSubscriber = false;
          resolve(window.isSubscriber);
        }, 1000);
      });
    }
  </script>
</head>

これは、googlefc.controlledMessagingFunction を使用して、メッセージを登録していないユーザーにのみ表示する方法の例です。

<head>
  <script>
    // Define googlefc and the controlled messaging function on the Window.
    window.googlefc = window.googlefc || {};
    googlefc.controlledMessagingFunction = async (message) => {
      // Determine if the user is a subscriber asynchronously.
      const isSubscriber = await determineIfUserIsSubscriber();

      if (isSubscriber) {
        // If the user is a subscriber, don't show any messages.
        message.proceed(false);
      } else {
        // Otherwise, show messages as usual.
        message.proceed(true);
      }
    }
  </script>
</head>

この機能の拡張版もあり、パブリッシャーはオファーウォールのみを非表示にするよう指定できます。この機能拡張を使用すると、他のメッセージ タイプを抑制せずにオファーウォールを抑制できます。

オファーウォール固有の制御されたメッセージは、message.proceed() に追加のパラメータ(googlefc.MessageTypeEnum 型の Array)を渡すことで実現されます。

例: 次の例では、googlefc.controlledMessagingFunction を使用して、他のメッセージ タイプを抑制せずに、定期購入者向けのオファーウォールの配信のみを抑制しています。

<head>
  <script>
    // Define googlefc and the controlled messaging function on the Window.
    window.googlefc = window.googlefc || {};
    googlefc.controlledMessagingFunction = async (message) => {
     // Determine if the Offerwall should display or not.
     const shouldDisplayOfferwall = await determineIfUserIsSubscriber();
     const applicableMessageTypes = [];

     if (!shouldDisplayOfferwall) {
       // Do not show the Offerwall, but allow other message types to display.
       applicableMessageTypes.push(window.googlefc.MessageTypeEnum.OFFERWALL);
       message.proceed(false, applicableMessageTypes);
     } else {
       // Otherwise, show messages as usual.
       message.proceed(true);
     }
    }
  </script>
</head>

googlefc.callbackQueue {!Array<!Object<string, function()>> | !Array<function()> | !googlefc.CallbackQueue}

メッセージ関連の呼び出しの非同期実行用のグローバル コールバック キューへの参照。関数を呼び出す唯一の方法は、callbackQueue に追加することです。

さまざまな種類のデータがさまざまなタイミングで利用可能になるため、関数はマップとして追加する必要があります。キーには次のいずれかの文字列、値には実行する関数を指定します。

サポートされているキー:

キー名 用途 相対レイテンシ
CONSENT_API_READY CONSENT_API_READY キーを使用してコールバック キューにプッシュされた関数は、サポートされている同意フレームワークの API が定義され、呼び出し可能になったときに実行されます。この時点以降、後で追加された CONSENT_API_READY キー付き関数の実行は同期的になります。フレームワーク固有の詳細については、 IAB フレームワークのセクションをご覧ください。
CONSENT_DATA_READY CONSENT_DATA_READY キーを使用してコールバック キューにプッシュされた関数は、サポートされている同意フレームワークで収集されたユーザーの同意が判明したときに実行されます(以前の実行から、またはユーザーが同意メッセージを操作したとき)。この時点以降、後で追加された CONSENT_DATA_READY キー付き関数の実行は同期的になります。
AD_BLOCK_DATA_READY AD_BLOCK_DATA_READY キーを使用してコールバック キューにプッシュされた関数は、フローで広告ブロック データが利用可能になると実行されます。この時点以降、後で追加された AD_BLOCK_DATA_READY キー付き関数の実行は同期されます。
CONSENT_MODE_DATA_READY CONSENT_MODE_DATA_READY キーを使用してコールバック キューにプッシュされた関数は、Google の [同意モード](https://support.google.com/google-ads/answer/10000067) データ(Google 広告とアナリティクスのタグで使用)がフローで使用可能になったときに実行されます。同意モードのデータの準備が整ったら、googlefc.getGoogleConsentModeValues を使用して同意モードの値にいつでもアクセスできます。
INITIAL_US_STATES_OPT_OUT_DATA_READY INITIAL_US_STATES_OPT_OUT_DATA_READY キーを使用してコールバック キューにプッシュされた関数は、フローで米国の州の規制データが使用可能になると実行されます。米国州の規制データに関する後続のリクエストは、GPP API(__gpp)を直接呼び出すことで取得する必要があります。
INITIAL_CCPA_DATA_READY 米国の州規制のレガシーキー。INITIAL_US_STATES_OPT_OUT_DATA_READY を優先します。

INITIAL_CCPA_DATA_READY キーを使用してコールバック キューにプッシュされた関数は、フローで米国の州の規制データが使用可能になったときに実行されます。米国州の規制データに関する後続のリクエストは、GPP API(__gpp)を直接呼び出すことで取得する必要があります。

googlefc.CallbackQueue {!Object}

メソッドの概要:

名前 タイプ パラメータ 戻り値の型 ロール
push(data) 数値 data: キーがデータ可用性タイプのいずれかで、値が実行される JavaScript 関数である Key-Value ペア。使用可能なデータ可用性キーは、CONSENT_API_READYCONSENT_DATA_READYAD_BLOCK_DATA_READYINITIAL_US_STATES_OPT_OUT_DATA_READYCONSENT_MODE_DATA_READYINITIAL_CCPA_DATA_READY(レガシー)です。 これまでに登録されたコマンドの数。これにより、配列の現在の長さが返されます。 渡された関数を、データが利用可能になった順序で実行し、次にこれらの関数がキューに追加された順序で実行します。

例:

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

  // Queue the callback on the callbackQueue.
  googlefc.callbackQueue.push({
    'AD_BLOCK_DATA_READY':
    () => {
      if (googlefc.getAdBlockerStatus() == googlefc.AdBlockerStatusEnum.NO_AD_BLOCKER) {
        // Handle a non-ad blocking user.
      }
    }
  });
</script>

googlefc.AdBlockerStatusEnum {!Object<string, number>}

ユーザーのさまざまな広告ブロックの状態を表します。状態は次のとおりです。

googlefc.AdBlockerStatusEnum = {
  // Something failed, in an unknown state.
  UNKNOWN: 0,
  // The user was running an extension level ad blocker.
  EXTENSION_AD_BLOCKER: 1,
  // The user was running a network level ad blocker.
  NETWORK_LEVEL_AD_BLOCKER: 2,
  // The user was not blocking ads.
  NO_AD_BLOCKER: 3,
};

googlefc.AllowAdsStatusEnum {!Object<string, number>}

ユーザーの広告ブロックによる損失収益の回復の広告を許可したさまざまな状態を表します。状態は次のとおりです。

googlefc.AllowAdsStatusEnum = {
  // Something failed, in an unknown state.
  UNKNOWN: 0,
  // User is currently using an ad blocker, was never using an ad blocker, or
  // allowed ads, but not because they saw the Privacy & messaging message.
  ADS_NOT_ALLOWED: 1,
  // User is no longer using an ad blocker after seeing the ad blocking message.
  ADS_ALLOWED: 2,
};

googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum{!Object<string, number>}

ユーザーの米国の州規制に関するさまざまなオプトアウト ステータスを表します。ステータスは次のとおりです。

googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum = {
  // Something failed, status unknown.
  UNKNOWN: 0,
  // No US state regulation applies to this user.
  DOES_NOT_APPLY: 1,
  // A US state regulation applies to this user, and the user has not opted out yet.
  NOT_OPTED_OUT: 2,
  // A US state regulation applies to this user, and the user has opted out.
  OPTED_OUT: 3,
};

googlefc.GoogleFcConsentModeUserStatus{!Object}

googlefc.getGoogleConsentModeValues によって返されるオブジェクトの型。

interface GoogleFcConsentModeUserStatus {

  // End user consent decision value for the ad_storage consent mode purpose.
  adStoragePurposeConsentStatus: number;

  // End user consent decision value for the ad_user_data consent mode purpose.
  adUserDataPurposeConsentStatus: number;

  // End user consent decision value for the ad_personalization consent mode purpose.
  adPersonalizationPurposeConsentStatus: number;

  // End user consent decision value for the analytics_storage consent mode purpose.
  analyticsStoragePurposeConsentStatus: number;
}

各フィールドの値は、googlefc.ConsentModePurposeStatusEnum 列挙値に対応する数値です。


googlefc.ConsentModePurposeStatusEnum{!Object<string, number>}

同意モードの目的で可能なエンドユーザーの同意の値を表します。値は次のとおりです。

googlefc.ConsentModePurposeStatusEnum = {
  // Indicates either an error state, or that consent mode data is not ready
  // yet.
  UNKNOWN: 0,
  // Consent is granted for the given consent mode purpose.
  GRANTED: 1,
  // Consent is denied for the given consent mode purpose.
  DENIED: 2,
  // Consent is not applicable for the given consent mode purpose.
  NOT_APPLICABLE: 3,
  // The consent mode purpose has not been configured for use in the Privacy &
  // messaging UI.
  NOT_CONFIGURED: 4
};

googlefc.usstatesoptout.overrideDnsLink{undefined|boolean}

デフォルトの [個人情報を売却、共有しない] リンクを非表示にして、独自のカスタム [個人情報を売却、共有しない] リンクを使用するには、このフィールドを true に設定します。

例:

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
  // Signals that the default DNS link will be overridden.
  googlefc.usstatesoptout.overrideDnsLink = true;
</script>

googlefc.ccpa.InitialCcpaStatusEnum{!Object<string, number>}

ユーザーの米国の州規制に関するさまざまなオプトアウト ステータスを表します。ステータスは次のとおりです。

googlefc.ccpa.InitialCcpaStatusEnum = {
  // Something failed, in an unknown state.
  UNKNOWN: 0,
  // No US state regulation applies to this user.
  CCPA_DOES_NOT_APPLY: 1,
  // A US state regulation applies to this user, and the user has not opted out yet.
  NOT_OPTED_OUT: 2,
  // A US state regulation applies to this user, and the user has opted out.
  OPTED_OUT: 3,
};

googlefc.ccpa.overrideDnsLink{undefined|boolean}

デフォルトの [個人情報を売却、共有しない] リンクを非表示にして、独自のカスタム [個人情報を売却、共有しない] リンクを使用するには、このフィールドを true に設定します。このフィールドを true に設定した場合、サイトに「個人情報の販売または共有を拒否する」リンクを表示する責任はお客様にあります。このフィールドは openConfirmationDialog と組み合わせて使用する必要があります。

例:

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.ccpa = window.googlefc.ccpa || {};
  // Signals that the default DNS link will be overridden.
  googlefc.ccpa.overrideDnsLink = true;
</script>

メソッド: 説明と例

googlefc.getConsentStatus(): {number}


googlefc.getConsentedProviderIds(): {!Array<string>}

  1. 呼び出されると、常に空のリストが返されるようになりました。

googlefc.showRevocationMessage(): {undefined}

現在の EU の規制に関する同意レコード(存在する場合)をクリアし、EU の規制に関するメッセージを再度表示して、ユーザーが同意の決定を変更できるようにします。

例 1: クリックすると取り消しメッセージが表示されるリンクを設定する簡単な例:

<a href="javascript:window.googlefc.showRevocationMessage();">Privacy and cookie settings</a>
<a href="javascript:window.googlefc.showRevocationMessage();" style="display: none;" id="revocation-link">Privacy and cookie settings</a>
<script>
  window.googlefc = window.googlefc || {};
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
  window.googlefc.callbackQueue.push({
    'CONSENT_API_READY':
    () => {
      // Update the revocation link so that it shows on the page.
      const revocationLink = document.getElementById('revocation-link');
      revocationLink.style.display = 'block';
    }
  });
</script>

例 2: EU の規制が現在のユーザーに適用される場合にのみリンクを表示したい場合は、TCF API で googlefc コールバック キューを使用して、gdprApplies の値が確定したら、その値に基づいてボタンの表示を条件付きで更新できます。これには、CONSENT_API_READY API キーを使用します。

<a href="javascript:window.googlefc.showRevocationMessage();" style="display: none;" id="revocation-link">Privacy and cookie settings</a>
<script>
  window.googlefc = window.googlefc || {};
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];
  window.googlefc.callbackQueue.push({
    'CONSENT_API_READY':
    // Specifying "0" for the version parameter will result in the API call
    // using the latest version of the TCF spec.
    () => __tcfapi('addEventListener', 0, (tcdata, success) => {
      const revocationLink = document.getElementById('revocation-link');
      if (!success || !tcdata) {
        // Something went wrong, don't show the revocation link.
        revocationLink.style.display = 'none';
      }
      else if (tcdata.gdprApplies) {
        revocationLink.style.display = 'block';
      } else {
        // GDPR does not apply so don't show the revocation link.
        revocationLink.style.display = 'none';
      }
    })
  });
</script>

googlefc.getAdBlockerStatus(): {number}

ユーザーの広告ブロック ステータスに応じて、AdBlockerStatusEnum の値を返します。この関数に指定するキーは AD_BLOCK_DATA_READY です。

例:

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

  // Queue the callback on the callbackQueue.
  googlefc.callbackQueue.push({
    'AD_BLOCK_DATA_READY':
    () => {
      switch (googlefc.getAdBlockerStatus()) {
          case googlefc.AdBlockerStatusEnum.EXTENSION_LEVEL_AD_BLOCKER:
          case googlefc.AdBlockerStatusEnum.NETWORK_LEVEL_AD_BLOCKER:
            // Insert handling for cases where the user is blocking ads.
            break;
          case googlefc.AdBlockerStatusEnum.NO_AD_BLOCKER:
            // Insert handling for cases where the user is not blocking ads.
            break;
          case googlefc.AdBlockerStatusEnum.UNKNOWN:
            // Insert handling for unknown cases.
            break;
      }
    }
  });
</script>

googlefc.getAllowAdsStatus(): {number}

ユーザーの広告許可ステータスに応じて、AllowAdsStatusEnum の値を返します。この関数に指定するキーは AD_BLOCK_DATA_READY です。

例:

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

  // Queue the callback on the callbackQueue.
  googlefc.callbackQueue.push({
    'AD_BLOCK_DATA_READY':
    () => {
      switch (googlefc.getAllowAdsStatus()) {
        case googlefc.AllowAdsStatusEnum.ADS_NOT_ALLOWED:
          // Insert handling for cases where the user has not allowed ads.
          // The user may have never been an ad blocker.
          break;
        case googlefc.AllowAdsStatusEnum.ADS_ALLOWED:
          // Insert handling for cases where the user saw the ad blocking
          // message and allowed ads on the site.
          break;
        case googlefc.AllowAdsStatusEnum.UNKNOWN:
          // Insert handling for unknown cases.
          break;
      }
    }
  });
</script>

googlefc.usstatesoptout.getInitialUsStatesOptOutStatus(): {number}

ユーザーの米国の州規制のオプトアウト ステータスに応じて、InitialUsStatesOptOutStatusEnum の値を返します。この関数に指定するキーは INITIAL_US_STATES_OPT_OUT_DATA_READY です。米国の州の規制に関するデータの後続のリクエストは、GPP API(__gpp)を直接呼び出すことで取得する必要があります。

[販売または共有を禁止する] リンクをオーバーライドする場合は、このメソッドを使用して、サイトにリンクを含めるタイミングを判断できます。

例:

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {}
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

  // Queue the callback on the callbackQueue.
  googlefc.callbackQueue.push({
    'INITIAL_US_STATES_OPT_OUT_DATA_READY':
    () => {
      switch (googlefc.usstatesoptout.getInitialUsStatesOptOutStatus()) {
        case googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum.DOES_NOT_APPLY:
          // Insert handling for cases where no US state regulation applies to
          // the user.
          break;
        case googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum.NOT_OPTED_OUT:
          // Insert handling for cases where a US state regulation applies to
          // the user, and the user has not opted out.
          break;
        case googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum.OPTED_OUT:
          // Insert handling for cases where a US state regulation applies to the
          // user, and the user has opted out.
          break;
      }
    }
  });
</script>

googlefc.usstatesoptout.openConfirmationDialog(function(boolean)): {undefined}

デフォルトの「販売しない」リンクがオーバーライドされている場合、米国の州の規制のオプトアウト確認ダイアログを開きます。ユーザーが確認ダイアログを操作すると、ユーザーがオプトアウトを選択した場合は true、それ以外の場合は false を指定して、提供されたコールバック関数が呼び出されます。

例:

<script>
// This callback will be called with the user's US state regulation opt-out
// decision.
const usStateRegCompletionCallback = (userOptedOut) => {
  // Insert handling for user opt-out status here.
}
// Invoke the US state regulations confirmation dialog when the user clicks the
// link.
document.getElementById("your-custom-do-not-sell-link").addEventListener(
  "click", () => googlefc.usstatesoptout.openConfirmationDialog(usStateRegCompletionCallback));
</script>

googlefc.getGoogleConsentModeValues(): {!Object}

ユーザーの同意の決定に基づいて、各同意モードの目的の現在の値を含む googlefc.GoogleFcConsentModeUserStatus オブジェクトを返します。

使用方法については、EU 規制に対応した同意モードで Google の同意管理ソリューションを使用するをご覧ください。


googlefc.ccpa.getInitialCcpaStatus(): {number}

ユーザーの米国の州規制に関するオプトアウト ステータスに応じて、InitialCcpaStatusEnum の値を返します。この関数に指定するキーは INITIAL_CCPA_DATA_READY です。米国の州の規制データに対する後続のリクエストは、GPP API(__gpp)を直接呼び出すことで取得する必要があります。

例:

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.ccpa = window.googlefc.ccpa || {}
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

  // Queue the callback on the callbackQueue.
  googlefc.callbackQueue.push({
    'INITIAL_CCPA_DATA_READY':
    () => {
      switch (googlefc.ccpa.getInitialCcpaStatus()) {
        case googlefc.ccpa.InitialCcpaStatusEnum.CCPA_DOES_NOT_APPLY:
          // Insert handling for cases where no US state regulation applies to
          // the user.
          break;
        case googlefc.ccpa.InitialCcpaStatusEnum.NOT_OPTED_OUT:
          // Insert handling for cases where a US state regulation applies to
          // the user, and the user has not opted out.
          break;
        case googlefc.ccpa.InitialCcpaStatusEnum.OPTED_OUT:
          // Insert handling for cases where a US state regulation applies to the
          // user, and the user has opted out.
          break;
      }
    }
  });
</script>

googlefc.ccpa.openConfirmationDialog(function(boolean)): {undefined}

デフォルトの「販売しない」リンクがオーバーライドされている場合、米国の州の規制のオプトアウト確認ダイアログを開きます。ユーザーが確認ダイアログを操作すると、ユーザーがオプトアウトを選択した場合は true、それ以外の場合は false を指定して、提供されたコールバック関数が呼び出されます。

例:

<script>
// This callback will be called with the user's US state regulation opt-out
// decision.
const usStateRegCompletionCallback = (userOptedOut) => {
  // Insert handling for user opt-out status here.
}
// Invoke the US state regulations confirmation dialog when the user clicks the
// link.
document.getElementById("your-custom-ccpa-do-not-sell-link").addEventListener(
  "click", () => googlefc.ccpa.openConfirmationDialog(ccpaCompletionCallback));
</script>

IAB TCF v2 フレームワークで GDPR の同意を取得するために Google の同意管理ソリューションを使用している場合は、IAB TCF v2 API を使用する必要があります。

CONSENT_API_READY コールバック キューキーを使用すると、IAB TCF v2 API がページで定義されている場合にのみ、対応するコールバックが呼び出されるようになります。これは、IAB TCF v2 API の 'addEventListener' コマンドと組み合わせて使用する必要があります。

例:

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

  // Queue the callback using the CONSENT_API_READY key on the callbackQueue.
  window.googlefc.callbackQueue.push({
    'CONSENT_API_READY':
    () => __tcfapi('addEventListener', 2.2, (data, success) => {
      // Do something with consent data value; this callback may be invoked
      // multiple times as user completes consent flow.
    })
  });
</script>

CONSENT_DATA_READY コールバック キューキーを使用すると、IAB TCF v2 API を使用してユーザーの同意が収集され、アクセス可能になった場合にのみ、対応するコールバックが呼び出されるようにできます。これは 'addEventListener' コマンドと組み合わせて使用できます。提供されたコールバックの最初の呼び出しで提供されるデータには、ユーザーの同意の選択が含まれます(TCF v2 がこのユーザーに適用される場合)。TCF v2.2 のリリースに伴い、'getTCData' コマンドは非推奨になりました。

例:

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

  // Queue the callback using the CONSENT_DATA_READY key on the callbackQueue.
  window.googlefc.callbackQueue.push({
    'CONSENT_DATA_READY':
    () => __tcfapi('addEventListener', 2.2, (data, success) => {
      // Do something with consent data value; this callback may be invoked
      // multiple times if user consent selections change.
    })
  });
</script>

Google の同意管理ソリューションは、EU 規制に関するユーザーの同意の選択を Google の同意モード用に解釈できます(詳しくは、ヘルプセンターをご覧ください)。

同意モードは、Google 広告とアナリティクスのドキュメントに記載されているとおり、基本モードまたは高度なモードで実装できます。法的要件を満たすために実装すべき同意モードについては、法務部門にご相談ください。

高度な同意モードはデフォルトでサポートされています。[プライバシーとメッセージ] の管理画面で同意モードを有効にすると、追加の作業は必要ありません。

Google の同意管理ソリューションを使用して基本的な同意モードを実装するには、CONSENT_MODE_DATA_READY コールバック キューキーを使用して、同意モードのデータが利用可能になったら Google 広告タグとアナリティクス タグを条件付きで読み込むことができます。同意モードのデータは、ファンディング チョイスがこのリクエストに同意モードが適用されないと判断した場合(たとえば、このリクエストに EU の規制が適用されない場合)、またはユーザーが EU の規制に関する同意の決定を行った後に利用可能になります。同意モードが利用可能になったときにタグを読み込めるかどうかを判断するために使用する基準については、法務部門にご相談ください。

たとえば、エンドユーザーの同意の決定に関係なく、同意モードのデータが利用可能になったらタグを読み込むには:

<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

// Helper function to load Google Ads/Analytics tags once consent mode data is
// ready.
const loadGtagScript = () => {
  // Load gtag.js script - code taken from
  // https://developers.google.com/tag-platform/security/guides/consent?consentmode=basic#set_up_consent_mode
  var gtagScript = document.createElement('script');
  gtagScript.async = true;
  gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=<Google tag ID>';

  var firstScript = document.getElementsByTagName('script')[0];
  firstScript.parentNode.insertBefore(gtagScript,firstScript);
}

// Queue the callback using the CONSENT_MODE_DATA_READY key on the callbackQueue.
window.googlefc.callbackQueue.push({
  'CONSENT_MODE_DATA_READY':
  () => {
      loadGtagScript();
  },
});
</script>

また、同意モードのデータが利用可能な場合は、googlefc.getGoogleConsentModeValues() API を使用して、同意モードの個々の目的の値を取得することもできます。この API は、サポートされている各同意モードの目的のフィールドを 1 つずつ含む GoogleFcConsentModeUserStatus オブジェクトを返します。各フィールドの値は、その同意モードの目的の値を示す列挙値です。

たとえば、googlefc.getGoogleConsentModeValues() を使用して、次のいずれかの条件を満たす場合にのみ Google 広告とアナリティクスのタグのブロックを解除できます。

  • エンドユーザーが EU の規制に関する同意の決定を行い、すべての同意モードの目的で同意が付与された場合。または
  • 現在のリクエストに同意モードのすべての目的が適用されない場合(EU の規制が適用されない場合や、[プライバシーとメッセージ] で 1 つ以上の目的に対して同意モードが設定されていない場合など)。
<script>
// Make sure that the properties exist on the window.
window.googlefc = window.googlefc || {};
window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

// Helper function to determine whether Google Ads and Analytics tags can be
// unblocked. Returns true if all consent mode purposes are set to GRANTED,
// NOT_APPLICABLE, or NOT_CONFIGURED.
const shouldUnblockConsentTags = (googleFcConsentModeStatus) => {
  const allConsentModeValues = [
    googleFcConsentModeStatus.adStoragePurposeConsentStatus,
    googleFcConsentModeStatus.adUserDataPurposeConsentStatus,
    googleFcConsentModeStatus.adPersonalizationPurposeConsentStatus,
    googleFcConsentModeStatus.analyticsStoragePurposeConsentStatus
  ];
  for (const consentModeValue of allConsentModeValues) {
    switch (consentModeValue) {
      case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_UNKNOWN:
        // Indicates either an error case or that consent mode data is not
        // ready yet. Cannot unblock tags until consent data is ready and valid,
        // so return false.
        return false;
      case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_GRANTED:
        // Consent is granted for this consent mode purpose.
        break;
      case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_DENIED:
        // Consent is denied for this consent mode purpose. Do not unblock tags.
        return false;
      case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_NOT_APPLICABLE:
        // Consent mode does not apply for this purpose.
        break;
      case googlefc.ConsentModePurposeStatusEnum.CONSENT_MODE_PURPOSE_STATUS_NOT_CONFIGURED:
        // Consent mode not configured for this purpose.
        // If you configured support for Ads purposes but not Analytics purposes in the
        // Privacy & messaging UI, the value of `analyticsStoragePurposeConsentStatus` will
        // always be set to NOT_CONFIGURED. If you do not enable any Consent Mode support
        // in the Privacy & messaging UI, the values of all purposes will always be set to
        // NOT_CONFIGURED.
        break;
      default:
        console.log("Unexpected consent mode value encountered");
    }
  }
  // If all prior checks pass, all consent mode values are either GRANTED,
  // NOT_APPLICABLE, or NOT_CONFIGURED.
  return true;
};

// Helper function to load Google Ads/Analytics tags.
const loadGtagScript = () => {
  // Load gtag.js script - code taken from
  // https://developers.google.com/tag-platform/security/guides/consent?consentmode=basic#set_up_consent_mode
  var gtagScript = document.createElement('script');
  gtagScript.async = true;
  gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id=<Google tag ID>';

  var firstScript = document.getElementsByTagName('script')[0];
  firstScript.parentNode.insertBefore(gtagScript,firstScript);
}

googlefc.callbackQueue.push({
  CONSENT_MODE_DATA_READY: () => {
    if (shouldUnblockConsentTags(googlefc.getGoogleConsentModeValues())) {
      loadGtagScript();
    }
  },
});
</script>

IAB GPP フレームワークで Google の同意管理ソリューションを使用して米国の州の規制に基づくオプトアウト メッセージをエンドユーザーに提供している場合は、IAB GPP API を使用する必要があります。

米国の州の規制はオプトアウト方式であるため、CONSENT_API_READY または CONSENT_DATA_READY コールバック キューキーを使用して、コールバックが呼び出されるときに IAB GPP API が呼び出し可能で、同意データを返していることを確認できます。

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

  // Queue the callback on the callbackQueue.
  window.googlefc.callbackQueue.push({
    'CONSENT_DATA_READY':
    () => __gpp('ping', (data, success) => {
        // Do something with consent data value.
    })
  });
</script>

IAB GPP フレームワークの下で Google の同意管理ソリューションを使用して米国の州の規制のオプトアウト メッセージをエンドユーザーに提供している場合は、googlefc.usstatesoptout.overrideDnsLink フラグを true に設定することで、独自のカスタムの「販売または共有しない」リンクを提供できます。

<script>
  // Make sure that the properties exist on the window.
  window.googlefc = window.googlefc || {};
  window.googlefc.usstatesoptout = window.googlefc.usstatesoptout || {};
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

  // Signals that the default DNS link will be overridden.
  window.googlefc.usstatesoptout.overrideDnsLink = true;

  // Register the callback for the initial US state regulations data.
  window.googlefc.callbackQueue.push({
      'INITIAL_US_STATES_OPT_OUT_DATA_READY': () => {
        if (googlefc.usstatesoptout.getInitialUsStatesOptOutStatus() ===
            googlefc.usstatesoptout.InitialUsStatesOptOutStatusEnum.NOT_OPTED_OUT) {
          // TODO: Display custom Do Not Sell or Share link here.
        }
      }
    });
</script>

これにより、デフォルトの「販売または共有しない」リンクがレンダリングされなくなります。次に、米国の州規制のオプトアウト確認ダイアログを呼び出して、カスタムの「販売、共有しない」リンクに関するユーザーの操作を処理する必要があります。

独自のカスタムの「販売、共有しない」リンクを使用する場合は、リンクが米国の州規制に準拠していることを確認する責任があります。

<script>
// This callback will be called when the user makes a US state regulations
// decision.
const usStateRegCompletionCallback = (userOptedOut) => {
  if (userOptedOut) {
    // TODO: Hide custom Do Not Sell or Share link here.
  }
}
// Invoke the US state regulations opt-out confirmation dialog when the user
// clicks the link.
document.getElementById("your-custom-do-not-sell-link").addEventListener(
  "click", () => googlefc.usstatesoptout.openConfirmationDialog(usStateRegCompletionCallback));
</script>