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

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

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

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

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

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

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

googletag

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

ชื่อแทนประเภท


GeneralSize

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

MultiSize

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

NamedSize

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

SingleSize

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

SingleSizeArray

SingleSizeArray: [number, number]
อาร์เรย์ของตัวเลข 2 ตัวที่แสดง [ความกว้าง, ความสูง]

SizeMapping

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

SizeMappingArray

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

ตัวแปร


Const apiReady

apiReady: boolean | undefined
Flag indicating that the GPT API is loaded and ready to be called. พร็อพเพอร์ตี้นี้จะเป็นเพียง undefined จนกว่า API จะพร้อม

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

Const cmd

cmd: ((this: typeof globalThis) => void)[] | CommandArray
การอ้างอิงคิวคำสั่งส่วนกลางสำหรับการเรียกที่เกี่ยวข้องกับ GPT แบบอะซิงโครนัส

ไวยากรณ์แท็ก 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 | undefined
Flag ที่ระบุว่ามีการเปิดใช้ โหลด และใช้งาน PubAdsService ได้อย่างสมบูรณ์ พร็อพเพอร์ตี้นี้จะเป็น undefined จนกว่าจะมีการเรียกใช้ enableServices และโหลดและเริ่มต้น PubAdsService

secureSignalProviders

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

ฟังก์ชัน


companionAds

companionAds(): CompanionAdsService
แสดงผลการอ้างอิงไปยัง CompanionAdsService
การคืนสินค้า
CompanionAdsServiceบริการโฆษณาที่แสดงร่วม

defineOutOfPageSlot

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

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

สำหรับโฆษณาที่ไม่อยู่ในขอบเขตหน้าที่จัดการด้วย GPT div เป็น OutOfPageFormat ที่รองรับ
ตัวอย่าง

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

defineSlot

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

destroySlots

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

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

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

JavaScript

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

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

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

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

JavaScript (เดิม)

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

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

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

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

TypeScript

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

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

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

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

disablePublisherConsole

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

display

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

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

enableServices

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

getConfig

getConfig(keys: string | string[]): Pick<PageSettingsConfig, "adsenseAttributes" | "disableInitialLoad" | "targeting">
รับตัวเลือกการกำหนดค่าทั่วไปสำหรับหน้าที่ตั้งค่าโดย setConfig

วิธีนี้ไม่รองรับพร็อพเพอร์ตี้ setConfig() บางรายการ พร็อพเพอร์ตี้ที่รองรับมีดังนี้
ตัวอย่าง

JavaScript

// Get the value of the `targeting` setting.
const targetingConfig = googletag.getConfig("targeting");

// Get the value of the `adsenseAttributes` and `disableInitialLoad` settings.
const config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);

JavaScript (เดิม)

// Get the value of the `targeting` setting.
var targetingConfig = googletag.getConfig("targeting");

// Get the value of the `adsenseAttributes` and `disableInitialLoad` settings.
var config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);

TypeScript

// Get the value of the `targeting` setting.
const targetingConfig = googletag.getConfig("targeting");

// Get the value of the `adsenseAttributes` and `disableInitialLoad` settings.
const config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);
พารามิเตอร์
keys: string | string[]คีย์ของตัวเลือกการกำหนดค่าที่จะรับ
การคืนสินค้า
Pick<PageSettingsConfig, "adsenseAttributes" | "disableInitialLoad" | "targeting">ตัวเลือกการกำหนดค่าสำหรับช่อง

getVersion

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

openConsole

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

pubads

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

setAdIframeTitle

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

JavaScript

googletag.setAdIframeTitle("title");

JavaScript (เดิม)

googletag.setAdIframeTitle("title");

TypeScript

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

setConfig

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

sizeMapping

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

googletag.CommandArray

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

เมธอด


push

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

googletag.CompanionAdsService

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

เมธอด


setRefreshUnfilledSlots

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

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

JavaScript

googletag.companionAds().setRefreshUnfilledSlots(true);

JavaScript (เดิม)

googletag.companionAds().setRefreshUnfilledSlots(true);

TypeScript

googletag.companionAds().setRefreshUnfilledSlots(true);
พารามิเตอร์
value: booleantrue เพื่อแสดงโฆษณาสำรองในช่องที่ไม่ได้แสดงโฆษณาโดยอัตโนมัติ false เพื่อปล่อยให้ช่องดังกล่าวไม่มีการเปลี่ยนแปลง

googletag.PrivacySettingsConfig

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

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


Optional childDirectedTreatment

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

Optional limitedAds

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

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

Optional nonPersonalizedAds

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

Optional restrictDataProcessing

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

Optional trafficSource

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

Optional underAgeOfConsent

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

googletag.PubAdsService

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

เมธอด


ล้าง

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();
พารามิเตอร์
Optional slots: Slot[]อาร์เรย์ของช่องที่จะล้าง อาร์เรย์เป็นตัวเลือก หากไม่ได้ระบุ ระบบจะล้างช่องทั้งหมด
การคืนสินค้า
booleanแสดงผล true หากช่องได้รับการล้างแล้ว หรือ false ในกรณีอื่นๆ

clearCategoryExclusions

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

JavaScript

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

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

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

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

JavaScript (เดิม)

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

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

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

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

TypeScript

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

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

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

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

clearTargeting

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

collapseEmptyDivs

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

disableInitialLoad

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

display

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

enableLazyLoad

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

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

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

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

enableSingleRequest

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

enableVideoAds

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

get

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

getAttributeKeys

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

getTargeting

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

getTargetingKeys

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

isInitialLoadDisabled

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

รีเฟรช

refresh(slots?: 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 });
ดูเพิ่มเติม
พารามิเตอร์
Optional slots: Slot[]ช่องที่จะรีเฟรช อาร์เรย์เป็นตัวเลือก หากไม่ได้ระบุ ระบบจะรีเฟรชช่องทั้งหมด
Optional options: {
  changeCorrelator: boolean;
}
ตัวเลือกการกำหนดค่าที่เชื่อมโยงกับการเรียกการรีเฟรชนี้
  • changeCorrelator

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

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

set

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

setCategoryExclusion

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

setCentering

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

setForceSafeFrame

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

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

JavaScript

googletag.pubads().setForceSafeFrame(true);

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

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

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

JavaScript (เดิม)

googletag.pubads().setForceSafeFrame(true);

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

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

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

TypeScript

googletag.pubads().setForceSafeFrame(true);

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

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

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

setLocation

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

setPrivacySettings

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

setPublisherProvidedId

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

setSafeFrameConfig

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

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

JavaScript

googletag.pubads().setForceSafeFrame(true);

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

const slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

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

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

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

JavaScript (เดิม)

googletag.pubads().setForceSafeFrame(true);

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

var slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

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

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

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

TypeScript

googletag.pubads().setForceSafeFrame(true);

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

const slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

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

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

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

setTargeting

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

setVideoContent

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

updateCorrelator

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

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

googletag.ResponseInformation

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

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


advertiserId

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

campaignId

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

creativeId

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

creativeTemplateId

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

lineItemId

lineItemId: number
รหัสของสินค้าในรายการสั่งซื้อ

googletag.RewardedPayload

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

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


amount

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

type

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

googletag.Service

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

เมธอด


addEventListener

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

getSlots

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

removeEventListener

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

googletag.SizeMappingBuilder

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

เมธอด


addSize

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

สร้าง

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

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

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

googletag.Slot

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

เมธอด


addService

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

clearCategoryExclusions

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

JavaScript

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

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

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

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

JavaScript (เดิม)

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

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

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

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

TypeScript

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

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

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

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

clearTargeting

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

defineSizeMapping

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

JavaScript

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

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

slot.defineSizeMapping(mapping);

JavaScript (เดิม)

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

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

slot.defineSizeMapping(mapping);

TypeScript

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

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

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

get

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

getAdUnitPath

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

getAttributeKeys

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

getCategoryExclusions

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

getConfig

getConfig(keys: string | string[]): Pick<SlotSettingsConfig, "adsenseAttributes" | "targeting" | "categoryExclusion">
รับตัวเลือกการกำหนดค่าทั่วไปสำหรับช่องที่ตั้งค่าโดย setConfig

วิธีนี้ไม่รองรับพร็อพเพอร์ตี้ setConfig() บางรายการ พร็อพเพอร์ตี้ที่รองรับมีดังนี้
ตัวอย่าง

JavaScript

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

// Get the value of the `targeting` setting.
const targetingConfig = slot.getConfig("targeting");

// Get the value of the `adsenseAttributes` and `categoryExclusion` settings.
const config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);

JavaScript (เดิม)

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

// Get the value of the `targeting` setting.
var targetingConfig = slot.getConfig("targeting");

// Get the value of the `adsenseAttributes` and `categoryExclusion` settings.
var config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);

TypeScript

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

// Get the value of the `targeting` setting.
const targetingConfig = slot.getConfig("targeting");

// Get the value of the `adsenseAttributes` and `categoryExclusion` settings.
const config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);
พารามิเตอร์
keys: string | string[]คีย์ของตัวเลือกการกำหนดค่าที่จะรับ
การคืนสินค้า
Pick<SlotSettingsConfig, "adsenseAttributes" | "targeting" | "categoryExclusion">ตัวเลือกการกำหนดค่าสำหรับช่อง

getResponseInformation

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

getSlotElementId

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

getTargeting

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

getTargetingKeys

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

set

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

setCategoryExclusion

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

setClickUrl

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

setCollapseEmptyDiv

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

setConfig

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

setForceSafeFrame

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

setSafeFrameConfig

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

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

JavaScript

googletag.pubads().setForceSafeFrame(true);

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

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

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

JavaScript (เดิม)

googletag.pubads().setForceSafeFrame(true);

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

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

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

TypeScript

googletag.pubads().setForceSafeFrame(true);

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

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

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

setTargeting

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

updateTargetingFromMap

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

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

googletag.config

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

ชื่อแทนประเภท


CollapseDivBehavior

CollapseDivBehavior: "DISABLED" | "BEFORE_FETCH" | "ON_NO_FILL"
ค่าที่รองรับสำหรับการควบคุมลักษณะการทำงานของการยุบช่องโฆษณา
ดูเพิ่มเติม

InterstitialTrigger

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

PrivacyTreatment

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

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


googletag.config.AdExpansionConfig

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

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


Optional เปิดใช้แล้ว

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

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

googletag.config.AdSenseAttributesConfig

การตั้งค่าเพื่อควบคุมลักษณะการทำงานของโฆษณา AdSense

คุณสามารถใช้แอตทริบิวต์เหล่านี้เพื่อลบล้างการตั้งค่าฝั่งเซิร์ฟเวอร์ตามคำขอแต่ละรายการได้
พร็อพเพอร์ตี้
adsense_ad_format?
รูปแบบโฆษณา AdSense
adsense_channel_ids?
รหัสแชแนล AdSense
adsense_test_mode?
เปิดใช้โหมดทดสอบหรือไม่
document_language?
ภาษาของหน้าเว็บที่แสดงโฆษณา
page_url?
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"
รูปแบบโฆษณา AdSense

Optional adsense_channel_ids

adsense_channel_ids?: string
รหัสแชแนล AdSense

ค่าที่ใช้ได้คือรหัสแชแนลที่คั่นด้วย "+"

ตัวอย่าง: 271828183+314159265
ดูเพิ่มเติม

Optional 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 ของหน้าเว็บที่แสดงโฆษณา

ค่าที่อนุญาตคือ URL ที่ถูกต้อง

ตัวอย่าง: http://www.example.com

googletag.config.ComponentAuctionConfig

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

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


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

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

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


Optional requireStorageAccess

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

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

Optional ทริกเกอร์

triggers?: 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

การตั้งค่าเพื่อควบคุมการใช้ Lazy Loading ใน GPT
พร็อพเพอร์ตี้
fetchMarginPercent?
ระยะทางขั้นต่ำจากวิวพอร์ตปัจจุบันที่ช่องต้องอยู่ก่อนที่เราจะขอโฆษณา โดยแสดงเป็นเปอร์เซ็นต์ของขนาดวิวพอร์ต
mobileScaling?
ตัวคูณที่ใช้กับระยะขอบในอุปกรณ์เคลื่อนที่
renderMarginPercent?
ระยะทางขั้นต่ำจากวิวพอร์ตปัจจุบันที่ช่องต้องอยู่ก่อนที่เราจะแสดงโฆษณา โดยแสดงเป็นเปอร์เซ็นต์ของขนาดวิวพอร์ต
ดูเพิ่มเติม

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


Optional fetchMarginPercent

fetchMarginPercent?: number
ระยะห่างขั้นต่ำจากวิวพอร์ตปัจจุบันที่ช่องต้องมีก่อนที่เราจะขอโฆษณา ซึ่งแสดงเป็นเปอร์เซ็นต์ของขนาดวิวพอร์ต

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

ค่า 0 หมายถึง "เมื่อช่องเข้าสู่ Viewport" ค่า 100 หมายถึง "เมื่อโฆษณาอยู่ห่างจาก Viewport 1 ช่อง" และอื่นๆ

Optional mobileScaling

mobileScaling?: number
ตัวคูณที่ใช้กับระยะขอบในอุปกรณ์เคลื่อนที่ ตัวคูณนี้ใช้กับทั้ง fetchMarginPercent และ renderMarginPercent

ซึ่งจะช่วยให้มีระยะขอบที่แตกต่างกันในอุปกรณ์เคลื่อนที่และเดสก์ท็อป ซึ่งขนาดวิวพอร์ตและความเร็วในการเลื่อนอาจแตกต่างกัน เช่น ค่า 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,
      });
พร็อพเพอร์ตี้
adExpansion?
การตั้งค่าเพื่อควบคุมการขยายโฆษณา
adsenseAttributes?
การตั้งค่าเพื่อกำหนดค่าแอตทริบิวต์ AdSense
adYield?
เลิกใช้งานแล้ว 
categoryExclusion?
การตั้งค่าเพื่อกำหนดค่าการยกเว้นหมวดหมู่โฆษณา
centering?
การตั้งค่าเพื่อควบคุมการจัดกึ่งกลางแนวนอนของโฆษณา
collapseDiv?
การตั้งค่าเพื่อควบคุมลักษณะการยุบของช่องโฆษณา
disableInitialLoad?
การตั้งค่าเพื่อควบคุมเวลาที่ขอโฆษณา
lazyLoad?
การตั้งค่าเพื่อควบคุมการใช้ Lazy Loading ใน GPT
location?
การตั้งค่าเพื่อกำหนดเป้าหมายตามภูมิศาสตร์ให้กับรายการโฆษณาตามสถานที่ตั้งทางภูมิศาสตร์
pps?
การตั้งค่าเพื่อควบคุมสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS)
privacyTreatments?
การตั้งค่าเพื่อควบคุมการจัดการความเป็นส่วนตัวของผู้เผยแพร่โฆษณา
safeFrame?
การตั้งค่าเพื่อควบคุมการใช้ SafeFrame ใน GPT
singleRequest?
การตั้งค่าเพื่อเปิดหรือปิดใช้สถาปัตยกรรมคำขอรวมครั้งเดียว (SRA)
targeting?
การตั้งค่าเพื่อควบคุมการกำหนดเป้าหมายคีย์-ค่า
threadYield?
การตั้งค่าเพื่อควบคุมว่า GPT ควรส่งต่อเธรด JS เมื่อขอและแสดงผลครีเอทีฟโฆษณาหรือไม่
videoAds?
การตั้งค่าเพื่อควบคุมโฆษณาวิดีโอ

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


Optional adExpansion

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

Optional adsenseAttributes

adsenseAttributes?: AdSenseAttributesConfig
การตั้งค่าเพื่อกำหนดค่าแอตทริบิวต์ AdSense

แอตทริบิวต์ 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?: CollapseDivBehavior
การตั้งค่าเพื่อควบคุมลักษณะการทำงานของการยุบช่องโฆษณา

ช่องโฆษณาที่ยุบจะไม่ใช้พื้นที่ใดๆ ในหน้า

ค่าที่รองรับ
  • null (ค่าเริ่มต้น): ระบบจะไม่ยุบช่อง
  • DISABLED: ช่องจะไม่ยุบ ไม่ว่าจะมีการแสดงโฆษณาหรือไม่ก็ตาม
  • BEFORE_FETCH: ช่องจะเริ่มยุบและขยายเมื่อมีการแสดงโฆษณา
  • ON_NO_FILL: ช่องจะเริ่มขยายและยุบหากไม่มีการแสดงผลโฆษณา
ตัวอย่าง

JavaScript

// Collapse the div for this slot if no ad is returned.
googletag.setConfig({ collapseDiv: "ON_NO_FILL" });

// Collapse the div for this slot by default, and expand only
// if an ad is returned.
googletag.setConfig({ collapseDiv: "BEFORE_FETCH" });

// Do not collapse the div for this slot.
googletag.setConfig({ collapseDiv: "DISABLED" });

// Clear the collapse setting.
googletag.setConfig({ collapseDiv: null });

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?: LazyLoadConfig
การตั้งค่าเพื่อควบคุมการใช้ Lazy Loading ใน GPT

Lazy 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

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

Optional privacyTreatments

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

Optional safeFrame

safeFrame?: SafeFrameConfig
การตั้งค่าเพื่อควบคุมการใช้ SafeFrame ใน GPT

ค่าที่กำหนดค่าผ่านการตั้งค่านี้จะมีผลกับช่องโฆษณาทั้งหมดในหน้า ช่องโฆษณาแต่ละช่องอาจลบล้างค่าเหล่านี้ผ่าน 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)

เมื่อเปิดใช้ 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 ควรส่งต่อเธรด JS เมื่อขอและแสดงผลครีเอทีฟโฆษณาหรือไม่

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

ออบเจ็กต์การกำหนดค่าสัญญาณที่ได้จากผู้เผยแพร่โฆษณา (PPS)
พร็อพเพอร์ตี้
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>>
ออบเจ็กต์ที่มีการแมปการจัดหมวดหมู่หรือ null เพื่อล้างการกำหนดค่า

googletag.config.SafeFrameConfig

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

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


Optional allowOverlayExpansion

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

Optional allowPushExpansion

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

Optional forceSafeFrame

forceSafeFrame?: boolean
ควรกำหนดให้โฆษณาแสดงผลโดยใช้คอนเทนเนอร์ SafeFrame หรือไม่

Optional sandbox

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

Optional useUniqueDomain

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

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

googletag.config.SlotSettingsConfig

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

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

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

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

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


Optional adExpansion

adExpansion?: AdExpansionConfig
การตั้งค่าเพื่อกำหนดค่าการขยายโฆษณา
ดูเพิ่มเติม

Optional adsenseAttributes

adsenseAttributes?: AdSenseAttributesConfig
การตั้งค่าเพื่อกำหนดค่าแอตทริบิวต์ AdSense

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

เซิร์ฟเวอร์ของ 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?: CollapseDivBehavior
การตั้งค่าเพื่อกำหนดค่าลักษณะการทำงานของการยุบของช่องโฆษณา

ช่องโฆษณาที่ยุบแล้วจะไม่ใช้พื้นที่ใดๆ ในหน้า

ค่าที่รองรับ
  • null (ค่าเริ่มต้น): ระบบจะไม่ยุบช่อง
  • DISABLED: ช่องจะไม่ยุบ ไม่ว่าจะมีการแสดงโฆษณาหรือไม่ก็ตาม
  • BEFORE_FETCH: ช่องจะเริ่มยุบและขยายเมื่อมีการแสดงโฆษณา
  • ON_NO_FILL: ช่องจะเริ่มขยายและยุบหากไม่มีการแสดงผลโฆษณา
ตัวอย่าง

JavaScript

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

// Collapse the div for this slot if no ad is returned.
slot.setConfig({
  collapseDiv: "ON_NO_FILL",
});

// Collapse the div for this slot by default, and expand only
// if an ad is returned.
slot.setConfig({
  collapseDiv: "BEFORE_FETCH",
});

// Do not collapse the div for this slot.
slot.setConfig({
  collapseDiv: "DISABLED",
});

// Clear the collapse setting.
slot.setConfig({
  collapseDiv: null,
});

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
การตั้งค่าเพื่อกำหนดค่าการใช้ SafeFrame ใน GPT

ค่าที่กำหนดค่าผ่านการตั้งค่านี้จะมีผลกับช่องโฆษณาเท่านั้น และจะลบล้างค่าที่ตั้งค่าผ่าน 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

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

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


values

values: readonly string[]
รายการค่าการจัดหมวดหมู่

googletag.config.VideoAdsConfig

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

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


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

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

การแจงนับ


OutOfPageFormat

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

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

TrafficSource

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

googletag.events

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

googletag.events.Event

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

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


serviceName

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

slot

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

googletag.events.EventTypeMap

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

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


gameManualInterstitialSlotClosed

gameManualInterstitialSlotClosed: GameManualInterstitialSlotClosedEvent
ชื่อแทนสำหรับ events.GameManualInterstitialSlotClosedEvent

gameManualInterstitialSlotReady

gameManualInterstitialSlotReady: GameManualInterstitialSlotReadyEvent
ชื่อแทนสำหรับ events.GameManualInterstitialSlotReadyEvent

impressionViewable

impressionViewable: ImpressionViewableEvent
ชื่อแทนสำหรับ events.ImpressionViewableEvent

rewardedSlotClosed

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

rewardedSlotGranted

rewardedSlotGranted: RewardedSlotGrantedEvent
ชื่อแทนสำหรับ events.RewardedSlotGrantedEvent

rewardedSlotReady

rewardedSlotReady: RewardedSlotReadyEvent
นามแฝงสำหรับ events.RewardedSlotReadyEvent

rewardedSlotVideoCompleted

rewardedSlotVideoCompleted: RewardedSlotVideoCompletedEvent
ชื่อแทนสำหรับ events.RewardedSlotVideoCompletedEvent

slotOnload

slotOnload: SlotOnloadEvent
ชื่อแทนสำหรับ events.SlotOnloadEvent

slotRenderEnded

slotRenderEnded: SlotRenderEndedEvent
ชื่อแทนสำหรับ events.SlotRenderEndedEvent

slotRequested

slotRequested: SlotRequestedEvent
ชื่อแทนสำหรับ events.SlotRequestedEvent

slotResponseReceived

slotResponseReceived: SlotResponseReceived
นามแฝงสำหรับ events.SlotResponseReceived

slotVisibilityChanged

slotVisibilityChanged: SlotVisibilityChangedEvent
ชื่อแทนสำหรับ events.SlotVisibilityChangedEvent

googletag.events.GameManualInterstitialSlotClosedEvent

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

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

JavaScript

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

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

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

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

JavaScript (เดิม)

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

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

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

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

TypeScript

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

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

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

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

googletag.events.GameManualInterstitialSlotReadyEvent

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

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

JavaScript

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

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

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

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

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

JavaScript (เดิม)

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

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

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

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

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

TypeScript

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

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

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

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

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

เมธอด


makeGameManualInterstitialVisible

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

googletag.events.ImpressionViewableEvent

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

googletag.events.RewardedSlotClosedEvent

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

JavaScript

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

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

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

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

JavaScript (เดิม)

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

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

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

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

TypeScript

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

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

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

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

googletag.events.RewardedSlotGrantedEvent

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

JavaScript

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

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

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

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

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

JavaScript (เดิม)

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

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

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

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

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

TypeScript

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

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

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

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

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

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


เพย์โหลด

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

googletag.events.RewardedSlotReadyEvent

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

JavaScript

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

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

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

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

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

JavaScript (เดิม)

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

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

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

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

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

TypeScript

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

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

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

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

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

เมธอด


makeRewardedVisible

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

googletag.events.RewardedSlotVideoCompletedEvent

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

JavaScript

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

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

  // This listener is called when the video in a rewarded ad slot has
  // finished playing.
  googletag.pubads().addEventListener("rewardedSlotVideoCompleted", (event) => {
    const slot = event.slot;
    console.log("Video in rewarded ad slot", slot.getSlotElementId(), "has finished playing.");

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

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 video in a rewarded ad slot has
  // finished playing.
  googletag.pubads().addEventListener("rewardedSlotVideoCompleted", function (event) {
    var slot = event.slot;
    console.log("Video in rewarded ad slot", slot.getSlotElementId(), "has finished playing.");

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

TypeScript

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

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

  // This listener is called when the video in a rewarded ad slot has
  // finished playing.
  googletag.pubads().addEventListener("rewardedSlotVideoCompleted", (event) => {
    const slot = event.slot;
    console.log("Video in rewarded ad slot", slot.getSlotElementId(), "has finished playing.");

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

googletag.events.SlotOnloadEvent

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

googletag.events.SlotRenderEndedEvent

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

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


advertiserId

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

campaignId

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

companyIds

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

creativeId

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

creativeTemplateId

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

isBackfill

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

isEmpty

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

labelIds

labelIds: number[]

lineItemId

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

responseIdentifier

responseIdentifier: string
ตัวระบุการตอบกลับคือตัวระบุที่ไม่ซ้ำกันสำหรับการตอบกลับของโฆษณา คุณใช้ค่านี้เพื่อระบุและบล็อกโฆษณาในศูนย์ตรวจสอบโฆษณา (ARC) ได้

size

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

slotContentChanged

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

sourceAgnosticCreativeId

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

sourceAgnosticLineItemId

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

yieldGroupIds

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

googletag.events.SlotRequestedEvent

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

googletag.events.SlotResponseReceived

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

JavaScript

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

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

JavaScript (เดิม)

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

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

TypeScript

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

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

googletag.events.SlotVisibilityChangedEvent

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

JavaScript

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

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

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

JavaScript (เดิม)

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

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

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

TypeScript

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

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

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

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


inViewPercentage

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

googletag.secureSignals

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

ชื่อแทนประเภท


SecureSignalProvider

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

googletag.secureSignals.BidderSignalProvider

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

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

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


collectorFunction

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

id

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

googletag.secureSignals.PublisherSignalProvider

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

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

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

JavaScript

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

JavaScript (เดิม)

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

TypeScript

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

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


collectorFunction

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

networkCode

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

googletag.secureSignals.SecureSignalProvidersArray

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

เมธอด


clearAllCache

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

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

push

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