Tài liệu tham khảo này sử dụng ký hiệu TypeScript để mô tả các loại. Bảng sau đây đưa ra nội dung giải thích ngắn gọn theo ví dụ.
Biểu thức loại | |
---|---|
string |
Loại chuỗi gốc. |
string[] |
Một loại mảng, trong đó giá trị chỉ có thể là chuỗi. |
number | string |
Kiểu kết hợp, trong đó giá trị có thể là một số hoặc một chuỗi. |
Array<number | string> |
Một loại mảng, trong đó giá trị là một kiểu phức hợp (kết hợp). |
[number, string] |
Kiểu bộ dữ liệu, trong đó giá trị là một mảng hai phần tử phải chứa một số và một chuỗi theo thứ tự đó. |
Slot |
Một loại đối tượng, trong đó giá trị là thực thể của googletag.Slot . |
() => void |
Loại hàm không có đối số được xác định và không có giá trị trả về. |
Để tìm hiểu thêm về các loại được hỗ trợ và biểu thức loại, hãy tham khảo Sổ tay TypeScript .
Nhập chú thích
Dấu hai chấm sau một biến, tên tham số, tên thuộc tính hoặc chữ ký hàm biểu thị một chú thích loại. Chú giải kiểu mô tả các loại mà phần tử ở bên trái dấu hai chấm có thể chấp nhận hoặc trả về. Bảng sau đây trình bày ví dụ về chú giải kiểu mà bạn có thể thấy trong tài liệu tham khảo này.
Nhập chú thích | |
---|---|
param: string |
Cho biết param chấp nhận hoặc trả về một giá trị chuỗi. Cú pháp này được dùng cho biến, tham số, thuộc tính và loại dữ liệu trả về.
|
param?: number | string |
Cho biết param là không bắt buộc, nhưng chấp nhận cả số hoặc chuỗi khi được chỉ định. Cú pháp này được dùng cho các tham số và thuộc tính.
|
...params: Array<() => void> |
Cho biết params là một
tham số nghỉ ngơi
chấp nhận các hàm. Thông số còn lại chấp nhận số lượng giá trị thuộc loại đã chỉ định không giới hạn.
|
Định nghĩa loại
Loại | |
---|---|
|
SingleSize | MultiSize
|
Cấu hình kích thước hợp lệ cho một vùng, có thể là một hoặc nhiều kích thước. |
|
|
SingleSize[]
|
Danh sách các kích thước hợp lệ. |
|
|
"fluid" | ["fluid"]
|
Kích thước được đặt tên mà một vùng có thể có. Trong hầu hết các trường hợp, kích thước là hình chữ nhật có kích thước cố định, nhưng có một số trường hợp chúng ta cần các loại thông số kỹ thuật khác về kích thước. Chỉ những kích thước sau đây là kích thước được đặt tên hợp lệ:
|
|
|
SingleSizeArray | NamedSize
|
Một kích thước hợp lệ cho một vị trí. |
|
|
[number, number]
|
Mảng gồm hai số đại diện cho [chiều rộng, chiều cao]. |
|
|
[SingleSizeArray, GeneralSize]
|
Ánh xạ kích thước khung nhìn tới kích thước quảng cáo. Dùng cho quảng cáo thích ứng. |
|
|
SizeMapping[]
|
Danh sách các liên kết kích thước. |
|
|
"unhideWindow" | "navBar"
|
Điều kiện kích hoạt quảng cáo xen kẽ được hỗ trợ. |
|
|
"disablePersonalization"
|
Các biện pháp bảo vệ quyền riêng tư được hỗ trợ cho nhà xuất bản. |
|
|
"IAB_AUDIENCE_1_1" | "IAB_CONTENT_2_2"
|
Hệ thống phân loại được hỗ trợ cho tín hiệu do nhà xuất bản cung cấp (PPS). |
|
|
BidderSignalProvider | PublisherSignalProvider
|
Giao diện để trả về tín hiệu an toàn cho một bên đặt giá thầu hoặc nhà cung cấp cụ thể. Bạn phải cung cấp một trong hai giá trị |
Các loại enum
Enum | |
---|---|
googletag.enums.OutOfPageFormat
|
Các định dạng nằm ngoài trang được GPT hỗ trợ.
|
googletag.enums.TrafficSource
|
Nguồn lưu lượng truy cập do GPT hỗ trợ.
|
googletag.enums.OutOfPageFormat
-
Các định dạng nằm ngoài trang được GPT hỗ trợ.
-
- Xem thêm
googletag.enums.TrafficSource
-
Nguồn lưu lượng truy cập do GPT hỗ trợ.
-
- Xem thêm
googletag
Không gian tên chung mà Thẻ nhà xuất bản của Google sử dụng cho API của thẻ.
Thông tin tóm tắt về biến | |
---|---|
apiReady
|
Cờ cho biết API GPT đã được tải và sẵn sàng được gọi.
|
cmd
|
Tham chiếu đến hàng đợi lệnh chung cho quá trình thực thi không đồng bộ các lệnh gọi liên quan đến GPT.
|
pubadsReady
|
Cờ cho biết
PubAdsService đã được bật, tải và hoạt động đầy đủ.
|
secureSignalProviders
|
Tham chiếu đến mảng nhà cung cấp tín hiệu an toàn.
|
Tóm tắt hàm | |
---|---|
companionAds
|
Trả về một tham chiếu đến
CompanionAdsService .
|
defineOutOfPageSlot
|
Tạo vùng quảng cáo ngoài trang có đường dẫn đơn vị quảng cáo nhất định.
|
defineSlot
|
Tạo vùng quảng cáo có đường dẫn và kích thước đơn vị quảng cáo nhất định, đồng thời liên kết đường dẫn và kích thước đó với ID của phần tử div trên trang sẽ chứa quảng cáo.
|
destroySlots
|
Huỷ bỏ các vùng đã cho, xoá tất cả đối tượng liên quan và tệp tham chiếu của các vùng đó khỏi GPT.
|
disablePublisherConsole
|
Tắt Bảng điều khiển dành cho nhà xuất bản của Google.
|
display
|
Hướng dẫn dịch vụ khe hiển thị vị trí.
|
enableServices
|
Bật tất cả dịch vụ GPT đã được xác định cho vùng quảng cáo trên trang.
|
getVersion
|
Trả về phiên bản GPT hiện tại.
|
openConsole
|
Mở Bảng điều khiển dành cho nhà xuất bản của Google.
|
pubads
|
Trả về một tham chiếu đến
PubAdsService .
|
setAdIframeTitle
|
Đặt tiêu đề cho tất cả các iframe vùng chứa quảng cáo do
PubAdsService tạo từ thời điểm này trở đi.
|
setConfig
|
Đặt các tuỳ chọn cấu hình chung cho trang.
|
sizeMapping
|
Tạo một
SizeMappingBuilder mới.
|
googletag.apiReady
-
apiReady: boolean | undefined
-
Cờ cho biết API GPT đã được tải và sẵn sàng được gọi. Thuộc tính này sẽ chỉ là
undefined
cho đến khi API sẵn sàng.
Lưu ý rằng cách xử lý không đồng bộ được đề xuất là sử dụng googletag.cmd để xếp hàng lệnh gọi lại khi GPT sẵn sàng. Những lệnh gọi lại này không cần phải kiểm tra googletag.apiReady vì chúng được đảm bảo sẽ thực thi sau khi API được thiết lập. -
- Ví dụ:
-
JavaScript
if (window.googletag && googletag.apiReady) { // GPT API can be called safely. }
JavaScript (cũ)
if (window.googletag && googletag.apiReady) { // GPT API can be called safely. }
TypeScript
if (window.googletag && googletag.apiReady) { // GPT API can be called safely. }
googletag.cmd
-
cmd: Array<(this: typeof globalThis) => void> | CommandArray
-
Tham chiếu đến hàng đợi lệnh chung cho các lệnh gọi có liên quan đến GPT để thực thi không đồng bộ.
Biếngoogletag.cmd
được khởi chạy cho một mảng JavaScript trống theo cú pháp thẻ GPT trên trang vàcmd.push
là phương thứcArray.push
tiêu chuẩn thêm một phần tử vào cuối mảng. Khi được tải, GPT JavaScript sẽ xem xét mảng và thực thi tất cả hàm theo thứ tự. Sau đó, tập lệnh sẽ thay thếcmd
bằng đối tượngCommandArray
có phương thức đẩy được xác định để thực thi đối số hàm được truyền vào đối tượng đó. Cơ chế này cho phép GPT giảm độ trễ dự kiến bằng cách tìm nạp JavaScript không đồng bộ trong khi cho phép trình duyệt tiếp tục hiển thị trang. -
- Ví dụ:
-
JavaScript
googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); });
JavaScript (cũ)
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()); });
googletag.pubadsReady
-
pubadsReady: boolean | undefined
-
Cờ cho biết
PubAdsService
đã được bật, tải và hoạt động đầy đủ. Thuộc tính này sẽ chỉ làundefined
cho đến khienableServices
được gọi vàPubAdsService
được tải cũng như khởi chạy. -
googletag.secureSignalProviders
-
secureSignalProviders: SecureSignalProvider[] | SecureSignalProvidersArray | undefined
-
Tham chiếu đến mảng nhà cung cấp tín hiệu an toàn.
Mảng nhà cung cấp tín hiệu an toàn chấp nhận một chuỗi các hàm tạo tín hiệu và gọi các hàm đó theo thứ tự. Tệp này nhằm thay thế một mảng chuẩn dùng để thêm các hàm tạo tín hiệu vào hàng đợi sẽ được gọi sau khi GPT được tải. -
- Ví dụ:
-
JavaScript
window.googletag = window.googletag || { cmd: [] }; googletag.secureSignalProviders = googletag.secureSignalProviders || []; googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: () => { return Promise.resolve("signal"); }, });
JavaScript (cũ)
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"); }, });
- Xem thêm
googletag.companionAds
-
companionAds(): CompanionAdsService
-
Trả về một tham chiếu đến
CompanionAdsService
. -
-
Giá trị trả về CompanionAdsService
Dịch vụ Quảng cáo đồng hành.
googletag.defineOutOfPageSlot
-
defineOutOfPageSlot(adUnitPath: string, div?: string | OutOfPageFormat): Slot | null
-
Tạo vùng quảng cáo ngoài trang bằng đường dẫn đơn vị quảng cáo nhất định.
Đối với quảng cáo ngoài trang tuỳ chỉnh,div
là mã của phần tử div chứa quảng cáo. Hãy xem bài viết về mẫu quảng cáo nằm ngoài trang để biết thêm thông tin.
Đối với quảng cáo nằm ngoài trang do GPT quản lý,div
là một OutOfPageFormat được hỗ trợ. -
- Ví dụ:
-
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 (cũ)
// 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);
- Xem thêm
-
Tham số adUnitPath: string
Đường dẫn đơn vị quảng cáo đầy đủ có mã mạng và mã đơn vị quảng cáo.div?: string | OutOfPageFormat
Mã của div sẽ chứa đơn vị quảng cáo này hoặc OutOfPageFormat. -
Giá trị trả về Slot | null
Vùng mới tạo hoặcnull
nếu không thể tạo vùng.
googletag.defineSlot
-
defineSlot(adUnitPath: string, size: GeneralSize, div?: string): Slot | null
-
Tạo vùng quảng cáo có đường dẫn và kích thước đơn vị quảng cáo nhất định, đồng thời liên kết đường dẫn và kích thước đó với ID của phần tử div trên trang sẽ chứa quảng cáo.
-
- Ví dụ:
-
JavaScript
googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
JavaScript (cũ)
googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
TypeScript
googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
- Xem thêm
-
Tham số adUnitPath: string
Đường dẫn đơn vị quảng cáo đầy đủ có mã mạng và mã đơn vị.size: GeneralSize
Chiều rộng và chiều cao của vùng đã thêm. Đây là kích thước được dùng trong yêu cầu quảng cáo nếu không có ánh xạ kích thước thích ứng nào được cung cấp hoặc kích thước của khung nhìn nhỏ hơn kích thước nhỏ nhất được cung cấp khi ánh xạ.div?: string
Mã của div sẽ chứa đơn vị quảng cáo này. -
Giá trị trả về Slot | null
Vùng mới tạo hoặcnull
nếu không thể tạo vùng.
googletag.destroySlots
-
destroySlots(slots?: Slot[]): boolean
-
Huỷ bỏ các vùng đã cho, xoá tất cả đối tượng liên quan và tệp tham chiếu của các vùng đó khỏi GPT. API này không hỗ trợ vùng trả về và vùng đồng hành.
Việc gọi API này trên một vùng sẽ xoá quảng cáo và loại bỏ đối tượng vùng quảng cáo khỏi trạng thái nội bộ do GPT duy trì. Gọi thêm bất kỳ hàm nào trên đối tượng vị trí sẽ dẫn đến hành vi không xác định. Xin lưu ý rằng trình duyệt có thể vẫn không giải phóng bộ nhớ được liên kết với vị trí đó nếu trang nhà xuất bản duy trì việc tham chiếu đến bộ nhớ. Khi gọi API này, div liên kết với vị trí đó sẽ có sẵn để sử dụng lại.
Đặc biệt, việc hủy một vùng sẽ xóa quảng cáo khỏi số lần xem trang dài hạn của GPT, vì vậy, các yêu cầu trong tương lai sẽ không bị ảnh hưởng bởi kỹ thuật khoanh vùng hoặc loại trừ cạnh tranh liên quan đến quảng cáo này. Việc không gọi hàm này trước khi xóa div của một vị trí khỏi trang sẽ dẫn đến hành vi không xác định. -
- Ví dụ:
-
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 (cũ)
// 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();
-
Tham số slots?: Slot[]
Mảng khe cần huỷ. Mảng là không bắt buộc; tất cả khe sẽ bị huỷ nếu không được chỉ định. -
Giá trị trả về boolean
true
nếu các khe đã bị huỷ, nếu không thìfalse
.
googletag.disablePublisherConsole
-
disablePublisherConsole(): void
-
Tắt Bảng điều khiển dành cho nhà xuất bản của Google.
googletag.display
-
display(divOrSlot: string | Element | Slot): void
-
Hướng dẫn dịch vụ khe hiển thị vị trí. Mỗi vùng quảng cáo chỉ nên được hiển thị một lần trên mỗi trang. Tất cả các vùng phải được xác định và liên kết với dịch vụ trước khi được hiển thị. Lệnh gọi hiển thị không được xảy ra cho đến khi phần tử này xuất hiện trong DOM. Cách thông thường để làm việc này là đặt quảng cáo trong một khối tập lệnh trong phần tử div có tên trong lệnh gọi phương thức.
Nếu đang sử dụng một cấu trúc yêu cầu duy nhất (SRA), thì tất cả các vùng quảng cáo không được tìm nạp tại thời điểm phương thức này được gọi sẽ được tìm nạp cùng một lúc. Để buộc một vùng quảng cáo không hiển thị, bạn phải xóa toàn bộ div. -
- Ví dụ:
-
JavaScript
googletag.cmd.push(() => { googletag.display("div-1"); });
JavaScript (cũ)
googletag.cmd.push(function () { googletag.display("div-1"); });
TypeScript
googletag.cmd.push(() => { googletag.display("div-1"); });
- Xem thêm
-
Tham số divOrSlot: string | Element | Slot
ID của phần tử div chứa vùng quảng cáo hoặc phần tử div hoặc đối tượng vị trí. Nếu bạn cung cấp một phần tử div thì phần tử đó phải có thuộc tính "id" khớp với mã nhận dạng được chuyển vàodefineSlot
.
googletag.enableServices
-
enableServices(): void
-
Bật tất cả dịch vụ GPT đã được xác định cho vùng quảng cáo trên trang.
-
googletag.getVersion
-
getVersion(): string
-
Trả về phiên bản GPT hiện tại.
-
- Xem thêm
-
Giá trị trả về string
Chuỗi phiên bản GPT hiện đang thực thi.
googletag.openConsole
-
openConsole(div?: string): void
-
Mở Bảng điều khiển dành cho nhà xuất bản của Google.
-
- Ví dụ:
-
JavaScript
// Calling with div ID. googletag.openConsole("div-1"); // Calling without div ID. googletag.openConsole();
JavaScript (cũ)
// 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();
- Xem thêm
-
Tham số div?: string
ID div vùng quảng cáo. Giá trị này là không bắt buộc. Khi được cung cấp, Bảng điều khiển dành cho nhà xuất bản sẽ cố gắng mở kèm theo thông tin chi tiết về vùng quảng cáo đã chỉ định trong chế độ xem.
googletag.pubads
-
pubads(): PubAdsService
-
Trả về một tham chiếu đến
PubAdsService
. -
-
Giá trị trả về PubAdsService
Dịch vụ Quảng cáo của nhà xuất bản.
googletag.setAdIframeTitle
-
setAdIframeTitle(title: string): void
-
Đặt tiêu đề cho tất cả các iframe vùng chứa quảng cáo do
PubAdsService
tạo từ thời điểm này trở đi. -
- Ví dụ:
-
JavaScript
googletag.setAdIframeTitle("title");
JavaScript (cũ)
googletag.setAdIframeTitle("title");
TypeScript
googletag.setAdIframeTitle("title");
-
Tham số title: string
Tiêu đề mới cho tất cả các iframe vùng chứa quảng cáo.
googletag.setConfig
-
setConfig(config: PageSettingsConfig): void
-
Đặt các tuỳ chọn cấu hình chung cho trang.
-
-
Tham số config: PageSettingsConfig
googletag.sizeMapping
-
sizeMapping(): SizeMappingBuilder
-
Tạo một
SizeMappingBuilder
mới. -
Giá trị trả về SizeMappingBuilder
Một trình tạo mới.
googletag.CommandArray
Mảng lệnh chấp nhận một chuỗi các hàm và gọi các hàm đó theo thứ tự. Thẻ này nhằm thay thế một mảng tiêu chuẩn dùng để thêm các hàm vào hàng đợi sẽ được gọi sau khi GPT được tải.
Tóm tắt phương pháp | |
---|---|
push
|
Thực thi chuỗi hàm được chỉ định trong đối số theo thứ tự.
|
push
-
push(...f: Array<(this: typeof globalThis) => void>): number
-
Thực thi chuỗi hàm được chỉ định trong đối số theo thứ tự.
-
- Ví dụ:
-
JavaScript
googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); });
JavaScript (cũ)
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()); });
-
Tham số ...f: Array<(this: typeof globalThis) => void>
Hàm JavaScript cần thực thi. Liên kết thời gian chạy sẽ luôn làglobalThis
. Hãy cân nhắc truyền một hàm mũi tên để giữ lại giá trịthis
của ngữ cảnh từ vựng kèm theo. -
Giá trị trả về number
Số lệnh đã xử lý cho đến thời điểm này. Giá trị này tương thích với giá trị trả về củaArray.push
(độ dài hiện tại của mảng).
googletag.CompanionAdsService
Mở rộng
dịch vụ Quảng cáo đồng hành. Dịch vụ này được quảng cáo video sử dụng để hiển thị quảng cáo đồng hành.
Tóm tắt phương pháp | |
---|---|
addEventListener
|
Đăng ký một trình nghe cho phép bạn thiết lập và gọi hàm JavaScript khi một sự kiện GPT cụ thể xảy ra trên trang.
Đã kế thừa từ
|
getSlots
|
Lấy danh sách vùng quảng cáo được liên kết với dịch vụ này.
Đã kế thừa từ
|
removeEventListener
|
Xoá trình nghe đã đăng ký trước đó.
Đã kế thừa từ
|
setRefreshUnfilledSlots
|
Thiết lập xem các vùng đồng hành chưa được lấp đầy có được tự động chèn lấp hay không.
|
setRefreshUnfilledSlots
-
setRefreshUnfilledSlots(value: boolean): void
-
Đặt liệu các vùng đồng hành chưa được lấp đầy có được tự động chèn lấp hay không.
Phương pháp này có thể được gọi nhiều lần trong suốt vòng đời của trang để bật và tắt tính năng chèn lấp. Chỉ những vùng đã được đăng ký bằngPubAdsService
mới được chèn lấp. Do các hạn chế của chính sách, phương pháp này không được thiết kế để lấp đầy các vùng đồng hành trống khi video Ad Exchange được phân phát. -
- Ví dụ:
-
JavaScript
googletag.companionAds().setRefreshUnfilledSlots(true);
JavaScript (cũ)
googletag.companionAds().setRefreshUnfilledSlots(true);
TypeScript
googletag.companionAds().setRefreshUnfilledSlots(true);
-
Tham số value: boolean
true
để tự động chèn lấp các vị trí chưa được lấp đầy,false
để giữ nguyên các vị trí đó.
googletag.PrivacySettingsConfig
Đối tượng cấu hình cho chế độ cài đặt quyền riêng tư.
Tóm tắt thuộc tính | |
---|---|
childDirectedTreatment
|
Cho biết liệu trang có được co là dành cho trẻ em hay không.
|
limitedAds
|
Cho phép phân phát ở chế độ quảng cáo bị hạn chế để hỗ trợ các nhu cầu tuân thủ quy định của nhà xuất bản.
|
nonPersonalizedAds
|
Cho phép phân phát ở chế độ quảng cáo không được cá nhân hoá để hỗ trợ nhu cầu tuân thủ quy định của nhà xuất bản.
|
restrictDataProcessing
|
Cho phép phân phát ở chế độ xử lý bị hạn chế để hỗ trợ nhu cầu tuân thủ quy định của nhà xuất bản.
|
trafficSource
|
Cho biết liệu yêu cầu đại diện cho lưu lượng truy cập đã mua hay không phải trả tiền.
|
underAgeOfConsent
|
Cho biết liệu có đánh dấu các yêu cầu quảng cáo là đến từ người dùng dưới độ tuổi hợp pháp để tự quản lý tài khoản hay không.
|
childDirectedTreatment
-
childDirectedTreatment: null | boolean
-
Cho biết liệu trang có được co là dành cho trẻ em hay không. Đặt thành
null
để xoá cấu hình. -
limitedAds
-
limitedAds: boolean
-
Cho phép phân phát ở chế độ quảng cáo bị hạn chế để hỗ trợ các nhu cầu tuân thủ quy định của nhà xuất bản. Khi bật, bạn có thể tuỳ ý yêu cầu thư viện GPT từ một URL quảng cáo bị hạn chế không có cookie.
-
- Xem thêm
nonPersonalizedAds
-
nonPersonalizedAds: boolean
-
Cho phép phân phát ở chế độ quảng cáo không được cá nhân hoá để hỗ trợ nhu cầu tuân thủ quy định của nhà xuất bản.
-
restrictDataProcessing
-
restrictDataProcessing: boolean
-
Cho phép phân phát ở chế độ xử lý bị hạn chế để hỗ trợ nhu cầu tuân thủ quy định của nhà xuất bản.
-
trafficSource
-
trafficSource: TrafficSource
-
Cho biết liệu yêu cầu đại diện cho lưu lượng truy cập đã mua hay không phải trả tiền. Giá trị này điền sẵn phương diện Nguồn lưu lượng truy cập trong báo cáo Ad Manager. Nếu bạn không đặt chính sách này, nguồn lưu lượng truy cập sẽ đặt mặc định là
undefined
trong báo cáo. -
- Ví dụ:
-
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 (cũ)
// 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, });
underAgeOfConsent
-
underAgeOfConsent: null | boolean
-
Cho biết liệu có đánh dấu các yêu cầu quảng cáo là đến từ người dùng dưới độ tuổi hợp pháp để tự quản lý tài khoản hay không. Đặt thành
null
để xoá cấu hình. -
googletag.PubAdsService
Mở rộng
dịch vụ Quảng cáo của nhà xuất bản. Dịch vụ này được dùng để tìm nạp và hiển thị quảng cáo từ tài khoản Google Ad Manager của bạn.
Tóm tắt phương pháp | |
---|---|
addEventListener
|
Đăng ký một trình nghe cho phép bạn thiết lập và gọi hàm JavaScript khi một sự kiện GPT cụ thể xảy ra trên trang.
Đã kế thừa từ
|
clear
|
Xóa quảng cáo khỏi các vùng nhất định và thay thế bằng nội dung trống.
|
clearCategoryExclusions
|
Xóa tất cả các nhãn loại trừ danh mục quảng cáo cấp trang.
|
clearTargeting
|
Xoá thông số nhắm mục tiêu tuỳ chỉnh cho một khoá cụ thể hoặc cho tất cả các khoá.
|
collapseEmptyDivs
|
Cho phép thu gọn div vị trí để chúng không chiếm bất kỳ không gian nào trên trang khi không có nội dung quảng cáo nào để hiển thị.
|
disableInitialLoad
|
Vô hiệu hóa yêu cầu đối với quảng cáo khi tải trang, nhưng cho phép yêu cầu quảng cáo bằng lệnh gọi
PubAdsService.refresh .
|
display
|
Tạo và hiển thị một vùng quảng cáo có đường dẫn và kích thước đơn vị quảng cáo nhất định.
|
enableLazyLoad
|
Bật tính năng tải từng phần trong GPT như được xác định bởi đối tượng cấu hình.
|
enableSingleRequest
|
Bật chế độ yêu cầu duy nhất để tìm nạp nhiều quảng cáo cùng lúc.
|
enableVideoAds
|
Báo hiệu cho GPT rằng quảng cáo dạng video sẽ xuất hiện trên trang.
|
get
|
Trả về giá trị cho thuộc tính AdSense được liên kết với khoá đã cho.
|
getAttributeKeys
|
Trả về các khoá thuộc tính đã đặt cho dịch vụ này.
|
getSlots
|
Lấy danh sách vùng quảng cáo được liên kết với dịch vụ này.
Đã kế thừa từ
|
getTargeting
|
Trả về một thông số nhắm mục tiêu cấp dịch vụ tuỳ chỉnh cụ thể đã được đặt.
|
getTargetingKeys
|
Trả về danh sách tất cả các khoá nhắm mục tiêu cấp dịch vụ tuỳ chỉnh đã được đặt.
|
isInitialLoadDisabled
|
Trả về các yêu cầu ban đầu cho quảng cáo có bị tắt thành công bởi lệnh gọi
PubAdsService.disableInitialLoad trước đó hay không.
|
refresh
|
Tìm nạp và hiển thị quảng cáo mới cho các vùng cụ thể hoặc tất cả các vùng trên trang.
|
removeEventListener
|
Xoá trình nghe đã đăng ký trước đó.
Đã kế thừa từ
|
set
|
Đặt giá trị cho các thuộc tính AdSense áp dụng cho tất cả các vùng quảng cáo trong dịch vụ Quảng cáo của nhà xuất bản.
|
setCategoryExclusion
|
Đặt loại trừ danh mục quảng cáo cấp độ trang cho tên nhãn đã cho.
|
setCentering
|
Bật và tắt tính năng căn giữa quảng cáo theo chiều ngang.
|
setForceSafeFrame
|
Định cấu hình xem liệu tất cả quảng cáo trên trang có bắt buộc phải hiển thị bằng cách sử dụng vùng chứa SafeFrame hay không.
|
setLocation
|
Truyền thông tin vị trí từ các trang web để bạn có thể nhắm mục tiêu theo địa lý đến các vị trí cụ thể.
|
setPrivacySettings
|
Cho phép định cấu hình tất cả các chế độ cài đặt quyền riêng tư từ một API bằng cách sử dụng đối tượng cấu hình.
|
setPublisherProvidedId
|
Đặt giá trị cho mã do nhà xuất bản cung cấp.
|
setSafeFrameConfig
|
Đặt lựa chọn ưu tiên cấp trang cho cấu hình SafeFrame.
|
setTargeting
|
Đặt tham số nhắm mục tiêu tuỳ chỉnh cho một khoá nhất định áp dụng cho tất cả các vùng quảng cáo dịch vụ Quảng cáo của nhà xuất bản.
|
setVideoContent
|
Thiết lập thông tin nội dung video cần gửi cùng với yêu cầu quảng cáo cho mục đích nhắm mục tiêu và loại trừ nội dung.
|
updateCorrelator
|
Thay đổi giá trị tương quan được gửi cùng với yêu cầu quảng cáo, bắt đầu hiệu quả một lượt xem trang mới.
|
clear
-
clear(slots?: Slot[]): boolean
-
Xóa quảng cáo khỏi các vùng nhất định và thay thế bằng nội dung trống. Các vị trí sẽ được đánh dấu là không thể tìm nạp.
Đặc biệt, việc xóa một vị trí sẽ xóa quảng cáo khỏi số lần xem trang dài hạn của GPT, do đó, các yêu cầu trong tương lai sẽ không bị ảnh hưởng bởi kỹ thuật khoanh vùng hoặc loại trừ cạnh tranh liên quan đến quảng cáo này. -
- Ví dụ:
-
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 (cũ)
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();
-
Tham số slots?: Slot[]
Mảng vị trí cần xoá. Mảng là không bắt buộc; tất cả ô trống sẽ bị xoá nếu không được chỉ định. -
Giá trị trả về boolean
Trả vềtrue
nếu các ô đã bị xoá, nếu không thì trả vềfalse
.
clearCategoryExclusions
-
clearCategoryExclusions(): PubAdsService
-
Xóa tất cả các nhãn loại trừ danh mục quảng cáo cấp trang. Việc này rất hữu ích nếu bạn muốn làm mới vị trí.
-
- Ví dụ:
-
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 (cũ)
// 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.
- Xem thêm
-
Giá trị trả về PubAdsService
Đối tượng dịch vụ mà phương thức được gọi trên đó.
clearTargeting
-
clearTargeting(key?: string): PubAdsService
-
Xoá thông số nhắm mục tiêu tuỳ chỉnh cho một khoá cụ thể hoặc cho tất cả các khoá.
-
- Ví dụ:
-
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 (cũ)
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.
- Xem thêm
-
Tham số key?: string
Khoá thông số nhắm mục tiêu. Khoá này là không bắt buộc; tất cả thông số nhắm mục tiêu sẽ bị xoá nếu bạn không chỉ định. -
Giá trị trả về PubAdsService
Đối tượng dịch vụ mà phương thức được gọi trên đó.
collapseEmptyDivs
-
collapseEmptyDivs(collapseBeforeAdFetch?: boolean): boolean
-
Cho phép thu gọn div vị trí để chúng không chiếm bất kỳ không gian nào trên trang khi không có nội dung quảng cáo nào để hiển thị. Bạn phải đặt chế độ này trước khi bật dịch vụ.
-
Tham số collapseBeforeAdFetch?: boolean
Liệu có thu gọn các vùng ngay cả trước khi quảng cáo được tìm nạp hay không. Tham số này là không bắt buộc; nếu không được cung cấp,false
sẽ được dùng làm giá trị mặc định. -
Giá trị trả về boolean
Trả vềtrue
nếu bật chế độ thu gọn div vàfalse
nếu không thể bật chế độ thu gọn vì phương thức này được gọi sau khi bật dịch vụ.
disableInitialLoad
-
disableInitialLoad(): void
-
Vô hiệu hóa yêu cầu đối với quảng cáo khi tải trang, nhưng cho phép yêu cầu quảng cáo bằng lệnh gọi
PubAdsService.refresh
. Bạn phải đặt thuộc tính này trước khi bật dịch vụ. Bạn phải sử dụng chế độ không đồng bộ; nếu không, bạn sẽ không thể yêu cầu quảng cáo bằngrefresh
.
display
-
display(adUnitPath: string, size: GeneralSize, div?: string | Element, clickUrl?: string): void
-
Tạo và hiển thị một vùng quảng cáo có đường dẫn và kích thước đơn vị quảng cáo nhất định. Phương thức này không hoạt động với chế độ yêu cầu duy nhất.
Lưu ý: Khi phương thức này được gọi, một ảnh chụp nhanh về vùng và trạng thái trang sẽ được tạo để đảm bảo tính nhất quán khi gửi yêu cầu quảng cáo và hiển thị phản hồi. Mọi thay đổi được thực hiện đối với vùng hoặc trạng thái trang sau khi phương pháp này được gọi (bao gồm tiêu chí nhắm mục tiêu, chế độ cài đặt quyền riêng tư, buộc SafeFrame, v.v.) sẽ chỉ áp dụng cho các yêu cầudisplay()
hoặcrefresh()
tiếp theo. -
- Ví dụ:
-
JavaScript
googletag.pubads().display("/1234567/sports", [728, 90], "div-1");
JavaScript (cũ)
googletag.pubads().display("/1234567/sports", [728, 90], "div-1");
TypeScript
googletag.pubads().display("/1234567/sports", [728, 90], "div-1");
- Xem thêm
-
Tham số adUnitPath: string
Đường dẫn đơn vị quảng cáo của vùng sẽ được hiển thị.size: GeneralSize
Chiều rộng và chiều cao của vùng.div?: string | Element
ID của div chứa vị trí hoặc chính phần tử div đó.clickUrl?: string
URL nhấp chuột để sử dụng trên vùng này.
enableLazyLoad
-
enableLazyLoad(config?: { fetchMarginPercent: number, mobileScaling: number, renderMarginPercent: number }): void
-
Bật tính năng tải từng phần trong GPT như được xác định bởi đối tượng cấu hình. Để biết thêm ví dụ chi tiết, hãy xem mẫu Tải từng phần.
Lưu ý: Tính năng tìm nạp từng phần trong SRA chỉ hoạt động nếu tất cả các vị trí đều nằm ngoài lề tìm nạp. -
- Ví dụ:
-
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 (cũ)
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, });
- Xem thêm
-
Tham số config?: { fetchMarginPercent: number, mobileScaling: number, renderMarginPercent: number }
Đối tượng cấu hình cho phép tuỳ chỉnh hành vi tải từng phần. Mọi cấu hình bị bỏ qua sẽ sử dụng chế độ mặc định do Google thiết lập và sẽ được điều chỉnh theo thời gian. Để tắt một chế độ cài đặt cụ thể, chẳng hạn như lề tìm nạp, hãy đặt giá trị thành-1
.fetchMarginPercent
Khoảng cách tối thiểu tính từ khung nhìn hiện tại đến một vùng phải trước khi chúng tôi tìm nạp quảng cáo dưới dạng tỷ lệ phần trăm kích thước khung nhìn. Giá trị 0 có nghĩa là "khi vùng quảng cáo xuất hiện trong khung nhìn", 100 có nghĩa là "khi quảng cáo cách xa 1 khung nhìn", v.v.renderMarginPercent
Khoảng cách tối thiểu tính từ khung nhìn hiện tại đến một vùng trước khi chúng tôi hiển thị quảng cáo. Điều này cho phép tìm nạp trước quảng cáo, nhưng chờ để hiển thị và tải xuống các tài nguyên phụ khác. Giá trị hoạt động giống nhưfetchMarginPercent
dưới dạng phần trăm khung nhìn.mobileScaling
Một hệ số được áp dụng cho lợi nhuận trên thiết bị di động. Điều này cho phép biên lợi nhuận thay đổi trên thiết bị di động so với máy tính để bàn. Ví dụ: giá trị 2.0 sẽ nhân tất cả lề với 2 trên thiết bị di động, làm tăng khoảng cách tối thiểu mà một vị trí có thể đạt được trước khi tìm nạp và hiển thị.
enableSingleRequest
-
enableSingleRequest(): boolean
-
Bật chế độ yêu cầu duy nhất để tìm nạp nhiều quảng cáo cùng lúc. Điều này yêu cầu tất cả các vùng Quảng cáo của nhà xuất bản phải được xác định và thêm vào PubAdsService trước khi bật dịch vụ. Phải đặt chế độ yêu cầu duy nhất trước khi bật dịch vụ.
-
Giá trị trả về boolean
Trả vềtrue
nếu bật chế độ yêu cầu duy nhất vàfalse
nếu không thể bật chế độ yêu cầu duy nhất vì phương thức này được gọi sau khi bật dịch vụ.
enableVideoAds
-
enableVideoAds(): void
-
Báo hiệu cho GPT rằng quảng cáo dạng video sẽ xuất hiện trên trang. Điều này tạo ra các quy tắc ràng buộc loại trừ cạnh tranh đối với quảng cáo hiển thị và quảng cáo dạng video. Nếu đã biết nội dung video, hãy gọi
PubAdsService.setVideoContent
để có thể sử dụng chế độ loại trừ nội dung cho quảng cáo hiển thị. -
get
-
get(key: string): null | string
-
Trả về giá trị cho thuộc tính AdSense được liên kết với khoá đã cho.
-
- Ví dụ:
-
JavaScript
googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().get("adsense_background_color"); // Returns '#FFFFFF'.
JavaScript (cũ)
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'.
- Xem thêm
-
Tham số key: string
Tên của thuộc tính cần tìm. -
Giá trị trả về null | string
Giá trị hiện tại của khoá thuộc tính hoặcnull
nếu không có khoá.
getAttributeKeys
-
getAttributeKeys(): string[]
-
Trả về các khoá thuộc tính đã đặt cho dịch vụ này.
-
- Ví dụ:
-
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 (cũ)
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'].
-
Giá trị trả về string[]
Mảng khoá thuộc tính được đặt trên dịch vụ này. Chưa xác định thứ tự.
getTargeting
-
getTargeting(key: string): string[]
-
Trả về một thông số nhắm mục tiêu cấp dịch vụ tuỳ chỉnh cụ thể đã được đặt.
-
- Ví dụ:
-
JavaScript
googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().getTargeting("interests"); // Returns ['sports']. googletag.pubads().getTargeting("age"); // Returns [] (empty array).
JavaScript (cũ)
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).
-
Tham số key: string
Khoá nhắm mục tiêu cần tìm. -
Giá trị trả về string[]
Các giá trị được liên kết với khóa này hoặc một mảng trống nếu không có khóa như vậy.
getTargetingKeys
-
getTargetingKeys(): string[]
-
Trả về danh sách tất cả các khoá nhắm mục tiêu cấp dịch vụ tuỳ chỉnh đã được đặt.
-
- Ví dụ:
-
JavaScript
googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().getTargetingKeys(); // Returns ['interests', 'colors'].
JavaScript (cũ)
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'].
-
Giá trị trả về string[]
Mảng khoá nhắm mục tiêu. Chưa xác định thứ tự.
isInitialLoadDisabled
-
isInitialLoadDisabled(): boolean
-
Trả về các yêu cầu ban đầu cho quảng cáo có bị tắt thành công bởi lệnh gọi
PubAdsService.disableInitialLoad
trước đó hay không. -
-
Giá trị trả về boolean
Trả vềtrue
nếu lệnh gọi trước đó đếnPubAdsService.disableInitialLoad
thành công, nếu không thìfalse
.
refresh
-
refresh(slots?: null | Slot[], options?: { changeCorrelator: boolean }): void
-
Tìm nạp và hiển thị quảng cáo mới cho các vùng cụ thể hoặc tất cả các vùng trên trang. Chỉ hoạt động trong chế độ hiển thị không đồng bộ.
Để hoạt động bình thường trên tất cả các trình duyệt, lệnh gọirefresh
phải được thực hiện trước lệnh gọi đếndisplay
vùng quảng cáo. Nếu lệnh gọi đếndisplay
bị bỏ qua, tính năng làm mới có thể hoạt động không như mong đợi. Nếu muốn, bạn có thể sử dụng phương phápPubAdsService.disableInitialLoad
để ngăndisplay
tìm nạp quảng cáo.
Việc làm mới một vùng sẽ xóa quảng cáo cũ khỏi số lượt xem trang dài hạn của GPT, vì vậy, các yêu cầu trong tương lai sẽ không bị ảnh hưởng bởi kỹ thuật khoanh vùng hoặc loại trừ cạnh tranh liên quan đến quảng cáo đó. -
- Ví dụ:
-
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 (cũ)
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 });
- Xem thêm
-
Tham số slots?: null | Slot[]
Các khe cần làm mới. Mảng là không bắt buộc; tất cả vị trí sẽ được làm mới nếu không được chỉ định.options?: { changeCorrelator: boolean }
Các lựa chọn cấu hình được liên kết với lệnh gọi làm mới này.changeCorrelator
Chỉ định xem có cần tạo một giá trị tương quan mới để tìm nạp quảng cáo hay không. Máy chủ quảng cáo của chúng tôi duy trì giá trị tương quan này trong thời gian ngắn (hiện là trong 30 giây, nhưng có thể thay đổi), những yêu cầu đó với cùng một giá trị tương quan đã nhận được gần nhau sẽ được coi là một lượt xem trang. Theo mặc định, một giá trị tương quan mới được tạo cho mỗi lần làm mới.
Lưu ý: tùy chọn này không ảnh hưởng đến số lần xem trang dài hạn của GPT, tùy chọn này tự động phản ánh các quảng cáo hiện có trên trang và không có thời gian hết hạn.
set
-
set(key: string, value: string): PubAdsService
-
Đặt giá trị cho các thuộc tính AdSense áp dụng cho tất cả các vùng quảng cáo trong dịch vụ Quảng cáo của nhà xuất bản.
Việc gọi lệnh này nhiều lần cho cùng một khoá sẽ ghi đè các giá trị đã đặt trước đó cho khoá đó. Tất cả các giá trị phải được đặt trước khi gọidisplay
hoặcrefresh
. -
- Ví dụ:
-
JavaScript
googletag.pubads().set("adsense_background_color", "#FFFFFF");
JavaScript (cũ)
googletag.pubads().set("adsense_background_color", "#FFFFFF");
TypeScript
googletag.pubads().set("adsense_background_color", "#FFFFFF");
- Xem thêm
-
Tham số key: string
Tên của thuộc tính.value: string
Giá trị thuộc tính. -
Giá trị trả về PubAdsService
Đối tượng dịch vụ mà phương thức được gọi trên đó.
setCategoryExclusion
-
setCategoryExclusion(categoryExclusion: string): PubAdsService
-
Đặt loại trừ danh mục quảng cáo cấp độ trang cho tên nhãn đã cho.
-
- Ví dụ:
-
JavaScript
// Label = AirlineAd. googletag.pubads().setCategoryExclusion("AirlineAd");
JavaScript (cũ)
// Label = AirlineAd. googletag.pubads().setCategoryExclusion("AirlineAd");
TypeScript
// Label = AirlineAd. googletag.pubads().setCategoryExclusion("AirlineAd");
- Xem thêm
-
Tham số categoryExclusion: string
Nhãn loại trừ danh mục quảng cáo cần thêm. -
Giá trị trả về PubAdsService
Đối tượng dịch vụ mà phương thức được gọi trên đó.
setCentering
-
setCentering(centerAds: boolean): void
-
Bật và tắt tính năng căn giữa quảng cáo theo chiều ngang. Tính năng căn giữa được tắt theo mặc định. Trong gpt_mobile.js cũ, căn giữa được bật theo mặc định.
Phương thức này phải được gọi trước khi gọidisplay
hoặcrefresh
vì chỉ những quảng cáo được yêu cầu sau khi gọi phương thức này mới được căn giữa. -
- Ví dụ:
-
JavaScript
// Make ads centered. googletag.pubads().setCentering(true);
JavaScript (cũ)
// Make ads centered. googletag.pubads().setCentering(true);
TypeScript
// Make ads centered. googletag.pubads().setCentering(true);
-
Tham số centerAds: boolean
true
để căn giữa quảng cáo,false
để căn trái chúng.
setForceSafeFrame
-
setForceSafeFrame(forceSafeFrame: boolean): PubAdsService
-
Thiết lập xem liệu tất cả quảng cáo trên trang có bắt buộc phải hiển thị bằng vùng chứa SafeFrame hay không.
Vui lòng ghi nhớ những điều sau khi sử dụng API này:- Chế độ cài đặt này sẽ chỉ có hiệu lực cho các yêu cầu quảng cáo tiếp theo được thực hiện cho các vùng tương ứng.
- Cài đặt cấp độ vùng, nếu được chỉ định, sẽ luôn ghi đè cài đặt cấp độ trang.
- Nếu được đặt thành
true
(ở cấp vùng hoặc cấp trang), quảng cáo sẽ luôn hiển thị khi sử dụng vùng chứa SafeFrame độc lập với lựa chọn được thực hiện trong giao diện người dùng Google Ad Manager. - Tuy nhiên, nếu đặt thành
false
hoặc không chỉ định, thì quảng cáo sẽ hiển thị bằng vùng chứa SafeFrame tùy thuộc vào loại quảng cáo và lựa chọn được thực hiện trong giao diện người dùng Google Ad Manager. - Bạn nên thận trọng khi sử dụng API này vì nó có thể ảnh hưởng đến hành vi của những mẫu quảng cáo tìm cách thoát khỏi iFrame hoặc khiến mẫu quảng cáo không hiển thị trực tiếp trên trang của nhà xuất bản.
-
- Ví dụ:
-
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 (cũ)
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");
- Xem thêm
-
Tham số forceSafeFrame: boolean
true
để buộc tất cả quảng cáo trên trang hiển thị trong SafeFrame vàfalse
thay đổi chế độ cài đặt trước đó thành false. Việc đặt thuộc tính này thànhfalse
khi chưa chỉ định trước đó sẽ không thay đổi gì. -
Giá trị trả về PubAdsService
Đối tượng dịch vụ nơi hàm được gọi.
setLocation
-
setLocation(address: string): PubAdsService
-
Truyền thông tin vị trí từ các trang web để bạn có thể nhắm mục tiêu theo địa lý đến các vị trí cụ thể.
-
- Ví dụ:
-
JavaScript
// Postal code: googletag.pubads().setLocation("10001,US");
JavaScript (cũ)
// Postal code: googletag.pubads().setLocation("10001,US");
TypeScript
// Postal code: googletag.pubads().setLocation("10001,US");
-
Tham số address: string
Địa chỉ dạng tự do. -
Giá trị trả về PubAdsService
Đối tượng dịch vụ mà phương thức được gọi trên đó.
setPrivacySettings
-
setPrivacySettings(privacySettings: PrivacySettingsConfig): PubAdsService
-
Cho phép định cấu hình tất cả các chế độ cài đặt quyền riêng tư từ một API bằng cách sử dụng đối tượng cấu hình.
-
- Ví dụ:
-
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 (cũ)
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, });
- Xem thêm
-
Tham số privacySettings: PrivacySettingsConfig
Đối tượng chứa cấu hình chế độ cài đặt quyền riêng tư. -
Giá trị trả về PubAdsService
Đối tượng dịch vụ nơi hàm được gọi.
setPublisherProvidedId
-
setPublisherProvidedId(ppid: string): PubAdsService
-
Đặt giá trị cho mã do nhà xuất bản cung cấp.
-
- Ví dụ:
-
JavaScript
googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
JavaScript (cũ)
googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
TypeScript
googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
- Xem thêm
-
Tham số ppid: string
Mã chứa chữ và số do nhà xuất bản cung cấp. Phải có từ 32 đến 150 ký tự. -
Giá trị trả về PubAdsService
Đối tượng dịch vụ mà phương thức được gọi trên đó.
setSafeFrameConfig
-
setSafeFrameConfig(config: SafeFrameConfig): PubAdsService
-
Đặt lựa chọn ưu tiên cấp trang cho cấu hình SafeFrame. Mọi khoá không nhận dạng được trong đối tượng cấu hình sẽ bị bỏ qua. Toàn bộ cấu hình sẽ bị bỏ qua nếu bạn chuyển giá trị không hợp lệ cho một khoá đã được nhận dạng.
Các lựa chọn ưu tiên ở cấp trang sẽ bị ghi đè bằng lựa chọn ưu tiên ở cấp vùng, nếu bạn chỉ định. -
- Ví dụ:
-
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 (cũ)
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");
- Xem thêm
-
Tham số config: SafeFrameConfig
Đối tượng cấu hình. -
Giá trị trả về PubAdsService
Đối tượng dịch vụ mà phương thức được gọi trên đó.
setTargeting
-
setTargeting(key: string, value: string | string[]): PubAdsService
-
Đặt tham số nhắm mục tiêu tuỳ chỉnh cho một khoá nhất định áp dụng cho tất cả các vùng quảng cáo dịch vụ Quảng cáo của nhà xuất bản. Việc gọi phương thức này nhiều lần cho cùng một khoá sẽ ghi đè các giá trị cũ. Các khóa này được xác định trong tài khoản Google Ad Manager của bạn.
-
- Ví dụ:
-
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 (cũ)
// 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"]);
- Xem thêm
-
Tham số key: string
Khoá thông số nhắm mục tiêu.value: string | string[]
Giá trị thông số nhắm mục tiêu hoặc mảng giá trị. -
Giá trị trả về PubAdsService
Đối tượng dịch vụ mà phương thức được gọi trên đó.
setVideoContent
-
setVideoContent(videoContentId: string, videoCmsId: string): void
-
Thiết lập thông tin nội dung video cần gửi cùng với yêu cầu quảng cáo cho mục đích nhắm mục tiêu và loại trừ nội dung. Quảng cáo dạng video sẽ tự động bật khi phương thức này được gọi. Đối với
videoContentId
vàvideoCmsId
, hãy sử dụng các giá trị được cung cấp cho dịch vụ nhập nội dung Google Ad Manager. -
- Xem thêm
-
Tham số videoContentId: string
Mã nội dung video.videoCmsId: string
Mã CMS của video.
updateCorrelator
-
updateCorrelator(): PubAdsService
-
Thay đổi giá trị tương quan được gửi cùng với yêu cầu quảng cáo, bắt đầu hiệu quả một lượt xem trang mới. Giá trị tương quan là giống nhau cho tất cả các yêu cầu quảng cáo đến từ một lượt xem trang và là duy nhất trên các lượt xem trang. Chỉ áp dụng cho chế độ không đồng bộ.
Lưu ý: điều này không ảnh hưởng đến số lần xem trang dài hạn của GPT, vốn tự động phản ánh quảng cáo thực sự trên trang và không có thời gian hết hạn. -
- Ví dụ:
-
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 (cũ)
// 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.
-
Giá trị trả về PubAdsService
Đối tượng dịch vụ nơi hàm được gọi.
googletag.ResponseInformation
Một đối tượng đại diện cho một lượt phản hồi quảng cáo.
Tóm tắt thuộc tính | |
---|---|
advertiserId
|
Mã nhận dạng của nhà quảng cáo.
|
campaignId
|
Mã của chiến dịch.
|
creativeId
|
Mã của mẫu quảng cáo.
|
creativeTemplateId
|
Mã mẫu của quảng cáo.
|
lineItemId
|
Mã của mục hàng.
|
- Xem thêm
advertiserId
-
advertiserId: null | number
-
Mã nhận dạng của nhà quảng cáo.
-
campaignId
-
campaignId: null | number
-
Mã của chiến dịch.
-
creativeId
-
creativeId: null | number
-
Mã của mẫu quảng cáo.
-
creativeTemplateId
-
creativeTemplateId: null | number
-
Mã mẫu của quảng cáo.
-
lineItemId
-
lineItemId: null | number
-
Mã của mục hàng.
-
googletag.RewardedPayload
Một đối tượng đại diện cho phần thưởng được liên kết với một quảng cáo có tặng thưởng
Tóm tắt thuộc tính | |
---|---|
amount
|
Số lượng mặt hàng có trong phần thưởng.
|
type
|
Loại mặt hàng được đưa vào phần thưởng (ví dụ: "xu").
|
- Xem thêm
amount
-
amount: number
-
Số lượng mặt hàng có trong phần thưởng.
-
type
-
type: string
-
Loại mặt hàng được đưa vào phần thưởng (ví dụ: "xu").
-
googletag.SafeFrameConfig
Đối tượng cấu hình cho vùng chứa SafeFrame.
Tóm tắt thuộc tính | |
---|---|
allowOverlayExpansion
|
Liệu SafeFrame có cho phép nội dung quảng cáo mở rộng bằng cách che phủ nội dung trang hay không.
|
allowPushExpansion
|
Liệu SafeFrame có cho phép nội dung quảng cáo mở rộng bằng cách đẩy nội dung trang hay không.
|
sandbox
|
Liệu SafeFrame có nên sử dụng thuộc tính hộp cát HTML5 để ngăn việc di chuyển ở cấp cao nhất mà không có sự tương tác của người dùng hay không.
|
useUniqueDomain
|
Không dùng nữa.
Liệu SafeFrame có nên sử dụng miền con ngẫu nhiên cho mẫu quảng cáo đặt trước hay không.
|
- Xem thêm
allowOverlayExpansion
-
allowOverlayExpansion: boolean
-
Liệu SafeFrame có cho phép nội dung quảng cáo mở rộng bằng cách che phủ nội dung trang hay không.
-
allowPushExpansion
-
allowPushExpansion: boolean
-
Liệu SafeFrame có cho phép nội dung quảng cáo mở rộng bằng cách đẩy nội dung trang hay không.
-
sandbox
-
sandbox: boolean
-
Liệu SafeFrame có nên sử dụng thuộc tính hộp cát HTML5 để ngăn việc di chuyển ở cấp cao nhất mà không có sự tương tác của người dùng hay không. Giá trị hợp lệ duy nhất là
true
(không thể buộc phải làfalse
). Lưu ý rằng thuộc tính hộp cát sẽ tắt các trình bổ trợ (ví dụ: Flash). -
useUniqueDomain
-
useUniqueDomain: null | boolean
-
Liệu SafeFrame có nên sử dụng miền con ngẫu nhiên cho mẫu quảng cáo đặt trước hay không. Truyền vào
null
để xoá giá trị đã lưu.
Lưu ý: tính năng này được bật theo mặc định.
googletag.Service
Lớp dịch vụ cơ sở chứa các phương thức phổ biến cho mọi dịch vụ.
Tóm tắt phương pháp | |
---|---|
addEventListener
|
Đăng ký một trình nghe cho phép bạn thiết lập và gọi hàm JavaScript khi một sự kiện GPT cụ thể xảy ra trên trang.
|
getSlots
|
Lấy danh sách vùng quảng cáo được liên kết với dịch vụ này.
|
removeEventListener
|
Xoá trình nghe đã đăng ký trước đó.
|
addEventListener
-
addEventListener<K extends keyof EventTypeMap>(eventType: K, listener: (arg: EventTypeMap[K]) => void): Service
-
Đăng ký một trình nghe cho phép bạn thiết lập và gọi hàm JavaScript khi một sự kiện GPT cụ thể xảy ra trên trang. Sau đây là các sự kiện được hỗ trợ:
Một đối tượng thuộc loại sự kiện thích hợp sẽ được truyền đến trình nghe khi được gọi. -
- Ví dụ:
-
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 (cũ)
// 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. } });
- Xem thêm
-
Tham số eventType: K
Một chuỗi biểu thị loại sự kiện do GPT tạo. Loại sự kiện có phân biệt chữ hoa chữ thường.listener: (arg: EventTypeMap[K]) => void
Hàm lấy một đối tượng sự kiện đơn. -
Giá trị trả về Service
Đối tượng dịch vụ mà phương thức được gọi trên đó.
getSlots
removeEventListener
-
removeEventListener<K extends keyof EventTypeMap>(eventType: K, listener: (event: EventTypeMap[K]) => void): void
-
Xoá trình nghe đã đăng ký trước đó.
-
- Ví dụ:
-
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 (cũ)
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(); });
-
Tham số eventType: K
Một chuỗi biểu thị loại sự kiện do GPT tạo. Loại sự kiện có phân biệt chữ hoa chữ thường.listener: (event: EventTypeMap[K]) => void
Hàm lấy một đối tượng sự kiện đơn.
googletag.SizeMappingBuilder
Trình tạo dành cho các đối tượng thông số kỹ thuật liên kết kích thước. Trình tạo này được cung cấp để giúp dễ dàng xây dựng thông số kỹ thuật về kích thước.
Tóm tắt phương pháp | |
---|---|
addSize
|
Thêm ánh xạ từ một mảng kích thước đơn (đại diện cho khung nhìn) đến một mảng một hoặc nhiều kích thước đại diện cho vị trí.
|
build
|
Xây dựng thông số kỹ thuật của bản đồ kích thước từ các liên kết được thêm vào trình tạo này.
|
addSize
-
addSize(viewportSize: SingleSizeArray, slotSize: GeneralSize): SizeMappingBuilder
-
Thêm ánh xạ từ một mảng kích thước đơn (đại diện cho khung nhìn) đến một mảng một hoặc nhiều kích thước đại diện cho vị trí.
-
- Ví dụ:
-
JavaScript
// Mapping 1 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], [728, 90]) .addSize([640, 480], "fluid") .addSize([0, 0], [88, 31]) // All viewports < 640x480 .build(); // Mapping 2 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], []) .addSize([640, 480], [120, 60]) .addSize([0, 0], []) .build(); // Mapping 2 will not show any ads for the following viewport sizes: // [1024, 768] > size >= [980, 690] and // [640, 480] > size >= [0, 0]
JavaScript (cũ)
// Mapping 1 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], [728, 90]) .addSize([640, 480], "fluid") .addSize([0, 0], [88, 31]) // All viewports < 640x480 .build(); // Mapping 2 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], []) .addSize([640, 480], [120, 60]) .addSize([0, 0], []) .build(); // Mapping 2 will not show any ads for the following viewport sizes: // [1024, 768] > size >= [980, 690] and // [640, 480] > size >= [0, 0]
TypeScript
// Mapping 1 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], [728, 90]) .addSize([640, 480], "fluid") .addSize([0, 0], [88, 31]) // All viewports < 640x480 .build(); // Mapping 2 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], []) .addSize([640, 480], [120, 60]) .addSize([0, 0], []) .build(); // Mapping 2 will not show any ads for the following viewport sizes: // [1024, 768] > size >= [980, 690] and // [640, 480] > size >= [0, 0]
-
Tham số viewportSize: SingleSizeArray
Kích thước của khung nhìn cho mục ánh xạ này.slotSize: GeneralSize
Kích thước của vị trí cho mục liên kết này. -
Giá trị trả về SizeMappingBuilder
Tham chiếu đến trình tạo này.
build
-
build(): null | SizeMappingArray
-
Tạo thông số kỹ thuật của bản đồ kích thước từ các mối liên kết được thêm vào trình tạo này.
Nếu bạn đã cung cấp bất kỳ mối liên kết không hợp lệ nào, phương thức này sẽ trả vềnull
. Nếu không, hàm này sẽ trả về thông số kỹ thuật ở định dạng chính xác để chuyển tớiSlot.defineSizeMapping
.
Lưu ý: hành vi của trình tạo sau khi gọi phương thức này không xác định. -
-
Giá trị trả về null | SizeMappingArray
Kết quả do trình tạo này tạo ra. Có thể có giá trị rỗng nếu bạn cung cấp các mục ánh xạ kích thước không hợp lệ.
googletag.Slot
Vị trí là đối tượng đại diện cho một vùng quảng cáo duy nhất trên trang.
Tóm tắt phương pháp | |
---|---|
addService
|
Thêm
Service vào vị trí này.
|
clearCategoryExclusions
|
Xóa tất cả các nhãn loại trừ danh mục quảng cáo cấp vùng cho vùng này.
|
clearTargeting
|
Xóa thông số cụ thể hoặc tất cả thông số nhắm mục tiêu cấp vùng tùy chỉnh cho vùng này.
|
defineSizeMapping
|
Đặt một mảng ánh xạ từ kích thước khung nhìn tối thiểu đến kích thước vùng cho vùng này.
|
get
|
Trả về giá trị cho thuộc tính AdSense được liên kết với khoá đã cho cho vị trí này.
|
getAdUnitPath
|
Trả về đường dẫn đầy đủ của đơn vị quảng cáo, cùng với mã mạng và đường dẫn đơn vị quảng cáo.
|
getAttributeKeys
|
Trả về danh sách các khoá thuộc tính được đặt trên vị trí này.
|
getCategoryExclusions
|
Trả về các nhãn loại trừ danh mục quảng cáo cho vùng này.
|
getResponseInformation
|
Trả về thông tin phản hồi quảng cáo.
|
getSlotElementId
|
Trả về mã nhận dạng vùng
div đã cung cấp khi vùng đó được xác định.
|
getTargeting
|
Trả về một thông số nhắm mục tiêu tuỳ chỉnh cụ thể được đặt trên vùng này.
|
getTargetingKeys
|
Trả về danh sách tất cả các khoá nhắm mục tiêu tuỳ chỉnh được đặt trên vùng này.
|
set
|
Đặt một giá trị cho thuộc tính AdSense trên vùng quảng cáo này.
|
setCategoryExclusion
|
Đặt nhãn loại trừ danh mục quảng cáo cấp vùng trên vùng này.
|
setClickUrl
|
Đặt URL nhấp chuột mà người dùng sẽ được chuyển hướng đến sau khi nhấp vào quảng cáo.
|
setCollapseEmptyDiv
|
Đặt xem có nên ẩn vùng
div hay không khi không có quảng cáo nào trong vùng đó.
|
setConfig
|
Đặt các tuỳ chọn cấu hình chung cho vị trí này.
|
setForceSafeFrame
|
Định cấu hình xem quảng cáo trong vùng này có bắt buộc phải hiển thị bằng cách sử dụng vùng chứa SafeFrame hay không.
|
setSafeFrameConfig
|
Đặt lựa chọn ưu tiên ở cấp vùng cho cấu hình SafeFrame.
|
setTargeting
|
Đặt tham số nhắm mục tiêu tuỳ chỉnh cho vùng này.
|
updateTargetingFromMap
|
Đặt tham số nhắm mục tiêu tuỳ chỉnh cho vị trí này, từ bản đồ key:value trong đối tượng JSON.
|
addService
-
Thêm
Service
vào vị trí này. -
- Ví dụ:
-
JavaScript
googletag.defineSlot("/1234567/sports", [160, 600], "div").addService(googletag.pubads());
JavaScript (cũ)
googletag.defineSlot("/1234567/sports", [160, 600], "div").addService(googletag.pubads());
TypeScript
googletag.defineSlot("/1234567/sports", [160, 600], "div")!.addService(googletag.pubads());
- Xem thêm
-
Tham số service: Service
Dịch vụ sẽ được thêm. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
clearCategoryExclusions
-
clearCategoryExclusions(): Slot
-
Xóa tất cả các nhãn loại trừ danh mục quảng cáo cấp vùng cho vùng này.
-
- Ví dụ:
-
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 (cũ)
// 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.
-
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
clearTargeting
-
clearTargeting(key?: string): Slot
-
Xóa thông số cụ thể hoặc tất cả thông số nhắm mục tiêu cấp vùng tùy chỉnh cho vùng này.
-
- Ví dụ:
-
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 (cũ)
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.
- Xem thêm
-
Tham số key?: string
Khoá thông số nhắm mục tiêu. Khoá này là không bắt buộc; tất cả thông số nhắm mục tiêu sẽ bị xoá nếu bạn không chỉ định. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
defineSizeMapping
-
defineSizeMapping(sizeMapping: SizeMappingArray): Slot
-
Đặt một mảng ánh xạ từ kích thước khung nhìn tối thiểu đến kích thước vùng cho vùng này.
-
- Ví dụ:
-
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 (cũ)
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!);
- Xem thêm
-
Tham số sizeMapping: SizeMappingArray
Mảng ánh xạ kích thước. Bạn có thể dùngSizeMappingBuilder
để tạo lớp này. Mỗi mục ánh xạ kích thước là một mảng gồm hai phần tử:SingleSizeArray
vàGeneralSize
. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
get
-
get(key: string): null | string
-
Trả về giá trị cho thuộc tính AdSense được liên kết với khoá đã cho cho vị trí này. Để xem các thuộc tính cấp dịch vụ được vùng này kế thừa, hãy sử dụng
PubAdsService.get
. -
- Ví dụ:
-
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 (cũ)
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'.
- Xem thêm
-
Tham số key: string
Tên của thuộc tính cần tìm. -
Giá trị trả về null | string
Giá trị hiện tại của khoá thuộc tính hoặcnull
nếu không có khoá.
getAdUnitPath
-
getAdUnitPath(): string
-
Trả về đường dẫn đầy đủ của đơn vị quảng cáo, cùng với mã mạng và đường dẫn đơn vị quảng cáo.
-
- Ví dụ:
-
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getAdUnitPath(); // Returns '/1234567/sports'.
JavaScript (cũ)
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'.
-
Giá trị trả về string
Đường dẫn đơn vị quảng cáo.
getAttributeKeys
-
getAttributeKeys(): string[]
-
Trả về danh sách các khoá thuộc tính được đặt trên vị trí này. Để xem các khoá của các thuộc tính cấp dịch vụ được vùng này kế thừa, hãy sử dụng
PubAdsService.getAttributeKeys
. -
- Ví dụ:
-
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 (cũ)
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'].
-
Giá trị trả về string[]
Mảng khoá thuộc tính. Chưa xác định thứ tự.
getCategoryExclusions
-
getCategoryExclusions(): string[]
-
Trả về các nhãn loại trừ danh mục quảng cáo cho vùng này.
-
- Ví dụ:
-
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .setCategoryExclusion("TrainAd") .addService(googletag.pubads()); slot.getCategoryExclusions(); // Returns ['AirlineAd', 'TrainAd'].
JavaScript (cũ)
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'].
-
Giá trị trả về string[]
Các nhãn loại trừ danh mục quảng cáo cho vùng này hoặc một mảng trống nếu bạn chưa đặt nhãn nào.
getResponseInformation
-
getResponseInformation(): null | ResponseInformation
-
Trả về thông tin phản hồi quảng cáo. Điều này dựa trên phản hồi quảng cáo gần đây nhất cho vùng đó. Nếu lệnh này được gọi khi vùng không có quảng cáo, thì
null
sẽ được trả về. -
-
Giá trị trả về null | ResponseInformation
Thông tin phản hồi quảng cáo mới nhất hoặcnull
nếu vùng không có quảng cáo.
getSlotElementId
-
getSlotElementId(): string
-
Trả về mã nhận dạng vùng
div
đã cung cấp khi vùng đó được xác định. -
- Ví dụ:
-
JavaScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getSlotElementId(); // Returns 'div-1'.
JavaScript (cũ)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getSlotElementId(); // Returns 'div-1'.
TypeScript
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); slot.getSlotElementId(); // Returns 'div-1'.
-
Giá trị trả về string
Mã vị trídiv
.
getTargeting
-
getTargeting(key: string): string[]
-
Trả về một thông số nhắm mục tiêu tuỳ chỉnh cụ thể được đặt trên vùng này. Các thông số nhắm mục tiêu cấp dịch vụ không được đưa vào.
-
- Ví dụ:
-
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 (cũ)
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).
-
Tham số key: string
Khoá nhắm mục tiêu cần tìm. -
Giá trị trả về string[]
Các giá trị được liên kết với khóa này hoặc một mảng trống nếu không có khóa như vậy.
getTargetingKeys
-
getTargetingKeys(): string[]
-
Trả về danh sách tất cả các khoá nhắm mục tiêu tuỳ chỉnh được đặt trên vùng này. Không bao gồm các khoá nhắm mục tiêu cấp dịch vụ.
-
- Ví dụ:
-
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 (cũ)
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'].
-
Giá trị trả về string[]
Mảng khoá nhắm mục tiêu. Chưa xác định thứ tự.
set
-
set(key: string, value: string): Slot
-
Đặt một giá trị cho thuộc tính AdSense trên vùng quảng cáo này. Thao tác này sẽ ghi đè mọi giá trị được đặt ở cấp dịch vụ cho khoá này.
Việc gọi phương thức này nhiều lần cho cùng một khoá sẽ ghi đè các giá trị đã đặt trước đó cho khoá đó. Tất cả các giá trị phải được đặt trước khi gọidisplay
hoặcrefresh
. -
- Ví dụ:
-
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 (cũ)
// 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());
- Xem thêm
-
Tham số key: string
Tên của thuộc tính.value: string
Giá trị thuộc tính. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
setCategoryExclusion
-
setCategoryExclusion(categoryExclusion: string): Slot
-
Đặt nhãn loại trừ danh mục quảng cáo cấp vùng trên vùng này.
-
- Ví dụ:
-
JavaScript
// Label = AirlineAd googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .addService(googletag.pubads());
JavaScript (cũ)
// 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());
- Xem thêm
-
Tham số categoryExclusion: string
Nhãn loại trừ danh mục quảng cáo cần thêm. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
setClickUrl
-
setClickUrl(value: string): Slot
-
Đặt URL nhấp chuột mà người dùng sẽ được chuyển hướng đến sau khi nhấp vào quảng cáo.
Máy chủ Google Ad Manager vẫn ghi lại lượt nhấp ngay cả khi URL nhấp chuột được thay thế. Mọi URL trang đích liên kết với mẫu quảng cáo được phân phát đều được thêm vào giá trị đã cung cấp. Các lệnh gọi tiếp theo sẽ ghi đè giá trị này. Điều này chỉ áp dụng cho các yêu cầu không có SRA. -
- Ví dụ:
-
JavaScript
googletag .defineSlot("/1234567/sports", [160, 600], "div") .setClickUrl("http://www.example.com?original_click_url=") .addService(googletag.pubads());
JavaScript (cũ)
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());
-
Tham số value: string
URL nhấp để đặt. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
setCollapseEmptyDiv
-
setCollapseEmptyDiv(collapse: boolean, collapseBeforeAdFetch?: boolean): Slot
-
Đặt xem có nên ẩn vùng
div
hay không khi không có quảng cáo nào trong vùng đó. Thao tác này sẽ ghi đè chế độ cài đặt cấp dịch vụ. -
- Ví dụ:
-
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 (cũ)
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.
- Xem thêm
-
Tham số collapse: boolean
Liệu có thu gọn vùng nếu không có quảng cáo nào được trả về.collapseBeforeAdFetch?: boolean
Liệu có thu gọn vùng ngay cả trước khi tìm nạp quảng cáo hay không. Bỏ qua nếu giá trị thu gọn không phải làtrue
. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
setConfig
-
setConfig(slotConfig: SlotSettingsConfig): void
-
Đặt các tuỳ chọn cấu hình chung cho vị trí này.
-
-
Tham số slotConfig: SlotSettingsConfig
Đối tượng cấu hình.
setForceSafeFrame
-
setForceSafeFrame(forceSafeFrame: boolean): Slot
-
Thiết lập xem liệu quảng cáo trong vùng này có bắt buộc phải hiển thị bằng cách sử dụng vùng chứa SafeFrame hay không.
Vui lòng ghi nhớ những điều sau khi sử dụng API này:- Chế độ cài đặt này sẽ chỉ có hiệu lực cho các yêu cầu quảng cáo tiếp theo được thực hiện cho các vùng tương ứng.
- Cài đặt cấp độ vùng, nếu được chỉ định, sẽ luôn ghi đè cài đặt cấp độ trang.
- Nếu được đặt thành
true
(ở cấp vùng hoặc cấp trang), quảng cáo sẽ luôn hiển thị khi sử dụng vùng chứa SafeFrame độc lập với lựa chọn được thực hiện trong giao diện người dùng Google Ad Manager. - Tuy nhiên, nếu đặt thành
false
hoặc không chỉ định, thì quảng cáo sẽ hiển thị bằng vùng chứa SafeFrame tùy thuộc vào loại quảng cáo và lựa chọn được thực hiện trong giao diện người dùng Google Ad Manager. - Bạn nên thận trọng khi sử dụng API này vì nó có thể ảnh hưởng đến hành vi của những mẫu quảng cáo tìm cách thoát khỏi iFrame hoặc khiến mẫu quảng cáo không hiển thị trực tiếp trên trang của nhà xuất bản.
-
- Ví dụ:
-
JavaScript
googletag .defineSlot("/1234567/sports", [160, 600], "div") .setForceSafeFrame(true) .addService(googletag.pubads());
JavaScript (cũ)
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());
- Xem thêm
-
Tham số forceSafeFrame: boolean
true
để buộc tất cả quảng cáo trong vùng này hiển thị trong SafeFrame vàfalse
chọn không sử dụng tùy chọn cài đặt cấp trang (nếu có). Việc đặt giá trị này thànhfalse
khi không được chỉ định ở cấp trang sẽ không thay đổi gì. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
setSafeFrameConfig
-
setSafeFrameConfig(config: null | SafeFrameConfig): Slot
-
Đặt lựa chọn ưu tiên ở cấp vùng cho cấu hình SafeFrame. Mọi khoá không nhận dạng được trong đối tượng cấu hình sẽ bị bỏ qua. Toàn bộ cấu hình sẽ bị bỏ qua nếu bạn chuyển giá trị không hợp lệ cho một khoá đã được nhận dạng.
Các lựa chọn ưu tiên ở cấp vùng này, nếu được chỉ định, sẽ ghi đè mọi lựa chọn ưu tiên ở cấp trang. -
- Ví dụ:
-
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 (cũ)
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");
- Xem thêm
-
Tham số config: null | SafeFrameConfig
Đối tượng cấu hình. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
setTargeting
-
setTargeting(key: string, value: string | string[]): Slot
-
Đặt tham số nhắm mục tiêu tuỳ chỉnh cho vùng này. Việc gọi phương thức này nhiều lần cho cùng một khoá sẽ ghi đè các giá trị cũ. Các giá trị được đặt tại đây sẽ ghi đè các thông số nhắm mục tiêu được đặt ở cấp dịch vụ. Các khóa này được xác định trong tài khoản Google Ad Manager của bạn.
-
- Ví dụ:
-
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 (cũ)
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"]);
- Xem thêm
-
Tham số key: string
Khoá thông số nhắm mục tiêu.value: string | string[]
Giá trị thông số nhắm mục tiêu hoặc mảng giá trị. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
updateTargetingFromMap
-
updateTargetingFromMap(map: { [adUnitPath: string]: string | string[] }): Slot
-
Đặt tham số nhắm mục tiêu tuỳ chỉnh cho vị trí này, từ bản đồ key:value trong đối tượng JSON. Điều này cũng giống như việc gọi
Slot.setTargeting
cho tất cả giá trị khoá của đối tượng. Các khoá này được xác định trong tài khoản Google Ad Manager của bạn.
Lưu ý:- Trong trường hợp ghi đè, chỉ giá trị cuối cùng được giữ lại.
- Nếu giá trị là một mảng, thì mọi giá trị trước đó sẽ bị ghi đè chứ không được hợp nhất.
- Các giá trị được đặt tại đây sẽ ghi đè các thông số nhắm mục tiêu được đặt ở cấp dịch vụ.
-
- Ví dụ:
-
JavaScript
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div"); slot.updateTargetingFromMap({ color: "red", interests: ["sports", "music", "movies"], });
JavaScript (cũ)
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"], });
-
Tham số map: { [adUnitPath: string]: string | string[] }
Bản đồ khoá thông số nhắm mục tiêu:giá trị. -
Giá trị trả về Slot
Đối tượng khe mà phương thức được gọi.
googletag.config.AdExpansionConfig
Chế độ cài đặt để kiểm soát tính năng mở rộng quảng cáo.
Tóm tắt thuộc tính | |
---|---|
enabled
|
Xem bạn đang bật hay tắt tính năng mở rộng quảng cáo.
|
- Ví dụ:
-
JavaScript
// Enable ad slot expansion across the entire page. googletag.setConfig({ adExpansion: { enabled: true }, });
JavaScript (cũ)
// 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 }, });
enabled
-
enabled: boolean
-
Cho dù bật hay tắt tính năng mở rộng quảng cáo.
Việc đặt giá trị này sẽ ghi đè giá trị mặc định được định cấu hình trong Google Ad Manager.
googletag.config.ComponentAuctionConfig
Một đối tượng đại diện cho một phiên đấu giá thành phần duy nhất trong một phiên đấu giá quảng cáo trên thiết bị.
Tóm tắt thuộc tính | |
---|---|
auctionConfig
|
Một đối tượng cấu hình phiên đấu giá cho phiên đấu giá thành phần này.
|
configKey
|
Khoá cấu hình được liên kết với phiên đấu giá thành phần này.
|
auctionConfig
-
auctionConfig: null | { auctionSignals: unknown, decisionLogicUrl: string, interestGroupBuyers: string[], perBuyerExperimentGroupIds: { [buyer: string]: number }, perBuyerGroupLimits: { [buyer: string]: number }, perBuyerSignals: { [buyer: string]: unknown }, perBuyerTimeouts: { [buyer: string]: number }, seller: string, sellerExperimentGroupId: number, sellerSignals: unknown, sellerTimeout: number, trustedScoringSignalsUrl: string }
-
Một đối tượng cấu hình đấu giá cho phiên đấu giá thành phần này.
Nếu bạn đặt giá trị này thànhnull
, thì mọi cấu hình hiện có choconfigKey
được chỉ định sẽ bị xoá. -
- Ví dụ:
-
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 (cũ)
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, }, ], });
- Xem thêm
configKey
-
configKey: string
-
Khoá cấu hình được liên kết với phiên đấu giá thành phần này.
Giá trị này không được để trống và phải là duy nhất. Nếu hai đối tượngComponentAuctionConfig
có cùng một giá trị configKey, thì giá trị được đặt gần đây nhất sẽ ghi đè các cấu hình trước đó. -
googletag.config.InterstitialConfig
Đối tượng xác định hành vi của một vùng quảng cáo xen kẽ.
Tóm tắt thuộc tính | |
---|---|
triggers
|
Cấu hình trình kích hoạt quảng cáo xen kẽ cho quảng cáo xen kẽ này.
|
triggers
-
triggers: Partial<Record<InterstitialTrigger, boolean>>
-
Cấu hình trình kích hoạt quảng cáo xen kẽ cho quảng cáo xen kẽ này.
Việc đặt giá trị của trình kích hoạt quảng cáo xen kẽ thànhtrue
sẽ bật trình kích hoạt quảng cáo xen kẽ vàfalse
sẽ tắt giá trị đó. Điều này sẽ ghi đè các giá trị mặc định được định cấu hình trong Google Ad Manager. -
- Ví dụ:
-
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 (cũ)
// 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, }, }, });
- Xem thêm
googletag.config.PageSettingsConfig
Giao diện cấu hình chính dành cho các chế độ cài đặt cấp trang.
Cho phép đặt nhiều tính năng bằng một lệnh gọi API duy nhất.
Tất cả thuộc tính được nêu dưới đây chỉ là ví dụ và không phản ánh các tính năng thực tế sử dụng setConfig. Để biết tập hợp tính năng này, hãy xem các trường trong loại PageSettingsConfig bên dưới.
Ví dụ:
- Chỉ các tính năng được chỉ định trong lệnh gọi
setConfig
mới được sửa đổi.// Configure feature alpha. googletag.setConfig({ alpha: {...} }); // Configure feature bravo. Feature alpha is unchanged. googletag.setConfig({ bravo: {...} });
- Tất cả các chế độ cài đặt của một tính năng cụ thể đều được cập nhật mỗi khi bạn thực hiện lệnh gọi đến
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 } });
- Bạn có thể xoá tất cả chế độ cài đặt của một đối tượng bằng cách truyền
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, });
Tóm tắt thuộc tính | |
---|---|
adExpansion
|
Chế độ cài đặt để kiểm soát tính năng mở rộng quảng cáo.
|
pps
|
Chế độ cài đặt để kiểm soát tín hiệu do nhà xuất bản cung cấp (PPS).
|
privacyTreatments
|
Các chế độ cài đặt để kiểm soát việc xử lý quyền riêng tư của nhà xuất bản.
|
adExpansion
-
adExpansion: null | AdExpansionConfig
-
Chế độ cài đặt để kiểm soát tính năng mở rộng quảng cáo.
-
pps
-
pps: null | PublisherProvidedSignalsConfig
-
Chế độ cài đặt để kiểm soát tín hiệu do nhà xuất bản cung cấp (PPS).
-
privacyTreatments
-
privacyTreatments: null | PrivacyTreatmentsConfig
-
Các chế độ cài đặt để kiểm soát việc xử lý quyền riêng tư của nhà xuất bản.
-
googletag.config.PrivacyTreatmentsConfig
Các chế độ cài đặt để kiểm soát việc xử lý quyền riêng tư của nhà xuất bản.
Tóm tắt thuộc tính | |
---|---|
treatments
|
Một loạt các biện pháp xử lý vấn đề quyền riêng tư dành cho nhà xuất bản cần cho phép.
|
treatments
-
treatments: "disablePersonalization"[]
-
Một loạt các biện pháp xử lý vấn đề quyền riêng tư dành cho nhà xuất bản cần cho phép.
-
- Ví dụ:
-
JavaScript
// Disable personalization across the entire page. googletag.setConfig({ privacyTreatments: { treatments: ["disablePersonalization"] }, });
JavaScript (cũ)
// 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
Đối tượng cấu hình Tín hiệu do nhà xuất bản cung cấp (PPS).
Tóm tắt thuộc tính | |
---|---|
taxonomies
|
Một đối tượng chứa mối liên kết Hệ thống phân loại.
|
- Ví dụ:
-
JavaScript
googletag.setConfig({ pps: { taxonomies: { IAB_AUDIENCE_1_1: { values: ["6", "626"] }, // '6' = 'Demographic | Age Range | 18-20' // '626' = 'Interest | Sports | Darts' IAB_CONTENT_2_2: { values: ["48", "127"] }, // '48' = 'Books and Literature | Fiction' // '127' = 'Careers | Job Search' }, }, });
JavaScript (cũ)
googletag.setConfig({ pps: { taxonomies: { IAB_AUDIENCE_1_1: { values: ["6", "626"] }, // '6' = 'Demographic | Age Range | 18-20' // '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 | 18-20' // '626' = 'Interest | Sports | Darts' IAB_CONTENT_2_2: { values: ["48", "127"] }, // '48' = 'Books and Literature | Fiction' // '127' = 'Careers | Job Search' }, }, });
- Xem thêm
taxonomies
-
taxonomies: Partial<Record<Taxonomy, TaxonomyData>>
-
Một đối tượng chứa mối liên kết Hệ thống phân loại.
-
googletag.config.SlotSettingsConfig
Giao diện cấu hình chính cho chế độ cài đặt cấp vùng.
Cho phép thiết lập nhiều tính năng bằng một lệnh gọi API duy nhất cho một vùng duy nhất.
Tất cả thuộc tính được liệt kê dưới đây chỉ là ví dụ và không phản ánh các tính năng thực tế sử dụng setConfig. Để biết tập hợp tính năng này, hãy xem các trường trong loại SlotSettingsConfig bên dưới.
Ví dụ:
- Chỉ các tính năng được chỉ định trong lệnh gọi
Slot.setConfig
mới được sửa đổi.const slot = googletag.defineSlot("/1234567/example", [160, 600]); // Configure feature alpha. slot.setConfig({ alpha: {...} }); // Configure feature bravo. Feature alpha is unchanged. slot.setConfig({ bravo: {...} });
- Tất cả các chế độ cài đặt của một tính năng cụ thể đều được cập nhật mỗi khi bạn thực hiện lệnh gọi đến
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 } });
- Bạn có thể xoá tất cả chế độ cài đặt của một đối tượng bằng cách truyền
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, });
Tóm tắt thuộc tính | |
---|---|
adExpansion
|
Chế độ cài đặt để kiểm soát tính năng mở rộng quảng cáo.
|
componentAuction
|
Một mảng các phiên đấu giá thành phần sẽ được đưa vào phiên đấu giá quảng cáo trên thiết bị.
|
interstitial
|
Các chế độ cài đặt kiểm soát hành vi của vùng quảng cáo xen kẽ.
|
adExpansion
-
adExpansion: AdExpansionConfig
-
Chế độ cài đặt để kiểm soát tính năng mở rộng quảng cáo.
-
componentAuction
-
componentAuction: ComponentAuctionConfig[]
-
Một mảng các phiên đấu giá thành phần sẽ được đưa vào phiên đấu giá quảng cáo trên thiết bị.
-
interstitial
-
interstitial: InterstitialConfig
-
Các chế độ cài đặt kiểm soát hành vi của vùng quảng cáo xen kẽ.
-
googletag.config.TaxonomyData
Đối tượng chứa các giá trị cho một Hệ thống phân loại.
Tóm tắt thuộc tính | |
---|---|
values
|
Danh sách các giá trị Hệ thống phân loại.
|
values
-
values: string[]
-
Danh sách các giá trị Hệ thống phân loại.
-
googletag.events.Event
Giao diện cơ sở cho tất cả các sự kiện GPT. Tất cả sự kiện GPT bên dưới sẽ có các trường sau.
Tóm tắt thuộc tính | |
---|---|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
|
slot
|
Vị trí đã kích hoạt sự kiện.
|
- Xem thêm
serviceName
-
serviceName: string
-
Tên của dịch vụ đã kích hoạt sự kiện.
-
slot
-
slot: Slot
-
Vị trí đã kích hoạt sự kiện.
-
googletag.events.EventTypeMap
Đây là loại giả liên kết tên sự kiện với loại đối tượng sự kiện tương ứng cho Service.addEventListener
và Service.removeEventListener
. Tài liệu này chỉ nhằm mục đích tham khảo và an toàn về loại.
Tóm tắt thuộc tính | |
---|---|
impressionViewable
|
Bí danh của
events.ImpressionViewableEvent .
|
rewardedSlotClosed
|
Bí danh của
events.RewardedSlotClosedEvent .
|
rewardedSlotGranted
|
Bí danh của
events.RewardedSlotGrantedEvent .
|
rewardedSlotReady
|
Bí danh của
events.RewardedSlotReadyEvent .
|
slotOnload
|
Bí danh của
events.SlotOnloadEvent .
|
slotRenderEnded
|
Bí danh của
events.SlotRenderEndedEvent .
|
slotRequested
|
Bí danh của
events.SlotRequestedEvent .
|
slotResponseReceived
|
Bí danh của
events.SlotResponseReceived .
|
slotVisibilityChanged
|
Bí danh của
events.SlotVisibilityChangedEvent .
|
impressionViewable
-
impressionViewable: ImpressionViewableEvent
-
Bí danh của
events.ImpressionViewableEvent
. -
rewardedSlotClosed
-
rewardedSlotClosed: RewardedSlotClosedEvent
-
Bí danh của
events.RewardedSlotClosedEvent
. -
rewardedSlotGranted
-
rewardedSlotGranted: RewardedSlotGrantedEvent
-
Bí danh của
events.RewardedSlotGrantedEvent
. -
rewardedSlotReady
-
rewardedSlotReady: RewardedSlotReadyEvent
-
Bí danh của
events.RewardedSlotReadyEvent
. -
slotOnload
-
slotOnload: SlotOnloadEvent
-
Bí danh của
events.SlotOnloadEvent
. -
slotRenderEnded
-
slotRenderEnded: SlotRenderEndedEvent
-
Bí danh của
events.SlotRenderEndedEvent
. -
slotRequested
-
slotRequested: SlotRequestedEvent
-
Bí danh của
events.SlotRequestedEvent
. -
slotResponseReceived
-
slotResponseReceived: SlotResponseReceived
-
Bí danh của
events.SlotResponseReceived
. -
slotVisibilityChanged
-
slotVisibilityChanged: SlotVisibilityChangedEvent
-
Bí danh của
events.SlotVisibilityChangedEvent
. -
googletag.events.ImpressionViewableEvent
Mở rộng
Sự kiện này được kích hoạt khi một lượt hiển thị có thể xem, theo tiêu chí của Chế độ xem đang kích hoạt.
Tóm tắt thuộc tính | |
---|---|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
Đã kế thừa từ
|
slot
|
Vị trí đã kích hoạt sự kiện.
Đã kế thừa từ
|
- Ví dụ:
-
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 (cũ)
// 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. } });
- Xem thêm
googletag.events.RewardedSlotClosedEvent
Mở rộng
Sự kiện này được kích hoạt khi người dùng đóng vùng quảng cáo có tặng thưởng. Nút này có thể kích hoạt trước hoặc sau khi bạn nhận được phần thưởng. Để xác định xem phần thưởng đã được cấp hay chưa, hãy sử dụng events.RewardedSlotGrantedEvent
.
Tóm tắt thuộc tính | |
---|---|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
Đã kế thừa từ
|
slot
|
Vị trí đã kích hoạt sự kiện.
Đã kế thừa từ
|
- Ví dụ:
-
JavaScript
// This listener is called when the user closes a rewarded ad slot. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); 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 (cũ)
// This listener is called when the user closes a rewarded ad slot. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); 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
// This listener is called when the user closes a rewarded ad slot. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); 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. } });
- Xem thêm
googletag.events.RewardedSlotGrantedEvent
Mở rộng
Sự kiện này được kích hoạt khi phần thưởng được cấp cho việc xem quảng cáo có tặng thưởng. Nếu quảng cáo bị đóng trước khi đáp ứng tiêu chí nhận phần thưởng, thì sự kiện này sẽ không kích hoạt.
Tóm tắt thuộc tính | |
---|---|
payload
|
Một đối tượng chứa thông tin về phần thưởng đã được cấp.
|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
Đã kế thừa từ
|
slot
|
Vị trí đã kích hoạt sự kiện.
Đã kế thừa từ
|
- Ví dụ:
-
JavaScript
// This listener is called whenever a reward is granted for a // rewarded ad. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); 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 (cũ)
// This listener is called whenever a reward is granted for a // rewarded ad. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); 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
// This listener is called whenever a reward is granted for a // rewarded ad. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); 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. } });
- Xem thêm
payload
-
payload: null | RewardedPayload
-
Một đối tượng chứa thông tin về phần thưởng đã được cấp.
-
googletag.events.RewardedSlotReadyEvent
Mở rộng
Sự kiện này được kích hoạt khi quảng cáo có tặng thưởng sẵn sàng hiển thị. Nhà xuất bản có trách nhiệm cung cấp cho người dùng tuỳ chọn xem quảng cáo trước khi hiển thị quảng cáo đó.
Tóm tắt thuộc tính | |
---|---|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
Đã kế thừa từ
|
slot
|
Vị trí đã kích hoạt sự kiện.
Đã kế thừa từ
|
Tóm tắt phương pháp | |
---|---|
makeRewardedVisible
|
Hiển thị quảng cáo có tặng thưởng.
|
- Ví dụ:
-
JavaScript
// This listener is called when a rewarded ad slot becomes ready to be // displayed. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); 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 (cũ)
// This listener is called when a rewarded ad slot becomes ready to be // displayed. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); 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.defineSlot("/1234567/example", [160, 600]); 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. } });
- Xem thêm
makeRewardedVisible
-
makeRewardedVisible(): void
-
Hiển thị quảng cáo có tặng thưởng. Phương pháp này sẽ không được gọi cho đến khi người dùng đồng ý xem quảng cáo.
-
googletag.events.SlotOnloadEvent
Mở rộng
Sự kiện này được kích hoạt khi iframe của mẫu quảng cáo kích hoạt sự kiện tải. Khi hiển thị quảng cáo đa phương tiện ở chế độ hiển thị đồng bộ, không có iframe nào được sử dụng, vì vậy sẽ không có SlotOnloadEvent
nào được kích hoạt.
Tóm tắt thuộc tính | |
---|---|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
Đã kế thừa từ
|
slot
|
Vị trí đã kích hoạt sự kiện.
Đã kế thừa từ
|
- Ví dụ:
-
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 (cũ)
// 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. } });
- Xem thêm
googletag.events.SlotRenderEndedEvent
Mở rộng
Sự kiện này được kích hoạt khi mã mẫu quảng cáo được đưa vào một vùng. Sự kiện này sẽ xảy ra trước khi tìm nạp tài nguyên của mẫu quảng cáo, vì vậy, mẫu quảng cáo có thể chưa hiển thị. Nếu bạn cần biết thời điểm tất cả tài nguyên mẫu quảng cáo cho một vùng đã tải xong, hãy cân nhắc sử dụng events.SlotOnloadEvent
.
Tóm tắt thuộc tính | |
---|---|
advertiserId
|
Mã nhận dạng nhà quảng cáo của quảng cáo được hiển thị.
|
campaignId
|
Mã chiến dịch của quảng cáo được hiển thị.
|
companyIds
|
Mã của các công ty đặt giá thầu cho quảng cáo chèn lấp được hiển thị.
|
creativeId
|
Mã mẫu quảng cáo của quảng cáo đặt trước được hiển thị.
|
creativeTemplateId
|
Mã mẫu mẫu quảng cáo của quảng cáo đặt trước được hiển thị.
|
isBackfill
|
Quảng cáo có phải là quảng cáo chèn lấp hay không.
|
isEmpty
|
Liệu quảng cáo có được trả lại cho vị trí đó hay không.
|
labelIds
|
Mã nhãn của quảng cáo được hiển thị.
|
lineItemId
|
Mã mục hàng của quảng cáo đặt trước được hiển thị.
|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
Đã kế thừa từ
|
size
|
Cho biết kích thước pixel của mẫu quảng cáo được hiển thị.
|
slot
|
Vị trí đã kích hoạt sự kiện.
Đã kế thừa từ
|
slotContentChanged
|
Liệu nội dung vùng quảng cáo có được thay đổi với quảng cáo được hiển thị hay không.
|
sourceAgnosticCreativeId
|
Mã mẫu quảng cáo của quảng cáo đặt trước hoặc quảng cáo thay thế được hiển thị.
|
sourceAgnosticLineItemId
|
Mã mục hàng của quảng cáo đặt trước hoặc quảng cáo thay thế được hiển thị.
|
yieldGroupIds
|
Mã của nhóm lợi nhuận cho quảng cáo thay thế được hiển thị.
|
- Ví dụ:
-
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("Label IDs:", event.labelIds); 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 (cũ)
// 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("Label IDs:", event.labelIds); 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("Label IDs:", event.labelIds); 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. } });
- Xem thêm
advertiserId
-
advertiserId: null | number
-
Mã nhận dạng nhà quảng cáo của quảng cáo được hiển thị. Giá trị là
null
cho các vùng trống, quảng cáo chèn lấp và mẫu quảng cáo do các dịch vụ không phải làPubAdsService
hiển thị. -
campaignId
-
campaignId: null | number
-
Mã chiến dịch của quảng cáo được hiển thị. Giá trị là
null
cho các vùng trống, quảng cáo chèn lấp và mẫu quảng cáo do các dịch vụ không phải làPubAdsService
hiển thị. -
companyIds
-
companyIds: null | number[]
-
Mã của các công ty đặt giá thầu cho quảng cáo chèn lấp được hiển thị. Giá trị là
null
cho các vùng trống, quảng cáo đặt trước và mẫu quảng cáo do các dịch vụ không phải làPubAdsService
hiển thị. -
creativeId
-
creativeId: null | number
-
Mã mẫu quảng cáo của quảng cáo đặt trước được hiển thị. Giá trị là
null
cho các vùng trống, quảng cáo chèn lấp và mẫu quảng cáo do các dịch vụ không phải làPubAdsService
hiển thị. -
creativeTemplateId
-
creativeTemplateId: null | number
-
Mã mẫu mẫu quảng cáo của quảng cáo đặt trước được hiển thị. Giá trị là
null
cho các vùng trống, quảng cáo chèn lấp và mẫu quảng cáo do các dịch vụ không phải làPubAdsService
hiển thị. -
isBackfill
-
isBackfill: boolean
-
Quảng cáo có phải là quảng cáo chèn lấp hay không. Giá trị là
true
nếu quảng cáo là quảng cáo chèn lấp, nếu không làfalse
. -
isEmpty
-
isEmpty: boolean
-
Liệu quảng cáo có được trả lại cho vị trí đó hay không. Giá trị là
true
nếu không có quảng cáo nào được trả về, nếu không thìfalse
. -
labelIds
-
labelIds: null | number[]
-
Mã nhãn của quảng cáo được hiển thị. Giá trị là
null
cho các vùng trống, quảng cáo chèn lấp và mẫu quảng cáo do các dịch vụ không phải làPubAdsService
hiển thị. -
lineItemId
-
lineItemId: null | number
-
Mã mục hàng của quảng cáo đặt trước được hiển thị. Giá trị là
null
cho các vùng trống, quảng cáo chèn lấp và mẫu quảng cáo do các dịch vụ không phải làPubAdsService
hiển thị. -
size
-
size: null | string | number[]
-
Cho biết kích thước pixel của mẫu quảng cáo được hiển thị. Ví dụ:
[728, 90]
Giá trị lànull
cho vùng quảng cáo trống. -
slotContentChanged
-
slotContentChanged: boolean
-
Liệu nội dung vùng quảng cáo có được thay đổi với quảng cáo được hiển thị hay không. Giá trị sẽ là
true
nếu nội dung đã thay đổi, nếu không thì giá trị sẽ làfalse
. -
sourceAgnosticCreativeId
-
sourceAgnosticCreativeId: null | number
-
Mã mẫu quảng cáo của quảng cáo đặt trước hoặc quảng cáo thay thế được hiển thị. Giá trị là
null
nếu quảng cáo không phải là quảng cáo đặt trước hoặc quảng cáo thay thế mục hàng, hoặc mẫu quảng cáo do các dịch vụ không phảiPubAdsService
hiển thị. -
sourceAgnosticLineItemId
-
sourceAgnosticLineItemId: null | number
-
Mã mục hàng của quảng cáo đặt trước hoặc quảng cáo thay thế được hiển thị. Giá trị là
null
nếu quảng cáo không phải là quảng cáo đặt trước hoặc quảng cáo thay thế mục hàng, hoặc mẫu quảng cáo do các dịch vụ không phảiPubAdsService
hiển thị. -
yieldGroupIds
-
yieldGroupIds: null | number[]
-
Mã của nhóm lợi nhuận cho quảng cáo thay thế được hiển thị. Giá trị là
null
cho các vùng trống, quảng cáo đặt trước và mẫu quảng cáo do các dịch vụ không phải làPubAdsService
hiển thị. -
googletag.events.SlotRequestedEvent
Mở rộng
Sự kiện này được kích hoạt khi yêu cầu quảng cáo cho một vị trí cụ thể.
Tóm tắt thuộc tính | |
---|---|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
Đã kế thừa từ
|
slot
|
Vị trí đã kích hoạt sự kiện.
Đã kế thừa từ
|
- Ví dụ:
-
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 (cũ)
// 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. } });
- Xem thêm
googletag.events.SlotResponseReceived
Mở rộng
Sự kiện này được kích hoạt khi nhận được phản hồi quảng cáo cho một vị trí cụ thể.
Tóm tắt thuộc tính | |
---|---|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
Đã kế thừa từ
|
slot
|
Vị trí đã kích hoạt sự kiện.
Đã kế thừa từ
|
- Ví dụ:
-
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 (cũ)
// 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. } });
- Xem thêm
googletag.events.SlotVisibilityChangedEvent
Mở rộng
Sự kiện này được kích hoạt bất cứ khi nào tỷ lệ phần trăm trên màn hình của một vùng quảng cáo thay đổi. Sự kiện được điều tiết và sẽ không kích hoạt thường xuyên hơn 1 lần mỗi 200 mili giây.
Tóm tắt thuộc tính | |
---|---|
inViewPercentage
|
Tỷ lệ phần trăm vùng quảng cáo có thể nhìn thấy.
|
serviceName
|
Tên của dịch vụ đã kích hoạt sự kiện.
Đã kế thừa từ
|
slot
|
Vị trí đã kích hoạt sự kiện.
Đã kế thừa từ
|
- Ví dụ:
-
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 (cũ)
// 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. } });
- Xem thêm
inViewPercentage
-
inViewPercentage: number
-
Tỷ lệ phần trăm vùng quảng cáo có thể nhìn thấy. Giá trị là một số từ 0 đến 100.
-
googletag.secureSignals.BidderSignalProvider
Trả về tín hiệu an toàn cho một bên đặt giá thầu cụ thể.
Nhà cung cấp tín hiệu an toàn của bên đặt giá thầu bao gồm 2 phần:
- Một hàm thu thập sẽ trả về
Promise
giúp phân giải thành tín hiệu an toàn. id
giúp xác định bên đặt giá thầu liên kết với tín hiệu này.
secureSignals.PublisherSignalProvider
.
Tóm tắt thuộc tính | |
---|---|
collectorFunction
|
.
|
id
|
Giá trị nhận dạng duy nhất cho trình thu thập liên quan đến tín hiệu an toàn này, như đã đăng ký trong Google Ad Manager.
|
- Ví dụ:
-
JavaScript
// id is provided googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, });
JavaScript (cũ)
// 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"); }, });
- Xem thêm
collectorFunction
-
collectorFunction: () => Promise<string>
-
id
-
id: string
-
Giá trị nhận dạng duy nhất cho trình thu thập liên quan đến tín hiệu an toàn này, như đã đăng ký trong Google Ad Manager.
-
googletag.secureSignals.PublisherSignalProvider
Trả về tín hiệu an toàn cho một nhà xuất bản cụ thể.
Nhà cung cấp tín hiệu của nhà xuất bản bao gồm 2 phần:
- Một hàm thu thập sẽ trả về
Promise
giúp phân giải thành tín hiệu an toàn. networkCode
xác định nhà xuất bản liên kết với tín hiệu đó.
secureSignals.BidderSignalProvider
.
Tóm tắt thuộc tính | |
---|---|
collectorFunction
|
.
|
networkCode
|
Mã mạng (như trong đường dẫn đơn vị quảng cáo) cho nhà xuất bản liên kết với tín hiệu an toàn này.
|
- Ví dụ:
-
JavaScript
// networkCode is provided googletag.secureSignalProviders.push({ networkCode: "123456", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, });
JavaScript (cũ)
// 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"); }, });
- Xem thêm
collectorFunction
-
collectorFunction: () => Promise<string>
-
networkCode
-
networkCode: string
-
Mã mạng (như trong đường dẫn đơn vị quảng cáo) cho nhà xuất bản liên kết với tín hiệu an toàn này.
-
googletag.secureSignals.SecureSignalProvidersArray
Một giao diện để quản lý tín hiệu an toàn.
Tóm tắt phương pháp | |
---|---|
clearAllCache
|
Xoá tất cả tín hiệu đã lưu vào bộ nhớ đệm khỏi bộ nhớ cục bộ.
|
push
|
Thêm một
secureSignals.SecureSignalProvider mới vào mảng nhà cung cấp tín hiệu và bắt đầu quá trình tạo tín hiệu.
|
clearAllCache
-
clearAllCache(): void
-
Xoá tất cả tín hiệu đã lưu vào bộ nhớ đệm khỏi bộ nhớ cục bộ.
-
push
-
push(provider: SecureSignalProvider): void
-
Thêm một
secureSignals.SecureSignalProvider
mới vào mảng nhà cung cấp tín hiệu và bắt đầu quá trình tạo tín hiệu. -
-
Tham số provider: SecureSignalProvider
Đối tượngsecureSignals.SecureSignalProvider
sẽ được thêm vào mảng.