การอ้างอิงนี้ใช้สัญกรณ์ TypeScript เพื่ออธิบายประเภท ตารางต่อไปนี้แสดงคำอธิบายโดยย่อพร้อมตัวอย่าง
| พิมพ์นิพจน์ | |
|---|---|
| string | ประเภทสตริงดั้งเดิม | 
| string[] | ประเภทอาร์เรย์ ซึ่งค่าต้องเป็นสตริงเท่านั้น | 
| number | string | ประเภทสหภาพ ซึ่งค่าอาจเป็นตัวเลขหรือสตริงก็ได้ | 
| Array<number | string> | ประเภทอาร์เรย์ซึ่งค่าเป็นประเภทที่ซับซ้อน (สหภาพ) | 
| [number, string] | ประเภททูเพิล ซึ่งค่าคืออาร์เรย์ 2 องค์ประกอบที่ต้องมีตัวเลขและสตริงตามลำดับ | 
| Slot | ประเภทออบเจ็กต์ซึ่งค่าเป็นอินสแตนซ์ของ googletag.Slot | 
| () => void | ประเภทฟังก์ชันที่ไม่มีอาร์กิวเมนต์ที่กำหนดและไม่มีค่าที่ส่งคืน | 
ดูข้อมูลเพิ่มเติมเกี่ยวกับประเภทที่รองรับและนิพจน์ประเภทได้ใน คู่มือ TypeScript
คำอธิบายประกอบประเภท
เครื่องหมายโคลอนหลังตัวแปร ชื่อพารามิเตอร์ ชื่อพร็อพเพอร์ตี้ หรือลายเซ็นของฟังก์ชันแสดงถึง คำอธิบายประกอบประเภท คำอธิบายประกอบประเภทจะอธิบายประเภทที่องค์ประกอบทางด้านซ้ายของโคลอน ยอมรับหรือส่งคืนได้ ตารางต่อไปนี้แสดงตัวอย่างคำอธิบายประกอบประเภทที่คุณอาจเห็นในข้อมูลอ้างอิงนี้
| คำอธิบายประกอบประเภท | |
|---|---|
| param: string | ระบุว่า paramยอมรับหรือแสดงผลค่าสตริง ไวยากรณ์นี้ใช้
        สำหรับตัวแปร พารามิเตอร์ พร็อพเพอร์ตี้ และประเภทการคืนค่า | 
| param?: number | string | ระบุว่า paramไม่บังคับ แต่ยอมรับทั้งตัวเลขหรือสตริง
        เมื่อระบุ ไวยากรณ์นี้ใช้กับพารามิเตอร์และพร็อพเพอร์ตี้ | 
| ...params: Array<() => void> | ระบุว่า paramsเป็น
        
          พารามิเตอร์ที่เหลือ
         ที่ยอมรับฟังก์ชัน พารามิเตอร์ที่เหลือจะยอมรับค่าประเภทที่ระบุได้ไม่จำกัดจำนวน | 
googletag
| เนมสเปซ | |
|---|---|
| config | อินเทอร์เฟซการกำหนดค่าหลักสำหรับการตั้งค่าระดับหน้า | 
| enums | นี่คือเนมสเปซที่ GPT ใช้สำหรับประเภทการแจงนับ | 
| events | นี่คือเนมสเปซที่ GPT ใช้สำหรับเหตุการณ์ | 
| secure | นี่คือเนมสเปซที่ GPT ใช้ในการจัดการสัญญาณที่ปลอดภัย | 
| อินเทอร์เฟซ | |
|---|---|
| Command | อาร์เรย์คำสั่งยอมรับลำดับของฟังก์ชันและเรียกใช้ตามลำดับ | 
| Companion | บริการโฆษณาที่แสดงร่วม | 
| Privacy | ออบเจ็กต์การกำหนดค่าสำหรับการตั้งค่าความเป็นส่วนตัว | 
| Pub | บริการโฆษณาของผู้เผยแพร่โฆษณา | 
| Response | ออบเจ็กต์ที่แสดงการตอบกลับโฆษณาเดียว | 
| Rewarded | ออบเจ็กต์ที่แสดงรางวัลที่เชื่อมโยงกับโฆษณาที่มีการให้รางวัล | 
| Service | คลาสบริการพื้นฐานที่มีเมธอดที่ใช้ร่วมกันสำหรับบริการทั้งหมด | 
| Size | เครื่องมือสร้างสำหรับออบเจ็กต์ข้อกำหนดการแมปขนาด | 
| Slot | Slot คือออบเจ็กต์ที่แสดงช่องโฆษณาเดียวในหน้าเว็บ | 
| ชื่อแทนประเภท | |
|---|---|
| General | การกำหนดค่าขนาดที่ถูกต้องสำหรับช่อง ซึ่งอาจเป็นขนาดเดียวหรือหลายขนาด | 
| Multi | รายการขนาดที่ใช้ได้รายการเดียว | 
| Named | ขนาดที่ตั้งชื่อแล้วซึ่งช่องจะมีได้ | 
| Single | ขนาดที่ใช้ได้ขนาดเดียวสำหรับช่อง | 
| Single | อาร์เรย์ของตัวเลข 2 ตัวที่แสดง [ความกว้าง, ความสูง] | 
| Size | การแมปขนาดวิวพอร์ตกับขนาดโฆษณา | 
| Size | รายการการแมปขนาด | 
| ตัวแปร | |
|---|---|
| api | Flag indicating that the GPT API is loaded and ready to be called. | 
| cmd | การอ้างอิงคิวคำสั่งส่วนกลางสำหรับการดำเนินการแบบไม่พร้อมกันของการเรียกที่เกี่ยวข้องกับ GPT | 
| pubads | Flag ที่ระบุว่ามีการเปิดใช้ โหลด และใช้งาน PubAdsService ได้อย่างสมบูรณ์ | 
| secure | อ้างอิงถึงอาร์เรย์ผู้ให้บริการสัญญาณที่ปลอดภัย | 
| ฟังก์ชัน | |
|---|---|
| companion | แสดงผลการอ้างอิงไปยัง CompanionAdsService | 
| define | สร้างช่องโฆษณาที่ไม่อยู่ในขอบเขตหน้าด้วยเส้นทางหน่วยโฆษณาดังกล่าว | 
| define | สร้างช่องโฆษณาที่มีเส้นทางและขนาดหน่วยโฆษณาที่ระบุ และเชื่อมโยงกับรหัสขององค์ประกอบ div ในหน้าเว็บที่จะมีโฆษณา | 
| destroy | ทำลายช่องที่ระบุ โดยนำออบเจ็กต์และการอ้างอิงที่เกี่ยวข้องทั้งหมดของช่องเหล่านั้นออกจาก GPT | 
| disable | ปิดใช้คอนโซลผู้เผยแพร่โฆษณาของ Google | 
| display | สั่งให้บริการช่องแสดงช่อง | 
| enable | เปิดใช้บริการ GPT ทั้งหมดที่กำหนดไว้สำหรับช่องโฆษณาในหน้าเว็บ | 
| get | แสดงผล GPT เวอร์ชันปัจจุบัน | 
| open | เปิดคอนโซลผู้เผยแพร่โฆษณาของ Google | 
| pubads | แสดงผลการอ้างอิงไปยัง PubAdsService | 
| set | ตั้งค่าชื่อสำหรับ iframe คอนเทนเนอร์โฆษณาทั้งหมดที่สร้างโดย PubAdsService ตั้งแต่ตอนนี้เป็นต้นไป | 
| set | ตั้งค่าตัวเลือกการกำหนดค่าทั่วไปสำหรับหน้าเว็บ | 
| size | สร้าง SizeMappingBuilder ใหม่ | 
ชื่อแทนประเภท
GeneralSize
GeneralSize: SingleSize | MultiSizeMultiSize
MultiSize: SingleSize[]NamedSize
NamedSize: "fluid" | ["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 เพื่อจัดคิวการเรียกกลับเมื่อ GPT พร้อม Callback เหล่านี้ไม่จำเป็นต้องตรวจสอบ googletag.apiReady เนื่องจากรับประกันว่าจะดำเนินการเมื่อตั้งค่า API แล้ว
Const cmd
cmd: ((this: typeof globalThis) => void)[] | CommandArrayไวยากรณ์แท็ก GPT ในหน้าเว็บจะเริ่มต้นตัวแปร
googletag.cmd เป็นอาร์เรย์ JavaScript ว่าง และ cmd.push คือเมธอด Array.push มาตรฐานที่เพิ่มองค์ประกอบลงในท้ายอาร์เรย์ เมื่อโหลด JavaScript ของ GPT แล้ว ระบบจะค้นหาอาร์เรย์และเรียกใช้ฟังก์ชันทั้งหมดตามลำดับ จากนั้นสคริปต์จะแทนที่ cmd ด้วยออบเจ็กต์ CommandArray ที่กำหนดเมธอด push เพื่อเรียกใช้อาร์กิวเมนต์ฟังก์ชันที่ส่งไปยังออบเจ็กต์ กลไกนี้ช่วยให้ GPT ลดเวลาในการตอบสนองที่รับรู้ได้โดยการดึงข้อมูล JavaScript แบบไม่พร้อมกัน ในขณะที่อนุญาตให้เบราว์เซอร์แสดงหน้าต่อไป- ตัวอย่าง
- JavaScript- googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); }); - JavaScript (เดิม)- googletag.cmd.push(function () { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); }); - TypeScript- googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600])!.addService(googletag.pubads()); }); 
Const pubadsReady
pubadsReady: boolean | 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"); }, }); - JavaScript (เดิม)- window.googletag = window.googletag || { cmd: [] }; googletag.secureSignalProviders = googletag.secureSignalProviders || []; googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: function () { return Promise.resolve("signal"); }, }); - TypeScript- window.googletag = window.googletag || { cmd: [] }; googletag.secureSignalProviders = googletag.secureSignalProviders || []; googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: () => { return Promise.resolve("signal"); }, }); 
- ดูเพิ่มเติม
ฟังก์ชัน
companionAds
companionAds(): CompanionAdsService| การคืนสินค้า | |
|---|---|
| CompanionAdsService | บริการโฆษณาที่แสดงร่วม | 
defineOutOfPageSlot
defineOutOfPageSlot(adUnitPath: string, div?: string | OutOfPageFormat): Slot | nullสำหรับโฆษณาที่ไม่อยู่ในขอบเขตหน้าที่กำหนดเอง
div คือรหัสขององค์ประกอบ div ที่จะมีโฆษณา ดูรายละเอียดเพิ่มเติมได้ที่บทความเกี่ยวกับครีเอทีฟโฆษณาที่ไม่อยู่ในขอบเขตหน้าสำหรับโฆษณาที่ไม่อยู่ในขอบเขตหน้าที่จัดการโดย GPT
div เป็น OutOfPageFormat ที่รองรับ- ตัวอย่าง
- JavaScript- // Define a custom out-of-page ad slot. googletag.defineOutOfPageSlot("/1234567/sports", "div-1"); // Define a GPT managed web interstitial ad slot. googletag.defineOutOfPageSlot("/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL); - JavaScript (เดิม)- // Define a custom out-of-page ad slot. googletag.defineOutOfPageSlot("/1234567/sports", "div-1"); // Define a GPT managed web interstitial ad slot. googletag.defineOutOfPageSlot("/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL); - TypeScript- // Define a custom out-of-page ad slot. googletag.defineOutOfPageSlot("/1234567/sports", "div-1"); // Define a GPT managed web interstitial ad slot. googletag.defineOutOfPageSlot("/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| adUnitPath: string | เส้นทางหน่วยโฆษณาแบบเต็มพร้อมรหัสเครือข่ายและรหัสหน่วยโฆษณา | 
|  | รหัสของ Div ที่จะมีหน่วยโฆษณาหรือ OutOfPageFormat นี้ | 
| การคืนสินค้า | |
|---|---|
| Slot | null | ช่องที่สร้างขึ้นใหม่ หรือ nullหากสร้างช่องไม่ได้ | 
defineSlot
defineSlot(adUnitPath: string, size: GeneralSize, div?: string): Slot | null- ตัวอย่าง
- JavaScript- googletag.defineSlot("/1234567/sports", [728, 90], "div-1"); - JavaScript (เดิม)- googletag.defineSlot("/1234567/sports", [728, 90], "div-1"); - TypeScript- googletag.defineSlot("/1234567/sports", [728, 90], "div-1"); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| adUnitPath: string | เส้นทางหน่วยโฆษณาแบบเต็มพร้อมรหัสเครือข่ายและรหัสหน่วย | 
| size: GeneralSize | ความกว้างและความสูงของช่องที่เพิ่ม นี่คือขนาดที่ใช้ในคำขอโฆษณาหากไม่ได้ระบุการแมปขนาดที่ปรับเปลี่ยนตามพื้นที่โฆษณา หรือขนาดของวิวพอร์ตเล็กกว่าขนาดที่เล็กที่สุดที่ระบุในการแมป | 
|  | รหัสขององค์ประกอบ div ที่จะมีหน่วยโฆษณานี้ | 
| การคืนสินค้า | |
|---|---|
| Slot | null | ช่องที่สร้างขึ้นใหม่ หรือ nullหากสร้างช่องไม่ได้ | 
destroySlots
destroySlots(slots?: Slot[]): booleanการเรียก API นี้ในช่องจะล้างโฆษณาและนำออบเจ็กต์ช่องออกจากสถานะภายในที่ GPT รักษาไว้ การเรียกใช้ฟังก์ชันอื่นๆ ในออบเจ็กต์ช่องจะทําให้เกิดลักษณะการทํางานที่ไม่ได้กําหนด โปรดทราบว่าเบราว์เซอร์อาจยังคงไม่ปล่อยหน่วยความจำที่เชื่อมโยงกับช่องดังกล่าวหากหน้าผู้เผยแพร่โฆษณายังคงมีการอ้างอิงถึงช่องนั้น การเรียก API นี้จะทำให้ div ที่เชื่อมโยงกับช่องโฆษณานั้นพร้อมสำหรับการนำกลับมาใช้ใหม่
โดยเฉพาะอย่างยิ่ง การทำลายช่องโฆษณาจะนำโฆษณาออกจากการดูหน้าเว็บที่ใช้งานได้นานของ GPT ดังนั้นคำขอในอนาคตจะไม่ได้รับผลกระทบจากโฆษณาที่จำกัดจำนวนหรือการยกเว้นโฆษณาของคู่แข่งที่เกี่ยวข้องกับโฆษณานี้ การไม่เรียกใช้ฟังก์ชันนี้ก่อนนำ div ของช่องออกจากหน้าเว็บจะส่งผลให้เกิดลักษณะการทำงานที่ไม่แน่นอน
- ตัวอย่าง
- JavaScript- // The calls to construct an ad and display contents. const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1"); googletag.display("div-1"); const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2"); googletag.display("div-2"); // This call to destroy only slot1. googletag.destroySlots([slot1]); // This call to destroy both slot1 and slot2. googletag.destroySlots([slot1, slot2]); // This call to destroy all slots. googletag.destroySlots(); - JavaScript (เดิม)- // The calls to construct an ad and display contents. var slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1"); googletag.display("div-1"); var slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2"); googletag.display("div-2"); // This call to destroy only slot1. googletag.destroySlots([slot1]); // This call to destroy both slot1 and slot2. googletag.destroySlots([slot1, slot2]); // This call to destroy all slots. googletag.destroySlots(); - TypeScript- // The calls to construct an ad and display contents. const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!; googletag.display("div-1"); const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!; googletag.display("div-2"); // This call to destroy only slot1. googletag.destroySlots([slot1]); // This call to destroy both slot1 and slot2. googletag.destroySlots([slot1, slot2]); // This call to destroy all slots. googletag.destroySlots(); 
| พารามิเตอร์ | |
|---|---|
|  | อาร์เรย์ของช่องที่จะทำลาย อาร์เรย์เป็นพารามิเตอร์ที่ไม่บังคับ หากไม่ได้ระบุ ระบบจะทำลายสล็อตทั้งหมด | 
| การคืนสินค้า | |
|---|---|
| boolean | trueหากมีการทำลายสล็อตfalseไม่เช่นนั้น | 
disablePublisherConsole
disablePublisherConsole(): void- ดูเพิ่มเติม
display
display(divOrSlot: string | Element | Slot): voidหากใช้สถาปัตยกรรมคำขอรวมครั้งเดียว (SRA) ระบบจะดึงข้อมูลช่องโฆษณาที่ยังไม่ได้ดึงข้อมูลทั้งหมดในขณะที่เรียกใช้เมธอดนี้พร้อมกัน หากต้องการบังคับไม่ให้ช่องโฆษณาแสดง คุณต้องนำ div ทั้งหมดออก
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| divOrSlot: string | Element | Slot | รหัสขององค์ประกอบ div ที่มีช่องโฆษณาหรือองค์ประกอบ div หรือออบเจ็กต์ช่อง หากระบุองค์ประกอบ Div จะต้องมีแอตทริบิวต์ "id" ที่ตรงกับรหัสที่ส่งไปยัง defineSlot | 
enableServices
enableServices(): voidgetVersion
getVersion(): string- ดูเพิ่มเติม
| การคืนสินค้า | |
|---|---|
| string | สตริงเวอร์ชัน GPT ที่กำลังดำเนินการอยู่ | 
openConsole
openConsole(div?: string): void- ตัวอย่าง
- JavaScript- // Calling with div ID. googletag.openConsole("div-1"); // Calling without div ID. googletag.openConsole(); - JavaScript (เดิม)- // Calling with div ID. googletag.openConsole("div-1"); // Calling without div ID. googletag.openConsole(); - TypeScript- // Calling with div ID. googletag.openConsole("div-1"); // Calling without div ID. googletag.openConsole(); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
|  | รหัส Div ของช่องโฆษณา ค่านี้จะระบุหรือไม่ก็ได้ เมื่อระบุแล้ว คอนโซลผู้เผยแพร่โฆษณาจะพยายามเปิดโดยแสดงรายละเอียดของช่องโฆษณาที่ระบุ | 
pubads
pubads(): PubAdsService| การคืนสินค้า | |
|---|---|
| PubAdsService | บริการโฆษณาของผู้เผยแพร่โฆษณา | 
setAdIframeTitle
setAdIframeTitle(title: string): void- ตัวอย่าง
- JavaScript- googletag.setAdIframeTitle("title"); - JavaScript (เดิม)- googletag.setAdIframeTitle("title"); - TypeScript- googletag.setAdIframeTitle("title"); 
| พารามิเตอร์ | |
|---|---|
| title: string | ชื่อใหม่สำหรับ iframe คอนเทนเนอร์โฆษณาทั้งหมด | 
setConfig
setConfig(config: PageSettingsConfig): void| พารามิเตอร์ | |
|---|---|
| config: PageSettingsConfig | |
sizeMapping
sizeMapping(): SizeMappingBuilder| การคืนสินค้า | |
|---|---|
| SizeMappingBuilder | เครื่องมือสร้างใหม่ | 
googletag.CommandArray
| เมธอด | |
|---|---|
| push | เรียกใช้ลำดับฟังก์ชันที่ระบุในอาร์กิวเมนต์ตามลำดับ | 
เมธอด
push
push(...f: ((this: typeof globalThis) => void)[]): number- ตัวอย่าง
- JavaScript- googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); }); - JavaScript (เดิม)- googletag.cmd.push(function () { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); }); - TypeScript- googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600])!.addService(googletag.pubads()); }); 
| พารามิเตอร์ | |
|---|---|
|  | ฟังก์ชัน JavaScript ที่จะดำเนินการ การเชื่อมโยงรันไทม์จะเป็น globalThisเสมอ พิจารณาส่งฟังก์ชันลูกศรเพื่อคงค่าthisของบริบทคำศัพท์ที่ล้อมรอบ | 
| การคืนสินค้า | |
|---|---|
| number | จำนวนคำสั่งที่ประมวลผลแล้วจนถึงตอนนี้ ซึ่งใช้ร่วมกับค่าที่ส่งคืนของ Array.push(ความยาวปัจจุบันของอาร์เรย์) ได้ | 
googletag.CompanionAdsService
Service| เมธอด | |
|---|---|
| add | ลงทะเบียน Listener ที่ช่วยให้คุณตั้งค่าและเรียกใช้ฟังก์ชัน JavaScript ได้เมื่อเกิดเหตุการณ์ GPT ที่เฉพาะเจาะจงในหน้าเว็บ รับค่าจาก  | 
| get | ดูรายการช่วงเวลาที่เชื่อมโยงกับบริการนี้ รับค่าจาก  | 
| remove | นำ Listener ที่ลงทะเบียนไว้ก่อนหน้านี้ออก รับค่าจาก  | 
| set | ตั้งค่าว่าช่องโฆษณาที่แสดงร่วมที่ยังไม่ได้รับโฆษณาจะได้รับโฆษณาทดแทนโดยอัตโนมัติหรือไม่ | 
- ดูเพิ่มเติม
เมธอด
setRefreshUnfilledSlots
setRefreshUnfilledSlots(value: boolean): voidเมธอดนี้เรียกใช้ได้หลายครั้งในระหว่างอายุการใช้งานของหน้าเว็บเพื่อเปิดและปิดการแสดงโฆษณาทดแทน เฉพาะช่องโฆษณาที่ลงทะเบียนกับ PubAdsService เท่านั้นที่จะได้รับการแสดงโฆษณาทดแทน เนื่องจากข้อจำกัดด้านนโยบาย วิธีนี้จึงไม่ได้ออกแบบมาเพื่อแสดงโฆษณาในช่องโฆษณาที่แสดงร่วมที่ว่างเปล่าเมื่อแสดงวิดีโอ Ad Exchange
- ตัวอย่าง
- JavaScript- googletag.companionAds().setRefreshUnfilledSlots(true); - JavaScript (เดิม)- googletag.companionAds().setRefreshUnfilledSlots(true); - TypeScript- googletag.companionAds().setRefreshUnfilledSlots(true); 
| พารามิเตอร์ | |
|---|---|
| value: boolean | trueเพื่อแสดงโฆษณาสำรองในช่องที่ไม่ได้แสดงโฆษณาโดยอัตโนมัติfalseเพื่อปล่อยให้ช่องดังกล่าวไม่มีการเปลี่ยนแปลง | 
googletag.PrivacySettingsConfig
| พร็อพเพอร์ตี้ | |
|---|---|
| child | ระบุว่าควรถือว่าหน้าเว็บเป็นเนื้อหาที่มีเด็กเป็นกลุ่มเป้าหมายหรือไม่ | 
| limited | เปิดใช้การแสดงโฆษณาในโหมดโฆษณาแบบจำกัดเพื่อช่วยให้ผู้เผยแพร่โฆษณาปฏิบัติตามกฎระเบียบได้ | 
| non | ช่วยให้การแสดงโฆษณาทำงานในโหมดโฆษณาที่ไม่ได้ปรับตามโปรไฟล์ของผู้ใช้เพื่อช่วยให้ผู้เผยแพร่โฆษณาปฏิบัติตามกฎระเบียบได้ | 
| restrict | ช่วยให้การแสดงโฆษณาทํางานในโหมดการประมวลผลแบบจํากัดเพื่อช่วยให้ผู้เผยแพร่โฆษณาปฏิบัติตามกฎระเบียบได้ | 
| traffic | ระบุว่าคำขอแสดงถึงการเข้าชมที่ซื้อมาหรือการเข้าชมจากการค้นหาทั่วไป | 
| under | ระบุว่าจะทําเครื่องหมายคําขอโฆษณาว่ามาจากผู้ใช้ที่อายุต่ำกว่าอายุที่ให้ความยินยอมได้หรือไม่ | 
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
Optional childDirectedTreatment
childDirectedTreatment?: 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, }); - 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 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, }); - 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 | ดึงและแสดงโฆษณาใหม่สำหรับช่องที่เฉพาะเจาะจงหรือทุกช่องในหน้าเว็บ | 
| remove | นำ Listener ที่ลงทะเบียนไว้ก่อนหน้านี้ออก รับค่าจาก  | 
| set | ตั้งค่าแอตทริบิวต์ AdSense ที่ใช้กับช่องโฆษณาทั้งหมดในบริการโฆษณาของผู้เผยแพร่โฆษณา | 
| set | ตั้งค่าการยกเว้นหมวดหมู่โฆษณาระดับหน้าเว็บสำหรับชื่อป้ายกำกับที่ระบุ | 
| set | เปิดและปิดใช้การจัดกึ่งกลางแนวนอนของโฆษณา | 
| set | กำหนดว่าจะบังคับให้โฆษณาทั้งหมดในหน้าเว็บแสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่ | 
| set | ส่งข้อมูลตำแหน่งจากเว็บไซต์เพื่อให้คุณกำหนดเป้าหมายตามภูมิศาสตร์ของรายการโฆษณาไปยังสถานที่ตั้งที่เฉพาะเจาะจงได้ | 
| set | อนุญาตให้กำหนดค่าการตั้งค่าความเป็นส่วนตัวทั้งหมดจาก API เดียวโดยใช้ออบเจ็กต์การกำหนดค่า | 
| set | ตั้งค่ารหัสที่ผู้เผยแพร่โฆษณามีให้ | 
| set | ตั้งค่ากำหนดระดับหน้าสำหรับการกำหนดค่า SafeFrame | 
| set | ตั้งค่าพารามิเตอร์การกำหนดเป้าหมายที่กำหนดเองสำหรับคีย์ที่ระบุซึ่งใช้กับช่องโฆษณาทั้งหมดของบริการโฆษณาของผู้เผยแพร่โฆษณา | 
| set | ตั้งค่าข้อมูลเนื้อหาวิดีโอที่จะส่งพร้อมกับคำขอโฆษณาเพื่อวัตถุประสงค์ในการกำหนดเป้าหมายและการยกเว้นเนื้อหา | 
| update | เปลี่ยนสหสัมพันธ์ที่ส่งพร้อมกับคำขอโฆษณา ซึ่งเป็นการเริ่มการดูหน้าเว็บครั้งใหม่ | 
เมธอด
ล้าง
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(); - JavaScript (เดิม)- var slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1"); googletag.display("div-1"); var slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2"); googletag.display("div-2"); // This call to clear only slot1. googletag.pubads().clear([slot1]); // This call to clear both slot1 and slot2. googletag.pubads().clear([slot1, slot2]); // This call to clear all slots. googletag.pubads().clear(); - TypeScript- const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!; googletag.display("div-1"); const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!; googletag.display("div-2"); // This call to clear only slot1. googletag.pubads().clear([slot1]); // This call to clear both slot1 and slot2. googletag.pubads().clear([slot1, slot2]); // This call to clear all slots. googletag.pubads().clear(); 
| พารามิเตอร์ | |
|---|---|
|  | อาร์เรย์ของช่องที่จะล้าง อาร์เรย์เป็นพารามิเตอร์ที่ไม่บังคับ ระบบจะล้างช่องทั้งหมดหากไม่ได้ระบุ | 
| การคืนสินค้า | |
|---|---|
| boolean | แสดงผล trueหากช่องได้รับการล้างแล้ว หรือfalseในกรณีอื่นๆ | 
clearCategoryExclusions
clearCategoryExclusions(): PubAdsService- ตัวอย่าง
- JavaScript- // Set category exclusion to exclude ads with 'AirlineAd' labels. googletag.pubads().setCategoryExclusion("AirlineAd"); // Make ad requests. No ad with 'AirlineAd' label will be returned. // Clear category exclusions so all ads can be returned. googletag.pubads().clearCategoryExclusions(); // Make ad requests. Any ad can be returned. - JavaScript (เดิม)- // Set category exclusion to exclude ads with 'AirlineAd' labels. googletag.pubads().setCategoryExclusion("AirlineAd"); // Make ad requests. No ad with 'AirlineAd' label will be returned. // Clear category exclusions so all ads can be returned. googletag.pubads().clearCategoryExclusions(); // Make ad requests. Any ad can be returned. - TypeScript- // Set category exclusion to exclude ads with 'AirlineAd' labels. googletag.pubads().setCategoryExclusion("AirlineAd"); // Make ad requests. No ad with 'AirlineAd' label will be returned. // Clear category exclusions so all ads can be returned. googletag.pubads().clearCategoryExclusions(); // Make ad requests. Any ad can be returned. 
- ดูเพิ่มเติม
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้เมธอด | 
clearTargeting
clearTargeting(key?: string): PubAdsService- ตัวอย่าง
- JavaScript- googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().setTargeting("fruits", "apple"); googletag.pubads().clearTargeting("interests"); // Targeting 'colors' and 'fruits' are still present, while 'interests' // was cleared. googletag.pubads().clearTargeting(); // All targeting has been cleared. - JavaScript (เดิม)- googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().setTargeting("fruits", "apple"); googletag.pubads().clearTargeting("interests"); // Targeting 'colors' and 'fruits' are still present, while 'interests' // was cleared. googletag.pubads().clearTargeting(); // All targeting has been cleared. - TypeScript- googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().setTargeting("fruits", "apple"); googletag.pubads().clearTargeting("interests"); // Targeting 'colors' and 'fruits' are still present, while 'interests' // was cleared. googletag.pubads().clearTargeting(); // All targeting has been cleared. 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
|  | คีย์พารามิเตอร์การกำหนดเป้าหมาย คีย์เป็นตัวเลือก หากไม่ได้ระบุ ระบบจะล้างพารามิเตอร์การกำหนดเป้าหมายทั้งหมด | 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้เมธอด | 
collapseEmptyDivs
collapseEmptyDivs(collapseBeforeAdFetch?: boolean): boolean- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
|  | ว่าจะยุบช่องแม้ก่อนที่จะดึงโฆษณาหรือไม่ พารามิเตอร์นี้ไม่บังคับ หากไม่ได้ระบุ ระบบจะใช้ falseเป็นค่าเริ่มต้น | 
| การคืนสินค้า | |
|---|---|
| boolean | ส่งคืน trueหากเปิดใช้โหมดการยุบ div และfalseหากเปิดใช้โหมดการยุบไม่ได้เนื่องจากมีการเรียกใช้เมธอดหลังจากเปิดใช้บริการ | 
disableInitialLoad
disableInitialLoad(): voidrefresh ไม่ได้- ดูเพิ่มเติม
display
display(adUnitPath: string, size: GeneralSize, div?: string | Element, clickUrl?: string): voidหมายเหตุ: เมื่อเรียกใช้วิธีนี้ ระบบจะสร้างสแนปชอตของช่องและสถานะหน้าเว็บเพื่อให้มั่นใจถึงความสอดคล้องกันเมื่อส่งคำขอโฆษณาและแสดงผลการตอบกลับ การเปลี่ยนแปลงใดๆ ที่เกิดขึ้นกับสถานะช่องหรือหน้าเว็บหลังจากเรียกใช้เมธอดนี้ (รวมถึงการกำหนดเป้าหมาย การตั้งค่าความเป็นส่วนตัว บังคับใช้ SafeFrame ฯลฯ) จะมีผลกับการขอ
display() หรือ refresh() ในภายหลังเท่านั้น- ตัวอย่าง
- JavaScript- googletag.pubads().display("/1234567/sports", [728, 90], "div-1"); - JavaScript (เดิม)- googletag.pubads().display("/1234567/sports", [728, 90], "div-1"); - TypeScript- googletag.pubads().display("/1234567/sports", [728, 90], "div-1"); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| adUnitPath: string | เส้นทางหน่วยโฆษณาของช่องที่จะแสดง | 
| size: GeneralSize | ความกว้างและความสูงของช่อง | 
|  | รหัสของ div ที่มีช่องหรือองค์ประกอบ div เอง | 
|  | URL การคลิกที่จะใช้ในช่องนี้ | 
enableLazyLoad
enableLazyLoad(config?: { 
  fetchMarginPercent?: number; 
  mobileScaling?: number; 
  renderMarginPercent?: number; 
}): voidหมายเหตุ: การดึงข้อมูลแบบ Lazy Loading ใน SRA จะใช้ได้ก็ต่อเมื่อช่องทั้งหมดอยู่นอกขอบเขตการดึงข้อมูล
- ตัวอย่าง
- JavaScript- googletag.pubads().enableLazyLoad({ // Fetch slots within 5 viewports. fetchMarginPercent: 500, // Render slots within 2 viewports. renderMarginPercent: 200, // Double the above values on mobile. mobileScaling: 2.0, }); - JavaScript (เดิม)- googletag.pubads().enableLazyLoad({ // Fetch slots within 5 viewports. fetchMarginPercent: 500, // Render slots within 2 viewports. renderMarginPercent: 200, // Double the above values on mobile. mobileScaling: 2.0, }); - TypeScript- googletag.pubads().enableLazyLoad({ // Fetch slots within 5 viewports. fetchMarginPercent: 500, // Render slots within 2 viewports. renderMarginPercent: 200, // Double the above values on mobile. mobileScaling: 2.0, }); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
|  | ออบเจ็กต์การกำหนดค่าช่วยให้ปรับแต่งลักษณะการทำงานแบบเลซีได้ การกำหนดค่าที่ละเว้นจะใช้ค่าเริ่มต้นที่ Google ตั้งไว้ ซึ่งจะได้รับการปรับแต่งเมื่อเวลาผ่านไป หากต้องการปิดใช้การตั้งค่าใดการตั้งค่าหนึ่ง เช่น ระยะขอบการดึงข้อมูล ให้ตั้งค่าเป็น -1
 | 
enableSingleRequest
enableSingleRequest(): boolean- ดูเพิ่มเติม
| การคืนสินค้า | |
|---|---|
| boolean | แสดงผล trueหากเปิดใช้โหมดคำขอรวมครั้งเดียว และfalseหากเปิดใช้โหมดคำขอรวมครั้งเดียวไม่ได้เนื่องจากมีการเรียกใช้เมธอดหลังจากเปิดใช้บริการแล้ว | 
enableVideoAds
enableVideoAds(): voidget
get(key: string): string- ตัวอย่าง
- JavaScript- googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().get("adsense_background_color"); // Returns '#FFFFFF'. - JavaScript (เดิม)- googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().get("adsense_background_color"); // Returns '#FFFFFF'. - TypeScript- googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().get("adsense_background_color"); // Returns '#FFFFFF'. 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| key: string | ชื่อของแอตทริบิวต์ที่จะค้นหา | 
| การคืนสินค้า | |
|---|---|
| string | ค่าปัจจุบันสำหรับคีย์แอตทริบิวต์ หรือ nullหากไม่มีคีย์ | 
getAttributeKeys
getAttributeKeys(): string[]- ตัวอย่าง
- JavaScript- googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().set("adsense_border_color", "#AABBCC"); googletag.pubads().getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color']. - JavaScript (เดิม)- googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().set("adsense_border_color", "#AABBCC"); googletag.pubads().getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color']. - TypeScript- googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().set("adsense_border_color", "#AABBCC"); googletag.pubads().getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color']. 
| การคืนสินค้า | |
|---|---|
| string[] | อาร์เรย์ของคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในบริการนี้ ไม่ได้กำหนดการเรียงลำดับ | 
getTargeting
getTargeting(key: string): string[]- ตัวอย่าง
- JavaScript- googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().getTargeting("interests"); // Returns ['sports']. googletag.pubads().getTargeting("age"); // Returns [] (empty array). - JavaScript (เดิม)- googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().getTargeting("interests"); // Returns ['sports']. googletag.pubads().getTargeting("age"); // Returns [] (empty array). - TypeScript- googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().getTargeting("interests"); // Returns ['sports']. googletag.pubads().getTargeting("age"); // Returns [] (empty array). 
| พารามิเตอร์ | |
|---|---|
| key: string | คีย์การกำหนดเป้าหมายที่จะค้นหา | 
| การคืนสินค้า | |
|---|---|
| string[] | ค่าที่เชื่อมโยงกับคีย์นี้ หรืออาร์เรย์ว่างหากไม่มีคีย์ดังกล่าว | 
getTargetingKeys
getTargetingKeys(): string[]- ตัวอย่าง
- JavaScript- googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().getTargetingKeys(); // Returns ['interests', 'colors']. - JavaScript (เดิม)- googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().getTargetingKeys(); // Returns ['interests', 'colors']. - TypeScript- googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().getTargetingKeys(); // Returns ['interests', 'colors']. 
| การคืนสินค้า | |
|---|---|
| string[] | อาร์เรย์ของคีย์การกำหนดเป้าหมาย ไม่ได้กำหนดการเรียงลำดับ | 
isInitialLoadDisabled
isInitialLoadDisabled(): boolean| การคืนสินค้า | |
|---|---|
| boolean | แสดงผล trueหากการเรียกใช้ PubAdsService.disableInitialLoad ก่อนหน้านี้สำเร็จ หรือfalseในกรณีอื่นๆ | 
รีเฟรช
refresh(slots?: 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 }); - JavaScript (เดิม)- var slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1"); googletag.display("div-1"); var slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2"); googletag.display("div-2"); // This call to refresh fetches a new ad for slot1 only. googletag.pubads().refresh([slot1]); // This call to refresh fetches a new ad for both slot1 and slot2. googletag.pubads().refresh([slot1, slot2]); // This call to refresh fetches a new ad for each slot. googletag.pubads().refresh(); // This call to refresh fetches a new ad for slot1, without changing // the correlator. googletag.pubads().refresh([slot1], { changeCorrelator: false }); // This call to refresh fetches a new ad for each slot, without // changing the correlator. googletag.pubads().refresh(null, { changeCorrelator: false }); - TypeScript- const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!; googletag.display("div-1"); const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!; googletag.display("div-2"); // This call to refresh fetches a new ad for slot1 only. googletag.pubads().refresh([slot1]); // This call to refresh fetches a new ad for both slot1 and slot2. googletag.pubads().refresh([slot1, slot2]); // This call to refresh fetches a new ad for each slot. googletag.pubads().refresh(); // This call to refresh fetches a new ad for slot1, without changing // the correlator. googletag.pubads().refresh([slot1], { changeCorrelator: false }); // This call to refresh fetches a new ad for each slot, without // changing the correlator. googletag.pubads().refresh(null, { changeCorrelator: false }); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
|  | ช่องที่จะรีเฟรช อาร์เรย์เป็นตัวเลือก ไม่บังคับ หากไม่ได้ระบุ ระบบจะรีเฟรชช่องทั้งหมด | 
|  | ตัวเลือกการกำหนดค่าที่เชื่อมโยงกับการเรียกการรีเฟรชนี้ 
 | 
ตั้งค่า
set(key: string, value: string): PubAdsServiceการเรียกใช้ฟังก์ชันนี้มากกว่า 1 ครั้งสำหรับคีย์เดียวกันจะลบล้างค่าที่ตั้งไว้ก่อนหน้านี้สำหรับคีย์นั้น ต้องตั้งค่าทั้งหมดก่อนเรียกใช้
display หรือ refresh- ตัวอย่าง
- JavaScript- googletag.pubads().set("adsense_background_color", "#FFFFFF"); - JavaScript (เดิม)- googletag.pubads().set("adsense_background_color", "#FFFFFF"); - TypeScript- googletag.pubads().set("adsense_background_color", "#FFFFFF"); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| key: string | ชื่อของแอตทริบิวต์ | 
| value: string | ค่าแอตทริบิวต์ | 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้เมธอด | 
setCategoryExclusion
setCategoryExclusion(categoryExclusion: string): PubAdsService- ตัวอย่าง
- JavaScript- // Label = AirlineAd. googletag.pubads().setCategoryExclusion("AirlineAd"); - JavaScript (เดิม)- // Label = AirlineAd. googletag.pubads().setCategoryExclusion("AirlineAd"); - TypeScript- // Label = AirlineAd. googletag.pubads().setCategoryExclusion("AirlineAd"); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| categoryExclusion: string | ป้ายกำกับการยกเว้นหมวดหมู่โฆษณาที่จะเพิ่ม | 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้เมธอด | 
setCentering
setCentering(centerAds: boolean): voidควรอัญเชิญเมธอดนี้ก่อนเรียกใช้
display หรือ refresh เนื่องจากจะมีเพียงโฆษณาที่ขอหลังจากเรียกใช้เมธอดนี้เท่านั้นที่จะจัดกึ่งกลาง- ตัวอย่าง
- JavaScript- // Make ads centered. googletag.pubads().setCentering(true); - JavaScript (เดิม)- // Make ads centered. googletag.pubads().setCentering(true); - TypeScript- // Make ads centered. googletag.pubads().setCentering(true); 
| พารามิเตอร์ | |
|---|---|
| centerAds: boolean | trueเพื่อจัดโฆษณาไว้ตรงกลางfalseเพื่อจัดโฆษณาไว้ทางซ้าย | 
setForceSafeFrame
setForceSafeFrame(forceSafeFrame: boolean): PubAdsServiceโปรดคำนึงถึงสิ่งต่อไปนี้ขณะใช้ API นี้
- การตั้งค่านี้จะมีผลกับคำขอโฆษณาในภายหลังที่ส่งสำหรับช่องที่เกี่ยวข้องเท่านั้น
- การตั้งค่าระดับช่องโฆษณาจะลบล้างการตั้งค่าระดับหน้าเว็บเสมอ หากมีการระบุ
- หากตั้งค่าเป็น true(ที่ระดับช่องหรือระดับหน้า) โฆษณาจะแสดงผลโดยใช้คอนเทนเนอร์ SafeFrame เสมอโดยไม่ขึ้นอยู่กับการเลือกที่ทำใน UI ของ Google Ad Manager
- อย่างไรก็ตาม หากตั้งค่าเป็น falseหรือไม่ได้ระบุ ระบบจะแสดงโฆษณาโดยใช้คอนเทนเนอร์ SafeFrame ขึ้นอยู่กับประเภทครีเอทีฟโฆษณาและการเลือกที่ทำใน UI ของ Google Ad Manager
- คุณควรใช้ API นี้ด้วยความระมัดระวัง เนื่องจากอาจส่งผลต่อลักษณะการทำงานของครีเอทีฟโฆษณาที่พยายามออกจาก iframe หรืออาศัยการแสดงผลในหน้าผู้เผยแพร่โฆษณาโดยตรง
- ตัวอย่าง
- JavaScript- googletag.pubads().setForceSafeFrame(true); // The following slot will be opted-out of the page-level force // SafeFrame instruction. googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setForceSafeFrame(false) .addService(googletag.pubads()); // The following slot will have SafeFrame forced. googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2"); - JavaScript (เดิม)- googletag.pubads().setForceSafeFrame(true); // The following slot will be opted-out of the page-level force // SafeFrame instruction. googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setForceSafeFrame(false) .addService(googletag.pubads()); // The following slot will have SafeFrame forced. googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2"); - TypeScript- googletag.pubads().setForceSafeFrame(true); // The following slot will be opted-out of the page-level force // SafeFrame instruction. googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setForceSafeFrame(false) .addService(googletag.pubads()); // The following slot will have SafeFrame forced. googletag.defineSlot("/1234567/news", [160, 600], "div-2")!.addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2"); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| forceSafeFrame: boolean | trueเพื่อบังคับให้แสดงโฆษณาทั้งหมดในหน้าเว็บใน SafeFrame และfalseเพื่อเปลี่ยนการตั้งค่าก่อนหน้าเป็น false การตั้งค่านี้เป็นfalseเมื่อไม่ได้ระบุไว้ก่อนหน้านี้จะไม่เปลี่ยนแปลงสิ่งใด | 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้ฟังก์ชัน | 
setLocation
setLocation(address: string): PubAdsService- ตัวอย่าง
- JavaScript- // Postal code: googletag.pubads().setLocation("10001,US"); - JavaScript (เดิม)- // Postal code: googletag.pubads().setLocation("10001,US"); - TypeScript- // Postal code: googletag.pubads().setLocation("10001,US"); 
| พารามิเตอร์ | |
|---|---|
| address: string | ที่อยู่รูปแบบอิสระ | 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้เมธอด | 
setPrivacySettings
setPrivacySettings(privacySettings: PrivacySettingsConfig): PubAdsService- ตัวอย่าง
- JavaScript- googletag.pubads().setPrivacySettings({ restrictDataProcessing: true, }); // Set multiple privacy settings at the same time. googletag.pubads().setPrivacySettings({ childDirectedTreatment: true, underAgeOfConsent: true, }); // Clear the configuration for childDirectedTreatment. googletag.pubads().setPrivacySettings({ childDirectedTreatment: null, }); - JavaScript (เดิม)- googletag.pubads().setPrivacySettings({ restrictDataProcessing: true, }); // Set multiple privacy settings at the same time. googletag.pubads().setPrivacySettings({ childDirectedTreatment: true, underAgeOfConsent: true, }); // Clear the configuration for childDirectedTreatment. googletag.pubads().setPrivacySettings({ childDirectedTreatment: null, }); - TypeScript- googletag.pubads().setPrivacySettings({ restrictDataProcessing: true, }); // Set multiple privacy settings at the same time. googletag.pubads().setPrivacySettings({ childDirectedTreatment: true, underAgeOfConsent: true, }); // Clear the configuration for childDirectedTreatment. googletag.pubads().setPrivacySettings({ childDirectedTreatment: null, }); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| privacySettings: PrivacySettingsConfig | ออบเจ็กต์ที่มีการกำหนดค่าการตั้งค่าความเป็นส่วนตัว | 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้ฟังก์ชัน | 
setPublisherProvidedId
setPublisherProvidedId(ppid: string): PubAdsService- ตัวอย่าง
- JavaScript- googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337"); - JavaScript (เดิม)- googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337"); - TypeScript- googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337"); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| ppid: string | รหัสตัวอักษรผสมตัวเลขที่ผู้เผยแพร่โฆษณามีให้ ต้องมีความยาวระหว่าง 32 ถึง 150 อักขระ | 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้เมธอด | 
setSafeFrameConfig
setSafeFrameConfig(config: SafeFrameConfig): PubAdsServiceค่ากำหนดระดับหน้านี้จะถูกลบล้างโดยค่ากำหนดระดับช่อง หากมีการระบุ
- ตัวอย่าง
- JavaScript- googletag.pubads().setForceSafeFrame(true); const pageConfig = { allowOverlayExpansion: true, allowPushExpansion: true, sandbox: true, }; const slotConfig = { allowOverlayExpansion: false }; googletag.pubads().setSafeFrameConfig(pageConfig); // The following slot will not allow for expansion by overlay. googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setSafeFrameConfig(slotConfig) .addService(googletag.pubads()); // The following slot will inherit the page level settings, and hence // would allow for expansion by overlay. googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2"); - JavaScript (เดิม)- googletag.pubads().setForceSafeFrame(true); var pageConfig = { allowOverlayExpansion: true, allowPushExpansion: true, sandbox: true, }; var slotConfig = { allowOverlayExpansion: false }; googletag.pubads().setSafeFrameConfig(pageConfig); // The following slot will not allow for expansion by overlay. googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setSafeFrameConfig(slotConfig) .addService(googletag.pubads()); // The following slot will inherit the page level settings, and hence // would allow for expansion by overlay. googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2"); - TypeScript- googletag.pubads().setForceSafeFrame(true); const pageConfig = { allowOverlayExpansion: true, allowPushExpansion: true, sandbox: true, }; const slotConfig = { allowOverlayExpansion: false }; googletag.pubads().setSafeFrameConfig(pageConfig); // The following slot will not allow for expansion by overlay. googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setSafeFrameConfig(slotConfig) .addService(googletag.pubads()); // The following slot will inherit the page level settings, and hence // would allow for expansion by overlay. googletag.defineSlot("/1234567/news", [160, 600], "div-2")!.addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2"); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| config: SafeFrameConfig | ออบเจ็กต์การกำหนดค่า | 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้เมธอด | 
setTargeting
setTargeting(key: string, value: string | string[]): PubAdsService- ตัวอย่าง
- JavaScript- // Example with a single value for a key. googletag.pubads().setTargeting("interests", "sports"); // Example with multiple values for a key inside in an array. googletag.pubads().setTargeting("interests", ["sports", "music"]); - JavaScript (เดิม)- // Example with a single value for a key. googletag.pubads().setTargeting("interests", "sports"); // Example with multiple values for a key inside in an array. googletag.pubads().setTargeting("interests", ["sports", "music"]); - TypeScript- // Example with a single value for a key. googletag.pubads().setTargeting("interests", "sports"); // Example with multiple values for a key inside in an array. googletag.pubads().setTargeting("interests", ["sports", "music"]); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| key: string | คีย์พารามิเตอร์การกำหนดเป้าหมาย | 
| value: string | string[] | ค่าพารามิเตอร์การกำหนดเป้าหมายหรืออาร์เรย์ของค่า | 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้เมธอด | 
setVideoContent
setVideoContent(videoContentId: string, videoCmsId: string): 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. - JavaScript (เดิม)- // Assume that the correlator is currently 12345. All ad requests made // by this page will currently use that value. // Replace the current correlator with a new correlator. googletag.pubads().updateCorrelator(); // The correlator will now be a new randomly selected value, different // from 12345. All subsequent ad requests made by this page will use // the new value. - TypeScript- // Assume that the correlator is currently 12345. All ad requests made // by this page will currently use that value. // Replace the current correlator with a new correlator. googletag.pubads().updateCorrelator(); // The correlator will now be a new randomly selected value, different // from 12345. All subsequent ad requests made by this page will use // the new value. 
| การคืนสินค้า | |
|---|---|
| PubAdsService | ออบเจ็กต์บริการที่เรียกใช้ฟังก์ชัน | 
googletag.ResponseInformation
| พร็อพเพอร์ตี้ | |
|---|---|
| advertiser | รหัสของผู้ลงโฆษณา | 
| campaign | รหัสของแคมเปญ | 
| creative | รหัสของครีเอทีฟโฆษณา | 
| creative | รหัสเทมเพลตของโฆษณา | 
| line | รหัสของสินค้าในรายการสั่งซื้อ | 
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
advertiserId
advertiserId: 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. } }); - JavaScript (เดิม)- // 1. Adding an event listener for the PubAdsService. googletag.pubads().addEventListener("slotOnload", function (event) { console.log("Slot has been loaded:"); console.log(event); }); // 2. Adding an event listener with slot specific logic. // Listeners operate at service level, which means that you cannot add // a listener for an event for a specific slot only. You can, however, // programmatically filter a listener to respond only to a certain ad // slot, using this pattern: var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotOnload", function (event) { if (event.slot === targetSlot) { // Slot specific logic. } }); - TypeScript- // 1. Adding an event listener for the PubAdsService. googletag.pubads().addEventListener("slotOnload", (event) => { console.log("Slot has been loaded:"); console.log(event); }); // 2. Adding an event listener with slot specific logic. // Listeners operate at service level, which means that you cannot add // a listener for an event for a specific slot only. You can, however, // programmatically filter a listener to respond only to a certain ad // slot, using this pattern: const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotOnload", (event) => { if (event.slot === targetSlot) { // Slot specific logic. } }); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| eventType: K | สตริงที่แสดงประเภทของเหตุการณ์ที่ GPT สร้างขึ้น ประเภทเหตุการณ์คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่ | 
| listener: ((arg: EventTypeMap[K]) => void) | ฟังก์ชันที่ใช้อาร์กิวเมนต์ออบเจ็กต์เหตุการณ์เดียว | 
| การคืนสินค้า | |
|---|---|
| Service | ออบเจ็กต์บริการที่เรียกใช้เมธอด | 
getSlots
removeEventListener
removeEventListener<K extends keyof EventTypeMap>(eventType: K, listener: ((event: EventTypeMap[K]) => void)): void- ตัวอย่าง
- JavaScript- googletag.cmd.push(() => { // Define a new ad slot. googletag.defineSlot("/6355419/Travel", [728, 90], "div-for-slot").addService(googletag.pubads()); // Define a new function that removes itself via removeEventListener // after the impressionViewable event fires. const onViewableListener = (event) => { googletag.pubads().removeEventListener("impressionViewable", onViewableListener); setTimeout(() => { googletag.pubads().refresh([event.slot]); }, 30000); }; // Add onViewableListener as a listener for impressionViewable events. googletag.pubads().addEventListener("impressionViewable", onViewableListener); googletag.enableServices(); }); - JavaScript (เดิม)- googletag.cmd.push(function () { // Define a new ad slot. googletag.defineSlot("/6355419/Travel", [728, 90], "div-for-slot").addService(googletag.pubads()); // Define a new function that removes itself via removeEventListener // after the impressionViewable event fires. var onViewableListener = function (event) { googletag.pubads().removeEventListener("impressionViewable", onViewableListener); setTimeout(function () { googletag.pubads().refresh([event.slot]); }, 30000); }; // Add onViewableListener as a listener for impressionViewable events. googletag.pubads().addEventListener("impressionViewable", onViewableListener); googletag.enableServices(); }); - TypeScript- googletag.cmd.push(() => { // Define a new ad slot. googletag .defineSlot("/6355419/Travel", [728, 90], "div-for-slot")! .addService(googletag.pubads()); // Define a new function that removes itself via removeEventListener // after the impressionViewable event fires. const onViewableListener = (event: googletag.events.ImpressionViewableEvent) => { googletag.pubads().removeEventListener("impressionViewable", onViewableListener); setTimeout(() => { googletag.pubads().refresh([event.slot]); }, 30000); }; // Add onViewableListener as a listener for impressionViewable events. googletag.pubads().addEventListener("impressionViewable", onViewableListener); googletag.enableServices(); }); 
| พารามิเตอร์ | |
|---|---|
| eventType: K | สตริงที่แสดงประเภทของเหตุการณ์ที่ GPT สร้างขึ้น ประเภทเหตุการณ์คำนึงถึงตัวพิมพ์เล็กและตัวพิมพ์ใหญ่ | 
| listener: ((event: EventTypeMap[K]) => void) | ฟังก์ชันที่ใช้อาร์กิวเมนต์ออบเจ็กต์เหตุการณ์เดียว | 
googletag.SizeMappingBuilder
| เมธอด | |
|---|---|
| add | เพิ่มการแมปจากอาร์เรย์ขนาดเดียว (แสดงถึงวิวพอร์ต) ไปยังอาร์เรย์ขนาดเดียวหรือหลายขนาดที่แสดงถึงช่อง | 
| build | สร้างข้อกำหนดแผนที่ขนาดจากการแมปที่เพิ่มลงในเครื่องมือสร้างนี้ | 
เมธอด
addSize
addSize(viewportSize: SingleSizeArray, slotSize: GeneralSize): SizeMappingBuilder- ตัวอย่าง
- JavaScript- // Mapping 1 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], [728, 90]) .addSize([640, 480], "fluid") .addSize([0, 0], [88, 31]) // All viewports < 640x480 .build(); // Mapping 2 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], []) .addSize([640, 480], [120, 60]) .addSize([0, 0], []) .build(); // Mapping 2 will not show any ads for the following viewport sizes: // [1024, 768] > size >= [980, 690] and // [640, 480] > size >= [0, 0] - JavaScript (เดิม)- // Mapping 1 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], [728, 90]) .addSize([640, 480], "fluid") .addSize([0, 0], [88, 31]) // All viewports < 640x480 .build(); // Mapping 2 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], []) .addSize([640, 480], [120, 60]) .addSize([0, 0], []) .build(); // Mapping 2 will not show any ads for the following viewport sizes: // [1024, 768] > size >= [980, 690] and // [640, 480] > size >= [0, 0] - TypeScript- // Mapping 1 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], [728, 90]) .addSize([640, 480], "fluid") .addSize([0, 0], [88, 31]) // All viewports < 640x480 .build(); // Mapping 2 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], []) .addSize([640, 480], [120, 60]) .addSize([0, 0], []) .build(); // Mapping 2 will not show any ads for the following viewport sizes: // [1024, 768] > size >= [980, 690] and // [640, 480] > size >= [0, 0] 
| พารามิเตอร์ | |
|---|---|
| viewportSize: SingleSizeArray | ขนาดของวิวพอร์ตสำหรับรายการการแมปนี้ | 
| slotSize: GeneralSize | ขนาดของช่องสำหรับรายการการแมปนี้ | 
| การคืนสินค้า | |
|---|---|
| SizeMappingBuilder | การอ้างอิงถึงเครื่องมือสร้างนี้ | 
สร้าง
build(): SizeMappingArrayหากมีการระบุการแมปที่ไม่ถูกต้อง วิธีนี้จะแสดงผล
null ไม่เช่นนั้น จะแสดงข้อกำหนดในรูปแบบที่ถูกต้องเพื่อส่งไปยัง Slot.defineSizeMappingหมายเหตุ: ระบบจะไม่กำหนดลักษณะการทำงานของเครื่องมือสร้างหลังจากเรียกใช้เมธอดนี้
| การคืนสินค้า | |
|---|---|
| SizeMappingArray | ผลลัพธ์ที่สร้างโดยเครื่องมือสร้างนี้ อาจเป็น Null หากมีการระบุการแมปขนาดที่ไม่ถูกต้อง | 
googletag.Slot
| เมธอด | |
|---|---|
| add | เพิ่มบริการลงในช่องนี้ | 
| clear | ล้างป้ายกำกับการยกเว้นหมวดหมู่โฆษณาระดับช่องทั้งหมดสำหรับช่องนี้ | 
| clear | ล้างพารามิเตอร์การกำหนดเป้าหมายระดับช่องที่กำหนดเองทั้งหมดหรือบางรายการสำหรับช่องนี้ | 
| define | ตั้งค่าอาร์เรย์ของการแมปจากขนาดวิวพอร์ตขั้นต่ำไปยังขนาดช่องโฆษณาสำหรับช่องโฆษณานี้ | 
| get | แสดงค่าสำหรับแอตทริบิวต์ AdSense ที่เชื่อมโยงกับคีย์ที่ระบุสำหรับช่องนี้ | 
| get | แสดงเส้นทางแบบเต็มของหน่วยโฆษณา พร้อมรหัสเครือข่ายและเส้นทางหน่วยโฆษณา | 
| get | แสดงผลรายการคีย์แอตทริบิวต์ที่ตั้งค่าไว้ในช่องนี้ | 
| get | แสดงป้ายกำกับการยกเว้นหมวดหมู่โฆษณาสำหรับช่องนี้ | 
| get | แสดงข้อมูลการตอบกลับด้วยโฆษณา | 
| get | แสดงผลรหัสของช่อง  divที่ระบุเมื่อกำหนดช่อง | 
| get | แสดงผลพารามิเตอร์การกำหนดเป้าหมายที่กำหนดเองที่เฉพาะเจาะจงซึ่งตั้งค่าไว้ในช่องนี้ | 
| get | แสดงรายการคีย์การกำหนดเป้าหมายที่กำหนดเองทั้งหมดที่ตั้งค่าไว้ในช่องนี้ | 
| set | ตั้งค่าแอตทริบิวต์ AdSense ในช่องโฆษณานี้ | 
| set | ตั้งค่าป้ายกำกับการยกเว้นหมวดหมู่โฆษณาระดับช่องในช่องนี้ | 
| set | ตั้งค่า URL การคลิกที่ระบบจะเปลี่ยนเส้นทางผู้ใช้ไปหลังจากคลิกโฆษณา | 
| set | ตั้งค่าว่าจะซ่อนช่อง  divหรือไม่เมื่อไม่มีโฆษณาในช่อง | 
| set | ตั้งค่าตัวเลือกการกำหนดค่าทั่วไปสำหรับช่องนี้ | 
| set | กำหนดค่าว่าจะบังคับให้โฆษณาในช่องนี้แสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่ | 
| set | ตั้งค่ากำหนดระดับช่องโฆษณาสำหรับการกำหนดค่า SafeFrame | 
| set | ตั้งค่าพารามิเตอร์การกำหนดเป้าหมายที่กำหนดเองสำหรับช่องนี้ | 
| update | ตั้งค่าพารามิเตอร์การกำหนดเป้าหมายที่กำหนดเองสำหรับช่องนี้จากแผนที่คีย์:ค่าในออบเจ็กต์ JSON | 
เมธอด
addService
addService(service: Service): Slot- ตัวอย่าง
- JavaScript- googletag.defineSlot("/1234567/sports", [160, 600], "div").addService(googletag.pubads()); - JavaScript (เดิม)- googletag.defineSlot("/1234567/sports", [160, 600], "div").addService(googletag.pubads()); - TypeScript- googletag.defineSlot("/1234567/sports", [160, 600], "div")!.addService(googletag.pubads()); 
| พารามิเตอร์ | |
|---|---|
| service: Service | บริการที่จะเพิ่ม | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
clearCategoryExclusions
clearCategoryExclusions(): Slot- ตัวอย่าง
- JavaScript- // Set category exclusion to exclude ads with 'AirlineAd' labels. const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .addService(googletag.pubads()); // Make an ad request. No ad with 'AirlineAd' label will be returned // for the slot. // Clear category exclusions so all ads can be returned. slot.clearCategoryExclusions(); // Make an ad request. Any ad can be returned for the slot. - JavaScript (เดิม)- // Set category exclusion to exclude ads with 'AirlineAd' labels. var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .addService(googletag.pubads()); // Make an ad request. No ad with 'AirlineAd' label will be returned // for the slot. // Clear category exclusions so all ads can be returned. slot.clearCategoryExclusions(); // Make an ad request. Any ad can be returned for the slot. - TypeScript- // Set category exclusion to exclude ads with 'AirlineAd' labels. const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setCategoryExclusion("AirlineAd") .addService(googletag.pubads()); // Make an ad request. No ad with 'AirlineAd' label will be returned // for the slot. // Clear category exclusions so all ads can be returned. slot.clearCategoryExclusions(); // Make an ad request. Any ad can be returned for the slot. 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
clearTargeting
clearTargeting(key?: string): Slot- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setTargeting("allow_expandable", "true") .setTargeting("interests", ["sports", "music"]) .setTargeting("color", "red") .addService(googletag.pubads()); slot.clearTargeting("color"); // Targeting 'allow_expandable' and 'interests' are still present, // while 'color' was cleared. slot.clearTargeting(); // All targeting has been cleared. - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setTargeting("allow_expandable", "true") .setTargeting("interests", ["sports", "music"]) .setTargeting("color", "red") .addService(googletag.pubads()); slot.clearTargeting("color"); // Targeting 'allow_expandable' and 'interests' are still present, // while 'color' was cleared. slot.clearTargeting(); // All targeting has been cleared. - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setTargeting("allow_expandable", "true") .setTargeting("interests", ["sports", "music"]) .setTargeting("color", "red") .addService(googletag.pubads()); slot.clearTargeting("color"); // Targeting 'allow_expandable' and 'interests' are still present, // while 'color' was cleared. slot.clearTargeting(); // All targeting has been cleared. 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
|  | คีย์พารามิเตอร์การกำหนดเป้าหมาย คีย์เป็นตัวเลือก หากไม่ได้ระบุ ระบบจะล้างพารามิเตอร์การกำหนดเป้าหมายทั้งหมด | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
defineSizeMapping
defineSizeMapping(sizeMapping: SizeMappingArray): Slot- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); const mapping = googletag .sizeMapping() .addSize([100, 100], [88, 31]) .addSize( [320, 400], [ [320, 50], [300, 50], ], ) .build(); slot.defineSizeMapping(mapping); - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); var mapping = googletag .sizeMapping() .addSize([100, 100], [88, 31]) .addSize( [320, 400], [ [320, 50], [300, 50], ], ) .build(); slot.defineSizeMapping(mapping); - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); const mapping = googletag .sizeMapping() .addSize([100, 100], [88, 31]) .addSize( [320, 400], [ [320, 50], [300, 50], ], ) .build(); slot.defineSizeMapping(mapping!); 
| พารามิเตอร์ | |
|---|---|
| sizeMapping: SizeMappingArray | อาร์เรย์ของการแมปขนาด คุณใช้ SizeMappingBuilder เพื่อสร้างได้ การแมปขนาดแต่ละรายการคืออาร์เรย์ที่มี 2 องค์ประกอบ ได้แก่ SingleSizeArray และ GeneralSize | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
get
get(key: string): string- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads()); slot.get("adsense_background_color"); // Returns '#FFFFFF'. - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads()); slot.get("adsense_background_color"); // Returns '#FFFFFF'. - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads()); slot.get("adsense_background_color"); // Returns '#FFFFFF'. 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| key: string | ชื่อของแอตทริบิวต์ที่จะค้นหา | 
| การคืนสินค้า | |
|---|---|
| string | ค่าปัจจุบันสำหรับคีย์แอตทริบิวต์ หรือ nullหากไม่มีคีย์ | 
getAdUnitPath
getAdUnitPath(): string- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getAdUnitPath(); // Returns '/1234567/sports'. - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getAdUnitPath(); // Returns '/1234567/sports'. - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); slot.getAdUnitPath(); // Returns '/1234567/sports'. 
| การคืนสินค้า | |
|---|---|
| string | เส้นทางหน่วยโฆษณา | 
getAttributeKeys
getAttributeKeys(): string[]- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .set("adsense_background_color", "#FFFFFF") .set("adsense_border_color", "#AABBCC") .addService(googletag.pubads()); slot.getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color']. - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .set("adsense_background_color", "#FFFFFF") .set("adsense_border_color", "#AABBCC") .addService(googletag.pubads()); slot.getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color']. - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .set("adsense_background_color", "#FFFFFF") .set("adsense_border_color", "#AABBCC") .addService(googletag.pubads()); slot.getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color']. 
| การคืนสินค้า | |
|---|---|
| string[] | อาร์เรย์ของคีย์แอตทริบิวต์ ไม่ได้กำหนดการเรียงลำดับ | 
getCategoryExclusions
getCategoryExclusions(): string[]- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .setCategoryExclusion("TrainAd") .addService(googletag.pubads()); slot.getCategoryExclusions(); // Returns ['AirlineAd', 'TrainAd']. - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .setCategoryExclusion("TrainAd") .addService(googletag.pubads()); slot.getCategoryExclusions(); // Returns ['AirlineAd', 'TrainAd']. - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setCategoryExclusion("AirlineAd") .setCategoryExclusion("TrainAd") .addService(googletag.pubads()); slot.getCategoryExclusions(); // Returns ['AirlineAd', 'TrainAd']. 
| การคืนสินค้า | |
|---|---|
| string[] | ป้ายกำกับการยกเว้นหมวดหมู่โฆษณาสำหรับช่องนี้ หรืออาร์เรย์ว่างหากไม่ได้ตั้งค่าไว้ | 
getResponseInformation
getResponseInformation(): ResponseInformationnull| การคืนสินค้า | |
|---|---|
| ResponseInformation | ข้อมูลการตอบกลับโฆษณาล่าสุด หรือ nullหากช่องไม่มีโฆษณา | 
getSlotElementId
getSlotElementId(): stringdiv ที่ระบุเมื่อกำหนดช่อง- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getSlotElementId(); // Returns 'div'. - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getSlotElementId(); // Returns 'div'. - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); slot.getSlotElementId(); // Returns 'div'. 
| การคืนสินค้า | |
|---|---|
| string | รหัสช่อง div | 
getTargeting
getTargeting(key: string): string[]- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setTargeting("allow_expandable", "true") .addService(googletag.pubads()); slot.getTargeting("allow_expandable"); // Returns ['true']. slot.getTargeting("age"); // Returns [] (empty array). - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setTargeting("allow_expandable", "true") .addService(googletag.pubads()); slot.getTargeting("allow_expandable"); // Returns ['true']. slot.getTargeting("age"); // Returns [] (empty array). - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setTargeting("allow_expandable", "true") .addService(googletag.pubads()); slot.getTargeting("allow_expandable"); // Returns ['true']. slot.getTargeting("age"); // Returns [] (empty array). 
| พารามิเตอร์ | |
|---|---|
| key: string | คีย์การกำหนดเป้าหมายที่จะค้นหา | 
| การคืนสินค้า | |
|---|---|
| string[] | ค่าที่เชื่อมโยงกับคีย์นี้ หรืออาร์เรย์ว่างหากไม่มีคีย์ดังกล่าว | 
getTargetingKeys
getTargetingKeys(): string[]- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setTargeting("allow_expandable", "true") .setTargeting("interests", ["sports", "music"]) .addService(googletag.pubads()); slot.getTargetingKeys(); // Returns ['interests', 'allow_expandable']. - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setTargeting("allow_expandable", "true") .setTargeting("interests", ["sports", "music"]) .addService(googletag.pubads()); slot.getTargetingKeys(); // Returns ['interests', 'allow_expandable']. - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setTargeting("allow_expandable", "true") .setTargeting("interests", ["sports", "music"]) .addService(googletag.pubads()); slot.getTargetingKeys(); // Returns ['interests', 'allow_expandable']. 
| การคืนสินค้า | |
|---|---|
| string[] | อาร์เรย์ของคีย์การกำหนดเป้าหมาย ไม่ได้กำหนดการเรียงลำดับ | 
ตั้งค่า
set(key: string, value: string): Slotการเรียกใช้เมธอดนี้มากกว่า 1 ครั้งสำหรับคีย์เดียวกันจะลบล้างค่าที่ตั้งไว้ก่อนหน้านี้สำหรับคีย์นั้น ต้องตั้งค่าทั้งหมดก่อนเรียกใช้
display หรือ refresh- ตัวอย่าง
- JavaScript- // Setting an attribute on a single ad slot. googletag .defineSlot("/1234567/sports", [160, 600], "div") .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads()); - JavaScript (เดิม)- // Setting an attribute on a single ad slot. googletag .defineSlot("/1234567/sports", [160, 600], "div") .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads()); - TypeScript- // Setting an attribute on a single ad slot. googletag .defineSlot("/1234567/sports", [160, 600], "div")! .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads()); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| key: string | ชื่อของแอตทริบิวต์ | 
| value: string | ค่าแอตทริบิวต์ | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
setCategoryExclusion
setCategoryExclusion(categoryExclusion: string): Slot- ตัวอย่าง
- JavaScript- // Label = AirlineAd googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .addService(googletag.pubads()); - JavaScript (เดิม)- // Label = AirlineAd googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .addService(googletag.pubads()); - TypeScript- // Label = AirlineAd googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setCategoryExclusion("AirlineAd") .addService(googletag.pubads()); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| categoryExclusion: string | ป้ายกำกับการยกเว้นหมวดหมู่โฆษณาที่จะเพิ่ม | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
setClickUrl
setClickUrl(value: string): Slotเซิร์ฟเวอร์ Google Ad Manager จะยังคงบันทึกการคลิกแม้ว่าจะมีการแทนที่ URL การคลิกก็ตาม ระบบจะต่อท้าย URL ของหน้า Landing Page ที่เชื่อมโยงกับครีเอทีฟโฆษณาที่แสดงกับค่าที่ระบุ การเรียกใช้ครั้งต่อๆ ไปจะเขียนทับค่า วิธีนี้ใช้ได้กับคำขอที่ไม่ใช่ SRA เท่านั้น
- ตัวอย่าง
- JavaScript- googletag .defineSlot("/1234567/sports", [160, 600], "div") .setClickUrl("http://www.example.com?original_click_url=") .addService(googletag.pubads()); - JavaScript (เดิม)- googletag .defineSlot("/1234567/sports", [160, 600], "div") .setClickUrl("http://www.example.com?original_click_url=") .addService(googletag.pubads()); - TypeScript- googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setClickUrl("http://www.example.com?original_click_url=") .addService(googletag.pubads()); 
| พารามิเตอร์ | |
|---|---|
| value: string | URL การคลิกที่จะตั้งค่า | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
setCollapseEmptyDiv
setCollapseEmptyDiv(collapse: boolean, collapseBeforeAdFetch?: boolean): Slotdiv หรือไม่เมื่อไม่มีโฆษณาในช่อง ซึ่งจะลบล้างการตั้งค่าระดับบริการ- ตัวอย่าง
- JavaScript- googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setCollapseEmptyDiv(true, true) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // when the page is loaded, before ads are requested. googletag .defineSlot("/1234567/sports", [160, 600], "div-2") .setCollapseEmptyDiv(true) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // only after GPT detects that no ads are available for the slot. - JavaScript (เดิม)- googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setCollapseEmptyDiv(true, true) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // when the page is loaded, before ads are requested. googletag .defineSlot("/1234567/sports", [160, 600], "div-2") .setCollapseEmptyDiv(true) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // only after GPT detects that no ads are available for the slot. - TypeScript- googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setCollapseEmptyDiv(true, true) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // when the page is loaded, before ads are requested. googletag .defineSlot("/1234567/sports", [160, 600], "div-2")! .setCollapseEmptyDiv(true) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // only after GPT detects that no ads are available for the slot. 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| collapse: boolean | จะยุบช่องหรือไม่หากไม่มีการแสดงโฆษณา | 
|  | จะยุบช่องแม้ก่อนที่จะดึงโฆษณาหรือไม่ จะไม่สนใจหาก collapse ไม่ใช่ true | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
setConfig
setConfig(slotConfig: SlotSettingsConfig): void| พารามิเตอร์ | |
|---|---|
| slotConfig: SlotSettingsConfig | ออบเจ็กต์การกำหนดค่า | 
setForceSafeFrame
setForceSafeFrame(forceSafeFrame: boolean): Slotโปรดคำนึงถึงสิ่งต่อไปนี้ขณะใช้ API นี้
- การตั้งค่านี้จะมีผลกับคำขอโฆษณาในภายหลังที่ส่งสำหรับช่องที่เกี่ยวข้องเท่านั้น
- การตั้งค่าระดับช่องโฆษณาจะลบล้างการตั้งค่าระดับหน้าเว็บเสมอ หากมีการระบุ
- หากตั้งค่าเป็น true(ที่ระดับช่องหรือระดับหน้า) โฆษณาจะแสดงผลโดยใช้คอนเทนเนอร์ SafeFrame เสมอโดยไม่ขึ้นอยู่กับการเลือกที่ทำใน UI ของ Google Ad Manager
- อย่างไรก็ตาม หากตั้งค่าเป็น falseหรือไม่ได้ระบุ ระบบจะแสดงโฆษณาโดยใช้คอนเทนเนอร์ SafeFrame ขึ้นอยู่กับประเภทครีเอทีฟโฆษณาและการเลือกที่ทำใน UI ของ Google Ad Manager
- คุณควรใช้ API นี้ด้วยความระมัดระวัง เนื่องจากอาจส่งผลต่อลักษณะการทำงานของครีเอทีฟโฆษณาที่พยายามออกจาก iframe หรืออาศัยการแสดงผลในหน้าผู้เผยแพร่โฆษณาโดยตรง
- ตัวอย่าง
- JavaScript- googletag .defineSlot("/1234567/sports", [160, 600], "div") .setForceSafeFrame(true) .addService(googletag.pubads()); - JavaScript (เดิม)- googletag .defineSlot("/1234567/sports", [160, 600], "div") .setForceSafeFrame(true) .addService(googletag.pubads()); - TypeScript- googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setForceSafeFrame(true) .addService(googletag.pubads()); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| forceSafeFrame: boolean | trueเพื่อบังคับให้โฆษณาทั้งหมดในช่องนี้แสดงผลใน SafeFrame และfalseเพื่อเลือกไม่ใช้การตั้งค่าระดับหน้า (หากมี) การตั้งค่านี้เป็นfalseเมื่อไม่ได้ระบุที่ระดับหน้าเว็บจะไม่เปลี่ยนแปลงสิ่งใด | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
setSafeFrameConfig
setSafeFrameConfig(config: SafeFrameConfig): Slotค่ากำหนดระดับช่องเหล่านี้จะลบล้างค่ากำหนดระดับหน้าหากมีการระบุ
- ตัวอย่าง
- JavaScript- googletag.pubads().setForceSafeFrame(true); // The following slot will have a sandboxed safeframe that only // disallows top-level navigation. googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setSafeFrameConfig({ sandbox: true }) .addService(googletag.pubads()); // The following slot will inherit page-level settings. googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2"); - JavaScript (เดิม)- googletag.pubads().setForceSafeFrame(true); // The following slot will have a sandboxed safeframe that only // disallows top-level navigation. googletag .defineSlot("/1234567/sports", [160, 600], "div-1") .setSafeFrameConfig({ sandbox: true }) .addService(googletag.pubads()); // The following slot will inherit page-level settings. googletag.defineSlot("/1234567/news", [160, 600], "div-2").addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2"); - TypeScript- googletag.pubads().setForceSafeFrame(true); // The following slot will have a sandboxed safeframe that only // disallows top-level navigation. googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setSafeFrameConfig({ sandbox: true }) .addService(googletag.pubads()); // The following slot will inherit page-level settings. googletag.defineSlot("/1234567/news", [160, 600], "div-2")!.addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2"); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| config: SafeFrameConfig | ออบเจ็กต์การกำหนดค่า | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
setTargeting
setTargeting(key: string, value: string | string[]): Slot- ตัวอย่าง
- JavaScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Example with a single value for a key. slot.setTargeting("allow_expandable", "true"); // Example with multiple values for a key inside in an array. slot.setTargeting("interests", ["sports", "music"]); - JavaScript (เดิม)- var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Example with a single value for a key. slot.setTargeting("allow_expandable", "true"); // Example with multiple values for a key inside in an array. slot.setTargeting("interests", ["sports", "music"]); - TypeScript- const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Example with a single value for a key. slot.setTargeting("allow_expandable", "true"); // Example with multiple values for a key inside in an array. slot.setTargeting("interests", ["sports", "music"]); 
- ดูเพิ่มเติม
| พารามิเตอร์ | |
|---|---|
| key: string | คีย์พารามิเตอร์การกำหนดเป้าหมาย | 
| value: string | string[] | ค่าพารามิเตอร์การกำหนดเป้าหมายหรืออาร์เรย์ของค่า | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
updateTargetingFromMap
updateTargetingFromMap(map: { 
  [adUnitPath: string]: string | string[]; 
}): Slotหมายเหตุ:
- ในกรณีที่มีการเขียนทับ ระบบจะเก็บเฉพาะค่าสุดท้ายไว้
- หากค่าเป็นอาร์เรย์ ระบบจะเขียนทับค่าก่อนหน้า ไม่ใช่ผสานรวม
- ค่าที่ตั้งไว้ที่นี่จะเขียนทับพารามิเตอร์การกำหนดเป้าหมายที่ตั้งไว้ที่ระดับบริการ
- ตัวอย่าง
- JavaScript- const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div"); slot.updateTargetingFromMap({ color: "red", interests: ["sports", "music", "movies"], }); - JavaScript (เดิม)- var slot = googletag.defineSlot("/1234567/sports", [160, 600], "div"); slot.updateTargetingFromMap({ color: "red", interests: ["sports", "music", "movies"], }); - TypeScript- const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div")!; slot.updateTargetingFromMap({ color: "red", interests: ["sports", "music", "movies"], }); 
| พารามิเตอร์ | |
|---|---|
| map: {  | การกำหนดเป้าหมายคีย์พารามิเตอร์:แผนที่ค่า | 
| การคืนสินค้า | |
|---|---|
| Slot | ออบเจ็กต์ช่องที่เรียกใช้เมธอด | 
googletag.config
| อินเทอร์เฟซ | |
|---|---|
| Ad | การตั้งค่าเพื่อควบคุมการขยายโฆษณา | 
| Ad | การตั้งค่าเพื่อควบคุมลักษณะการทำงานของโฆษณา AdSense | 
| Component | ออบเจ็กต์ที่แสดงการประมูลคอมโพเนนต์เดียวในการประมูลโฆษณาในอุปกรณ์ | 
| Interstitial | ออบเจ็กต์ที่กำหนดลักษณะการทำงานของช่องโฆษณาคั่นระหว่างหน้าช่องเดียว | 
| Lazy | การตั้งค่าเพื่อควบคุมการใช้ Lazy Loading ใน GPT | 
| Page | อินเทอร์เฟซการกำหนดค่าหลักสำหรับการตั้งค่าระดับหน้า | 
| Privacy | การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา | 
| Publisher | ออบเจ็กต์การกำหนดค่าสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS) | 
| Safe | การตั้งค่าเพื่อควบคุม SafeFrame ใน GPT | 
| Slot | อินเทอร์เฟซการกำหนดค่าหลักสำหรับการตั้งค่าระดับช่อง | 
| Taxonomy | ออบเจ็กต์ที่มีค่าสำหรับ Taxonomy รายการเดียว | 
| Video | การตั้งค่าเพื่อกำหนดค่าการตั้งค่าที่เกี่ยวข้องกับโฆษณาวิดีโอ | 
| ชื่อแทนประเภท | |
|---|---|
| Interstitial | ทริกเกอร์โฆษณาคั่นระหว่างหน้าที่รองรับ | 
| Privacy | การดูแลด้านความเป็นส่วนตัวสำหรับผู้เผยแพร่โฆษณาที่รองรับ | 
| Taxonomy | การจัดหมวดหมู่ที่รองรับสำหรับสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS) | 
ชื่อแทนประเภท
InterstitialTrigger
InterstitialTrigger: "unhideWindow" | "navBar"PrivacyTreatment
PrivacyTreatment: "disablePersonalization"การจัดหมวดหมู่
Taxonomy: "IAB_AUDIENCE_1_1" | "IAB_CONTENT_2_2"googletag.config.AdExpansionConfig
| พร็อพเพอร์ตี้ | |
|---|---|
| enabled | เปิดใช้หรือปิดใช้การขยายโฆษณา | 
- ตัวอย่าง
- JavaScript- // Enable ad slot expansion across the entire page. googletag.setConfig({ adExpansion: { enabled: true }, }); - JavaScript (เดิม)- // Enable ad slot expansion across the entire page. googletag.setConfig({ adExpansion: { enabled: true }, }); - TypeScript- // Enable ad slot expansion across the entire page. googletag.setConfig({ adExpansion: { enabled: true }, }); 
พร็อพเพอร์ตี้
Optional เปิดใช้แล้ว
enabled?: 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.ComponentAuctionConfig
| พร็อพเพอร์ตี้ | |
|---|---|
| auction | ออบเจ็กต์การกำหนดค่าการประมูลสำหรับการประมูลคอมโพเนนต์นี้ | 
| config | คีย์การกำหนดค่าที่เชื่อมโยงกับการประมูลคอมโพเนนต์นี้ | 
พร็อพเพอร์ตี้
auctionConfig
auctionConfig: { 
  auctionSignals?: unknown; 
  decisionLogicURL: string; 
  interestGroupBuyers?: string[]; 
  perBuyerExperimentGroupIds?: { 
    [buyer: string]: number; 
  }; 
  perBuyerGroupLimits?: { 
    [buyer: string]: number; 
  }; 
  perBuyerSignals?: { 
    [buyer: string]: unknown; 
  }; 
  perBuyerTimeouts?: { 
    [buyer: string]: number; 
  }; 
  seller: string; 
  sellerExperimentGroupId?: number; 
  sellerSignals?: unknown; 
  sellerTimeout?: number; 
  trustedScoringSignalsURL?: string; 
}หากตั้งค่านี้เป็น
null ระบบจะลบการกำหนดค่าที่มีอยู่สำหรับ configKey ที่ระบุ- ตัวอย่าง
- JavaScript- const componentAuctionConfig = { // Seller URL should be https and the same as decisionLogicURL's origin seller: "https://testSeller.com", decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js", interestGroupBuyers: ["https://example-buyer.com"], auctionSignals: { auction_signals: "auction_signals" }, sellerSignals: { seller_signals: "seller_signals" }, perBuyerSignals: { // listed on interestGroupBuyers "https://example-buyer.com": { per_buyer_signals: "per_buyer_signals", }, }, }; const auctionSlot = googletag.defineSlot("/1234567/example", [160, 600]); // To add configKey to the component auction: auctionSlot.setConfig({ componentAuction: [ { configKey: "https://testSeller.com", auctionConfig: componentAuctionConfig, }, ], }); // To remove configKey from the component auction: auctionSlot.setConfig({ componentAuction: [ { configKey: "https://testSeller.com", auctionConfig: null, }, ], }); - JavaScript (เดิม)- var componentAuctionConfig = { // Seller URL should be https and the same as decisionLogicURL's origin seller: "https://testSeller.com", decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js", interestGroupBuyers: ["https://example-buyer.com"], auctionSignals: { auction_signals: "auction_signals" }, sellerSignals: { seller_signals: "seller_signals" }, perBuyerSignals: { // listed on interestGroupBuyers "https://example-buyer.com": { per_buyer_signals: "per_buyer_signals", }, }, }; var auctionSlot = googletag.defineSlot("/1234567/example", [160, 600]); // To add configKey to the component auction: auctionSlot.setConfig({ componentAuction: [ { configKey: "https://testSeller.com", auctionConfig: componentAuctionConfig, }, ], }); // To remove configKey from the component auction: auctionSlot.setConfig({ componentAuction: [ { configKey: "https://testSeller.com", auctionConfig: null, }, ], }); - TypeScript- const componentAuctionConfig = { // Seller URL should be https and the same as decisionLogicURL's origin seller: "https://testSeller.com", decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js", interestGroupBuyers: ["https://example-buyer.com"], auctionSignals: { auction_signals: "auction_signals" }, sellerSignals: { seller_signals: "seller_signals" }, perBuyerSignals: { // listed on interestGroupBuyers "https://example-buyer.com": { per_buyer_signals: "per_buyer_signals", }, }, }; const auctionSlot = googletag.defineSlot("/1234567/example", [160, 600])!; // To add configKey to the component auction: auctionSlot.setConfig({ componentAuction: [ { configKey: "https://testSeller.com", auctionConfig: componentAuctionConfig, }, ], }); // To remove configKey from the component auction: auctionSlot.setConfig({ componentAuction: [ { configKey: "https://testSeller.com", auctionConfig: null, }, ], }); 
configKey
configKey: stringค่านี้ต้องไม่ว่างเปล่าและควรไม่ซ้ำกัน หากออบเจ็กต์
ComponentAuctionConfig 2 รายการแชร์ค่า configKey เดียวกัน รายการที่ตั้งค่าล่าสุดจะเขียนทับการกำหนดค่าก่อนหน้าgoogletag.config.InterstitialConfig
| พร็อพเพอร์ตี้ | |
|---|---|
| require | ต้องได้รับความยินยอมเพื่อเข้าถึงพื้นที่เก็บข้อมูลในเครื่องจึงจะแสดงโฆษณาคั่นระหว่างหน้านี้ได้หรือไม่ | 
| triggers | การกำหนดค่าทริกเกอร์โฆษณาคั่นระหว่างหน้าสำหรับโฆษณาคั่นระหว่างหน้านี้ | 
พร็อพเพอร์ตี้
Optional requireStorageAccess
requireStorageAccess?: 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 }, }); - JavaScript (เดิม)- // Opt out of showing interstitials to users // without local storage consent. var interstitialSlot = googletag.defineOutOfPageSlot( "/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL, ); interstitialSlot.setConfig({ interstitial: { requireStorageAccess: true, // defaults to false }, }); - TypeScript- // Opt out of showing interstitials to users // without local storage consent. const interstitialSlot = googletag.defineOutOfPageSlot( "/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL, )!; interstitialSlot.setConfig({ interstitial: { requireStorageAccess: true, // defaults to false }, }); 
- ดูเพิ่มเติม
Optional ทริกเกอร์
triggers?: Partial<Record<InterstitialTrigger, boolean>>การตั้งค่าทริกเกอร์โฆษณาคั่นระหว่างหน้าเป็น
true จะเปิดใช้ และ false จะปิดใช้ ซึ่งจะลบล้างค่าเริ่มต้นที่กำหนดค่าไว้ใน Google Ad Manager- ตัวอย่าง
- JavaScript- // Define a GPT managed web interstitial ad slot. const interstitialSlot = googletag.defineOutOfPageSlot( "/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL, ); // Enable optional interstitial triggers. // Change this value to false to disable. const enableTriggers = true; interstitialSlot.setConfig({ interstitial: { triggers: { navBar: enableTriggers, unhideWindow: enableTriggers, }, }, }); - JavaScript (เดิม)- // Define a GPT managed web interstitial ad slot. var interstitialSlot = googletag.defineOutOfPageSlot( "/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL, ); // Enable optional interstitial triggers. // Change this value to false to disable. var enableTriggers = true; interstitialSlot.setConfig({ interstitial: { triggers: { navBar: enableTriggers, unhideWindow: enableTriggers, }, }, }); - TypeScript- // Define a GPT managed web interstitial ad slot. const interstitialSlot = googletag.defineOutOfPageSlot( "/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL, )!; // Enable optional interstitial triggers. // Change this value to false to disable. const enableTriggers = true; interstitialSlot.setConfig({ interstitial: { triggers: { navBar: enableTriggers, unhideWindow: enableTriggers, }, }, }); 
- ดูเพิ่มเติม
googletag.config.LazyLoadConfig
| พร็อพเพอร์ตี้ | |
|---|---|
| fetch | ระยะทางขั้นต่ำจากวิวพอร์ตปัจจุบันที่ช่องต้องอยู่ก่อนที่เราจะขอโฆษณา โดยแสดงเป็นเปอร์เซ็นต์ของขนาดวิวพอร์ต | 
| mobile | ตัวคูณที่ใช้กับระยะขอบในอุปกรณ์เคลื่อนที่ | 
| render | ระยะทางขั้นต่ำจากวิวพอร์ตปัจจุบันที่ช่องต้องอยู่ก่อนที่เราจะแสดงโฆษณา โดยแสดงเป็นเปอร์เซ็นต์ของขนาดวิวพอร์ต | 
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
Optional fetchMarginPercent
fetchMarginPercent?: numberการตั้งค่านี้ใช้ร่วมกับ renderMarginPercent เพื่อให้สามารถดึงข้อมูลโฆษณาล่วงหน้าได้ แต่จะรอแสดงผลและดาวน์โหลดทรัพยากรย่อยอื่นๆ ดังนั้น ค่านี้ควรมากกว่าหรือเท่ากับ renderMarginPercent เสมอ
ค่า
0 หมายถึง "เมื่อช่องเข้าสู่ Viewport" ค่า 100 หมายถึง "เมื่อโฆษณาอยู่ห่างจาก Viewport 1 ช่อง" และอื่นๆOptional mobileScaling
mobileScaling?: numberซึ่งจะช่วยให้มีระยะขอบที่แตกต่างกันในอุปกรณ์เคลื่อนที่และเดสก์ท็อป ซึ่งขนาดวิวพอร์ตและความเร็วในการเลื่อนอาจแตกต่างกัน เช่น ค่า 2.0 จะคูณขอบทั้งหมดด้วย 2 ในอุปกรณ์เคลื่อนที่ ซึ่งจะเพิ่มระยะห่างขั้นต่ำที่ช่องสามารถอยู่จากวิวพอร์ตก่อนที่จะดึงข้อมูลและแสดงผล
Optional renderMarginPercent
renderMarginPercent?: numberการตั้งค่านี้ใช้ร่วมกับ fetchMarginPercent ซึ่งช่วยให้สามารถดึงข้อมูลโฆษณาล่วงหน้าได้ แต่จะรอแสดงผลและดาวน์โหลดทรัพยากรย่อยอื่นๆ ดังนั้น ค่านี้ควรน้อยกว่าหรือเท่ากับ fetchMarginPercent เสมอ
ค่า
0 หมายถึง "เมื่อช่องเข้าสู่ Viewport" ค่า 100 หมายถึง "เมื่อโฆษณาอยู่ห่างจาก Viewport 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 | เลิกใช้งานแล้ว  | 
| category | การตั้งค่าเพื่อกำหนดค่าการยกเว้นหมวดหมู่โฆษณา | 
| centering | การตั้งค่าเพื่อควบคุมการจัดกึ่งกลางแนวนอนของโฆษณา | 
| collapse | การตั้งค่าเพื่อควบคุมลักษณะการยุบของช่องโฆษณา | 
| disable | การตั้งค่าเพื่อควบคุมเวลาที่ขอโฆษณา | 
| lazy | การตั้งค่าเพื่อควบคุมการใช้ Lazy Loading ใน GPT | 
| location | การตั้งค่าเพื่อกำหนดเป้าหมายตามภูมิศาสตร์ให้กับรายการโฆษณาตามสถานที่ตั้งทางภูมิศาสตร์ | 
| pps | การตั้งค่าเพื่อควบคุมสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS) | 
| privacy | การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา | 
| 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 }); - 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 categoryExclusion
categoryExclusion?: string[]- ตัวอย่าง
- JavaScript- // Label = AirlineAd. googletag.setConfig({ categoryExclusion: ["AirlineAd"] }); // Clearing category exclusion setting. googletag.setConfig({ categoryExclusion: null }); - 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 }); - 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?: "DISABLED" | "BEFORE_FETCH" | "ON_NO_FILL"ช่องโฆษณาที่ยุบแล้วจะไม่ใช้พื้นที่ใดๆ ในหน้า
ค่าที่รองรับ
- 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 }); - 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 }); - 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?: LazyLoadConfigLazy Loading เป็นเทคนิคในการหน่วงเวลาการขอและการแสดงผลโฆษณาจนกว่าโฆษณาจะเข้าใกล้วิวพอร์ตของผู้ใช้ ดูตัวอย่างแบบละเอียดเพิ่มเติมได้ที่ตัวอย่างการโหลดแบบ Lazy Loading
หมายเหตุ: หากเปิดใช้
singleRequest การดึงข้อมูลแบบ Lazy Fetch จะทํางานได้ก็ต่อเมื่อช่องทั้งหมดอยู่นอกขอบเขตการดึงข้อมูลการตั้งค่า 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 }); - 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 }); - 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 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 }); - 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 }); - 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 } }); - 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 }); - 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", }, }); - 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"] }, }); - 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' }, }, }); - JavaScript (เดิม)- googletag.setConfig({ pps: { taxonomies: { IAB_AUDIENCE_1_1: { values: ["6", "626"] }, // '6' = 'Demographic | Age Range | 30-34' // '626' = 'Interest | Sports | Darts' IAB_CONTENT_2_2: { values: ["48", "127"] }, // '48' = 'Books and Literature | Fiction' // '127' = 'Careers | Job Search' }, }, }); - TypeScript- googletag.setConfig({ pps: { taxonomies: { IAB_AUDIENCE_1_1: { values: ["6", "626"] }, // '6' = 'Demographic | Age Range | 30-34' // '626' = 'Interest | Sports | Darts' IAB_CONTENT_2_2: { values: ["48", "127"] }, // '48' = 'Books and Literature | Fiction' // '127' = 'Careers | Job Search' }, }, }); 
พร็อพเพอร์ตี้
อนุกรมวิธาน
taxonomies: Partial<Record<Taxonomy, TaxonomyData>>googletag.config.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 | การตั้งค่าเพื่อกำหนดค่าลักษณะการยุบของช่องโฆษณา | 
| component | อาร์เรย์ของการประมูลคอมโพเนนต์ที่จะรวมไว้ในการประมูลโฆษณาในอุปกรณ์ | 
| 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 }); - JavaScript (เดิม)- var 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 }); - JavaScript (เดิม)- var 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, }); - JavaScript (เดิม)- var 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?: "DISABLED" | "BEFORE_FETCH" | "ON_NO_FILL"ช่องโฆษณาที่ยุบแล้วจะไม่ใช้พื้นที่ใดๆ ในหน้า
ค่าที่รองรับ
- 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, }); - JavaScript (เดิม)- var 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 componentAuction
componentAuction?: ComponentAuctionConfig[]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 }); - JavaScript (เดิม)- var 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 }); - JavaScript (เดิม)- var 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 รองรับ | 
| Traffic | แหล่งที่มาของการเข้าชมที่ GPT รองรับ | 
การแจงนับ
OutOfPageFormat
OutOfPageFormat- ดูเพิ่มเติม
| สมาชิกการแจงนับ | |
|---|---|
| BOTTOM_ | รูปแบบโฆษณา Anchor ที่ช่องโฆษณาติดอยู่กับด้านล่างของวิวพอร์ต | 
| GAME_ | รูปแบบโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกม หมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง | 
| INTERSTITIAL | รูปแบบครีเอทีฟโฆษณาคั่นระหว่างหน้าบนเว็บ | 
| LEFT_ | รูปแบบโฆษณาที่แถบข้างด้านซ้าย | 
| REWARDED | รูปแบบที่มีการให้รางวัล | 
| RIGHT_ | รูปแบบโฆษณาที่แถบข้างด้านขวา | 
| TOP_ | รูปแบบโฆษณา Anchor ที่ช่องโฆษณาติดอยู่ด้านบนของวิวพอร์ต | 
TrafficSource
TrafficSource- ดูเพิ่มเติม
| สมาชิกการแจงนับ | |
|---|---|
| ORGANIC | การป้อน URL โดยตรง การค้นหาเว็บไซต์ หรือการดาวน์โหลดแอป | 
| PURCHASED | การเข้าชมที่เปลี่ยนเส้นทางจากพร็อพเพอร์ตี้นอกเหนือจากที่เป็นเจ้าของ (ได้มาหรือกิจกรรมที่จูงใจ) | 
googletag.events
| อินเทอร์เฟซ | |
|---|---|
| Event | อินเทอร์เฟซพื้นฐานสำหรับเหตุการณ์ GPT ทั้งหมด | 
| Event | นี่คือประเภทเสมือนที่แมปชื่อเหตุการณ์กับประเภทออบเจ็กต์เหตุการณ์ที่เกี่ยวข้องสำหรับ Service.addEventListener และ Service.removeEventListener | 
| Game | เหตุการณ์นี้จะเริ่มทำงานเมื่อผู้ใช้ปิดช่องโฆษณาคั่นระหว่างหน้าแบบเกมที่ต้องดำเนินการด้วยตนเอง | 
| Game | เหตุการณ์นี้จะเริ่มทำงานเมื่อช่องโฆษณาคั่นระหว่างหน้าที่กำหนดเองของเกมพร้อมที่จะแสดงต่อผู้ใช้ | 
| Impression | เหตุการณ์นี้จะเริ่มทำงานเมื่อการแสดงผลได้แสดงตามเกณฑ์ของมุมมองแอ็กทีฟ | 
| Rewarded | เหตุการณ์นี้จะเริ่มทำงานเมื่อผู้ใช้ปิดช่องโฆษณาที่มีการให้รางวัล | 
| Rewarded | ระบบจะทริกเกอร์เหตุการณ์นี้เมื่อมีการให้รางวัลสำหรับการดูโฆษณาที่มีการให้รางวัล | 
| Rewarded | เหตุการณ์นี้จะเริ่มทำงานเมื่อโฆษณาที่มีการให้รางวัลพร้อมแสดง | 
| Slot | เหตุการณ์นี้จะเริ่มทำงานเมื่อ iframe ของครีเอทีฟโฆษณาเริ่มเหตุการณ์การโหลด | 
| Slot | ระบบจะทริกเกอร์เหตุการณ์นี้เมื่อมีการแทรกโค้ดครีเอทีฟโฆษณาลงในช่อง | 
| Slot | เหตุการณ์นี้จะเริ่มทำงานเมื่อมีการขอโฆษณาสำหรับช่องโฆษณาหนึ่งๆ | 
| Slot | ระบบจะทริกเกอร์เหตุการณ์นี้เมื่อได้รับคำตอบของโฆษณาสำหรับช่องที่เฉพาะเจาะจง | 
| Slot | เหตุการณ์นี้จะเริ่มทำงานเมื่อใดก็ตามที่เปอร์เซ็นต์บนหน้าจอของพื้นที่ช่องโฆษณาเปลี่ยนแปลง | 
googletag.events.Event
| พร็อพเพอร์ตี้ | |
|---|---|
| service | ชื่อของบริการที่ทริกเกอร์เหตุการณ์ | 
| slot | ช่องที่ทริกเกอร์เหตุการณ์ | 
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
serviceName
serviceName: stringslot
slot: Slotgoogletag.events.EventTypeMap
| พร็อพเพอร์ตี้ | |
|---|---|
| game | ชื่อแทนสำหรับ events.GameManualInterstitialSlotClosedEvent | 
| game | ชื่อแทนสำหรับ events.GameManualInterstitialSlotReadyEvent | 
| impression | ชื่อแทนสำหรับ events.ImpressionViewableEvent | 
| rewarded | ชื่อแทนสำหรับ events.RewardedSlotClosedEvent | 
| rewarded | ชื่อแทนสำหรับ events.RewardedSlotGrantedEvent | 
| rewarded | นามแฝงสำหรับ events.RewardedSlotReadyEvent | 
| 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: RewardedSlotReadyEventslotOnload
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. } }); } - JavaScript (เดิม)- // This listener is called when a game manual interstitial slot is closed. var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", function (event) { var slot = event.slot; console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed."); if (slot === targetSlot) { // Slot specific logic. } }); } - TypeScript- // This listener is called when a game manual interstitial slot is closed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", (event) => { const slot = event.slot; console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed."); if (slot === targetSlot) { // Slot specific logic. } }); } 
googletag.events.GameManualInterstitialSlotReadyEvent
Eventหมายเหตุ: โฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมเป็นรูปแบบที่จำกัดการเข้าถึง
| พร็อพเพอร์ตี้ | |
|---|---|
| service | ชื่อของบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก  | 
| slot | ช่องที่ทริกเกอร์เหตุการณ์ รับค่าจาก  | 
| เมธอด | |
|---|---|
| make | แสดงโฆษณาคั่นระหว่างหน้าที่กำหนดเองในเกมต่อผู้ใช้ | 
- ตัวอย่าง
- JavaScript- // This listener is called when a game manual interstitial slot is ready to // be displayed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotReady", (event) => { const slot = event.slot; console.log( "Game manual interstital slot", slot.getSlotElementId(), "is ready to be displayed.", ); // Replace with custom logic. const displayGmiAd = true; if (displayGmiAd) { event.makeGameManualInterstitialVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); } - JavaScript (เดิม)- // This listener is called when a game manual interstitial slot is ready to // be displayed. var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotReady", function (event) { var slot = event.slot; console.log( "Game manual interstital slot", slot.getSlotElementId(), "is ready to be displayed.", ); // Replace with custom logic. var displayGmiAd = true; if (displayGmiAd) { event.makeGameManualInterstitialVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); } - TypeScript- // This listener is called when a game manual interstitial slot is ready to // be displayed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotReady", (event) => { const slot = event.slot; console.log( "Game manual interstital slot", slot.getSlotElementId(), "is ready to be displayed.", ); // Replace with custom logic. const displayGmiAd = true; if (displayGmiAd) { event.makeGameManualInterstitialVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); } 
เมธอด
makeGameManualInterstitialVisible
makeGameManualInterstitialVisible(): voidgoogletag.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. } }); - JavaScript (เดิม)- // This listener is called when an impression becomes viewable. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("impressionViewable", function (event) { var slot = event.slot; console.log("Impression for slot", slot.getSlotElementId(), "became viewable."); if (slot === targetSlot) { // Slot specific logic. } }); - TypeScript- // This listener is called when an impression becomes viewable. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("impressionViewable", (event) => { const slot = event.slot; console.log("Impression for slot", slot.getSlotElementId(), "became viewable."); if (slot === targetSlot) { // Slot specific logic. } }); 
- ดูเพิ่มเติม
googletag.events.RewardedSlotClosedEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
| service | ชื่อของบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก  | 
| slot | ช่องที่ทริกเกอร์เหตุการณ์ รับค่าจาก  | 
- ตัวอย่าง
- JavaScript- const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the user closes a rewarded ad slot. googletag.pubads().addEventListener("rewardedSlotClosed", (event) => { const slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed."); if (slot === targetSlot) { // Slot specific logic. } }); } - JavaScript (เดิม)- var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the user closes a rewarded ad slot. googletag.pubads().addEventListener("rewardedSlotClosed", function (event) { var slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed."); if (slot === targetSlot) { // Slot specific logic. } }); } - TypeScript- const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the user closes a rewarded ad slot. googletag.pubads().addEventListener("rewardedSlotClosed", (event) => { const slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed."); if (slot === targetSlot) { // Slot specific logic. } }); } 
googletag.events.RewardedSlotGrantedEvent
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. } }); } - JavaScript (เดิม)- var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotGranted", function (event) { var _a, _b; var slot = event.slot; console.group("Reward granted for slot", slot.getSlotElementId(), "."); // Log details of the reward. console.log("Reward type:", (_a = event.payload) === null || _a === void 0 ? void 0 : _a.type); console.log( "Reward amount:", (_b = event.payload) === null || _b === void 0 ? void 0 : _b.amount, ); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } }); } - TypeScript- const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotGranted", (event) => { const slot = event.slot; console.group("Reward granted for slot", slot.getSlotElementId(), "."); // Log details of the reward. console.log("Reward type:", event.payload?.type); console.log("Reward amount:", event.payload?.amount); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } }); } 
พร็อพเพอร์ตี้
เพย์โหลด
payload: 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. } }); } - JavaScript (เดิม)- // This listener is called when a rewarded ad slot becomes ready to be // displayed. var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotReady", function (event) { var slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed."); // Replace with custom logic. var userHasConsented = true; if (userHasConsented) { event.makeRewardedVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); } - TypeScript- // This listener is called when a rewarded ad slot becomes ready to be // displayed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotReady", (event) => { const slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed."); // Replace with custom logic. const userHasConsented = true; if (userHasConsented) { event.makeRewardedVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); } 
เมธอด
makeRewardedVisible
makeRewardedVisible(): voidgoogletag.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. } }); - JavaScript (เดิม)- // This listener is called when a creative iframe load event fires. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotOnload", function (event) { var slot = event.slot; console.log("Creative iframe for slot", slot.getSlotElementId(), "has loaded."); if (slot === targetSlot) { // Slot specific logic. } }); - TypeScript- // This listener is called when a creative iframe load event fires. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotOnload", (event) => { const slot = event.slot; console.log("Creative iframe for slot", slot.getSlotElementId(), "has loaded."); if (slot === targetSlot) { // Slot specific logic. } }); 
- ดูเพิ่มเติม
googletag.events.SlotRenderEndedEvent
Event| พร็อพเพอร์ตี้ | |
|---|---|
| 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. } }); - JavaScript (เดิม)- // This listener is called when a slot has finished rendering. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotRenderEnded", function (event) { var slot = event.slot; console.group("Slot", slot.getSlotElementId(), "finished rendering."); // Log details of the rendered ad. console.log("Advertiser ID:", event.advertiserId); console.log("Campaign ID:", event.campaignId); console.log("Company IDs:", event.companyIds); console.log("Creative ID:", event.creativeId); console.log("Creative Template ID:", event.creativeTemplateId); console.log("Is backfill?:", event.isBackfill); console.log("Is empty?:", event.isEmpty); console.log("Line Item ID:", event.lineItemId); console.log("Size:", event.size); console.log("Slot content changed?", event.slotContentChanged); console.log("Source Agnostic Creative ID:", event.sourceAgnosticCreativeId); console.log("Source Agnostic Line Item ID:", event.sourceAgnosticLineItemId); console.log("Yield Group IDs:", event.yieldGroupIds); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } }); - TypeScript- // This listener is called when a slot has finished rendering. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotRenderEnded", (event) => { const slot = event.slot; console.group("Slot", slot.getSlotElementId(), "finished rendering."); // Log details of the rendered ad. console.log("Advertiser ID:", event.advertiserId); console.log("Campaign ID:", event.campaignId); console.log("Company IDs:", event.companyIds); console.log("Creative ID:", event.creativeId); console.log("Creative Template ID:", event.creativeTemplateId); console.log("Is backfill?:", event.isBackfill); console.log("Is empty?:", event.isEmpty); console.log("Line Item ID:", event.lineItemId); console.log("Size:", event.size); console.log("Slot content changed?", event.slotContentChanged); console.log("Source Agnostic Creative ID:", event.sourceAgnosticCreativeId); console.log("Source Agnostic Line Item ID:", event.sourceAgnosticLineItemId); console.log("Yield Group IDs:", event.yieldGroupIds); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } }); 
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
advertiserId
advertiserId: 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 หากโฆษณาไม่ใช่การจองหรือการแสดงโฆษณาสำรองของรายการโฆษณา หรือบริการอื่นๆ นอกเหนือจาก PubAdsService เป็นผู้แสดงครีเอทีฟโฆษณาsourceAgnosticLineItemId
sourceAgnosticLineItemId: numbernull หากโฆษณาไม่ใช่การจองหรือการแสดงโฆษณาสำรองของรายการโฆษณา หรือบริการอื่นๆ นอกเหนือจาก PubAdsService เป็นผู้แสดงครีเอทีฟโฆษณาyieldGroupIds
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. } }); - JavaScript (เดิม)- // This listener is called when the specified service issues an ad // request for a slot. Each slot will fire this event, even though they // may be batched together in a single request if single request // architecture (SRA) is enabled. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotRequested", function (event) { var slot = event.slot; console.log("Slot", slot.getSlotElementId(), "has been requested."); if (slot === targetSlot) { // Slot specific logic. } }); - TypeScript- // This listener is called when the specified service issues an ad // request for a slot. Each slot will fire this event, even though they // may be batched together in a single request if single request // architecture (SRA) is enabled. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotRequested", (event) => { const slot = event.slot; console.log("Slot", slot.getSlotElementId(), "has been requested."); if (slot === targetSlot) { // Slot specific logic. } }); 
- ดูเพิ่มเติม
googletag.events.SlotResponseReceived
Event| พร็อพเพอร์ตี้ | |
|---|---|
| service | ชื่อของบริการที่ทริกเกอร์เหตุการณ์ รับค่าจาก  | 
| slot | ช่องที่ทริกเกอร์เหตุการณ์ รับค่าจาก  | 
- ตัวอย่าง
- JavaScript- // This listener is called when an ad response has been received // for a slot. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotResponseReceived", (event) => { const slot = event.slot; console.log("Ad response for slot", slot.getSlotElementId(), "received."); if (slot === targetSlot) { // Slot specific logic. } }); - JavaScript (เดิม)- // This listener is called when an ad response has been received // for a slot. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotResponseReceived", function (event) { var slot = event.slot; console.log("Ad response for slot", slot.getSlotElementId(), "received."); if (slot === targetSlot) { // Slot specific logic. } }); - TypeScript- // This listener is called when an ad response has been received // for a slot. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotResponseReceived", (event) => { const slot = event.slot; console.log("Ad response for slot", slot.getSlotElementId(), "received."); if (slot === targetSlot) { // Slot specific logic. } }); 
- ดูเพิ่มเติม
googletag.events.SlotVisibilityChangedEvent
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. } }); - JavaScript (เดิม)- // This listener is called whenever the on-screen percentage of an // ad slot's area changes. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotVisibilityChanged", function (event) { var slot = event.slot; console.group("Visibility of slot", slot.getSlotElementId(), "changed."); // Log details of the event. console.log("Visible area:", "".concat(event.inViewPercentage, "%")); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } }); - TypeScript- // This listener is called whenever the on-screen percentage of an // ad slot's area changes. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotVisibilityChanged", (event) => { const slot = event.slot; console.group("Visibility of slot", slot.getSlotElementId(), "changed."); // Log details of the event. console.log("Visible area:", `${event.inViewPercentage}%`); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } }); 
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
inViewPercentage
inViewPercentage: numbergoogletag.secureSignals
| อินเทอร์เฟซ | |
|---|---|
| Bidder | แสดงผลสัญญาณที่ปลอดภัยสำหรับผู้เสนอราคาที่เฉพาะเจาะจง | 
| Publisher | แสดงผลสัญญาณที่ปลอดภัยสำหรับผู้เผยแพร่โฆษณารายหนึ่งๆ | 
| Secure | อินเทอร์เฟซสําหรับจัดการสัญญาณที่ปลอดภัย | 
| ชื่อแทนประเภท | |
|---|---|
| Secure | อินเทอร์เฟซสําหรับการแสดงผลสัญญาณที่ปลอดภัยสําหรับผู้เสนอราคาหรือผู้ให้บริการที่เฉพาะเจาะจง | 
ชื่อแทนประเภท
SecureSignalProvider
SecureSignalProvider: BidderSignalProvider | PublisherSignalProviderid หรือ networkCode อย่างใดอย่างหนึ่ง แต่ไม่ใช่ทั้ง 2 อย่างgoogletag.secureSignals.BidderSignalProvider
ผู้ให้บริการสัญญาณที่ปลอดภัยของผู้เสนอราคาประกอบด้วย 2 ส่วน ดังนี้
- ฟังก์ชันรวบรวม ซึ่งแสดงผล Promiseที่แปลงเป็นสัญญาณที่ปลอดภัย
- idซึ่งระบุผู้เสนอราคาที่เชื่อมโยงกับสัญญาณ
| พร็อพเพอร์ตี้ | |
|---|---|
| collector | ฟังก์ชันที่แสดงผล  Promiseซึ่งจะเปลี่ยนเป็นสัญญาณที่ปลอดภัย | 
| id | ตัวระบุที่ไม่ซ้ำกันสำหรับเครื่องมือรวบรวมที่เชื่อมโยงกับสัญญาณที่ปลอดภัยนี้ตามที่ลงทะเบียนไว้ใน Google Ad Manager | 
- ตัวอย่าง
- JavaScript- // id is provided googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, }); - JavaScript (เดิม)- // id is provided googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: function () { // ...custom signal generation logic... return Promise.resolve("signal"); }, }); - TypeScript- // id is provided googletag.secureSignalProviders!.push({ id: "collector123", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, }); 
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
collectorFunction
collectorFunction: (() => Promise<string>)Promise ซึ่งจะเปลี่ยนเป็นสัญญาณที่ปลอดภัยid
id: stringgoogletag.secureSignals.PublisherSignalProvider
ผู้ให้บริการสัญญาณของผู้เผยแพร่โฆษณาประกอบด้วย 2 ส่วน ดังนี้
- ฟังก์ชันรวบรวม ซึ่งแสดงผล Promiseที่แปลงเป็นสัญญาณที่ปลอดภัย
- networkCodeซึ่งระบุผู้เผยแพร่โฆษณาที่เชื่อมโยงกับสัญญาณ
| พร็อพเพอร์ตี้ | |
|---|---|
| collector | ฟังก์ชันที่แสดงผล  Promiseซึ่งจะเปลี่ยนเป็นสัญญาณที่ปลอดภัย | 
| network | รหัสเครือข่าย (ตามที่เห็นในเส้นทางหน่วยโฆษณา) ของผู้เผยแพร่โฆษณาที่เชื่อมโยงกับสัญญาณที่ปลอดภัยนี้ | 
- ตัวอย่าง
- JavaScript- // networkCode is provided googletag.secureSignalProviders.push({ networkCode: "123456", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, }); - JavaScript (เดิม)- // networkCode is provided googletag.secureSignalProviders.push({ networkCode: "123456", collectorFunction: function () { // ...custom signal generation logic... return Promise.resolve("signal"); }, }); - TypeScript- // networkCode is provided googletag.secureSignalProviders!.push({ networkCode: "123456", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, }); 
- ดูเพิ่มเติม
พร็อพเพอร์ตี้
collectorFunction
collectorFunction: (() => Promise<string>)Promise ซึ่งจะเปลี่ยนเป็นสัญญาณที่ปลอดภัยnetworkCode
networkCode: stringgoogletag.secureSignals.SecureSignalProvidersArray
| เมธอด | |
|---|---|
| clear | ล้างสัญญาณทั้งหมดสำหรับผู้รวบรวมข้อมูลทั้งหมดจากแคช | 
| push | เพิ่ม secureSignals.SecureSignalProvider ใหม่ลงในอาร์เรย์ผู้ให้บริการสัญญาณและเริ่มกระบวนการสร้างสัญญาณ | 
เมธอด
clearAllCache
clearAllCache(): voidการเรียกใช้วิธีนี้อาจลดโอกาสที่สัญญาณจะรวมอยู่ในคำขอโฆษณาสำหรับการดูหน้าเว็บปัจจุบันและหน้าเว็บที่อาจดูในภายหลัง ดังนั้นจึงควรเรียกใช้เฉพาะเมื่อมีการเปลี่ยนแปลงสถานะที่สำคัญเท่านั้น เช่น เหตุการณ์ที่ระบุถึงผู้ใช้ใหม่ (เข้าสู่ระบบ ออกจากระบบ ลงชื่อสมัครใช้ ฯลฯ)
push
push(provider: SecureSignalProvider): void| พารามิเตอร์ | |
|---|---|
| provider: SecureSignalProvider | ออบเจ็กต์ secureSignals.SecureSignalProvider ที่จะเพิ่มลงในอาร์เรย์ |