ข้อมูลอ้างอิงเกี่ยวกับ GPT

ข้อมูลอ้างอิงนี้ใช้การเขียนสัญกรณ์ TypeScript เพื่ออธิบายประเภท ตารางต่อไปนี้แสดงคำอธิบายโดยย่อพร้อมตัวอย่าง

พิมพ์นิพจน์
string ประเภทสตริงพื้นฐาน
string[] ประเภทอาร์เรย์ที่ค่าต้องเป็นสตริงเท่านั้น
number | string ประเภทยูเนียน ซึ่งค่าอาจเป็นตัวเลขหรือสตริงก็ได้
Array<number | string> ประเภทอาร์เรย์ที่ค่าเป็นประเภทคอมเพล็กซ์ (ยูเนียน)
[number, string] ประเภททูเปิล โดยค่าจะเป็นอาร์เรย์ 2 องค์ประกอบที่ต้องมีตัวเลขและสตริงตามลําดับนั้น
Slot ประเภทออบเจ็กต์ซึ่งมีค่าเป็นอินสแตนซ์ของ googletag.Slot
() => void ประเภทฟังก์ชันที่ไม่มีอาร์กิวเมนต์ที่กําหนดไว้และไม่มีค่าส่งคืน

ดูข้อมูลเพิ่มเติมเกี่ยวกับประเภทและนิพจน์ประเภทที่รองรับได้ที่ คู่มือ TypeScript

คำอธิบายประกอบประเภท

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

คำอธิบายประกอบประเภท
param: string บ่งบอกว่า param ยอมรับหรือแสดงผลค่าสตริง ไวยากรณ์นี้ใช้สำหรับตัวแปร พารามิเตอร์ พร็อพเพอร์ตี้ และประเภทผลลัพธ์
param?: number | string ระบุว่า param ไม่บังคับ แต่ยอมรับตัวเลขหรือสตริงเมื่อระบุ ไวยากรณ์นี้ใช้สำหรับพารามิเตอร์และพร็อพเพอร์ตี้
...params: Array<() => void> ระบุว่า params เป็น พารามิเตอร์ Rest ที่ยอมรับฟังก์ชัน พารามิเตอร์ Rest จะยอมรับค่าประเภทที่ระบุได้ไม่จํากัด

googletag

เนมสเปซส่วนกลางที่แท็กผู้เผยแพร่โฆษณาผ่าน Google ใช้สำหรับ API
เนมสเปซ
config
อินเทอร์เฟซการกําหนดค่าหลักสําหรับการตั้งค่าระดับหน้า
enums
นี่คือเนมสเปซที่ GPT ใช้สำหรับประเภท Enum
events
ซึ่งเป็นเนมสเปซที่ GPT ใช้สำหรับเหตุการณ์
secureSignals
ซึ่งเป็นเนมสเปซที่ GPT ใช้สำหรับจัดการสัญญาณที่ปลอดภัย
อินเทอร์เฟซ
CommandArray
อาร์เรย์คําสั่งจะยอมรับลําดับของฟังก์ชันและเรียกใช้ตามลําดับ
CompanionAdsService
บริการโฆษณาที่แสดงร่วม
PrivacySettingsConfig
ออบเจ็กต์การกําหนดค่าสําหรับการตั้งค่าความเป็นส่วนตัว
PubAdsService
บริการโฆษณาของผู้เผยแพร่โฆษณา
ResponseInformation
ออบเจ็กต์ที่แสดงการตอบกลับโฆษณารายการเดียว
RewardedPayload
ออบเจ็กต์ที่แสดงรางวัลที่เชื่อมโยงกับโฆษณาที่มีการให้รางวัล
SafeFrameConfig
ออบเจ็กต์การกําหนดค่าสําหรับคอนเทนเนอร์ SafeFrame
Service
คลาสบริการพื้นฐานที่มีเมธอดที่ใช้ร่วมกันสำหรับบริการทั้งหมด
SizeMappingBuilder
ตัวสร้างสำหรับออบเจ็กต์ข้อกำหนดการแมปขนาด
Slot
ช่องคือออบเจ็กต์ที่แสดงช่องโฆษณาเดียวในหน้าเว็บ
ประเภทอีเมลแทน
GeneralSize
การกําหนดค่าขนาดที่ถูกต้องสําหรับช่อง ซึ่งอาจเป็นขนาดเดียวหรือหลายขนาดก็ได้
MultiSize
รายการขนาดเดียวที่ใช้ได้
NamedSize
ขนาดที่ตั้งชื่อซึ่งช่องมีได้
SingleSize
ขนาดเดียวที่ใช้ได้สำหรับช่วงเวลา
SingleSizeArray
อาร์เรย์ของตัวเลข 2 รายการที่แสดงถึง [width, height]
SizeMapping
การแมปขนาดวิวพอร์ตกับขนาดโฆษณา
SizeMappingArray
รายการการแมปขนาด
ตัวแปร
apiReady
การแจ้งที่ระบุว่า GPT API โหลดแล้วและพร้อมเรียกใช้
cmd
การอ้างอิงคิวคําสั่งส่วนกลางสําหรับการเรียกใช้ที่เกี่ยวข้องกับ GPT แบบไม่พร้อมกัน
pubadsReady
การแจ้งที่ระบุว่า PubAdsService เปิดใช้ โหลด และทํางานได้อย่างสมบูรณ์
secureSignalProviders
การอ้างอิงอาร์เรย์ผู้ให้บริการสัญญาณที่ปลอดภัย
ฟังก์ชัน
companionAds
แสดงการอ้างอิงถึง CompanionAdsService
defineOutOfPageSlot
สร้างช่องโฆษณาที่ไม่อยู่ในขอบเขตหน้าด้วยเส้นทางหน่วยโฆษณาที่ระบุ
defineSlot
สร้างช่องโฆษณาที่มีเส้นทางและขนาดหน่วยโฆษณาที่ระบุ และเชื่อมโยงกับรหัสขององค์ประกอบ div ในหน้าเว็บที่จะแสดงโฆษณา
destroySlots
ทำลายช่องที่ระบุ โดยนําออบเจ็กต์และการอ้างอิงทั้งหมดที่เกี่ยวข้องกับช่องเหล่านั้นออกจาก GPT
disablePublisherConsole
ปิดใช้คอนโซลผู้เผยแพร่โฆษณาของ Google
display
สั่งให้บริการสล็อตแสดงผลสล็อต
enableServices
เปิดใช้บริการ GPT ทั้งหมดที่กําหนดไว้สําหรับช่องโฆษณาในหน้า
getVersion
แสดงผล GPT เวอร์ชันปัจจุบัน
openConsole
เปิดคอนโซลผู้เผยแพร่โฆษณาของ Google
pubads
แสดงผลข้อมูลอ้างอิงถึง PubAdsService
setAdIframeTitle
ตั้งค่าชื่อสําหรับ iframe ของคอนเทนเนอร์โฆษณาทั้งหมดที่สร้างโดย PubAdsService นับจากนี้เป็นต้นไป
setConfig
ตั้งค่าตัวเลือกการกําหนดค่าทั่วไปสําหรับหน้าเว็บ
sizeMapping
สร้าง SizeMappingBuilder ใหม่

ประเภทอีเมลแทน


GeneralSize

GeneralSize: SingleSize | MultiSize
การกําหนดค่าขนาดที่ถูกต้องสําหรับช่อง ซึ่งอาจเป็นขนาดเดียวหรือหลายขนาดก็ได้

MultiSize

MultiSize: SingleSize[]
รายการขนาดเดียวที่ใช้ได้

NamedSize

NamedSize: "fluid" | ["fluid"]
ขนาดที่ตั้งชื่อซึ่งช่องมีได้ ในกรณีส่วนใหญ่ ขนาดจะเป็นสี่เหลี่ยมผืนผ้าขนาดคงที่ แต่ในบางกรณี เราอาจต้องใช้ข้อกำหนดขนาดประเภทอื่นๆ เฉพาะขนาดที่มีชื่อต่อไปนี้เท่านั้นที่ถูกต้อง
  • แบบยืดหยุ่น: คอนเทนเนอร์โฆษณาใช้ความกว้าง 100% ของ div หลัก จากนั้นปรับขนาดความสูงให้พอดีกับเนื้อหาครีเอทีฟโฆษณา คล้ายกับลักษณะการทํางานขององค์ประกอบบล็อกปกติในหน้าเว็บ ใช้สำหรับโฆษณาเนทีฟ (ดูบทความที่เกี่ยวข้อง) โปรดทราบว่าทั้ง fluid และ ['fluid'] เป็นรูปแบบที่ยอมรับได้ในการประกาศขนาดช่องเป็นแบบปรับขนาดได้

SingleSize

ขนาดเดียวที่ใช้ได้สำหรับช่วงเวลา

SingleSizeArray

SingleSizeArray: [number, number]
อาร์เรย์ของตัวเลข 2 รายการที่แสดงถึง [width, height]

SizeMapping

การแมปขนาดวิวพอร์ตกับขนาดโฆษณา ใช้สำหรับโฆษณาที่ปรับเปลี่ยนตามพื้นที่โฆษณา

SizeMappingArray

SizeMappingArray: SizeMapping[]
รายการการแมปขนาด

ตัวแปร


Const apiReady

apiReady: boolean | undefined
การแจ้งที่ระบุว่า GPT API โหลดแล้วและพร้อมเรียกใช้ พร็อพเพอร์ตี้นี้จะมีค่าเป็น undefined จนกระทั่ง API พร้อมใช้งาน

โปรดทราบว่าวิธีจัดการแบบแอซิงค์ที่แนะนําคือการใช้ googletag.cmd เพื่อจัดคิวการเรียกกลับเมื่อ GPT พร้อมใช้งาน โค้ดเรียกกลับเหล่านี้ไม่จําเป็นต้องตรวจสอบ googletag.apiReady เนื่องจากระบบรับประกันว่าจะเรียกใช้เมื่อตั้งค่า API แล้ว

Const cmd

cmd: ((this: typeof globalThis) => void)[] | CommandArray
การอ้างอิงคิวคําสั่งส่วนกลางสําหรับการเรียกใช้ที่เกี่ยวข้องกับ GPT แบบไม่พร้อมกัน

ตัวแปร googletag.cmd จะเริ่มต้นเป็นอาร์เรย์ JavaScript ว่างโดยไวยากรณ์แท็ก GPT ในหน้าเว็บ และ cmd.push คือเมธอด Array.push มาตรฐานที่เพิ่มองค์ประกอบลงท้ายอาร์เรย์ เมื่อโหลด JavaScript ของ GPT ระบบจะเรียกใช้อาร์เรย์และดำเนินการฟังก์ชันทั้งหมดตามลำดับ จากนั้นสคริปต์จะแทนที่ cmd ด้วยออบเจ็กต์ CommandArray ที่มีการกำหนดเมธอด push เพื่อเรียกใช้อาร์กิวเมนต์ฟังก์ชันที่ส่งผ่าน กลไกนี้ช่วยให้ GPT ลดเวลาในการตอบสนองที่รับรู้ได้โดยดึงข้อมูล JavaScript แบบอะซิงโครนัสขณะที่อนุญาตให้เบราว์เซอร์แสดงผลหน้าเว็บต่อไป
ตัวอย่าง

JavaScript

googletag.cmd.push(() => {
  googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads());
});

JavaScript (เดิม)

googletag.cmd.push(function () {
  googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads());
});

TypeScript

googletag.cmd.push(() => {
  googletag.defineSlot("/1234567/sports", [160, 600])!.addService(googletag.pubads());
});

Const pubadsReady

pubadsReady: boolean | undefined
การแจ้งที่ระบุว่า PubAdsService เปิดใช้ โหลด และทํางานได้อย่างสมบูรณ์ พร็อพเพอร์ตี้นี้จะมีค่าเป็น undefined เท่านั้นจนกว่าจะมีการเรียกใช้ enableServices และโหลดและเริ่มต้น PubAdsService

secureSignalProviders

secureSignalProviders: SecureSignalProvider[] | SecureSignalProvidersArray | undefined
การอ้างอิงอาร์เรย์ผู้ให้บริการสัญญาณที่ปลอดภัย

อาร์เรย์ผู้ให้บริการสัญญาณที่ปลอดภัยจะยอมรับลําดับฟังก์ชันการสร้างสัญญาณและเรียกใช้ตามลําดับ โดยมีไว้เพื่อแทนที่อาร์เรย์มาตรฐานที่ใช้จัดคิวฟังก์ชันการสร้างสัญญาณที่จะเรียกใช้เมื่อโหลด GPT
ตัวอย่าง

JavaScript

window.googletag = window.googletag || { cmd: [] };
googletag.secureSignalProviders = googletag.secureSignalProviders || [];
googletag.secureSignalProviders.push({
  id: "collector123",
  collectorFunction: () => {
    return Promise.resolve("signal");
  },
});

JavaScript (เดิม)

window.googletag = window.googletag || { cmd: [] };
googletag.secureSignalProviders = googletag.secureSignalProviders || [];
googletag.secureSignalProviders.push({
  id: "collector123",
  collectorFunction: function () {
    return Promise.resolve("signal");
  },
});

TypeScript

window.googletag = window.googletag || { cmd: [] };
googletag.secureSignalProviders = googletag.secureSignalProviders || [];
googletag.secureSignalProviders.push({
  id: "collector123",
  collectorFunction: () => {
    return Promise.resolve("signal");
  },
});
ดูเพิ่มเติม

ฟังก์ชัน


companionAds

companionAds(): CompanionAdsService
แสดงการอ้างอิงถึง CompanionAdsService
การคืนสินค้า
CompanionAdsServiceบริการโฆษณาที่แสดงร่วม

defineOutOfPageSlot

defineOutOfPageSlot(adUnitPath: string, div?: string | OutOfPageFormat): Slot | null
สร้างช่องโฆษณานอกหน้าเว็บด้วยเส้นทางหน่วยโฆษณาที่ระบุ

สําหรับโฆษณานอกหน้าเว็บที่กําหนดเอง div คือรหัสขององค์ประกอบ div ที่จะมีโฆษณา ดูรายละเอียดเพิ่มเติมได้ในบทความเกี่ยวกับครีเอทีฟโฆษณาที่ไม่อยู่ในขอบเขตหน้า

สําหรับโฆษณานอกหน้าเว็บที่จัดการโดย GPT div คือ OutOfPageFormat ที่รองรับ
ตัวอย่าง

JavaScript

// Define a custom out-of-page ad slot.
googletag.defineOutOfPageSlot("/1234567/sports", "div-1");

// Define a GPT managed web interstitial ad slot.
googletag.defineOutOfPageSlot("/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL);

JavaScript (เดิม)

// Define a custom out-of-page ad slot.
googletag.defineOutOfPageSlot("/1234567/sports", "div-1");

// Define a GPT managed web interstitial ad slot.
googletag.defineOutOfPageSlot("/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL);

TypeScript

// Define a custom out-of-page ad slot.
googletag.defineOutOfPageSlot("/1234567/sports", "div-1");

// Define a GPT managed web interstitial ad slot.
googletag.defineOutOfPageSlot("/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL);
ดูเพิ่มเติม
พารามิเตอร์
adUnitPath: stringเส้นทางหน่วยโฆษณาแบบเต็มพร้อมรหัสเครือข่ายและรหัสหน่วยโฆษณา
Optional div: string | OutOfPageFormatรหัสของ div ที่จะมีหน่วยโฆษณานี้หรือ OutOfPageFormat
การคืนสินค้า
Slot | nullสล็อตที่สร้างขึ้นใหม่ หรือ null หากสร้างสล็อตไม่ได้

defineSlot

defineSlot(adUnitPath: string, size: GeneralSize, div?: string): Slot | null
สร้างช่องโฆษณาที่มีเส้นทางและขนาดหน่วยโฆษณาที่ระบุ และเชื่อมโยงกับรหัสขององค์ประกอบ div ในหน้าเว็บที่จะแสดงโฆษณา
ตัวอย่าง

JavaScript

googletag.defineSlot("/1234567/sports", [728, 90], "div-1");

JavaScript (เดิม)

googletag.defineSlot("/1234567/sports", [728, 90], "div-1");

TypeScript

googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
ดูเพิ่มเติม
พารามิเตอร์
adUnitPath: stringเส้นทางหน่วยโฆษณาแบบเต็มพร้อมรหัสเครือข่ายและรหัสหน่วยโฆษณา
size: GeneralSizeความกว้างและความสูงของช่องที่เพิ่ม ซึ่งเป็นขนาดที่ใช้ในคําขอโฆษณาหากไม่มีการแมปขนาดที่ปรับเปลี่ยนตามพื้นที่โฆษณาหรือขนาดของวิวพอร์ตเล็กกว่าขนาดที่เล็กที่สุดที่ระบุไว้ในการแมป
Optional div: stringรหัสของ div ที่จะมีหน่วยโฆษณานี้
การคืนสินค้า
Slot | nullช่วงเวลาที่สะดวกซึ่งสร้างขึ้นใหม่ หรือ null หากสร้างช่วงเวลาที่สะดวกไม่ได้

destroySlots

destroySlots(slots?: Slot[]): boolean
ทำลายช่องที่ระบุ โดยนําออบเจ็กต์และการอ้างอิงทั้งหมดที่เกี่ยวข้องกับช่องเหล่านั้นออกจาก GPT API นี้ไม่รองรับสล็อตพาสแบ็กและสล็อตสหาย

การเรียก API นี้ในสล็อตจะล้างโฆษณาและนําออบเจ็กต์สล็อตออกจากสถานะภายในที่ GPT ดูแล การเรียกใช้ฟังก์ชันอื่นๆ ในออบเจ็กต์สล็อตจะทําให้ลักษณะการทํางานไม่ชัดเจน โปรดทราบว่าเบราว์เซอร์อาจยังคงไม่เพิ่มพื้นที่ว่างของหน่วยความจำที่เชื่อมโยงกับช่องนั้นหากหน้าของผู้เผยแพร่โฆษณามีการอ้างอิงถึงช่องดังกล่าว การเรียก API นี้จะทําให้ div ที่เชื่อมโยงกับช่องนั้นพร้อมใช้งานอีกครั้ง

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

JavaScript

// The calls to construct an ad and display contents.
const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to destroy only slot1.
googletag.destroySlots([slot1]);

// This call to destroy both slot1 and slot2.
googletag.destroySlots([slot1, slot2]);

// This call to destroy all slots.
googletag.destroySlots();

JavaScript (เดิม)

// The calls to construct an ad and display contents.
var slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
var slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to destroy only slot1.
googletag.destroySlots([slot1]);

// This call to destroy both slot1 and slot2.
googletag.destroySlots([slot1, slot2]);

// This call to destroy all slots.
googletag.destroySlots();

TypeScript

// The calls to construct an ad and display contents.
const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!;
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!;
googletag.display("div-2");

// This call to destroy only slot1.
googletag.destroySlots([slot1]);

// This call to destroy both slot1 and slot2.
googletag.destroySlots([slot1, slot2]);

// This call to destroy all slots.
googletag.destroySlots();
พารามิเตอร์
Optional slots: Slot[]อาร์เรย์ของช่องที่จะทำลาย อาร์เรย์เป็นตัวเลือก สล็อตทั้งหมดจะถูกทำลายหากไม่ได้ระบุ
การคืนสินค้า
booleantrue หากมีการทำลายสล็อต false ไม่เช่นนั้น

disablePublisherConsole

disablePublisherConsole(): void
ปิดใช้คอนโซลผู้เผยแพร่โฆษณาของ Google
ดูเพิ่มเติม

display

display(divOrSlot: string | Element | Slot): void
สั่งให้บริการสล็อตแสดงผลสล็อต แต่ละช่องโฆษณาควรแสดงเพียงครั้งเดียวต่อหน้า คุณต้องกำหนดและเชื่อมโยงบริการกับทุกช่องก่อนจึงจะแสดงได้ การเรียกใช้การแสดงผลต้องไม่เกิดขึ้นจนกว่าองค์ประกอบจะปรากฏใน DOM วิธีปกติในการดําเนินการดังกล่าวคือวางภายในบล็อกสคริปต์ภายในองค์ประกอบ div ที่มีชื่อในการเรียกใช้เมธอด

หากใช้สถาปัตยกรรมคําขอรวมครั้งเดียว (SRA) ระบบจะดึงข้อมูลช่องโฆษณาทั้งหมดที่ไม่ได้ดึงข้อมูล ณ เวลาที่มีการเรียกใช้เมธอดนี้พร้อมกัน หากต้องการบังคับไม่ให้ช่องโฆษณาแสดง คุณต้องนํา div ทั้งหมดออก
ดูเพิ่มเติม
พารามิเตอร์
divOrSlot: string | Element | Slotรหัสขององค์ประกอบ div ที่มีช่องโฆษณาหรือองค์ประกอบ div หรือออบเจ็กต์ช่อง หากระบุองค์ประกอบ div ไว้ องค์ประกอบดังกล่าวต้องมีแอตทริบิวต์ "id" ที่ตรงกับรหัสที่ส่งไปยัง defineSlot

enableServices

enableServices(): void
เปิดใช้บริการ GPT ทั้งหมดที่กําหนดไว้สําหรับช่องโฆษณาในหน้า

getVersion

getVersion(): string
แสดงผล GPT เวอร์ชันปัจจุบัน
ดูเพิ่มเติม
การคืนสินค้า
stringสตริงเวอร์ชัน GPT ที่ใช้งานอยู่

openConsole

openConsole(div?: string): void
เปิดคอนโซลผู้เผยแพร่โฆษณาของ Google
ตัวอย่าง

JavaScript

// Calling with div ID.
googletag.openConsole("div-1");

// Calling without div ID.
googletag.openConsole();

JavaScript (เดิม)

// Calling with div ID.
googletag.openConsole("div-1");

// Calling without div ID.
googletag.openConsole();

TypeScript

// Calling with div ID.
googletag.openConsole("div-1");

// Calling without div ID.
googletag.openConsole();
ดูเพิ่มเติม
พารามิเตอร์
Optional div: stringรหัส div ของช่องโฆษณา ค่านี้ไม่บังคับ เมื่อระบุแล้ว คอนโซลผู้เผยแพร่โฆษณาจะพยายามเปิดขึ้นพร้อมแสดงรายละเอียดของช่องโฆษณาที่ระบุ

pubads

pubads(): PubAdsService
แสดงผลข้อมูลอ้างอิงถึง PubAdsService
การคืนสินค้า
PubAdsServiceบริการโฆษณาของผู้เผยแพร่โฆษณา

setAdIframeTitle

setAdIframeTitle(title: string): void
ตั้งค่าชื่อสําหรับ iframe ของคอนเทนเนอร์โฆษณาทั้งหมดที่สร้างโดย PubAdsService นับจากนี้เป็นต้นไป
ตัวอย่าง

JavaScript

googletag.setAdIframeTitle("title");

JavaScript (เดิม)

googletag.setAdIframeTitle("title");

TypeScript

googletag.setAdIframeTitle("title");
พารามิเตอร์
title: stringชื่อใหม่สำหรับ iframe ของคอนเทนเนอร์โฆษณาทั้งหมด

setConfig

setConfig(config: PageSettingsConfig): void
ตั้งค่าตัวเลือกการกําหนดค่าทั่วไปสําหรับหน้าเว็บ
พารามิเตอร์
config: PageSettingsConfig

sizeMapping

sizeMapping(): SizeMappingBuilder
สร้าง SizeMappingBuilder ใหม่
ดูเพิ่มเติม
การคืนสินค้า
SizeMappingBuilderตัวสร้างใหม่

googletag.CommandArray

อาร์เรย์คําสั่งจะยอมรับลําดับของฟังก์ชันและเรียกใช้ตามลําดับ โดยมีไว้เพื่อแทนที่อาร์เรย์มาตรฐานที่ใช้จัดคิวฟังก์ชันที่จะเรียกใช้เมื่อโหลด GPT
เมธอด
push
เรียกใช้ลำดับฟังก์ชันที่ระบุในอาร์กิวเมนต์ตามลำดับ

เมธอด


push

push(...f: ((this: typeof globalThis) => void)[]): number
เรียกใช้ลำดับฟังก์ชันที่ระบุไว้ในอาร์กิวเมนต์ตามลำดับ
ตัวอย่าง

JavaScript

googletag.cmd.push(() => {
  googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads());
});

JavaScript (เดิม)

googletag.cmd.push(function () {
  googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads());
});

TypeScript

googletag.cmd.push(() => {
  googletag.defineSlot("/1234567/sports", [160, 600])!.addService(googletag.pubads());
});
พารามิเตอร์
Rest ...f: ((this: typeof globalThis) => void)[]ฟังก์ชัน JavaScript ที่จะเรียกใช้ การเชื่อมโยงรันไทม์จะเป็น globalThis เสมอ ลองส่งผ่านฟังก์ชันลูกศรเพื่อเก็บค่า this ของบริบทเชิงคำที่ล้อมรอบ
การคืนสินค้า
numberจํานวนคําสั่งที่ประมวลผลจนถึงตอนนี้ ซึ่งเข้ากันได้กับค่าที่ Array.push แสดงผล (ความยาวปัจจุบันของอาร์เรย์)

googletag.CompanionAdsService

ขยายเวลา Service
บริการโฆษณาที่แสดงร่วม โฆษณาวิดีโอใช้บริการนี้เพื่อแสดงโฆษณาที่แสดงร่วมกัน
เมธอด
addEventListener
ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript ได้เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้า
getSlots
ดูรายการช่องที่เชื่อมโยงกับบริการนี้
removeEventListener
นำผู้ฟังที่ลงทะเบียนไว้ก่อนหน้านี้ออก
setRefreshUnfilledSlots
ตั้งค่าว่าช่องโฆษณาที่แสดงร่วมที่ยังไม่ได้รับโฆษณาจะได้รับโฆษณาทดแทนโดยอัตโนมัติหรือไม่
ดูเพิ่มเติม

เมธอด


setRefreshUnfilledSlots

setRefreshUnfilledSlots(value: boolean): void
ตั้งค่าว่าช่องโฆษณาที่แสดงร่วมที่ยังไม่ได้รับโฆษณาจะได้รับโฆษณาทดแทนโดยอัตโนมัติหรือไม่

เมธอดนี้สามารถเรียกใช้ได้หลายครั้งตลอดอายุการใช้งานของหน้าเว็บเพื่อเปิดและปิดโฆษณาทดแทน เฉพาะช่องที่ลงทะเบียนกับ PubAdsService เท่านั้นที่จะได้รับโฆษณาทดแทน วิธีการนี้ไม่ได้ออกแบบมาเพื่อเติมเต็มช่องโฆษณาที่แสดงร่วมกันที่ว่างเปล่าเมื่อมีการเผยแพร่วิดีโอ Ad Exchange เนื่องจากข้อจํากัดด้านนโยบาย
ตัวอย่าง

JavaScript

googletag.companionAds().setRefreshUnfilledSlots(true);

JavaScript (เดิม)

googletag.companionAds().setRefreshUnfilledSlots(true);

TypeScript

googletag.companionAds().setRefreshUnfilledSlots(true);
พารามิเตอร์
value: booleantrue เพื่อทดแทนช่องว่างโดยอัตโนมัติ หรือ false เพื่อคงค่าเดิม

googletag.PrivacySettingsConfig

ออบเจ็กต์การกําหนดค่าสําหรับการตั้งค่าความเป็นส่วนตัว
พร็อพเพอร์ตี้
childDirectedTreatment?
limitedAds?
เปิดใช้การแสดงโฆษณาในโหมดโฆษณาแบบจํากัดเพื่อช่วยในการปฏิบัติตามข้อกําหนดของผู้เผยแพร่โฆษณา
nonPersonalizedAds?
เปิดใช้การแสดงโฆษณาในโหมดโฆษณาที่ไม่ได้ปรับตามโปรไฟล์ของผู้ใช้เพื่อช่วยในการปฏิบัติตามข้อกําหนดของผู้เผยแพร่โฆษณา
restrictDataProcessing?
เปิดใช้การแสดงโฆษณาในโหมดการประมวลผลแบบจํากัดเพื่อช่วยในการปฏิบัติตามข้อกําหนดของผู้เผยแพร่โฆษณา
trafficSource?
ระบุว่าคำขอแสดงการเข้าชมที่ซื้อมาหรือการเข้าชมจากการค้นหาทั่วไป
underAgeOfConsent?
ระบุว่าจะทําเครื่องหมายคําขอโฆษณาว่ามาจากผู้ใช้ที่มีอายุต่ำกว่าอายุที่ยินยอมหรือไม่
ดูเพิ่มเติม

พร็อพเพอร์ตี้


Optional childDirectedTreatment

childDirectedTreatment?: null | boolean
ระบุว่าควรถือว่าหน้าเว็บมีไว้สําหรับเด็กหรือไม่ ตั้งค่าเป็น null เพื่อล้างการกำหนดค่า

Optional limitedAds

limitedAds?: boolean
เปิดใช้การแสดงโฆษณาในโหมดโฆษณาแบบจํากัดเพื่อช่วยในการปฏิบัติตามข้อกําหนดของผู้เผยแพร่โฆษณา

คุณสามารถสั่งให้ GPT ขอโฆษณาแบบจํากัดได้ 2 วิธี ดังนี้
  • โดยอัตโนมัติโดยใช้สัญญาณจากแพลตฟอร์มการจัดการความยินยอม TCF เวอร์ชัน 2.0 ของ IAB
  • ด้วยตนเองโดยตั้งค่าของช่องนี้เป็น true
การกำหนดค่าโฆษณาแบบจำกัดด้วยตนเองจะทำได้ก็ต่อเมื่อมีการโหลด GPT จาก URL ของโฆษณาแบบจำกัดเท่านั้น การพยายามแก้ไขการตั้งค่านี้เมื่อโหลด GPT จาก URL มาตรฐานจะทำให้เกิดคำเตือนในคอนโซลผู้เผยแพร่โฆษณา

โปรดทราบว่าคุณไม่จำเป็นต้องเปิดใช้โฆษณาแบบจำกัดด้วยตนเองเมื่อใช้ CMP อยู่
ตัวอย่าง

JavaScript

// Manually enable limited ads serving.
// GPT must be loaded from the limited ads URL to configure this setting.
googletag.pubads().setPrivacySettings({
  limitedAds: true,
});

JavaScript (เดิม)

// Manually enable limited ads serving.
// GPT must be loaded from the limited ads URL to configure this setting.
googletag.pubads().setPrivacySettings({
  limitedAds: true,
});

TypeScript

// Manually enable limited ads serving.
// GPT must be loaded from the limited ads URL to configure this setting.
googletag.pubads().setPrivacySettings({
  limitedAds: true,
});
ดูเพิ่มเติม

Optional nonPersonalizedAds

nonPersonalizedAds?: boolean
เปิดใช้การแสดงโฆษณาในโหมดโฆษณาที่ไม่ได้ปรับตามโปรไฟล์ของผู้ใช้เพื่อช่วยในการปฏิบัติตามข้อกําหนดของผู้เผยแพร่โฆษณา

Optional restrictDataProcessing

restrictDataProcessing?: boolean
เปิดใช้การแสดงโฆษณาในโหมดการประมวลผลแบบจํากัดเพื่อช่วยในการปฏิบัติตามข้อกําหนดของผู้เผยแพร่โฆษณา

Optional trafficSource

trafficSource?: TrafficSource
ระบุว่าคำขอแสดงการเข้าชมที่ซื้อมาหรือการเข้าชมจากการค้นหาทั่วไป ค่านี้จะป้อนข้อมูลมิติข้อมูลแหล่งที่มาของการเข้าชมในการรายงาน Ad Manager หากไม่ได้ตั้งค่า ระบบจะใช้ undefined เป็นค่าเริ่มต้นในการรายงาน
ตัวอย่าง

JavaScript

// Indicate requests represent organic traffic.
googletag.pubads().setPrivacySettings({
  trafficSource: googletag.enums.TrafficSource.ORGANIC,
});

// Indicate requests represent purchased traffic.
googletag.pubads().setPrivacySettings({
  trafficSource: googletag.enums.TrafficSource.PURCHASED,
});

JavaScript (เดิม)

// Indicate requests represent organic traffic.
googletag.pubads().setPrivacySettings({
  trafficSource: googletag.enums.TrafficSource.ORGANIC,
});

// Indicate requests represent purchased traffic.
googletag.pubads().setPrivacySettings({
  trafficSource: googletag.enums.TrafficSource.PURCHASED,
});

TypeScript

// Indicate requests represent organic traffic.
googletag.pubads().setPrivacySettings({
  trafficSource: googletag.enums.TrafficSource.ORGANIC,
});

// Indicate requests represent purchased traffic.
googletag.pubads().setPrivacySettings({
  trafficSource: googletag.enums.TrafficSource.PURCHASED,
});

Optional underAgeOfConsent

underAgeOfConsent?: null | boolean
ระบุว่าจะทําเครื่องหมายคําขอโฆษณาว่ามาจากผู้ใช้ที่มีอายุต่ำกว่าอายุที่ยินยอมหรือไม่ ตั้งค่าเป็น null เพื่อล้างการกำหนดค่า

googletag.PubAdsService

ขยายเวลา Service
บริการโฆษณาของผู้เผยแพร่โฆษณา บริการนี้ใช้ดึงข้อมูลและแสดงโฆษณาจากบัญชี Google Ad Manager
เมธอด
addEventListener
ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript ได้เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้า
clear
นําโฆษณาออกจากช่องที่ระบุและแทนที่ด้วยเนื้อหาว่าง
clearCategoryExclusions
ล้างป้ายกํากับการยกเว้นหมวดหมู่โฆษณาระดับหน้าเว็บทั้งหมด
clearTargeting
ล้างพารามิเตอร์การกําหนดเป้าหมายเองสําหรับคีย์ที่เฉพาะเจาะจงหรือสําหรับคีย์ทั้งหมด
collapseEmptyDivs
เปิดใช้การยุบ div ของช่องโฆษณาเพื่อไม่ให้ช่องโฆษณาใช้พื้นที่ในหน้าเว็บเมื่อไม่มีเนื้อหาโฆษณาที่จะแสดง
disableInitialLoad
ปิดใช้คําขอโฆษณาเมื่อโหลดหน้าเว็บ แต่อนุญาตให้ขอโฆษณาด้วยการเรียกใช้ PubAdsService.refresh
display
สร้างและแสดงช่องโฆษณาที่มีเส้นทางและขนาดหน่วยโฆษณาที่ระบุ
enableLazyLoad
เปิดใช้การโหลดแบบเลื่อนเวลาใน GPT ตามที่ออบเจ็กต์การกําหนดค่าระบุ
enableSingleRequest
เปิดใช้โหมดคำขอเดียวเพื่อดึงข้อมูลโฆษณาหลายรายการพร้อมกัน
enableVideoAds
ส่งสัญญาณให้ GPT ทราบว่าจะมีโฆษณาวิดีโอในหน้า
get
แสดงผลค่าสําหรับแอตทริบิวต์ AdSense ที่เชื่อมโยงกับคีย์ที่ระบุ
getAttributeKeys
แสดงคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในบริการนี้
getSlots
ดูรายการช่องที่เชื่อมโยงกับบริการนี้
getTargeting
แสดงผลพารามิเตอร์การกําหนดเป้าหมายระดับบริการที่กําหนดเองที่เฉพาะเจาะจงซึ่งตั้งค่าไว้
getTargetingKeys
แสดงรายการคีย์การกําหนดเป้าหมายระดับบริการที่กําหนดเองทั้งหมดที่ตั้งไว้
isInitialLoadDisabled
แสดงผลว่าคําขอโฆษณาครั้งแรกถูกปิดใช้ด้วยคําเรียก PubAdsService.disableInitialLoad ก่อนหน้านี้สําเร็จหรือไม่
refresh
ดึงข้อมูลและแสดงโฆษณาใหม่สำหรับบางช่องหรือทุกช่องในหน้า
removeEventListener
นำผู้ฟังที่ลงทะเบียนไว้ก่อนหน้านี้ออก
set
ตั้งค่าแอตทริบิวต์ AdSense ที่มีผลกับช่องโฆษณาทั้งหมดภายใต้บริการโฆษณาของผู้เผยแพร่โฆษณา
setCategoryExclusion
ตั้งค่าการยกเว้นหมวดหมู่โฆษณาระดับหน้าเว็บสําหรับชื่อป้ายกำกับที่ระบุ
setCentering
เปิดและปิดใช้การกึ่งกลางโฆษณาในแนวนอน
setForceSafeFrame
กําหนดค่าว่าควรบังคับให้โฆษณาทั้งหมดในหน้าแสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่
setLocation
ส่งข้อมูลตําแหน่งจากเว็บไซต์เพื่อให้คุณกําหนดเป้าหมายรายการโฆษณาตามภูมิศาสตร์ไปยังตําแหน่งที่ต้องการได้
setPrivacySettings
อนุญาตให้กําหนดการตั้งค่าความเป็นส่วนตัวทั้งหมดจาก API รายการเดียวโดยใช้ออบเจ็กต์การกําหนดค่า
setPublisherProvidedId
ตั้งค่ารหัสที่ผู้เผยแพร่โฆษณาระบุ
setSafeFrameConfig
ตั้งค่ากำหนดระดับหน้าสำหรับการกำหนดค่า SafeFrame
setTargeting
ตั้งค่าพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองสําหรับคีย์หนึ่งๆ ที่มีผลกับช่องโฆษณาบริการโฆษณาของผู้เผยแพร่โฆษณาทั้งหมด
setVideoContent
ตั้งค่าข้อมูลเนื้อหาวิดีโอที่จะส่งไปพร้อมกับคําขอโฆษณาเพื่อวัตถุประสงค์ในการกําหนดเป้าหมายและการยกเว้นเนื้อหา
updateCorrelator
เปลี่ยนตัวเชื่อมโยงที่ส่งไปพร้อมกับคําขอโฆษณา ซึ่งจะเริ่มต้นการดูหน้าเว็บใหม่อย่างมีประสิทธิภาพ

เมธอด


ล้าง

clear(slots?: Slot[]): boolean
นําโฆษณาออกจากช่องที่ระบุและแทนที่ด้วยเนื้อหาว่าง ระบบจะทําเครื่องหมายช่องว่าไม่ได้ดึงข้อมูล

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

JavaScript

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to clear only slot1.
googletag.pubads().clear([slot1]);

// This call to clear both slot1 and slot2.
googletag.pubads().clear([slot1, slot2]);

// This call to clear all slots.
googletag.pubads().clear();

JavaScript (เดิม)

var slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
var slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to clear only slot1.
googletag.pubads().clear([slot1]);

// This call to clear both slot1 and slot2.
googletag.pubads().clear([slot1, slot2]);

// This call to clear all slots.
googletag.pubads().clear();

TypeScript

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!;
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!;
googletag.display("div-2");

// This call to clear only slot1.
googletag.pubads().clear([slot1]);

// This call to clear both slot1 and slot2.
googletag.pubads().clear([slot1, slot2]);

// This call to clear all slots.
googletag.pubads().clear();
พารามิเตอร์
Optional slots: Slot[]อาร์เรย์ของช่องที่จะล้าง อาร์เรย์เป็นตัวเลือก ระบบจะล้างช่องทั้งหมดหากไม่ได้ระบุ
การคืนสินค้า
booleanแสดงผล true หากมีการล้างช่องแล้ว หรือแสดงผล false ในกรณีอื่นๆ

clearCategoryExclusions

clearCategoryExclusions(): PubAdsService
ล้างป้ายกํากับการยกเว้นหมวดหมู่โฆษณาระดับหน้าเว็บทั้งหมด ซึ่งจะมีประโยชน์หากคุณต้องการรีเฟรชช่อง
ตัวอย่าง

JavaScript

// Set category exclusion to exclude ads with 'AirlineAd' labels.
googletag.pubads().setCategoryExclusion("AirlineAd");

// Make ad requests. No ad with 'AirlineAd' label will be returned.

// Clear category exclusions so all ads can be returned.
googletag.pubads().clearCategoryExclusions();

// Make ad requests. Any ad can be returned.

JavaScript (เดิม)

// Set category exclusion to exclude ads with 'AirlineAd' labels.
googletag.pubads().setCategoryExclusion("AirlineAd");

// Make ad requests. No ad with 'AirlineAd' label will be returned.

// Clear category exclusions so all ads can be returned.
googletag.pubads().clearCategoryExclusions();

// Make ad requests. Any ad can be returned.

TypeScript

// Set category exclusion to exclude ads with 'AirlineAd' labels.
googletag.pubads().setCategoryExclusion("AirlineAd");

// Make ad requests. No ad with 'AirlineAd' label will be returned.

// Clear category exclusions so all ads can be returned.
googletag.pubads().clearCategoryExclusions();

// Make ad requests. Any ad can be returned.
ดูเพิ่มเติม
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้เมธอด

clearTargeting

clearTargeting(key?: string): PubAdsService
ล้างพารามิเตอร์การกําหนดเป้าหมายเองสําหรับคีย์ที่เฉพาะเจาะจงหรือสําหรับคีย์ทั้งหมด
ตัวอย่าง

JavaScript

googletag.pubads().setTargeting("interests", "sports");
googletag.pubads().setTargeting("colors", "blue");
googletag.pubads().setTargeting("fruits", "apple");

googletag.pubads().clearTargeting("interests");
// Targeting 'colors' and 'fruits' are still present, while 'interests'
// was cleared.

googletag.pubads().clearTargeting();
// All targeting has been cleared.

JavaScript (เดิม)

googletag.pubads().setTargeting("interests", "sports");
googletag.pubads().setTargeting("colors", "blue");
googletag.pubads().setTargeting("fruits", "apple");

googletag.pubads().clearTargeting("interests");
// Targeting 'colors' and 'fruits' are still present, while 'interests'
// was cleared.

googletag.pubads().clearTargeting();
// All targeting has been cleared.

TypeScript

googletag.pubads().setTargeting("interests", "sports");
googletag.pubads().setTargeting("colors", "blue");
googletag.pubads().setTargeting("fruits", "apple");

googletag.pubads().clearTargeting("interests");
// Targeting 'colors' and 'fruits' are still present, while 'interests'
// was cleared.

googletag.pubads().clearTargeting();
// All targeting has been cleared.
ดูเพิ่มเติม
พารามิเตอร์
Optional key: stringคีย์พารามิเตอร์การกําหนดเป้าหมาย คุณไม่จำเป็นต้องระบุคีย์นี้ ระบบจะล้างพารามิเตอร์การกำหนดเป้าหมายทั้งหมดหากไม่ระบุ
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้เมธอด

collapseEmptyDivs

collapseEmptyDivs(collapseBeforeAdFetch?: boolean): boolean
เปิดใช้การยุบ div ของช่องโฆษณาเพื่อไม่ให้ช่องโฆษณาใช้พื้นที่ในหน้าเว็บเมื่อไม่มีเนื้อหาโฆษณาที่จะแสดง คุณต้องตั้งค่าโหมดนี้ก่อนเปิดใช้บริการ
ดูเพิ่มเติม
พารามิเตอร์
Optional collapseBeforeAdFetch: booleanเลือกว่าจะยุบช่องก่อนที่จะดึงข้อมูลโฆษณาหรือไม่ พารามิเตอร์นี้ไม่บังคับ หากไม่ระบุ ระบบจะใช้ false เป็นค่าเริ่มต้น
การคืนสินค้า
booleanแสดงผลเป็น true หากเปิดใช้โหมดยุบ div และ false หากเปิดใช้โหมดยุบไม่ได้เนื่องจากมีการเรียกใช้เมธอดหลังจากเปิดใช้บริการแล้ว

disableInitialLoad

disableInitialLoad(): void
ปิดใช้คําขอโฆษณาเมื่อโหลดหน้าเว็บ แต่อนุญาตให้ขอโฆษณาด้วยการเรียกใช้ PubAdsService.refresh คุณควรตั้งค่านี้ก่อนเปิดใช้บริการ ต้องใช้โหมดอะซิงโครนัส ไม่เช่นนั้นคุณจะขอโฆษณาโดยใช้ refresh ไม่ได้
ดูเพิ่มเติม

display

display(adUnitPath: string, size: GeneralSize, div?: string | Element, clickUrl?: string): void
สร้างและแสดงช่องโฆษณาที่มีเส้นทางและขนาดหน่วยโฆษณาที่ระบุ วิธีการนี้ใช้ไม่ได้กับโหมดคำขอเดียว

หมายเหตุ: เมื่อเรียกใช้วิธีการนี้ ระบบจะสร้างภาพรวมของสถานะช่องและหน้าเว็บเพื่อให้แน่ใจว่ามีความสอดคล้องกันเมื่อส่งคำขอโฆษณาและแสดงผลคำตอบ การเปลี่ยนแปลงใดๆ ที่เกิดขึ้นกับสถานะช่องหรือหน้าเว็บหลังจากเรียกใช้เมธอดนี้ (รวมถึงการกำหนดเป้าหมาย การตั้งค่าความเป็นส่วนตัว การบังคับใช้ SafeFrame ฯลฯ) จะมีผลกับคำขอ display() หรือ refresh() ที่ตามมาเท่านั้น
ตัวอย่าง

JavaScript

googletag.pubads().display("/1234567/sports", [728, 90], "div-1");

JavaScript (เดิม)

googletag.pubads().display("/1234567/sports", [728, 90], "div-1");

TypeScript

googletag.pubads().display("/1234567/sports", [728, 90], "div-1");
ดูเพิ่มเติม
พารามิเตอร์
adUnitPath: stringเส้นทางหน่วยโฆษณาของช่องที่จะแสดงผล
size: GeneralSizeความกว้างและความสูงของช่อง
Optional div: string | Elementรหัสของ div ที่มีช่องหรือองค์ประกอบ div เอง
Optional clickUrl: stringURL การคลิกที่จะใช้ในช่องนี้

enableLazyLoad

enableLazyLoad(config?: {
  fetchMarginPercent?: number;
  mobileScaling?: number;
  renderMarginPercent?: number;
}): void
เปิดใช้การโหลดแบบเลื่อนเวลาใน GPT ตามที่ออบเจ็กต์การกําหนดค่าระบุ ดูตัวอย่างโดยละเอียดได้ที่ตัวอย่างการโหลดแบบ Lazy Loading

หมายเหตุ: การดึงข้อมูลแบบ Lazy Loading ใน SRA จะใช้งานได้ก็ต่อเมื่อช่องทั้งหมดอยู่นอกระยะการดึงข้อมูลเท่านั้น
ตัวอย่าง

JavaScript

googletag.pubads().enableLazyLoad({
  // Fetch slots within 5 viewports.
  fetchMarginPercent: 500,
  // Render slots within 2 viewports.
  renderMarginPercent: 200,
  // Double the above values on mobile.
  mobileScaling: 2.0,
});

JavaScript (เดิม)

googletag.pubads().enableLazyLoad({
  // Fetch slots within 5 viewports.
  fetchMarginPercent: 500,
  // Render slots within 2 viewports.
  renderMarginPercent: 200,
  // Double the above values on mobile.
  mobileScaling: 2.0,
});

TypeScript

googletag.pubads().enableLazyLoad({
  // Fetch slots within 5 viewports.
  fetchMarginPercent: 500,
  // Render slots within 2 viewports.
  renderMarginPercent: 200,
  // Double the above values on mobile.
  mobileScaling: 2.0,
});
ดูเพิ่มเติม
พารามิเตอร์
Optional config: {
  fetchMarginPercent?: number;
  mobileScaling?: number;
  renderMarginPercent?: number;
}
ออบเจ็กต์การกําหนดค่าช่วยให้ปรับแต่งลักษณะการทํางานแบบ Lazy ได้ การกําหนดค่าที่ละเว้นจะใช้ค่าเริ่มต้นที่ Google ตั้งไว้ซึ่งจะได้รับการปรับแต่งเมื่อเวลาผ่านไป หากต้องการปิดใช้การตั้งค่าบางอย่าง เช่น ระยะการดึงข้อมูล ให้ตั้งค่าเป็น -1
  • fetchMarginPercent

    ระยะทางขั้นต่ำจากวิวพอร์ตปัจจุบันที่ช่องโฆษณาต้องอยู่ก่อนที่เราจะนำข้อมูลโฆษณามาแสดงเป็นเปอร์เซ็นต์ของขนาดวิวพอร์ต ค่า 0 หมายถึง "เมื่อช่องโฆษณาเข้าสู่วิวพอร์ต", 100 หมายถึง "เมื่อโฆษณาอยู่ห่างจากวิวพอร์ต 1 ช่อง" และอื่นๆ
  • renderMarginPercent

    ระยะห่างขั้นต่ำจากวิวพอร์ตปัจจุบันที่ช่องโฆษณาต้องอยู่ก่อนที่เราจะทำการแสดงผลโฆษณา ซึ่งช่วยให้สามารถโหลดโฆษณาล่วงหน้าได้ แต่ต้องรอแสดงผลและดาวน์โหลดทรัพยากรย่อยอื่นๆ ค่านี้ทํางานเหมือนกับ fetchMarginPercent เป็นเปอร์เซ็นต์ของวิวพอร์ต
  • mobileScaling

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

enableSingleRequest

enableSingleRequest(): boolean
เปิดใช้โหมดคำขอเดียวเพื่อดึงข้อมูลโฆษณาหลายรายการพร้อมกัน ซึ่งกำหนดให้ต้องกําหนดช่องโฆษณาของผู้เผยแพร่โฆษณาทั้งหมดและเพิ่มลงใน PubAdsService ก่อนเปิดใช้บริการ คุณต้องตั้งค่าโหมดคำขอเดี่ยวก่อนเปิดใช้บริการ
ดูเพิ่มเติม
การคืนสินค้า
booleanแสดงผลเป็น true หากเปิดใช้โหมดคำขอเดี่ยว และ false หากเปิดใช้โหมดคำขอเดี่ยวไม่ได้เนื่องจากมีการเรียกใช้เมธอดหลังจากเปิดใช้บริการแล้ว

enableVideoAds

enableVideoAds(): void
ส่งสัญญาณให้ GPT ทราบว่าจะมีโฆษณาวิดีโอในหน้า ซึ่งจะเปิดใช้ข้อจำกัดการยกเว้นโฆษณาคู่แข่งในโฆษณา Display และโฆษณาวิดีโอ หากทราบเนื้อหาวิดีโอ ให้เรียกใช้ PubAdsService.setVideoContent เพื่อให้ใช้การยกเว้นเนื้อหาสําหรับโฆษณา Display ได้

get

get(key: string): null | string
แสดงค่าสำหรับแอตทริบิวต์ AdSense ที่เชื่อมโยงกับคีย์ที่ระบุ
ตัวอย่าง

JavaScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().get("adsense_background_color");
// Returns '#FFFFFF'.

JavaScript (เดิม)

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().get("adsense_background_color");
// Returns '#FFFFFF'.

TypeScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().get("adsense_background_color");
// Returns '#FFFFFF'.
ดูเพิ่มเติม
พารามิเตอร์
key: stringชื่อแอตทริบิวต์ที่จะค้นหา
การคืนสินค้า
null | stringค่าปัจจุบันสำหรับคีย์แอตทริบิวต์ หรือ null หากไม่มีคีย์

getAttributeKeys

getAttributeKeys(): string[]
แสดงคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในบริการนี้
ตัวอย่าง

JavaScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().set("adsense_border_color", "#AABBCC");
googletag.pubads().getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].

JavaScript (เดิม)

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().set("adsense_border_color", "#AABBCC");
googletag.pubads().getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].

TypeScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().set("adsense_border_color", "#AABBCC");
googletag.pubads().getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].
การคืนสินค้า
string[]อาร์เรย์ของคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในบริการนี้ ไม่ได้ระบุลําดับ

getTargeting

getTargeting(key: string): string[]
แสดงผลพารามิเตอร์การกําหนดเป้าหมายระดับบริการที่กําหนดเองที่เฉพาะเจาะจงซึ่งตั้งค่าไว้
ตัวอย่าง

JavaScript

googletag.pubads().setTargeting("interests", "sports");

googletag.pubads().getTargeting("interests");
// Returns ['sports'].

googletag.pubads().getTargeting("age");
// Returns [] (empty array).

JavaScript (เดิม)

googletag.pubads().setTargeting("interests", "sports");

googletag.pubads().getTargeting("interests");
// Returns ['sports'].

googletag.pubads().getTargeting("age");
// Returns [] (empty array).

TypeScript

googletag.pubads().setTargeting("interests", "sports");

googletag.pubads().getTargeting("interests");
// Returns ['sports'].

googletag.pubads().getTargeting("age");
// Returns [] (empty array).
พารามิเตอร์
key: stringคีย์การกําหนดเป้าหมายที่จะค้นหา
การคืนสินค้า
string[]ค่าที่เชื่อมโยงกับคีย์นี้ หรืออาร์เรย์ว่างหากไม่มีคีย์ดังกล่าว

getTargetingKeys

getTargetingKeys(): string[]
แสดงรายการคีย์การกําหนดเป้าหมายระดับบริการที่กําหนดเองทั้งหมดที่ตั้งไว้
ตัวอย่าง

JavaScript

googletag.pubads().setTargeting("interests", "sports");
googletag.pubads().setTargeting("colors", "blue");

googletag.pubads().getTargetingKeys();
// Returns ['interests', 'colors'].

JavaScript (เดิม)

googletag.pubads().setTargeting("interests", "sports");
googletag.pubads().setTargeting("colors", "blue");

googletag.pubads().getTargetingKeys();
// Returns ['interests', 'colors'].

TypeScript

googletag.pubads().setTargeting("interests", "sports");
googletag.pubads().setTargeting("colors", "blue");

googletag.pubads().getTargetingKeys();
// Returns ['interests', 'colors'].
การคืนสินค้า
string[]อาร์เรย์ของคีย์การกําหนดเป้าหมาย ไม่ได้ระบุลําดับ

isInitialLoadDisabled

isInitialLoadDisabled(): boolean
แสดงผลว่าคําขอโฆษณาครั้งแรกถูกปิดใช้ด้วยคําเรียก PubAdsService.disableInitialLoad ก่อนหน้านี้สําเร็จหรือไม่
การคืนสินค้า
booleanแสดงผล true หากการเรียกใช้ PubAdsService.disableInitialLoad ก่อนหน้านี้สำเร็จ ไม่เช่นนั้นแสดงผล false

รีเฟรช

refresh(slots?: null | Slot[], options?: {
  changeCorrelator: boolean;
}): void
ดึงข้อมูลและแสดงโฆษณาใหม่สำหรับบางช่องหรือทุกช่องในหน้า ใช้งานได้ในโหมดการแสดงผลแบบแอซิงโครนัสเท่านั้น

การเรียกใช้ refresh ต้องอยู่หลังการเรียกใช้ display ช่องโฆษณา เพื่อให้ทํางานได้อย่างถูกต้องในเบราว์เซอร์ทุกประเภท หากไม่เรียกใช้ display การรีเฟรชอาจทำงานผิดปกติ หากต้องการ คุณสามารถใช้เมธอด PubAdsService.disableInitialLoad เพื่อหยุดdisplayไม่ให้ดึงข้อมูลโฆษณา

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

JavaScript

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to refresh fetches a new ad for slot1 only.
googletag.pubads().refresh([slot1]);

// This call to refresh fetches a new ad for both slot1 and slot2.
googletag.pubads().refresh([slot1, slot2]);

// This call to refresh fetches a new ad for each slot.
googletag.pubads().refresh();

// This call to refresh fetches a new ad for slot1, without changing
// the correlator.
googletag.pubads().refresh([slot1], { changeCorrelator: false });

// This call to refresh fetches a new ad for each slot, without
// changing the correlator.
googletag.pubads().refresh(null, { changeCorrelator: false });

JavaScript (เดิม)

var slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
var slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to refresh fetches a new ad for slot1 only.
googletag.pubads().refresh([slot1]);

// This call to refresh fetches a new ad for both slot1 and slot2.
googletag.pubads().refresh([slot1, slot2]);

// This call to refresh fetches a new ad for each slot.
googletag.pubads().refresh();

// This call to refresh fetches a new ad for slot1, without changing
// the correlator.
googletag.pubads().refresh([slot1], { changeCorrelator: false });

// This call to refresh fetches a new ad for each slot, without
// changing the correlator.
googletag.pubads().refresh(null, { changeCorrelator: false });

TypeScript

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!;
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!;
googletag.display("div-2");

// This call to refresh fetches a new ad for slot1 only.
googletag.pubads().refresh([slot1]);

// This call to refresh fetches a new ad for both slot1 and slot2.
googletag.pubads().refresh([slot1, slot2]);

// This call to refresh fetches a new ad for each slot.
googletag.pubads().refresh();

// This call to refresh fetches a new ad for slot1, without changing
// the correlator.
googletag.pubads().refresh([slot1], { changeCorrelator: false });

// This call to refresh fetches a new ad for each slot, without
// changing the correlator.
googletag.pubads().refresh(null, { changeCorrelator: false });
ดูเพิ่มเติม
พารามิเตอร์
Optional slots: null | Slot[]ช่องที่จะรีเฟรช อาร์เรย์เป็นตัวเลือก โดยระบบจะรีเฟรชทุกช่องหากไม่ได้ระบุ
Optional options: {
  changeCorrelator: boolean;
}
ตัวเลือกการกําหนดค่าที่เชื่อมโยงกับการเรียกใช้การรีเฟรชนี้
  • changeCorrelator

    ระบุว่าจะสร้างตัวเชื่อมโยงใหม่สำหรับการดึงข้อมูลโฆษณาหรือไม่ เซิร์ฟเวอร์โฆษณาจะเก็บค่าสหสัมพันธ์นี้ไว้ชั่วคราว (ปัจจุบันคือ 30 วินาที แต่อาจมีการเปลี่ยนแปลง) เพื่อให้คำขอที่มีค่าสหสัมพันธ์เดียวกันซึ่งได้รับในช่วงเวลาใกล้เคียงกันจะถือว่าเป็นการดูหน้าเว็บครั้งเดียว โดยค่าเริ่มต้น ระบบจะสร้างตัวเชื่อมโยงใหม่สำหรับการรีเฟรชทุกครั้ง

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

set

set(key: string, value: string): PubAdsService
ตั้งค่าแอตทริบิวต์ AdSense ที่มีผลกับช่องโฆษณาทั้งหมดภายใต้บริการโฆษณาของผู้เผยแพร่โฆษณา

การเรียกใช้คีย์นี้มากกว่า 1 ครั้งสำหรับคีย์เดียวกันจะเป็นการลบล้างค่าที่ตั้งไว้ก่อนหน้านี้สำหรับคีย์นั้น คุณต้องตั้งค่าทุกค่าก่อนเรียกใช้ display หรือ refresh
ตัวอย่าง

JavaScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");

JavaScript (เดิม)

googletag.pubads().set("adsense_background_color", "#FFFFFF");

TypeScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
ดูเพิ่มเติม
พารามิเตอร์
key: stringชื่อแอตทริบิวต์
value: stringค่าแอตทริบิวต์
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้เมธอด

setCategoryExclusion

setCategoryExclusion(categoryExclusion: string): PubAdsService
ตั้งค่าการยกเว้นหมวดหมู่โฆษณาระดับหน้าเว็บสําหรับชื่อป้ายกำกับที่ระบุ
ตัวอย่าง

JavaScript

// Label = AirlineAd.
googletag.pubads().setCategoryExclusion("AirlineAd");

JavaScript (เดิม)

// Label = AirlineAd.
googletag.pubads().setCategoryExclusion("AirlineAd");

TypeScript

// Label = AirlineAd.
googletag.pubads().setCategoryExclusion("AirlineAd");
ดูเพิ่มเติม
พารามิเตอร์
categoryExclusion: stringป้ายกํากับการยกเว้นหมวดหมู่โฆษณาที่จะเพิ่ม
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้เมธอด

setCentering

setCentering(centerAds: boolean): void
เปิดและปิดใช้การกึ่งกลางโฆษณาในแนวนอน การจัดกึ่งกลางจะปิดอยู่โดยค่าเริ่มต้น ใน gpt_mobile.js เดิม ระบบจะเปิดใช้การกึ่งกลางโดยค่าเริ่มต้น

คุณควรเรียกใช้เมธอดนี้ก่อนเรียกใช้ display หรือ refresh เนื่องจากจะมีเฉพาะโฆษณาที่ขอหลังจากเรียกใช้เมธอดนี้เท่านั้นที่จะได้รับการกึ่งกลาง
ตัวอย่าง

JavaScript

// Make ads centered.
googletag.pubads().setCentering(true);

JavaScript (เดิม)

// Make ads centered.
googletag.pubads().setCentering(true);

TypeScript

// Make ads centered.
googletag.pubads().setCentering(true);
พารามิเตอร์
centerAds: booleantrue เพื่อจัดโฆษณาให้อยู่กึ่งกลาง false เพื่อจัดโฆษณาให้ชิดซ้าย

setForceSafeFrame

setForceSafeFrame(forceSafeFrame: boolean): PubAdsService
กําหนดค่าว่าควรบังคับให้โฆษณาทั้งหมดในหน้าแสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่

โปรดคํานึงถึงสิ่งต่อไปนี้ขณะใช้ API นี้
  • การตั้งค่านี้จะมีผลกับคำขอโฆษณาที่ตามมาซึ่งส่งสําหรับช่องที่เกี่ยวข้องเท่านั้น
  • การตั้งค่าระดับช่อง (หากระบุ) จะลบล้างการตั้งค่าระดับหน้าเสมอ
  • หากตั้งค่าเป็น true (ที่ระดับช่องหรือระดับหน้า) โฆษณาจะแสดงผลด้วยคอนเทนเนอร์ SafeFrame เสมอ โดยไม่ขึ้นอยู่กับตัวเลือกที่เลือกใน UI ของ Google Ad Manager
  • อย่างไรก็ตาม หากตั้งค่าเป็น false หรือไม่ได้ระบุไว้ ระบบจะแสดงผลโฆษณาโดยใช้คอนเทนเนอร์ SafeFrame โดยขึ้นอยู่กับประเภทของครีเอทีฟโฆษณาและการเลือกที่ทำใน UI ของ Google Ad Manager
  • คุณควรใช้ API นี้อย่างระมัดระวังเนื่องจากอาจส่งผลต่อลักษณะการทํางานของครีเอทีฟโฆษณาที่พยายามจะออกจาก iframe หรืออาศัยการแสดงผลในหน้าของผู้เผยแพร่โฆษณาโดยตรง
ตัวอย่าง

JavaScript

googletag.pubads().setForceSafeFrame(true);

// The following slot will be opted-out of the page-level force
// SafeFrame instruction.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")
  .setForceSafeFrame(false)
  .addService(googletag.pubads());

// The following slot will have SafeFrame forced.
googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads());

googletag.display("div-1");
googletag.display("div-2");

JavaScript (เดิม)

googletag.pubads().setForceSafeFrame(true);

// The following slot will be opted-out of the page-level force
// SafeFrame instruction.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")
  .setForceSafeFrame(false)
  .addService(googletag.pubads());

// The following slot will have SafeFrame forced.
googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads());

googletag.display("div-1");
googletag.display("div-2");

TypeScript

googletag.pubads().setForceSafeFrame(true);

// The following slot will be opted-out of the page-level force
// SafeFrame instruction.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")!
  .setForceSafeFrame(false)
  .addService(googletag.pubads());

// The following slot will have SafeFrame forced.
googletag.defineSlot("/1234567/news", [160, 600], "div-2")!.addService(googletag.pubads());

googletag.display("div-1");
googletag.display("div-2");
ดูเพิ่มเติม
พารามิเตอร์
forceSafeFrame: booleantrue เพื่อบังคับให้แสดงโฆษณาทั้งหมดในหน้าเว็บใน SafeFrame และ false เพื่อเปลี่ยนการตั้งค่าก่อนหน้าเป็นเท็จ การตั้งค่านี้เป็น false เมื่อไม่ได้ระบุไว้ก่อนหน้านี้จะไม่เปลี่ยนแปลงอะไร
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้ฟังก์ชัน

setLocation

setLocation(address: string): PubAdsService
ส่งข้อมูลตําแหน่งจากเว็บไซต์เพื่อให้คุณกําหนดเป้าหมายรายการโฆษณาตามภูมิศาสตร์ไปยังตําแหน่งที่ต้องการได้
ตัวอย่าง

JavaScript

// Postal code:
googletag.pubads().setLocation("10001,US");

JavaScript (เดิม)

// Postal code:
googletag.pubads().setLocation("10001,US");

TypeScript

// Postal code:
googletag.pubads().setLocation("10001,US");
พารามิเตอร์
address: stringที่อยู่รูปแบบอิสระ
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้เมธอด

setPrivacySettings

setPrivacySettings(privacySettings: PrivacySettingsConfig): PubAdsService
อนุญาตให้กําหนดการตั้งค่าความเป็นส่วนตัวทั้งหมดจาก API รายการเดียวโดยใช้ออบเจ็กต์การกําหนดค่า
ตัวอย่าง

JavaScript

googletag.pubads().setPrivacySettings({
  restrictDataProcessing: true,
});

// Set multiple privacy settings at the same time.
googletag.pubads().setPrivacySettings({
  childDirectedTreatment: true,
  underAgeOfConsent: true,
});

// Clear the configuration for childDirectedTreatment.
googletag.pubads().setPrivacySettings({
  childDirectedTreatment: null,
});

JavaScript (เดิม)

googletag.pubads().setPrivacySettings({
  restrictDataProcessing: true,
});

// Set multiple privacy settings at the same time.
googletag.pubads().setPrivacySettings({
  childDirectedTreatment: true,
  underAgeOfConsent: true,
});

// Clear the configuration for childDirectedTreatment.
googletag.pubads().setPrivacySettings({
  childDirectedTreatment: null,
});

TypeScript

googletag.pubads().setPrivacySettings({
  restrictDataProcessing: true,
});

// Set multiple privacy settings at the same time.
googletag.pubads().setPrivacySettings({
  childDirectedTreatment: true,
  underAgeOfConsent: true,
});

// Clear the configuration for childDirectedTreatment.
googletag.pubads().setPrivacySettings({
  childDirectedTreatment: null,
});
ดูเพิ่มเติม
พารามิเตอร์
privacySettings: PrivacySettingsConfigออบเจ็กต์ที่มีการกำหนดค่าการตั้งค่าความเป็นส่วนตัว
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้ฟังก์ชัน

setPublisherProvidedId

setPublisherProvidedId(ppid: string): PubAdsService
ตั้งค่ารหัสที่ผู้เผยแพร่โฆษณาระบุ
ตัวอย่าง

JavaScript

googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");

JavaScript (เดิม)

googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");

TypeScript

googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
ดูเพิ่มเติม
พารามิเตอร์
ppid: stringรหัสตัวอักษรผสมตัวเลขที่ได้จากผู้เผยแพร่โฆษณา ต้องมีความยาวระหว่าง 32 ถึง 150 อักขระ
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้เมธอด

setSafeFrameConfig

setSafeFrameConfig(config: SafeFrameConfig): PubAdsService
ตั้งค่ากำหนดระดับหน้าสำหรับการกำหนดค่า SafeFrame ระบบจะไม่สนใจคีย์ที่ไม่รู้จักในออบเจ็กต์การกําหนดค่า ระบบจะไม่สนใจการกําหนดค่าทั้งหมดหากมีการส่งค่าที่ไม่ถูกต้องสําหรับคีย์ที่รู้จัก

ค่ากําหนดระดับหน้าเว็บเหล่านี้จะถูกลบล้างโดยค่ากําหนดระดับช่อง หากระบุไว้
ตัวอย่าง

JavaScript

googletag.pubads().setForceSafeFrame(true);

const pageConfig = {
  allowOverlayExpansion: true,
  allowPushExpansion: true,
  sandbox: true,
};

const slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

// The following slot will not allow for expansion by overlay.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")
  .setSafeFrameConfig(slotConfig)
  .addService(googletag.pubads());

// The following slot will inherit the page level settings, and hence
// would allow for expansion by overlay.
googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads());

googletag.display("div-1");
googletag.display("div-2");

JavaScript (เดิม)

googletag.pubads().setForceSafeFrame(true);

var pageConfig = {
  allowOverlayExpansion: true,
  allowPushExpansion: true,
  sandbox: true,
};

var slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

// The following slot will not allow for expansion by overlay.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")
  .setSafeFrameConfig(slotConfig)
  .addService(googletag.pubads());

// The following slot will inherit the page level settings, and hence
// would allow for expansion by overlay.
googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads());

googletag.display("div-1");
googletag.display("div-2");

TypeScript

googletag.pubads().setForceSafeFrame(true);

const pageConfig = {
  allowOverlayExpansion: true,
  allowPushExpansion: true,
  sandbox: true,
};

const slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

// The following slot will not allow for expansion by overlay.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")!
  .setSafeFrameConfig(slotConfig)
  .addService(googletag.pubads());

// The following slot will inherit the page level settings, and hence
// would allow for expansion by overlay.
googletag.defineSlot("/1234567/news", [160, 600], "div-2")!.addService(googletag.pubads());

googletag.display("div-1");
googletag.display("div-2");
ดูเพิ่มเติม
พารามิเตอร์
config: SafeFrameConfigออบเจ็กต์การกําหนดค่า
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้เมธอด

setTargeting

setTargeting(key: string, value: string | string[]): PubAdsService
ตั้งค่าพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองสําหรับคีย์หนึ่งๆ ที่มีผลกับช่องโฆษณาบริการโฆษณาของผู้เผยแพร่โฆษณาทั้งหมด การเรียกใช้คีย์นี้หลายครั้งสําหรับคีย์เดียวกันจะเป็นการเขียนทับค่าเก่า คีย์เหล่านี้จะกําหนดไว้ในบัญชี Google Ad Manager
ตัวอย่าง

JavaScript

// Example with a single value for a key.
googletag.pubads().setTargeting("interests", "sports");

// Example with multiple values for a key inside in an array.
googletag.pubads().setTargeting("interests", ["sports", "music"]);

JavaScript (เดิม)

// Example with a single value for a key.
googletag.pubads().setTargeting("interests", "sports");

// Example with multiple values for a key inside in an array.
googletag.pubads().setTargeting("interests", ["sports", "music"]);

TypeScript

// Example with a single value for a key.
googletag.pubads().setTargeting("interests", "sports");

// Example with multiple values for a key inside in an array.
googletag.pubads().setTargeting("interests", ["sports", "music"]);
ดูเพิ่มเติม
พารามิเตอร์
key: stringคีย์พารามิเตอร์การกําหนดเป้าหมาย
value: string | string[]ค่าพารามิเตอร์การกําหนดเป้าหมายหรืออาร์เรย์ของค่า
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้เมธอด

setVideoContent

setVideoContent(videoContentId: string, videoCmsId: string): void
ตั้งค่าข้อมูลเนื้อหาวิดีโอที่จะส่งไปพร้อมกับคําขอโฆษณาเพื่อวัตถุประสงค์ในการกําหนดเป้าหมายและการยกเว้นเนื้อหา ระบบจะเปิดใช้โฆษณาวิดีโอโดยอัตโนมัติเมื่อเรียกใช้เมธอดนี้ สําหรับ videoContentId และ videoCmsId ให้ใช้ค่าที่ระบุไว้ในบริการส่งผ่านข้อมูลเนื้อหาของ Google Ad Manager
ดูเพิ่มเติม
พารามิเตอร์
videoContentId: stringหมายเลขเนื้อหาวิดีโอ
videoCmsId: stringรหัส CMS ของวิดีโอ

updateCorrelator

updateCorrelator(): PubAdsService
เปลี่ยนตัวเชื่อมโยงที่ส่งไปพร้อมกับคําขอโฆษณา ซึ่งจะเริ่มต้นการดูหน้าเว็บใหม่อย่างมีประสิทธิภาพ สหสัมพันธ์จะเหมือนกันสําหรับคําขอโฆษณาทั้งหมดที่มาจากการแสดงผลหน้าเว็บครั้งเดียว และจะไม่ซ้ำกันระหว่างการแสดงผลหน้าเว็บ มีผลกับโหมดอะซิงโครนัสเท่านั้น

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

JavaScript

// Assume that the correlator is currently 12345. All ad requests made
// by this page will currently use that value.

// Replace the current correlator with a new correlator.
googletag.pubads().updateCorrelator();

// The correlator will now be a new randomly selected value, different
// from 12345. All subsequent ad requests made by this page will use
// the new value.

JavaScript (เดิม)

// Assume that the correlator is currently 12345. All ad requests made
// by this page will currently use that value.

// Replace the current correlator with a new correlator.
googletag.pubads().updateCorrelator();

// The correlator will now be a new randomly selected value, different
// from 12345. All subsequent ad requests made by this page will use
// the new value.

TypeScript

// Assume that the correlator is currently 12345. All ad requests made
// by this page will currently use that value.

// Replace the current correlator with a new correlator.
googletag.pubads().updateCorrelator();

// The correlator will now be a new randomly selected value, different
// from 12345. All subsequent ad requests made by this page will use
// the new value.
การคืนสินค้า
PubAdsServiceออบเจ็กต์บริการที่เรียกใช้ฟังก์ชัน

googletag.ResponseInformation

ออบเจ็กต์ที่แสดงการตอบกลับโฆษณารายการเดียว
พร็อพเพอร์ตี้
advertiserId
รหัสของผู้ลงโฆษณา
campaignId
รหัสของแคมเปญ
creativeId
รหัสของครีเอทีฟโฆษณา
creativeTemplateId
รหัสเทมเพลตของโฆษณา
lineItemId
รหัสของรายการโฆษณา
ดูเพิ่มเติม

พร็อพเพอร์ตี้


advertiserId

advertiserId: null | number
รหัสของผู้ลงโฆษณา

campaignId

campaignId: null | number
รหัสของแคมเปญ

creativeId

creativeId: null | number
รหัสของครีเอทีฟโฆษณา

creativeTemplateId

creativeTemplateId: null | number
รหัสเทมเพลตของโฆษณา

lineItemId

lineItemId: null | number
รหัสของรายการโฆษณา

googletag.RewardedPayload

ออบเจ็กต์ที่แสดงรางวัลที่เชื่อมโยงกับโฆษณาที่มีการให้รางวัล
พร็อพเพอร์ตี้
amount
จํานวนสินค้าที่รวมอยู่ในรางวัล
type
ประเภทของไอเทมที่รวมอยู่ในรางวัล (เช่น "เหรียญ")
ดูเพิ่มเติม

พร็อพเพอร์ตี้


amount

amount: number
จํานวนสินค้าที่รวมอยู่ในรางวัล

type

type: string
ประเภทของไอเทมที่รวมอยู่ในรางวัล (เช่น "เหรียญ")

googletag.SafeFrameConfig

ออบเจ็กต์การกําหนดค่าสําหรับคอนเทนเนอร์ SafeFrame
พร็อพเพอร์ตี้
allowOverlayExpansion?
SafeFrame ควรอนุญาตให้เนื้อหาโฆษณาขยายโดยการวางซ้อนเนื้อหาของหน้าหรือไม่
allowPushExpansion?
กำหนดว่า SafeFrame ควรอนุญาตให้เนื้อหาโฆษณาขยายโดยการดันเนื้อหาหน้าเว็บหรือไม่
sandbox?
ระบุว่า SafeFrame ควรใช้แอตทริบิวต์ sandbox ของ HTML5 เพื่อป้องกันการนำทางระดับบนสุดโดยไม่มีการโต้ตอบของผู้ใช้หรือไม่
useUniqueDomain?
เลิกใช้งานแล้ว SafeFrame ควรใช้โดเมนย่อยแบบสุ่มสําหรับครีเอทีฟโฆษณาแบบจองหรือไม่
ดูเพิ่มเติม

พร็อพเพอร์ตี้


Optional allowOverlayExpansion

allowOverlayExpansion?: boolean
SafeFrame ควรอนุญาตให้เนื้อหาโฆษณาขยายโดยการวางซ้อนเนื้อหาของหน้าหรือไม่

Optional allowPushExpansion

allowPushExpansion?: boolean
กำหนดว่า SafeFrame ควรอนุญาตให้เนื้อหาโฆษณาขยายโดยการดันเนื้อหาหน้าเว็บหรือไม่

Optional sandbox

sandbox?: boolean
ระบุว่า SafeFrame ควรใช้แอตทริบิวต์ sandbox ของ HTML5 เพื่อป้องกันการนำทางระดับบนสุดโดยไม่มีการโต้ตอบของผู้ใช้หรือไม่ ค่าที่ถูกต้องเพียงค่าเดียวคือ true (บังคับให้เป็น false ไม่ได้) โปรดทราบว่าแอตทริบิวต์แซนด์บ็อกซ์จะปิดใช้ปลั๊กอิน (เช่น Flash)

Optional useUniqueDomain

useUniqueDomain?: null | boolean
SafeFrame ควรใช้โดเมนย่อยแบบสุ่มสําหรับครีเอทีฟโฆษณาแบบจองหรือไม่ ส่ง null เพื่อล้างค่าที่เก็บไว้

หมายเหตุ: ฟีเจอร์นี้เปิดใช้โดยค่าเริ่มต้น
ดูเพิ่มเติม

googletag.Service

คลาสบริการพื้นฐานที่มีเมธอดที่ใช้ร่วมกันสำหรับบริการทั้งหมด
เมธอด
addEventListener
ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript ได้เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้า
getSlots
ดูรายการช่องที่เชื่อมโยงกับบริการนี้
removeEventListener
นำผู้ฟังที่ลงทะเบียนไว้ก่อนหน้านี้ออก

เมธอด


addEventListener

addEventListener<K extends keyof EventTypeMap>(eventType: K, listener: ((arg: EventTypeMap[K]) => void)): Service
ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript ได้เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้า ระบบรองรับเหตุการณ์ต่อไปนี้ ระบบจะส่งออบเจ็กต์ประเภทเหตุการณ์ที่เหมาะสมไปยัง Listener เมื่อมีการเรียก
ตัวอย่าง

JavaScript

// 1. Adding an event listener for the PubAdsService.
googletag.pubads().addEventListener("slotOnload", (event) => {
  console.log("Slot has been loaded:");
  console.log(event);
});

// 2. Adding an event listener with slot specific logic.
// Listeners operate at service level, which means that you cannot add
// a listener for an event for a specific slot only. You can, however,
// programmatically filter a listener to respond only to a certain ad
// slot, using this pattern:
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotOnload", (event) => {
  if (event.slot === targetSlot) {
    // Slot specific logic.
  }
});

JavaScript (เดิม)

// 1. Adding an event listener for the PubAdsService.
googletag.pubads().addEventListener("slotOnload", function (event) {
  console.log("Slot has been loaded:");
  console.log(event);
});

// 2. Adding an event listener with slot specific logic.
// Listeners operate at service level, which means that you cannot add
// a listener for an event for a specific slot only. You can, however,
// programmatically filter a listener to respond only to a certain ad
// slot, using this pattern:
var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotOnload", function (event) {
  if (event.slot === targetSlot) {
    // Slot specific logic.
  }
});

TypeScript

// 1. Adding an event listener for the PubAdsService.
googletag.pubads().addEventListener("slotOnload", (event) => {
  console.log("Slot has been loaded:");
  console.log(event);
});

// 2. Adding an event listener with slot specific logic.
// Listeners operate at service level, which means that you cannot add
// a listener for an event for a specific slot only. You can, however,
// programmatically filter a listener to respond only to a certain ad
// slot, using this pattern:
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotOnload", (event) => {
  if (event.slot === targetSlot) {
    // Slot specific logic.
  }
});
ดูเพิ่มเติม
พารามิเตอร์
eventType: Kสตริงที่แสดงถึงประเภทเหตุการณ์ที่ GPT สร้างขึ้น ประเภทเหตุการณ์คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่
listener: ((arg: EventTypeMap[K]) => void)ฟังก์ชันที่ใช้อาร์กิวเมนต์ออบเจ็กต์เหตุการณ์รายการเดียว
การคืนสินค้า
Serviceออบเจ็กต์บริการที่เรียกใช้เมธอด

getSlots

getSlots(): Slot[]
ดูรายการช่องที่เชื่อมโยงกับบริการนี้
การคืนสินค้า
Slot[]ช่องตามลำดับที่เพิ่มลงในบริการ

removeEventListener

removeEventListener<K extends keyof EventTypeMap>(eventType: K, listener: ((event: EventTypeMap[K]) => void)): void
นำผู้ฟังที่ลงทะเบียนไว้ก่อนหน้านี้ออก
ตัวอย่าง

JavaScript

googletag.cmd.push(() => {
  // Define a new ad slot.
  googletag.defineSlot("/6355419/Travel", [728, 90], "div-for-slot").addService(googletag.pubads());

  // Define a new function that removes itself via removeEventListener
  // after the impressionViewable event fires.
  const onViewableListener = (event) => {
    googletag.pubads().removeEventListener("impressionViewable", onViewableListener);
    setTimeout(() => {
      googletag.pubads().refresh([event.slot]);
    }, 30000);
  };

  // Add onViewableListener as a listener for impressionViewable events.
  googletag.pubads().addEventListener("impressionViewable", onViewableListener);
  googletag.enableServices();
});

JavaScript (เดิม)

googletag.cmd.push(function () {
  // Define a new ad slot.
  googletag.defineSlot("/6355419/Travel", [728, 90], "div-for-slot").addService(googletag.pubads());

  // Define a new function that removes itself via removeEventListener
  // after the impressionViewable event fires.
  var onViewableListener = function (event) {
    googletag.pubads().removeEventListener("impressionViewable", onViewableListener);
    setTimeout(function () {
      googletag.pubads().refresh([event.slot]);
    }, 30000);
  };

  // Add onViewableListener as a listener for impressionViewable events.
  googletag.pubads().addEventListener("impressionViewable", onViewableListener);
  googletag.enableServices();
});

TypeScript

googletag.cmd.push(() => {
  // Define a new ad slot.
  googletag
    .defineSlot("/6355419/Travel", [728, 90], "div-for-slot")!
    .addService(googletag.pubads());

  // Define a new function that removes itself via removeEventListener
  // after the impressionViewable event fires.
  const onViewableListener = (event: googletag.events.ImpressionViewableEvent) => {
    googletag.pubads().removeEventListener("impressionViewable", onViewableListener);
    setTimeout(() => {
      googletag.pubads().refresh([event.slot]);
    }, 30000);
  };

  // Add onViewableListener as a listener for impressionViewable events.
  googletag.pubads().addEventListener("impressionViewable", onViewableListener);
  googletag.enableServices();
});
พารามิเตอร์
eventType: Kสตริงที่แสดงถึงประเภทเหตุการณ์ที่ GPT สร้างขึ้น ประเภทเหตุการณ์คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่
listener: ((event: EventTypeMap[K]) => void)ฟังก์ชันที่ใช้อาร์กิวเมนต์ออบเจ็กต์เหตุการณ์รายการเดียว

googletag.SizeMappingBuilder

ตัวสร้างสำหรับออบเจ็กต์ข้อกำหนดการแมปขนาด เครื่องมือสร้างนี้มีไว้เพื่อช่วยสร้างข้อกำหนดด้านขนาดได้อย่างง่ายดาย
เมธอด
addSize
เพิ่มการแมปจากอาร์เรย์ขนาดเดียว (แสดงถึงวิวพอร์ต) ไปยังอาร์เรย์ขนาดเดียวหรือหลายขนาดที่แสดงถึงช่อง
build
สร้างข้อกําหนดแผนที่ขนาดจากการแมปที่เพิ่มลงในเครื่องมือสร้างนี้
ดูเพิ่มเติม

เมธอด


addSize

addSize(viewportSize: SingleSizeArray, slotSize: GeneralSize): SizeMappingBuilder
เพิ่มการแมปจากอาร์เรย์ขนาดเดียว (แสดงถึงวิวพอร์ต) ไปยังอาร์เรย์ขนาดเดียวหรือหลายขนาดที่แสดงถึงช่อง
ตัวอย่าง

JavaScript

// Mapping 1
googletag
  .sizeMapping()
  .addSize([1024, 768], [970, 250])
  .addSize([980, 690], [728, 90])
  .addSize([640, 480], "fluid")
  .addSize([0, 0], [88, 31]) // All viewports &lt; 640x480
  .build();

// Mapping 2
googletag
  .sizeMapping()
  .addSize([1024, 768], [970, 250])
  .addSize([980, 690], [])
  .addSize([640, 480], [120, 60])
  .addSize([0, 0], [])
  .build();

// Mapping 2 will not show any ads for the following viewport sizes:
// [1024, 768] > size >= [980, 690] and
// [640, 480] > size >= [0, 0]

JavaScript (เดิม)

// Mapping 1
googletag
  .sizeMapping()
  .addSize([1024, 768], [970, 250])
  .addSize([980, 690], [728, 90])
  .addSize([640, 480], "fluid")
  .addSize([0, 0], [88, 31]) // All viewports &lt; 640x480
  .build();

// Mapping 2
googletag
  .sizeMapping()
  .addSize([1024, 768], [970, 250])
  .addSize([980, 690], [])
  .addSize([640, 480], [120, 60])
  .addSize([0, 0], [])
  .build();

// Mapping 2 will not show any ads for the following viewport sizes:
// [1024, 768] > size >= [980, 690] and
// [640, 480] > size >= [0, 0]

TypeScript

// Mapping 1
googletag
  .sizeMapping()
  .addSize([1024, 768], [970, 250])
  .addSize([980, 690], [728, 90])
  .addSize([640, 480], "fluid")
  .addSize([0, 0], [88, 31]) // All viewports &lt; 640x480
  .build();

// Mapping 2
googletag
  .sizeMapping()
  .addSize([1024, 768], [970, 250])
  .addSize([980, 690], [])
  .addSize([640, 480], [120, 60])
  .addSize([0, 0], [])
  .build();

// Mapping 2 will not show any ads for the following viewport sizes:
// [1024, 768] > size >= [980, 690] and
// [640, 480] > size >= [0, 0]
พารามิเตอร์
viewportSize: SingleSizeArrayขนาดของวิวพอร์ตสําหรับรายการการแมปนี้
slotSize: GeneralSizeขนาดของช่องสําหรับรายการการแมปนี้
การคืนสินค้า
SizeMappingBuilderการอ้างอิงไปยังเครื่องมือสร้างนี้

build

build(): null | SizeMappingArray
สร้างข้อกําหนดของแผนที่ขนาดจากการแมปที่เพิ่มลงในเครื่องมือสร้างนี้

หากมีการระบุการแมปที่ไม่ถูกต้อง วิธีการนี้จะแสดงผลเป็น null มิเช่นนั้น ระบบจะแสดงผลข้อกําหนดในรูปแบบที่ถูกต้องเพื่อส่งไปยัง Slot.defineSizeMapping

หมายเหตุ: ลักษณะการทํางานของโปรแกรมสร้างหลังจากเรียกใช้เมธอดนี้จะไม่ได้รับการกําหนด
การคืนสินค้า
null | SizeMappingArrayผลลัพธ์ที่สร้างโดยเครื่องมือสร้างนี้ อาจเป็นค่า Null ได้หากมีการระบุการแมปขนาดที่ไม่ถูกต้อง

googletag.Slot

ช่องคือออบเจ็กต์ที่แสดงช่องโฆษณาเดียวในหน้าเว็บ
เมธอด
addService
เพิ่มบริการลงในช่องนี้
clearCategoryExclusions
ล้างป้ายกํากับการยกเว้นหมวดหมู่โฆษณาระดับช่องทั้งหมดสําหรับช่องนี้
clearTargeting
ล้างพารามิเตอร์การกําหนดเป้าหมายระดับช่องที่กําหนดเองที่เฉพาะเจาะจงหรือทั้งหมดสําหรับช่องนี้
defineSizeMapping
ตั้งค่าอาร์เรย์การแมปจากขนาดวิวพอร์ตขั้นต่ำเป็นขนาดช่องสำหรับช่องนี้
get
แสดงค่าสำหรับแอตทริบิวต์ AdSense ที่เชื่อมโยงกับคีย์ที่ระบุสำหรับช่องนี้
getAdUnitPath
แสดงเส้นทางแบบเต็มของหน่วยโฆษณาพร้อมรหัสเครือข่ายและเส้นทางหน่วยโฆษณา
getAttributeKeys
แสดงรายการคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในช่องนี้
getCategoryExclusions
แสดงป้ายกํากับการยกเว้นหมวดหมู่โฆษณาสําหรับช่องนี้
getResponseInformation
แสดงข้อมูลการตอบกลับด้วยโฆษณา
getSlotElementId
แสดงผลรหัสของช่อง div ที่ระบุเมื่อมีการกําหนดช่อง
getTargeting
แสดงผลพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองที่เฉพาะเจาะจงซึ่งตั้งค่าไว้ในช่องนี้
getTargetingKeys
แสดงรายการคีย์การกําหนดเป้าหมายที่กําหนดเองทั้งหมดที่ตั้งค่าไว้ในช่องนี้
set
ตั้งค่าแอตทริบิวต์ AdSense ในช่องโฆษณานี้
setCategoryExclusion
ตั้งค่าป้ายกํากับการยกเว้นหมวดหมู่โฆษณาระดับช่องในช่องนี้
setClickUrl
ตั้งค่า URL การคลิกที่ระบบจะเปลี่ยนเส้นทางผู้ใช้หลังจากคลิกโฆษณา
setCollapseEmptyDiv
ตั้งค่าว่าควรซ่อนช่อง div หรือไม่เมื่อมีโฆษณาในช่อง
setConfig
ตั้งค่าตัวเลือกการกําหนดค่าทั่วไปสําหรับช่องนี้
setForceSafeFrame
กําหนดค่าว่าจะบังคับให้โฆษณาในช่องนี้แสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่
setSafeFrameConfig
ตั้งค่ากำหนดระดับช่องสำหรับการกำหนดค่า SafeFrame
setTargeting
ตั้งค่าพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองสําหรับช่องนี้
updateTargetingFromMap
ตั้งค่าพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองสําหรับช่องนี้จากแผนที่คีย์:ค่าในแออบเจ็กต์ JSON

เมธอด


addService

addService(service: Service): Slot
เพิ่มบริการลงในช่องนี้
ตัวอย่าง

JavaScript

googletag.defineSlot("/1234567/sports", [160, 600], "div").addService(googletag.pubads());

JavaScript (เดิม)

googletag.defineSlot("/1234567/sports", [160, 600], "div").addService(googletag.pubads());

TypeScript

googletag.defineSlot("/1234567/sports", [160, 600], "div")!.addService(googletag.pubads());
ดูเพิ่มเติม
พารามิเตอร์
service: Serviceบริการที่จะเพิ่ม
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

clearCategoryExclusions

clearCategoryExclusions(): Slot
ล้างป้ายกํากับการยกเว้นหมวดหมู่โฆษณาระดับช่องทั้งหมดสําหรับช่องนี้
ตัวอย่าง

JavaScript

// Set category exclusion to exclude ads with 'AirlineAd' labels.
const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setCategoryExclusion("AirlineAd")
  .addService(googletag.pubads());

// Make an ad request. No ad with 'AirlineAd' label will be returned
// for the slot.

// Clear category exclusions so all ads can be returned.
slot.clearCategoryExclusions();

// Make an ad request. Any ad can be returned for the slot.

JavaScript (เดิม)

// Set category exclusion to exclude ads with 'AirlineAd' labels.
var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setCategoryExclusion("AirlineAd")
  .addService(googletag.pubads());

// Make an ad request. No ad with 'AirlineAd' label will be returned
// for the slot.

// Clear category exclusions so all ads can be returned.
slot.clearCategoryExclusions();

// Make an ad request. Any ad can be returned for the slot.

TypeScript

// Set category exclusion to exclude ads with 'AirlineAd' labels.
const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setCategoryExclusion("AirlineAd")
  .addService(googletag.pubads());

// Make an ad request. No ad with 'AirlineAd' label will be returned
// for the slot.

// Clear category exclusions so all ads can be returned.
slot.clearCategoryExclusions();

// Make an ad request. Any ad can be returned for the slot.
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

clearTargeting

clearTargeting(key?: string): Slot
ล้างพารามิเตอร์การกําหนดเป้าหมายระดับช่องที่กําหนดเองที่เฉพาะเจาะจงหรือทั้งหมดสําหรับช่องนี้
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setTargeting("allow_expandable", "true")
  .setTargeting("interests", ["sports", "music"])
  .setTargeting("color", "red")
  .addService(googletag.pubads());

slot.clearTargeting("color");
// Targeting 'allow_expandable' and 'interests' are still present,
// while 'color' was cleared.

slot.clearTargeting();
// All targeting has been cleared.

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setTargeting("allow_expandable", "true")
  .setTargeting("interests", ["sports", "music"])
  .setTargeting("color", "red")
  .addService(googletag.pubads());

slot.clearTargeting("color");
// Targeting 'allow_expandable' and 'interests' are still present,
// while 'color' was cleared.

slot.clearTargeting();
// All targeting has been cleared.

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setTargeting("allow_expandable", "true")
  .setTargeting("interests", ["sports", "music"])
  .setTargeting("color", "red")
  .addService(googletag.pubads());

slot.clearTargeting("color");
// Targeting 'allow_expandable' and 'interests' are still present,
// while 'color' was cleared.

slot.clearTargeting();
// All targeting has been cleared.
ดูเพิ่มเติม
พารามิเตอร์
Optional key: stringคีย์พารามิเตอร์การกําหนดเป้าหมาย คุณไม่จำเป็นต้องระบุคีย์นี้ ระบบจะล้างพารามิเตอร์การกำหนดเป้าหมายทั้งหมดหากไม่ระบุ
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

defineSizeMapping

defineSizeMapping(sizeMapping: SizeMappingArray): Slot
กำหนดอาร์เรย์การแมปจากขนาดวิวพอร์ตขั้นต่ำเป็นขนาดช่องสำหรับช่องนี้
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .addService(googletag.pubads());

const mapping = googletag
  .sizeMapping()
  .addSize([100, 100], [88, 31])
  .addSize(
    [320, 400],
    [
      [320, 50],
      [300, 50],
    ],
  )
  .build();

slot.defineSizeMapping(mapping);

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .addService(googletag.pubads());

var mapping = googletag
  .sizeMapping()
  .addSize([100, 100], [88, 31])
  .addSize(
    [320, 400],
    [
      [320, 50],
      [300, 50],
    ],
  )
  .build();

slot.defineSizeMapping(mapping);

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .addService(googletag.pubads());

const mapping = googletag
  .sizeMapping()
  .addSize([100, 100], [88, 31])
  .addSize(
    [320, 400],
    [
      [320, 50],
      [300, 50],
    ],
  )
  .build();

slot.defineSizeMapping(mapping!);
ดูเพิ่มเติม
พารามิเตอร์
sizeMapping: SizeMappingArrayอาร์เรย์ของการแมปขนาด คุณสามารถใช้ SizeMappingBuilder เพื่อสร้าง การแมปขนาดแต่ละรายการคืออาร์เรย์ขององค์ประกอบ 2 รายการ ได้แก่ SingleSizeArray และ GeneralSize
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

get

get(key: string): null | string
แสดงค่าสำหรับแอตทริบิวต์ AdSense ที่เชื่อมโยงกับคีย์ที่ระบุสำหรับช่องนี้ หากต้องการดูแอตทริบิวต์ระดับบริการที่ช่องนี้รับค่ามา ให้ใช้ PubAdsService.get
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .set("adsense_background_color", "#FFFFFF")
  .addService(googletag.pubads());

slot.get("adsense_background_color");
// Returns '#FFFFFF'.

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .set("adsense_background_color", "#FFFFFF")
  .addService(googletag.pubads());

slot.get("adsense_background_color");
// Returns '#FFFFFF'.

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .set("adsense_background_color", "#FFFFFF")
  .addService(googletag.pubads());

slot.get("adsense_background_color");
// Returns '#FFFFFF'.
ดูเพิ่มเติม
พารามิเตอร์
key: stringชื่อแอตทริบิวต์ที่จะค้นหา
การคืนสินค้า
null | stringค่าปัจจุบันสำหรับคีย์แอตทริบิวต์ หรือ null หากไม่มีคีย์

getAdUnitPath

getAdUnitPath(): string
แสดงเส้นทางแบบเต็มของหน่วยโฆษณาพร้อมรหัสเครือข่ายและเส้นทางหน่วยโฆษณา
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .addService(googletag.pubads());

slot.getAdUnitPath();
// Returns '/1234567/sports'.

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .addService(googletag.pubads());

slot.getAdUnitPath();
// Returns '/1234567/sports'.

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .addService(googletag.pubads());

slot.getAdUnitPath();
// Returns '/1234567/sports'.
การคืนสินค้า
stringเส้นทางหน่วยโฆษณา

getAttributeKeys

getAttributeKeys(): string[]
แสดงรายการคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในช่องนี้ หากต้องการดูคีย์ของแอตทริบิวต์ระดับบริการที่สลอตนี้รับค่ามา ให้ใช้ PubAdsService.getAttributeKeys
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .set("adsense_background_color", "#FFFFFF")
  .set("adsense_border_color", "#AABBCC")
  .addService(googletag.pubads());

slot.getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .set("adsense_background_color", "#FFFFFF")
  .set("adsense_border_color", "#AABBCC")
  .addService(googletag.pubads());

slot.getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .set("adsense_background_color", "#FFFFFF")
  .set("adsense_border_color", "#AABBCC")
  .addService(googletag.pubads());

slot.getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].
การคืนสินค้า
string[]อาร์เรย์ของคีย์แอตทริบิวต์ ไม่ได้ระบุลําดับ

getCategoryExclusions

getCategoryExclusions(): string[]
แสดงผลป้ายกํากับการยกเว้นหมวดหมู่โฆษณาสําหรับช่องนี้
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setCategoryExclusion("AirlineAd")
  .setCategoryExclusion("TrainAd")
  .addService(googletag.pubads());

slot.getCategoryExclusions();
// Returns ['AirlineAd', 'TrainAd'].

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setCategoryExclusion("AirlineAd")
  .setCategoryExclusion("TrainAd")
  .addService(googletag.pubads());

slot.getCategoryExclusions();
// Returns ['AirlineAd', 'TrainAd'].

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setCategoryExclusion("AirlineAd")
  .setCategoryExclusion("TrainAd")
  .addService(googletag.pubads());

slot.getCategoryExclusions();
// Returns ['AirlineAd', 'TrainAd'].
การคืนสินค้า
string[]ป้ายกํากับการยกเว้นหมวดหมู่โฆษณาสําหรับช่องนี้ หรืออาร์เรย์ว่างหากไม่มีการตั้งค่า

getResponseInformation

getResponseInformation(): null | ResponseInformation
แสดงข้อมูลการตอบกลับด้วยโฆษณา ซึ่งอิงตามการตอบสนองของโฆษณาครั้งล่าสุดสำหรับช่อง หากเรียกใช้เมื่อช่องไม่มีโฆษณา ระบบจะแสดง null
การคืนสินค้า
null | ResponseInformationข้อมูลการตอบสนองของโฆษณาล่าสุด หรือ null หากช่องไม่มีโฆษณา

getSlotElementId

getSlotElementId(): string
แสดงผลรหัสของช่อง div ที่ระบุเมื่อมีการกําหนดช่อง
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .addService(googletag.pubads());

slot.getSlotElementId();
// Returns 'div'.

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .addService(googletag.pubads());

slot.getSlotElementId();
// Returns 'div'.

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .addService(googletag.pubads());

slot.getSlotElementId();
// Returns 'div'.
การคืนสินค้า
stringรหัสช่อง div

getTargeting

getTargeting(key: string): string[]
แสดงผลพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองที่เฉพาะเจาะจงซึ่งตั้งค่าไว้ในช่องนี้ โดยไม่รวมพารามิเตอร์การกำหนดเป้าหมายระดับบริการ
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setTargeting("allow_expandable", "true")
  .addService(googletag.pubads());

slot.getTargeting("allow_expandable");
// Returns ['true'].

slot.getTargeting("age");
// Returns [] (empty array).

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setTargeting("allow_expandable", "true")
  .addService(googletag.pubads());

slot.getTargeting("allow_expandable");
// Returns ['true'].

slot.getTargeting("age");
// Returns [] (empty array).

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setTargeting("allow_expandable", "true")
  .addService(googletag.pubads());

slot.getTargeting("allow_expandable");
// Returns ['true'].

slot.getTargeting("age");
// Returns [] (empty array).
พารามิเตอร์
key: stringคีย์การกําหนดเป้าหมายที่จะค้นหา
การคืนสินค้า
string[]ค่าที่เชื่อมโยงกับคีย์นี้ หรืออาร์เรย์ว่างหากไม่มีคีย์ดังกล่าว

getTargetingKeys

getTargetingKeys(): string[]
แสดงรายการคีย์การกําหนดเป้าหมายที่กําหนดเองทั้งหมดที่ตั้งค่าไว้ในช่องนี้ โดยไม่รวมคีย์การกําหนดเป้าหมายระดับบริการ
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setTargeting("allow_expandable", "true")
  .setTargeting("interests", ["sports", "music"])
  .addService(googletag.pubads());

slot.getTargetingKeys();
// Returns ['interests', 'allow_expandable'].

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setTargeting("allow_expandable", "true")
  .setTargeting("interests", ["sports", "music"])
  .addService(googletag.pubads());

slot.getTargetingKeys();
// Returns ['interests', 'allow_expandable'].

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setTargeting("allow_expandable", "true")
  .setTargeting("interests", ["sports", "music"])
  .addService(googletag.pubads());

slot.getTargetingKeys();
// Returns ['interests', 'allow_expandable'].
การคืนสินค้า
string[]อาร์เรย์ของคีย์การกําหนดเป้าหมาย ไม่ได้ระบุลําดับ

set

set(key: string, value: string): Slot
ตั้งค่าแอตทริบิวต์ AdSense ในช่องโฆษณานี้ ซึ่งจะลบล้างค่าที่กำหนดไว้ที่ระดับบริการสำหรับคีย์นี้

การเรียกใช้เมธอดนี้มากกว่า 1 ครั้งสำหรับคีย์เดียวกันจะลบล้างค่าที่กำหนดไว้ก่อนหน้านี้สำหรับคีย์นั้น คุณต้องตั้งค่าทุกค่าก่อนเรียกใช้ display หรือ refresh
ตัวอย่าง

JavaScript

// Setting an attribute on a single ad slot.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .set("adsense_background_color", "#FFFFFF")
  .addService(googletag.pubads());

JavaScript (เดิม)

// Setting an attribute on a single ad slot.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .set("adsense_background_color", "#FFFFFF")
  .addService(googletag.pubads());

TypeScript

// Setting an attribute on a single ad slot.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .set("adsense_background_color", "#FFFFFF")
  .addService(googletag.pubads());
ดูเพิ่มเติม
พารามิเตอร์
key: stringชื่อแอตทริบิวต์
value: stringค่าแอตทริบิวต์
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

setCategoryExclusion

setCategoryExclusion(categoryExclusion: string): Slot
ตั้งค่าป้ายกํากับการยกเว้นหมวดหมู่โฆษณาระดับช่องในช่องนี้
ตัวอย่าง

JavaScript

// Label = AirlineAd
googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setCategoryExclusion("AirlineAd")
  .addService(googletag.pubads());

JavaScript (เดิม)

// Label = AirlineAd
googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setCategoryExclusion("AirlineAd")
  .addService(googletag.pubads());

TypeScript

// Label = AirlineAd
googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setCategoryExclusion("AirlineAd")
  .addService(googletag.pubads());
ดูเพิ่มเติม
พารามิเตอร์
categoryExclusion: stringป้ายกํากับการยกเว้นหมวดหมู่โฆษณาที่จะเพิ่ม
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

setClickUrl

setClickUrl(value: string): Slot
ตั้งค่า URL การคลิกที่ระบบจะเปลี่ยนเส้นทางผู้ใช้หลังจากคลิกโฆษณา

เซิร์ฟเวอร์ Google Ad Manager จะยังคงบันทึกการคลิกแม้ว่าจะมีการแทนที่ URL การคลิกก็ตาม ระบบจะเพิ่ม URL ของหน้า Landing Page ที่เชื่อมโยงกับครีเอทีฟโฆษณาที่แสดงต่อท้ายค่าที่ระบุ การเรียกใช้ครั้งต่อๆ ไปจะเขียนทับค่า วิธีนี้ใช้ได้กับคำขอที่ไม่ใช่ SRA เท่านั้น
ตัวอย่าง

JavaScript

googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setClickUrl("http://www.example.com?original_click_url=")
  .addService(googletag.pubads());

JavaScript (เดิม)

googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setClickUrl("http://www.example.com?original_click_url=")
  .addService(googletag.pubads());

TypeScript

googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setClickUrl("http://www.example.com?original_click_url=")
  .addService(googletag.pubads());
พารามิเตอร์
value: stringURL คลิกที่จะตั้งค่า
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

setCollapseEmptyDiv

setCollapseEmptyDiv(collapse: boolean, collapseBeforeAdFetch?: boolean): Slot
ตั้งค่าว่าควรซ่อนช่อง div หรือไม่เมื่อมีโฆษณาในช่อง ซึ่งจะลบล้างการตั้งค่าระดับบริการ
ตัวอย่าง

JavaScript

googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")
  .setCollapseEmptyDiv(true, true)
  .addService(googletag.pubads());
// The above will cause the div for this slot to be collapsed
// when the page is loaded, before ads are requested.

googletag
  .defineSlot("/1234567/sports", [160, 600], "div-2")
  .setCollapseEmptyDiv(true)
  .addService(googletag.pubads());
// The above will cause the div for this slot to be collapsed
// only after GPT detects that no ads are available for the slot.

JavaScript (เดิม)

googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")
  .setCollapseEmptyDiv(true, true)
  .addService(googletag.pubads());
// The above will cause the div for this slot to be collapsed
// when the page is loaded, before ads are requested.

googletag
  .defineSlot("/1234567/sports", [160, 600], "div-2")
  .setCollapseEmptyDiv(true)
  .addService(googletag.pubads());
// The above will cause the div for this slot to be collapsed
// only after GPT detects that no ads are available for the slot.

TypeScript

googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")!
  .setCollapseEmptyDiv(true, true)
  .addService(googletag.pubads());
// The above will cause the div for this slot to be collapsed
// when the page is loaded, before ads are requested.

googletag
  .defineSlot("/1234567/sports", [160, 600], "div-2")!
  .setCollapseEmptyDiv(true)
  .addService(googletag.pubads());
// The above will cause the div for this slot to be collapsed
// only after GPT detects that no ads are available for the slot.
ดูเพิ่มเติม
พารามิเตอร์
collapse: booleanเลือกว่าจะยุบช่องหรือไม่หากไม่มีการแสดงโฆษณา
Optional collapseBeforeAdFetch: booleanต้องการยุบช่องก่อนที่จะดึงข้อมูลโฆษณาหรือไม่ ละเว้นหาก collapse ไม่ใช่ true
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

setConfig

setConfig(slotConfig: SlotSettingsConfig): void
ตั้งค่าตัวเลือกการกําหนดค่าทั่วไปสําหรับช่องนี้
พารามิเตอร์
slotConfig: SlotSettingsConfigออบเจ็กต์การกําหนดค่า

setForceSafeFrame

setForceSafeFrame(forceSafeFrame: boolean): Slot
กําหนดค่าว่าควรบังคับให้โฆษณาในช่องนี้แสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่

โปรดคํานึงถึงสิ่งต่อไปนี้ขณะใช้ API นี้
  • การตั้งค่านี้จะมีผลกับคำขอโฆษณาที่ตามมาซึ่งส่งสําหรับช่องที่เกี่ยวข้องเท่านั้น
  • การตั้งค่าระดับช่อง (หากระบุ) จะลบล้างการตั้งค่าระดับหน้าเสมอ
  • หากตั้งค่าเป็น true (ที่ระดับช่องหรือระดับหน้า) โฆษณาจะแสดงผลด้วยคอนเทนเนอร์ SafeFrame เสมอ โดยไม่ขึ้นอยู่กับตัวเลือกที่เลือกใน UI ของ Google Ad Manager
  • อย่างไรก็ตาม หากตั้งค่าเป็น false หรือไม่ได้ระบุไว้ ระบบจะแสดงผลโฆษณาโดยใช้คอนเทนเนอร์ SafeFrame โดยขึ้นอยู่กับประเภทของครีเอทีฟโฆษณาและการเลือกที่ทำใน UI ของ Google Ad Manager
  • คุณควรใช้ API นี้อย่างระมัดระวังเนื่องจากอาจส่งผลต่อลักษณะการทํางานของครีเอทีฟโฆษณาที่พยายามจะออกจาก iframe หรืออาศัยการแสดงผลในหน้าของผู้เผยแพร่โฆษณาโดยตรง
ตัวอย่าง

JavaScript

googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setForceSafeFrame(true)
  .addService(googletag.pubads());

JavaScript (เดิม)

googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .setForceSafeFrame(true)
  .addService(googletag.pubads());

TypeScript

googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setForceSafeFrame(true)
  .addService(googletag.pubads());
ดูเพิ่มเติม
พารามิเตอร์
forceSafeFrame: booleantrue เพื่อบังคับให้โฆษณาทั้งหมดในช่องนี้แสดงผลใน SafeFrame และ false เพื่อเลือกไม่ใช้การตั้งค่าระดับหน้า (หากมี) การตั้งค่านี้เป็น false เมื่อไม่ได้ระบุที่ระดับหน้าเว็บจะไม่เปลี่ยนแปลงอะไร
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

setSafeFrameConfig

setSafeFrameConfig(config: null | SafeFrameConfig): Slot
ตั้งค่ากำหนดระดับช่องสำหรับการกำหนดค่า SafeFrame ระบบจะไม่สนใจคีย์ที่ไม่รู้จักในออบเจ็กต์การกําหนดค่า ระบบจะไม่สนใจการกําหนดค่าทั้งหมดหากมีการส่งค่าที่ไม่ถูกต้องสําหรับคีย์ที่รู้จัก

ค่ากําหนดระดับช่องเหล่านี้ (หากระบุ) จะลบล้างค่ากําหนดระดับหน้า
ตัวอย่าง

JavaScript

googletag.pubads().setForceSafeFrame(true);

// The following slot will have a sandboxed safeframe that only
// disallows top-level navigation.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")
  .setSafeFrameConfig({ sandbox: true })
  .addService(googletag.pubads());

// The following slot will inherit page-level settings.
googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads());

googletag.display("div-1");
googletag.display("div-2");

JavaScript (เดิม)

googletag.pubads().setForceSafeFrame(true);

// The following slot will have a sandboxed safeframe that only
// disallows top-level navigation.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")
  .setSafeFrameConfig({ sandbox: true })
  .addService(googletag.pubads());

// The following slot will inherit page-level settings.
googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads());

googletag.display("div-1");
googletag.display("div-2");

TypeScript

googletag.pubads().setForceSafeFrame(true);

// The following slot will have a sandboxed safeframe that only
// disallows top-level navigation.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div-1")!
  .setSafeFrameConfig({ sandbox: true })
  .addService(googletag.pubads());

// The following slot will inherit page-level settings.
googletag.defineSlot("/1234567/news", [160, 600], "div-2")!.addService(googletag.pubads());

googletag.display("div-1");
googletag.display("div-2");
ดูเพิ่มเติม
พารามิเตอร์
config: null | SafeFrameConfigออบเจ็กต์การกําหนดค่า
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

setTargeting

setTargeting(key: string, value: string | string[]): Slot
ตั้งค่าพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองสําหรับช่องนี้ การเรียกใช้เมธอดนี้หลายครั้งสําหรับคีย์เดียวกันจะเป็นการเขียนทับค่าเก่า ค่าที่ตั้งไว้ที่นี่จะเขียนทับพารามิเตอร์การกําหนดเป้าหมายที่ตั้งไว้ที่ระดับบริการ คีย์เหล่านี้จะกําหนดไว้ในบัญชี Google Ad Manager
ตัวอย่าง

JavaScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .addService(googletag.pubads());

// Example with a single value for a key.
slot.setTargeting("allow_expandable", "true");

// Example with multiple values for a key inside in an array.
slot.setTargeting("interests", ["sports", "music"]);

JavaScript (เดิม)

var slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")
  .addService(googletag.pubads());

// Example with a single value for a key.
slot.setTargeting("allow_expandable", "true");

// Example with multiple values for a key inside in an array.
slot.setTargeting("interests", ["sports", "music"]);

TypeScript

const slot = googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .addService(googletag.pubads());

// Example with a single value for a key.
slot.setTargeting("allow_expandable", "true");

// Example with multiple values for a key inside in an array.
slot.setTargeting("interests", ["sports", "music"]);
ดูเพิ่มเติม
พารามิเตอร์
key: stringคีย์พารามิเตอร์การกําหนดเป้าหมาย
value: string | string[]ค่าพารามิเตอร์การกําหนดเป้าหมายหรืออาร์เรย์ของค่า
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

updateTargetingFromMap

updateTargetingFromMap(map: {
  [adUnitPath: string]: string | string[];
}): Slot
ตั้งค่าพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองสําหรับช่องนี้จากแผนที่คีย์:ค่าในแออบเจ็กต์ JSON ซึ่งเหมือนกับการเรียก Slot.setTargeting สำหรับค่าคีย์ทั้งหมดของออบเจ็กต์ คีย์เหล่านี้จะกำหนดไว้ในบัญชี Google Ad Manager

หมายเหตุ:
  • ในกรณีที่มีการเขียนทับ ระบบจะเก็บเฉพาะค่าสุดท้ายไว้
  • หากค่าเป็นอาร์เรย์ ระบบจะเขียนทับค่าก่อนหน้า ไม่ใช่ผสานรวม
  • ค่าที่ตั้งไว้ที่นี่จะเขียนทับพารามิเตอร์การกําหนดเป้าหมายที่ตั้งไว้ที่ระดับบริการ
ตัวอย่าง

JavaScript

const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div");

slot.updateTargetingFromMap({
  color: "red",
  interests: ["sports", "music", "movies"],
});

JavaScript (เดิม)

var slot = googletag.defineSlot("/1234567/sports", [160, 600], "div");

slot.updateTargetingFromMap({
  color: "red",
  interests: ["sports", "music", "movies"],
});

TypeScript

const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div")!;

slot.updateTargetingFromMap({
  color: "red",
  interests: ["sports", "music", "movies"],
});
พารามิเตอร์
map: {
  [adUnitPath: string]: string | string[];
}
การแมปคีย์:ค่าของพารามิเตอร์การกําหนดเป้าหมาย
การคืนสินค้า
Slotออบเจ็กต์ช่องที่เรียกใช้เมธอด

googletag.config

อินเทอร์เฟซการกําหนดค่าหลักสําหรับการตั้งค่าระดับหน้า
อินเทอร์เฟซ
AdExpansionConfig
การตั้งค่าเพื่อควบคุมการขยายโฆษณา
ComponentAuctionConfig
ออบเจ็กต์ที่แสดงการประมูลคอมโพเนนต์เดียวในการประมูลโฆษณาบนอุปกรณ์
InterstitialConfig
ออบเจ็กต์ที่กําหนดลักษณะการทํางานของสล็อตโฆษณาคั่นระหว่างหน้ารายการเดียว
PageSettingsConfig
อินเทอร์เฟซการกําหนดค่าหลักสําหรับการตั้งค่าระดับหน้า
PrivacyTreatmentsConfig
การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา
PublisherProvidedSignalsConfig
ออบเจ็กต์การกําหนดค่าสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS)
SlotSettingsConfig
อินเทอร์เฟซการกําหนดค่าหลักสําหรับการตั้งค่าระดับช่อง
TaxonomyData
ออบเจ็กต์ที่มีค่าสำหรับการจัดหมวดหมู่เดียว
ประเภทอีเมลแทน
InterstitialTrigger
ทริกเกอร์โฆษณาคั่นระหว่างหน้าที่รองรับ
PrivacyTreatment
การดูแลด้านความเป็นส่วนตัวของผู้เผยแพร่โฆษณาที่รองรับ
Taxonomy
การจัดหมวดหมู่ที่รองรับสำหรับสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS)

ประเภทอีเมลแทน


InterstitialTrigger

InterstitialTrigger: "unhideWindow" | "navBar"
ทริกเกอร์โฆษณาคั่นระหว่างหน้าที่รองรับ

PrivacyTreatment

PrivacyTreatment: "disablePersonalization"
การดูแลด้านความเป็นส่วนตัวของผู้เผยแพร่โฆษณาที่รองรับ

การจัดหมวดหมู่


googletag.config.AdExpansionConfig

การตั้งค่าเพื่อควบคุมการขยายโฆษณา
พร็อพเพอร์ตี้
enabled?
การเปิดหรือปิดใช้การขยายโฆษณา
ตัวอย่าง

JavaScript

// Enable ad slot expansion across the entire page.
googletag.setConfig({
  adExpansion: { enabled: true },
});

JavaScript (เดิม)

// Enable ad slot expansion across the entire page.
googletag.setConfig({
  adExpansion: { enabled: true },
});

TypeScript

// Enable ad slot expansion across the entire page.
googletag.setConfig({
  adExpansion: { enabled: true },
});

พร็อพเพอร์ตี้


Optional เปิดใช้

enabled?: null | boolean
การเปิดหรือปิดใช้การขยายโฆษณา

การตั้งค่านี้จะลบล้างค่าเริ่มต้นที่กำหนดค่าไว้ใน Google Ad Manager
ดูเพิ่มเติม

googletag.config.ComponentAuctionConfig

ออบเจ็กต์ที่แสดงการประมูลคอมโพเนนต์เดียวในการประมูลโฆษณาบนอุปกรณ์
พร็อพเพอร์ตี้
auctionConfig
ออบเจ็กต์การกําหนดค่าการประมูลสําหรับการประมูลคอมโพเนนต์นี้
configKey
คีย์การกําหนดค่าที่เชื่อมโยงกับการประมูลคอมโพเนนต์นี้
ดูเพิ่มเติม

พร็อพเพอร์ตี้


auctionConfig

auctionConfig: null | {
  auctionSignals?: unknown;
  decisionLogicURL: string;
  interestGroupBuyers?: string[];
  perBuyerExperimentGroupIds?: {
    [buyer: string]: number;
  };
  perBuyerGroupLimits?: {
    [buyer: string]: number;
  };
  perBuyerSignals?: {
    [buyer: string]: unknown;
  };
  perBuyerTimeouts?: {
    [buyer: string]: number;
  };
  seller: string;
  sellerExperimentGroupId?: number;
  sellerSignals?: unknown;
  sellerTimeout?: number;
  trustedScoringSignalsURL?: string;
}
ออบเจ็กต์การกําหนดค่าการประมูลสําหรับการประมูลคอมโพเนนต์นี้

หากตั้งค่านี้เป็น null ระบบจะลบการกําหนดค่าที่มีอยู่สําหรับ configKey ที่ระบุ
ตัวอย่าง

JavaScript

const componentAuctionConfig = {
  // Seller URL should be https and the same as decisionLogicURL's origin
  seller: "https://testSeller.com",
  decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js",
  interestGroupBuyers: ["https://example-buyer.com"],
  auctionSignals: { auction_signals: "auction_signals" },
  sellerSignals: { seller_signals: "seller_signals" },
  perBuyerSignals: {
    // listed on interestGroupBuyers
    "https://example-buyer.com": {
      per_buyer_signals: "per_buyer_signals",
    },
  },
};

const auctionSlot = googletag.defineSlot("/1234567/example", [160, 600]);

// To add configKey to the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: componentAuctionConfig,
    },
  ],
});

// To remove configKey from the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: null,
    },
  ],
});

JavaScript (เดิม)

var componentAuctionConfig = {
  // Seller URL should be https and the same as decisionLogicURL's origin
  seller: "https://testSeller.com",
  decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js",
  interestGroupBuyers: ["https://example-buyer.com"],
  auctionSignals: { auction_signals: "auction_signals" },
  sellerSignals: { seller_signals: "seller_signals" },
  perBuyerSignals: {
    // listed on interestGroupBuyers
    "https://example-buyer.com": {
      per_buyer_signals: "per_buyer_signals",
    },
  },
};

var auctionSlot = googletag.defineSlot("/1234567/example", [160, 600]);

// To add configKey to the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: componentAuctionConfig,
    },
  ],
});

// To remove configKey from the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: null,
    },
  ],
});

TypeScript

const componentAuctionConfig = {
  // Seller URL should be https and the same as decisionLogicURL's origin
  seller: "https://testSeller.com",
  decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js",
  interestGroupBuyers: ["https://example-buyer.com"],
  auctionSignals: { auction_signals: "auction_signals" },
  sellerSignals: { seller_signals: "seller_signals" },
  perBuyerSignals: {
    // listed on interestGroupBuyers
    "https://example-buyer.com": {
      per_buyer_signals: "per_buyer_signals",
    },
  },
};

const auctionSlot = googletag.defineSlot("/1234567/example", [160, 600])!;

// To add configKey to the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: componentAuctionConfig,
    },
  ],
});

// To remove configKey from the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: null,
    },
  ],
});
ดูเพิ่มเติม

configKey

configKey: string
คีย์การกําหนดค่าที่เชื่อมโยงกับการประมูลคอมโพเนนต์นี้

ค่านี้ต้องไม่ว่างเปล่าและควรไม่ซ้ำกัน หากออบเจ็กต์ ComponentAuctionConfig 2 รายการมีค่า configKey เดียวกัน ระบบจะเขียนทับการกําหนดค่าก่อนหน้าด้วยค่าล่าสุดที่ตั้งไว้

googletag.config.InterstitialConfig

ออบเจ็กต์ที่กําหนดลักษณะการทํางานของสล็อตโฆษณาคั่นระหว่างหน้ารายการเดียว
พร็อพเพอร์ตี้
requireStorageAccess?
จำเป็นต้องขอความยินยอมในการจัดเก็บข้อมูลในเครื่องเพื่อแสดงโฆษณาคั่นระหว่างหน้านี้หรือไม่
triggers?
การกําหนดค่าทริกเกอร์โฆษณาคั่นระหว่างหน้าสําหรับโฆษณาคั่นระหว่างหน้านี้

พร็อพเพอร์ตี้


Optional requireStorageAccess

requireStorageAccess?: null | boolean
จำเป็นต้องได้รับความยินยอมในการใช้พื้นที่เก็บข้อมูลในเครื่องเพื่อแสดงโฆษณาคั่นระหว่างหน้านี้หรือไม่

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

JavaScript

// Opt out of showing interstitials to users
// without local storage consent.
const interstitialSlot = googletag.defineOutOfPageSlot(
  "/1234567/sports",
  googletag.enums.OutOfPageFormat.INTERSTITIAL,
);

interstitialSlot.setConfig({
  interstitial: {
    requireStorageAccess: true, // defaults to false
  },
});

JavaScript (เดิม)

// Opt out of showing interstitials to users
// without local storage consent.
var interstitialSlot = googletag.defineOutOfPageSlot(
  "/1234567/sports",
  googletag.enums.OutOfPageFormat.INTERSTITIAL,
);

interstitialSlot.setConfig({
  interstitial: {
    requireStorageAccess: true, // defaults to false
  },
});

TypeScript

// Opt out of showing interstitials to users
// without local storage consent.
const interstitialSlot = googletag.defineOutOfPageSlot(
  "/1234567/sports",
  googletag.enums.OutOfPageFormat.INTERSTITIAL,
)!;

interstitialSlot.setConfig({
  interstitial: {
    requireStorageAccess: true, // defaults to false
  },
});
ดูเพิ่มเติม

Optional ทริกเกอร์

triggers?: null | Partial<Record<InterstitialTrigger, boolean>>
การกําหนดค่าทริกเกอร์โฆษณาคั่นระหว่างหน้าสําหรับโฆษณาคั่นระหว่างหน้านี้

การตั้งค่าค่าของทริกเกอร์โฆษณาคั่นระหว่างหน้าเป็น true จะเปิดใช้ และ false จะปิดใช้ ซึ่งจะลบล้างค่าเริ่มต้นที่กําหนดค่าใน Google Ad Manager
ตัวอย่าง

JavaScript

// Define a GPT managed web interstitial ad slot.
const interstitialSlot = googletag.defineOutOfPageSlot(
  "/1234567/sports",
  googletag.enums.OutOfPageFormat.INTERSTITIAL,
);

// Enable optional interstitial triggers.
// Change this value to false to disable.
const enableTriggers = true;

interstitialSlot.setConfig({
  interstitial: {
    triggers: {
      navBar: enableTriggers,
      unhideWindow: enableTriggers,
    },
  },
});

JavaScript (เดิม)

// Define a GPT managed web interstitial ad slot.
var interstitialSlot = googletag.defineOutOfPageSlot(
  "/1234567/sports",
  googletag.enums.OutOfPageFormat.INTERSTITIAL,
);

// Enable optional interstitial triggers.
// Change this value to false to disable.
var enableTriggers = true;

interstitialSlot.setConfig({
  interstitial: {
    triggers: {
      navBar: enableTriggers,
      unhideWindow: enableTriggers,
    },
  },
});

TypeScript

// Define a GPT managed web interstitial ad slot.
const interstitialSlot = googletag.defineOutOfPageSlot(
  "/1234567/sports",
  googletag.enums.OutOfPageFormat.INTERSTITIAL,
)!;

// Enable optional interstitial triggers.
// Change this value to false to disable.
const enableTriggers = true;

interstitialSlot.setConfig({
  interstitial: {
    triggers: {
      navBar: enableTriggers,
      unhideWindow: enableTriggers,
    },
  },
});
ดูเพิ่มเติม

googletag.config.PageSettingsConfig

อินเทอร์เฟซการกําหนดค่าหลักสําหรับการตั้งค่าระดับหน้า

อนุญาตให้ตั้งค่าฟีเจอร์หลายรายการด้วยการเรียก API ครั้งเดียว

พร็อพเพอร์ตี้ทั้งหมดที่แสดงด้านล่างเป็นตัวอย่างและไม่ได้แสดงถึงฟีเจอร์จริงที่ใช้ setConfig ดูชุดฟีเจอร์ได้ที่ช่องภายในประเภท PageSettingsConfig ด้านล่าง

ตัวอย่าง
  • ระบบจะแก้ไขเฉพาะฟีเจอร์ที่ระบุในการเรียกใช้ googletag.setConfig
      // Configure feature alpha.
      googletag.setConfig({
          alpha: {...}
      });
    
      // Configure feature bravo. Feature alpha is unchanged.
      googletag.setConfig({
         bravo: {...}
      });
  • การตั้งค่าทั้งหมดสําหรับฟีเจอร์หนึ่งๆ จะอัปเดตทุกครั้งที่มีการเรียกใช้ googletag.setConfig
      // Configure feature charlie to echo = 1, foxtrot = true.
      googletag.setConfig({
          charlie: {
              echo: 1,
              foxtrot: true,
          }
      });
    
      // Update feature charlie to echo = 2. Since foxtrot was not specified,
      // the value is cleared.
      googletag.setConfig({
          charlie: {
              echo: 2
          }
      });
  • คุณล้างการตั้งค่าทั้งหมดของฟีเจอร์ได้โดยส่ง null
      // Configure features delta, golf, and hotel.
      googletag.setConfig({
          delta: {...},
          golf: {...},
          hotel: {...},
      });
    
      // Feature delta and hotel are cleared, but feature golf remains set.
      googletag.setConfig({
          delta: null,
          hotel: null,
      });
พร็อพเพอร์ตี้
adExpansion?
การตั้งค่าเพื่อควบคุมการขยายโฆษณา
adYield?
เลิกใช้งานแล้ว 
pps?
การตั้งค่าเพื่อควบคุมสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS)
privacyTreatments?
การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา
threadYield?
การตั้งค่าเพื่อควบคุมว่า GPT ควรสร้างเธรด JS เมื่อแสดงผลครีเอทีฟโฆษณาหรือไม่

พร็อพเพอร์ตี้


Optional adExpansion

adExpansion?: null | AdExpansionConfig
การตั้งค่าเพื่อควบคุมการขยายโฆษณา

Optional adYield

adYield?: null | "DISABLED" | "ENABLED_ALL_SLOTS"

Optional pps

การตั้งค่าเพื่อควบคุมสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS)

Optional privacyTreatments

privacyTreatments?: null | PrivacyTreatmentsConfig
การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา

Optional threadYield

threadYield?: null | "DISABLED" | "ENABLED_ALL_SLOTS"
การตั้งค่าเพื่อควบคุมว่า GPT ควรแสดงผลเธรด JS เมื่อแสดงผลครีเอทีฟโฆษณาหรือไม่

GPT จะแสดงผลสําหรับเบราว์เซอร์ที่รองรับ Scheduler.postTask หรือ Scheduler.yield API เท่านั้น

ค่าที่รองรับ:
  • null (ค่าเริ่มต้น): GPT จะแสดงผลชุดข้อความ JS สําหรับช่องที่อยู่นอกวิวพอร์ต
  • ENABLED_ALL_SLOTS: GPT จะแสดงผลเธรด JS สําหรับทุกช่อง ไม่ว่าช่องจะอยู่ภายในวิวพอร์ตหรือไม่ก็ตาม
  • DISABLED: GPT จะไม่แสดงชุดข้อความ JS
ตัวอย่าง

JavaScript

// Disable yielding.
googletag.setConfig({ threadYield: "DISABLED" });

// Enable yielding for all slots.
googletag.setConfig({ threadYield: "ENABLED_ALL_SLOTS" });

// Enable yielding only for slots outside of the viewport (default).
googletag.setConfig({ threadYield: null });

JavaScript (เดิม)

// Disable yielding.
googletag.setConfig({ threadYield: "DISABLED" });

// Enable yielding for all slots.
googletag.setConfig({ threadYield: "ENABLED_ALL_SLOTS" });

// Enable yielding only for slots outside of the viewport (default).
googletag.setConfig({ threadYield: null });

TypeScript

// Disable yielding.
googletag.setConfig({ threadYield: "DISABLED" });

// Enable yielding for all slots.
googletag.setConfig({ threadYield: "ENABLED_ALL_SLOTS" });

// Enable yielding only for slots outside of the viewport (default).
googletag.setConfig({ threadYield: null });
ดูเพิ่มเติม

googletag.config.PrivacyTreatmentsConfig

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

พร็อพเพอร์ตี้


treatments

treatments: null | "disablePersonalization"[]
การดูแลด้านความเป็นส่วนตัวสำหรับผู้เผยแพร่โฆษณาที่หลากหลายเพื่อเปิดใช้
ตัวอย่าง

JavaScript

// Disable personalization across the entire page.
googletag.setConfig({
  privacyTreatments: { treatments: ["disablePersonalization"] },
});

JavaScript (เดิม)

// Disable personalization across the entire page.
googletag.setConfig({
  privacyTreatments: { treatments: ["disablePersonalization"] },
});

TypeScript

// Disable personalization across the entire page.
googletag.setConfig({
  privacyTreatments: { treatments: ["disablePersonalization"] },
});

googletag.config.PublisherProvidedSignalsConfig

ออบเจ็กต์การกําหนดค่าสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS)
พร็อพเพอร์ตี้
taxonomies
ออบเจ็กต์ที่มีการแมปการจัดหมวดหมู่
ตัวอย่าง

JavaScript

googletag.setConfig({
  pps: {
    taxonomies: {
      IAB_AUDIENCE_1_1: { values: ["6", "626"] },
      // '6' = 'Demographic | Age Range | 30-34'
      // '626' = 'Interest | Sports | Darts'
      IAB_CONTENT_2_2: { values: ["48", "127"] },
      // '48' = 'Books and Literature | Fiction'
      // '127' = 'Careers | Job Search'
    },
  },
});

JavaScript (เดิม)

googletag.setConfig({
  pps: {
    taxonomies: {
      IAB_AUDIENCE_1_1: { values: ["6", "626"] },
      // '6' = 'Demographic | Age Range | 30-34'
      // '626' = 'Interest | Sports | Darts'
      IAB_CONTENT_2_2: { values: ["48", "127"] },
      // '48' = 'Books and Literature | Fiction'
      // '127' = 'Careers | Job Search'
    },
  },
});

TypeScript

googletag.setConfig({
  pps: {
    taxonomies: {
      IAB_AUDIENCE_1_1: { values: ["6", "626"] },
      // '6' = 'Demographic | Age Range | 30-34'
      // '626' = 'Interest | Sports | Darts'
      IAB_CONTENT_2_2: { values: ["48", "127"] },
      // '48' = 'Books and Literature | Fiction'
      // '127' = 'Careers | Job Search'
    },
  },
});
ดูเพิ่มเติม

พร็อพเพอร์ตี้


การจัดหมวดหมู่

taxonomies: Partial<Record<Taxonomy, TaxonomyData>>
ออบเจ็กต์ที่มีการแมปการจัดหมวดหมู่

googletag.config.SlotSettingsConfig

อินเทอร์เฟซการกําหนดค่าหลักสําหรับการตั้งค่าระดับช่อง

อนุญาตให้ตั้งค่าฟีเจอร์หลายรายการด้วยการเรียก API ครั้งเดียวสําหรับช่องเดียว

พร็อพเพอร์ตี้ทั้งหมดที่แสดงด้านล่างเป็นตัวอย่างและไม่ได้แสดงถึงฟีเจอร์จริงที่ใช้ setConfig สำหรับชุดฟีเจอร์ ให้ดูช่องภายในประเภท SlotSettingsConfig ด้านล่าง

ตัวอย่าง
  • ระบบจะแก้ไขเฉพาะฟีเจอร์ที่ระบุในการเรียก Slot.setConfig เท่านั้น
      const slot = googletag.defineSlot("/1234567/example", [160, 600]);
    
      // Configure feature alpha.
      slot.setConfig({
          alpha: {...}
      });
    
      // Configure feature bravo. Feature alpha is unchanged.
      slot.setConfig({
         bravo: {...}
      });
  • การตั้งค่าทั้งหมดสำหรับฟีเจอร์หนึ่งๆ จะอัปเดตทุกครั้งที่มีการเรียกใช้ Slot.setConfig
      // Configure feature charlie to echo = 1, foxtrot = true.
      slot.setConfig({
          charlie: {
              echo: 1,
              foxtrot: true,
          }
      });
    
      // Update feature charlie to echo = 2. Since foxtrot was not specified,
      // the value is cleared.
      slot.setConfig({
          charlie: {
              echo: 2
          }
      });
  • คุณล้างการตั้งค่าทั้งหมดของฟีเจอร์ได้โดยส่ง null
      // Configure features delta, golf, and hotel.
      slot.setConfig({
          delta: {...},
          golf: {...},
          hotel: {...},
      });
    
      // Feature delta and hotel are cleared, but feature golf remains set.
      slot.setConfig({
          delta: null,
          hotel: null,
      });
พร็อพเพอร์ตี้
adExpansion?
การตั้งค่าเพื่อควบคุมการขยายโฆษณา
componentAuction?
อาร์เรย์ของการประมูลคอมโพเนนต์ที่จะรวมอยู่ในการประมูลโฆษณาบนอุปกรณ์
interstitial?
การตั้งค่าที่ควบคุมลักษณะการทํางานของช่องโฆษณาคั่นระหว่างหน้า

พร็อพเพอร์ตี้


Optional adExpansion

adExpansion?: null | AdExpansionConfig
การตั้งค่าเพื่อควบคุมการขยายโฆษณา

Optional componentAuction

componentAuction?: null | ComponentAuctionConfig[]
อาร์เรย์ของการประมูลคอมโพเนนต์ที่จะรวมอยู่ในการประมูลโฆษณาบนอุปกรณ์

Optional โฆษณาคั่นระหว่างหน้า

interstitial?: null | InterstitialConfig
การตั้งค่าที่ควบคุมลักษณะการทํางานของช่องโฆษณาคั่นระหว่างหน้า

googletag.config.TaxonomyData

ออบเจ็กต์ที่มีค่าสำหรับการจัดหมวดหมู่เดียว
พร็อพเพอร์ตี้
values
รายการค่า Taxonomy

พร็อพเพอร์ตี้


values

values: string[]
รายการค่า Taxonomy

googletag.enums

นี่คือเนมสเปซที่ GPT ใช้สำหรับประเภท Enum
การแจงนับ
OutOfPageFormat
รูปแบบโฆษณานอกหน้าเว็บที่ GPT รองรับ
TrafficSource

การแจงนับ


OutOfPageFormat

OutOfPageFormat
รูปแบบโฆษณานอกหน้าเว็บที่ GPT รองรับ
ดูเพิ่มเติม
สมาชิกการแจงนับ
BOTTOM_ANCHOR
รูปแบบการยึดตำแหน่งที่ช่องโฆษณาติดอยู่ที่ด้านล่างของวิวพอร์ต
GAME_MANUAL_INTERSTITIAL
รูปแบบโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกม

หมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง
INTERSTITIAL
รูปแบบครีเอทีฟโฆษณาคั่นระหว่างหน้าในเว็บ
LEFT_SIDE_RAIL
รูปแบบโฆษณาที่แถบข้างด้านซ้าย
REWARDED
รูปแบบที่มีการให้รางวัล
RIGHT_SIDE_RAIL
รูปแบบโฆษณาที่แถบข้างด้านขวา
TOP_ANCHOR
รูปแบบตำแหน่งเฉพาะที่ช่องโฆษณาติดอยู่ที่ด้านบนของวิวพอร์ต

TrafficSource

TrafficSource
แหล่งที่มาของการเข้าชมที่ GPT รองรับ
ดูเพิ่มเติม
สมาชิกการแจงนับ
ORGANIC
รายการ URL โดยตรง การค้นหาเว็บไซต์ หรือการดาวน์โหลดแอป
PURCHASED
การเข้าชมที่เปลี่ยนเส้นทางจากพร็อพเพอร์ตี้นอกเหนือจากที่เป็นเจ้าของ (ได้มาหรือกิจกรรมที่จูงใจ)

googletag.events

ซึ่งเป็นเนมสเปซที่ GPT ใช้สำหรับเหตุการณ์ โค้ดของคุณจะตอบสนองต่อเหตุการณ์เหล่านี้ได้โดยใช้ Service.addEventListener
อินเทอร์เฟซ
Event
อินเทอร์เฟซพื้นฐานสําหรับเหตุการณ์ GPT ทั้งหมด
EventTypeMap
นี่เป็นประเภทจำลองที่แมปชื่อเหตุการณ์กับประเภทออบเจ็กต์เหตุการณ์ที่เกี่ยวข้องสำหรับ Service.addEventListener และ Service.removeEventListener
GameManualInterstitialSlotClosedEvent
เหตุการณ์นี้จะเริ่มต้นเมื่อผู้ใช้ปิดสล็อตโฆษณาคั่นระหว่างหน้าของเกมด้วยตนเอง
GameManualInterstitialSlotReadyEvent
เหตุการณ์นี้จะเริ่มต้นเมื่อช่องโฆษณาคั่นระหว่างหน้าที่กำหนดเองของเกมพร้อมที่จะแสดงต่อผู้ใช้
ImpressionViewableEvent
เหตุการณ์นี้จะทริกเกอร์เมื่อการแสดงผลปรากฏขึ้นตามเกณฑ์มุมมองแอ็กทีฟ
RewardedSlotClosedEvent
เหตุการณ์นี้จะเริ่มต้นเมื่อผู้ใช้ปิดช่องโฆษณาที่มีการให้รางวัล
RewardedSlotGrantedEvent
เหตุการณ์นี้จะเริ่มต้นเมื่อมีการมอบรางวัลสำหรับการดูโฆษณาที่มีการให้รางวัล
RewardedSlotReadyEvent
เหตุการณ์นี้จะเริ่มต้นเมื่อโฆษณาที่มีการให้รางวัลพร้อมแสดง
SlotOnloadEvent
เหตุการณ์นี้จะเริ่มต้นเมื่อ iframe ของครีเอทีฟโฆษณาเริ่มเหตุการณ์การโหลด
SlotRenderEndedEvent
เหตุการณ์นี้จะเริ่มต้นขึ้นเมื่อมีการแทรกโค้ดครีเอทีฟโฆษณาลงในช่อง
SlotRequestedEvent
เหตุการณ์นี้จะเริ่มต้นเมื่อมีการขอโฆษณาสําหรับช่องหนึ่งๆ
SlotResponseReceived
เหตุการณ์นี้จะเริ่มต้นเมื่อได้รับการตอบกลับโฆษณาสําหรับช่องหนึ่งๆ
SlotVisibilityChangedEvent
เหตุการณ์นี้จะเริ่มต้นเมื่อใดก็ตามที่เปอร์เซ็นต์พื้นที่บนหน้าจอของช่องโฆษณามีการเปลี่ยนแปลง

googletag.events.Event

อินเทอร์เฟซพื้นฐานสําหรับเหตุการณ์ GPT ทั้งหมด เหตุการณ์ GPT ทั้งหมดด้านล่างจะมีช่องต่อไปนี้
พร็อพเพอร์ตี้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
ดูเพิ่มเติม

พร็อพเพอร์ตี้


serviceName

serviceName: string
ชื่อบริการที่ทริกเกอร์เหตุการณ์

slot

slot: Slot
ช่องที่ทริกเกอร์เหตุการณ์

googletag.events.EventTypeMap

นี่เป็นประเภทจำลองที่แมปชื่อเหตุการณ์กับประเภทออบเจ็กต์เหตุการณ์ที่เกี่ยวข้องสำหรับ Service.addEventListener และ Service.removeEventListener ข้อมูลนี้มีไว้เพื่อวัตถุประสงค์ในการอ้างอิงและความปลอดภัยของประเภทเท่านั้น
พร็อพเพอร์ตี้
gameManualInterstitialSlotClosed
gameManualInterstitialSlotReady
impressionViewable
rewardedSlotClosed
ชื่อแทนสําหรับ events.RewardedSlotClosedEvent
rewardedSlotGranted
rewardedSlotReady
อีเมลแทนสําหรับ events.RewardedSlotReadyEvent
slotOnload
แทนที่ events.SlotOnloadEvent
slotRenderEnded
แทนที่ events.SlotRenderEndedEvent
slotRequested
อีเมลสำหรับ events.SlotRequestedEvent
slotResponseReceived
อีเมลสำหรับ events.SlotResponseReceived
slotVisibilityChanged

พร็อพเพอร์ตี้


gameManualInterstitialSlotClosed


gameManualInterstitialSlotReady


impressionViewable

impressionViewable: ImpressionViewableEvent
แทนที่ events.ImpressionViewableEvent

rewardedSlotClosed

rewardedSlotClosed: RewardedSlotClosedEvent
ชื่อแทนสําหรับ events.RewardedSlotClosedEvent

rewardedSlotGranted


rewardedSlotReady

rewardedSlotReady: RewardedSlotReadyEvent
อีเมลแทนสําหรับ events.RewardedSlotReadyEvent

slotOnload

slotOnload: SlotOnloadEvent
แทนที่ events.SlotOnloadEvent

slotRenderEnded

slotRenderEnded: SlotRenderEndedEvent
แทนที่ events.SlotRenderEndedEvent

slotRequested

slotRequested: SlotRequestedEvent
อีเมลสำหรับ events.SlotRequestedEvent

slotResponseReceived

slotResponseReceived: SlotResponseReceived
อีเมลสำหรับ events.SlotResponseReceived

slotVisibilityChanged

slotVisibilityChanged: SlotVisibilityChangedEvent
แทนที่ events.SlotVisibilityChangedEvent

googletag.events.GameManualInterstitialSlotClosedEvent

ขยายเวลา Event
เหตุการณ์นี้จะเริ่มต้นเมื่อผู้ใช้ปิดช่องโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกม

หมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง
พร็อพเพอร์ตี้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
ตัวอย่าง

JavaScript

// This listener is called when a game manual interstitial slot is closed.
const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL,
);

// Slot returns null if the page or device does not support game manual interstitial ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", (event) => {
    const slot = event.slot;
    console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed.");

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

JavaScript (เดิม)

// This listener is called when a game manual interstitial slot is closed.
var targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL,
);

// Slot returns null if the page or device does not support game manual interstitial ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", function (event) {
    var slot = event.slot;
    console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed.");

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

TypeScript

// This listener is called when a game manual interstitial slot is closed.
const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL,
);

// Slot returns null if the page or device does not support game manual interstitial ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", (event) => {
    const slot = event.slot;
    console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed.");

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
ดูเพิ่มเติม

googletag.events.GameManualInterstitialSlotReadyEvent

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

หมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง
พร็อพเพอร์ตี้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
เมธอด
makeGameManualInterstitialVisible
แสดงโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมต่อผู้ใช้
ตัวอย่าง

JavaScript

// This listener is called when a game manual interstitial slot is ready to
// be displayed.
const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL,
);

// Slot returns null if the page or device does not support game manual interstitial ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  googletag.pubads().addEventListener("gameManualInterstitialSlotReady", (event) => {
    const slot = event.slot;
    console.log(
      "Game manual interstital slot",
      slot.getSlotElementId(),
      "is ready to be displayed.",
    );

    // Replace with custom logic.
    const displayGmiAd = true;
    if (displayGmiAd) {
      event.makeGameManualInterstitialVisible();
    }

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

JavaScript (เดิม)

// This listener is called when a game manual interstitial slot is ready to
// be displayed.
var targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL,
);

// Slot returns null if the page or device does not support game manual interstitial ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  googletag.pubads().addEventListener("gameManualInterstitialSlotReady", function (event) {
    var slot = event.slot;
    console.log(
      "Game manual interstital slot",
      slot.getSlotElementId(),
      "is ready to be displayed.",
    );

    // Replace with custom logic.
    var displayGmiAd = true;
    if (displayGmiAd) {
      event.makeGameManualInterstitialVisible();
    }

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

TypeScript

// This listener is called when a game manual interstitial slot is ready to
// be displayed.
const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL,
);

// Slot returns null if the page or device does not support game manual interstitial ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  googletag.pubads().addEventListener("gameManualInterstitialSlotReady", (event) => {
    const slot = event.slot;
    console.log(
      "Game manual interstital slot",
      slot.getSlotElementId(),
      "is ready to be displayed.",
    );

    // Replace with custom logic.
    const displayGmiAd = true;
    if (displayGmiAd) {
      event.makeGameManualInterstitialVisible();
    }

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
ดูเพิ่มเติม

เมธอด


makeGameManualInterstitialVisible

makeGameManualInterstitialVisible(): void
แสดงโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมต่อผู้ใช้

googletag.events.ImpressionViewableEvent

ขยายเวลา Event
เหตุการณ์นี้จะทริกเกอร์เมื่อการแสดงผลปรากฏขึ้นตามเกณฑ์มุมมองแอ็กทีฟ
พร็อพเพอร์ตี้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
ตัวอย่าง

JavaScript

// This listener is called when an impression becomes viewable.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("impressionViewable", (event) => {
  const slot = event.slot;
  console.log("Impression for slot", slot.getSlotElementId(), "became viewable.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

JavaScript (เดิม)

// This listener is called when an impression becomes viewable.
var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("impressionViewable", function (event) {
  var slot = event.slot;
  console.log("Impression for slot", slot.getSlotElementId(), "became viewable.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

TypeScript

// This listener is called when an impression becomes viewable.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("impressionViewable", (event) => {
  const slot = event.slot;
  console.log("Impression for slot", slot.getSlotElementId(), "became viewable.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
ดูเพิ่มเติม

googletag.events.RewardedSlotClosedEvent

ขยายเวลา Event
เหตุการณ์นี้จะเริ่มต้นเมื่อผู้ใช้ปิดช่องโฆษณาที่มีการให้รางวัล ซึ่งอาจทํางานก่อนหรือหลังจากที่มีการมอบรางวัล หากต้องการตรวจสอบว่าผู้ใช้ได้รับรางวัลหรือไม่ ให้ใช้ events.RewardedSlotGrantedEvent แทน
พร็อพเพอร์ตี้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
ตัวอย่าง

JavaScript

const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.REWARDED,
);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  // This listener is called when the user closes a rewarded ad slot.
  googletag.pubads().addEventListener("rewardedSlotClosed", (event) => {
    const slot = event.slot;
    console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed.");

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

JavaScript (เดิม)

var targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.REWARDED,
);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  // This listener is called when the user closes a rewarded ad slot.
  googletag.pubads().addEventListener("rewardedSlotClosed", function (event) {
    var slot = event.slot;
    console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed.");

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

TypeScript

const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.REWARDED,
);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  // This listener is called when the user closes a rewarded ad slot.
  googletag.pubads().addEventListener("rewardedSlotClosed", (event) => {
    const slot = event.slot;
    console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed.");

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
ดูเพิ่มเติม

googletag.events.RewardedSlotGrantedEvent

ขยายเวลา Event
เหตุการณ์นี้จะเริ่มต้นเมื่อมีการมอบรางวัลสำหรับการดูโฆษณาที่มีการให้รางวัล หากโฆษณาปิดก่อนที่เกณฑ์การให้รางวัลจะครบถ้วน เหตุการณ์นี้จะไม่ทํางาน
พร็อพเพอร์ตี้
payload
ออบเจ็กต์ที่มีข้อมูลเกี่ยวกับรางวัลที่ได้รับ
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
ตัวอย่าง

JavaScript

const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.REWARDED,
);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  // This listener is called whenever a reward is granted for a
  // rewarded ad.
  googletag.pubads().addEventListener("rewardedSlotGranted", (event) => {
    const slot = event.slot;
    console.group("Reward granted for slot", slot.getSlotElementId(), ".");

    // Log details of the reward.
    console.log("Reward type:", event.payload?.type);
    console.log("Reward amount:", event.payload?.amount);
    console.groupEnd();

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

JavaScript (เดิม)

var targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.REWARDED,
);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  // This listener is called whenever a reward is granted for a
  // rewarded ad.
  googletag.pubads().addEventListener("rewardedSlotGranted", function (event) {
    var _a, _b;
    var slot = event.slot;
    console.group("Reward granted for slot", slot.getSlotElementId(), ".");

    // Log details of the reward.
    console.log("Reward type:", (_a = event.payload) === null || _a === void 0 ? void 0 : _a.type);
    console.log(
      "Reward amount:",
      (_b = event.payload) === null || _b === void 0 ? void 0 : _b.amount,
    );
    console.groupEnd();

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

TypeScript

const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.REWARDED,
);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  // This listener is called whenever a reward is granted for a
  // rewarded ad.
  googletag.pubads().addEventListener("rewardedSlotGranted", (event) => {
    const slot = event.slot;
    console.group("Reward granted for slot", slot.getSlotElementId(), ".");

    // Log details of the reward.
    console.log("Reward type:", event.payload?.type);
    console.log("Reward amount:", event.payload?.amount);
    console.groupEnd();

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
ดูเพิ่มเติม

พร็อพเพอร์ตี้


payload

payload: null | RewardedPayload
ออบเจ็กต์ที่มีข้อมูลเกี่ยวกับรางวัลที่ได้รับ

googletag.events.RewardedSlotReadyEvent

ขยายเวลา Event
เหตุการณ์นี้จะเริ่มต้นเมื่อโฆษณาที่มีการให้รางวัลพร้อมแสดง ผู้เผยแพร่โฆษณามีหน้าที่แสดงตัวเลือกให้ผู้ใช้ดูโฆษณาก่อนที่จะแสดงโฆษณา
พร็อพเพอร์ตี้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
เมธอด
makeRewardedVisible
แสดงโฆษณาที่มีการให้รางวัล
ตัวอย่าง

JavaScript

// This listener is called when a rewarded ad slot becomes ready to be
// displayed.
const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.REWARDED,
);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  // This listener is called whenever a reward is granted for a
  // rewarded ad.
  googletag.pubads().addEventListener("rewardedSlotReady", (event) => {
    const slot = event.slot;
    console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed.");

    // Replace with custom logic.
    const userHasConsented = true;
    if (userHasConsented) {
      event.makeRewardedVisible();
    }

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

JavaScript (เดิม)

// This listener is called when a rewarded ad slot becomes ready to be
// displayed.
var targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.REWARDED,
);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  // This listener is called whenever a reward is granted for a
  // rewarded ad.
  googletag.pubads().addEventListener("rewardedSlotReady", function (event) {
    var slot = event.slot;
    console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed.");

    // Replace with custom logic.
    var userHasConsented = true;
    if (userHasConsented) {
      event.makeRewardedVisible();
    }

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}

TypeScript

// This listener is called when a rewarded ad slot becomes ready to be
// displayed.
const targetSlot = googletag.defineOutOfPageSlot(
  "/1234567/example",
  googletag.enums.OutOfPageFormat.REWARDED,
);

// Slot returns null if the page or device does not support rewarded ads.
if (targetSlot) {
  targetSlot.addService(googletag.pubads());

  // This listener is called whenever a reward is granted for a
  // rewarded ad.
  googletag.pubads().addEventListener("rewardedSlotReady", (event) => {
    const slot = event.slot;
    console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed.");

    // Replace with custom logic.
    const userHasConsented = true;
    if (userHasConsented) {
      event.makeRewardedVisible();
    }

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
ดูเพิ่มเติม

เมธอด


makeRewardedVisible

makeRewardedVisible(): void
แสดงโฆษณาที่มีการให้รางวัล ไม่ควรเรียกใช้เมธอดนี้จนกว่าผู้ใช้จะยินยอมดูโฆษณา

googletag.events.SlotOnloadEvent

ขยายเวลา Event
เหตุการณ์นี้จะเริ่มต้นเมื่อ iframe ของครีเอทีฟโฆษณาเริ่มเหตุการณ์การโหลด เมื่อแสดงผลโฆษณาริชมีเดียในโหมดการแสดงผลแบบซิงค์ ระบบจะไม่ใช้ iframe ดังนั้นจึงไม่มีการเรียกใช้ SlotOnloadEvent
พร็อพเพอร์ตี้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
ตัวอย่าง

JavaScript

// This listener is called when a creative iframe load event fires.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotOnload", (event) => {
  const slot = event.slot;
  console.log("Creative iframe for slot", slot.getSlotElementId(), "has loaded.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

JavaScript (เดิม)

// This listener is called when a creative iframe load event fires.
var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotOnload", function (event) {
  var slot = event.slot;
  console.log("Creative iframe for slot", slot.getSlotElementId(), "has loaded.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

TypeScript

// This listener is called when a creative iframe load event fires.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotOnload", (event) => {
  const slot = event.slot;
  console.log("Creative iframe for slot", slot.getSlotElementId(), "has loaded.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
ดูเพิ่มเติม

googletag.events.SlotRenderEndedEvent

ขยายเวลา Event
เหตุการณ์นี้จะเริ่มต้นขึ้นเมื่อมีการแทรกโค้ดครีเอทีฟโฆษณาลงในช่อง เหตุการณ์นี้จะเกิดขึ้นก่อนที่ระบบจะดึงข้อมูลทรัพยากรของครีเอทีฟโฆษณา ครีเอทีฟโฆษณาจึงอาจยังไม่แสดง หากต้องการทราบว่าทรัพยากรครีเอทีฟโฆษณาทั้งหมดสําหรับช่องหนึ่งๆ โหลดเสร็จแล้ว ให้ใช้ events.SlotOnloadEvent แทน
พร็อพเพอร์ตี้
advertiserId
รหัสผู้ลงโฆษณาของโฆษณาที่แสดงผล
campaignId
รหัสแคมเปญของโฆษณาที่แสดงผล
companyIds
รหัสของบริษัทที่เสนอราคาสําหรับโฆษณาทดแทนที่แสดงผล
creativeId
รหัสครีเอทีฟโฆษณาของโฆษณาการจองที่แสดงผล
creativeTemplateId
รหัสเทมเพลตครีเอทีฟโฆษณาของโฆษณาการจองที่ผ่านการจัดการแสดงผล
isBackfill
โฆษณาเป็นโฆษณาทดแทนหรือไม่
isEmpty
มีการแสดงโฆษณาสําหรับช่องหรือไม่
labelIds
เลิกใช้งานแล้ว 
lineItemId
รหัสรายการโฆษณาของโฆษณาการจองที่แสดงผล
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
size
ระบุขนาดพิกเซลของครีเอทีฟโฆษณาที่แสดงผล
slot
ช่องที่ทริกเกอร์เหตุการณ์
slotContentChanged
เนื้อหาของช่องมีการเปลี่ยนแปลงเมื่อแสดงโฆษณาที่ผ่านการจัดการแสดงผลแล้วหรือไม่
sourceAgnosticCreativeId
รหัสครีเอทีฟโฆษณาของการจองที่แสดงผลแล้วหรือโฆษณาทดแทน
sourceAgnosticLineItemId
รหัสรายการโฆษณาของการจองที่แสดงผลแล้วหรือโฆษณาทดแทน
yieldGroupIds
รหัสของกลุ่มผลตอบแทนสําหรับโฆษณาทดแทนที่แสดงผลแล้ว
ตัวอย่าง

JavaScript

// This listener is called when a slot has finished rendering.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotRenderEnded", (event) => {
  const slot = event.slot;
  console.group("Slot", slot.getSlotElementId(), "finished rendering.");

  // Log details of the rendered ad.
  console.log("Advertiser ID:", event.advertiserId);
  console.log("Campaign ID:", event.campaignId);
  console.log("Company IDs:", event.companyIds);
  console.log("Creative ID:", event.creativeId);
  console.log("Creative Template ID:", event.creativeTemplateId);
  console.log("Is backfill?:", event.isBackfill);
  console.log("Is empty?:", event.isEmpty);
  console.log("Line Item ID:", event.lineItemId);
  console.log("Size:", event.size);
  console.log("Slot content changed?", event.slotContentChanged);
  console.log("Source Agnostic Creative ID:", event.sourceAgnosticCreativeId);
  console.log("Source Agnostic Line Item ID:", event.sourceAgnosticLineItemId);
  console.log("Yield Group IDs:", event.yieldGroupIds);
  console.groupEnd();

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

JavaScript (เดิม)

// This listener is called when a slot has finished rendering.
var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotRenderEnded", function (event) {
  var slot = event.slot;
  console.group("Slot", slot.getSlotElementId(), "finished rendering.");

  // Log details of the rendered ad.
  console.log("Advertiser ID:", event.advertiserId);
  console.log("Campaign ID:", event.campaignId);
  console.log("Company IDs:", event.companyIds);
  console.log("Creative ID:", event.creativeId);
  console.log("Creative Template ID:", event.creativeTemplateId);
  console.log("Is backfill?:", event.isBackfill);
  console.log("Is empty?:", event.isEmpty);
  console.log("Line Item ID:", event.lineItemId);
  console.log("Size:", event.size);
  console.log("Slot content changed?", event.slotContentChanged);
  console.log("Source Agnostic Creative ID:", event.sourceAgnosticCreativeId);
  console.log("Source Agnostic Line Item ID:", event.sourceAgnosticLineItemId);
  console.log("Yield Group IDs:", event.yieldGroupIds);
  console.groupEnd();

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

TypeScript

// This listener is called when a slot has finished rendering.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotRenderEnded", (event) => {
  const slot = event.slot;
  console.group("Slot", slot.getSlotElementId(), "finished rendering.");

  // Log details of the rendered ad.
  console.log("Advertiser ID:", event.advertiserId);
  console.log("Campaign ID:", event.campaignId);
  console.log("Company IDs:", event.companyIds);
  console.log("Creative ID:", event.creativeId);
  console.log("Creative Template ID:", event.creativeTemplateId);
  console.log("Is backfill?:", event.isBackfill);
  console.log("Is empty?:", event.isEmpty);
  console.log("Line Item ID:", event.lineItemId);
  console.log("Size:", event.size);
  console.log("Slot content changed?", event.slotContentChanged);
  console.log("Source Agnostic Creative ID:", event.sourceAgnosticCreativeId);
  console.log("Source Agnostic Line Item ID:", event.sourceAgnosticLineItemId);
  console.log("Yield Group IDs:", event.yieldGroupIds);
  console.groupEnd();

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
ดูเพิ่มเติม

พร็อพเพอร์ตี้


advertiserId

advertiserId: null | number
รหัสผู้ลงโฆษณาของโฆษณาที่แสดงผล ค่าคือ null สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsService

campaignId

campaignId: null | number
รหัสแคมเปญของโฆษณาที่แสดงผล ค่าคือ null สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsService

companyIds

companyIds: null | number[]
รหัสของบริษัทที่เสนอราคาสําหรับโฆษณาทดแทนที่แสดงผล ค่าคือ null สำหรับช่องว่าง โฆษณาแบบจองล่วงหน้า และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsService

creativeId

creativeId: null | number
รหัสครีเอทีฟโฆษณาของโฆษณาการจองที่แสดงผล ค่าคือ null สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsService

creativeTemplateId

creativeTemplateId: null | number
รหัสเทมเพลตครีเอทีฟโฆษณาของโฆษณาการจองที่ผ่านการจัดการแสดงผล ค่าคือ null สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsService

isBackfill

isBackfill: boolean
โฆษณาเป็นโฆษณาทดแทนหรือไม่ ค่าจะเป็น true หากโฆษณาเป็นโฆษณาทดแทน หรือ false หากไม่ใช่

isEmpty

isEmpty: boolean
มีการแสดงโฆษณาสําหรับช่องหรือไม่ ค่าจะเป็น true หากไม่มีการแสดงโฆษณา หรือ false หากมีการแสดงโฆษณา

labelIds

labelIds: null | number[]

lineItemId

lineItemId: null | number
รหัสรายการโฆษณาของโฆษณาการจองที่แสดงผล ค่าคือ null สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsService

size

size: null | string | number[]
ระบุขนาดพิกเซลของครีเอทีฟโฆษณาที่แสดงผล ตัวอย่าง: [728, 90] ค่าคือ null สำหรับช่องโฆษณาว่าง

slotContentChanged

slotContentChanged: boolean
เนื้อหาของช่องมีการเปลี่ยนแปลงเมื่อแสดงโฆษณาที่ผ่านการจัดการแสดงผลแล้วหรือไม่ ค่าคือ true หากเนื้อหามีการเปลี่ยนแปลง และเป็น false ในกรณีอื่นๆ

sourceAgnosticCreativeId

sourceAgnosticCreativeId: null | number
รหัสครีเอทีฟโฆษณาของการจองที่แสดงผลแล้วหรือโฆษณาทดแทน ค่าคือ null หากโฆษณาไม่ใช่การจองหรือโฆษณาที่แสดงแทนรายการโฆษณาที่ขาดหายไป หรือครีเอทีฟโฆษณาแสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsService

sourceAgnosticLineItemId

sourceAgnosticLineItemId: null | number
รหัสรายการโฆษณาของการจองที่แสดงผลแล้วหรือโฆษณาทดแทน ค่าคือ null หากโฆษณาไม่ใช่การจองหรือโฆษณาที่แสดงแทนรายการโฆษณาที่ขาดหายไป หรือครีเอทีฟโฆษณาแสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsService

yieldGroupIds

yieldGroupIds: null | number[]
รหัสของกลุ่มผลตอบแทนสําหรับโฆษณาทดแทนที่แสดงผลแล้ว ค่าคือ null สำหรับช่องว่าง โฆษณาแบบจองล่วงหน้า และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsService

googletag.events.SlotRequestedEvent

ขยายเวลา Event
เหตุการณ์นี้จะเริ่มต้นเมื่อมีการขอโฆษณาสําหรับช่องหนึ่งๆ
พร็อพเพอร์ตี้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
ตัวอย่าง

JavaScript

// This listener is called when the specified service issues an ad
// request for a slot. Each slot will fire this event, even though they
// may be batched together in a single request if single request
// architecture (SRA) is enabled.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotRequested", (event) => {
  const slot = event.slot;
  console.log("Slot", slot.getSlotElementId(), "has been requested.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

JavaScript (เดิม)

// This listener is called when the specified service issues an ad
// request for a slot. Each slot will fire this event, even though they
// may be batched together in a single request if single request
// architecture (SRA) is enabled.
var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotRequested", function (event) {
  var slot = event.slot;
  console.log("Slot", slot.getSlotElementId(), "has been requested.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

TypeScript

// This listener is called when the specified service issues an ad
// request for a slot. Each slot will fire this event, even though they
// may be batched together in a single request if single request
// architecture (SRA) is enabled.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotRequested", (event) => {
  const slot = event.slot;
  console.log("Slot", slot.getSlotElementId(), "has been requested.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
ดูเพิ่มเติม

googletag.events.SlotResponseReceived

ขยายเวลา Event
เหตุการณ์นี้จะเริ่มต้นเมื่อได้รับการตอบกลับโฆษณาสําหรับช่องหนึ่งๆ
พร็อพเพอร์ตี้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
ตัวอย่าง

JavaScript

// This listener is called when an ad response has been received
// for a slot.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotResponseReceived", (event) => {
  const slot = event.slot;
  console.log("Ad response for slot", slot.getSlotElementId(), "received.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

JavaScript (เดิม)

// This listener is called when an ad response has been received
// for a slot.
var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotResponseReceived", function (event) {
  var slot = event.slot;
  console.log("Ad response for slot", slot.getSlotElementId(), "received.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

TypeScript

// This listener is called when an ad response has been received
// for a slot.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotResponseReceived", (event) => {
  const slot = event.slot;
  console.log("Ad response for slot", slot.getSlotElementId(), "received.");

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
ดูเพิ่มเติม

googletag.events.SlotVisibilityChangedEvent

ขยายเวลา Event
เหตุการณ์นี้จะเริ่มต้นเมื่อใดก็ตามที่เปอร์เซ็นต์พื้นที่บนหน้าจอของช่องโฆษณามีการเปลี่ยนแปลง ระบบจะควบคุมเหตุการณ์นี้และจะไม่ทริกเกอร์บ่อยกว่า 1 ครั้งในทุกๆ 200 มิลลิวินาที
พร็อพเพอร์ตี้
inViewPercentage
เปอร์เซ็นต์ของพื้นที่โฆษณาที่มองเห็นได้
serviceName
ชื่อบริการที่ทริกเกอร์เหตุการณ์
slot
ช่องที่ทริกเกอร์เหตุการณ์
ตัวอย่าง

JavaScript

// This listener is called whenever the on-screen percentage of an
// ad slot's area changes.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotVisibilityChanged", (event) => {
  const slot = event.slot;
  console.group("Visibility of slot", slot.getSlotElementId(), "changed.");

  // Log details of the event.
  console.log("Visible area:", `${event.inViewPercentage}%`);
  console.groupEnd();

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

JavaScript (เดิม)

// This listener is called whenever the on-screen percentage of an
// ad slot's area changes.
var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotVisibilityChanged", function (event) {
  var slot = event.slot;
  console.group("Visibility of slot", slot.getSlotElementId(), "changed.");

  // Log details of the event.
  console.log("Visible area:", "".concat(event.inViewPercentage, "%"));
  console.groupEnd();

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});

TypeScript

// This listener is called whenever the on-screen percentage of an
// ad slot's area changes.
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotVisibilityChanged", (event) => {
  const slot = event.slot;
  console.group("Visibility of slot", slot.getSlotElementId(), "changed.");

  // Log details of the event.
  console.log("Visible area:", `${event.inViewPercentage}%`);
  console.groupEnd();

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
ดูเพิ่มเติม

พร็อพเพอร์ตี้


inViewPercentage

inViewPercentage: number
เปอร์เซ็นต์ของพื้นที่โฆษณาที่มองเห็นได้ ค่าคือตัวเลขระหว่าง 0 ถึง 100

googletag.secureSignals

ซึ่งเป็นเนมสเปซที่ GPT ใช้สำหรับจัดการสัญญาณที่ปลอดภัย
อินเทอร์เฟซ
BidderSignalProvider
แสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เสนอราคาที่เฉพาะเจาะจง
PublisherSignalProvider
แสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เผยแพร่โฆษณาที่เฉพาะเจาะจง
SecureSignalProvidersArray
อินเทอร์เฟซสำหรับจัดการสัญญาณที่ปลอดภัย
ประเภทอีเมลแทน
SecureSignalProvider
อินเทอร์เฟซสําหรับแสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เสนอราคาหรือผู้ให้บริการที่เฉพาะเจาะจง

ประเภทอีเมลแทน


SecureSignalProvider

อินเทอร์เฟซสําหรับแสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เสนอราคาหรือผู้ให้บริการที่เฉพาะเจาะจง ต้องระบุ id หรือ networkCode อย่างใดอย่างหนึ่ง

googletag.secureSignals.BidderSignalProvider

แสดงสัญญาณที่ปลอดภัยสำหรับผู้เสนอราคาที่เฉพาะเจาะจง

ผู้ให้บริการสัญญาณที่ปลอดภัยสำหรับผู้เสนอราคาประกอบด้วย 2 ส่วน ได้แก่

  1. ฟังก์ชันรวบรวม ซึ่งแสดงผล Promise ที่แก้ไขเป็นสัญญาณที่ปลอดภัย
  2. id ที่ระบุผู้เสนอราคาที่เชื่อมโยงกับสัญญาณ
หากต้องการแสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เผยแพร่โฆษณา ให้ใช้ secureSignals.PublisherSignalProvider แทน
พร็อพเพอร์ตี้
collectorFunction
ฟังก์ชันที่แสดงผล Promise ซึ่งจะแสดงผลเป็นสัญญาณที่ปลอดภัย
id
ตัวระบุที่ไม่ซ้ำกันสำหรับเครื่องมือรวบรวมข้อมูลที่เชื่อมโยงกับสัญญาณที่ปลอดภัยนี้ตามที่ลงทะเบียนไว้ใน Google Ad Manager
ตัวอย่าง

JavaScript

// id is provided
googletag.secureSignalProviders.push({
  id: "collector123",
  collectorFunction: () => {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});

JavaScript (เดิม)

// id is provided
googletag.secureSignalProviders.push({
  id: "collector123",
  collectorFunction: function () {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});

TypeScript

// id is provided
googletag.secureSignalProviders!.push({
  id: "collector123",
  collectorFunction: () => {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});
ดูเพิ่มเติม

พร็อพเพอร์ตี้


collectorFunction

collectorFunction: (() => Promise<string>)
ฟังก์ชันที่แสดงผล Promise ซึ่งจะแสดงผลเป็นสัญญาณที่ปลอดภัย

id

id: string
ตัวระบุที่ไม่ซ้ำกันสำหรับเครื่องมือรวบรวมข้อมูลที่เชื่อมโยงกับสัญญาณที่ปลอดภัยนี้ตามที่ลงทะเบียนไว้ใน Google Ad Manager

googletag.secureSignals.PublisherSignalProvider

แสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เผยแพร่โฆษณาที่เฉพาะเจาะจง

ผู้ให้บริการสัญญาณของผู้เผยแพร่โฆษณาประกอบด้วย 2 ส่วน ได้แก่

  1. ฟังก์ชันรวบรวม ซึ่งแสดงผล Promise ที่แก้ไขเป็นสัญญาณที่ปลอดภัย
  2. networkCode ที่ระบุผู้เผยแพร่โฆษณาที่เชื่อมโยงกับสัญญาณ
หากต้องการแสดงผลสัญญาณที่ปลอดภัยสำหรับผู้เสนอราคา ให้ใช้ secureSignals.BidderSignalProvider แทน
พร็อพเพอร์ตี้
collectorFunction
ฟังก์ชันที่แสดงผล Promise ซึ่งจะแสดงผลเป็นสัญญาณที่ปลอดภัย
networkCode
รหัสเครือข่าย (ตามที่เห็นในเส้นทางหน่วยโฆษณา) ของผู้เผยแพร่โฆษณาที่เชื่อมโยงกับสัญญาณที่ปลอดภัยนี้
ตัวอย่าง

JavaScript

// networkCode is provided
googletag.secureSignalProviders.push({
  networkCode: "123456",
  collectorFunction: () => {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});

JavaScript (เดิม)

// networkCode is provided
googletag.secureSignalProviders.push({
  networkCode: "123456",
  collectorFunction: function () {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});

TypeScript

// networkCode is provided
googletag.secureSignalProviders!.push({
  networkCode: "123456",
  collectorFunction: () => {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});
ดูเพิ่มเติม

พร็อพเพอร์ตี้


collectorFunction

collectorFunction: (() => Promise<string>)
ฟังก์ชันที่แสดงผล Promise ซึ่งจะแสดงผลเป็นสัญญาณที่ปลอดภัย

networkCode

networkCode: string
รหัสเครือข่าย (ตามที่เห็นในเส้นทางหน่วยโฆษณา) ของผู้เผยแพร่โฆษณาที่เชื่อมโยงกับสัญญาณที่ปลอดภัยนี้

googletag.secureSignals.SecureSignalProvidersArray

อินเทอร์เฟซสำหรับจัดการสัญญาณที่ปลอดภัย
เมธอด
clearAllCache
ล้างสัญญาณทั้งหมดสําหรับเครื่องมือรวบรวมข้อมูลทั้งหมดออกจากแคช
push
เพิ่ม secureSignals.SecureSignalProvider ใหม่ลงในอาร์เรย์ผู้ให้บริการสัญญาณและเริ่มกระบวนการสร้างสัญญาณ

เมธอด


clearAllCache

clearAllCache(): void
ล้างสัญญาณทั้งหมดสำหรับผู้รวบรวมทั้งหมดออกจากแคช

การเรียกใช้เมธอดนี้อาจลดโอกาสที่สัญญาณจะรวมอยู่ในคําขอโฆษณาสําหรับการดูหน้าเว็บปัจจุบันและที่อาจเกิดขึ้นในภายหลัง ด้วยเหตุนี้ จึงควรเรียกใช้เฉพาะเมื่อมีการเปลี่ยนแปลงสถานะที่มีความหมาย เช่น เหตุการณ์ที่บ่งบอกถึงผู้ใช้ใหม่ (เข้าสู่ระบบ ออกจากระบบ ลงชื่อสมัครใช้ ฯลฯ)

push

push(provider: SecureSignalProvider): void
เพิ่ม secureSignals.SecureSignalProvider ใหม่ลงในอาร์เรย์ผู้ให้บริการสัญญาณและเริ่มกระบวนการสร้างสัญญาณ
พารามิเตอร์
provider: SecureSignalProviderออบเจ็กต์ secureSignals.SecureSignalProvider ที่จะเพิ่มลงในอาร์เรย์