プライバシーと Messaging JavaScript API

はじめに

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

  • 特定のユーザーのメッセージを非表示にする
  • ユーザーの広告ブロック ステータスをクエリする
  • ユーザーが同意を取り消すことを許可する(該当する場合)

これらのツールを使用して、業界標準に従ってユーザーの同意を取得することもできます。 機能:

その場合、同意ステータスはこれらの API を介して通知されます。

このユーザー メッセージ機能をサイトに導入するには、いくつかの方法があります。 方法:

  1. ほとんどの場合、タグを再設定する必要はありません。既存の Google 出版社 タグまたは AdSense タグのデプロイ 関連プロダクトでメッセージがパブリッシュされると、ユーザーにメッセージが送信されます。
  2. 広告ブロックによる損失収益の回復メッセージを使用している場合は、広告の 追加することをおすすめします広告 Manager および AdSense のタグ設定 手順をご覧ください。

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

<ph type="x-smartling-placeholder">

フィールドの概要

名前 タイプ 定義
googlefc.controlledMessagingFunction function(!Object) メッセージを続行するかどうかを決定する関数。この機能は、すべてのメッセージ タイプでサポートされています。
googlefc.callbackQueue !Array<!Object<文字列, function()>>|!Array&lt;function()&gt;|!googlefc.CallbackQueue ユーザー メッセージング クエリを非同期で実行するためのコールバック キューへの参照。
googlefc.CallbackQueue !Object コールバック キュー オブジェクトの型。
googlefc.AdBlockerStatusEnum !Object<文字列、数値> ユーザーの広告ブロッカーの状態を表す列挙型。
googlefc.AllowAdsStatusEnum !Object<文字列、数値> ユーザーの広告許可の状態を表す列挙型。
googlefc.ccpa.InitialCcpaStatusEnum !Object<文字列、数値> ユーザーの初期 CPRA ステータスを表す列挙型。
googlefc.ccpa.overrideDnsLink 未定義|ブール値 カスタムの「販売拒否」リンクを使用するには、true に設定するブール値。

メソッドの概要

名前 戻り値の型 定義
googlefc.showRevocationMessage() 未定義 同意レコードを消去し、googlefc スクリプトを再読み込みして、ユーザーに適した同意メッセージを表示します。
googlefc.getAdBlockerStatus() 数値 ユーザーの広告ブロック ステータスに応じて AdBlockerStatusEnum の値を返します。
googlefc.getAllowAdsStatus() 数値 ユーザーの広告許可ステータスに応じて AllowAdsStatusEnum の値を返します。
googlefc.ccpa.getInitialCcpaStatus() 数値 ユーザーの初期 CPRA ステータスに応じて、InitialCcpaStatusEnum に値を返します。
googlefc.ccpa.openConfirmationDialog(function(boolean)) 未定義 デフォルトの [販売しない] リンクがオーバーライドされている場合に、CPRA の確認ダイアログが開きます。

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

プライバシーとメッセージングには、デバッグやテストの機能を使用して 特定のメッセージ(またはメッセージの組み合わせ)が 表示されます。

前提条件:

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

次のデバッグ用 URL を使用すると、サイトでライブ プレビューを表示できます parameters:

デバッグ パラメータ 使用できる値
fc alwaysshow(デバッグ/プレビュー モードをトリガーするため)
fctype ab(広告ブロック メッセージ)、ccpa(CPRA オプトアウト メッセージ)、gdpr(GDPR 同意メッセージ)、monetization(Offerwall メッセージ)

サイト(foo.com)でのプレビューに使用する方法の例:

  • CPRA メッセージのテスト -- http://foo.com/?fc=alwaysshow&fctype=ccpa
  • GDPR メッセージのテスト -- http://foo.com/?fc=alwaysshow&fctype=gdpr
で確認できます。 <ph type="x-smartling-placeholder">

フィールド: 説明と例

googlefc.controlledMessagingFunction {function(!Object)}

メッセージを表示するかどうかを決定する関数。かもしれない などのパブリッシャー指定の条件でのメッセージ レンダリングを制御するために使用します。 購読者のステータスや ページの URL などです

次の日付より前にウィンドウで 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>

これは、Google Cloud Storage バケットを 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>

この機能を拡張して Offerwall のクローズド ベータ版で、Offerwall のみを表示するよう指定 抑えられます。他のメッセージ タイプは、この機能を有効にしても影響を受けません。

Offerwall 固有の制御メッセージを利用するには、追加の message.proceed()googlefc.MessageTypeEnum 型の Array)にパラメータを追加します。

例: これは、googlefc.controlledMessagingFunction を使用して以下を行う例です。 購読者への Offerwall の配信のみを抑制し、他の購読は抑制しません。 メッセージ タイプ:

<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 キー付きの関数の実行は同期します。
INITIAL_CCPA_DATA_READY INITIAL_CCPA_DATA_READY とともにコールバック キューにプッシュされた関数は、フローで CPRA データが利用可能になると実行されます。なお、CPRA データの後続のリクエストは、US Privacy API(__uspapi)を直接呼び出して取得する必要があります。

googlefc.CallbackQueue {!Object}

メソッドの概要:

名前 タイプ パラメータ 戻り値の型 ロール
push(data) 数値 data: キーがデータの 1 つである Key-Value ペア 実行する JavaScript 関数としての値。 使用できるデータ可用性キーは CONSENT_API_READY です。 CONSENT_DATA_READYAD_BLOCK_DATA_READYINITIAL_CCPA_DATA_READY これまでに追加されたコマンドの数。配列の現在の長さを返します。 渡された関数を、データが取り込まれた順序で 追加された順に並べて 表示されます。

例:

<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({
    '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.ccpa.InitialCcpaStatusEnum{!Object<string, number>}

広告ブロックにおけるユーザーのさまざまな広告許可ステータスを表します。異なる 次のとおりです。

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

googlefc.ccpa.overrideDnsLink{undefined|boolean}

デフォルトの [販売しない] リンクを非表示にして カスタム [販売しない]リンクを選択します

例:

<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}

現在の同意レコードを消去し、同意メッセージを表示します。 表示されます。この関数に指定する必要があるキーは、 CONSENT_DATA_READY

例:

<button type="button" onclick="googlefc.callbackQueue.push({'CONSENT_DATA_READY': () => googlefc.showRevocationMessage()});">
  Click here to revoke
</button>

googlefc.getAdBlockerStatus(): {number}

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

例:

<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({
    '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.ccpa = window.googlefc.ccpa || {}
  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.ccpa.getInitialCcpaStatus(): {number}

次の CPRA ステータスに応じて、InitialCcpaStatusEnum で値を返します。 できます。この関数に指定する必要があるキーは、 INITIAL_CCPA_DATA_READY。なお、後続の CPRA データ リクエストでは、 US Privacy API(__uspapi)を直接呼び出して取得できます。

例:

<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 the user is not CPRA eligible.
          break;
        case googlefc.ccpa.InitialCcpaStatusEnum.NOT_OPTED_OUT:
          // Insert handling for cases where the user is CPRA eligible and has
          // not opted out.
          break;
        case googlefc.ccpa.InitialCcpaStatusEnum.OPTED_OUT:
          // Insert handling for cases where the user is CPRA eligible and has
          // opted out.
          break;
      }
    }
  });
</script>

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

デフォルトの [販売しない] リンクが オーバーライドされます。ユーザーが確認ダイアログを操作すると、提供された ユーザーがオプトアウトすると、true とともにコールバック関数が呼び出されます。また、 そうでない場合は false

例:

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

Google の同意管理ソリューションを使用して GDPR 同意を収集している場合 IAB TCF v2 フレームワークに基づく API

CONSENT_API_READY を使用できます。 コールバック キューのキーを使用して、対応するコールバックが ページで 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' command - 指定されたコールバックの初回呼び出しで提供されたデータ にユーザーの同意に関する選択内容が含まれる(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>

CPRA 向けの IAB GPP フレームワークで Google の同意管理ソリューションを使用する

Google の同意管理ソリューションを使用して CPRA のオプトアウトを収集している場合 IAB GPP フレームワークでは、IAB GPP API

CPRA 規則のオプトアウトの性質上、 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.ccpa = window.googlefc.ccpa || {}
  window.googlefc.callbackQueue = window.googlefc.callbackQueue || [];

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

CPRA 向けの IAB GPP フレームワークで Google の同意管理ソリューションを使用し、[販売禁止] のカスタムリンクを設定する

Google の同意管理ソリューションを使用して CPRA のオプトアウトを収集している場合 IAB GPP フレームワークでは、カスタムの「販売拒否」リンクを提供できる googlefc.ccpa.overrideDnsLink フラグを true に設定します。

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

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

  // Register the callback for the initial CPRA data.
  window.googlefc.callbackQueue.push({
      'INITIAL_CCPA_DATA_READY': () => {
        if (googlefc.ccpa.getInitialCcpaStatus() ===
            googlefc.ccpa.InitialCcpaStatusEnum.NOT_OPTED_OUT) {
          // TODO: Display custom CPRA Do Not Sell link here.
        }
      }
    });
</script>

これにより、デフォルトの [販売しない] リンクは表示されません。なお、 独自の「販売しない」リンクをレンダリングし、ポリシーを遵守する 組み合わせたものです次に、カスタマイズした Do Not ユーザー インタラクションを処理し、 販売リンクは、CPRA の確認ダイアログで呼び出します。

<script>
// This callback will be called with the user CPRA decision.
const ccpaCompletionCallback = (userOptedOut) => {
  if (userOptedOut) {
    // TODO: Hide custom CPRA Do Not Sell link here.
  }
}
// Invoke the CPRA confirmation dialog when the user clicks the link.
document.getElementById("your-custom-ccpa-do-not-sell-link").addEventListener(
  "click", () => googlefc.ccpa.openConfirmationDialog(ccpaCompletionCallback));
</script>