ข้อมูลอ้างอิงนี้ใช้การเขียนสัญกรณ์ 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
เนมสเปซ | |
---|---|
config | อินเทอร์เฟซการกําหนดค่าหลักสําหรับการตั้งค่าระดับหน้า |
enums | นี่คือเนมสเปซที่ GPT ใช้สำหรับประเภท Enum |
events | ซึ่งเป็นเนมสเปซที่ GPT ใช้สำหรับเหตุการณ์ |
secure | ซึ่งเป็นเนมสเปซที่ GPT ใช้สำหรับจัดการสัญญาณที่ปลอดภัย |
อินเทอร์เฟซ | |
---|---|
Command | อาร์เรย์คําสั่งจะยอมรับลําดับของฟังก์ชันและเรียกใช้ตามลําดับ |
Companion | บริการโฆษณาที่แสดงร่วม |
Privacy | ออบเจ็กต์การกําหนดค่าสําหรับการตั้งค่าความเป็นส่วนตัว |
Pub | บริการโฆษณาของผู้เผยแพร่โฆษณา |
Response | ออบเจ็กต์ที่แสดงการตอบกลับโฆษณารายการเดียว |
Rewarded | ออบเจ็กต์ที่แสดงรางวัลที่เชื่อมโยงกับโฆษณาที่มีการให้รางวัล |
Safe | ออบเจ็กต์การกําหนดค่าสําหรับคอนเทนเนอร์ SafeFrame |
Service | คลาสบริการพื้นฐานที่มีเมธอดที่ใช้ร่วมกันสำหรับบริการทั้งหมด |
Size | ตัวสร้างสำหรับออบเจ็กต์ข้อกำหนดการแมปขนาด |
Slot | ช่องคือออบเจ็กต์ที่แสดงช่องโฆษณาเดียวในหน้าเว็บ |
ประเภทอีเมลแทน | |
---|---|
General | การกําหนดค่าขนาดที่ถูกต้องสําหรับช่อง ซึ่งอาจเป็นขนาดเดียวหรือหลายขนาดก็ได้ |
Multi | รายการขนาดเดียวที่ใช้ได้ |
Named | ขนาดที่ตั้งชื่อซึ่งช่องมีได้ |
Single | ขนาดเดียวที่ใช้ได้สำหรับช่วงเวลา |
Single | อาร์เรย์ของตัวเลข 2 รายการที่แสดงถึง [width, height] |
Size | การแมปขนาดวิวพอร์ตกับขนาดโฆษณา |
Size | รายการการแมปขนาด |
ตัวแปร | |
---|---|
api | การแจ้งที่ระบุว่า GPT API โหลดแล้วและพร้อมเรียกใช้ |
cmd | การอ้างอิงคิวคําสั่งส่วนกลางสําหรับการเรียกใช้ที่เกี่ยวข้องกับ GPT แบบไม่พร้อมกัน |
pubads | การแจ้งที่ระบุว่า PubAdsService เปิดใช้ โหลด และทํางานได้อย่างสมบูรณ์ |
secure | การอ้างอิงอาร์เรย์ผู้ให้บริการสัญญาณที่ปลอดภัย |
ฟังก์ชัน | |
---|---|
companion | แสดงการอ้างอิงถึง CompanionAdsService |
define | สร้างช่องโฆษณาที่ไม่อยู่ในขอบเขตหน้าด้วยเส้นทางหน่วยโฆษณาที่ระบุ |
define | สร้างช่องโฆษณาที่มีเส้นทางและขนาดหน่วยโฆษณาที่ระบุ และเชื่อมโยงกับรหัสขององค์ประกอบ div ในหน้าเว็บที่จะแสดงโฆษณา |
destroy | ทำลายช่องที่ระบุ โดยนําออบเจ็กต์และการอ้างอิงทั้งหมดที่เกี่ยวข้องกับช่องเหล่านั้นออกจาก GPT |
disable | ปิดใช้คอนโซลผู้เผยแพร่โฆษณาของ Google |
display | สั่งให้บริการสล็อตแสดงผลสล็อต |
enable | เปิดใช้บริการ GPT ทั้งหมดที่กําหนดไว้สําหรับช่องโฆษณาในหน้า |
get | แสดงผล GPT เวอร์ชันปัจจุบัน |
open | เปิดคอนโซลผู้เผยแพร่โฆษณาของ Google |
pubads | แสดงผลข้อมูลอ้างอิงถึง PubAdsService |
set | ตั้งค่าชื่อสําหรับ iframe ของคอนเทนเนอร์โฆษณาทั้งหมดที่สร้างโดย PubAdsService นับจากนี้เป็นต้นไป |
set | ตั้งค่าตัวเลือกการกําหนดค่าทั่วไปสําหรับหน้าเว็บ |
size | สร้าง SizeMappingBuilder ใหม่ |
ประเภทอีเมลแทน
GeneralSize
GeneralSize: SingleSize | MultiSize
MultiSize
MultiSize: SingleSize[]
NamedSize
NamedSize: "fluid" | ["fluid"]
- แบบยืดหยุ่น: คอนเทนเนอร์โฆษณาใช้ความกว้าง 100% ของ div หลัก จากนั้นปรับขนาดความสูงให้พอดีกับเนื้อหาครีเอทีฟโฆษณา คล้ายกับลักษณะการทํางานขององค์ประกอบบล็อกปกติในหน้าเว็บ ใช้สำหรับโฆษณาเนทีฟ (ดูบทความที่เกี่ยวข้อง) โปรดทราบว่าทั้ง
fluid
และ['fluid']
เป็นรูปแบบที่ยอมรับได้ในการประกาศขนาดช่องเป็นแบบปรับขนาดได้
SingleSize
SingleSize: SingleSizeArray | NamedSize
SingleSizeArray
SingleSizeArray: [number, number]
SizeMapping
SizeMapping: [SingleSizeArray, GeneralSize]
SizeMappingArray
SizeMappingArray: SizeMapping[]
ตัวแปร
Const
apiReady
apiReady: boolean | undefined
undefined
จนกระทั่ง API พร้อมใช้งานโปรดทราบว่าวิธีจัดการแบบแอซิงค์ที่แนะนําคือการใช้ googletag.cmd เพื่อจัดคิวการเรียกกลับเมื่อ GPT พร้อมใช้งาน โค้ดเรียกกลับเหล่านี้ไม่จําเป็นต้องตรวจสอบ googletag.apiReady เนื่องจากระบบรับประกันว่าจะเรียกใช้เมื่อตั้งค่า API แล้ว
Const
cmd
cmd: ((this: typeof globalThis) => void)[] | CommandArray
ตัวแปร
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
undefined
เท่านั้นจนกว่าจะมีการเรียกใช้ enableServices และโหลดและเริ่มต้น PubAdsServicesecureSignalProviders
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 | บริการโฆษณาที่แสดงร่วม |
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 | เส้นทางหน่วยโฆษณาแบบเต็มพร้อมรหัสเครือข่ายและรหัสหน่วยโฆษณา |
| รหัสของ div ที่จะมีหน่วยโฆษณานี้หรือ OutOfPageFormat |
การคืนสินค้า | |
---|---|
Slot | null | สล็อตที่สร้างขึ้นใหม่ หรือ null หากสร้างสล็อตไม่ได้ |
defineSlot
defineSlot(adUnitPath: string, size: GeneralSize, div?: string): Slot | null
- ตัวอย่าง
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 | ความกว้างและความสูงของช่องที่เพิ่ม ซึ่งเป็นขนาดที่ใช้ในคําขอโฆษณาหากไม่มีการแมปขนาดที่ปรับเปลี่ยนตามพื้นที่โฆษณาหรือขนาดของวิวพอร์ตเล็กกว่าขนาดที่เล็กที่สุดที่ระบุไว้ในการแมป |
| รหัสของ div ที่จะมีหน่วยโฆษณานี้ |
การคืนสินค้า | |
---|---|
Slot | null | ช่วงเวลาที่สะดวกซึ่งสร้างขึ้นใหม่ หรือ null หากสร้างช่วงเวลาที่สะดวกไม่ได้ |
destroySlots
destroySlots(slots?: Slot[]): boolean
การเรียก 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();
พารามิเตอร์ | |
---|---|
| อาร์เรย์ของช่องที่จะทำลาย อาร์เรย์เป็นตัวเลือก สล็อตทั้งหมดจะถูกทำลายหากไม่ได้ระบุ |
การคืนสินค้า | |
---|---|
boolean | true หากมีการทำลายสล็อต false ไม่เช่นนั้น |
disablePublisherConsole
disablePublisherConsole(): void
- ดูเพิ่มเติม
display
display(divOrSlot: string | Element | Slot): void
หากใช้สถาปัตยกรรมคําขอรวมครั้งเดียว (SRA) ระบบจะดึงข้อมูลช่องโฆษณาทั้งหมดที่ไม่ได้ดึงข้อมูล ณ เวลาที่มีการเรียกใช้เมธอดนี้พร้อมกัน หากต้องการบังคับไม่ให้ช่องโฆษณาแสดง คุณต้องนํา div ทั้งหมดออก
- ดูเพิ่มเติม
พารามิเตอร์ | |
---|---|
divOrSlot: string | Element | Slot | รหัสขององค์ประกอบ div ที่มีช่องโฆษณาหรือองค์ประกอบ div หรือออบเจ็กต์ช่อง หากระบุองค์ประกอบ div ไว้ องค์ประกอบดังกล่าวต้องมีแอตทริบิวต์ "id" ที่ตรงกับรหัสที่ส่งไปยัง defineSlot |
enableServices
enableServices(): void
getVersion
getVersion(): string
- ดูเพิ่มเติม
การคืนสินค้า | |
---|---|
string | สตริงเวอร์ชัน GPT ที่ใช้งานอยู่ |
openConsole
openConsole(div?: string): void
- ตัวอย่าง
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();
- ดูเพิ่มเติม
พารามิเตอร์ | |
---|---|
| รหัส div ของช่องโฆษณา ค่านี้ไม่บังคับ เมื่อระบุแล้ว คอนโซลผู้เผยแพร่โฆษณาจะพยายามเปิดขึ้นพร้อมแสดงรายละเอียดของช่องโฆษณาที่ระบุ |
pubads
pubads(): PubAdsService
การคืนสินค้า | |
---|---|
PubAdsService | บริการโฆษณาของผู้เผยแพร่โฆษณา |
setAdIframeTitle
setAdIframeTitle(title: string): void
- ตัวอย่าง
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 | ตัวสร้างใหม่ |
googletag.CommandArray
เมธอด | |
---|---|
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()); });
พารามิเตอร์ | |
---|---|
| ฟังก์ชัน JavaScript ที่จะเรียกใช้ การเชื่อมโยงรันไทม์จะเป็น globalThis เสมอ ลองส่งผ่านฟังก์ชันลูกศรเพื่อเก็บค่า this ของบริบทเชิงคำที่ล้อมรอบ |
การคืนสินค้า | |
---|---|
number | จํานวนคําสั่งที่ประมวลผลจนถึงตอนนี้ ซึ่งเข้ากันได้กับค่าที่ Array.push แสดงผล (ความยาวปัจจุบันของอาร์เรย์) |
googletag.CompanionAdsService
ขยายเวลาเมธอด | |
---|---|
add | ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript ได้เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้า รับค่าจาก |
get | ดูรายการช่องที่เชื่อมโยงกับบริการนี้ รับค่าจาก |
remove | นำผู้ฟังที่ลงทะเบียนไว้ก่อนหน้านี้ออก รับค่าจาก |
set | ตั้งค่าว่าช่องโฆษณาที่แสดงร่วมที่ยังไม่ได้รับโฆษณาจะได้รับโฆษณาทดแทนโดยอัตโนมัติหรือไม่ |
- ดูเพิ่มเติม
เมธอด
setRefreshUnfilledSlots
setRefreshUnfilledSlots(value: boolean): void
เมธอดนี้สามารถเรียกใช้ได้หลายครั้งตลอดอายุการใช้งานของหน้าเว็บเพื่อเปิดและปิดโฆษณาทดแทน เฉพาะช่องที่ลงทะเบียนกับ PubAdsService เท่านั้นที่จะได้รับโฆษณาทดแทน วิธีการนี้ไม่ได้ออกแบบมาเพื่อเติมเต็มช่องโฆษณาที่แสดงร่วมกันที่ว่างเปล่าเมื่อมีการเผยแพร่วิดีโอ Ad Exchange เนื่องจากข้อจํากัดด้านนโยบาย
- ตัวอย่าง
JavaScript
googletag.companionAds().setRefreshUnfilledSlots(true);
JavaScript (เดิม)
googletag.companionAds().setRefreshUnfilledSlots(true);
TypeScript
googletag.companionAds().setRefreshUnfilledSlots(true);
พารามิเตอร์ | |
---|---|
value: boolean | true เพื่อทดแทนช่องว่างโดยอัตโนมัติ หรือ false เพื่อคงค่าเดิม |
googletag.PrivacySettingsConfig
พร็อพเพอร์ตี้ | |
---|---|
child | ระบุว่าควรถือว่าหน้าเว็บมีไว้สําหรับเด็กหรือไม่ |
limited | เปิดใช้การแสดงโฆษณาในโหมดโฆษณาแบบจํากัดเพื่อช่วยในการปฏิบัติตามข้อกําหนดของผู้เผยแพร่โฆษณา |
non | เปิดใช้การแสดงโฆษณาในโหมดโฆษณาที่ไม่ได้ปรับตามโปรไฟล์ของผู้ใช้เพื่อช่วยในการปฏิบัติตามข้อกําหนดของผู้เผยแพร่โฆษณา |
restrict | เปิดใช้การแสดงโฆษณาในโหมดการประมวลผลแบบจํากัดเพื่อช่วยในการปฏิบัติตามข้อกําหนดของผู้เผยแพร่โฆษณา |
traffic | ระบุว่าคำขอแสดงการเข้าชมที่ซื้อมาหรือการเข้าชมจากการค้นหาทั่วไป |
under | ระบุว่าจะทําเครื่องหมายคําขอโฆษณาว่ามาจากผู้ใช้ที่มีอายุต่ำกว่าอายุที่ยินยอมหรือไม่ |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
Optional
childDirectedTreatment
childDirectedTreatment?: null | boolean
null
เพื่อล้างการกำหนดค่าOptional
limitedAds
limitedAds?: boolean
คุณสามารถสั่งให้ GPT ขอโฆษณาแบบจํากัดได้ 2 วิธี ดังนี้
- โดยอัตโนมัติโดยใช้สัญญาณจากแพลตฟอร์มการจัดการความยินยอม TCF เวอร์ชัน 2.0 ของ IAB
- ด้วยตนเองโดยตั้งค่าของช่องนี้เป็น
true
โปรดทราบว่าคุณไม่จำเป็นต้องเปิดใช้โฆษณาแบบจำกัดด้วยตนเองเมื่อใช้ 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
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
ขยายเวลาเมธอด | |
---|---|
add | ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript ได้เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้า รับค่าจาก |
clear | นําโฆษณาออกจากช่องที่ระบุและแทนที่ด้วยเนื้อหาว่าง |
clear | ล้างป้ายกํากับการยกเว้นหมวดหมู่โฆษณาระดับหน้าเว็บทั้งหมด |
clear | ล้างพารามิเตอร์การกําหนดเป้าหมายเองสําหรับคีย์ที่เฉพาะเจาะจงหรือสําหรับคีย์ทั้งหมด |
collapse | เปิดใช้การยุบ div ของช่องโฆษณาเพื่อไม่ให้ช่องโฆษณาใช้พื้นที่ในหน้าเว็บเมื่อไม่มีเนื้อหาโฆษณาที่จะแสดง |
disable | ปิดใช้คําขอโฆษณาเมื่อโหลดหน้าเว็บ แต่อนุญาตให้ขอโฆษณาด้วยการเรียกใช้ PubAdsService.refresh |
display | สร้างและแสดงช่องโฆษณาที่มีเส้นทางและขนาดหน่วยโฆษณาที่ระบุ |
enable | เปิดใช้การโหลดแบบเลื่อนเวลาใน GPT ตามที่ออบเจ็กต์การกําหนดค่าระบุ |
enable | เปิดใช้โหมดคำขอเดียวเพื่อดึงข้อมูลโฆษณาหลายรายการพร้อมกัน |
enable | ส่งสัญญาณให้ GPT ทราบว่าจะมีโฆษณาวิดีโอในหน้า |
get | แสดงผลค่าสําหรับแอตทริบิวต์ AdSense ที่เชื่อมโยงกับคีย์ที่ระบุ |
get | แสดงคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในบริการนี้ |
get | ดูรายการช่องที่เชื่อมโยงกับบริการนี้ รับค่าจาก |
get | แสดงผลพารามิเตอร์การกําหนดเป้าหมายระดับบริการที่กําหนดเองที่เฉพาะเจาะจงซึ่งตั้งค่าไว้ |
get | แสดงรายการคีย์การกําหนดเป้าหมายระดับบริการที่กําหนดเองทั้งหมดที่ตั้งไว้ |
is | แสดงผลว่าคําขอโฆษณาครั้งแรกถูกปิดใช้ด้วยคําเรียก PubAdsService.disableInitialLoad ก่อนหน้านี้สําเร็จหรือไม่ |
refresh | ดึงข้อมูลและแสดงโฆษณาใหม่สำหรับบางช่องหรือทุกช่องในหน้า |
remove | นำผู้ฟังที่ลงทะเบียนไว้ก่อนหน้านี้ออก รับค่าจาก |
set | ตั้งค่าแอตทริบิวต์ AdSense ที่มีผลกับช่องโฆษณาทั้งหมดภายใต้บริการโฆษณาของผู้เผยแพร่โฆษณา |
set | ตั้งค่าการยกเว้นหมวดหมู่โฆษณาระดับหน้าเว็บสําหรับชื่อป้ายกำกับที่ระบุ |
set | เปิดและปิดใช้การกึ่งกลางโฆษณาในแนวนอน |
set | กําหนดค่าว่าควรบังคับให้โฆษณาทั้งหมดในหน้าแสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่ |
set | ส่งข้อมูลตําแหน่งจากเว็บไซต์เพื่อให้คุณกําหนดเป้าหมายรายการโฆษณาตามภูมิศาสตร์ไปยังตําแหน่งที่ต้องการได้ |
set | อนุญาตให้กําหนดการตั้งค่าความเป็นส่วนตัวทั้งหมดจาก API รายการเดียวโดยใช้ออบเจ็กต์การกําหนดค่า |
set | ตั้งค่ารหัสที่ผู้เผยแพร่โฆษณาระบุ |
set | ตั้งค่ากำหนดระดับหน้าสำหรับการกำหนดค่า SafeFrame |
set | ตั้งค่าพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองสําหรับคีย์หนึ่งๆ ที่มีผลกับช่องโฆษณาบริการโฆษณาของผู้เผยแพร่โฆษณาทั้งหมด |
set | ตั้งค่าข้อมูลเนื้อหาวิดีโอที่จะส่งไปพร้อมกับคําขอโฆษณาเพื่อวัตถุประสงค์ในการกําหนดเป้าหมายและการยกเว้นเนื้อหา |
update | เปลี่ยนตัวเชื่อมโยงที่ส่งไปพร้อมกับคําขอโฆษณา ซึ่งจะเริ่มต้นการดูหน้าเว็บใหม่อย่างมีประสิทธิภาพ |
เมธอด
ล้าง
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();
พารามิเตอร์ | |
---|---|
| อาร์เรย์ของช่องที่จะล้าง อาร์เรย์เป็นตัวเลือก ระบบจะล้างช่องทั้งหมดหากไม่ได้ระบุ |
การคืนสินค้า | |
---|---|
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.
- ดูเพิ่มเติม
พารามิเตอร์ | |
---|---|
| คีย์พารามิเตอร์การกําหนดเป้าหมาย คุณไม่จำเป็นต้องระบุคีย์นี้ ระบบจะล้างพารามิเตอร์การกำหนดเป้าหมายทั้งหมดหากไม่ระบุ |
การคืนสินค้า | |
---|---|
PubAdsService | ออบเจ็กต์บริการที่เรียกใช้เมธอด |
collapseEmptyDivs
collapseEmptyDivs(collapseBeforeAdFetch?: boolean): boolean
- ดูเพิ่มเติม
พารามิเตอร์ | |
---|---|
| เลือกว่าจะยุบช่องก่อนที่จะดึงข้อมูลโฆษณาหรือไม่ พารามิเตอร์นี้ไม่บังคับ หากไม่ระบุ ระบบจะใช้ false เป็นค่าเริ่มต้น |
การคืนสินค้า | |
---|---|
boolean | แสดงผลเป็น true หากเปิดใช้โหมดยุบ div และ false หากเปิดใช้โหมดยุบไม่ได้เนื่องจากมีการเรียกใช้เมธอดหลังจากเปิดใช้บริการแล้ว |
disableInitialLoad
disableInitialLoad(): void
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 | ความกว้างและความสูงของช่อง |
| รหัสของ div ที่มีช่องหรือองค์ประกอบ div เอง |
| URL การคลิกที่จะใช้ในช่องนี้ |
enableLazyLoad
enableLazyLoad(config?: {
fetchMarginPercent?: number;
mobileScaling?: number;
renderMarginPercent?: number;
}): void
หมายเหตุ: การดึงข้อมูลแบบ 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, });
- ดูเพิ่มเติม
พารามิเตอร์ | |
---|---|
| ออบเจ็กต์การกําหนดค่าช่วยให้ปรับแต่งลักษณะการทํางานแบบ Lazy ได้ การกําหนดค่าที่ละเว้นจะใช้ค่าเริ่มต้นที่ Google ตั้งไว้ซึ่งจะได้รับการปรับแต่งเมื่อเวลาผ่านไป หากต้องการปิดใช้การตั้งค่าบางอย่าง เช่น ระยะการดึงข้อมูล ให้ตั้งค่าเป็น -1
|
enableSingleRequest
enableSingleRequest(): boolean
- ดูเพิ่มเติม
การคืนสินค้า | |
---|---|
boolean | แสดงผลเป็น true หากเปิดใช้โหมดคำขอเดี่ยว และ false หากเปิดใช้โหมดคำขอเดี่ยวไม่ได้เนื่องจากมีการเรียกใช้เมธอดหลังจากเปิดใช้บริการแล้ว |
enableVideoAds
enableVideoAds(): void
get
get(key: string): null | string
- ตัวอย่าง
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
การคืนสินค้า | |
---|---|
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 });
- ดูเพิ่มเติม
พารามิเตอร์ | |
---|---|
| ช่องที่จะรีเฟรช อาร์เรย์เป็นตัวเลือก โดยระบบจะรีเฟรชทุกช่องหากไม่ได้ระบุ |
| ตัวเลือกการกําหนดค่าที่เชื่อมโยงกับการเรียกใช้การรีเฟรชนี้
|
set
set(key: string, value: string): PubAdsService
การเรียกใช้คีย์นี้มากกว่า 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
คุณควรเรียกใช้เมธอดนี้ก่อนเรียกใช้
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: boolean | true เพื่อจัดโฆษณาให้อยู่กึ่งกลาง false เพื่อจัดโฆษณาให้ชิดซ้าย |
setForceSafeFrame
setForceSafeFrame(forceSafeFrame: boolean): PubAdsService
โปรดคํานึงถึงสิ่งต่อไปนี้ขณะใช้ 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: boolean | true เพื่อบังคับให้แสดงโฆษณาทั้งหมดในหน้าเว็บใน 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
- ตัวอย่าง
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
ค่ากําหนดระดับหน้าเว็บเหล่านี้จะถูกลบล้างโดยค่ากําหนดระดับช่อง หากระบุไว้
- ตัวอย่าง
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
- ตัวอย่าง
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
พร็อพเพอร์ตี้ | |
---|---|
advertiser | รหัสของผู้ลงโฆษณา |
campaign | รหัสของแคมเปญ |
creative | รหัสของครีเอทีฟโฆษณา |
creative | รหัสเทมเพลตของโฆษณา |
line | รหัสของรายการโฆษณา |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
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
พร็อพเพอร์ตี้ | |
---|---|
allow | SafeFrame ควรอนุญาตให้เนื้อหาโฆษณาขยายโดยการวางซ้อนเนื้อหาของหน้าหรือไม่ |
allow | กำหนดว่า SafeFrame ควรอนุญาตให้เนื้อหาโฆษณาขยายโดยการดันเนื้อหาหน้าเว็บหรือไม่ |
sandbox | ระบุว่า SafeFrame ควรใช้แอตทริบิวต์ sandbox ของ HTML5 เพื่อป้องกันการนำทางระดับบนสุดโดยไม่มีการโต้ตอบของผู้ใช้หรือไม่ |
use | เลิกใช้งานแล้ว SafeFrame ควรใช้โดเมนย่อยแบบสุ่มสําหรับครีเอทีฟโฆษณาแบบจองหรือไม่ |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
Optional
allowOverlayExpansion
allowOverlayExpansion?: boolean
Optional
allowPushExpansion
allowPushExpansion?: boolean
Optional
sandbox
sandbox?: boolean
true
(บังคับให้เป็น false
ไม่ได้) โปรดทราบว่าแอตทริบิวต์แซนด์บ็อกซ์จะปิดใช้ปลั๊กอิน (เช่น Flash)Optional
useUniqueDomain
useUniqueDomain?: null | boolean
null
เพื่อล้างค่าที่เก็บไว้หมายเหตุ: ฟีเจอร์นี้เปิดใช้โดยค่าเริ่มต้น
- ดูเพิ่มเติม
googletag.Service
เมธอด | |
---|---|
add | ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript ได้เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้า |
get | ดูรายการช่องที่เชื่อมโยงกับบริการนี้ |
remove | นำผู้ฟังที่ลงทะเบียนไว้ก่อนหน้านี้ออก |
เมธอด
addEventListener
addEventListener<K extends keyof EventTypeMap>(eventType: K, listener: ((arg: EventTypeMap[K]) => void)): Service
- events.GameManualInterstitialSlotClosedEvent
- events.GameManualInterstitialSlotReadyEvent
- events.ImpressionViewableEvent
- events.RewardedSlotClosedEvent
- events.RewardedSlotGrantedEvent
- events.RewardedSlotReadyEvent
- events.SlotOnloadEvent
- events.SlotRenderEndedEvent
- events.SlotRequestedEvent
- events.SlotResponseReceived
- events.SlotVisibilityChangedEvent
- ตัวอย่าง
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
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
เมธอด | |
---|---|
add | เพิ่มการแมปจากอาร์เรย์ขนาดเดียว (แสดงถึงวิวพอร์ต) ไปยังอาร์เรย์ขนาดเดียวหรือหลายขนาดที่แสดงถึงช่อง |
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 < 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 < 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 < 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
เมธอด | |
---|---|
add | เพิ่มบริการลงในช่องนี้ |
clear | ล้างป้ายกํากับการยกเว้นหมวดหมู่โฆษณาระดับช่องทั้งหมดสําหรับช่องนี้ |
clear | ล้างพารามิเตอร์การกําหนดเป้าหมายระดับช่องที่กําหนดเองที่เฉพาะเจาะจงหรือทั้งหมดสําหรับช่องนี้ |
define | ตั้งค่าอาร์เรย์การแมปจากขนาดวิวพอร์ตขั้นต่ำเป็นขนาดช่องสำหรับช่องนี้ |
get | แสดงค่าสำหรับแอตทริบิวต์ AdSense ที่เชื่อมโยงกับคีย์ที่ระบุสำหรับช่องนี้ |
get | แสดงเส้นทางแบบเต็มของหน่วยโฆษณาพร้อมรหัสเครือข่ายและเส้นทางหน่วยโฆษณา |
get | แสดงรายการคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในช่องนี้ |
get | แสดงป้ายกํากับการยกเว้นหมวดหมู่โฆษณาสําหรับช่องนี้ |
get | แสดงข้อมูลการตอบกลับด้วยโฆษณา |
get | แสดงผลรหัสของช่อง div ที่ระบุเมื่อมีการกําหนดช่อง |
get | แสดงผลพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองที่เฉพาะเจาะจงซึ่งตั้งค่าไว้ในช่องนี้ |
get | แสดงรายการคีย์การกําหนดเป้าหมายที่กําหนดเองทั้งหมดที่ตั้งค่าไว้ในช่องนี้ |
set | ตั้งค่าแอตทริบิวต์ AdSense ในช่องโฆษณานี้ |
set | ตั้งค่าป้ายกํากับการยกเว้นหมวดหมู่โฆษณาระดับช่องในช่องนี้ |
set | ตั้งค่า URL การคลิกที่ระบบจะเปลี่ยนเส้นทางผู้ใช้หลังจากคลิกโฆษณา |
set | ตั้งค่าว่าควรซ่อนช่อง div หรือไม่เมื่อมีโฆษณาในช่อง |
set | ตั้งค่าตัวเลือกการกําหนดค่าทั่วไปสําหรับช่องนี้ |
set | กําหนดค่าว่าจะบังคับให้โฆษณาในช่องนี้แสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่ |
set | ตั้งค่ากำหนดระดับช่องสำหรับการกำหนดค่า SafeFrame |
set | ตั้งค่าพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองสําหรับช่องนี้ |
update | ตั้งค่าพารามิเตอร์การกําหนดเป้าหมายที่กําหนดเองสําหรับช่องนี้จากแผนที่คีย์:ค่าในแออบเจ็กต์ 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.
- ดูเพิ่มเติม
พารามิเตอร์ | |
---|---|
| คีย์พารามิเตอร์การกําหนดเป้าหมาย คุณไม่จำเป็นต้องระบุคีย์นี้ ระบบจะล้างพารามิเตอร์การกำหนดเป้าหมายทั้งหมดหากไม่ระบุ |
การคืนสินค้า | |
---|---|
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
- ตัวอย่าง
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[]
- ตัวอย่าง
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
การเรียกใช้เมธอดนี้มากกว่า 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
เซิร์ฟเวอร์ 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: string | URL คลิกที่จะตั้งค่า |
การคืนสินค้า | |
---|---|
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 | เลือกว่าจะยุบช่องหรือไม่หากไม่มีการแสดงโฆษณา |
| ต้องการยุบช่องก่อนที่จะดึงข้อมูลโฆษณาหรือไม่ ละเว้นหาก collapse ไม่ใช่ true |
การคืนสินค้า | |
---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
setConfig
setConfig(slotConfig: SlotSettingsConfig): void
พารามิเตอร์ | |
---|---|
slotConfig: SlotSettingsConfig | ออบเจ็กต์การกําหนดค่า |
setForceSafeFrame
setForceSafeFrame(forceSafeFrame: boolean): Slot
โปรดคํานึงถึงสิ่งต่อไปนี้ขณะใช้ 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: boolean | true เพื่อบังคับให้โฆษณาทั้งหมดในช่องนี้แสดงผลใน SafeFrame และ false เพื่อเลือกไม่ใช้การตั้งค่าระดับหน้า (หากมี) การตั้งค่านี้เป็น false เมื่อไม่ได้ระบุที่ระดับหน้าเว็บจะไม่เปลี่ยนแปลงอะไร |
การคืนสินค้า | |
---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
setSafeFrameConfig
setSafeFrameConfig(config: null | SafeFrameConfig): Slot
ค่ากําหนดระดับช่องเหล่านี้ (หากระบุ) จะลบล้างค่ากําหนดระดับหน้า
- ตัวอย่าง
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
- ตัวอย่าง
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
หมายเหตุ:
- ในกรณีที่มีการเขียนทับ ระบบจะเก็บเฉพาะค่าสุดท้ายไว้
- หากค่าเป็นอาร์เรย์ ระบบจะเขียนทับค่าก่อนหน้า ไม่ใช่ผสานรวม
- ค่าที่ตั้งไว้ที่นี่จะเขียนทับพารามิเตอร์การกําหนดเป้าหมายที่ตั้งไว้ที่ระดับบริการ
- ตัวอย่าง
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: { | การแมปคีย์:ค่าของพารามิเตอร์การกําหนดเป้าหมาย |
การคืนสินค้า | |
---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
googletag.config
อินเทอร์เฟซ | |
---|---|
Ad | การตั้งค่าเพื่อควบคุมการขยายโฆษณา |
Component | ออบเจ็กต์ที่แสดงการประมูลคอมโพเนนต์เดียวในการประมูลโฆษณาบนอุปกรณ์ |
Interstitial | ออบเจ็กต์ที่กําหนดลักษณะการทํางานของสล็อตโฆษณาคั่นระหว่างหน้ารายการเดียว |
Page | อินเทอร์เฟซการกําหนดค่าหลักสําหรับการตั้งค่าระดับหน้า |
Privacy | การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา |
Publisher | ออบเจ็กต์การกําหนดค่าสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS) |
Slot | อินเทอร์เฟซการกําหนดค่าหลักสําหรับการตั้งค่าระดับช่อง |
Taxonomy | ออบเจ็กต์ที่มีค่าสำหรับการจัดหมวดหมู่เดียว |
ประเภทอีเมลแทน | |
---|---|
Interstitial | ทริกเกอร์โฆษณาคั่นระหว่างหน้าที่รองรับ |
Privacy | การดูแลด้านความเป็นส่วนตัวของผู้เผยแพร่โฆษณาที่รองรับ |
Taxonomy | การจัดหมวดหมู่ที่รองรับสำหรับสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS) |
ประเภทอีเมลแทน
InterstitialTrigger
InterstitialTrigger: "unhideWindow" | "navBar"
PrivacyTreatment
PrivacyTreatment: "disablePersonalization"
การจัดหมวดหมู่
Taxonomy: "IAB_AUDIENCE_1_1" | "IAB_CONTENT_2_2"
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
พร็อพเพอร์ตี้ | |
---|---|
auction | ออบเจ็กต์การกําหนดค่าการประมูลสําหรับการประมูลคอมโพเนนต์นี้ |
config | คีย์การกําหนดค่าที่เชื่อมโยงกับการประมูลคอมโพเนนต์นี้ |
พร็อพเพอร์ตี้
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
พร็อพเพอร์ตี้ | |
---|---|
require | จำเป็นต้องขอความยินยอมในการจัดเก็บข้อมูลในเครื่องเพื่อแสดงโฆษณาคั่นระหว่างหน้านี้หรือไม่ |
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, });
พร็อพเพอร์ตี้ | |
---|---|
ad | การตั้งค่าเพื่อควบคุมการขยายโฆษณา |
ad | เลิกใช้งานแล้ว |
pps | การตั้งค่าเพื่อควบคุมสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS) |
privacy | การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา |
thread | การตั้งค่าเพื่อควบคุมว่า GPT ควรสร้างเธรด JS เมื่อแสดงผลครีเอทีฟโฆษณาหรือไม่ |
พร็อพเพอร์ตี้
Optional
adExpansion
adExpansion?: null | AdExpansionConfig
Optional
adYield
adYield?: null | "DISABLED" | "ENABLED_ALL_SLOTS"
Optional
pps
pps?: null | PublisherProvidedSignalsConfig
Optional
privacyTreatments
privacyTreatments?: null | PrivacyTreatmentsConfig
Optional
threadYield
threadYield?: null | "DISABLED" | "ENABLED_ALL_SLOTS"
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
พร็อพเพอร์ตี้ | |
---|---|
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, });
พร็อพเพอร์ตี้ | |
---|---|
ad | การตั้งค่าเพื่อควบคุมการขยายโฆษณา |
component | อาร์เรย์ของการประมูลคอมโพเนนต์ที่จะรวมอยู่ในการประมูลโฆษณาบนอุปกรณ์ |
interstitial | การตั้งค่าที่ควบคุมลักษณะการทํางานของช่องโฆษณาคั่นระหว่างหน้า |
พร็อพเพอร์ตี้
Optional
adExpansion
adExpansion?: null | AdExpansionConfig
Optional
componentAuction
componentAuction?: null | ComponentAuctionConfig[]
Optional
โฆษณาคั่นระหว่างหน้า
interstitial?: null | InterstitialConfig
googletag.config.TaxonomyData
พร็อพเพอร์ตี้ | |
---|---|
values | รายการค่า Taxonomy |
พร็อพเพอร์ตี้
values
values: string[]
googletag.enums
การแจงนับ | |
---|---|
Out | รูปแบบโฆษณานอกหน้าเว็บที่ GPT รองรับ |
Traffic | แหล่งที่มาของการเข้าชมที่ GPT รองรับ |
การแจงนับ
OutOfPageFormat
OutOfPageFormat
- ดูเพิ่มเติม
สมาชิกการแจงนับ | |
---|---|
BOTTOM_ | รูปแบบการยึดตำแหน่งที่ช่องโฆษณาติดอยู่ที่ด้านล่างของวิวพอร์ต |
GAME_ | รูปแบบโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกม หมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง |
INTERSTITIAL | รูปแบบครีเอทีฟโฆษณาคั่นระหว่างหน้าในเว็บ |
LEFT_ | รูปแบบโฆษณาที่แถบข้างด้านซ้าย |
REWARDED | รูปแบบที่มีการให้รางวัล |
RIGHT_ | รูปแบบโฆษณาที่แถบข้างด้านขวา |
TOP_ | รูปแบบตำแหน่งเฉพาะที่ช่องโฆษณาติดอยู่ที่ด้านบนของวิวพอร์ต |
TrafficSource
TrafficSource
- ดูเพิ่มเติม
สมาชิกการแจงนับ | |
---|---|
ORGANIC | รายการ URL โดยตรง การค้นหาเว็บไซต์ หรือการดาวน์โหลดแอป |
PURCHASED | การเข้าชมที่เปลี่ยนเส้นทางจากพร็อพเพอร์ตี้นอกเหนือจากที่เป็นเจ้าของ (ได้มาหรือกิจกรรมที่จูงใจ) |
googletag.events
อินเทอร์เฟซ | |
---|---|
Event | อินเทอร์เฟซพื้นฐานสําหรับเหตุการณ์ GPT ทั้งหมด |
Event | นี่เป็นประเภทจำลองที่แมปชื่อเหตุการณ์กับประเภทออบเจ็กต์เหตุการณ์ที่เกี่ยวข้องสำหรับ Service.addEventListener และ Service.removeEventListener |
Game | เหตุการณ์นี้จะเริ่มต้นเมื่อผู้ใช้ปิดสล็อตโฆษณาคั่นระหว่างหน้าของเกมด้วยตนเอง |
Game | เหตุการณ์นี้จะเริ่มต้นเมื่อช่องโฆษณาคั่นระหว่างหน้าที่กำหนดเองของเกมพร้อมที่จะแสดงต่อผู้ใช้ |
Impression | เหตุการณ์นี้จะทริกเกอร์เมื่อการแสดงผลปรากฏขึ้นตามเกณฑ์มุมมองแอ็กทีฟ |
Rewarded | เหตุการณ์นี้จะเริ่มต้นเมื่อผู้ใช้ปิดช่องโฆษณาที่มีการให้รางวัล |
Rewarded | เหตุการณ์นี้จะเริ่มต้นเมื่อมีการมอบรางวัลสำหรับการดูโฆษณาที่มีการให้รางวัล |
Rewarded | เหตุการณ์นี้จะเริ่มต้นเมื่อโฆษณาที่มีการให้รางวัลพร้อมแสดง |
Slot | เหตุการณ์นี้จะเริ่มต้นเมื่อ iframe ของครีเอทีฟโฆษณาเริ่มเหตุการณ์การโหลด |
Slot | เหตุการณ์นี้จะเริ่มต้นขึ้นเมื่อมีการแทรกโค้ดครีเอทีฟโฆษณาลงในช่อง |
Slot | เหตุการณ์นี้จะเริ่มต้นเมื่อมีการขอโฆษณาสําหรับช่องหนึ่งๆ |
Slot | เหตุการณ์นี้จะเริ่มต้นเมื่อได้รับการตอบกลับโฆษณาสําหรับช่องหนึ่งๆ |
Slot | เหตุการณ์นี้จะเริ่มต้นเมื่อใดก็ตามที่เปอร์เซ็นต์พื้นที่บนหน้าจอของช่องโฆษณามีการเปลี่ยนแปลง |
googletag.events.Event
พร็อพเพอร์ตี้ | |
---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ |
slot | ช่องที่ทริกเกอร์เหตุการณ์ |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
serviceName
serviceName: string
slot
slot: Slot
googletag.events.EventTypeMap
พร็อพเพอร์ตี้
gameManualInterstitialSlotClosed
gameManualInterstitialSlotClosed: GameManualInterstitialSlotClosedEvent
gameManualInterstitialSlotReady
gameManualInterstitialSlotReady: GameManualInterstitialSlotReadyEvent
impressionViewable
impressionViewable: ImpressionViewableEvent
rewardedSlotClosed
rewardedSlotClosed: RewardedSlotClosedEvent
rewardedSlotGranted
rewardedSlotGranted: RewardedSlotGrantedEvent
rewardedSlotReady
rewardedSlotReady: RewardedSlotReadyEvent
slotOnload
slotOnload: SlotOnloadEvent
slotRenderEnded
slotRenderEnded: SlotRenderEndedEvent
slotRequested
slotRequested: SlotRequestedEvent
slotResponseReceived
slotResponseReceived: SlotResponseReceived
slotVisibilityChanged
slotVisibilityChanged: SlotVisibilityChangedEvent
googletag.events.GameManualInterstitialSlotClosedEvent
ขยายเวลาหมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง
พร็อพเพอร์ตี้ | |
---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
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
ขยายเวลาหมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง
พร็อพเพอร์ตี้ | |
---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
slot | ช่องที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
เมธอด | |
---|---|
make | แสดงโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมต่อผู้ใช้ |
- ตัวอย่าง
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
ขยายเวลาพร็อพเพอร์ตี้ | |
---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
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
ขยายเวลาพร็อพเพอร์ตี้ | |
---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
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
ขยายเวลาพร็อพเพอร์ตี้ | |
---|---|
payload | ออบเจ็กต์ที่มีข้อมูลเกี่ยวกับรางวัลที่ได้รับ |
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
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
ขยายเวลาพร็อพเพอร์ตี้ | |
---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
slot | ช่องที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
เมธอด | |
---|---|
make | แสดงโฆษณาที่มีการให้รางวัล |
- ตัวอย่าง
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
ขยายเวลาSlotOnloadEvent
พร็อพเพอร์ตี้ | |
---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
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
ขยายเวลาพร็อพเพอร์ตี้ | |
---|---|
advertiser | รหัสผู้ลงโฆษณาของโฆษณาที่แสดงผล |
campaign | รหัสแคมเปญของโฆษณาที่แสดงผล |
company | รหัสของบริษัทที่เสนอราคาสําหรับโฆษณาทดแทนที่แสดงผล |
creative | รหัสครีเอทีฟโฆษณาของโฆษณาการจองที่แสดงผล |
creative | รหัสเทมเพลตครีเอทีฟโฆษณาของโฆษณาการจองที่ผ่านการจัดการแสดงผล |
is | โฆษณาเป็นโฆษณาทดแทนหรือไม่ |
is | มีการแสดงโฆษณาสําหรับช่องหรือไม่ |
label | เลิกใช้งานแล้ว |
line | รหัสรายการโฆษณาของโฆษณาการจองที่แสดงผล |
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
size | ระบุขนาดพิกเซลของครีเอทีฟโฆษณาที่แสดงผล |
slot | ช่องที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
slot | เนื้อหาของช่องมีการเปลี่ยนแปลงเมื่อแสดงโฆษณาที่ผ่านการจัดการแสดงผลแล้วหรือไม่ |
source | รหัสครีเอทีฟโฆษณาของการจองที่แสดงผลแล้วหรือโฆษณาทดแทน |
source | รหัสรายการโฆษณาของการจองที่แสดงผลแล้วหรือโฆษณาทดแทน |
yield | รหัสของกลุ่มผลตอบแทนสําหรับโฆษณาทดแทนที่แสดงผลแล้ว |
- ตัวอย่าง
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
สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicecampaignId
campaignId: null | number
null
สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicecompanyIds
companyIds: null | number[]
null
สำหรับช่องว่าง โฆษณาแบบจองล่วงหน้า และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicecreativeId
creativeId: null | number
null
สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicecreativeTemplateId
creativeTemplateId: null | number
null
สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServiceisBackfill
isBackfill: boolean
true
หากโฆษณาเป็นโฆษณาทดแทน หรือ false
หากไม่ใช่isEmpty
isEmpty: boolean
true
หากไม่มีการแสดงโฆษณา หรือ false
หากมีการแสดงโฆษณาlabelIds
labelIds: null | number[]
lineItemId
lineItemId: null | number
null
สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicesize
size: null | string | number[]
[728, 90]
ค่าคือ null
สำหรับช่องโฆษณาว่างslotContentChanged
slotContentChanged: boolean
true
หากเนื้อหามีการเปลี่ยนแปลง และเป็น false
ในกรณีอื่นๆsourceAgnosticCreativeId
sourceAgnosticCreativeId: null | number
null
หากโฆษณาไม่ใช่การจองหรือโฆษณาที่แสดงแทนรายการโฆษณาที่ขาดหายไป หรือครีเอทีฟโฆษณาแสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicesourceAgnosticLineItemId
sourceAgnosticLineItemId: null | number
null
หากโฆษณาไม่ใช่การจองหรือโฆษณาที่แสดงแทนรายการโฆษณาที่ขาดหายไป หรือครีเอทีฟโฆษณาแสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServiceyieldGroupIds
yieldGroupIds: null | number[]
null
สำหรับช่องว่าง โฆษณาแบบจองล่วงหน้า และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicegoogletag.events.SlotRequestedEvent
ขยายเวลาพร็อพเพอร์ตี้ | |
---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
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
ขยายเวลาพร็อพเพอร์ตี้ | |
---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
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
ขยายเวลาพร็อพเพอร์ตี้ | |
---|---|
in | เปอร์เซ็นต์ของพื้นที่โฆษณาที่มองเห็นได้ |
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก |
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
googletag.secureSignals
อินเทอร์เฟซ | |
---|---|
Bidder | แสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เสนอราคาที่เฉพาะเจาะจง |
Publisher | แสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เผยแพร่โฆษณาที่เฉพาะเจาะจง |
Secure | อินเทอร์เฟซสำหรับจัดการสัญญาณที่ปลอดภัย |
ประเภทอีเมลแทน | |
---|---|
Secure | อินเทอร์เฟซสําหรับแสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เสนอราคาหรือผู้ให้บริการที่เฉพาะเจาะจง |
ประเภทอีเมลแทน
SecureSignalProvider
SecureSignalProvider: BidderSignalProvider | PublisherSignalProvider
id
หรือ networkCode
อย่างใดอย่างหนึ่งgoogletag.secureSignals.BidderSignalProvider
ผู้ให้บริการสัญญาณที่ปลอดภัยสำหรับผู้เสนอราคาประกอบด้วย 2 ส่วน ได้แก่
- ฟังก์ชันรวบรวม ซึ่งแสดงผล
Promise
ที่แก้ไขเป็นสัญญาณที่ปลอดภัย id
ที่ระบุผู้เสนอราคาที่เชื่อมโยงกับสัญญาณ
พร็อพเพอร์ตี้ | |
---|---|
collector | ฟังก์ชันที่แสดงผล 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
googletag.secureSignals.PublisherSignalProvider
ผู้ให้บริการสัญญาณของผู้เผยแพร่โฆษณาประกอบด้วย 2 ส่วน ได้แก่
- ฟังก์ชันรวบรวม ซึ่งแสดงผล
Promise
ที่แก้ไขเป็นสัญญาณที่ปลอดภัย networkCode
ที่ระบุผู้เผยแพร่โฆษณาที่เชื่อมโยงกับสัญญาณ
พร็อพเพอร์ตี้ | |
---|---|
collector | ฟังก์ชันที่แสดงผล Promise ซึ่งจะแสดงผลเป็นสัญญาณที่ปลอดภัย |
network | รหัสเครือข่าย (ตามที่เห็นในเส้นทางหน่วยโฆษณา) ของผู้เผยแพร่โฆษณาที่เชื่อมโยงกับสัญญาณที่ปลอดภัยนี้ |
- ตัวอย่าง
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
เมธอด | |
---|---|
clear | ล้างสัญญาณทั้งหมดสําหรับเครื่องมือรวบรวมข้อมูลทั้งหมดออกจากแคช |
push | เพิ่ม secureSignals.SecureSignalProvider ใหม่ลงในอาร์เรย์ผู้ให้บริการสัญญาณและเริ่มกระบวนการสร้างสัญญาณ |
เมธอด
clearAllCache
clearAllCache(): void
การเรียกใช้เมธอดนี้อาจลดโอกาสที่สัญญาณจะรวมอยู่ในคําขอโฆษณาสําหรับการดูหน้าเว็บปัจจุบันและที่อาจเกิดขึ้นในภายหลัง ด้วยเหตุนี้ จึงควรเรียกใช้เฉพาะเมื่อมีการเปลี่ยนแปลงสถานะที่มีความหมาย เช่น เหตุการณ์ที่บ่งบอกถึงผู้ใช้ใหม่ (เข้าสู่ระบบ ออกจากระบบ ลงชื่อสมัครใช้ ฯลฯ)
push
push(provider: SecureSignalProvider): void
พารามิเตอร์ | |
---|---|
provider: SecureSignalProvider | ออบเจ็กต์ secureSignals.SecureSignalProvider ที่จะเพิ่มลงในอาร์เรย์ |