ความเป็นส่วนตัวและการรับส่งข้อความ JavaScript API

บทนำ

API นี้มีเครื่องมือสำหรับโต้ตอบกับข้อความที่แท็บความเป็นส่วนตัวและการแสดงข้อความแจ้งผู้ใช้เสนอ ซึ่งช่วยให้คุณทำสิ่งต่อไปนี้ได้

และอื่นๆ

นอกจากนี้ คุณยังใช้เครื่องมือเหล่านี้เพื่อรวบรวมความยินยอมของผู้ใช้โดยใช้โปรโตคอลมาตรฐานอุตสาหกรรม ได้ด้วย

ในกรณีเหล่านี้ ระบบจะแจ้งสถานะความยินยอมผ่าน API เหล่านั้น

คุณสามารถติดตั้งใช้งานฟังก์ชันการรับส่งข้อความกับผู้ใช้ในเว็บไซต์ได้ 2 วิธี ดังนี้

  1. ในกรณีส่วนใหญ่ คุณไม่จำเป็นต้องติดแท็กใหม่เลย แท็กผู้เผยแพร่โฆษณาผ่าน Google หรือแท็ก AdSense ที่มีอยู่จะแสดงข้อความสำหรับผู้ใช้เมื่อเผยแพร่ข้อความในผลิตภัณฑ์ที่เกี่ยวข้อง
  2. หากใช้ข้อความการกู้คืนรายได้จากการบล็อกโฆษณา คุณต้องเพิ่มแท็กการบล็อกโฆษณาลงในหน้าเว็บอย่างชัดเจน ดูข้อมูลเพิ่มเติมได้ที่วิธีการติดแท็ก Ad Manager และ AdSense

googlefc คือเนมสเปซส่วนกลางที่ฟังก์ชันการรับส่งข้อความของผู้ใช้ใช้ สำหรับ API ใน JavaScript Window

สรุปฟิลด์

ชื่อ ประเภท คำจำกัดความ
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 ที่มีค่าโหมดความยินยอมปัจจุบันสำหรับผู้ใช้ โดยมีค่าหนึ่งสำหรับวัตถุประสงค์ของโหมดความยินยอมที่มีอยู่แต่ละรายการ
googlefc.ccpa.getInitialCcpaStatus()

รุ่นเดิม ต้องการ googlefc.usstatesoptout.getInitialUsStatesOptOutStatus()
ตัวเลข แสดงค่าใน InitialCcpaStatusEnum โดยขึ้นอยู่กับสถานะการเลือกไม่ใช้กฎระเบียบของรัฐในสหรัฐอเมริกาเริ่มต้นของผู้ใช้
googlefc.ccpa.openConfirmationDialog(function(boolean))

รุ่นเดิม ต้องการ googlefc.usstatesoptout.openConfirmationDialog()
ไม่ได้กำหนด เปิดกล่องโต้ตอบการยืนยันการเลือกไม่ใช้กฎระเบียบของรัฐในสหรัฐอเมริกา หากมีการลบล้างลิงก์ "ไม่อนุญาตให้ขายหรือแชร์" เริ่มต้น

การทดสอบและการแก้ไขข้อบกพร่องในเว็บไซต์

เครื่องมือความเป็นส่วนตัวและการแสดงข้อความแจ้งผู้ใช้มีฟังก์ชันการแก้ไขข้อบกพร่องและการทดสอบที่ช่วยให้คุณ ดูว่าข้อความเฉพาะเจาะจง ประเภทข้อความย่อย หรือชุดข้อความ มีลักษณะอย่างไรในเว็บไซต์จริง

สิ่งที่ต้องมีก่อน

  • คุณต้องเผยแพร่ข้อความที่ต้องการแสดงตัวอย่างในเว็บไซต์ที่คุณ ใช้ทดสอบ

คุณดูตัวอย่างแบบเรียลไทม์ในเว็บไซต์ได้โดยใช้พารามิเตอร์ URL การแก้ไขข้อบกพร่องต่อไปนี้

พารามิเตอร์การแก้ไขข้อบกพร่อง ค่าที่อนุญาต
fc alwaysshow (เพื่อเรียกใช้โหมดแก้ไขข้อบกพร่อง/แสดงตัวอย่าง)
fctype ab (ข้อความแจ้งว่ามีการบล็อกโฆษณา), ccpa (ข้อความแสดงการไม่ให้ความยินยอมตามกฎระเบียบของรัฐในสหรัฐอเมริกา), gdpr (ข้อความขอความยินยอมตาม GDPR), monetization (ข้อความ Offerwall), usfl (ข้อความแสดงการไม่ให้ความยินยอมตามกฎระเบียบของรัฐในสหรัฐอเมริกา เฉพาะฟลอริดา), usnat (ข้อความแสดงการไม่ให้ความยินยอมตามกฎระเบียบของรัฐในสหรัฐอเมริกา รัฐที่รองรับทั้งหมด ยกเว้นฟลอริดา เทียบเท่ากับ ccpa)

ตัวอย่างวิธีใช้เพื่อดูตัวอย่างในเว็บไซต์ (foo.com) มีดังนี้

  • ทดสอบการแสดงข้อความไม่ให้ความยินยอมตามกฎระเบียบของรัฐในสหรัฐอเมริกา -- http://foo.com/?fc=alwaysshow&fctype=ccpa
  • ทดสอบการแสดงข้อความ GDPR -- http://foo.com/?fc=alwaysshow&fctype=gdpr

ฟิลด์: คำอธิบายและตัวอย่าง

googlefc.controlledMessagingFunction {function(!Object)}

ฟังก์ชันที่กำหนดว่าควรแสดงข้อความหรือไม่ โดยใช้เพื่อควบคุมการแสดงข้อความตามเงื่อนไขที่ผู้เผยแพร่โฆษณาระบุ เช่น สถานะสมาชิกหรือ URL ของหน้าเว็บ ได้

เมื่อคุณกำหนด googlefc.controlledMessagingFunction ใน Window ก่อนที่สคริปต์อื่นๆ จะโหลด ข้อความจะไม่แสดงจนกว่าคุณจะเรียกใช้ message.proceed(boolean) การเรียกใช้ message.proceed(true) จะช่วยให้การรับส่งข้อความ ดำเนินต่อไปได้ตามปกติ ในขณะที่การเรียกใช้ message.proceed(false) จะป้องกันไม่ให้ข้อความ ใดๆ แสดงสำหรับการดูหน้าเว็บ

ตัวอย่าง: สมมติว่าคุณมีสคริปต์นี้ในหน้าเว็บซึ่งกำหนดฟังก์ชัน async function 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>

นอกจากนี้ ยังมีส่วนขยายของฟีเจอร์นี้ที่ช่วยให้ผู้เผยแพร่โฆษณาระบุได้ว่า ควรระงับเฉพาะ Offerwall เท่านั้น ใช้ส่วนขยายฟีเจอร์นี้เพื่อ ระงับ Offerwall โดยไม่ระงับข้อความประเภทอื่นๆ

การรับส่งข้อความที่ควบคุมเฉพาะ Offerwall จะทำได้โดยการส่งพารามิเตอร์เพิ่มเติมไปยัง message.proceed() ซึ่งเป็น Array ประเภท googlefc.MessageTypeEnum

ตัวอย่าง: นี่คือตัวอย่างการใช้ 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 ที่เพิ่มในภายหลังจะเป็นแบบซิงโครนัส สูง
CONSENT_MODE_DATA_READY ฟังก์ชันที่ส่งไปยังคิวการเรียกกลับด้วยคีย์ CONSENT_MODE_DATA_READY จะทํางานเมื่อข้อมูล[โหมดความยินยอม](https://support.google.com/google-ads/answer/10000067) ของ Google (สําหรับใช้กับแท็ก Google Ads และ Analytics) พร้อมใช้งานในโฟลว์ เมื่อข้อมูลโหมดความยินยอมพร้อมใช้งานแล้ว คุณจะเข้าถึงค่าโหมดความยินยอมได้ทุกเมื่อโดยใช้ 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

ฟังก์ชันที่ส่งไปยังคิว Callback ด้วยคีย์ INITIAL_CCPA_DATA_READY จะได้รับการดำเนินการเมื่อข้อมูลกฎระเบียบของรัฐในสหรัฐอเมริกาพร้อมใช้งานในโฟลว์ โปรดทราบว่าคำขอข้อมูลกฎระเบียบของรัฐในสหรัฐอเมริกาในภายหลังควรได้รับโดยการเรียกใช้ GPP API (__gpp) โดยตรง
ปานกลาง

googlefc.CallbackQueue {!Object}

สรุปวิธีการ

ชื่อ ประเภท พารามิเตอร์ ประเภทการแสดงผล บทบาท
push(data) ตัวเลข data: คู่คีย์-ค่าที่มีคีย์เป็นประเภทความพร้อมใช้งานของข้อมูลอย่างใดอย่างหนึ่ง และค่าเป็นฟังก์ชัน JavaScript ที่จะเรียกใช้ คีย์ความพร้อมใช้งานของข้อมูลที่ยอมรับได้คือ CONSENT_API_READY, CONSENT_DATA_READY, AD_BLOCK_DATA_READY, INITIAL_US_STATES_OPT_OUT_DATA_READY, CONSENT_MODE_DATA_READY และ (เดิม) INITIAL_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;
}

ค่าของแต่ละฟิลด์คือตัวเลขที่สอดคล้องกับค่า enum ของ 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}

ตั้งค่าฟิลด์นี้เป็น "จริง" เพื่อซ่อนลิงก์ "ห้ามขายหรือแชร์" เริ่มต้น และใช้ลิงก์ "ห้ามขายหรือแชร์" ที่กำหนดเองของคุณเอง

ตัวอย่าง

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

ตั้งค่าฟิลด์นี้เป็น "จริง" เพื่อซ่อนลิงก์ "ห้ามขายหรือแชร์" เริ่มต้น และใช้ลิงก์ "ห้ามขายหรือแชร์" ที่กำหนดเองของคุณเอง โปรดทราบว่าหากตั้งค่าฟิลด์นี้เป็น "จริง" คุณมีหน้าที่รับผิดชอบในการแสดงลิงก์ "ห้ามขายหรือแชร์" ในเว็บไซต์ ควรใช้ช่องนี้ร่วมกับ 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}

ล้างระเบียนความยินยอมตามกฎระเบียบของสหภาพยุโรปปัจจุบัน (หากมี) และแสดงข้อความเกี่ยวกับกฎระเบียบของสหภาพยุโรปอีกครั้งเพื่อให้ผู้ใช้เปลี่ยนการตัดสินใจให้ความยินยอมได้

ตัวอย่างที่ 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 มีผลกับผู้ใช้ปัจจุบันเท่านั้น คุณสามารถใช้คิวการเรียกกลับ googlefc กับ TCF API เพื่ออัปเดตการแสดงปุ่มแบบมีเงื่อนไขตามค่า gdprApplies เมื่อกำหนดแล้ว โดยใช้คีย์ API CONSENT_API_READY

<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 ที่มีค่าปัจจุบันของวัตถุประสงค์แต่ละข้อในโหมดความยินยอม โดยอิงตาม การตัดสินใจให้ความยินยอมของผู้ใช้

ดูการใช้งานที่ต้องการได้ที่การใช้โซลูชันการจัดการความยินยอมของ Google ที่รองรับโหมดความยินยอมสำหรับกฎระเบียบของ EU


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>

หากคุณใช้โซลูชันการจัดการความยินยอมของ Google เพื่อรวบรวมความยินยอมตาม GDPR ภายใต้กรอบ TCF เวอร์ชัน 2 ของ IAB คุณควรใช้ API ของ TCF เวอร์ชัน 2 ของ IAB

คุณใช้คีย์คิวการเรียกกลับ CONSENT_API_READY เพื่อตรวจสอบว่ามีการเรียกใช้การเรียกกลับที่เกี่ยวข้องเฉพาะเมื่อ มีการกำหนด API ของ TCF เวอร์ชัน 2 ของ IAB ในหน้าเว็บเท่านั้น ควรใช้ร่วมกับคำสั่ง 'addEventListener' ของ API TCF เวอร์ชัน 2 ของ IAB

ตัวอย่าง

<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 เพื่อให้แน่ใจว่าระบบจะเรียกใช้การเรียกกลับที่เกี่ยวข้อง เมื่อรวบรวมความยินยอมของผู้ใช้และเข้าถึงได้โดยใช้ API ของ TCF เวอร์ชัน 2 ของ IAB เท่านั้น คำสั่งนี้ใช้ร่วมกับคำสั่ง 'addEventListener' ได้ โดยข้อมูลที่ระบุในการเรียกกลับครั้งแรกที่คุณระบุ จะมีตัวเลือกความยินยอมของผู้ใช้ (ตราบใดที่ TCF เวอร์ชัน 2 มีผลกับผู้ใช้รายนี้) โปรดทราบว่าเมื่อเปิดตัว TCF เวอร์ชัน 2.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 Ads และ Analytics คุณควรปรึกษาฝ่ายกฎหมายเกี่ยวกับโหมดความยินยอมที่จะใช้ เพื่อให้เป็นไปตามข้อกำหนดทางกฎหมาย

ระบบรองรับโหมดความยินยอมขั้นสูงโดยค่าเริ่มต้น เมื่อเปิดใช้โหมดความยินยอมใน UI ของความเป็นส่วนตัวและการแสดงข้อความแจ้งผู้ใช้แล้ว คุณก็ไม่ต้องดำเนินการใดๆ เพิ่มเติม

หากต้องการใช้โหมดความยินยอมพื้นฐานโดยใช้โซลูชันการจัดการความยินยอมของ Google คุณสามารถใช้CONSENT_MODE_DATA_READYคีย์คิวการเรียกกลับเพื่อโหลดแท็ก Google Ads และ Analytics แบบมีเงื่อนไข เมื่อมีข้อมูลโหมดความยินยอม ข้อมูลโหมดความยินยอมจะพร้อมใช้งานหลังจากที่ Funding Choices ระบุว่าโหมดความยินยอมไม่มีผลกับคำขอนี้ (เช่น เนื่องจากกฎระเบียบของ 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 นี้จะแสดงออบเจ็กต์ GoogleFcConsentModeUserStatus ที่มีฟิลด์ 1 รายการ สำหรับวัตถุประสงค์ของโหมดความยินยอมที่รองรับแต่ละรายการ และค่า ของแต่ละฟิลด์คือค่า Enum ที่ระบุค่าของวัตถุประสงค์ของโหมดความยินยอมนั้น

เช่น คุณสามารถใช้ googlefc.getGoogleConsentModeValues() เพื่อเลิกบล็อกแท็ก Google Ads และ Analytics ได้ก็ต่อเมื่อมีกรณีใดกรณีหนึ่งต่อไปนี้

  • ผู้ใช้ปลายทางตัดสินใจให้ความยินยอมตามกฎระเบียบของ 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>

หากคุณใช้โซลูชันการจัดการความยินยอมของ Google เพื่อแสดงข้อความเลือกไม่รับกฎระเบียบของรัฐในสหรัฐอเมริกาต่อผู้ใช้ปลายทางภายใต้เฟรมเวิร์ก GPP ของ IAB คุณควรใช้ IAB GPP API

เนื่องจากลักษณะการเลือกไม่ใช้ของกฎระเบียบของรัฐในสหรัฐอเมริกา คุณอาจใช้คีย์คิว CONSENT_API_READY หรือ CONSENT_DATA_READYการเรียกกลับ เพื่อให้แน่ใจว่าเรียกใช้ API ของ GPP ของ IAB ได้และส่งคืนข้อมูลความยินยอม ในเวลาที่เรียกใช้การเรียกกลับ

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

หากคุณใช้โซลูชันการจัดการความยินยอมของ Google เพื่อแสดงข้อความเลือกไม่รับตามกฎระเบียบของรัฐในสหรัฐอเมริกาต่อผู้ใช้ปลายทางภายใต้เฟรมเวิร์ก GPP ของ IAB คุณสามารถระบุลิงก์ "ห้ามขายหรือแชร์" ที่กำหนดเองได้โดยตั้งค่าแฟล็ก 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>