ข้อมูลอ้างอิงนี้ใช้สัญกรณ์ TypeScript เพื่ออธิบายประเภท ตารางต่อไปนี้แสดงคำอธิบายสั้นๆ พร้อมตัวอย่าง
| พิมพ์นิพจน์ | |
|---|---|
string |
ประเภทสตริงพื้นฐาน |
string[] |
ประเภทอาร์เรย์ที่ค่าต้องเป็นสตริงเท่านั้น |
number | string |
ประเภทยูเนียนที่ค่าอาจเป็นตัวเลขหรือสตริงก็ได้ |
Array<number | string> |
ประเภทอาร์เรย์ โดยที่ค่าเป็นประเภทที่ซับซ้อน (ยูเนียน) |
[number, string] |
ประเภท Tuple โดยที่ค่าเป็นอาร์เรย์ 2 องค์ประกอบซึ่งต้องมีตัวเลขและสตริงตามลำดับ |
Slot |
ประเภทออบเจ็กต์ โดยที่ค่าเป็นอินสแตนซ์ของ googletag.Slot |
() => void |
ประเภทฟังก์ชันที่ไม่มีอาร์กิวเมนต์ที่กำหนดไว้และไม่มีค่าที่แสดงผล |
ดูข้อมูลเพิ่มเติมเกี่ยวกับประเภทและนิพจน์ประเภทที่รองรับได้ใน คู่มือ TypeScript
คำอธิบายประกอบประเภท
เครื่องหมายโคลอนหลังตัวแปร ชื่อพารามิเตอร์ ชื่อพร็อพเพอร์ตี้ หรือลายเซ็นของฟังก์ชันหมายถึงคำอธิบายประกอบประเภท คำอธิบายประกอบประเภทจะอธิบายประเภทที่องค์ประกอบทางด้านซ้ายของโคลอนสามารถยอมรับหรือแสดงผลได้ ตารางต่อไปนี้แสดงตัวอย่างคำอธิบายประกอบประเภทที่คุณอาจเห็นในข้อมูลอ้างอิงนี้
| คำอธิบายประกอบประเภท | |
|---|---|
param: string |
ระบุว่า param ยอมรับหรือแสดงผลค่าสตริง ไวยากรณ์นี้ใช้สำหรับตัวแปร พารามิเตอร์ พร็อพเพอร์ตี้ และประเภทการแสดงผล
|
param?: number | string |
ระบุว่า param เป็นตัวเลือกที่ไม่บังคับ แต่จะยอมรับตัวเลขหรือสตริงเมื่อระบุ ไวยากรณ์นี้ใช้สำหรับพารามิเตอร์และพร็อพเพอร์ตี้
|
...params: Array<() => void> |
ระบุว่า params เป็น
พารามิเตอร์ที่เหลือ
ซึ่งยอมรับฟังก์ชัน พารามิเตอร์ที่เหลือจะยอมรับค่าของประเภทที่ระบุได้ไม่จำกัดจำนวน
|
googletag
| เนมสเปซ | |
|---|---|
config | อินเทอร์เฟซการกำหนดค่าหลักสำหรับการตั้งค่าระดับหน้าเว็บ |
enums | นี่คือเนมสเปซที่ GPT ใช้สำหรับประเภท enum |
events | นี่คือเนมสเปซที่ GPT ใช้สำหรับเหตุการณ์ |
secure | นี่คือเนมสเปซที่ GPT ใช้เพื่อจัดการสัญญาณที่ปลอดภัย |
| อินเทอร์เฟซ | |
|---|---|
Command | อาร์เรย์คำสั่งจะยอมรับลำดับของฟังก์ชันและเรียกใช้ตามลำดับ |
Companion | บริการโฆษณาที่แสดงร่วม |
Privacy | ออบเจ็กต์การกำหนดค่าสำหรับการตั้งค่าความเป็นส่วนตัว |
Pub | บริการโฆษณาของผู้เผยแพร่โฆษณา |
Request | ระบบจะเรียกใช้ฟังก์ชัน Callback ก่อนคำขอโฆษณาแต่ละรายการเมื่อลงทะเบียนผ่าน PubAdsService.registerRequestHook |
Response | ออบเจ็กต์ที่แสดงการตอบกลับโฆษณารายการเดียว |
Rewarded | ออบเจ็กต์ที่แสดงรางวัลที่เชื่อมโยงกับโฆษณาที่มีการให้รางวัล |
Service | คลาสบริการพื้นฐานที่มีเมธอดที่ใช้ร่วมกันสำหรับบริการทั้งหมด |
Size | เครื่องมือสร้างออบเจ็กต์ข้อกำหนดการแมปขนาด |
Slot | ช่องคือออบเจ็กต์ที่แสดงช่องโฆษณาเดียวในหน้าเว็บ |
| ชื่อแทนประเภท | |
|---|---|
Fluid | สตริงขนาดที่คอนเทนเนอร์โฆษณาใช้ความกว้าง 100% ของ div หลัก แล้วปรับขนาดความสูงให้พอดีกับเนื้อหาครีเอทีฟโฆษณา |
General | การกำหนดค่าขนาดที่ถูกต้องสำหรับช่องโฆษณา ซึ่งอาจเป็นขนาดเดียวหรือหลายขนาดก็ได้ |
Multi | รายการขนาดที่ถูกต้องรายการเดียว |
Named | ขนาดที่ตั้งชื่อไว้ซึ่งช่องโฆษณาสามารถมีได้ |
Single | ขนาดที่ถูกต้องขนาดเดียวสำหรับช่องโฆษณา |
Single | อาร์เรย์ของตัวเลข 2 ตัวที่แสดง [ความกว้าง ความสูง] |
Size | การแมปขนาดวิวพอร์ตกับขนาดโฆษณา |
Size | รายการการแมปขนาด |
| ตัวแปร | |
|---|---|
api | การแจ้งที่ระบุว่ามีการโหลด GPT API และพร้อมที่จะเรียกใช้ |
cmd | การอ้างอิงคิวคำสั่งส่วนกลางสำหรับการเรียกใช้ที่เกี่ยวข้องกับ GPT แบบอะซิงโครนัส |
pubads | การแจ้งที่ระบุว่ามีการเปิดใช้ PubAdsService โหลดแล้ว และทำงานได้อย่างสมบูรณ์ |
secure | การอ้างอิงอาร์เรย์ผู้ให้บริการสัญญาณที่ปลอดภัย |
| ฟังก์ชัน | |
|---|---|
companion | แสดงผลการอ้างอิงไปยัง CompanionAdsService |
define | สร้างช่องโฆษณาที่ไม่อยู่ในขอบเขตหน้าด้วยเส้นทางหน่วยโฆษณาที่ระบุ |
define | สร้างช่องโฆษณาที่มีเส้นทางและขนาดหน่วยโฆษณาที่ระบุ และเชื่อมโยงกับรหัสขององค์ประกอบ div ในหน้าเว็บที่จะมีโฆษณา |
destroy | ทำลายช่องที่ระบุ โดยนำออบเจ็กต์และการอ้างอิงที่เกี่ยวข้องทั้งหมดของช่องเหล่านั้นออกจาก GPT |
disable | ปิดใช้คอนโซลผู้เผยแพร่โฆษณาของ Google |
display | สั่งให้บริการช่องโฆษณาแสดงผลช่องโฆษณา |
enable | เปิดใช้บริการ GPT ทั้งหมดที่กำหนดไว้สำหรับช่องโฆษณาในหน้าเว็บ |
get | รับสำเนาที่ตรึงไว้ของตัวเลือกการกำหนดค่าทั่วไปสำหรับหน้าเว็บที่ตั้งค่าโดย setConfig |
get | แสดงผล GPT เวอร์ชันปัจจุบัน |
open | เปิดคอนโซลผู้เผยแพร่โฆษณาของ Google |
pubads | แสดงผลการอ้างอิงไปยัง PubAdsService |
set | ตั้งชื่อ iframe ของคอนเทนเนอร์โฆษณาทั้งหมดที่สร้างโดย PubAdsService ตั้งแต่จุดนี้เป็นต้นไป |
set | ตั้งค่าตัวเลือกการกำหนดค่าทั่วไปสำหรับหน้าเว็บ |
size | สร้าง SizeMappingBuilder ใหม่ |
ชื่อแทนประเภท
FluidSize
FluidSize: "fluid"GeneralSize
GeneralSize: SingleSize | MultiSizeMultiSize
MultiSize: SingleSize[]NamedSize
- fluid: คอนเทนเนอร์โฆษณาจะใช้ความกว้าง 100% ของ div หลัก จากนั้นจะปรับขนาดความสูงให้พอดีกับเนื้อหาครีเอทีฟโฆษณา ซึ่งคล้ายกับลักษณะการทำงานขององค์ประกอบบล็อกปกติในหน้าเว็บ ใช้สำหรับโฆษณาเนทีฟและแบนเนอร์ (ดูบทความที่เกี่ยวข้อง) โปรดทราบว่าทั้ง
fluidและ['fluid']เป็นรูปแบบที่ยอมรับได้ในการประกาศขนาดช่องโฆษณาเป็นแบบยืดหยุ่น
SingleSize
SingleSize: SingleSizeArray | NamedSizeSingleSizeArray
SingleSizeArray: [number, number]SizeMapping
SizeMapping: [SingleSizeArray, GeneralSize]SizeMappingArray
SizeMappingArray: SizeMapping[]ตัวแปร
Const apiReady
apiReady: boolean | undefinedundefined จนกว่า API จะพร้อมใช้งานโปรดทราบว่าวิธีที่แนะนำในการจัดการอะซิงโครนัสคือการใช้ googletag.cmd เพื่อจัดคิว Callback เมื่อ GPT พร้อมใช้งาน Callback เหล่านี้ไม่จำเป็นต้องตรวจสอบ googletag.apiReady เนื่องจากรับประกันว่าจะทำงานเมื่อตั้งค่า API แล้ว
Const cmd
cmd: ((this: typeof globalThis) => void)[] | CommandArrayตัวแปร
googletag.cmd จะเริ่มต้นเป็นอาร์เรย์ JavaScript ที่ว่างเปล่าตามไวยากรณ์แท็ก GPT ในหน้าเว็บ และ cmd.push เป็นเมธอด Array.push มาตรฐานที่เพิ่มองค์ประกอบต่อท้ายอาร์เรย์ เมื่อโหลด JavaScript ของ GPT แล้ว ระบบจะตรวจสอบอาร์เรย์และเรียกใช้ฟังก์ชันทั้งหมดตามลำดับ จากนั้นสคริปต์จะแทนที่ cmd ด้วยออบเจ็กต์ CommandArray ซึ่งมีการกำหนดเมธอดพุชเพื่อเรียกใช้อาร์กิวเมนต์ฟังก์ชันที่ส่งไปยังออบเจ็กต์ กลไกนี้ช่วยให้ GPT ลดเวลาในการตอบสนองที่รับรู้ได้โดยการดึงข้อมูล JavaScript แบบอะซิงโครนัสขณะที่อนุญาตให้เบราว์เซอร์แสดงผลหน้าเว็บต่อไป- ตัวอย่าง
JavaScript
googletag.cmd.push(() => { 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 | undefinedundefined จนกว่าจะมีการเรียกใช้ 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"); }, });
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);
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");
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 ดังนั้นคำขอในอนาคตจะไม่ได้รับอิทธิพลจาก Roadblock หรือการยกเว้นการแข่งขันที่เกี่ยวข้องกับโฆษณานี้ หากไม่เรียกใช้ฟังก์ชันนี้ก่อนนำ 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();
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(): voidgetConfig
getConfig(keys: string | string[]): Readonly<Pick<PageSettingsConfig, "adsenseAttributes" | "disableInitialLoad" | "targeting">>เมธอดนี้ไม่รองรับพร็อพเพอร์ตี้
setConfig() บางรายการ พร็อพเพอร์ตี้ที่รองรับมีดังนี้- ตัวอย่าง
JavaScript
// Get the value of the `targeting` setting. const targetingConfig = googletag.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `disableInitialLoad` settings. const config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);
TypeScript
// Get the value of the `targeting` setting. const targetingConfig = googletag.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `disableInitialLoad` settings. const config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);
| พารามิเตอร์ | |
|---|---|
keys: string | string[] | คีย์ของตัวเลือกการกำหนดค่าที่จะรับ |
| การคืนสินค้า | |
|---|---|
Readonly<Pick<PageSettingsConfig, "adsenseAttributes" | "disableInitialLoad" | "targeting">> | สำเนาที่คงที่ของตัวเลือกการกำหนดค่าสำหรับหน้าเว็บ |
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();
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");
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()); });
TypeScript
googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600])!.addService(googletag.pubads()); });
| พารามิเตอร์ | |
|---|---|
| ฟังก์ชัน JavaScript ที่จะเรียกใช้ การเชื่อมโยงรันไทม์จะเป็น globalThis เสมอ ลองส่งฟังก์ชันลูกศรเพื่อคงค่า this ของบริบทเชิงคำศัพท์ที่ล้อมรอบไว้ |
| การคืนสินค้า | |
|---|---|
number | จำนวนคำสั่งที่ประมวลผลจนถึงตอนนี้ ซึ่งเข้ากันได้กับค่าที่แสดงผลของ Array.push (ความยาวปัจจุบันของอาร์เรย์) |
googletag.CompanionAdsService
Service| เมธอด | |
|---|---|
add | ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้าเว็บ รับค่ามาจากเมธอด |
get | ดูรายการช่วงเวลาที่เชื่อมโยงกับบริการนี้ รับค่ามาจากเมธอด |
remove | นำ Listener ที่ลงทะเบียนไว้ก่อนหน้านี้ออก รับค่ามาจากเมธอด |
set | กำหนดว่าจะให้ช่องโฆษณาที่แสดงร่วมที่ยังไม่ได้รับโฆษณาได้รับโฆษณาทดแทนโดยอัตโนมัติหรือไม่ |
- ดูเพิ่มเติม
เมธอด
setRefreshUnfilledSlots
setRefreshUnfilledSlots(value: boolean): voidคุณสามารถเรียกใช้เมธอดนี้ได้หลายครั้งตลอดอายุของหน้าเว็บเพื่อเปิดและปิดการทดแทนโฆษณา ระบบจะทดแทนโฆษณาเฉพาะช่องที่ลงทะเบียนกับ PubAdsService ด้วยเท่านั้น เนื่องจากข้อจำกัดด้านนโยบาย วิธีนี้จึงไม่ได้ออกแบบมาเพื่อเติมช่องที่ว่างอยู่ของโฆษณาที่แสดงร่วมเมื่อมีการแสดงวิดีโอ Ad Exchange
- ตัวอย่าง
JavaScript
googletag.companionAds().setRefreshUnfilledSlots(true);
TypeScript
googletag.companionAds().setRefreshUnfilledSlots(true);
| พารามิเตอร์ | |
|---|---|
value: boolean | true เพื่อทดแทนช่องโฆษณาที่ไม่ได้แสดงโดยอัตโนมัติ false เพื่อปล่อยไว้ตามเดิม |
googletag.PrivacySettingsConfig
| พร็อพเพอร์ตี้ | |
|---|---|
child | ระบุว่าควรดูแลหน้าเว็บให้เหมาะสมกับเด็กหรือไม่ |
limited | เปิดใช้การแสดงโฆษณาในโหมดโฆษณาแบบจำกัดเพื่อช่วยตอบสนองความต้องการด้านการปฏิบัติตามกฎระเบียบของผู้เผยแพร่โฆษณา |
non | เปิดใช้การแสดงโฆษณาในโหมดโฆษณาที่ไม่ได้ปรับตามโปรไฟล์ของผู้ใช้เพื่อช่วยให้ผู้เผยแพร่โฆษณาปฏิบัติตามกฎระเบียบได้ตามต้องการ |
restrict | เปิดใช้การแสดงโฆษณาให้ทำงานในโหมดการประมวลผลแบบจำกัดเพื่อช่วยตอบสนองความต้องการด้านการปฏิบัติตามกฎระเบียบของผู้เผยแพร่โฆษณา |
tag | การดูแลแบบจำกัดอายุ ซึ่งระบุว่าควรดูแลคำขอโฆษณาเป็นเด็ก วัยรุ่น หรือไม่ระบุ |
traffic | ระบุว่าคำขอแสดงถึงการเข้าชมที่ซื้อมาหรือการเข้าชมจากการค้นหาทั่วไป |
under | ระบุว่าจะทำเครื่องหมายคำขอโฆษณาว่ามาจากผู้ใช้ที่อายุต่ำกว่าอายุที่ให้ความยินยอมได้หรือไม่ |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
Optional childDirectedTreatment
childDirectedTreatment?: booleannull เพื่อล้างการกำหนดค่า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, });
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?: booleanOptional restrictDataProcessing
restrictDataProcessing?: booleanOptional tagForAgeTreatment
tagForAgeTreatment?: TagForAgeTreatmentโปรดปรึกษาที่ปรึกษาด้านกฎหมายเพื่อกำหนดการตั้งค่าการดูแลตามอายุสำหรับผู้ใช้ตามข้อกำหนดทางกฎหมายและกฎระเบียบ ดูข้อมูลเพิ่มเติมเกี่ยวกับการตั้งค่านี้ได้ที่บทความในศูนย์ช่วยเหลือ
การตั้งค่าพร็อพเพอร์ตี้นี้เป็นการรับรองว่าการแจ้งเตือนนี้ถูกต้อง และคุณได้รับอนุญาตให้ดำเนินการในนามของเจ้าของเว็บไซต์ คุณเข้าใจว่าการใช้การตั้งค่านี้ในทางที่ผิดอาจส่งผลให้มีการสิ้นสุดการใช้งานบัญชี Google ของคุณ
- ตัวอย่าง
JavaScript
// Enable teen privacy treatment. googletag.pubads().setPrivacySettings({ tagForAgeTreatment: googletag.enums.TagForAgeTreatment.TEEN, }); // Clear age treatment configuration. googletag.pubads().setPrivacySettings({ tagForAgeTreatment: googletag.enums.TagForAgeTreatment.UNSPECIFIED, });
TypeScript
// Enable teen privacy treatment. googletag.pubads().setPrivacySettings({ tagForAgeTreatment: googletag.enums.TagForAgeTreatment.TEEN, }); // Clear age treatment configuration. googletag.pubads().setPrivacySettings({ tagForAgeTreatment: googletag.enums.TagForAgeTreatment.UNSPECIFIED, });
Optional trafficSource
trafficSource?: TrafficSourceundefined ในการรายงาน- ตัวอย่าง
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?: booleannull เพื่อล้างการกำหนดค่าgoogletag.PubAdsService
Service| เมธอด | |
|---|---|
add | ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้าเว็บ รับค่ามาจากเมธอด |
clear | นำโฆษณาออกจากช่องที่กำหนดและแทนที่ด้วยเนื้อหาว่างเปล่า |
clear | เลิกใช้งานแล้ว ล้างป้ายกำกับการยกเว้นหมวดหมู่โฆษณาระดับหน้าเว็บทั้งหมด |
clear | เลิกใช้งานแล้ว ล้างพารามิเตอร์การกำหนดเป้าหมายเองสำหรับคีย์ที่เฉพาะเจาะจงหรือคีย์ทั้งหมด |
collapse | เลิกใช้งานแล้ว เปิดใช้การยุบ div ของช่องโฆษณาเพื่อไม่ให้ใช้พื้นที่ในหน้าเว็บเมื่อไม่มีเนื้อหาโฆษณาที่จะแสดง |
disable | เลิกใช้งานแล้ว ปิดใช้คำขอโฆษณาในการโหลดหน้าเว็บ แต่อนุญาตให้ขอโฆษณาด้วยการเรียก PubAdsService.refresh |
display | สร้างและแสดงช่องโฆษณาที่มีเส้นทางและขนาดหน่วยโฆษณาที่ระบุ |
enable | เลิกใช้งานแล้ว เปิดใช้การโหลดแบบ Lazy Loading ใน GPT ตามที่กำหนดโดยออบเจ็กต์การกำหนดค่า |
enable | เลิกใช้งานแล้ว เปิดใช้โหมดคำขอเดี่ยวเพื่อดึงโฆษณาหลายรายการพร้อมกัน |
enable | เลิกใช้งานแล้ว ส่งสัญญาณไปยัง GPT ว่าจะมีโฆษณาวิดีโอในหน้าเว็บ |
get | เลิกใช้งานแล้ว แสดงค่าสำหรับแอตทริบิวต์ AdSense ที่เชื่อมโยงกับคีย์ที่ระบุ |
get | เลิกใช้งานแล้ว แสดงผลคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในบริการนี้ |
get | ดูรายการช่วงเวลาที่เชื่อมโยงกับบริการนี้ รับค่ามาจากเมธอด |
get | เลิกใช้งานแล้ว แสดงผลพารามิเตอร์การกำหนดเป้าหมายระดับบริการที่กำหนดเองที่เฉพาะเจาะจงซึ่งตั้งค่าไว้ |
get | เลิกใช้งานแล้ว แสดงรายการคีย์การกำหนดเป้าหมายระดับบริการที่กำหนดเองทั้งหมดที่ตั้งค่าไว้ |
is | เลิกใช้งานแล้ว แสดงผลว่าการเรียกใช้ PubAdsService.disableInitialLoad ก่อนหน้านี้ปิดใช้คำขอโฆษณาเริ่มต้นสำเร็จหรือไม่ |
refresh | ดึงข้อมูลและแสดงโฆษณาใหม่สำหรับช่องโฆษณาที่เฉพาะเจาะจงหรือช่องโฆษณาทั้งหมดในหน้าเว็บ |
register | ลงทะเบียนฮุกที่จะดำเนินการควบคู่ไปกับฮุกอื่นๆ ที่ลงทะเบียนไว้ก่อนคำขอโฆษณาแต่ละรายการในหน้าเว็บภายในระยะหมดเวลาทั่วโลก |
remove | นำ Listener ที่ลงทะเบียนไว้ก่อนหน้านี้ออก รับค่ามาจากเมธอด |
set | เลิกใช้งานแล้ว ตั้งค่าแอตทริบิวต์ AdSense ที่ใช้กับช่องโฆษณาทั้งหมดในบริการโฆษณาของผู้เผยแพร่โฆษณา |
set | เลิกใช้งานแล้ว ตั้งค่าการยกเว้นหมวดหมู่โฆษณาระดับหน้าเว็บสำหรับชื่อป้ายกำกับที่ระบุ |
set | เลิกใช้งานแล้ว เปิดและปิดใช้การจัดโฆษณาให้อยู่กึ่งกลางในแนวนอน |
set | เลิกใช้งานแล้ว กำหนดค่าว่าจะบังคับให้โฆษณาทั้งหมดในหน้าแสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่ |
set | เลิกใช้งานแล้ว ส่งข้อมูลตำแหน่งจากเว็บไซต์เพื่อให้คุณกำหนดเป้าหมายทางภูมิศาสตร์ของรายการโฆษณาไปยังสถานที่ที่เฉพาะเจาะจงได้ |
set | อนุญาตให้กำหนดค่าการตั้งค่าความเป็นส่วนตัวทั้งหมดจาก API เดียวโดยใช้ออบเจ็กต์การกำหนดค่า |
set | ตั้งค่ารหัสที่ผู้เผยแพร่โฆษณามีให้ |
set | เลิกใช้งานแล้ว ตั้งค่ากำหนดระดับหน้าสำหรับการกำหนดค่า SafeFrame |
set | เลิกใช้งานแล้ว ตั้งค่าพารามิเตอร์การกำหนดเป้าหมายเองสำหรับคีย์ที่กำหนดซึ่งใช้กับช่องโฆษณาของบริการโฆษณาของผู้เผยแพร่โฆษณาทั้งหมด |
set | เลิกใช้งานแล้ว ตั้งค่าข้อมูลเนื้อหาวิดีโอที่จะส่งไปพร้อมกับคำขอโฆษณาเพื่อวัตถุประสงค์ในการกำหนดเป้าหมายและการยกเว้นเนื้อหา |
update | เปลี่ยน Correlator ที่ส่งพร้อมกับคำขอโฆษณา ซึ่งจะเริ่มการดูหน้าเว็บใหม่ได้อย่างมีประสิทธิภาพ |
เมธอด
clear
clear(slots?: Slot[]): booleanโดยเฉพาะอย่างยิ่ง การล้างช่องจะนำโฆษณาออกจากการดูหน้าเว็บที่ใช้เวลานานของ GPT ดังนั้นคำขอในอนาคตจะไม่ได้รับผลกระทบจาก Roadblock หรือการยกเว้นโฆษณาของคู่แข่งที่เกี่ยวข้องกับโฆษณานี้
- ตัวอย่าง
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();
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.setConfig({ categoryExclusion: ["AirlineAd"], }); // Make ad requests. No ad with 'AirlineAd' label will be returned. // Clear category exclusions so all ads can be returned. googletag.setConfig({ categoryExclusion: null, }); // Make ad requests. Any ad can be returned.
TypeScript
// Set category exclusion to exclude ads with 'AirlineAd' labels. googletag.setConfig({ categoryExclusion: ["AirlineAd"], }); // Make ad requests. No ad with 'AirlineAd' label will be returned. // Clear category exclusions so all ads can be returned. googletag.setConfig({ categoryExclusion: null, }); // Make ad requests. Any ad can be returned.
- ดูเพิ่มเติม
| การคืนสินค้า | |
|---|---|
PubAdsService | ออบเจ็กต์บริการที่มีการเรียกใช้เมธอด |
clearTargeting
clearTargeting(key?: string): PubAdsService- ตัวอย่าง
JavaScript
googletag.setConfig({ targeting: { interests: "sports", colors: "blue", fruits: "apple", }, }); googletag.setConfig({ targeting: { interests: null, }, }); // Targeting 'colors' and 'fruits' are still present, while 'interests' // was cleared. googletag.setConfig({ targeting: null, }); // All targeting has been cleared.
TypeScript
googletag.setConfig({ targeting: { interests: "sports", colors: "blue", fruits: "apple", }, }); googletag.setConfig({ targeting: { interests: null, }, }); // Targeting 'colors' and 'fruits' are still present, while 'interests' // was cleared. googletag.setConfig({ targeting: null, }); // All targeting has been cleared.
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| คีย์พารามิเตอร์การกำหนดเป้าหมาย คีย์เป็นแบบไม่บังคับ ระบบจะล้างพารามิเตอร์การกำหนดเป้าหมายทั้งหมดหากไม่ได้ระบุคีย์ |
| การคืนสินค้า | |
|---|---|
PubAdsService | ออบเจ็กต์บริการที่มีการเรียกใช้เมธอด |
collapseEmptyDivs
collapseEmptyDivs(collapseBeforeAdFetch?: boolean): boolean- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| เลือกว่าจะยุบช่องโฆษณาแม้ก่อนที่จะดึงข้อมูลโฆษณาหรือไม่ พารามิเตอร์นี้ไม่บังคับ หากไม่ได้ระบุ ระบบจะใช้ false เป็นค่าเริ่มต้น |
| การคืนสินค้า | |
|---|---|
boolean | แสดงผล true หากเปิดใช้โหมดยุบ div และ false หากเปิดใช้โหมดยุบไม่ได้เนื่องจากมีการเรียกใช้เมธอดหลังจากเปิดใช้บริการ |
disableInitialLoad
disableInitialLoad(): voidrefresh ไม่ได้- ดูเพิ่มเติม
display
display(adUnitPath: string, size: GeneralSize, div?: string | Element, clickUrl?: string): voidเมธอดนี้เป็นทางลัดที่เทียบเท่ากับการเรียก googletag.defineSlot ตามด้วย googletag.display ทันที
ลักษณะการทำงานของเมธอดนี้ขึ้นอยู่กับว่ามีการเปิดใช้สถาปัตยกรรมคำขอรวมครั้งเดียว (SRA) หรือไม่
- เปิดใช้ SRA: ระบบจะจัดกลุ่มและขอช่องโฆษณาทั้งหมดที่กำหนดไว้จนถึงจุดที่มีการเรียกนี้พร้อมกัน
- ปิดใช้ SRA (ค่าเริ่มต้น): ระบบจะขอช่องโฆษณาแยกกัน
display() หรือ refresh() ที่ตามมาเท่านั้น- ตัวอย่าง
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.setConfig({ lazyLoad: { // 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.setConfig({ lazyLoad: { // 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(): voidget
get(key: string): string- ตัวอย่าง
JavaScript
googletag.setConfig({ adsenseAttributes: { page_url: "http://www.example.com", }, }); const adsenseConfig = googletag.getConfig("adsenseAttributes").adsenseAttributes; const pageUrl = adsenseConfig?.page_url || null; // Returns 'http://www.example.com'.
TypeScript
googletag.setConfig({ adsenseAttributes: { page_url: "http://www.example.com", }, }); const adsenseConfig = googletag.getConfig("adsenseAttributes").adsenseAttributes; const pageUrl = adsenseConfig?.page_url || null; // Returns 'http://www.example.com'.
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
key: string | ชื่อของแอตทริบิวต์ที่ต้องการค้นหา |
| การคืนสินค้า | |
|---|---|
string | ค่าปัจจุบันของคีย์แอตทริบิวต์ หรือ null หากไม่มีคีย์ |
getAttributeKeys
getAttributeKeys(): string[]- ตัวอย่าง
JavaScript
googletag.setConfig({ adsenseAttributes: { page_url: "http://www.example.com", document_language: "en", }, }); const adsenseConfig = googletag.getConfig("adsenseAttributes").adsenseAttributes; const adsenseAttributes = Object.keys(adsenseConfig || {}); // Returns ['page_url', 'document_language'].
TypeScript
googletag.setConfig({ adsenseAttributes: { page_url: "http://www.example.com", document_language: "en", }, }); const adsenseConfig = googletag.getConfig("adsenseAttributes").adsenseAttributes; const adsenseAttributes = Object.keys(adsenseConfig || {}); // Returns ['page_url', 'document_language'].
| การคืนสินค้า | |
|---|---|
string[] | อาร์เรย์ของคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในบริการนี้ ไม่ได้กำหนดการจัดลำดับ |
getTargeting
getTargeting(key: string): string[]- ตัวอย่าง
JavaScript
googletag.setConfig({ targeting: { interests: "sports", }, }); const targetingConfig = googletag.getConfig("targeting").targeting; // Get targeting for a specific key. const targeting = targetingConfig?.["interests"] || []; // Returns ['sports']. const ageTargeting = targetingConfig?.["age"] || []; // Returns [] (empty array).
TypeScript
googletag.setConfig({ targeting: { interests: "sports", }, }); const targetingConfig = googletag.getConfig("targeting").targeting; // Get targeting for a specific key. const targeting = targetingConfig?.["interests"] || []; // Returns ['sports']. const ageTargeting = targetingConfig?.["age"] || []; // Returns [] (empty array).
| พารามิเตอร์ | |
|---|---|
key: string | คีย์การกำหนดเป้าหมายที่ต้องการค้นหา |
| การคืนสินค้า | |
|---|---|
string[] | ค่าที่เชื่อมโยงกับคีย์นี้ หรืออาร์เรย์ว่างหากไม่มีคีย์ดังกล่าว |
getTargetingKeys
getTargetingKeys(): string[]- ตัวอย่าง
JavaScript
googletag.setConfig({ targeting: { interests: "sports", colors: "blue", }, }); const targetingConfig = googletag.getConfig("targeting").targeting; const keys = Object.keys(targetingConfig || {}); // Returns ['interests', 'colors'].
TypeScript
googletag.setConfig({ targeting: { interests: "sports", colors: "blue", }, }); const targetingConfig = googletag.getConfig("targeting").targeting; const keys = Object.keys(targetingConfig || {}); // Returns ['interests', 'colors'].
| การคืนสินค้า | |
|---|---|
string[] | อาร์เรย์ของคีย์การกำหนดเป้าหมาย ไม่ได้กำหนดการจัดลำดับ |
isInitialLoadDisabled
isInitialLoadDisabled(): boolean| การคืนสินค้า | |
|---|---|
boolean | แสดงผล true หากการเรียกใช้ PubAdsService.disableInitialLoad ก่อนหน้านี้สำเร็จ หรือแสดงผล false หากไม่สำเร็จ |
refresh
refresh(slots?: Slot[], options?: {
changeCorrelator: boolean;
}): voidเพื่อให้ทำงานได้อย่างถูกต้องในทุกเบราว์เซอร์ การเรียก
refresh ต้องทำก่อนการเรียก display ช่องโฆษณา หากละเว้นการเรียกใช้ display การรีเฟรชอาจทำงานผิดปกติ หากต้องการ คุณสามารถใช้เมธอด PubAdsService.disableInitialLoad เพื่อหยุด display ไม่ให้ดึงข้อมูลโฆษณาได้การรีเฟรชช่องโฆษณาจะนำโฆษณาเก่าออกจากการดูหน้าเว็บที่ใช้เวลานานของ GPT ดังนั้นคำขอในอนาคตจะไม่ได้รับผลกระทบจาก Roadblock หรือการยกเว้นโฆษณาของคู่แข่งที่เกี่ยวข้องกับโฆษณานั้น
- ตัวอย่าง
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 });
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 });
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| ช่องโฆษณาที่จะรีเฟรช อาร์เรย์เป็นตัวเลือกที่ไม่บังคับ ช่องทั้งหมดจะรีเฟรชหากไม่ได้ระบุ |
| ตัวเลือกการกำหนดค่าที่เชื่อมโยงกับการเรียกใช้การรีเฟรชนี้
|
registerRequestHook
registerRequestHook(hook: RequestHook, hookId: string): (() => void)Experimental ลงทะเบียนฮุกที่จะดำเนินการควบคู่ไปกับฮุกอื่นๆ ที่ลงทะเบียนไว้ก่อนคำขอโฆษณาแต่ละรายการในหน้าเว็บภายในระยะหมดเวลาทั่วโลก- ตัวอย่าง
JavaScript
// Register a request hook. const unregister = googletag.pubads().registerRequestHook(async ({ slots }) => { const someAsynchronousAction = Promise.resolve(); await someAsynchronousAction; for (const slot of slots) { slot.setConfig({ targeting: { hookApplied: "true" } }); } }, "my-hook"); // Unregister the hook. unregister();
TypeScript
// Register a request hook. const unregister = googletag.pubads().registerRequestHook(async ({ slots }) => { const someAsynchronousAction = Promise.resolve(); await someAsynchronousAction; for (const slot of slots) { slot.setConfig({ targeting: { hookApplied: "true" } }); } }, "my-hook"); // Unregister the hook. unregister();
| พารามิเตอร์ | |
|---|---|
hook: RequestHook | ฟังก์ชันที่รับออบเจ็กต์ที่มีรายการช่องโฆษณาที่ขอและแสดงผล Promise ที่จะได้รับการแก้ไขเมื่อการดำเนินการแบบอะซิงโครนัสทั้งหมดเสร็จสมบูรณ์ |
hookId: string | รหัสสำหรับติดป้ายกำกับ Hook เพื่อการวินิจฉัยที่ดีขึ้น |
| การคืนสินค้า | |
|---|---|
(() => void) | ฟังก์ชันสำหรับยกเลิกการลงทะเบียนฮุก |
ชุด
set(key: string, value: string): PubAdsServiceการเรียกใช้เมธอดนี้มากกว่า 1 ครั้งสำหรับคีย์เดียวกันจะลบล้างค่าที่ตั้งไว้ก่อนหน้านี้สำหรับคีย์นั้น ต้องตั้งค่าทั้งหมดก่อนเรียกใช้
display หรือ refresh- ตัวอย่าง
JavaScript
googletag.setConfig({ adsenseAttributes: { page_url: "http://www.example.com", }, });
TypeScript
googletag.setConfig({ adsenseAttributes: { page_url: "http://www.example.com", }, });
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
key: string | ชื่อของแอตทริบิวต์ |
value: string | ค่าแอตทริบิวต์ |
| การคืนสินค้า | |
|---|---|
PubAdsService | ออบเจ็กต์บริการที่มีการเรียกใช้เมธอด |
setCategoryExclusion
setCategoryExclusion(categoryExclusion: string): PubAdsService- ตัวอย่าง
JavaScript
// Label = AirlineAd. googletag.setConfig({ categoryExclusion: ["AirlineAd"], });
TypeScript
// Label = AirlineAd. googletag.setConfig({ categoryExclusion: ["AirlineAd"], });
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
categoryExclusion: string | ป้ายกำกับการยกเว้นหมวดหมู่โฆษณาที่จะเพิ่ม |
| การคืนสินค้า | |
|---|---|
PubAdsService | ออบเจ็กต์บริการที่มีการเรียกใช้เมธอด |
setCentering
setCentering(centerAds: boolean): voidควรเรียกใช้เมธอดนี้ก่อนเรียกใช้
display หรือ refresh เนื่องจากระบบจะจัดให้อยู่กึ่งกลางเฉพาะโฆษณาที่ขอหลังจากเรียกใช้เมธอดนี้เท่านั้น- ตัวอย่าง
JavaScript
// Make ads centered. googletag.setConfig({ centering: true, });
TypeScript
// Make ads centered. googletag.setConfig({ centering: 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.setConfig({ safeFrame: { forceSafeFrame: true, }, }); // The following slot will be opted-out of the page-level force // SafeFrame instruction. googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setConfig({ safeFrame: { forceSafeFrame: 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.setConfig({ safeFrame: { forceSafeFrame: true, }, }); // The following slot will be opted-out of the page-level force // SafeFrame instruction. googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setConfig({ safeFrame: { forceSafeFrame: 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.setConfig({ location: "10001,US", });
TypeScript
// Postal code: googletag.setConfig({ location: "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, });
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");
TypeScript
googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
ppid: string | รหัสตัวอักษรและตัวเลขคละกันที่ผู้เผยแพร่โฆษณามีให้ ต้องมีอักขระระหว่าง 22 ถึง 150 ตัว |
| การคืนสินค้า | |
|---|---|
PubAdsService | ออบเจ็กต์บริการที่มีการเรียกใช้เมธอด |
setSafeFrameConfig
setSafeFrameConfig(config: SafeFrameConfig): PubAdsServiceค่ากำหนดระดับหน้าเหล่านี้จะถูกลบล้างโดยค่ากำหนดระดับช่องโฆษณา หากระบุไว้
- ตัวอย่าง
JavaScript
googletag.setConfig({ safeFrame: { forceSafeFrame: true, allowOverlayExpansion: true, allowPushExpansion: true, sandbox: true, }, }); googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setConfig({ safeFrame: { allowOverlayExpansion: false, }, }) .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.setConfig({ safeFrame: { forceSafeFrame: true, allowOverlayExpansion: true, allowPushExpansion: true, sandbox: true, }, }); googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setConfig({ safeFrame: { allowOverlayExpansion: false, }, }) .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.setConfig({ targeting: { interests: "sports", }, }); // Example with multiple values for a key inside in an array. googletag.setConfig({ targeting: { interests: ["sports", "music"], }, });
TypeScript
// Example with a single value for a key. googletag.setConfig({ targeting: { interests: "sports", }, }); // Example with multiple values for a key inside in an array. googletag.setConfig({ targeting: { interests: ["sports", "music"], }, });
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
key: string | คีย์พารามิเตอร์การกำหนดเป้าหมาย |
value: string | string[] | ค่าพารามิเตอร์การกำหนดเป้าหมายหรืออาร์เรย์ของค่า |
| การคืนสินค้า | |
|---|---|
PubAdsService | ออบเจ็กต์บริการที่มีการเรียกใช้เมธอด |
setVideoContent
setVideoContent(videoContentId: string, videoCmsId: string): voidvideoContentId และ 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.
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.RequestHook
googletag.ResponseInformation
| พร็อพเพอร์ตี้ | |
|---|---|
advertiser | รหัสของผู้ลงโฆษณา |
campaign | รหัสของแคมเปญ |
creative | รหัสของครีเอทีฟโฆษณา |
creative | รหัสเทมเพลตของโฆษณา |
line | รหัสของรายการโฆษณา |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
advertiserId
advertiserId: numbercampaignId
campaignId: numbercreativeId
creativeId: numbercreativeTemplateId
creativeTemplateId: numberlineItemId
lineItemId: numbergoogletag.RewardedPayload
| พร็อพเพอร์ตี้ | |
|---|---|
amount | จำนวนสินค้าที่รวมอยู่ในรางวัล |
type | ประเภทของไอเทมที่รวมอยู่ในรางวัล (เช่น "เหรียญ") |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
amount
amount: numbertype
type: stringgoogletag.Service
| เมธอด | |
|---|---|
add | ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้าเว็บ |
get | ดูรายการช่วงเวลาที่เชื่อมโยงกับบริการนี้ |
remove | นำ Listener ที่ลงทะเบียนไว้ก่อนหน้านี้ออก |
เมธอด
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. } });
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(); });
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]
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 | การอ้างอิงถึง Builder นี้ |
build
build(): SizeMappingArrayหากมีการแมปที่ไม่ถูกต้อง เมธอดนี้จะแสดงผลเป็น
null มิเช่นนั้น ระบบจะแสดงข้อกำหนดในรูปแบบที่ถูกต้องเพื่อส่งไปยัง Slot.defineSizeMappingหมายเหตุ: ระบบไม่ได้กำหนดลักษณะการทำงานของเครื่องมือสร้างหลังจากเรียกใช้เมธอดนี้
| การคืนสินค้า | |
|---|---|
SizeMappingArray | ผลลัพธ์ที่สร้างโดยเครื่องมือสร้างนี้ อาจเป็น Null หากมีการระบุการแมปขนาดที่ไม่ถูกต้อง |
googletag.Slot
| เมธอด | |
|---|---|
add | เพิ่มบริการลงในช่องนี้ |
clear | เลิกใช้งานแล้ว ล้างป้ายกำกับการยกเว้นหมวดหมู่โฆษณาระดับช่องทั้งหมดสำหรับช่องนี้ |
clear | เลิกใช้งานแล้ว ล้างพารามิเตอร์การกำหนดเป้าหมายระดับช่องโฆษณาที่กำหนดเองบางรายการหรือทั้งหมดสำหรับช่องโฆษณานี้ |
define | ตั้งค่าอาร์เรย์ของการแมปจากขนาดวิวพอร์ตขั้นต่ำเป็นขนาดช่องสำหรับช่องนี้ |
get | เลิกใช้งานแล้ว แสดงผลค่าสำหรับแอตทริบิวต์ AdSense ที่เชื่อมโยงกับคีย์ที่ระบุสำหรับช่องนี้ |
get | แสดงเส้นทางแบบเต็มของหน่วยโฆษณา พร้อมรหัสเครือข่ายและเส้นทางหน่วยโฆษณา |
get | เลิกใช้งานแล้ว แสดงรายการคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในช่องนี้ |
get | เลิกใช้งานแล้ว แสดงป้ายกำกับการยกเว้นหมวดหมู่โฆษณาสำหรับช่องนี้ |
get | รับสำเนาที่ตรึงไว้ของตัวเลือกการกำหนดค่าทั่วไปสำหรับช่องที่ตั้งค่าโดย setConfig |
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());
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") .setConfig({ categoryExclusion: ["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.setConfig({ categoryExclusion: null, }); // 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")! .setConfig({ categoryExclusion: ["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.setConfig({ categoryExclusion: null, }); // 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") .setConfig({ targeting: { allow_expandable: "true", interests: ["sports", "music"], color: "red", }, }) .addService(googletag.pubads()); slot.setConfig({ targeting: { color: null, }, }); // Targeting 'allow_expandable' and 'interests' are still present, // while 'color' was cleared. slot.setConfig({ targeting: null, }); // All targeting has been cleared.
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setConfig({ targeting: { allow_expandable: "true", interests: ["sports", "music"], color: "red", }, }) .addService(googletag.pubads()); slot.setConfig({ targeting: { color: null, }, }); // Targeting 'allow_expandable' and 'interests' are still present, // while 'color' was cleared. slot.setConfig({ targeting: null, }); // 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);
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): string- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setConfig({ adsenseAttributes: { page_url: "http://www.example.com", }, }) .addService(googletag.pubads()); const adsenseConfig = slot.getConfig("adsenseAttributes").adsenseAttributes; const pageUrl = adsenseConfig?.page_url || null; // Returns 'http://www.example.com'.
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setConfig({ adsenseAttributes: { page_url: "http://www.example.com", }, }) .addService(googletag.pubads()); const adsenseConfig = slot.getConfig("adsenseAttributes").adsenseAttributes; const pageUrl = adsenseConfig?.page_url || null; // Returns 'http://www.example.com'.
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
key: string | ชื่อของแอตทริบิวต์ที่ต้องการค้นหา |
| การคืนสินค้า | |
|---|---|
string | ค่าปัจจุบันของคีย์แอตทริบิวต์ หรือ null หากไม่มีคีย์ |
getAdUnitPath
getAdUnitPath(): string- ตัวอย่าง
JavaScript
const 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") .setConfig({ adsenseAttributes: { page_url: "http://www.example.com", document_language: "en", }, }) .addService(googletag.pubads()); const adsenseConfig = slot.getConfig("adsenseAttributes").adsenseAttributes; const adsenseAttributes = Object.keys(adsenseConfig || {}); // Returns ['page_url', 'document_language'].
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setConfig({ adsenseAttributes: { page_url: "http://www.example.com", document_language: "en", }, }) .addService(googletag.pubads()); const adsenseConfig = slot.getConfig("adsenseAttributes").adsenseAttributes; const adsenseAttributes = Object.keys(adsenseConfig || {}); // Returns ['page_url', 'document_language'].
| การคืนสินค้า | |
|---|---|
string[] | อาร์เรย์ของคีย์แอตทริบิวต์ ไม่ได้กำหนดการจัดลำดับ |
getCategoryExclusions
getCategoryExclusions(): string[]- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setConfig({ categoryExclusion: ["AirlineAd", "TrainAd"], }) .addService(googletag.pubads()); const exclusions = slot.getConfig("categoryExclusion")?.categoryExclusion || []; // Returns ['AirlineAd', 'TrainAd'].
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setConfig({ categoryExclusion: ["AirlineAd", "TrainAd"], }) .addService(googletag.pubads()); const exclusions = slot.getConfig("categoryExclusion")?.categoryExclusion || []; // Returns ['AirlineAd', 'TrainAd'].
| การคืนสินค้า | |
|---|---|
string[] | ป้ายกำกับการยกเว้นหมวดหมู่โฆษณาสำหรับช่องนี้ หรืออาร์เรย์ว่างหากไม่ได้ตั้งค่าไว้ |
getConfig
getConfig(keys: string | string[]): Readonly<Pick<SlotSettingsConfig, "adsenseAttributes" | "targeting" | "categoryExclusion">>เมธอดนี้ไม่รองรับพร็อพเพอร์ตี้
setConfig() บางรายการ พร็อพเพอร์ตี้ที่รองรับมีดังนี้- ตัวอย่าง
JavaScript
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div"); // Get the value of the `targeting` setting. const targetingConfig = slot.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `categoryExclusion` settings. const config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);
TypeScript
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div")!; // Get the value of the `targeting` setting. const targetingConfig = slot.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `categoryExclusion` settings. const config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);
| พารามิเตอร์ | |
|---|---|
keys: string | string[] | คีย์ของตัวเลือกการกำหนดค่าที่จะรับ |
| การคืนสินค้า | |
|---|---|
Readonly<Pick<SlotSettingsConfig, "adsenseAttributes" | "targeting" | "categoryExclusion">> | สำเนาที่คงที่ของตัวเลือกการกำหนดค่าสำหรับช่องโฆษณา |
getResponseInformation
getResponseInformation(): ResponseInformationnull| การคืนสินค้า | |
|---|---|
ResponseInformation | ข้อมูลการตอบกลับโฆษณาล่าสุด หรือ null หากช่องไม่มีโฆษณา |
getSlotElementId
getSlotElementId(): stringdiv ที่ระบุเมื่อมีการกำหนดช่องโฆษณา- ตัวอย่าง
JavaScript
const 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") .setConfig({ targeting: { allow_expandable: "true", }, }) .addService(googletag.pubads()); const targetingConfig = slot.getConfig("targeting").targeting; // Get targeting for a specific key. const targeting = targetingConfig?.["allow_expandable"] || []; // Returns ['true']. const ageTargeting = targetingConfig?.["age"] || []; // Returns [] (empty array).
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setConfig({ targeting: { allow_expandable: "true", }, }) .addService(googletag.pubads()); const targetingConfig = slot.getConfig("targeting").targeting; // Get targeting for a specific key. const targeting = targetingConfig?.["allow_expandable"] || []; // Returns ['true']. const ageTargeting = targetingConfig?.["age"] || []; // Returns [] (empty array).
| พารามิเตอร์ | |
|---|---|
key: string | คีย์การกำหนดเป้าหมายที่ต้องการค้นหา |
| การคืนสินค้า | |
|---|---|
string[] | ค่าที่เชื่อมโยงกับคีย์นี้ หรืออาร์เรย์ว่างหากไม่มีคีย์ดังกล่าว |
getTargetingKeys
getTargetingKeys(): string[]- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setConfig({ targeting: { allow_expandable: "true", interests: ["sports", "music"], }, }) .addService(googletag.pubads()); const targetingConfig = slot.getConfig("targeting").targeting; const keys = Object.keys(targetingConfig || {}); // Returns ['interests', 'allow_expandable'].
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setConfig({ targeting: { allow_expandable: "true", interests: ["sports", "music"], }, }) .addService(googletag.pubads()); const targetingConfig = slot.getConfig("targeting").targeting; const keys = Object.keys(targetingConfig || {}); // Returns ['interests', 'allow_expandable'].
| การคืนสินค้า | |
|---|---|
string[] | อาร์เรย์ของคีย์การกำหนดเป้าหมาย ไม่ได้กำหนดการจัดลำดับ |
ชุด
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") .setConfig({ adsenseAttributes: { page_url: "http://www.example.com", }, }) .addService(googletag.pubads());
TypeScript
// Setting an attribute on a single ad slot. googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setConfig({ adsenseAttributes: { page_url: "http://www.example.com", }, }) .addService(googletag.pubads());
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
key: string | ชื่อของแอตทริบิวต์ |
value: string | ค่าแอตทริบิวต์ |
| การคืนสินค้า | |
|---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
setCategoryExclusion
setCategoryExclusion(categoryExclusion: string): Slot- ตัวอย่าง
JavaScript
// Label = AirlineAd. googletag .defineSlot("/1234567/sports", [160, 600], "div") .setConfig({ categoryExclusion: ["AirlineAd"], }) .addService(googletag.pubads());
TypeScript
// Label = AirlineAd. googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setConfig({ categoryExclusion: ["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") .setConfig({ clickUrl: "http://www.example.com?original_click_url=", }) .addService(googletag.pubads());
TypeScript
googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setConfig({ clickUrl: "http://www.example.com?original_click_url=", }) .addService(googletag.pubads());
| พารามิเตอร์ | |
|---|---|
value: string | URL การคลิกที่จะตั้งค่า |
| การคืนสินค้า | |
|---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
setCollapseEmptyDiv
setCollapseEmptyDiv(collapse: boolean, collapseBeforeAdFetch?: boolean): Slotdiv หรือไม่เมื่อไม่มีโฆษณาในช่อง การตั้งค่านี้จะลบล้างการตั้งค่าระดับบริการ- ตัวอย่าง
JavaScript
const slot1 = googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setConfig({ collapseDiv: "BEFORE_FETCH", }) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // when the page is loaded, before ads are requested. const slot2 = googletag .defineSlot("/1234567/sports", [160, 600], "div-2") .setConfig({ collapseDiv: "ON_NO_FILL", }) .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
const slot1 = googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setConfig({ collapseDiv: "BEFORE_FETCH", }) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // when the page is loaded, before ads are requested. const slot2 = googletag .defineSlot("/1234567/sports", [160, 600], "div-2")! .setConfig({ collapseDiv: "ON_NO_FILL", }) .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 | เลือกว่าจะยุบช่องโฆษณาหรือไม่หากไม่มีการแสดงผลโฆษณา |
| ยุบช่องโฆษณาแม้ก่อนที่จะดึงข้อมูลโฆษณาหรือไม่ ระบบจะไม่สนใจหากการยุบไม่ใช่ true |
| การคืนสินค้า | |
|---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
setConfig
setConfig(slotConfig: SlotSettingsConfig): Slot| พารามิเตอร์ | |
|---|---|
slotConfig: SlotSettingsConfig | ออบเจ็กต์การกำหนดค่า |
| การคืนสินค้า | |
|---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
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());
TypeScript
googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setForceSafeFrame(true) .addService(googletag.pubads());
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
forceSafeFrame: boolean | true เพื่อบังคับให้โฆษณาทั้งหมดในช่องนี้แสดงผลใน SafeFrame และ false เพื่อเลือกไม่ใช้การตั้งค่าระดับหน้า (หากมี) การตั้งค่านี้เป็น false เมื่อไม่ได้ระบุที่ระดับหน้าเว็บจะไม่เปลี่ยนแปลงสิ่งใด |
| การคืนสินค้า | |
|---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
setSafeFrameConfig
setSafeFrameConfig(config: 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");
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: SafeFrameConfig | ออบเจ็กต์การกำหนดค่า |
| การคืนสินค้า | |
|---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
setTargeting
setTargeting(key: string, value: string | string[]): Slot- ตัวอย่าง
JavaScript
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div"); slot.addService(googletag.pubads()); // Example with a single value for a key. slot.setConfig({ targeting: { allow_expandable: "true", }, }); // Example with multiple values for a key inside in an array. slot.setConfig({ targeting: { interests: ["sports", "music"], }, });
TypeScript
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div")!; slot.addService(googletag.pubads()); // Example with a single value for a key. slot.setConfig({ targeting: { allow_expandable: "true", }, }); // Example with multiple values for a key inside in an array. slot.setConfig({ targeting: { 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"], });
TypeScript
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div")!; slot.updateTargetingFromMap({ color: "red", interests: ["sports", "music", "movies"], });
| พารามิเตอร์ | |
|---|---|
map: { | การแมปคีย์:ค่าของพารามิเตอร์การกำหนดเป้าหมาย |
| การคืนสินค้า | |
|---|---|
Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด |
googletag.config
| อินเทอร์เฟซ | |
|---|---|
Ad | การตั้งค่าเพื่อควบคุมการขยายโฆษณา |
Ad | การตั้งค่าเพื่อควบคุมลักษณะการทำงานของโฆษณา AdSense |
Auto | การตั้งค่าการกำหนดค่าการรีเฟรชอัตโนมัติ |
Continue | การตั้งค่าเพื่อกำหนดค่าลักษณะการทำงานของปุ่มดำเนินการต่อ |
Interstitial | ออบเจ็กต์ที่กำหนดลักษณะการทำงานของช่องโฆษณาคั่นระหว่างหน้ารายการเดียว |
Lazy | การตั้งค่าเพื่อควบคุมการใช้การโหลดแบบ Lazy Loading ใน GPT |
Page | อินเทอร์เฟซการกำหนดค่าหลักสำหรับการตั้งค่าระดับหน้าเว็บ |
Privacy | การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา |
Publisher | ออบเจ็กต์การกำหนดค่าสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS) |
Safe | การตั้งค่าเพื่อควบคุม SafeFrame ใน GPT |
Slot | อินเทอร์เฟซการกำหนดค่าหลักสำหรับการตั้งค่าระดับช่องโฆษณา |
Taxonomy | ออบเจ็กต์ที่มีค่าสำหรับการจัดหมวดหมู่รายการเดียว |
Video | การตั้งค่าเพื่อกำหนดการตั้งค่าที่เกี่ยวข้องกับโฆษณาวิดีโอ |
| ชื่อแทนประเภท | |
|---|---|
Collapse | ค่าที่รองรับสำหรับการควบคุมลักษณะการยุบของช่องโฆษณา |
Interstitial | ทริกเกอร์โฆษณาคั่นระหว่างหน้าที่รองรับ |
Privacy | การดูแลด้านความเป็นส่วนตัวสำหรับผู้เผยแพร่โฆษณาที่รองรับ |
Taxonomy | การจัดหมวดหมู่ที่รองรับสำหรับสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS) |
ชื่อแทนประเภท
CollapseDivBehavior
CollapseDivBehavior: "DISABLED" | "BEFORE_FETCH" | "ON_NO_FILL"InterstitialTrigger
InterstitialTrigger: "unhideWindow" | "navBar" | "inactivity" | "endOfArticle" | "continueReading" | "backward"หมายเหตุ: ตั้งแต่วันที่ 15 มิถุนายน 2026 ระบบจะไม่รองรับทริกเกอร์
backward อีกต่อไป และการเปิดใช้จะไม่มีผลใดๆ ดูข้อมูลเพิ่มเติมได้ที่บันทึกประจำรุ่นของ GPTPrivacyTreatment
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 }, });
TypeScript
// Enable ad slot expansion across the entire page. googletag.setConfig({ adExpansion: { enabled: true }, });
พร็อพเพอร์ตี้
Optional เปิดใช้แล้ว
enabled?: booleanการตั้งค่านี้จะลบล้างค่าเริ่มต้นที่กำหนดค่าไว้ใน Google Ad Manager
googletag.config.AdSenseAttributesConfig
แอตทริบิวต์เหล่านี้ใช้เพื่อลบล้างการตั้งค่าฝั่งเซิร์ฟเวอร์ตามคำขอแต่ละรายการได้
| พร็อพเพอร์ตี้ | |
|---|---|
adsense | รูปแบบโฆษณา AdSense |
adsense | รหัสช่อง AdSense |
adsense | เปิดใช้โหมดทดสอบหรือไม่ |
document | ภาษาของหน้าเว็บที่แสดงโฆษณา |
page | URL ของหน้าเว็บที่แสดงโฆษณา |
พร็อพเพอร์ตี้
Optional adsense_ad_format
adsense_ad_format?: "120x240_as" | "120x600_as" | "125x125_as" | "160x600_as" | "180x150_as" | "200x200_as" | "234x60_as" | "250x250_as" | "300x250_as" | "336x280_as" | "468x60_as" | "728x90_as"Optional adsense_channel_ids
adsense_channel_ids?: stringค่าที่ใช้ได้คือรหัสช่องที่คั่นด้วย "+"
ตัวอย่าง:
271828183+314159265Optional adsense_test_mode
adsense_test_mode?: "on"เมื่อตั้งค่าเป็น
on ระบบจะทำเครื่องหมายโฆษณาเป็นแบบทดสอบเท่านั้น และจะไม่รวมอยู่ในการนับหรือการเรียกเก็บเงิน ต้องยกเลิกการตั้งค่านี้สำหรับการเข้าชมจริงที่ไม่ใช่การเข้าชมทดสอบOptional document_language
document_language?: stringค่าที่อนุญาตคือรหัสภาษา ISO 639-1 ที่ถูกต้อง
ตัวอย่าง:
en- ดูเพิ่มเติม
Optional page_url
page_url?: stringค่าที่ใช้ได้คือ URL ที่ถูกต้อง
ตัวอย่าง:
http://www.example.comgoogletag.config.AutoRefreshConfig
| พร็อพเพอร์ตี้ | |
|---|---|
back | GPT จะรีเฟรชช่องโฆษณาที่ผู้ใช้กำลังดูอยู่โดยอัตโนมัติหรือไม่เมื่อกู้คืนหน้าเว็บจาก Back-Forward Cache |
heavy | GPT จะรีเฟรชช่องโฆษณาโดยอัตโนมัติหรือไม่หากการแทรกแซงโฆษณาอย่างมากของ Chrome ทริกเกอร์ใน iframe โฆษณาของช่องโฆษณา |
พร็อพเพอร์ตี้
Optional backForwardCache
backForwardCache?: booleantrue- ตัวอย่าง
JavaScript
// Set the auto refresh configuration, disabling auto refresh on // back/forward cache restore. googletag.setConfig({ autoRefresh: { backForwardCache: false } }); // Clear the auto refresh configuration, restoring to default behavior. googletag.setConfig({ autoRefresh: null });
TypeScript
// Set the auto refresh configuration, disabling auto refresh on // back/forward cache restore. googletag.setConfig({ autoRefresh: { backForwardCache: false } }); // Clear the auto refresh configuration, restoring to default behavior. googletag.setConfig({ autoRefresh: null });
- ดูเพิ่มเติม
Optional heavyAds
heavyAds?: booleantrue- ตัวอย่าง
JavaScript
// Set the auto refresh configuration, disabling auto refresh on heavy // ad intervention. googletag.setConfig({ autoRefresh: { heavyAds: false } }); // Clear the auto refresh configuration, restoring to default behavior. googletag.setConfig({ autoRefresh: null });
TypeScript
// Set the auto refresh configuration, disabling auto refresh on heavy // ad intervention. googletag.setConfig({ autoRefresh: { heavyAds: false } }); // Clear the auto refresh configuration, restoring to default behavior. googletag.setConfig({ autoRefresh: null });
googletag.config.ContinueButtonConfig
| พร็อพเพอร์ตี้ | |
|---|---|
background | สีพื้นหลังของปุ่ม |
font | ชุดแบบอักษรของข้อความในปุ่ม |
font | สีข้อความของปุ่ม |
freq | ช่วงเวลาในการกำหนดความถี่สูงสุดเป็นนาที |
target | รหัสขององค์ประกอบ HTML ที่จะแสดงผล/ทริกเกอร์ปุ่มดำเนินการต่อ |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
Optional backgroundColor
backgroundColor?: stringตัวอย่าง:
'blue', '#94B1FF'Optional แบบอักษร
font?: stringตัวอย่าง:
'Arial'Optional fontColor
fontColor?: stringตัวอย่าง:
'white', '#B73B87'Optional freqCapIntervalMinutes
freqCapIntervalMinutes?: numberต้องเป็นจำนวนเต็มที่มากกว่าหรือเท่ากับ 1
Optional targetId
targetId?: stringgoogletag.config.InterstitialConfig
| พร็อพเพอร์ตี้ | |
|---|---|
require | ต้องได้รับความยินยอมเพื่อเข้าถึงพื้นที่เก็บข้อมูลในเครื่องหรือไม่จึงจะแสดงโฆษณาคั่นระหว่างหน้านี้ได้ |
triggers | การกำหนดค่าทริกเกอร์โฆษณาคั่นระหว่างหน้าสำหรับโฆษณาคั่นระหว่างหน้านี้ |
พร็อพเพอร์ตี้
Optional requireStorageAccess
requireStorageAccess?: booleanGPT ใช้พื้นที่เก็บข้อมูลในเครื่องเพื่อบังคับใช้ความถี่สูงสุดสำหรับโฆษณาคั่นระหว่างหน้า อย่างไรก็ตาม ผู้ใช้ที่ไม่ได้ให้ความยินยอมเพื่อเข้าถึงพื้นที่เก็บข้อมูลในเครื่องจะยังมีสิทธิ์เห็นโฆษณาคั่นระหว่างหน้า การตั้งค่าพร็อพเพอร์ตี้นี้เป็น
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 }, });
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?: 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, }, }, });
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.LazyLoadConfig
| พร็อพเพอร์ตี้ | |
|---|---|
fetch | ระยะห่างขั้นต่ำจากวิวพอร์ตปัจจุบันที่ช่องโฆษณาต้องมีก่อนที่เราจะขอโฆษณา โดยแสดงเป็นเปอร์เซ็นต์ของขนาดวิวพอร์ต |
mobile | ตัวคูณที่ใช้กับมาร์จินในอุปกรณ์เคลื่อนที่ |
render | ระยะห่างขั้นต่ำจากวิวพอร์ตปัจจุบันที่ช่องโฆษณาต้องมีก่อนที่เราจะแสดงโฆษณา โดยแสดงเป็นเปอร์เซ็นต์ของขนาดวิวพอร์ต |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
Optional fetchMarginPercent
fetchMarginPercent?: numberเมื่อใช้ร่วมกับ renderMarginPercent การตั้งค่านี้จะช่วยให้ดึงข้อมูลโฆษณาล่วงหน้าได้ แต่จะรอแสดงผลและดาวน์โหลดทรัพยากรย่อยอื่นๆ ดังนั้น ค่านี้จึงควรมากกว่าหรือเท่ากับ renderMarginPercent เสมอ
ค่า
0 หมายถึง "เมื่อช่องโฆษณาเข้าสู่วิวพอร์ต" 100 หมายถึง "เมื่อโฆษณาอยู่ห่างจากวิวพอร์ต 1 วิวพอร์ต" เป็นต้นOptional mobileScaling
mobileScaling?: numberซึ่งจะช่วยให้มีระยะขอบที่แตกต่างกันในอุปกรณ์เคลื่อนที่และเดสก์ท็อป ซึ่งขนาดวิวพอร์ตและความเร็วในการเลื่อนอาจแตกต่างกัน เช่น ค่า 2.0 จะคูณระยะขอบทั้งหมดด้วย 2 ในอุปกรณ์เคลื่อนที่ ซึ่งจะเพิ่มระยะห่างขั้นต่ำที่ช่องโฆษณาจะอยู่ห่างจากวิวพอร์ตได้ก่อนที่จะดึงข้อมูลและแสดงผล
Optional renderMarginPercent
renderMarginPercent?: numberเมื่อใช้ร่วมกับ fetchMarginPercent การตั้งค่านี้จะช่วยให้ดึงข้อมูลโฆษณาล่วงหน้าได้ แต่จะรอแสดงผลและดาวน์โหลดทรัพยากรย่อยอื่นๆ ดังนั้น ค่านี้จึงควรน้อยกว่าหรือเท่ากับ fetchMarginPercent เสมอ
ค่า
0 หมายถึง "เมื่อช่องโฆษณาเข้าสู่วิวพอร์ต" 100 หมายถึง "เมื่อโฆษณาอยู่ห่างออกไป 1 วิวพอร์ต" เป็นต้น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 | การตั้งค่าเพื่อควบคุมการขยายโฆษณา |
adsense | การตั้งค่าเพื่อกำหนดค่าแอตทริบิวต์ AdSense |
ad | เลิกใช้งานแล้ว |
auto | การตั้งค่าเพื่อกำหนดค่าลักษณะการรีเฟรชโฆษณาอัตโนมัติ |
category | การตั้งค่าเพื่อกำหนดค่าการยกเว้นหมวดหมู่โฆษณา |
centering | การตั้งค่าเพื่อควบคุมการจัดโฆษณาให้อยู่กึ่งกลางแนวนอน |
collapse | การตั้งค่าเพื่อควบคุมลักษณะการยุบของช่องโฆษณา |
disable | การตั้งค่าเพื่อควบคุมเวลาที่ขอโฆษณา |
lazy | การตั้งค่าเพื่อควบคุมการใช้การโหลดแบบ Lazy Loading ใน GPT |
location | การตั้งค่าเพื่อกำหนดเป้าหมายรายการโฆษณาทางภูมิศาสตร์ไปยังสถานที่ตั้งทางภูมิศาสตร์ |
pps | การตั้งค่าเพื่อควบคุมสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS) |
privacy | การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา |
request | การตั้งค่าเพื่อควบคุมเวลาสูงสุดที่ GPT จะรอให้ฮุกคำขอที่ลงทะเบียนทั้งหมดดำเนินการเสร็จสมบูรณ์ก่อนที่จะดำเนินการต่อด้วยคำขอโฆษณา |
safe | การตั้งค่าเพื่อควบคุมการใช้ SafeFrame ใน GPT |
single | การตั้งค่าเพื่อเปิดหรือปิดใช้สถาปัตยกรรมคำขอรวมครั้งเดียว (SRA) |
targeting | การตั้งค่าเพื่อควบคุมการกำหนดเป้าหมายคีย์-ค่า |
thread | การตั้งค่าเพื่อควบคุมว่า GPT ควรสร้างเทรด JS เมื่อขอและแสดงผลครีเอทีฟโฆษณาหรือไม่ |
video | การตั้งค่าเพื่อควบคุมโฆษณาวิดีโอ |
พร็อพเพอร์ตี้
Optional adExpansion
adExpansion?: AdExpansionConfigOptional adsenseAttributes
adsenseAttributes?: AdSenseAttributesConfigแอตทริบิวต์ AdSense ที่กำหนดค่าผ่านการตั้งค่านี้จะมีผลกับช่องโฆษณาทั้งหมดในหน้าเว็บ ระบบอาจเรียกใช้การตั้งค่านี้หลายครั้งเพื่อกำหนดค่าแอตทริบิวต์หลายค่า หรือเขียนทับค่าที่มีอยู่
การเปลี่ยนแปลงแอตทริบิวต์ AdSense จะมีผลกับโฆษณาที่ขอหลังจากเรียกใช้เมธอดนี้เท่านั้น ด้วยเหตุนี้ เราขอแนะนำให้เรียกใช้เมธอดนี้ก่อนการเรียกใช้ googletag.display หรือ PubAdsService.refresh
- ตัวอย่าง
JavaScript
// Set the document language and page URL. googletag.setConfig({ adsenseAttributes: { document_language: "en", page_url: "http://www.example.com" }, }); // Clear the page URL only. googletag.setConfig({ adsenseAttributes: { page_url: null } }); // Clear all AdSense attributes. googletag.setConfig({ adsenseAttributes: null });
TypeScript
// Set the document language and page URL. googletag.setConfig({ adsenseAttributes: { document_language: "en", page_url: "http://www.example.com" }, }); // Clear the page URL only. googletag.setConfig({ adsenseAttributes: { page_url: null } }); // Clear all AdSense attributes. googletag.setConfig({ adsenseAttributes: null });
Optional adYield
adYield?: "DISABLED" | "ENABLED_ALL_SLOTS"Optional autoRefresh
autoRefresh?: AutoRefreshConfig- ตัวอย่าง
JavaScript
// Set the auto refresh configuration. googletag.setConfig({ autoRefresh: { heavyAds: false } }); // Clear the auto refresh configuration. googletag.setConfig({ autoRefresh: null });
TypeScript
// Set the auto refresh configuration. googletag.setConfig({ autoRefresh: { heavyAds: false } }); // Clear the auto refresh configuration. googletag.setConfig({ autoRefresh: null });
Optional categoryExclusion
categoryExclusion?: string[]- ตัวอย่าง
JavaScript
// Label = AirlineAd. googletag.setConfig({ categoryExclusion: ["AirlineAd"] }); // Clearing category exclusion setting. googletag.setConfig({ categoryExclusion: null });
TypeScript
// Label = AirlineAd. googletag.setConfig({ categoryExclusion: ["AirlineAd"] }); // Clearing category exclusion setting. googletag.setConfig({ categoryExclusion: null });
- ดูเพิ่มเติม
Optional การจัดให้อยู่กึ่งกลาง
centering?: booleanการเปลี่ยนแปลงการจัดให้อยู่ตรงกลางในแนวนอนจะมีผลกับคำขอโฆษณาที่ขอหลังจากเรียกใช้เมธอดนี้เท่านั้น ด้วยเหตุนี้ เราขอแนะนำให้เรียกใช้เมธอดนี้ก่อนการเรียกใช้ googletag.display หรือ PubAdsService.refresh
- ตัวอย่าง
JavaScript
// Make ads centered. googletag.setConfig({ centering: true }); // Clear the centering setting. googletag.setConfig({ centering: null });
TypeScript
// Make ads centered. googletag.setConfig({ centering: true }); // Clear the centering setting. googletag.setConfig({ centering: null });
Optional collapseDiv
collapseDiv?: CollapseDivBehaviorช่องโฆษณาที่ยุบจะไม่ใช้พื้นที่ในหน้าเว็บ
ค่าที่รองรับ:
null(ค่าเริ่มต้น): ช่องจะไม่ยุบDISABLED: ช่องจะไม่ยุบ ไม่ว่าจะมีการแสดงโฆษณาหรือไม่ก็ตามBEFORE_FETCH: ช่องจะเริ่มยุบและขยายเมื่อมีการแสดงโฆษณาON_NO_FILL: ช่องจะเริ่มขยายออก และยุบลงหากไม่มีการแสดงผลโฆษณา
- ตัวอย่าง
JavaScript
// Collapse the div for this slot if no ad is returned. googletag.setConfig({ collapseDiv: "ON_NO_FILL" }); // Collapse the div for this slot by default, and expand only // if an ad is returned. googletag.setConfig({ collapseDiv: "BEFORE_FETCH" }); // Do not collapse the div for this slot. googletag.setConfig({ collapseDiv: "DISABLED" }); // Clear the collapse setting. googletag.setConfig({ collapseDiv: null });
TypeScript
// Collapse the div for this slot if no ad is returned. googletag.setConfig({ collapseDiv: "ON_NO_FILL" }); // Collapse the div for this slot by default, and expand only // if an ad is returned. googletag.setConfig({ collapseDiv: "BEFORE_FETCH" }); // Do not collapse the div for this slot. googletag.setConfig({ collapseDiv: "DISABLED" }); // Clear the collapse setting. googletag.setConfig({ collapseDiv: null });
- ดูเพิ่มเติม
Optional disableInitialLoad
disableInitialLoad?: booleanโดยค่าเริ่มต้น เมธอด googletag.display จะลงทะเบียนช่องโฆษณาและขอโฆษณาสำหรับช่องโฆษณาเหล่านั้น อย่างไรก็ตาม ในบางครั้งคุณอาจต้องการแยกการดำเนินการเหล่านี้ออกจากกัน เพื่อควบคุมเวลาที่โหลดเนื้อหาโฆษณาได้แม่นยำยิ่งขึ้น
การเปิดใช้การตั้งค่านี้จะทำให้ระบบไม่ขอโฆษณาสำหรับช่องที่ลงทะเบียนไว้เมื่อมีการเรียกใช้เมธอด
display() แต่ต้องเรียกใช้ PubAdsService.refresh แยกต่างหากเพื่อเริ่มคำขอโฆษณาต้องเรียกใช้เมธอดนี้ก่อนเรียกใช้ googletag.enableServices
- ตัวอย่าง
JavaScript
// Prevent requesting ads when `display()` is called. googletag.setConfig({ disableInitialLoad: true });
TypeScript
// Prevent requesting ads when `display()` is called. googletag.setConfig({ disableInitialLoad: true });
- ดูเพิ่มเติม
Optional lazyLoad
lazyLoad?: LazyLoadConfigการโหลดแบบ Lazy Loading เป็นเทคนิคในการหน่วงเวลาการขอและการแสดงผลโฆษณาจนกว่าโฆษณาจะเข้าใกล้วิวพอร์ตของผู้ใช้ ดูตัวอย่างโดยละเอียดได้ที่ตัวอย่างการโหลดแบบ Lazy Loading
หมายเหตุ: หากเปิดใช้
singleRequest การดึงข้อมูลแบบ Lazy Loading จะทำงานเมื่อช่องทั้งหมดอยู่นอกระยะขอบการดึงข้อมูลเท่านั้นการตั้งค่าการโหลดแบบ Lazy Loading ที่ไม่ได้ระบุเมื่อเรียกใช้
setConfig() จะใช้ค่าเริ่มต้นที่ Google กำหนดไว้ ค่าเริ่มต้นเหล่านี้อาจมีการปรับเปลี่ยนเมื่อเวลาผ่านไป หากต้องการปิดใช้การตั้งค่าหนึ่งๆ ให้ตั้งค่าเป็น null- ตัวอย่าง
JavaScript
// Enable lazy loading. googletag.setConfig({ lazyLoad: { // Fetch slots within 5 viewports. fetchMarginPercent: 500, // Render slots within 2 viewports. renderMarginPercent: 200, // Double the above values on mobile. mobileScaling: 2.0, }, }); // Clear fetch margin only. googletag.setConfig({ lazyLoad: { fetchMarginPercent: null }, }); // Clear all lazy loading settings. googletag.setConfig({ lazyLoad: null });
TypeScript
// Enable lazy loading. googletag.setConfig({ lazyLoad: { // Fetch slots within 5 viewports. fetchMarginPercent: 500, // Render slots within 2 viewports. renderMarginPercent: 200, // Double the above values on mobile. mobileScaling: 2.0, }, }); // Clear fetch margin only. googletag.setConfig({ lazyLoad: { fetchMarginPercent: null }, }); // Clear all lazy loading settings. googletag.setConfig({ lazyLoad: null });
Optional สถานที่
location?: string- ตัวอย่าง
JavaScript
// Geo-target line items to US postal code 10001. googletag.setConfig({ location: "10001,US" }); // Clear the location setting. googletag.setConfig({ location: null });
TypeScript
// Geo-target line items to US postal code 10001. googletag.setConfig({ location: "10001,US" }); // Clear the location setting. googletag.setConfig({ location: null });
Optional pps
Optional privacyTreatments
privacyTreatments?: PrivacyTreatmentsConfigOptional Experimental requestHookTimeoutMs
requestHookTimeoutMs?: number | "auto"ฮุกคำขอที่ลงทะเบียนทั้งหมดจะทำงานพร้อมกัน ระยะหมดเวลานี้จะกำหนดขีดจำกัดสูงสุดของระยะเวลาที่กระบวนการคำขอโฆษณาจะหยุดชั่วคราวขณะรอให้การดำเนินการแบบขนานเหล่านั้นเสร็จสมบูรณ์
ค่าที่รองรับ:
- ตัวเลขบวกในหน่วยมิลลิวินาที: ระยะเวลารอที่กำหนดเอง
'auto': GPT ใช้การหมดเวลาที่เพิ่มประสิทธิภาพโดย Googlenull: ปิดใช้การหมดเวลา (GPT จะรอให้ฮุกทำงานเสร็จโดยไม่มีกำหนด)
- ตัวอย่าง
JavaScript
// Set a 1000ms timeout for request hooks. googletag.setConfig({ requestHookTimeoutMs: 1000 }); // Use a Google-optimized timeout for request hooks. googletag.setConfig({ requestHookTimeoutMs: "auto" }); // Clear the timeout. googletag.setConfig({ requestHookTimeoutMs: null });
TypeScript
// Set a 1000ms timeout for request hooks. googletag.setConfig({ requestHookTimeoutMs: 1000 }); // Use a Google-optimized timeout for request hooks. googletag.setConfig({ requestHookTimeoutMs: "auto" }); // Clear the timeout. googletag.setConfig({ requestHookTimeoutMs: null });
Optional safeFrame
safeFrame?: SafeFrameConfigค่าที่กำหนดผ่านการตั้งค่านี้จะมีผลกับช่องโฆษณาทั้งหมดในหน้าเว็บ ช่องโฆษณาแต่ละช่องอาจลบล้างค่าเหล่านี้ผ่าน SlotSettingsConfig.safeFrame
- ตัวอย่าง
JavaScript
// Force SafeFrame for all ads on the page. googletag.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion. googletag.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting. googletag.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings. googletag.setConfig({ safeFrame: null });
TypeScript
// Force SafeFrame for all ads on the page. googletag.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion. googletag.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting. googletag.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings. googletag.setConfig({ safeFrame: null });
Optional singleRequest
singleRequest?: booleanเมื่อเปิดใช้ SRA ระบบจะรวมช่องโฆษณาทั้งหมดที่กำหนดไว้ก่อนการเรียกใช้ googletag.display หรือ PubAdsService.refresh ไว้ในคำขอโฆษณาเดียว ซึ่งจะช่วยเพิ่มประสิทธิภาพ และยังจำเป็นต่อการตรวจสอบว่าระบบได้ปฏิบัติตาม Roadblock และการยกเว้นโฆษณาของคู่แข่ง
เมื่อปิดใช้ SRA ระบบจะขอช่องโฆษณาแต่ละช่องแยกกัน นี่คือลักษณะการทำงานเริ่มต้นของ GPT
ต้องเรียกใช้เมธอดนี้ก่อนเรียกใช้ googletag.enableServices
- ตัวอย่าง
JavaScript
// Enable Single Request Architecture. googletag.setConfig({ singleRequest: true });
TypeScript
// Enable Single Request Architecture. googletag.setConfig({ singleRequest: true });
Optional การกำหนดเป้าหมาย
targeting?: Record<string, string | string[]>การกำหนดเป้าหมายที่กำหนดค่าผ่านการตั้งค่านี้จะมีผลกับช่องโฆษณาทั้งหมดในหน้าเว็บ ระบบอาจเรียกใช้การตั้งค่านี้หลายครั้งเพื่อกำหนดคีย์-ค่าการกำหนดเป้าหมายหลายรายการ หรือเขียนทับค่าที่มีอยู่ คีย์การกำหนดเป้าหมายจะกำหนดไว้ในบัญชี Google Ad Manager
- ตัวอย่าง
JavaScript
// Setting a single targeting key-value. googletag.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key googletag.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. googletag.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. googletag.setConfig({ targeting: { interests: null } });
TypeScript
// Setting a single targeting key-value. googletag.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key googletag.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. googletag.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. googletag.setConfig({ targeting: { interests: null } });
- ดูเพิ่มเติม
Optional threadYield
threadYield?: "DISABLED" | "ENABLED_ALL_SLOTS"GPT จะปล่อยเธรดเฉพาะสำหรับเบราว์เซอร์ที่รองรับ API ของ Scheduler.postTask หรือ Scheduler.yield
ค่าที่รองรับ:
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 });
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 });
- ดูเพิ่มเติม
Optional videoAds
videoAds?: VideoAdsConfig- ตัวอย่าง
JavaScript
// Enable video ads and set video content and content source IDs. googletag.setConfig({ videoAds: { enableVideoAds: true, videoContentId: "e1eGlRL7ju8", videoCmsId: "1234567", }, });
TypeScript
// Enable video ads and set video content and content source IDs. googletag.setConfig({ videoAds: { enableVideoAds: true, videoContentId: "e1eGlRL7ju8", videoCmsId: "1234567", }, });
- ดูเพิ่มเติม
googletag.config.PrivacyTreatmentsConfig
| พร็อพเพอร์ตี้ | |
|---|---|
treatments | อาร์เรย์ของการดูแลด้านความเป็นส่วนตัวสำหรับผู้เผยแพร่โฆษณาที่จะเปิดใช้ |
พร็อพเพอร์ตี้
การรักษา
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 | ออบเจ็กต์ที่มีการแมปการจัดหมวดหมู่หรือค่า Null เพื่อล้างการกำหนดค่า |
- ตัวอย่าง
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
taxonomies: Partial<Record<Taxonomy, TaxonomyData>>googletag.config.SafeFrameConfig
| พร็อพเพอร์ตี้ | |
|---|---|
allow | SafeFrame ควรอนุญาตให้เนื้อหาโฆษณาขยายโดยการวางซ้อนเนื้อหาของหน้าเว็บหรือไม่ |
allow | SafeFrame ควรอนุญาตให้เนื้อหาโฆษณาขยายโดยการดันเนื้อหาของหน้าหรือไม่ |
force | ควรบังคับให้แสดงโฆษณาโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่ |
sandbox | SafeFrame ควรใช้แอตทริบิวต์ Sandbox ของ HTML5 เพื่อป้องกันการนำทางระดับบนสุดโดยไม่มีการโต้ตอบของผู้ใช้หรือไม่ |
use | เลิกใช้งานแล้ว SafeFrame ควรใช้โดเมนย่อยแบบสุ่มสำหรับครีเอทีฟโฆษณาแบบจองหรือไม่ |
พร็อพเพอร์ตี้
Optional allowOverlayExpansion
allowOverlayExpansion?: booleanOptional allowPushExpansion
allowPushExpansion?: booleanOptional forceSafeFrame
forceSafeFrame?: booleanOptional sandbox
sandbox?: booleantrue (บังคับให้เป็น false ไม่ได้) โปรดทราบว่าแอตทริบิวต์ sandbox จะปิดใช้ปลั๊กอิน (เช่น Flash)Optional useUniqueDomain
useUniqueDomain?: booleannull เพื่อล้างค่าที่จัดเก็บไว้หมายเหตุ: ฟีเจอร์นี้เปิดใช้อยู่โดยค่าเริ่มต้น
- ดูเพิ่มเติม
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 | การตั้งค่าเพื่อกำหนดค่าการขยายโฆษณา |
adsense | การตั้งค่าเพื่อกำหนดค่าแอตทริบิวต์ AdSense |
category | การตั้งค่าเพื่อกำหนดค่าการยกเว้นหมวดหมู่โฆษณา |
click | การตั้งค่าเพื่อกำหนดค่า URL ที่ระบบจะเปลี่ยนเส้นทางผู้ใช้ไปหลังจากคลิกโฆษณา |
collapse | การตั้งค่าเพื่อกำหนดค่าลักษณะการยุบของช่องโฆษณา |
continue | การตั้งค่าเพื่อกำหนดค่าลักษณะการทำงานของปุ่ม "เล่นต่อ" สำหรับโฆษณาช่วงวิดีโอหยุดเล่น |
interstitial | การตั้งค่าที่กำหนดค่าลักษณะการทำงานของช่องโฆษณาคั่นระหว่างหน้า |
safe | การตั้งค่าเพื่อกำหนดค่าการใช้ SafeFrame ใน GPT |
targeting | การตั้งค่าเพื่อกำหนดค่าการกำหนดเป้าหมายคีย์-ค่า |
พร็อพเพอร์ตี้
Optional adExpansion
adExpansion?: AdExpansionConfig- ดูเพิ่มเติม
Optional adsenseAttributes
adsenseAttributes?: AdSenseAttributesConfigแอตทริบิวต์ AdSense ที่กำหนดค่าผ่านการตั้งค่านี้จะมีผลกับช่องโฆษณาเท่านั้น ระบบอาจเรียกใช้การตั้งค่านี้หลายครั้งเพื่อกำหนดค่าแอตทริบิวต์หลายค่า หรือเขียนทับค่าที่มีอยู่
การเปลี่ยนแปลงแอตทริบิวต์ AdSense จะมีผลกับโฆษณาที่ขอหลังจากเรียกใช้เมธอดนี้เท่านั้น ด้วยเหตุนี้ เราขอแนะนำให้เรียกใช้เมธอดนี้ก่อนการเรียกใช้ googletag.display หรือ PubAdsService.refresh
- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Set the AdSense ad format and channel IDs. slot.setConfig({ adsenseAttributes: { adsense_ad_format: "120x240_as", adsense_channel_ids: "271828183+314159265", }, }); // Clear the AdSense channel IDs only. slot.setConfig({ adsenseAttributes: { adsense_channel_ids: null } }); // Clear all AdSense attributes. slot.setConfig({ adsenseAttributes: null });
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Set the AdSense ad format and channel IDs. slot.setConfig({ adsenseAttributes: { adsense_ad_format: "120x240_as", adsense_channel_ids: "271828183+314159265", }, }); // Clear the AdSense channel IDs only. slot.setConfig({ adsenseAttributes: { adsense_channel_ids: null } }); // Clear all AdSense attributes. slot.setConfig({ adsenseAttributes: null });
Optional categoryExclusion
categoryExclusion?: string[]- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Label = AirlineAd slot.setConfig({ categoryExclusion: ["AirlineAd"], }); // Clearing category exclusion setting. slot.setConfig({ categoryExclusion: null });
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Label = AirlineAd slot.setConfig({ categoryExclusion: ["AirlineAd"], }); // Clearing category exclusion setting. slot.setConfig({ categoryExclusion: null });
- ดูเพิ่มเติม
Optional clickUrl
clickUrl?: stringเซิร์ฟเวอร์ Google Ad Manager จะยังคงบันทึกการคลิกแม้ว่าจะมีการแทนที่ URL การคลิกก็ตาม ระบบจะเพิ่ม URL ของหน้า Landing Page ที่เชื่อมโยงกับครีเอทีฟโฆษณาที่แสดงต่อท้ายค่าที่ระบุ การตั้งค่านี้มากกว่า 1 ครั้งจะเขียนทับค่าที่กำหนดค่าไว้ก่อนหน้านี้
null จะล้างค่าหมายเหตุ: การตั้งค่านี้ใช้ได้กับคำขอที่ไม่ใช่ SRA เท่านั้น
- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Sets the click URL to 'http://www.example.com?original_click_url='. slot.setConfig({ clickUrl: "http://www.example.com?original_click_url=", }); // Clears the click URL. slot.setConfig({ clickUrl: null, });
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Sets the click URL to 'http://www.example.com?original_click_url='. slot.setConfig({ clickUrl: "http://www.example.com?original_click_url=", }); // Clears the click URL. slot.setConfig({ clickUrl: null, });
Optional collapseDiv
collapseDiv?: CollapseDivBehaviorช่องโฆษณาที่ยุบจะไม่ใช้พื้นที่ในหน้าเว็บ
ค่าที่รองรับ:
null(ค่าเริ่มต้น): ช่องจะไม่ยุบDISABLED: ช่องจะไม่ยุบ ไม่ว่าจะมีการแสดงโฆษณาหรือไม่ก็ตามBEFORE_FETCH: ช่องจะเริ่มยุบและขยายเมื่อมีการแสดงโฆษณาON_NO_FILL: ช่องจะเริ่มขยายออก และยุบลงหากไม่มีการแสดงผลโฆษณา
- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Collapse the div for this slot if no ad is returned. slot.setConfig({ collapseDiv: "ON_NO_FILL", }); // Collapse the div for this slot by default, and expand only // if an ad is returned. slot.setConfig({ collapseDiv: "BEFORE_FETCH", }); // Do not collapse the div for this slot. slot.setConfig({ collapseDiv: "DISABLED", }); // Clear the collapse setting. slot.setConfig({ collapseDiv: null, });
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Collapse the div for this slot if no ad is returned. slot.setConfig({ collapseDiv: "ON_NO_FILL", }); // Collapse the div for this slot by default, and expand only // if an ad is returned. slot.setConfig({ collapseDiv: "BEFORE_FETCH", }); // Do not collapse the div for this slot. slot.setConfig({ collapseDiv: "DISABLED", }); // Clear the collapse setting. slot.setConfig({ collapseDiv: null, });
- ดูเพิ่มเติม
Optional continueButton
continueButton?: ContinueButtonConfigการตั้งค่าเหล่านี้ช่วยให้คุณปรับแต่งลักษณะที่ปรากฏและลักษณะการทำงานของการโต้ตอบเพื่อออกและอ่านต่อที่เชื่อมโยงกับรูปแบบช่วงหยุดเล่นเนื้อหาได้
การตั้งค่าปุ่มดำเนินการต่อที่ไม่ได้ระบุไว้เมื่อเรียกใช้
setConfig() จะใช้ค่าเริ่มต้นที่ Google กำหนดไว้หากต้องการปิดใช้หรือล้างการตั้งค่าปุ่มดำเนินการต่อทั้งหมด ให้ส่ง
null- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Configure continue button settings. slot.setConfig({ continueButton: { font: "Arial", fontColor: "white", backgroundColor: "blue", targetId: "target-div-id", freqCapIntervalMinutes: 20, }, }); // Clear continue button settings. slot.setConfig({ continueButton: null });
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Configure continue button settings. slot.setConfig({ continueButton: { font: "Arial", fontColor: "white", backgroundColor: "blue", targetId: "target-div-id", freqCapIntervalMinutes: 20, }, }); // Clear continue button settings. slot.setConfig({ continueButton: null });
Optional โฆษณาคั่นระหว่างหน้า
interstitial?: InterstitialConfig- ดูเพิ่มเติม
Optional safeFrame
safeFrame?: SafeFrameConfigค่าที่กำหนดผ่านการตั้งค่านี้จะมีผลกับช่องโฆษณาเท่านั้น และจะลบล้างค่าที่ตั้งไว้ผ่าน PageSettingsConfig.safeFrame
- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Force SafeFrame for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion for the slot. slot.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings for the slot. slot.setConfig({ safeFrame: null });
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Force SafeFrame for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion for the slot. slot.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings for the slot. slot.setConfig({ safeFrame: null });
Optional การกำหนดเป้าหมาย
targeting?: Record<string, string | string[]>การกำหนดเป้าหมายที่กำหนดค่าผ่านการตั้งค่านี้จะมีผลกับช่องโฆษณาเท่านั้น ระบบอาจเรียกใช้การตั้งค่านี้หลายครั้งเพื่อกำหนดคีย์-ค่าการกำหนดเป้าหมายหลายรายการ หรือเขียนทับค่าที่มีอยู่ คีย์การกำหนดเป้าหมายจะกำหนดไว้ในบัญชี Google Ad Manager
- ตัวอย่าง
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Setting a single targeting key-value. slot.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key. slot.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. slot.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. slot.setConfig({ targeting: { interests: null } }); // Clear all targeting keys. slot.setConfig({ targeting: null });
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Setting a single targeting key-value. slot.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key. slot.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. slot.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. slot.setConfig({ targeting: { interests: null } }); // Clear all targeting keys. slot.setConfig({ targeting: null });
- ดูเพิ่มเติม
googletag.config.TaxonomyData
| พร็อพเพอร์ตี้ | |
|---|---|
values | รายการค่าการจัดหมวดหมู่ |
พร็อพเพอร์ตี้
values
values: readonly string[]googletag.config.VideoAdsConfig
| พร็อพเพอร์ตี้ | |
|---|---|
enable | โฆษณาวิดีโอจะแสดงในหน้าเว็บหรือไม่ |
video | รหัสแหล่งที่มาของเนื้อหาวิดีโอ |
video | รหัสเนื้อหาวิดีโอ |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
enableVideoAds
enableVideoAds: booleanเมื่อตั้งค่าเป็น
true ระบบจะเปิดใช้ข้อจำกัดการยกเว้นเนื้อหาในโฆษณา Display และโฆษณาวิดีโอหากทราบเนื้อหาวิดีโอ ให้ตั้งค่า videoContentId และ videoCmsId เป็นค่าที่ระบุไว้ในบริการนำเข้าเนื้อหาของ Google Ad Manager เพื่อใช้การยกเว้นเนื้อหาสำหรับโฆษณา Display
Optional videoCmsId
videoCmsId?: stringค่านี้เป็นค่าที่ไม่ซ้ำกันซึ่งกำหนดโดยบริการนำเข้าเนื้อหาของ Google Ad Manager เพื่อระบุแหล่งที่มาของเนื้อหาวิดีโอที่ระบุโดย videoContentId
- ดูเพิ่มเติม
Optional videoContentId
videoContentId?: stringค่านี้เป็นค่าที่ไม่ซ้ำกันซึ่งระบุวิดีโอหนึ่งๆ จากแหล่งที่มาของเนื้อหาที่ระบุโดย videoCmsId ค่านี้กำหนดโดย CMS ที่โฮสต์เนื้อหาวิดีโอของคุณ
- ดูเพิ่มเติม
googletag.enums
| การแจงนับ | |
|---|---|
Out | รูปแบบโฆษณาที่ไม่อยู่ในขอบเขตหน้าที่ GPT รองรับ |
Tag | การตั้งค่าการจัดการตามอายุที่ GPT รองรับ |
Traffic | แหล่งที่มาของการเข้าชมที่ GPT รองรับ |
การแจงนับ
OutOfPageFormat
OutOfPageFormat- ดูเพิ่มเติม
| สมาชิกการแจงนับ | |
|---|---|
AD_ | รูปแบบโฆษณาที่อิงตามความตั้งใจ |
BOTTOM_ | รูปแบบ Anchor ที่ช่องโฆษณาติดอยู่ที่ด้านล่างของวิวพอร์ต |
GAME_ | รูปแบบโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกม หมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง |
INTERSTITIAL | รูปแบบครีเอทีฟโฆษณาคั่นระหว่างหน้าในเว็บ |
LEFT_ | รูปแบบโฆษณาที่แถบข้างด้านซ้าย |
REWARDED | รูปแบบที่มีการให้รางวัล |
RIGHT_ | รูปแบบโฆษณาที่แถบข้างด้านขวา |
TOP_ | รูปแบบ Anchor ที่ช่องโฆษณาติดอยู่ที่ด้านบนของวิวพอร์ต |
TagForAgeTreatment
TrafficSource
TrafficSource- ดูเพิ่มเติม
| สมาชิกการแจงนับ | |
|---|---|
ORGANIC | การป้อน URL โดยตรง การค้นหาเว็บไซต์ หรือการดาวน์โหลดแอป |
PURCHASED | การเข้าชมที่เปลี่ยนเส้นทางจากพร็อพเพอร์ตี้นอกเหนือจากที่เป็นเจ้าของ (ได้มาหรือกิจกรรมที่จูงใจ) |
googletag.events
| อินเทอร์เฟซ | |
|---|---|
Event | อินเทอร์เฟซพื้นฐานสำหรับเหตุการณ์ GPT ทั้งหมด |
Event | นี่คือประเภทจำลองที่แมปชื่อเหตุการณ์กับประเภทออบเจ็กต์เหตุการณ์ที่เกี่ยวข้องสำหรับ Service.addEventListener และ Service.removeEventListener |
Game | ระบบจะเริ่มเหตุการณ์นี้เมื่อผู้ใช้ปิดช่องโฆษณาคั่นระหว่างหน้าในเกมที่แสดงด้วยตนเอง |
Game | เหตุการณ์นี้จะเริ่มทำงานเมื่อช่องโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมพร้อมแสดงต่อผู้ใช้ |
Impression | ระบบจะเริ่มเหตุการณ์นี้เมื่อการแสดงผลสามารถมองเห็นได้ตามเกณฑ์ของมุมมองแอ็กทีฟ |
Rewarded | ระบบจะเริ่มเหตุการณ์นี้เมื่อผู้ใช้ปิดช่องโฆษณาที่มีการให้รางวัล |
Rewarded | ระบบจะเริ่มเหตุการณ์นี้เมื่อมีการให้รางวัลสำหรับการดูโฆษณาที่มีการให้รางวัล |
Rewarded | ระบบจะเริ่มเหตุการณ์นี้เมื่อโฆษณาที่มีการให้รางวัลพร้อมแสดง |
Rewarded | เหตุการณ์นี้จะเริ่มทำงานเมื่อโฆษณาวิดีโอที่มีการให้รางวัลเล่นจบ |
Slot | ระบบจะเริ่มเหตุการณ์นี้เมื่อ iframe ของครีเอทีฟโฆษณาเริ่มเหตุการณ์การโหลด |
Slot | เหตุการณ์นี้จะเริ่มทำงานเมื่อมีการแทรกโค้ดครีเอทีฟโฆษณาลงในช่อง |
Slot | เหตุการณ์นี้จะเริ่มทำงานเมื่อมีการขอโฆษณาสำหรับช่องหนึ่งๆ |
Slot | เหตุการณ์นี้จะเริ่มทำงานเมื่อได้รับการตอบกลับโฆษณาสำหรับช่องโฆษณาหนึ่งๆ |
Slot | เหตุการณ์นี้จะเริ่มทำงานเมื่อเปอร์เซ็นต์บนหน้าจอของพื้นที่ช่องโฆษณาเปลี่ยนแปลง |
googletag.events.Event
| พร็อพเพอร์ตี้ | |
|---|---|
service | ชื่อบริการที่ทริกเกอร์เหตุการณ์ |
slot | ช่องที่เรียกเหตุการณ์ให้แสดง |
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
serviceName
serviceName: stringslot
slot: Slotgoogletag.events.EventTypeMap
| พร็อพเพอร์ตี้ | |
|---|---|
game | ชื่อแทนสำหรับ events.GameManualInterstitialSlotClosedEvent |
game | ชื่อแทนสำหรับ events.GameManualInterstitialSlotReadyEvent |
impression | ชื่อแทนสำหรับ events.ImpressionViewableEvent |
rewarded | ชื่อแทนสำหรับ events.RewardedSlotClosedEvent |
rewarded | ชื่อแทนสำหรับ events.RewardedSlotGrantedEvent |
rewarded | ชื่อแทนสำหรับ events.RewardedSlotReadyEvent |
rewarded | ชื่อแทนสำหรับ events.RewardedSlotVideoCompletedEvent |
slot | ชื่อแทนสำหรับ events.SlotOnloadEvent |
slot | ชื่อแทนสำหรับ events.SlotRenderEndedEvent |
slot | ชื่อแทนสำหรับ events.SlotRequestedEvent |
slot | ชื่อแทนสำหรับ events.SlotResponseReceived |
slot | ชื่อแทนสำหรับ events.SlotVisibilityChangedEvent |
พร็อพเพอร์ตี้
gameManualInterstitialSlotClosed
gameManualInterstitialSlotClosed: GameManualInterstitialSlotClosedEventgameManualInterstitialSlotReady
gameManualInterstitialSlotReady: GameManualInterstitialSlotReadyEventimpressionViewable
impressionViewable: ImpressionViewableEventrewardedSlotClosed
rewardedSlotClosed: RewardedSlotClosedEventrewardedSlotGranted
rewardedSlotGranted: RewardedSlotGrantedEventrewardedSlotReady
rewardedSlotReady: RewardedSlotReadyEventrewardedSlotVideoCompleted
rewardedSlotVideoCompleted: RewardedSlotVideoCompletedEventslotOnload
slotOnload: SlotOnloadEventslotRenderEnded
slotRenderEnded: SlotRenderEndedEventslotRequested
slotRequested: SlotRequestedEventslotResponseReceived
slotResponseReceived: SlotResponseReceivedslotVisibilityChanged
slotVisibilityChanged: SlotVisibilityChangedEventgoogletag.events.GameManualInterstitialSlotClosedEvent
Eventหมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง
| พร็อพเพอร์ตี้ | |
|---|---|
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. } }); }
TypeScript
// This listener is called when a game manual interstitial slot is closed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", (event) => { const slot = event.slot; console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed."); if (slot === targetSlot) { // Slot specific logic. } }); }
googletag.events.GameManualInterstitialSlotReadyEvent
Eventหมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง
| พร็อพเพอร์ตี้ | |
|---|---|
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. } }); }
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(): boolean| การคืนสินค้า | |
|---|---|
boolean | |
googletag.events.ImpressionViewableEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
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. } });
TypeScript
// This listener is called when an impression becomes viewable. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("impressionViewable", (event) => { const slot = event.slot; console.log("Impression for slot", slot.getSlotElementId(), "became viewable."); if (slot === targetSlot) { // Slot specific logic. } });
- ดูเพิ่มเติม
googletag.events.RewardedSlotClosedEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
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. } }); }
TypeScript
const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the user closes a rewarded ad slot. googletag.pubads().addEventListener("rewardedSlotClosed", (event) => { const slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed."); if (slot === targetSlot) { // Slot specific logic. } }); }
- ดูเพิ่มเติม
googletag.events.RewardedSlotGrantedEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
payload | ออบเจ็กต์ที่มีข้อมูลเกี่ยวกับรางวัลที่ได้รับ |
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. } }); }
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: RewardedPayloadgoogletag.events.RewardedSlotReadyEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
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. } }); }
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(): boolean| การคืนสินค้า | |
|---|---|
boolean | แสดงโฆษณาที่มีการให้รางวัลสำเร็จหรือไม่ |
googletag.events.RewardedSlotVideoCompletedEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
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 video in a rewarded ad slot has // finished playing. googletag.pubads().addEventListener("rewardedSlotVideoCompleted", (event) => { const slot = event.slot; console.log("Video in rewarded ad slot", slot.getSlotElementId(), "has finished playing."); 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 video in a rewarded ad slot has // finished playing. googletag.pubads().addEventListener("rewardedSlotVideoCompleted", (event) => { const slot = event.slot; console.log("Video in rewarded ad slot", slot.getSlotElementId(), "has finished playing."); if (slot === targetSlot) { // Slot specific logic. } }); }
- ดูเพิ่มเติม
googletag.events.SlotOnloadEvent
EventSlotOnloadEvent| พร็อพเพอร์ตี้ | |
|---|---|
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. } });
TypeScript
// This listener is called when a creative iframe load event fires. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotOnload", (event) => { const slot = event.slot; console.log("Creative iframe for slot", slot.getSlotElementId(), "has loaded."); if (slot === targetSlot) { // Slot specific logic. } });
- ดูเพิ่มเติม
googletag.events.SlotRenderEndedEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
advertiser | รหัสผู้ลงโฆษณาของโฆษณาที่แสดงผล |
campaign | รหัสแคมเปญของโฆษณาที่แสดงผล |
company | รหัสของบริษัทที่เสนอราคาในโฆษณาทดแทนที่แสดงผล |
creative | รหัสครีเอทีฟโฆษณาของโฆษณาแบบจองล่วงหน้าที่แสดงผล |
creative | รหัสเทมเพลตครีเอทีฟโฆษณาของโฆษณาแบบจองล่วงหน้าที่แสดงผล |
is | โฆษณาเป็นโฆษณาทดแทนหรือไม่ |
is | มีการแสดงโฆษณาสำหรับช่องโฆษณาหรือไม่ |
label | เลิกใช้งานแล้ว |
line | รหัสรายการโฆษณาของโฆษณาแบบจองล่วงหน้าที่แสดงผล |
response | ตัวระบุการตอบกลับคือตัวระบุที่ไม่ซ้ำกันสำหรับการตอบกลับของโฆษณา |
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. } });
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: numbernull สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicecampaignId
campaignId: numbernull สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicecompanyIds
companyIds: number[]null สำหรับช่องว่าง โฆษณาแบบจองล่วงหน้า และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicecreativeId
creativeId: numbernull สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicecreativeTemplateId
creativeTemplateId: numbernull สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServiceisBackfill
isBackfill: booleantrue หากโฆษณาเป็นโฆษณาทดแทน และเป็น false หากไม่ใช่isEmpty
isEmpty: booleantrue หากไม่มีการแสดงโฆษณา และเป็น false หากมีการแสดงโฆษณาlabelIds
labelIds: number[]lineItemId
lineItemId: numbernull สำหรับช่องว่าง โฆษณาทดแทน และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServiceresponseIdentifier
responseIdentifier: stringsize
size: string | number[][728, 90] ค่าจะเป็น null สำหรับช่องโฆษณาว่างslotContentChanged
slotContentChanged: booleantrue หากมีการเปลี่ยนแปลงเนื้อหา และเป็น false หากไม่มีการเปลี่ยนแปลงsourceAgnosticCreativeId
sourceAgnosticCreativeId: numbernull หากโฆษณาไม่ใช่การจองหรือโฆษณาทดแทนรายการโฆษณา หรือครีเอทีฟโฆษณาแสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicesourceAgnosticLineItemId
sourceAgnosticLineItemId: numbernull หากโฆษณาไม่ใช่การจองหรือโฆษณาทดแทนรายการโฆษณา หรือครีเอทีฟโฆษณาแสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServiceyieldGroupIds
yieldGroupIds: number[]null สำหรับช่องว่าง โฆษณาแบบจองล่วงหน้า และครีเอทีฟโฆษณาที่แสดงผลโดยบริการอื่นที่ไม่ใช่ PubAdsServicegoogletag.events.SlotRequestedEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
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. } });
TypeScript
// This listener is called when the specified service issues an ad // request for a slot. Each slot will fire this event, even though they // may be batched together in a single request if single request // architecture (SRA) is enabled. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotRequested", (event) => { const slot = event.slot; console.log("Slot", slot.getSlotElementId(), "has been requested."); if (slot === targetSlot) { // Slot specific logic. } });
- ดูเพิ่มเติม
googletag.events.SlotResponseReceived
Event| พร็อพเพอร์ตี้ | |
|---|---|
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. } });
TypeScript
// This listener is called when an ad response has been received // for a slot. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotResponseReceived", (event) => { const slot = event.slot; console.log("Ad response for slot", slot.getSlotElementId(), "received."); if (slot === targetSlot) { // Slot specific logic. } });
- ดูเพิ่มเติม
googletag.events.SlotVisibilityChangedEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
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. } });
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: numbergoogletag.secureSignals
| อินเทอร์เฟซ | |
|---|---|
Bidder | แสดงผลสัญญาณที่ปลอดภัยสำหรับผู้เสนอราคาที่เฉพาะเจาะจง |
Publisher | แสดงผลสัญญาณที่ปลอดภัยสำหรับผู้เผยแพร่โฆษณาที่เฉพาะเจาะจง |
Secure | อินเทอร์เฟซสําหรับจัดการสัญญาณที่ปลอดภัย |
| ชื่อแทนประเภท | |
|---|---|
Secure | อินเทอร์เฟซสำหรับการแสดงผลสัญญาณที่ปลอดภัยสำหรับผู้เสนอราคาหรือผู้ให้บริการที่เฉพาะเจาะจง |
ชื่อแทนประเภท
SecureSignalProvider
SecureSignalProvider: BidderSignalProvider | PublisherSignalProviderid หรือ networkCode อย่างใดอย่างหนึ่ง แต่ไม่ใช่ทั้ง 2 รายการgoogletag.secureSignals.BidderSignalProvider
ผู้ให้บริการสัญญาณที่ปลอดภัยของผู้เสนอราคาประกอบด้วย 2 ส่วน ดังนี้
- ฟังก์ชัน Collector ซึ่งจะแสดงผล
Promiseที่แปลงเป็นสัญญาณที่ปลอดภัย idซึ่งระบุผู้เสนอราคาที่เชื่อมโยงกับสัญญาณ
| พร็อพเพอร์ตี้ | |
|---|---|
collector | ฟังก์ชันที่แสดงผล Promise ซึ่งแปลงเป็นสัญญาณที่ปลอดภัย |
id | ตัวระบุที่ไม่ซ้ำกันสำหรับ Collector ที่เชื่อมโยงกับสัญญาณที่ปลอดภัยนี้ ตามที่ลงทะเบียนไว้ใน Google Ad Manager |
- ตัวอย่าง
JavaScript
// id is provided googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: () => { // ...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: stringgoogletag.secureSignals.PublisherSignalProvider
ผู้ให้บริการสัญญาณของผู้เผยแพร่โฆษณาประกอบด้วย 2 ส่วนดังนี้
- ฟังก์ชัน Collector ซึ่งจะแสดงผล
Promiseที่แปลงเป็นสัญญาณที่ปลอดภัย networkCodeซึ่งระบุผู้เผยแพร่โฆษณาที่เชื่อมโยงกับสัญญาณ
| พร็อพเพอร์ตี้ | |
|---|---|
collector | ฟังก์ชันที่แสดงผล Promise ซึ่งแปลงเป็นสัญญาณที่ปลอดภัย |
network | รหัสเครือข่าย (ตามที่เห็นในเส้นทางหน่วยโฆษณา) สำหรับผู้เผยแพร่โฆษณาที่เชื่อมโยงกับสัญญาณที่ปลอดภัยนี้ |
- ตัวอย่าง
JavaScript
// networkCode is provided googletag.secureSignalProviders.push({ networkCode: "123456", collectorFunction: () => { // ...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: stringgoogletag.secureSignals.SecureSignalProvidersArray
| เมธอด | |
|---|---|
clear | ล้างสัญญาณทั้งหมดสำหรับ Collector ทั้งหมดออกจากแคช |
push | เพิ่ม secureSignals.SecureSignalProvider ใหม่ลงในอาร์เรย์ผู้ให้บริการสัญญาณและเริ่มกระบวนการสร้างสัญญาณ |
เมธอด
clearAllCache
clearAllCache(): voidการเรียกใช้วิธีนี้อาจลดโอกาสที่สัญญาณจะรวมอยู่ในคำขอโฆษณาสำหรับการดูหน้าเว็บปัจจุบันและหน้าเว็บที่อาจดูในภายหลัง ดังนั้นจึงควรเรียกใช้เฉพาะเมื่อมีการเปลี่ยนแปลงสถานะที่สำคัญเท่านั้น เช่น เหตุการณ์ที่ระบุถึงผู้ใช้ใหม่ (เข้าสู่ระบบ ออกจากระบบ ลงชื่อสมัครใช้ ฯลฯ)
push
push(provider: SecureSignalProvider): void| พารามิเตอร์ | |
|---|---|
provider: SecureSignalProvider | ออบเจ็กต์ secureSignals.SecureSignalProvider ที่จะเพิ่มลงในอาร์เรย์ |