این مرجع از نمادگذاری TypeScript برای توصیف نوعها استفاده میکند. جدول زیر توضیح مختصری را با مثال ارائه میدهد.
| عبارت نوع | |
|---|---|
string | نوع رشته اولیه. |
string[] | یک نوع آرایه، که در آن مقادیر فقط میتوانند رشته باشند. |
number | string | یک نوع یونیونی، که در آن مقدار میتواند عدد یا رشته باشد. |
Array<number | string> | یک نوع آرایه، که در آن مقادیر از نوع مختلط (اتحادیهای) هستند. |
[number, string] | یک نوع چندتایی، که در آن مقدار یک آرایه دو عنصری است که باید شامل یک عدد و یک رشته به همان ترتیب باشد. |
Slot | یک نوع شیء، که مقدار آن نمونهای از googletag.Slot است. |
() => void | یک نوع تابع بدون آرگومان تعریف شده و بدون مقدار بازگشتی. |
برای کسب اطلاعات بیشتر در مورد انواع و عبارات نوع پشتیبانی شده، به کتابچه راهنمای TypeScript مراجعه کنید.
حاشیهنویسیهای نوع
علامت دونقطه بعد از یک متغیر، نام پارامتر، نام ویژگی یا امضای تابع، نشاندهندهی یک حاشیهنویسی نوع است. حاشیهنویسیهای نوع، انواعی را توصیف میکنند که عنصر سمت چپ دونقطه میتواند بپذیرد یا برگرداند. جدول زیر نمونههایی از حاشیهنویسیهای نوع را که ممکن است در این مرجع ببینید، نشان میدهد.
| حاشیهنویسی نوع | |
|---|---|
param: string | نشان میدهد که param یک مقدار رشتهای را میپذیرد یا برمیگرداند. این سینتکس برای متغیرها، پارامترها، ویژگیها و انواع بازگشتی استفاده میشود. |
param?: number | string | نشان میدهد که param اختیاری است، اما در صورت مشخص شدن، عدد یا رشته را میپذیرد. این سینتکس برای پارامترها و ویژگیها استفاده میشود. |
...params: Array<() => void> | نشان میدهد که params یک پارامتر rest است که توابع را میپذیرد. پارامترهای rest تعداد نامحدودی از مقادیر از نوع مشخص شده را میپذیرند. |
googletag
| فضاهای نام | |
|---|---|
config | رابط پیکربندی اصلی برای تنظیمات سطح صفحه. |
enums | این همان فضای نامی است که GPT برای انواع enum استفاده میکند. |
events | این فضای نامی است که GPT برای رویدادها استفاده میکند. |
secure Signals | این فضای نامی است که GPT برای مدیریت سیگنالهای امن از آن استفاده میکند. |
| رابطها | |
|---|---|
Command Array | آرایه فرمان، دنبالهای از توابع را میپذیرد و آنها را به ترتیب فراخوانی میکند. |
Companion Ads Service | سرویس تبلیغات همراه. |
Privacy Settings Config | شیء پیکربندی برای تنظیمات حریم خصوصی. |
Pub Ads Service | سرویس تبلیغات ناشران. |
Response Information | یک شیء که نشاندهندهی یک پاسخ تبلیغ واحد است. |
Rewarded Payload | یک شیء که نشان دهنده پاداش مرتبط با یک تبلیغ جایزهدار است. |
Service | کلاس سرویس پایه که شامل متدهای مشترک برای همه سرویسها است. |
Size Mapping Builder | سازنده برای نگاشت اندازه اشیاء مشخصات. |
Slot | Slot یک شیء است که یک جایگاه تبلیغاتی واحد را در یک صفحه نشان میدهد. |
| نامهای مستعار نوع | |
|---|---|
General Size | پیکربندی اندازه معتبر برای یک اسلات، که میتواند یک یا چند اندازه باشد. |
Multi Size | فهرستی از اندازههای معتبر تکی. |
Named Size | اندازههای نامگذاری شدهای که یک اسلات میتواند داشته باشد. |
Single Size | یک اندازه معتبر برای یک اسلات. |
Single Size Array | آرایهای از دو عدد که نشاندهندهی [عرض، ارتفاع] هستند. |
Size Mapping | نگاشت اندازه نمایشگر به اندازه تبلیغات. |
Size Mapping Array | فهرستی از نگاشتهای اندازه. |
| متغیرها | |
|---|---|
api Ready | پرچمی که نشان میدهد API GPT بارگذاری شده و آماده فراخوانی است. |
cmd | ارجاع به صف فرمان سراسری برای اجرای ناهمزمان فراخوانیهای مرتبط با GPT. |
pubads Ready | پرچمی که نشان میدهد PubAdsService فعال، بارگذاری شده و کاملاً عملیاتی است. |
secure Signal Providers | ارجاع به آرایه ارائه دهندگان سیگنال امن. |
| توابع | |
|---|---|
companion Ads | یک ارجاع به CompanionAdsService برمیگرداند. |
define Out Of Page Slot | یک جایگاه تبلیغاتی خارج از صفحه با مسیر واحد تبلیغاتی داده شده میسازد. |
define Slot | یک جایگاه تبلیغاتی با مسیر و اندازه واحد تبلیغاتی مشخص میسازد و آن را با شناسه یک عنصر div در صفحهای که حاوی تبلیغ خواهد بود، مرتبط میکند. |
destroy Slots | اسلاتهای داده شده را از بین میبرد و تمام اشیاء و ارجاعات مرتبط با آن اسلاتها را از GPT حذف میکند. |
disable Publisher Console | کنسول ناشر گوگل را غیرفعال میکند. |
display | به سرویسهای اسلات دستور میدهد تا اسلات را رندر کنند. |
enable Services | تمام سرویسهای GPT که برای جایگاههای تبلیغاتی در صفحه تعریف شدهاند را فعال میکند. |
get Config | گزینههای پیکربندی عمومی برای صفحهای که توسط setConfig تنظیم شده است را دریافت میکند. |
get Version | نسخه فعلی GPT را برمیگرداند. |
open Console | کنسول ناشر گوگل را باز میکند. |
pubads | یک ارجاع به PubAdsService برمیگرداند. |
set Ad Iframe Title | از این نقطه به بعد، عنوان همه آیفریمهای محفظه تبلیغات ایجاد شده توسط PubAdsService را تنظیم میکند. |
set Config | گزینههای پیکربندی کلی صفحه را تنظیم میکند. |
size Mapping | یک SizeMappingBuilder جدید ایجاد میکند. |
نامهای مستعار نوع
اندازه عمومی
GeneralSize : SingleSize | MultiSizeچند سایزی
MultiSize : SingleSize []نامگذاریشدهاندازه
NamedSize : "fluid" | [ "fluid" ]- سیال : ظرف تبلیغ، عرض ۱۰۰٪ از div والد را میگیرد و سپس ارتفاع آن را متناسب با محتوای خلاقانه تغییر میدهد. مشابه نحوه رفتار عناصر بلوکی معمولی در یک صفحه. برای تبلیغات بومی استفاده میشود (به مقاله مرتبط مراجعه کنید). توجه داشته باشید که هم
fluidو هم['fluid']فرمهای قابل قبولی برای اعلام اندازه اسلات به عنوان سیال هستند.
تک سایز
SingleSize : SingleSizeArray | NamedSizeآرایه تکاندازه
SingleSizeArray : [ number , number ]نگاشت اندازه
SizeMapping : [ SingleSizeArray , GeneralSize ]SizeMappingArray
SizeMappingArray : SizeMapping []متغیرها
Const apiReady
apiReady : boolean | undefinedundefined خواهد بود.توجه داشته باشید که روش توصیهشده برای مدیریت ناهمزمانی، استفاده از googletag.cmd برای صفبندی فراخوانیها برای زمانی است که GPT آماده است. این فراخوانیهای برگشتی نیازی به بررسی googletag.apiReady ندارند، زیرا تضمین میشود که پس از راهاندازی API اجرا شوند.
Const cmd
cmd : ( ( this : typeof globalThis ) => void ) [] | CommandArrayمتغیر
googletag.cmd توسط سینتکس تگ GPT در صفحه، به یک آرایه خالی جاوا اسکریپت مقداردهی اولیه میشود و cmd.push متد استاندارد Array.push است که یک عنصر را به انتهای آرایه اضافه میکند. هنگامی که جاوا اسکریپت GPT بارگذاری میشود، آرایه را جستجو کرده و تمام توابع را به ترتیب اجرا میکند. سپس اسکریپت cmd با یک شیء CommandArray جایگزین میکند که متد push آن برای اجرای آرگومان تابع ارسالی به آن تعریف شده است. این مکانیزم به GPT اجازه میدهد تا با واکشی ناهمزمان جاوا اسکریپت، تأخیر درک شده را کاهش دهد و در عین حال به مرورگر اجازه دهد تا به رندر صفحه ادامه دهد.- مثال
جاوا اسکریپت
googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); });
جاوا اسکریپت (قدیمی)
googletag.cmd.push(function () { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); });
تایپ اسکریپت
googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600])!.addService(googletag.pubads()); });
آماده Const همه
pubadsReady : boolean | undefinedundefined خواهد بود. ارائه دهندگان سیگنال امن
secureSignalProviders : SecureSignalProvider [] | SecureSignalProvidersArray | undefinedآرایه ارائه دهندگان سیگنال امن، دنبالهای از توابع تولید سیگنال را میپذیرد و آنها را به ترتیب فراخوانی میکند. این آرایه قرار است جایگزین یک آرایه استاندارد شود که برای در صف قرار دادن توابع تولید سیگنال جهت فراخوانی پس از بارگذاری GPT استفاده میشود.
- مثال
جاوا اسکریپت
window.googletag = window.googletag || { cmd: [] }; googletag.secureSignalProviders = googletag.secureSignalProviders || []; googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: () => { return Promise.resolve("signal"); }, });
جاوا اسکریپت (قدیمی)
window.googletag = window.googletag || { cmd: [] }; googletag.secureSignalProviders = googletag.secureSignalProviders || []; googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: function () { return Promise.resolve("signal"); }, });
تایپ اسکریپت
window.googletag = window.googletag || { cmd: [] }; googletag.secureSignalProviders = googletag.secureSignalProviders || []; googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: () => { return Promise.resolve("signal"); }, });
- همچنین ببینید
توابع
تبلیغات همراه
companionAds ( ) : CompanionAdsService| بازگشتها | |
|---|---|
CompanionAdsService | سرویس تبلیغات همراه. |
defineOutOfPageSlot
defineOutOfPageSlot ( adUnitPath : string , div ?: string | OutOfPageFormat ) : Slot | nullبرای تبلیغات سفارشی خارج از صفحه،
div شناسه عنصر div است که شامل تبلیغ خواهد بود. برای جزئیات بیشتر به مقاله مربوط به تبلیغات خارج از صفحه مراجعه کنید.برای تبلیغات خارج از صفحه مدیریتشده توسط GPT،
div یک OutOfPageFormat پشتیبانیشده است.- مثال
جاوا اسکریپت
// 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);
جاوا اسکریپت (قدیمی)
// 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);
تایپ اسکریپت
// Define a custom out-of-page ad slot. googletag.defineOutOfPageSlot("/1234567/sports", "div-1"); // Define a GPT managed web interstitial ad slot. googletag.defineOutOfPageSlot("/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL);
- همچنین ببینید
| پارامترها | |
|---|---|
adUnitPath : string | مسیر کامل واحد تبلیغاتی به همراه کد شبکه و کد واحد تبلیغاتی. |
| شناسهی div که شامل این واحد تبلیغاتی یا OutOfPageFormat خواهد بود. |
| بازگشتها | |
|---|---|
Slot | null | اسلات تازه ایجاد شده، یا اگر اسلاتی قابل ایجاد نباشد، null . |
تعریف اسلات
defineSlot ( adUnitPath : string , size : GeneralSize , div ?: string ) : Slot | null- مثال
جاوا اسکریپت
googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
جاوا اسکریپت (قدیمی)
googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
تایپ اسکریپت
googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
- همچنین ببینید
| پارامترها | |
|---|---|
adUnitPath : string | مسیر کامل واحد تبلیغ به همراه کد شبکه و کد واحد. |
size : GeneralSize | عرض و ارتفاع اسلات اضافه شده. این اندازهای است که در درخواست تبلیغ استفاده میشود اگر هیچ نگاشت اندازه واکنشگرا ارائه نشده باشد یا اندازه نمای دید کوچکتر از کوچکترین اندازه ارائه شده در نگاشت باشد. |
| شناسهی div که شامل این واحد تبلیغاتی خواهد بود. |
| بازگشتها | |
|---|---|
Slot | null | اسلات تازه ایجاد شده، یا اگر اسلاتی قابل ایجاد نباشد، null . |
نابود کردن اسلاتها
destroySlots ( slots ?: Slot [] ) : booleanفراخوانی این API روی یک اسلات، تبلیغ را پاک میکند و شیء اسلات را از حالت داخلی که توسط GPT نگهداری میشود، خارج میکند. فراخوانی هر تابع دیگری روی شیء اسلات منجر به رفتار نامشخص خواهد شد. توجه داشته باشید که اگر صفحه ناشر به آن ارجاع دهد، مرورگر ممکن است همچنان حافظه مرتبط با آن اسلات را آزاد نکند. فراخوانی این API باعث میشود div مرتبط با آن اسلات برای استفاده مجدد در دسترس باشد.
به طور خاص، از بین بردن یک اسلات، تبلیغ را از نمای صفحه طولانی مدت GPT حذف میکند، بنابراین درخواستهای آینده تحت تأثیر موانع یا حذفهای رقابتی مربوط به این تبلیغ قرار نخواهند گرفت. عدم فراخوانی این تابع قبل از حذف div یک اسلات از صفحه منجر به رفتار نامشخص خواهد شد.
- مثال
جاوا اسکریپت
// 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();
جاوا اسکریپت (قدیمی)
// 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();
تایپ اسکریپت
// The calls to construct an ad and display contents. const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!; googletag.display("div-1"); const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!; googletag.display("div-2"); // This call to destroy only slot1. googletag.destroySlots([slot1]); // This call to destroy both slot1 and slot2. googletag.destroySlots([slot1, slot2]); // This call to destroy all slots. googletag.destroySlots();
| پارامترها | |
|---|---|
| آرایهای از اسلاتها که باید نابود شوند. آرایه اختیاری است؛ اگر مشخص نشود، تمام اسلاتها نابود خواهند شد. |
| بازگشتها | |
|---|---|
boolean | اگر اسلاتها از بین رفته باشند، true و در غیر این صورت false . |
غیرفعال کردن کنسول ناشر
disablePublisherConsole ( ) : void- همچنین ببینید
نمایش
display ( divOrSlot : string | Element | Slot ) : voidاگر از معماری تک درخواستی (SRA) استفاده شود، تمام جایگاههای تبلیغاتی واکشی نشده در زمان فراخوانی این متد، به طور همزمان واکشی میشوند. برای اینکه یک جایگاه تبلیغاتی نمایش داده نشود، باید کل div حذف شود.
- همچنین ببینید
| پارامترها | |
|---|---|
divOrSlot : string | Element | Slot | یا شناسهی عنصر div حاوی جایگاه تبلیغ یا عنصر div، یا شیء اسلات. اگر یک عنصر div ارائه شده باشد، باید دارای یک ویژگی 'id' باشد که با شناسهی ارسال شده به defineSlot مطابقت داشته باشد. |
فعال کردن سرویسها
enableServices ( ) : voidدریافت پیکربندی
getConfig ( keys : string | string [] ) : Pick < PageSettingsConfig , "adsenseAttributes" | "disableInitialLoad" | "targeting" >همه ویژگیهای
setConfig() توسط این متد پشتیبانی نمیشوند. ویژگیهای پشتیبانیشده عبارتند از:- مثال
جاوا اسکریپت
// Get the value of the `targeting` setting. const targetingConfig = googletag.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `disableInitialLoad` settings. const config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);
جاوا اسکریپت (قدیمی)
// Get the value of the `targeting` setting. var targetingConfig = googletag.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `disableInitialLoad` settings. var config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);
تایپ اسکریپت
// Get the value of the `targeting` setting. const targetingConfig = googletag.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `disableInitialLoad` settings. const config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);
| پارامترها | |
|---|---|
keys : string | string [] | کلیدهای گزینههای پیکربندی که باید دریافت شوند. |
| بازگشتها | |
|---|---|
Pick < PageSettingsConfig , "adsenseAttributes" | "disableInitialLoad" | "targeting" > | گزینههای پیکربندی برای اسلات. |
دریافت نسخه
getVersion ( ) : string- همچنین ببینید
| بازگشتها | |
|---|---|
string | رشتهی نسخهی GPT که در حال حاضر در حال اجرا است. |
کنسول باز
openConsole ( div ?: string ) : void- مثال
جاوا اسکریپت
// Calling with div ID. googletag.openConsole("div-1"); // Calling without div ID. googletag.openConsole();
جاوا اسکریپت (قدیمی)
// Calling with div ID. googletag.openConsole("div-1"); // Calling without div ID. googletag.openConsole();
تایپ اسکریپت
// Calling with div ID. googletag.openConsole("div-1"); // Calling without div ID. googletag.openConsole();
- همچنین ببینید
| پارامترها | |
|---|---|
| شناسه تقسیم جایگاه تبلیغاتی. این مقدار اختیاری است. در صورت ارائه، کنسول ناشر سعی میکند جزئیات جایگاه تبلیغاتی مشخص شده را نمایش دهد. |
میخانهها
pubads ( ) : PubAdsService| بازگشتها | |
|---|---|
PubAdsService | سرویس تبلیغات ناشر. |
عنوان تنظیمشدهی AdIframe
setAdIframeTitle ( title : string ) : void- مثال
جاوا اسکریپت
googletag.setAdIframeTitle("title");
جاوا اسکریپت (قدیمی)
googletag.setAdIframeTitle("title");
تایپ اسکریپت
googletag.setAdIframeTitle("title");
| پارامترها | |
|---|---|
title : string | عنوان جدید برای همه آیفریمهای محفظه تبلیغات. |
تنظیم پیکربندی
setConfig ( config : PageSettingsConfig ) : void| پارامترها | |
|---|---|
config : PageSettingsConfig | |
اندازه نگاشت
sizeMapping ( ) : SizeMappingBuildergoogletag.CommandArray
| روشها | |
|---|---|
push | دنباله توابع مشخص شده در آرگومانها را به ترتیب اجرا میکند. |
روشها
فشار دادن
push ( ... f : ( ( this : typeof globalThis ) => void ) [] ) : number- مثال
جاوا اسکریپت
googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); });
جاوا اسکریپت (قدیمی)
googletag.cmd.push(function () { googletag.defineSlot("/1234567/sports", [160, 600]).addService(googletag.pubads()); });
تایپ اسکریپت
googletag.cmd.push(() => { googletag.defineSlot("/1234567/sports", [160, 600])!.addService(googletag.pubads()); });
| پارامترها | |
|---|---|
| یک تابع جاوا اسکریپت که باید اجرا شود. متغیر زمان اجرا همیشه globalThis خواهد بود. ارسال یک تابع فلش را برای حفظ مقدار this از زمینه لغوی در برگیرنده در نظر بگیرید. |
| بازگشتها | |
|---|---|
number | تعداد دستورات پردازش شده تاکنون. این با مقدار بازگشتی Array.push (طول فعلی آرایه) سازگار است. |
خدمات تبلیغات همراه گوگل تگ
Service گسترش میدهد| روشها | |
|---|---|
add Event Listener | یک شنونده (listener) ثبت میکند که به شما امکان میدهد هنگام وقوع یک رویداد خاص GPT در صفحه، یک تابع جاوا اسکریپت را تنظیم و فراخوانی کنید. از |
get Slots | لیست اسلاتهای مرتبط با این سرویس را دریافت کنید. از |
remove Event Listener | شنوندهای که قبلاً ثبتنام شده است را حذف میکند. از |
set Refresh Unfilled Slots | تنظیم میکند که آیا اسلاتهای همراه که پر نشدهاند، به طور خودکار دوباره پر شوند یا خیر. |
- همچنین ببینید
روشها
setRefreshUnfilledSlots
setRefreshUnfilledSlots ( value : boolean ) : voidاین متد را میتوان چندین بار در طول عمر صفحه فراخوانی کرد تا قابلیت پر کردن مجدد را فعال و غیرفعال کند. فقط اسلاتهایی که در PubAdsService نیز ثبت شدهاند، دوباره پر میشوند. با توجه به محدودیتهای سیاست، این متد برای پر کردن اسلاتهای خالی همراه هنگام ارائه ویدیوی Ad Exchange طراحی نشده است.
- مثال
جاوا اسکریپت
googletag.companionAds().setRefreshUnfilledSlots(true);
جاوا اسکریپت (قدیمی)
googletag.companionAds().setRefreshUnfilledSlots(true);
تایپ اسکریپت
googletag.companionAds().setRefreshUnfilledSlots(true);
| پارامترها | |
|---|---|
value : boolean | برای پر کردن خودکار فضاهای خالی، true و برای بدون تغییر گذاشتن آنها، false را وارد کنید. |
پیکربندی تنظیمات حریم خصوصی گوگل تگ
| خواص | |
|---|---|
child Directed Treatment ? | نشان میدهد که آیا صفحه باید به عنوان صفحه فرزند-محور در نظر گرفته شود یا خیر. |
limited Ads ? | برای کمک به الزامات انطباق با مقررات ناشر، امکان اجرای سرویس در حالت تبلیغات محدود را فراهم میکند. |
non Personalized Ads ? | برای کمک به نیازهای انطباق با مقررات ناشر، امکان اجرا در حالت تبلیغات غیرشخصیسازیشده را فراهم میکند. |
restrict Data Processing ? | برای کمک به نیازهای انطباق با مقررات ناشر، امکان اجرای سرویس در حالت پردازش محدود را فراهم میکند. |
traffic Source ? | نشان میدهد که آیا درخواستها نشاندهنده ترافیک خریداری شده یا ارگانیک هستند. |
under Age Of Consent ? | نشان میدهد که آیا درخواستهای تبلیغ به عنوان درخواستهایی که از کاربران زیر سن قانونی ارسال میشوند، علامتگذاری شوند یا خیر. |
- همچنین ببینید
خواص
درمان Optional هدایتشده توسط کودک
childDirectedTreatment ?: booleannull قرار دهید. تبلیغات محدود Optional
limitedAds ?: booleanشما میتوانید به دو روش به GPT دستور دهید که تبلیغات محدود درخواست کند:
- به صورت خودکار، با استفاده از سیگنالی از پلتفرم مدیریت رضایت IAB TCF v2.0 .
- به صورت دستی، با تنظیم مقدار این فیلد روی
true.
توجه داشته باشید که هنگام استفاده از CMP، فعال کردن دستی تبلیغات محدود ضروری نیست.
- مثال
جاوا اسکریپت
// Manually enable limited ads serving. // GPT must be loaded from the limited ads URL to configure this setting. googletag.pubads().setPrivacySettings({ limitedAds: true, });
جاوا اسکریپت (قدیمی)
// Manually enable limited ads serving. // GPT must be loaded from the limited ads URL to configure this setting. googletag.pubads().setPrivacySettings({ limitedAds: true, });
تایپ اسکریپت
// Manually enable limited ads serving. // GPT must be loaded from the limited ads URL to configure this setting. googletag.pubads().setPrivacySettings({ limitedAds: true, });
- همچنین ببینید
تبلیغات غیرشخصی Optional
nonPersonalizedAds ?: boolean محدود کردن Optional پردازش داده
restrictDataProcessing ?: boolean منبع ترافیک Optional
trafficSource ?: TrafficSourceundefined تنظیم میشود.- مثال
جاوا اسکریپت
// 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, });
جاوا اسکریپت (قدیمی)
// 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, });
تایپ اسکریپت
// Indicate requests represent organic traffic. googletag.pubads().setPrivacySettings({ trafficSource: googletag.enums.TrafficSource.ORGANIC, }); // Indicate requests represent purchased traffic. googletag.pubads().setPrivacySettings({ trafficSource: googletag.enums.TrafficSource.PURCHASED, });
Optional زیر سن قانونی
underAgeOfConsent ?: booleannull تنظیم کنید. سرویس تبلیغات گوگل (googletag.PubAds)
Service گسترش میدهد| روشها | |
|---|---|
add Event Listener | یک شنونده (listener) ثبت میکند که به شما امکان میدهد هنگام وقوع یک رویداد خاص GPT در صفحه، یک تابع جاوا اسکریپت را تنظیم و فراخوانی کنید. از |
clear | تبلیغات را از جایگاههای داده شده حذف کرده و آنها را با محتوای خالی جایگزین میکند. |
clear Category Exclusions | منسوخ شده. تمام برچسبهای حذف دستهبندی تبلیغات در سطح صفحه را پاک میکند. |
clear Targeting | منسوخ شده. پارامترهای هدفگیری سفارشی را برای یک کلید خاص یا برای همه کلیدها پاک میکند. |
collapse Empty Divs | منسوخ شده. قابلیت جمع شدن div های اسلات را فعال میکند تا وقتی هیچ محتوای تبلیغاتی برای نمایش وجود ندارد، فضایی از صفحه را اشغال نکنند. |
disable Initial Load | منسوخ شده. درخواست تبلیغات در هنگام بارگذاری صفحه را غیرفعال میکند، اما اجازه میدهد تبلیغات با فراخوانی PubAdsService.refresh درخواست شوند. |
display | یک جایگاه تبلیغاتی با مسیر و اندازه واحد تبلیغاتی داده شده میسازد و نمایش میدهد. |
enable Lazy Load | منسوخ شده. بارگذاری تنبل را در GPT فعال میکند، همانطور که توسط شیء پیکربندی تعریف شده است. |
enable Single Request | منسوخ شده. حالت درخواست واحد را برای دریافت چندین تبلیغ به طور همزمان فعال میکند. |
enable Video Ads | منسوخ شده. به GPT سیگنال میدهد که تبلیغات ویدیویی در صفحه وجود خواهد داشت. |
get | منسوخ شده. مقدار مربوط به ویژگی AdSense مرتبط با کلید داده شده را برمیگرداند. |
get Attribute Keys | منسوخ شده. کلیدهای ویژگی تنظیم شده روی این سرویس را برمیگرداند. |
get Slots | لیست اسلاتهای مرتبط با این سرویس را دریافت کنید. از |
get Targeting | منسوخ شده. یک پارامتر هدفگیری سطح سرویس سفارشی خاص که تنظیم شده است را برمیگرداند. |
get Targeting Keys | منسوخ شده. لیستی از تمام کلیدهای هدفگیری سطح سرویس سفارشی که تنظیم شدهاند را برمیگرداند. |
is Initial Load Disabled | منسوخ شده. برمیگرداند که آیا درخواستهای اولیه برای تبلیغات با موفقیت توسط فراخوانی قبلی PubAdsService.disableInitialLoad غیرفعال شدهاند یا خیر. |
refresh | تبلیغات جدید را برای یک یا همه جایگاههای خاص در صفحه دریافت و نمایش میدهد. |
remove Event Listener | شنوندهای که قبلاً ثبتنام شده است را حذف میکند. از |
set | منسوخ شده. مقادیری را برای ویژگیهای AdSense تنظیم میکند که برای همه جایگاههای تبلیغاتی تحت سرویس تبلیغات ناشر اعمال میشود. |
set Category Exclusion | منسوخ شده. برای نام برچسب داده شده، یک استثنای دستهبندی تبلیغات در سطح صفحه تنظیم میکند. |
set Centering | منسوخ شده. فعال و غیرفعال کردن قرار دادن تبلیغات در مرکز افقی. |
set Force Safe Frame | منسوخ شده. پیکربندی میکند که آیا همه تبلیغات موجود در صفحه باید با استفاده از یک کانتینر SafeFrame رندر شوند یا خیر. |
set Location | منسوخ شده. اطلاعات موقعیت مکانی را از وبسایتها ارسال میکند تا بتوانید آیتمهای خطی را به مکانهای خاص جغرافیایی هدایت کنید. |
set Privacy Settings | امکان پیکربندی تمام تنظیمات حریم خصوصی را از یک API واحد با استفاده از یک شیء پیکربندی فراهم میکند. |
set Publisher Provided Id | مقدار شناسه ارائه شده توسط ناشر را تنظیم میکند. |
set Safe Frame Config | منسوخ شده. تنظیمات سطح صفحه را برای پیکربندی SafeFrame تنظیم میکند. |
set Targeting | منسوخ شده. پارامترهای هدفگیری سفارشی را برای یک کلید مشخص تنظیم میکند که برای همه جایگاههای تبلیغاتی سرویس تبلیغات ناشر اعمال میشود. |
set Video Content | منسوخ شده. اطلاعات محتوای ویدیو را که باید همراه با درخواستهای تبلیغ برای اهداف هدفگیری و حذف محتوا ارسال شوند، تنظیم میکند. |
update Correlator | همبستگیای را که با درخواستهای تبلیغ ارسال میشود تغییر میدهد و عملاً یک نمای صفحه جدید را آغاز میکند. |
روشها
واضح
clear ( slots ?: Slot [] ) : booleanبه طور خاص، پاک کردن یک جایگاه، تبلیغ را از نمای صفحه طولانی مدت GPT حذف میکند، بنابراین درخواستهای آینده تحت تأثیر موانع یا حذفهای رقابتی مربوط به این تبلیغ قرار نخواهند گرفت.
- مثال
جاوا اسکریپت
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();
جاوا اسکریپت (قدیمی)
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();
تایپ اسکریپت
const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!; googletag.display("div-1"); const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!; googletag.display("div-2"); // This call to clear only slot1. googletag.pubads().clear([slot1]); // This call to clear both slot1 and slot2. googletag.pubads().clear([slot1, slot2]); // This call to clear all slots. googletag.pubads().clear();
| پارامترها | |
|---|---|
| آرایهای از اسلاتها که باید پاک شوند. آرایه اختیاری است؛ اگر مشخص نشود، تمام اسلاتها پاک خواهند شد. |
| بازگشتها | |
|---|---|
boolean | اگر اسلاتها خالی شده باشند، true و در غیر این صورت false را برمیگرداند. |
پاک کردنردههااستثنائات
clearCategoryExclusions ( ) : PubAdsService- مثال
جاوا اسکریپت
// 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.
جاوا اسکریپت (قدیمی)
// 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.
تایپ اسکریپت
// Set category exclusion to exclude ads with 'AirlineAd' labels. googletag.pubads().setCategoryExclusion("AirlineAd"); // Make ad requests. No ad with 'AirlineAd' label will be returned. // Clear category exclusions so all ads can be returned. googletag.pubads().clearCategoryExclusions(); // Make ad requests. Any ad can be returned.
- همچنین ببینید
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که متد روی آن فراخوانی شده است. |
هدفگیری شفاف
clearTargeting ( key ?: string ) : PubAdsService- مثال
جاوا اسکریپت
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.
جاوا اسکریپت (قدیمی)
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.
تایپ اسکریپت
googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().setTargeting("fruits", "apple"); googletag.pubads().clearTargeting("interests"); // Targeting 'colors' and 'fruits' are still present, while 'interests' // was cleared. googletag.pubads().clearTargeting(); // All targeting has been cleared.
- همچنین ببینید
| پارامترها | |
|---|---|
| کلید پارامتر هدفگیری. این کلید اختیاری است؛ در صورت عدم تعیین آن، تمام پارامترهای هدفگیری پاک خواهند شد. |
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که متد روی آن فراخوانی شده است. |
collapseEmptyDivs
collapseEmptyDivs ( collapseBeforeAdFetch ?: boolean ) : boolean| پارامترها | |
|---|---|
| اینکه آیا حتی قبل از نمایش تبلیغات، اسلاتها بسته شوند یا خیر. این پارامتر اختیاری است؛ در صورت عدم ارائه، مقدار پیشفرض false در نظر گرفته میشود. |
| بازگشتها | |
|---|---|
boolean | اگر حالت فروپاشی div فعال بوده باشد، true و اگر فعال کردن حالت فروپاشی به دلیل فراخوانی متد پس از فعال شدن سرویس غیرممکن باشد false را برمیگرداند. |
غیرفعال کردن بارگذاری اولیه
disableInitialLoad ( ) : voidrefresh غیرممکن خواهد بود.- همچنین ببینید
نمایش
display ( adUnitPath : string , size : GeneralSize , div ?: string | Element , clickUrl ?: string ) : voidتوجه: وقتی این متد فراخوانی میشود، یک تصویر لحظهای از وضعیت اسلات و صفحه ایجاد میشود تا از ثبات هنگام ارسال درخواست تبلیغ و رندر پاسخ اطمینان حاصل شود. هرگونه تغییری که پس از فراخوانی این متد در وضعیت اسلات یا صفحه ایجاد شود (از جمله هدفگیری، تنظیمات حریم خصوصی، اجبار SafeFrame و غیره) فقط در درخواستهای بعدی
display() یا refresh() اعمال خواهد شد.- مثال
جاوا اسکریپت
googletag.pubads().display("/1234567/sports", [728, 90], "div-1");
جاوا اسکریپت (قدیمی)
googletag.pubads().display("/1234567/sports", [728, 90], "div-1");
تایپ اسکریپت
googletag.pubads().display("/1234567/sports", [728, 90], "div-1");
- همچنین ببینید
| پارامترها | |
|---|---|
adUnitPath : string | مسیر واحد تبلیغاتی اسلاتی که قرار است رندر شود. |
size : GeneralSize | عرض و ارتفاع شکاف. |
| یا شناسهی div حاوی اسلات یا خود عنصر div. |
| آدرس اینترنتی کلیک برای استفاده در این اسلات. |
فعالسازی بارگذاری تنبل
enableLazyLoad ( config ?: {
fetchMarginPercent ?: number ;
mobileScaling ?: number ;
renderMarginPercent ?: number ;
} ) : voidنکته: واکشی تنبل در SRA فقط در صورتی کار میکند که همه اسلاتها خارج از حاشیه واکشی باشند.
- مثال
جاوا اسکریپت
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, });
جاوا اسکریپت (قدیمی)
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, });
تایپ اسکریپت
googletag.pubads().enableLazyLoad({ // Fetch slots within 5 viewports. fetchMarginPercent: 500, // Render slots within 2 viewports. renderMarginPercent: 200, // Double the above values on mobile. mobileScaling: 2.0, });
| پارامترها | |
|---|---|
| شیء پیکربندی امکان سفارشیسازی رفتار تنبل (lazy behavior) را فراهم میکند. هرگونه پیکربندی حذفشده از یک تنظیم پیشفرض توسط گوگل استفاده میکند که به مرور زمان تنظیم میشود. برای غیرفعال کردن یک تنظیم خاص، مانند حاشیه واکشی، مقدار را روی -1 تنظیم کنید.
|
enableSingleRequest
enableSingleRequest ( ) : boolean| بازگشتها | |
|---|---|
boolean | اگر حالت درخواست تکی فعال شده باشد، true و اگر فعال کردن حالت درخواست تکی به دلیل فراخوانی متد پس از فعال شدن سرویس غیرممکن باشد false را برمیگرداند. |
فعال کردن تبلیغات ویدیویی
enableVideoAds ( ) : voidدریافت
get ( key : string ) : string- مثال
جاوا اسکریپت
googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().get("adsense_background_color"); // Returns '#FFFFFF'.
جاوا اسکریپت (قدیمی)
googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().get("adsense_background_color"); // Returns '#FFFFFF'.
تایپ اسکریپت
googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().get("adsense_background_color"); // Returns '#FFFFFF'.
- همچنین ببینید
| پارامترها | |
|---|---|
key : string | نام ویژگی مورد نظر برای جستجو. |
| بازگشتها | |
|---|---|
string | مقدار فعلی برای کلید ویژگی، یا در صورت عدم وجود کلید، null است. |
کلیدهای ویژگی را دریافت کنید
getAttributeKeys ( ) : string []- مثال
جاوا اسکریپت
googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().set("adsense_border_color", "#AABBCC"); googletag.pubads().getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color'].
جاوا اسکریپت (قدیمی)
googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().set("adsense_border_color", "#AABBCC"); googletag.pubads().getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color'].
تایپ اسکریپت
googletag.pubads().set("adsense_background_color", "#FFFFFF"); googletag.pubads().set("adsense_border_color", "#AABBCC"); googletag.pubads().getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color'].
| بازگشتها | |
|---|---|
string [] | آرایهای از کلیدهای ویژگی تنظیمشده روی این سرویس. ترتیب آن تعریف نشده است. |
هدفگیری
getTargeting ( key : string ) : string []- مثال
جاوا اسکریپت
googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().getTargeting("interests"); // Returns ['sports']. googletag.pubads().getTargeting("age"); // Returns [] (empty array).
جاوا اسکریپت (قدیمی)
googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().getTargeting("interests"); // Returns ['sports']. googletag.pubads().getTargeting("age"); // Returns [] (empty array).
تایپ اسکریپت
googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().getTargeting("interests"); // Returns ['sports']. googletag.pubads().getTargeting("age"); // Returns [] (empty array).
| پارامترها | |
|---|---|
key : string | کلید هدفگیری که باید به دنبالش باشید. |
| بازگشتها | |
|---|---|
string [] | مقادیر مرتبط با این کلید، یا یک آرایه خالی در صورت عدم وجود چنین کلیدی. |
کلیدهای هدفگیری را دریافت کنید
getTargetingKeys ( ) : string []- مثال
جاوا اسکریپت
googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().getTargetingKeys(); // Returns ['interests', 'colors'].
جاوا اسکریپت (قدیمی)
googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().getTargetingKeys(); // Returns ['interests', 'colors'].
تایپ اسکریپت
googletag.pubads().setTargeting("interests", "sports"); googletag.pubads().setTargeting("colors", "blue"); googletag.pubads().getTargetingKeys(); // Returns ['interests', 'colors'].
| بازگشتها | |
|---|---|
string [] | آرایهای از کلیدهای هدفگیری. ترتیب آن تعریف نشده است. |
isInitialLoadDisabled
isInitialLoadDisabled ( ) : boolean| بازگشتها | |
|---|---|
boolean | اگر فراخوانی قبلی PubAdsService.disableInitialLoad موفقیتآمیز بوده باشد، true و در غیر این صورت مقدار false را برمیگرداند. |
تازه کردن
refresh ( slots ?: Slot [] , options ?: {
changeCorrelator : boolean ;
} ) : voidبرای عملکرد صحیح در همه مرورگرها، فراخوانی
refresh باید قبل از فراخوانی برای display جایگاه تبلیغ انجام شود. اگر فراخوانی display حذف شود، ممکن است refresh رفتار غیرمنتظرهای داشته باشد. در صورت تمایل، میتوان از متد PubAdsService.disableInitialLoad برای جلوگیری از دریافت تبلیغ توسط display استفاده کرد.بهروزرسانی یک بازه، تبلیغ قدیمی را از نمای صفحه طولانیمدت GPT حذف میکند، بنابراین درخواستهای آینده تحت تأثیر موانع یا حذفهای رقابتی مربوط به آن تبلیغ قرار نخواهند گرفت.
- مثال
جاوا اسکریپت
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 });
جاوا اسکریپت (قدیمی)
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 });
تایپ اسکریپت
const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!; googletag.display("div-1"); const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!; googletag.display("div-2"); // This call to refresh fetches a new ad for slot1 only. googletag.pubads().refresh([slot1]); // This call to refresh fetches a new ad for both slot1 and slot2. googletag.pubads().refresh([slot1, slot2]); // This call to refresh fetches a new ad for each slot. googletag.pubads().refresh(); // This call to refresh fetches a new ad for slot1, without changing // the correlator. googletag.pubads().refresh([slot1], { changeCorrelator: false }); // This call to refresh fetches a new ad for each slot, without // changing the correlator. googletag.pubads().refresh(null, { changeCorrelator: false });
| پارامترها | |
|---|---|
| اسلاتهایی که باید بهروزرسانی شوند. آرایه اختیاری است؛ اگر مشخص نشود، همه اسلاتها بهروزرسانی میشوند. |
| گزینههای پیکربندی مرتبط با این فراخوانی بهروزرسانی.
|
مجموعه
set ( key : string , value : string ) : PubAdsServiceفراخوانی این تابع بیش از یک بار برای یک کلید، مقادیر تنظیم شده قبلی برای آن کلید را لغو میکند. همه مقادیر باید قبل از فراخوانی
display یا refresh تنظیم شوند.- مثال
جاوا اسکریپت
googletag.pubads().set("adsense_background_color", "#FFFFFF");
جاوا اسکریپت (قدیمی)
googletag.pubads().set("adsense_background_color", "#FFFFFF");
تایپ اسکریپت
googletag.pubads().set("adsense_background_color", "#FFFFFF");
- همچنین ببینید
| پارامترها | |
|---|---|
key : string | نام ویژگی. |
value : string | مقدار ویژگی. |
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که متد روی آن فراخوانی شده است. |
مجموعه ردهبندی استثنا
setCategoryExclusion ( categoryExclusion : string ) : PubAdsService- مثال
جاوا اسکریپت
// Label = AirlineAd. googletag.pubads().setCategoryExclusion("AirlineAd");
جاوا اسکریپت (قدیمی)
// Label = AirlineAd. googletag.pubads().setCategoryExclusion("AirlineAd");
تایپ اسکریپت
// Label = AirlineAd. googletag.pubads().setCategoryExclusion("AirlineAd");
- همچنین ببینید
| پارامترها | |
|---|---|
categoryExclusion : string | برچسب حذف دسته آگهی برای اضافه کردن. |
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که متد روی آن فراخوانی شده است. |
تنظیم مرکزی
setCentering ( centerAds : boolean ) : voidاین متد باید قبل از فراخوانی
display یا refresh فراخوانی شود، زیرا فقط تبلیغاتی که پس از فراخوانی این متد درخواست میشوند، در مرکز صفحه قرار میگیرند.- مثال
جاوا اسکریپت
// Make ads centered. googletag.pubads().setCentering(true);
جاوا اسکریپت (قدیمی)
// Make ads centered. googletag.pubads().setCentering(true);
تایپ اسکریپت
// Make ads centered. googletag.pubads().setCentering(true);
| پارامترها | |
|---|---|
centerAds : boolean | برای تبلیغات در مرکز، true برای تبلیغات در سمت چپ، false . |
تنظیم فریم امن نیرو
setForceSafeFrame ( forceSafeFrame : boolean ) : PubAdsServiceلطفا هنگام استفاده از این API موارد زیر را در نظر داشته باشید:
- این تنظیم فقط برای درخواستهای تبلیغاتی بعدی که برای اسلاتهای مربوطه انجام میشوند، اعمال خواهد شد.
- تنظیم سطح اسلات، در صورت مشخص شدن، همیشه بر تنظیم سطح صفحه اولویت خواهد داشت.
- اگر روی
trueتنظیم شود (در سطح اسلات یا سطح صفحه)، تبلیغ همیشه با استفاده از یک ظرف SafeFrame مستقل از انتخابی که در رابط کاربری Google Ad Manager انجام شده است، رندر میشود. - با این حال، اگر روی
falseتنظیم شود یا نامشخص باقی بماند، تبلیغ با استفاده از یک محفظه SafeFrame بسته به نوع تبلیغ و انتخاب انجام شده در رابط کاربری Google Ad Manager رندر میشود. - این API باید با احتیاط استفاده شود زیرا میتواند بر رفتار طراحانی که سعی در خروج از iFrameهای خود دارند یا به رندر شدن مستقیم آنها در صفحه ناشران متکی هستند، تأثیر بگذارد.
- مثال
جاوا اسکریپت
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");
جاوا اسکریپت (قدیمی)
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");
تایپ اسکریپت
googletag.pubads().setForceSafeFrame(true); // The following slot will be opted-out of the page-level force // SafeFrame instruction. googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setForceSafeFrame(false) .addService(googletag.pubads()); // The following slot will have SafeFrame forced. googletag.defineSlot("/1234567/news", [160, 600], "div-2")!.addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2");
- همچنین ببینید
| پارامترها | |
|---|---|
forceSafeFrame : boolean | برای اینکه تمام تبلیغات صفحه در SafeFrames رندر شوند، true false برای تغییر تنظیمات قبلی به false، مقدار false را وارد کنید. تنظیم این مقدار روی false در صورتی که قبلاً مشخص نشده باشد، چیزی را تغییر نمیدهد. |
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که متد روی آن فراخوانی شده است. |
تنظیم موقعیت مکانی
setLocation ( address : string ) : PubAdsService- مثال
جاوا اسکریپت
// Postal code: googletag.pubads().setLocation("10001,US");
جاوا اسکریپت (قدیمی)
// Postal code: googletag.pubads().setLocation("10001,US");
تایپ اسکریپت
// Postal code: googletag.pubads().setLocation("10001,US");
| پارامترها | |
|---|---|
address : string | آدرس فریفرم. |
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که متد روی آن فراخوانی شده است. |
تنظیمات حریم خصوصی
setPrivacySettings ( privacySettings : PrivacySettingsConfig ) : PubAdsService- مثال
جاوا اسکریپت
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, });
جاوا اسکریپت (قدیمی)
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, });
تایپ اسکریپت
googletag.pubads().setPrivacySettings({ restrictDataProcessing: true, }); // Set multiple privacy settings at the same time. googletag.pubads().setPrivacySettings({ childDirectedTreatment: true, underAgeOfConsent: true, }); // Clear the configuration for childDirectedTreatment. googletag.pubads().setPrivacySettings({ childDirectedTreatment: null, });
- همچنین ببینید
| پارامترها | |
|---|---|
privacySettings : PrivacySettingsConfig | شیء حاوی پیکربندی تنظیمات حریم خصوصی. |
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که تابع روی آن فراخوانی شده است. |
شناسه ناشر تنظیمشده
setPublisherProvidedId ( ppid : string ) : PubAdsService- مثال
جاوا اسکریپت
googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
جاوا اسکریپت (قدیمی)
googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
تایپ اسکریپت
googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
- همچنین ببینید
| پارامترها | |
|---|---|
ppid : string | یک شناسه الفبایی-عددی که توسط ناشر ارائه میشود. باید بین ۳۲ تا ۱۵۰ کاراکتر باشد. |
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که متد روی آن فراخوانی شده است. |
پیکربندی setSafeFrame
setSafeFrameConfig ( config : SafeFrameConfig ) : PubAdsServiceاین تنظیمات سطح صفحه، در صورت مشخص شدن، توسط تنظیمات سطح اسلات لغو میشوند.
- مثال
جاوا اسکریپت
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");
جاوا اسکریپت (قدیمی)
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");
تایپ اسکریپت
googletag.pubads().setForceSafeFrame(true); const pageConfig = { allowOverlayExpansion: true, allowPushExpansion: true, sandbox: true, }; const slotConfig = { allowOverlayExpansion: false }; googletag.pubads().setSafeFrameConfig(pageConfig); // The following slot will not allow for expansion by overlay. googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setSafeFrameConfig(slotConfig) .addService(googletag.pubads()); // The following slot will inherit the page level settings, and hence // would allow for expansion by overlay. googletag.defineSlot("/1234567/news", [160, 600], "div-2")!.addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2");
- همچنین ببینید
| پارامترها | |
|---|---|
config : SafeFrameConfig | شیء پیکربندی. |
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که متد روی آن فراخوانی شده است. |
تنظیم هدفگیری
setTargeting ( key : string , value : string | string [] ) : PubAdsService- مثال
جاوا اسکریپت
// 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"]);
جاوا اسکریپت (قدیمی)
// 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"]);
تایپ اسکریپت
// Example with a single value for a key. googletag.pubads().setTargeting("interests", "sports"); // Example with multiple values for a key inside in an array. googletag.pubads().setTargeting("interests", ["sports", "music"]);
- همچنین ببینید
| پارامترها | |
|---|---|
key : string | کلید پارامتر هدفگیری. |
value : string | string [] | هدف قرار دادن مقدار پارامتر یا آرایهای از مقادیر. |
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که متد روی آن فراخوانی شده است. |
محتوای ویدیو را تنظیم کنید
setVideoContent ( videoContentId : string , videoCmsId : string ) : voidvideoContentId و videoCmsId ، از مقادیری که به سرویس جذب محتوای Google Ad Manager ارائه میشود، استفاده کنید.- همچنین ببینید
| پارامترها | |
|---|---|
videoContentId : string | شناسه محتوای ویدیو. |
videoCmsId : string | شناسه سیستم مدیریت محتوای ویدیو. |
بهروزرسانیهمبستگی
updateCorrelator ( ) : PubAdsServiceتوجه: این هیچ تاثیری بر نمایش طولانی مدت صفحه GPT ندارد، که به طور خودکار تبلیغات موجود در صفحه را منعکس میکند و هیچ زمان انقضایی ندارد.
- مثال
جاوا اسکریپت
// 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.
جاوا اسکریپت (قدیمی)
// 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.
تایپ اسکریپت
// Assume that the correlator is currently 12345. All ad requests made // by this page will currently use that value. // Replace the current correlator with a new correlator. googletag.pubads().updateCorrelator(); // The correlator will now be a new randomly selected value, different // from 12345. All subsequent ad requests made by this page will use // the new value.
| بازگشتها | |
|---|---|
PubAdsService | شیء سرویسی که تابع روی آن فراخوانی شده است. |
اطلاعات پاسخ googletag
| خواص | |
|---|---|
advertiser Id | شناسه آگهی دهنده. |
campaign Id | شناسه کمپین. |
creative Id | شناسنامهی فرد خلاق. |
creative Template Id | شناسه قالب تبلیغ. |
line Item Id | شناسهی ردیف. |
خواص
شناسه تبلیغکننده
advertiserId : numberشناسه کمپین
campaignId : numberکریتیو آیدی
creativeId : numberشناسه قالب خلاق
creativeTemplateId : numberشناسه خط
lineItemId : numbergoogletag.RewardedPayload
| خواص | |
|---|---|
amount | تعداد اقلامی که شامل پاداش میشوند. |
type | نوع آیتمی که در پاداش گنجانده شده است (برای مثال، «سکه»). |
- همچنین ببینید
خواص
مبلغ
amount : numberنوع
type : stringسرویس googletag
| روشها | |
|---|---|
add Event Listener | یک شنونده (listener) ثبت میکند که به شما امکان میدهد هنگام وقوع یک رویداد خاص GPT در صفحه، یک تابع جاوا اسکریپت را تنظیم و فراخوانی کنید. |
get Slots | لیست اسلاتهای مرتبط با این سرویس را دریافت کنید. |
remove Event Listener | شنوندهای که قبلاً ثبتنام شده است را حذف میکند. |
روشها
addEventListener
addEventListener < K extends keyof EventTypeMap > ( eventType : K , listener : ( ( arg : EventTypeMap [ K ] ) => void ) ) : Service- events.GameManualInterstitialSlotClosedEvent
- events.GameManualInterstitialSlotReadyEvent
- events.ImpressionViewableEvent
- events.RewardedSlotClosedEvent
- events.RewardedSlotGrantedEvent
- events.RewardedSlotReadyEvent
- events.SlotOnloadEvent
- events.SlotRenderEndedEvent
- events.SlotRequestedEvent
- events.SlotResponseReceived
- events.SlotVisibilityChangedEvent
- مثال
جاوا اسکریپت
// 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 (legacy)
// 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. } });
تایپ اسکریپت
// 1. Adding an event listener for the PubAdsService. googletag.pubads().addEventListener("slotOnload", (event) => { console.log("Slot has been loaded:"); console.log(event); }); // 2. Adding an event listener with slot specific logic. // Listeners operate at service level, which means that you cannot add // a listener for an event for a specific slot only. You can, however, // programmatically filter a listener to respond only to a certain ad // slot, using this pattern: const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotOnload", (event) => { if (event.slot === targetSlot) { // Slot specific logic. } });
- همچنین ببینید
| پارامترها | |
|---|---|
eventType : K | A string representing the type of event generated by GPT. Event types are case sensitive. |
listener : ( ( arg : EventTypeMap [ K ] ) => void ) | Function that takes a single event object argument. |
| بازگشتها | |
|---|---|
Service | The service object on which the method was called. |
getSlots
removeEventListener
removeEventListener < K extends keyof EventTypeMap > ( eventType : K , listener : ( ( event : EventTypeMap [ K ] ) => void ) ) : void- مثال
جاوا اسکریپت
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 (legacy)
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(); });
تایپ اسکریپت
googletag.cmd.push(() => { // Define a new ad slot. googletag .defineSlot("/6355419/Travel", [728, 90], "div-for-slot")! .addService(googletag.pubads()); // Define a new function that removes itself via removeEventListener // after the impressionViewable event fires. const onViewableListener = (event: googletag.events.ImpressionViewableEvent) => { googletag.pubads().removeEventListener("impressionViewable", onViewableListener); setTimeout(() => { googletag.pubads().refresh([event.slot]); }, 30000); }; // Add onViewableListener as a listener for impressionViewable events. googletag.pubads().addEventListener("impressionViewable", onViewableListener); googletag.enableServices(); });
| پارامترها | |
|---|---|
eventType : K | A string representing the type of event generated by GPT. Event types are case sensitive. |
listener : ( ( event : EventTypeMap [ K ] ) => void ) | Function that takes a single event object argument. |
googletag.SizeMappingBuilder
| روشها | |
|---|---|
add Size | Adds a mapping from a single-size array (representing the viewport) to a single- or multi-size array representing the slot. |
build | Builds a size map specification from the mappings added to this builder. |
- همچنین ببینید
روشها
addSize
addSize ( viewportSize : SingleSizeArray , slotSize : GeneralSize ) : SizeMappingBuilder- مثال
جاوا اسکریپت
// 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 (legacy)
// 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]
تایپ اسکریپت
// Mapping 1 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], [728, 90]) .addSize([640, 480], "fluid") .addSize([0, 0], [88, 31]) // All viewports < 640x480 .build(); // Mapping 2 googletag .sizeMapping() .addSize([1024, 768], [970, 250]) .addSize([980, 690], []) .addSize([640, 480], [120, 60]) .addSize([0, 0], []) .build(); // Mapping 2 will not show any ads for the following viewport sizes: // [1024, 768] > size >= [980, 690] and // [640, 480] > size >= [0, 0]
| پارامترها | |
|---|---|
viewportSize : SingleSizeArray | The size of the viewport for this mapping entry. |
slotSize : GeneralSize | The sizes of the slot for this mapping entry. |
| بازگشتها | |
|---|---|
SizeMappingBuilder | A reference to this builder. |
ساختن
build ( ) : SizeMappingArrayIf any invalid mappings have been supplied, this method will return
null . Otherwise it returns a specification in the correct format to pass to Slot.defineSizeMapping .Note: the behavior of the builder after calling this method is undefined.
| بازگشتها | |
|---|---|
SizeMappingArray | The result built by this builder. Can be null if invalid size mappings were supplied. |
googletag.Slot
| روشها | |
|---|---|
add Service | Adds a Service to this slot. |
clear Category Exclusions | Deprecated. Clears all slot-level ad category exclusion labels for this slot. |
clear Targeting | Deprecated. Clears specific or all custom slot-level targeting parameters for this slot. |
define Size Mapping | Sets an array of mappings from a minimum viewport size to slot size for this slot. |
get | Deprecated. Returns the value for the AdSense attribute associated with the given key for this slot. |
get Ad Unit Path | Returns the full path of the ad unit, with the network code and ad unit path. |
get Attribute Keys | Deprecated. Returns the list of attribute keys set on this slot. |
get Category Exclusions | Deprecated. Returns the ad category exclusion labels for this slot. |
get Config | Gets general configuration options for the slot set by setConfig . |
get Response Information | Returns the ad response information. |
get Slot Element Id | Returns the ID of the slot div provided when the slot was defined. |
get Targeting | Deprecated. Returns a specific custom targeting parameter set on this slot. |
get Targeting Keys | Deprecated. Returns the list of all custom targeting keys set on this slot. |
set | Deprecated. Sets a value for an AdSense attribute on this ad slot. |
set Category Exclusion | Deprecated. Sets a slot-level ad category exclusion label on this slot. |
set Click Url | Deprecated. Sets the click URL to which users will be redirected after clicking on the ad. |
set Collapse Empty Div | Deprecated. Sets whether the slot div should be hidden when there is no ad in the slot. |
set Config | Sets general configuration options for this slot. |
set Force Safe Frame | Deprecated. Configures whether ads in this slot should be forced to be rendered using a SafeFrame container. |
set Safe Frame Config | Deprecated. Sets the slot-level preferences for SafeFrame configuration. |
set Targeting | Deprecated. Sets a custom targeting parameter for this slot. |
update Targeting From Map | Deprecated. Sets custom targeting parameters for this slot, from a key:value map in a JSON object. |
روشها
addService
addService ( service : Service ) : Slot- مثال
جاوا اسکریپت
googletag.defineSlot("/1234567/sports", [160, 600], "div").addService(googletag.pubads());
JavaScript (legacy)
googletag.defineSlot("/1234567/sports", [160, 600], "div").addService(googletag.pubads());
تایپ اسکریپت
googletag.defineSlot("/1234567/sports", [160, 600], "div")!.addService(googletag.pubads());
- همچنین ببینید
| پارامترها | |
|---|---|
service : Service | The service to be added. |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
clearCategoryExclusions
clearCategoryExclusions ( ) : Slot- مثال
جاوا اسکریپت
// 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 (legacy)
// 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.
تایپ اسکریپت
// Set category exclusion to exclude ads with 'AirlineAd' labels. const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setCategoryExclusion("AirlineAd") .addService(googletag.pubads()); // Make an ad request. No ad with 'AirlineAd' label will be returned // for the slot. // Clear category exclusions so all ads can be returned. slot.clearCategoryExclusions(); // Make an ad request. Any ad can be returned for the slot.
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
clearTargeting
clearTargeting ( key ?: string ) : Slot- مثال
جاوا اسکریپت
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 (legacy)
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.
تایپ اسکریپت
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.
- همچنین ببینید
| پارامترها | |
|---|---|
| Targeting parameter key. The key is optional; all targeting parameters will be cleared if it is unspecified. |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
defineSizeMapping
defineSizeMapping ( sizeMapping : SizeMappingArray ) : Slot- مثال
جاوا اسکریپت
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 (legacy)
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);
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); const mapping = googletag .sizeMapping() .addSize([100, 100], [88, 31]) .addSize( [320, 400], [ [320, 50], [300, 50], ], ) .build(); slot.defineSizeMapping(mapping!);
- همچنین ببینید
| پارامترها | |
|---|---|
sizeMapping : SizeMappingArray | Array of size mappings. You can use SizeMappingBuilder to create it. Each size mapping is an array of two elements: SingleSizeArray and GeneralSize . |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
دریافت
get ( key : string ) : string- مثال
جاوا اسکریپت
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 (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads()); slot.get("adsense_background_color"); // Returns '#FFFFFF'.
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads()); slot.get("adsense_background_color"); // Returns '#FFFFFF'.
- همچنین ببینید
| پارامترها | |
|---|---|
key : string | Name of the attribute to look for. |
| بازگشتها | |
|---|---|
string | Current value for the attribute key, or null if the key is not present. |
getAdUnitPath
getAdUnitPath ( ) : string- مثال
جاوا اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getAdUnitPath(); // Returns '/1234567/sports'.
JavaScript (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getAdUnitPath(); // Returns '/1234567/sports'.
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); slot.getAdUnitPath(); // Returns '/1234567/sports'.
| بازگشتها | |
|---|---|
string | Ad unit path. |
getAttributeKeys
getAttributeKeys ( ) : string []- مثال
جاوا اسکریپت
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 (legacy)
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'].
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .set("adsense_background_color", "#FFFFFF") .set("adsense_border_color", "#AABBCC") .addService(googletag.pubads()); slot.getAttributeKeys(); // Returns ['adsense_background_color', 'adsense_border_color'].
| بازگشتها | |
|---|---|
string [] | Array of attribute keys. Ordering is undefined. |
getCategoryExclusions
getCategoryExclusions ( ) : string []- مثال
جاوا اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .setCategoryExclusion("TrainAd") .addService(googletag.pubads()); slot.getCategoryExclusions(); // Returns ['AirlineAd', 'TrainAd'].
JavaScript (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .setCategoryExclusion("TrainAd") .addService(googletag.pubads()); slot.getCategoryExclusions(); // Returns ['AirlineAd', 'TrainAd'].
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setCategoryExclusion("AirlineAd") .setCategoryExclusion("TrainAd") .addService(googletag.pubads()); slot.getCategoryExclusions(); // Returns ['AirlineAd', 'TrainAd'].
| بازگشتها | |
|---|---|
string [] | The ad category exclusion labels for this slot, or an empty array if none have been set. |
دریافت پیکربندی
getConfig ( keys : string | string [] ) : Pick < SlotSettingsConfig , "adsenseAttributes" | "targeting" | "categoryExclusion" >Not all
setConfig() properties are supported by this method. Supported properties are:- مثال
جاوا اسکریپت
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div"); // Get the value of the `targeting` setting. const targetingConfig = slot.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `categoryExclusion` settings. const config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);
JavaScript (legacy)
var slot = googletag.defineSlot("/1234567/sports", [160, 600], "div"); // Get the value of the `targeting` setting. var targetingConfig = slot.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `categoryExclusion` settings. var config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);
تایپ اسکریپت
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div")!; // Get the value of the `targeting` setting. const targetingConfig = slot.getConfig("targeting"); // Get the value of the `adsenseAttributes` and `categoryExclusion` settings. const config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);
| پارامترها | |
|---|---|
keys : string | string [] | The keys of the configuration options to get. |
| بازگشتها | |
|---|---|
Pick < SlotSettingsConfig , "adsenseAttributes" | "targeting" | "categoryExclusion" > | The configuration options for the slot. |
getResponseInformation
getResponseInformation ( ) : ResponseInformationnull will be returned. | بازگشتها | |
|---|---|
ResponseInformation | The latest ad response information, or null if the slot has no ad. |
getSlotElementId
getSlotElementId ( ) : stringdiv provided when the slot was defined.- مثال
جاوا اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getSlotElementId(); // Returns 'div'.
JavaScript (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); slot.getSlotElementId(); // Returns 'div'.
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); slot.getSlotElementId(); // Returns 'div'.
| بازگشتها | |
|---|---|
string | Slot div ID. |
getTargeting
getTargeting ( key : string ) : string []- مثال
جاوا اسکریپت
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 (legacy)
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).
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setTargeting("allow_expandable", "true") .addService(googletag.pubads()); slot.getTargeting("allow_expandable"); // Returns ['true']. slot.getTargeting("age"); // Returns [] (empty array).
| پارامترها | |
|---|---|
key : string | The targeting key to look for. |
| بازگشتها | |
|---|---|
string [] | The values associated with this key, or an empty array if there is no such key. |
getTargetingKeys
getTargetingKeys ( ) : string []- مثال
جاوا اسکریپت
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 (legacy)
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'].
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setTargeting("allow_expandable", "true") .setTargeting("interests", ["sports", "music"]) .addService(googletag.pubads()); slot.getTargetingKeys(); // Returns ['interests', 'allow_expandable'].
| بازگشتها | |
|---|---|
string [] | Array of targeting keys. Ordering is undefined. |
مجموعه
set ( key : string , value : string ) : SlotCalling this method more than once for the same key will override previously set values for that key. All values must be set before calling
display or refresh .- مثال
جاوا اسکریپت
// Setting an attribute on a single ad slot. googletag .defineSlot("/1234567/sports", [160, 600], "div") .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads());
JavaScript (legacy)
// Setting an attribute on a single ad slot. googletag .defineSlot("/1234567/sports", [160, 600], "div") .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads());
تایپ اسکریپت
// Setting an attribute on a single ad slot. googletag .defineSlot("/1234567/sports", [160, 600], "div")! .set("adsense_background_color", "#FFFFFF") .addService(googletag.pubads());
- همچنین ببینید
| پارامترها | |
|---|---|
key : string | The name of the attribute. |
value : string | Attribute value. |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
setCategoryExclusion
setCategoryExclusion ( categoryExclusion : string ) : Slot- مثال
جاوا اسکریپت
// Label = AirlineAd googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .addService(googletag.pubads());
JavaScript (legacy)
// Label = AirlineAd googletag .defineSlot("/1234567/sports", [160, 600], "div") .setCategoryExclusion("AirlineAd") .addService(googletag.pubads());
تایپ اسکریپت
// Label = AirlineAd googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setCategoryExclusion("AirlineAd") .addService(googletag.pubads());
- همچنین ببینید
| پارامترها | |
|---|---|
categoryExclusion : string | The ad category exclusion label to add. |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
setClickUrl
setClickUrl ( value : string ) : SlotThe Google Ad Manager servers still record a click even if the click URL is replaced. Any landing page URL associated with the creative that is served is appended to the provided value. Subsequent calls overwrite the value. This works only for non-SRA requests.
- مثال
جاوا اسکریپت
googletag .defineSlot("/1234567/sports", [160, 600], "div") .setClickUrl("http://www.example.com?original_click_url=") .addService(googletag.pubads());
JavaScript (legacy)
googletag .defineSlot("/1234567/sports", [160, 600], "div") .setClickUrl("http://www.example.com?original_click_url=") .addService(googletag.pubads());
تایپ اسکریپت
googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setClickUrl("http://www.example.com?original_click_url=") .addService(googletag.pubads());
| پارامترها | |
|---|---|
value : string | The click URL to set. |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
setCollapseEmptyDiv
setCollapseEmptyDiv ( collapse : boolean , collapseBeforeAdFetch ?: boolean ) : Slotdiv should be hidden when there is no ad in the slot. This overrides the service-level settings.- مثال
جاوا اسکریپت
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 (legacy)
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.
تایپ اسکریپت
googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setCollapseEmptyDiv(true, true) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // when the page is loaded, before ads are requested. googletag .defineSlot("/1234567/sports", [160, 600], "div-2")! .setCollapseEmptyDiv(true) .addService(googletag.pubads()); // The above will cause the div for this slot to be collapsed // only after GPT detects that no ads are available for the slot.
- همچنین ببینید
| پارامترها | |
|---|---|
collapse : boolean | Whether to collapse the slot if no ad is returned. |
| Whether to collapse the slot even before an ad is fetched. Ignored if collapse is not true . |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
setConfig
setConfig ( slotConfig : SlotSettingsConfig ) : void| پارامترها | |
|---|---|
slotConfig : SlotSettingsConfig | The configuration object. |
setForceSafeFrame
setForceSafeFrame ( forceSafeFrame : boolean ) : SlotPlease keep the following things in mind while using this API:
- This setting will only take effect for subsequent ad requests made for the respective slots.
- The slot level setting, if specified, will always override the page level setting.
- If set to
true(at slot-level or page level), the ad will always be rendered using a SafeFrame container independent of the choice made in the Google Ad Manager UI. - However, if set to
falseor left unspecified, the ad will be rendered using a SafeFrame container depending on the type of creative and the selection made in the Google Ad Manager UI. - This API should be used with caution as it could impact the behaviour of creatives that attempt to break out of their iFrames or rely on them being rendered directly in a publishers page.
- مثال
جاوا اسکریپت
googletag .defineSlot("/1234567/sports", [160, 600], "div") .setForceSafeFrame(true) .addService(googletag.pubads());
JavaScript (legacy)
googletag .defineSlot("/1234567/sports", [160, 600], "div") .setForceSafeFrame(true) .addService(googletag.pubads());
تایپ اسکریپت
googletag .defineSlot("/1234567/sports", [160, 600], "div")! .setForceSafeFrame(true) .addService(googletag.pubads());
- همچنین ببینید
| پارامترها | |
|---|---|
forceSafeFrame : boolean | true to force all ads in this slot to be rendered in SafeFrames and false to opt-out of a page-level setting (if present). Setting this to false when not specified at the page-level won't change anything. |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
setSafeFrameConfig
setSafeFrameConfig ( config : SafeFrameConfig ) : SlotThese slot-level preferences, if specified, will override any page-level preferences.
- مثال
جاوا اسکریپت
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 (legacy)
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");
تایپ اسکریپت
googletag.pubads().setForceSafeFrame(true); // The following slot will have a sandboxed safeframe that only // disallows top-level navigation. googletag .defineSlot("/1234567/sports", [160, 600], "div-1")! .setSafeFrameConfig({ sandbox: true }) .addService(googletag.pubads()); // The following slot will inherit page-level settings. googletag.defineSlot("/1234567/news", [160, 600], "div-2")!.addService(googletag.pubads()); googletag.display("div-1"); googletag.display("div-2");
- همچنین ببینید
| پارامترها | |
|---|---|
config : SafeFrameConfig | The configuration object. |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
setTargeting
setTargeting ( key : string , value : string | string [] ) : Slot- مثال
جاوا اسکریپت
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 (legacy)
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"]);
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Example with a single value for a key. slot.setTargeting("allow_expandable", "true"); // Example with multiple values for a key inside in an array. slot.setTargeting("interests", ["sports", "music"]);
- همچنین ببینید
| پارامترها | |
|---|---|
key : string | Targeting parameter key. |
value : string | string [] | Targeting parameter value or array of values. |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
updateTargetingFromMap
updateTargetingFromMap ( map : {
[ adUnitPath : string ] : string | string [] ;
} ) : Slotیادداشتها:
- In case of overwriting, only the last value will be kept.
- If the value is an array, any previous value will be overwritten, not merged.
- Values set here will overwrite targeting parameters set at the service-level.
- مثال
جاوا اسکریپت
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div"); slot.updateTargetingFromMap({ color: "red", interests: ["sports", "music", "movies"], });
JavaScript (legacy)
var slot = googletag.defineSlot("/1234567/sports", [160, 600], "div"); slot.updateTargetingFromMap({ color: "red", interests: ["sports", "music", "movies"], });
تایپ اسکریپت
const slot = googletag.defineSlot("/1234567/sports", [160, 600], "div")!; slot.updateTargetingFromMap({ color: "red", interests: ["sports", "music", "movies"], });
| پارامترها | |
|---|---|
map : { | Targeting parameter key:value map. |
| بازگشتها | |
|---|---|
Slot | The slot object on which the method was called. |
googletag.config
| رابطها | |
|---|---|
Ad Expansion Config | Settings to control ad expansion. |
Ad Sense Attributes Config | Settings to control the behavior of AdSense ads. |
Component Auction Config | An object representing a single component auction in a on-device ad auction. |
Interstitial Config | An object which defines the behavior of a single interstitial ad slot. |
Lazy Load Config | Settings to control the use of lazy loading in GPT. |
Page Settings Config | Main configuration interface for page-level settings. |
Privacy Treatments Config | Settings to control publisher privacy treatments. |
Publisher Provided Signals Config | Publisher provided signals (PPS) configuration object. |
Safe Frame Config | Settings to control SafeFrame in GPT. |
Slot Settings Config | Main configuration interface for slot-level settings. |
Taxonomy Data | An object containing the values for a single Taxonomy . |
Video Ads Config | Settings to configure video ad related settings. |
| نامهای مستعار نوع | |
|---|---|
Collapse Div Behavior | Supported values for controlling the collapsing behavior of ad slots. |
Interstitial Trigger | Supported interstitial ad triggers. |
Privacy Treatment | Supported publisher privacy treatments. |
Taxonomy | Supported taxonomies for publisher provided signals (PPS) . |
نامهای مستعار نوع
CollapseDivBehavior
CollapseDivBehavior : "DISABLED" | "BEFORE_FETCH" | "ON_NO_FILL"- همچنین ببینید
InterstitialTrigger
InterstitialTrigger : "unhideWindow" | "navBar"PrivacyTreatment
PrivacyTreatment : "disablePersonalization"طبقهبندی
Taxonomy : "IAB_AUDIENCE_1_1" | "IAB_CONTENT_2_2"- همچنین ببینید
googletag.config.AdExpansionConfig
| خواص | |
|---|---|
enabled ? | Whether ad expansion is enabled or disabled. |
- مثال
جاوا اسکریپت
// Enable ad slot expansion across the entire page. googletag.setConfig({ adExpansion: { enabled: true }, });
JavaScript (legacy)
// Enable ad slot expansion across the entire page. googletag.setConfig({ adExpansion: { enabled: true }, });
تایپ اسکریپت
// Enable ad slot expansion across the entire page. googletag.setConfig({ adExpansion: { enabled: true }, });
خواص
Optional enabled
enabled ?: booleanSetting this value overrides the default configured in Google Ad Manager.
googletag.config.AdSenseAttributesConfig
These attributes can be used to override server-side settings on a per-request basis.
| خواص | |
|---|---|
adsense _ad _format ? | AdSense ad format. |
adsense _channel _ids ? | AdSense channel IDs. |
adsense _test _mode ? | Whether or not test mode is enabled. |
document _language ? | Language of the page on which ads are displayed. |
page _url ? | URL of the page on which ads are displayed. |
خواص
Optional adsense_ad_format
adsense_ad_format ?: "120x240_as" | "120x600_as" | "125x125_as" | "160x600_as" | "180x150_as" | "200x200_as" | "234x60_as" | "250x250_as" | "300x250_as" | "336x280_as" | "468x60_as" | "728x90_as" Optional adsense_channel_ids
adsense_channel_ids ?: stringAllowed values are channel IDs separated by '+'.
Example:
271828183+314159265- همچنین ببینید
Optional adsense_test_mode
adsense_test_mode ?: "on"When set to
on , ads are marked as test-only, and won't be included in counting or billing. This setting must be unset for production, non-test traffic. Optional document_language
document_language ?: stringAllowed values are valid ISO 639-1 language codes.
مثال:
en- همچنین ببینید
Optional page_url
page_url ?: stringAllowed values are valid URLs.
Example:
http://www.example.com googletag.config.ComponentAuctionConfig
| خواص | |
|---|---|
auction Config | An auction configuration object for this component auction. |
config Key | The configuration key associated with this component auction. |
- همچنین ببینید
خواص
auctionConfig
auctionConfig : {
auctionSignals ?: unknown ;
decisionLogicURL : string ;
interestGroupBuyers ?: string [] ;
perBuyerExperimentGroupIds ?: {
[ buyer : string ] : number ;
} ;
perBuyerGroupLimits ?: {
[ buyer : string ] : number ;
} ;
perBuyerSignals ?: {
[ buyer : string ] : unknown ;
} ;
perBuyerTimeouts ?: {
[ buyer : string ] : number ;
} ;
seller : string ;
sellerExperimentGroupId ?: number ;
sellerSignals ?: unknown ;
sellerTimeout ?: number ;
trustedScoringSignalsURL ?: string ;
}If this value is set to
null , any existing configuration for the specified configKey will be deleted.- مثال
جاوا اسکریپت
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 (legacy)
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, }, ], });
تایپ اسکریپت
const componentAuctionConfig = { // Seller URL should be https and the same as decisionLogicURL's origin seller: "https://testSeller.com", decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js", interestGroupBuyers: ["https://example-buyer.com"], auctionSignals: { auction_signals: "auction_signals" }, sellerSignals: { seller_signals: "seller_signals" }, perBuyerSignals: { // listed on interestGroupBuyers "https://example-buyer.com": { per_buyer_signals: "per_buyer_signals", }, }, }; const auctionSlot = googletag.defineSlot("/1234567/example", [160, 600])!; // To add configKey to the component auction: auctionSlot.setConfig({ componentAuction: [ { configKey: "https://testSeller.com", auctionConfig: componentAuctionConfig, }, ], }); // To remove configKey from the component auction: auctionSlot.setConfig({ componentAuction: [ { configKey: "https://testSeller.com", auctionConfig: null, }, ], });
- همچنین ببینید
configKey
configKey : stringThis value must be non-empty and should be unique. If two
ComponentAuctionConfig objects share the same configKey value, the last to be set will overwrite prior configurations. googletag.config.InterstitialConfig
| خواص | |
|---|---|
require Storage Access ? | Whether local storage consent is required to display this interstitial ad. |
triggers ? | The interstitial trigger configuration for this interstitial ad. |
خواص
Optional requireStorageAccess
requireStorageAccess ?: booleanGPT uses local storage to enforce a frequency cap for interstitial ads. However, users who have not provided local storage consent are still eligible to be served interstitial ads. Setting this property to
true opts out of the default behavior, and ensures interstial ads are only shown to users who have provided local storage consent.- مثال
جاوا اسکریپت
// Opt out of showing interstitials to users // without local storage consent. const interstitialSlot = googletag.defineOutOfPageSlot( "/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL, ); interstitialSlot.setConfig({ interstitial: { requireStorageAccess: true, // defaults to false }, });
JavaScript (legacy)
// Opt out of showing interstitials to users // without local storage consent. var interstitialSlot = googletag.defineOutOfPageSlot( "/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL, ); interstitialSlot.setConfig({ interstitial: { requireStorageAccess: true, // defaults to false }, });
تایپ اسکریپت
// Opt out of showing interstitials to users // without local storage consent. const interstitialSlot = googletag.defineOutOfPageSlot( "/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL, )!; interstitialSlot.setConfig({ interstitial: { requireStorageAccess: true, // defaults to false }, });
- همچنین ببینید
Optional triggers
triggers ?: Partial < Record < InterstitialTrigger , boolean > >Setting the value of an interstitial trigger to
true will enable it and false will disable it. This will override the default values configured in Google Ad Manager .- مثال
جاوا اسکریپت
// 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 (legacy)
// 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, }, }, });
تایپ اسکریپت
// Define a GPT managed web interstitial ad slot. const interstitialSlot = googletag.defineOutOfPageSlot( "/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL, )!; // Enable optional interstitial triggers. // Change this value to false to disable. const enableTriggers = true; interstitialSlot.setConfig({ interstitial: { triggers: { navBar: enableTriggers, unhideWindow: enableTriggers, }, }, });
- همچنین ببینید
googletag.config.LazyLoadConfig
| خواص | |
|---|---|
fetch Margin Percent ? | The minimum distance from the current viewport a slot must be before we request an ad, expressed as a percentage of viewport size. |
mobile Scaling ? | A multiplier applied to margins on mobile devices. |
render Margin Percent ? | The minimum distance from the current viewport a slot must be before we render an ad, expressed as a percentage of viewport size. |
- همچنین ببینید
خواص
Optional fetchMarginPercent
fetchMarginPercent ?: numberUsed in conjunction with renderMarginPercent , this setting allows for prefetching an ad, but waiting to render and download other subresources. As such, this value should always be greater than or equal to renderMarginPercent .
A value of
0 means "when the slot enters the viewport", 100 means "when the ad is 1 viewport away", and so on. Optional mobileScaling
mobileScaling ?: numberThis allows for different margins on mobile vs. desktop, where viewport sizes and scroll speeds may be different. For example, a value of 2.0 will multiply all margins by 2 on mobile devices, increasing the minimum distance a slot can be from the viewport before fetching and rendering.
Optional renderMarginPercent
renderMarginPercent ?: numberUsed in conjunction with fetchMarginPercent , this setting allows for prefetching an ad, but waiting to render and download other subresources. As such, this value should always be less than or equal to fetchMarginPercent .
A value of
0 means "when the slot enters the viewport", 100 means "when the ad is 1 viewport away", and so on. googletag.config.PageSettingsConfig
Allows setting multiple features with a single API call.
All properties listed below are examples and do not reflect actual features that utilize setConfig. For the set of features, see fields within the PageSettingsConfig type below.
مثالها:
- Only features specified in the googletag.setConfig call are modified.
// Configure feature alpha. googletag.setConfig({ alpha: {...} }); // Configure feature bravo. Feature alpha is unchanged. googletag.setConfig({ bravo: {...} });
- All settings for a given feature are updated with each call to googletag.setConfig .
// Configure feature charlie to echo = 1, foxtrot = true. googletag.setConfig({ charlie: { echo: 1, foxtrot: true, } }); // Update feature charlie to echo = 2. Since foxtrot was not specified, // the value is cleared. googletag.setConfig({ charlie: { echo: 2 } });
- All settings for a feature can be cleared by passing
null.// Configure features delta, golf, and hotel. googletag.setConfig({ delta: {...}, golf: {...}, hotel: {...}, }); // Feature delta and hotel are cleared, but feature golf remains set. googletag.setConfig({ delta: null, hotel: null, });
| خواص | |
|---|---|
ad Expansion ? | Settings to control ad expansion. |
adsense Attributes ? | Setting to configure AdSense attributes. |
ad Yield ? | منسوخ شده. |
category Exclusion ? | Setting to configure ad category exclusions. |
centering ? | Setting to control the horizontal centering of ads. |
collapse Div ? | Setting to control the collapsing behavior of ad slots. |
disable Initial Load ? | Setting to control when ads are requested. |
lazy Load ? | Settings to control the use of lazy loading in GPT. |
location ? | Setting to geo-target line items to geographic locations. |
pps ? | Settings to control publisher provided signals (PPS). |
privacy Treatments ? | Settings to control publisher privacy treatments. |
safe Frame ? | Settings to control the use of SafeFrame in GPT. |
single Request ? | Setting to enable or disable Single Request Architecture (SRA). |
targeting ? | Setting to control key-value targeting. |
thread Yield ? | Setting to control whether GPT should yield the JS thread when requesting and rendering creatives. |
video Ads ? | Settings to control video ads. |
خواص
Optional adExpansion
adExpansion ?: AdExpansionConfig Optional adsenseAttributes
adsenseAttributes ?: AdSenseAttributesConfigAdSense attributes configured via this setting will apply to all ad slots on the page. This setting may be called multiple times to define multiple attribute values, or overwrite existing values.
AdSense attribute changes only apply to ads requested after this method has been called. For that reason, it is recommended to call this method before any calls to googletag.display or PubAdsService.refresh .
- مثال
جاوا اسکریپت
// Set the document language and page URL. googletag.setConfig({ adsenseAttributes: { document_language: "en", page_url: "http://www.example.com" }, }); // Clear the page URL only. googletag.setConfig({ adsenseAttributes: { page_url: null } }); // Clear all AdSense attributes. googletag.setConfig({ adsenseAttributes: null });
JavaScript (legacy)
// Set the document language and page URL. googletag.setConfig({ adsenseAttributes: { document_language: "en", page_url: "http://www.example.com" }, }); // Clear the page URL only. googletag.setConfig({ adsenseAttributes: { page_url: null } }); // Clear all AdSense attributes. googletag.setConfig({ adsenseAttributes: null });
تایپ اسکریپت
// Set the document language and page URL. googletag.setConfig({ adsenseAttributes: { document_language: "en", page_url: "http://www.example.com" }, }); // Clear the page URL only. googletag.setConfig({ adsenseAttributes: { page_url: null } }); // Clear all AdSense attributes. googletag.setConfig({ adsenseAttributes: null });
Optional adYield
adYield ?: "DISABLED" | "ENABLED_ALL_SLOTS" Optional categoryExclusion
categoryExclusion ?: string []- مثال
جاوا اسکریپت
// Label = AirlineAd. googletag.setConfig({ categoryExclusion: ["AirlineAd"] }); // Clearing category exclusion setting. googletag.setConfig({ categoryExclusion: null });
JavaScript (legacy)
// Label = AirlineAd. googletag.setConfig({ categoryExclusion: ["AirlineAd"] }); // Clearing category exclusion setting. googletag.setConfig({ categoryExclusion: null });
تایپ اسکریپت
// Label = AirlineAd. googletag.setConfig({ categoryExclusion: ["AirlineAd"] }); // Clearing category exclusion setting. googletag.setConfig({ categoryExclusion: null });
- همچنین ببینید
Optional centering
centering ?: booleanHorizontal centering changes only apply to ads requested after this method has been called. For that reason, it is recommended to call this method before any calls to googletag.display or PubAdsService.refresh .
- مثال
جاوا اسکریپت
// Make ads centered. googletag.setConfig({ centering: true }); // Clear the centering setting. googletag.setConfig({ centering: null });
JavaScript (legacy)
// Make ads centered. googletag.setConfig({ centering: true }); // Clear the centering setting. googletag.setConfig({ centering: null });
تایپ اسکریپت
// Make ads centered. googletag.setConfig({ centering: true }); // Clear the centering setting. googletag.setConfig({ centering: null });
Optional collapseDiv
collapseDiv ?: CollapseDivBehaviorA collapsed ad slot does not take up any space on the page.
Supported values:
-
null(default): The slot will not be collapsed. -
DISABLED: The slot will not collapse, whether or not an ad is returned. -
BEFORE_FETCH: The slot will start out collapsed, and expand when an ad is returned. -
ON_NO_FILL: The slot will start out expanded, and collapse if no ad is returned.
- مثال
جاوا اسکریپت
// Collapse the div for this slot if no ad is returned. googletag.setConfig({ collapseDiv: "ON_NO_FILL" }); // Collapse the div for this slot by default, and expand only // if an ad is returned. googletag.setConfig({ collapseDiv: "BEFORE_FETCH" }); // Do not collapse the div for this slot. googletag.setConfig({ collapseDiv: "DISABLED" }); // Clear the collapse setting. googletag.setConfig({ collapseDiv: null });
JavaScript (legacy)
// Collapse the div for this slot if no ad is returned. googletag.setConfig({ collapseDiv: "ON_NO_FILL" }); // Collapse the div for this slot by default, and expand only // if an ad is returned. googletag.setConfig({ collapseDiv: "BEFORE_FETCH" }); // Do not collapse the div for this slot. googletag.setConfig({ collapseDiv: "DISABLED" }); // Clear the collapse setting. googletag.setConfig({ collapseDiv: null });
تایپ اسکریپت
// Collapse the div for this slot if no ad is returned. googletag.setConfig({ collapseDiv: "ON_NO_FILL" }); // Collapse the div for this slot by default, and expand only // if an ad is returned. googletag.setConfig({ collapseDiv: "BEFORE_FETCH" }); // Do not collapse the div for this slot. googletag.setConfig({ collapseDiv: "DISABLED" }); // Clear the collapse setting. googletag.setConfig({ collapseDiv: null });
- همچنین ببینید
Optional disableInitialLoad
disableInitialLoad ?: booleanBy default, the googletag.display method both registers ad slots and requests ads for them. However, there are times when it may be preferable to separate these actions, in order to more precisely control when ad content is loaded.
By enabling this setting, ads will not be requested for registered slots when the
display() method is called. Instead, a separate call to PubAdsService.refresh must be made to initiate an ad request.This method must be called before calling googletag.enableServices .
- مثال
جاوا اسکریپت
// Prevent requesting ads when `display()` is called. googletag.setConfig({ disableInitialLoad: true });
JavaScript (legacy)
// Prevent requesting ads when `display()` is called. googletag.setConfig({ disableInitialLoad: true });
تایپ اسکریپت
// Prevent requesting ads when `display()` is called. googletag.setConfig({ disableInitialLoad: true });
- همچنین ببینید
Optional lazyLoad
lazyLoad ?: LazyLoadConfigLazy loading is a technique to delay the requesting and rendering of ads until they approach the user's viewport. For a more detailed example, see the Lazy loading sample.
Note: If
singleRequest is enabled, lazy fetching only works when all slots are outside the fetch margin.Any lazy load settings which are not specified when calling
setConfig() will use a default value set by Google. These defaults may be tuned over time. To disable a particular setting, set the value to null .- مثال
جاوا اسکریپت
// Enable lazy loading. googletag.setConfig({ lazyLoad: { // Fetch slots within 5 viewports. fetchMarginPercent: 500, // Render slots within 2 viewports. renderMarginPercent: 200, // Double the above values on mobile. mobileScaling: 2.0, }, }); // Clear fetch margin only. googletag.setConfig({ lazyLoad: { fetchMarginPercent: null }, }); // Clear all lazy loading settings. googletag.setConfig({ lazyLoad: null });
JavaScript (legacy)
// Enable lazy loading. googletag.setConfig({ lazyLoad: { // Fetch slots within 5 viewports. fetchMarginPercent: 500, // Render slots within 2 viewports. renderMarginPercent: 200, // Double the above values on mobile. mobileScaling: 2.0, }, }); // Clear fetch margin only. googletag.setConfig({ lazyLoad: { fetchMarginPercent: null }, }); // Clear all lazy loading settings. googletag.setConfig({ lazyLoad: null });
تایپ اسکریپت
// Enable lazy loading. googletag.setConfig({ lazyLoad: { // Fetch slots within 5 viewports. fetchMarginPercent: 500, // Render slots within 2 viewports. renderMarginPercent: 200, // Double the above values on mobile. mobileScaling: 2.0, }, }); // Clear fetch margin only. googletag.setConfig({ lazyLoad: { fetchMarginPercent: null }, }); // Clear all lazy loading settings. googletag.setConfig({ lazyLoad: null });
Optional location
location ?: string- مثال
جاوا اسکریپت
// Geo-target line items to US postal code 10001. googletag.setConfig({ location: "10001,US" }); // Clear the location setting. googletag.setConfig({ location: null });
JavaScript (legacy)
// Geo-target line items to US postal code 10001. googletag.setConfig({ location: "10001,US" }); // Clear the location setting. googletag.setConfig({ location: null });
تایپ اسکریپت
// Geo-target line items to US postal code 10001. googletag.setConfig({ location: "10001,US" }); // Clear the location setting. googletag.setConfig({ location: null });
- همچنین ببینید
Optional pps
Optional privacyTreatments
privacyTreatments ?: PrivacyTreatmentsConfig Optional safeFrame
safeFrame ?: SafeFrameConfigValues configured via this setting will apply to all ad slots on the page. Individual ad slots may override these values via SlotSettingsConfig.safeFrame .
- مثال
جاوا اسکریپت
// Force SafeFrame for all ads on the page. googletag.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion. googletag.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting. googletag.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings. googletag.setConfig({ safeFrame: null });
JavaScript (legacy)
// Force SafeFrame for all ads on the page. googletag.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion. googletag.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting. googletag.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings. googletag.setConfig({ safeFrame: null });
تایپ اسکریپت
// Force SafeFrame for all ads on the page. googletag.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion. googletag.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting. googletag.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings. googletag.setConfig({ safeFrame: null });
Optional singleRequest
singleRequest ?: booleanWhen SRA is enabled, all ad slots defined prior to a googletag.display or PubAdsService.refresh call will be batched into a single ad request. This provides performance benefits, but is also necessary to ensure roadblocks and competetive exclusions are honored.
When SRA is disabled, each ad slot is requested individually. This is the default behavior of GPT.
This method must be called prior to calling googletag.enableServices .
- مثال
جاوا اسکریپت
// Enable Single Request Architecture. googletag.setConfig({ singleRequest: true });
JavaScript (legacy)
// Enable Single Request Architecture. googletag.setConfig({ singleRequest: true });
تایپ اسکریپت
// Enable Single Request Architecture. googletag.setConfig({ singleRequest: true });
Optional targeting
targeting ?: Record < string , string | string [] >Targeting configured via this setting will apply to all ad slots on the page. This setting may be called multiple times to define multiple targeting key-values, or overwrite existing values. Targeting keys are defined in your Google Ad Manager account.
- مثال
جاوا اسکریپت
// Setting a single targeting key-value. googletag.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key googletag.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. googletag.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. googletag.setConfig({ targeting: { interests: null } });
JavaScript (legacy)
// Setting a single targeting key-value. googletag.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key googletag.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. googletag.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. googletag.setConfig({ targeting: { interests: null } });
تایپ اسکریپت
// Setting a single targeting key-value. googletag.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key googletag.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. googletag.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. googletag.setConfig({ targeting: { interests: null } });
- همچنین ببینید
Optional threadYield
threadYield ?: "DISABLED" | "ENABLED_ALL_SLOTS"GPT will yield only for browsers that support the Scheduler.postTask or Scheduler.yield API.
Supported values:
-
null(default): GPT will yield the JS thread for slots outside of the viewport. -
ENABLED_ALL_SLOTS: GPT will yield the JS thread for all slots regardless of whether the slot is within the viewport. -
DISABLED: GPT will not yield the JS thread.
- مثال
جاوا اسکریپت
// Disable yielding. googletag.setConfig({ threadYield: "DISABLED" }); // Enable yielding for all slots. googletag.setConfig({ threadYield: "ENABLED_ALL_SLOTS" }); // Enable yielding only for slots outside of the viewport (default). googletag.setConfig({ threadYield: null });
JavaScript (legacy)
// Disable yielding. googletag.setConfig({ threadYield: "DISABLED" }); // Enable yielding for all slots. googletag.setConfig({ threadYield: "ENABLED_ALL_SLOTS" }); // Enable yielding only for slots outside of the viewport (default). googletag.setConfig({ threadYield: null });
تایپ اسکریپت
// Disable yielding. googletag.setConfig({ threadYield: "DISABLED" }); // Enable yielding for all slots. googletag.setConfig({ threadYield: "ENABLED_ALL_SLOTS" }); // Enable yielding only for slots outside of the viewport (default). googletag.setConfig({ threadYield: null });
- همچنین ببینید
Optional videoAds
videoAds ?: VideoAdsConfig- مثال
جاوا اسکریپت
// Enable video ads and set video content and content source IDs. googletag.setConfig({ videoAds: { enableVideoAds: true, videoContentId: "e1eGlRL7ju8", videoCmsId: "1234567", }, });
JavaScript (legacy)
// Enable video ads and set video content and content source IDs. googletag.setConfig({ videoAds: { enableVideoAds: true, videoContentId: "e1eGlRL7ju8", videoCmsId: "1234567", }, });
تایپ اسکریپت
// Enable video ads and set video content and content source IDs. googletag.setConfig({ videoAds: { enableVideoAds: true, videoContentId: "e1eGlRL7ju8", videoCmsId: "1234567", }, });
- همچنین ببینید
googletag.config.PrivacyTreatmentsConfig
| خواص | |
|---|---|
treatments | An array of publisher privacy treatments to enable. |
خواص
درمانها
treatments : "disablePersonalization" []- مثال
جاوا اسکریپت
// Disable personalization across the entire page. googletag.setConfig({ privacyTreatments: { treatments: ["disablePersonalization"] }, });
JavaScript (legacy)
// Disable personalization across the entire page. googletag.setConfig({ privacyTreatments: { treatments: ["disablePersonalization"] }, });
تایپ اسکریپت
// Disable personalization across the entire page. googletag.setConfig({ privacyTreatments: { treatments: ["disablePersonalization"] }, });
googletag.config.PublisherProvidedSignalsConfig
| خواص | |
|---|---|
taxonomies | An object containing Taxonomy mappings or null to clear the config. |
- مثال
جاوا اسکریپت
googletag.setConfig({ pps: { taxonomies: { IAB_AUDIENCE_1_1: { values: ["6", "626"] }, // '6' = 'Demographic | Age Range | 30-34' // '626' = 'Interest | Sports | Darts' IAB_CONTENT_2_2: { values: ["48", "127"] }, // '48' = 'Books and Literature | Fiction' // '127' = 'Careers | Job Search' }, }, });
JavaScript (legacy)
googletag.setConfig({ pps: { taxonomies: { IAB_AUDIENCE_1_1: { values: ["6", "626"] }, // '6' = 'Demographic | Age Range | 30-34' // '626' = 'Interest | Sports | Darts' IAB_CONTENT_2_2: { values: ["48", "127"] }, // '48' = 'Books and Literature | Fiction' // '127' = 'Careers | Job Search' }, }, });
تایپ اسکریپت
googletag.setConfig({ pps: { taxonomies: { IAB_AUDIENCE_1_1: { values: ["6", "626"] }, // '6' = 'Demographic | Age Range | 30-34' // '626' = 'Interest | Sports | Darts' IAB_CONTENT_2_2: { values: ["48", "127"] }, // '48' = 'Books and Literature | Fiction' // '127' = 'Careers | Job Search' }, }, });
خواص
طبقهبندیها
taxonomies : Partial < Record < Taxonomy , TaxonomyData > >googletag.config.SafeFrameConfig
| خواص | |
|---|---|
allow Overlay Expansion ? | Whether SafeFrame should allow ad content to expand by overlaying page content. |
allow Push Expansion ? | Whether SafeFrame should allow ad content to expand by pushing page content. |
force Safe Frame ? | Whether ad(s) should be forced to be rendered using a SafeFrame container. |
sandbox ? | Whether SafeFrame should use the HTML5 sandbox attribute to prevent top level navigation without user interaction. |
use Unique Domain ? | Deprecated. Whether SafeFrame should use randomized subdomains for Reservation creatives. |
- همچنین ببینید
خواص
Optional allowOverlayExpansion
allowOverlayExpansion ?: boolean Optional allowPushExpansion
allowPushExpansion ?: boolean Optional forceSafeFrame
forceSafeFrame ?: boolean Optional sandbox
sandbox ?: booleantrue (cannot be forced to false ). Note that the sandbox attribute disables plugins (eg Flash). Optional useUniqueDomain
useUniqueDomain ?: booleannull to clear the stored value.Note: this feature is enabled by default.
- همچنین ببینید
googletag.config.SlotSettingsConfig
Allows setting multiple features with a single API call for a single slot.
All properties listed below are examples and do not reflect actual features that utilize setConfig. For the set of features, see fields within the SlotSettingsConfig type below.
مثالها:
- Only features specified in the Slot.setConfig call are modified.
const slot = googletag.defineSlot("/1234567/example", [160, 600]); // Configure feature alpha. slot.setConfig({ alpha: {...} }); // Configure feature bravo. Feature alpha is unchanged. slot.setConfig({ bravo: {...} });
- All settings for a given feature are updated with each call to 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 } });
- All settings for a feature can be cleared by passing
null.// Configure features delta, golf, and hotel. slot.setConfig({ delta: {...}, golf: {...}, hotel: {...}, }); // Feature delta and hotel are cleared, but feature golf remains set. slot.setConfig({ delta: null, hotel: null, });
| خواص | |
|---|---|
ad Expansion ? | Settings to configure ad expansion. |
adsense Attributes ? | Setting to configure AdSense attributes. |
category Exclusion ? | Setting to configure ad category exclusions. |
click Url ? | Setting to configure the URL to which users will be redirected after clicking on the ad. |
collapse Div ? | Setting to configure the collapsing behavior of the ad slot. |
component Auction ? | An array of component auctions to be included in an on-device ad auction. |
interstitial ? | Settings that configure interstitial ad slot behavior. |
safe Frame ? | Settings to configure the use of SafeFrame in GPT. |
targeting ? | Setting to configure key-value targeting. |
خواص
Optional adExpansion
adExpansion ?: AdExpansionConfig- همچنین ببینید
Optional adsenseAttributes
adsenseAttributes ?: AdSenseAttributesConfigAdSense attributes configured via this setting will only apply to the ad slot. This setting may be called multiple times to define multiple attribute values, or overwrite existing values.
AdSense attribute changes only apply to ads requested after this method has been called. For that reason, it is recommended to call this method before any calls to googletag.display or PubAdsService.refresh .
- مثال
جاوا اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Set the AdSense ad format and channel IDs. slot.setConfig({ adsenseAttributes: { adsense_ad_format: "120x240_as", adsense_channel_ids: "271828183+314159265", }, }); // Clear the AdSense channel IDs only. slot.setConfig({ adsenseAttributes: { adsense_channel_ids: null } }); // Clear all AdSense attributes. slot.setConfig({ adsenseAttributes: null });
JavaScript (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Set the AdSense ad format and channel IDs. slot.setConfig({ adsenseAttributes: { adsense_ad_format: "120x240_as", adsense_channel_ids: "271828183+314159265", }, }); // Clear the AdSense channel IDs only. slot.setConfig({ adsenseAttributes: { adsense_channel_ids: null } }); // Clear all AdSense attributes. slot.setConfig({ adsenseAttributes: null });
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Set the AdSense ad format and channel IDs. slot.setConfig({ adsenseAttributes: { adsense_ad_format: "120x240_as", adsense_channel_ids: "271828183+314159265", }, }); // Clear the AdSense channel IDs only. slot.setConfig({ adsenseAttributes: { adsense_channel_ids: null } }); // Clear all AdSense attributes. slot.setConfig({ adsenseAttributes: null });
Optional categoryExclusion
categoryExclusion ?: string []- مثال
جاوا اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Label = AirlineAd slot.setConfig({ categoryExclusion: ["AirlineAd"], }); // Clearing category exclusion setting. slot.setConfig({ categoryExclusion: null });
JavaScript (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Label = AirlineAd slot.setConfig({ categoryExclusion: ["AirlineAd"], }); // Clearing category exclusion setting. slot.setConfig({ categoryExclusion: null });
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Label = AirlineAd slot.setConfig({ categoryExclusion: ["AirlineAd"], }); // Clearing category exclusion setting. slot.setConfig({ categoryExclusion: null });
- همچنین ببینید
Optional clickUrl
clickUrl ?: stringThe Google Ad Manager servers still record a click even if the click URL is replaced. Any landing page URL associated with the creative that is served is appended to the provided value. Setting this value more than once will overwrite any previously configured value. Passing in
null will clear the value.Note: This setting only applies to non-SRA requests .
- مثال
جاوا اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Sets the click URL to 'http://www.example.com?original_click_url='. slot.setConfig({ clickUrl: "http://www.example.com?original_click_url=", }); // Clears the click URL. slot.setConfig({ clickUrl: null, });
JavaScript (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Sets the click URL to 'http://www.example.com?original_click_url='. slot.setConfig({ clickUrl: "http://www.example.com?original_click_url=", }); // Clears the click URL. slot.setConfig({ clickUrl: null, });
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Sets the click URL to 'http://www.example.com?original_click_url='. slot.setConfig({ clickUrl: "http://www.example.com?original_click_url=", }); // Clears the click URL. slot.setConfig({ clickUrl: null, });
Optional collapseDiv
collapseDiv ?: CollapseDivBehaviorA collapsed ad slot does not take up any space on the page.
Supported values:
-
null(default): The slot will not be collapsed. -
DISABLED: The slot will not collapse, whether or not an ad is returned. -
BEFORE_FETCH: The slot will start out collapsed, and expand when an ad is returned. -
ON_NO_FILL: The slot will start out expanded, and collapse if no ad is returned.
- مثال
جاوا اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Collapse the div for this slot if no ad is returned. slot.setConfig({ collapseDiv: "ON_NO_FILL", }); // Collapse the div for this slot by default, and expand only // if an ad is returned. slot.setConfig({ collapseDiv: "BEFORE_FETCH", }); // Do not collapse the div for this slot. slot.setConfig({ collapseDiv: "DISABLED", }); // Clear the collapse setting. slot.setConfig({ collapseDiv: null, });
JavaScript (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Collapse the div for this slot if no ad is returned. slot.setConfig({ collapseDiv: "ON_NO_FILL", }); // Collapse the div for this slot by default, and expand only // if an ad is returned. slot.setConfig({ collapseDiv: "BEFORE_FETCH", }); // Do not collapse the div for this slot. slot.setConfig({ collapseDiv: "DISABLED", }); // Clear the collapse setting. slot.setConfig({ collapseDiv: null, });
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Collapse the div for this slot if no ad is returned. slot.setConfig({ collapseDiv: "ON_NO_FILL", }); // Collapse the div for this slot by default, and expand only // if an ad is returned. slot.setConfig({ collapseDiv: "BEFORE_FETCH", }); // Do not collapse the div for this slot. slot.setConfig({ collapseDiv: "DISABLED", }); // Clear the collapse setting. slot.setConfig({ collapseDiv: null, });
- همچنین ببینید
Optional componentAuction
componentAuction ?: ComponentAuctionConfig [] Optional interstitial
interstitial ?: InterstitialConfig- همچنین ببینید
Optional safeFrame
safeFrame ?: SafeFrameConfigValues configured via this setting will only apply to the ad slot, and override values set via PageSettingsConfig.safeFrame .
- مثال
جاوا اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Force SafeFrame for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion for the slot. slot.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings for the slot. slot.setConfig({ safeFrame: null });
JavaScript (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Force SafeFrame for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion for the slot. slot.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings for the slot. slot.setConfig({ safeFrame: null });
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Force SafeFrame for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: true }, }); // Configure SafeFrame to allow overlay expansion for the slot. slot.setConfig({ safeFrame: { allowOverlayExpansion: true }, }); // Clear forceSafeFrame setting for the slot. slot.setConfig({ safeFrame: { forceSafeFrame: null }, }); // Clear all SafeFrame settings for the slot. slot.setConfig({ safeFrame: null });
Optional targeting
targeting ?: Record < string , string | string [] >Targeting configured via this setting will only apply to the ad slot. This setting may be called multiple times to define multiple targeting key-values, or overwrite existing values. Targeting keys are defined in your Google Ad Manager account.
- مثال
جاوا اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Setting a single targeting key-value. slot.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key. slot.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. slot.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. slot.setConfig({ targeting: { interests: null } }); // Clear all targeting keys. slot.setConfig({ targeting: null });
JavaScript (legacy)
var slot = googletag .defineSlot("/1234567/sports", [160, 600], "div") .addService(googletag.pubads()); // Setting a single targeting key-value. slot.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key. slot.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. slot.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. slot.setConfig({ targeting: { interests: null } }); // Clear all targeting keys. slot.setConfig({ targeting: null });
تایپ اسکریپت
const slot = googletag .defineSlot("/1234567/sports", [160, 600], "div")! .addService(googletag.pubads()); // Setting a single targeting key-value. slot.setConfig({ targeting: { interests: "sports" } }); // Setting multiple values for a single targeting key. slot.setConfig({ targeting: { interests: ["sports", "music"] } }); // Setting multiple targeting key-values at once. slot.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } }); // Clearing a single targeting key. slot.setConfig({ targeting: { interests: null } }); // Clear all targeting keys. slot.setConfig({ targeting: null });
- همچنین ببینید
googletag.config.TaxonomyData
| خواص | |
|---|---|
values | A list of Taxonomy values. |
خواص
ارزشها
values : readonly string []googletag.config.VideoAdsConfig
| خواص | |
|---|---|
enable Video Ads | Whether videos ads will be present on the page. |
video Cms Id ? | The video content source ID. |
video Content Id ? | The video content ID. |
- همچنین ببینید
خواص
enableVideoAds
enableVideoAds : booleanWhen set to
true , this enables content exclusion constraints on display and video ads.If the video content is known, set videoContentId and videoCmsId to the values provided to the Google Ad Manager content ingestion service to utilize content exclusion for display ads.
Optional videoCmsId
videoCmsId ?: stringThis is a unique value assigned by the Google Ad Manager content ingestion service to identify the source of video content specified by videoContentId .
- همچنین ببینید
Optional videoContentId
videoContentId ?: stringThis is a unique value that identifies a particular video from the content source specified by videoCmsId . This value is assigned by the CMS that hosts your video content.
- همچنین ببینید
googletag.enums
| شمارشها | |
|---|---|
Out Of Page Format | Out-of-page formats supported by GPT. |
Traffic Source | Traffic sources supported by GPT. |
شمارشها
OutOfPageFormat
OutOfPageFormat- همچنین ببینید
TrafficSource
TrafficSource- همچنین ببینید
| Enumeration Members | |
|---|---|
ORGANIC | Direct URL entry, site search, or app download. |
PURCHASED | Traffic redirected from properties other than owned (acquired or otherwise incentivized activity). |
googletag.events
| رابطها | |
|---|---|
Event | Base Interface for all GPT events. |
Event Type Map | This is a pseudo-type that maps an event name to its corresponding event object type for Service.addEventListener and Service.removeEventListener . |
Game Manual Interstitial Slot Closed Event | This event is fired when a game manual interstitial slot has been closed by the user. |
Game Manual Interstitial Slot Ready Event | This event is fired when a game manual interstitial slot is ready to be shown to the user. |
Impression Viewable Event | This event is fired when an impression becomes viewable, according to the Active View criteria . |
Rewarded Slot Closed Event | This event is fired when a rewarded ad slot is closed by the user. |
Rewarded Slot Granted Event | This event is fired when a reward is granted for viewing a rewarded ad . |
Rewarded Slot Ready Event | This event is fired when a rewarded ad is ready to be displayed. |
Rewarded Slot Video Completed Event | This event is fired when a rewarded video ad has finished playing. |
Slot Onload Event | This event is fired when the creative's iframe fires its load event. |
Slot Render Ended Event | This event is fired when the creative code is injected into a slot. |
Slot Requested Event | This event is fired when an ad has been requested for a particular slot. |
Slot Response Received | This event is fired when an ad response has been received for a particular slot. |
Slot Visibility Changed Event | This event is fired whenever the on-screen percentage of an ad slot's area changes. |
googletag.events.Event
| خواص | |
|---|---|
service Name | Name of the service that triggered the event. |
slot | The slot that triggered the event. |
- همچنین ببینید
خواص
نام سرویس
serviceName : stringاسلات
slot : Slotgoogletag.events.EventTypeMap
| خواص | |
|---|---|
game Manual Interstitial Slot Closed | Alias for events.GameManualInterstitialSlotClosedEvent . |
game Manual Interstitial Slot Ready | Alias for events.GameManualInterstitialSlotReadyEvent . |
impression Viewable | Alias for events.ImpressionViewableEvent . |
rewarded Slot Closed | Alias for events.RewardedSlotClosedEvent . |
rewarded Slot Granted | Alias for events.RewardedSlotGrantedEvent . |
rewarded Slot Ready | Alias for events.RewardedSlotReadyEvent . |
rewarded Slot Video Completed | Alias for events.RewardedSlotVideoCompletedEvent . |
slot Onload | Alias for events.SlotOnloadEvent . |
slot Render Ended | Alias for events.SlotRenderEndedEvent . |
slot Requested | Alias for events.SlotRequestedEvent . |
slot Response Received | Alias for events.SlotResponseReceived . |
slot Visibility Changed | Alias for events.SlotVisibilityChangedEvent . |
خواص
gameManualInterstitialSlotClosed
gameManualInterstitialSlotClosed : GameManualInterstitialSlotClosedEventgameManualInterstitialSlotReady
gameManualInterstitialSlotReady : GameManualInterstitialSlotReadyEventimpressionViewable
impressionViewable : ImpressionViewableEventrewardedSlotClosed
rewardedSlotClosed : RewardedSlotClosedEventrewardedSlotGranted
rewardedSlotGranted : RewardedSlotGrantedEventrewardedSlotReady
rewardedSlotReady : RewardedSlotReadyEventrewardedSlotVideoCompleted
rewardedSlotVideoCompleted : RewardedSlotVideoCompletedEventslotOnload
slotOnload : SlotOnloadEventslotRenderEnded
slotRenderEnded : SlotRenderEndedEventslotRequested
slotRequested : SlotRequestedEventslotResponseReceived
slotResponseReceived : SlotResponseReceivedslotVisibilityChanged
slotVisibilityChanged : SlotVisibilityChangedEventgoogletag.events.GameManualInterstitialSlotClosedEvent
EventNote: Game manual interstitial is a limited-access format.
| خواص | |
|---|---|
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
- مثال
جاوا اسکریپت
// This listener is called when a game manual interstitial slot is closed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", (event) => { const slot = event.slot; console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed."); if (slot === targetSlot) { // Slot specific logic. } }); }
JavaScript (legacy)
// This listener is called when a game manual interstitial slot is closed. var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", function (event) { var slot = event.slot; console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed."); if (slot === targetSlot) { // Slot specific logic. } }); }
تایپ اسکریپت
// This listener is called when a game manual interstitial slot is closed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotClosed", (event) => { const slot = event.slot; console.log("Game manual interstital slot", slot.getSlotElementId(), "is closed."); if (slot === targetSlot) { // Slot specific logic. } }); }
- همچنین ببینید
googletag.events.GameManualInterstitialSlotReadyEvent
EventNote: Game manual interstitial is a limited-access format.
| خواص | |
|---|---|
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
| روشها | |
|---|---|
make Game Manual Interstitial Visible | Displays the game manual interstitial ad to the user. |
- مثال
جاوا اسکریپت
// This listener is called when a game manual interstitial slot is ready to // be displayed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotReady", (event) => { const slot = event.slot; console.log( "Game manual interstital slot", slot.getSlotElementId(), "is ready to be displayed.", ); // Replace with custom logic. const displayGmiAd = true; if (displayGmiAd) { event.makeGameManualInterstitialVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); }
JavaScript (legacy)
// This listener is called when a game manual interstitial slot is ready to // be displayed. var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotReady", function (event) { var slot = event.slot; console.log( "Game manual interstital slot", slot.getSlotElementId(), "is ready to be displayed.", ); // Replace with custom logic. var displayGmiAd = true; if (displayGmiAd) { event.makeGameManualInterstitialVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); }
تایپ اسکریپت
// This listener is called when a game manual interstitial slot is ready to // be displayed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.GAME_MANUAL_INTERSTITIAL, ); // Slot returns null if the page or device does not support game manual interstitial ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); googletag.pubads().addEventListener("gameManualInterstitialSlotReady", (event) => { const slot = event.slot; console.log( "Game manual interstital slot", slot.getSlotElementId(), "is ready to be displayed.", ); // Replace with custom logic. const displayGmiAd = true; if (displayGmiAd) { event.makeGameManualInterstitialVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); }
- همچنین ببینید
روشها
makeGameManualInterstitialVisible
makeGameManualInterstitialVisible ( ) : boolean| بازگشتها | |
|---|---|
boolean | |
googletag.events.ImpressionViewableEvent
Event| خواص | |
|---|---|
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
- مثال
جاوا اسکریپت
// 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 (legacy)
// 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. } });
تایپ اسکریپت
// This listener is called when an impression becomes viewable. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("impressionViewable", (event) => { const slot = event.slot; console.log("Impression for slot", slot.getSlotElementId(), "became viewable."); if (slot === targetSlot) { // Slot specific logic. } });
- همچنین ببینید
googletag.events.RewardedSlotClosedEvent
Event| خواص | |
|---|---|
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
- مثال
جاوا اسکریپت
const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the user closes a rewarded ad slot. googletag.pubads().addEventListener("rewardedSlotClosed", (event) => { const slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed."); if (slot === targetSlot) { // Slot specific logic. } }); }
JavaScript (legacy)
var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the user closes a rewarded ad slot. googletag.pubads().addEventListener("rewardedSlotClosed", function (event) { var slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed."); if (slot === targetSlot) { // Slot specific logic. } }); }
تایپ اسکریپت
const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the user closes a rewarded ad slot. googletag.pubads().addEventListener("rewardedSlotClosed", (event) => { const slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "has been closed."); if (slot === targetSlot) { // Slot specific logic. } }); }
- همچنین ببینید
googletag.events.RewardedSlotGrantedEvent
Event| خواص | |
|---|---|
payload | An object containing information about the reward that was granted. |
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
- مثال
جاوا اسکریپت
const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotGranted", (event) => { const slot = event.slot; console.group("Reward granted for slot", slot.getSlotElementId(), "."); // Log details of the reward. console.log("Reward type:", event.payload?.type); console.log("Reward amount:", event.payload?.amount); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } }); }
JavaScript (legacy)
var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotGranted", function (event) { var _a, _b; var slot = event.slot; console.group("Reward granted for slot", slot.getSlotElementId(), "."); // Log details of the reward. console.log("Reward type:", (_a = event.payload) === null || _a === void 0 ? void 0 : _a.type); console.log( "Reward amount:", (_b = event.payload) === null || _b === void 0 ? void 0 : _b.amount, ); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } }); }
تایپ اسکریپت
const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotGranted", (event) => { const slot = event.slot; console.group("Reward granted for slot", slot.getSlotElementId(), "."); // Log details of the reward. console.log("Reward type:", event.payload?.type); console.log("Reward amount:", event.payload?.amount); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } }); }
- همچنین ببینید
خواص
بار مفید
payload : RewardedPayloadgoogletag.events.RewardedSlotReadyEvent
Event| خواص | |
|---|---|
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
| روشها | |
|---|---|
make Rewarded Visible | Displays the rewarded ad. |
- مثال
جاوا اسکریپت
// This listener is called when a rewarded ad slot becomes ready to be // displayed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotReady", (event) => { const slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed."); // Replace with custom logic. const userHasConsented = true; if (userHasConsented) { event.makeRewardedVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); }
JavaScript (legacy)
// This listener is called when a rewarded ad slot becomes ready to be // displayed. var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotReady", function (event) { var slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed."); // Replace with custom logic. var userHasConsented = true; if (userHasConsented) { event.makeRewardedVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); }
تایپ اسکریپت
// This listener is called when a rewarded ad slot becomes ready to be // displayed. const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called whenever a reward is granted for a // rewarded ad. googletag.pubads().addEventListener("rewardedSlotReady", (event) => { const slot = event.slot; console.log("Rewarded ad slot", slot.getSlotElementId(), "is ready to be displayed."); // Replace with custom logic. const userHasConsented = true; if (userHasConsented) { event.makeRewardedVisible(); } if (slot === targetSlot) { // Slot specific logic. } }); }
- همچنین ببینید
روشها
makeRewardedVisible
makeRewardedVisible ( ) : boolean| بازگشتها | |
|---|---|
boolean | Whether the rewarded ad was successfully displayed. |
googletag.events.RewardedSlotVideoCompletedEvent
Event| خواص | |
|---|---|
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
- مثال
جاوا اسکریپت
const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the video in a rewarded ad slot has // finished playing. googletag.pubads().addEventListener("rewardedSlotVideoCompleted", (event) => { const slot = event.slot; console.log("Video in rewarded ad slot", slot.getSlotElementId(), "has finished playing."); if (slot === targetSlot) { // Slot specific logic. } }); }
JavaScript (legacy)
var targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the video in a rewarded ad slot has // finished playing. googletag.pubads().addEventListener("rewardedSlotVideoCompleted", function (event) { var slot = event.slot; console.log("Video in rewarded ad slot", slot.getSlotElementId(), "has finished playing."); if (slot === targetSlot) { // Slot specific logic. } }); }
تایپ اسکریپت
const targetSlot = googletag.defineOutOfPageSlot( "/1234567/example", googletag.enums.OutOfPageFormat.REWARDED, ); // Slot returns null if the page or device does not support rewarded ads. if (targetSlot) { targetSlot.addService(googletag.pubads()); // This listener is called when the video in a rewarded ad slot has // finished playing. googletag.pubads().addEventListener("rewardedSlotVideoCompleted", (event) => { const slot = event.slot; console.log("Video in rewarded ad slot", slot.getSlotElementId(), "has finished playing."); if (slot === targetSlot) { // Slot specific logic. } }); }
- همچنین ببینید
googletag.events.SlotOnloadEvent
EventSlotOnloadEvent will be fired. | خواص | |
|---|---|
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
- مثال
جاوا اسکریپت
// 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 (legacy)
// 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. } });
تایپ اسکریپت
// This listener is called when a creative iframe load event fires. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotOnload", (event) => { const slot = event.slot; console.log("Creative iframe for slot", slot.getSlotElementId(), "has loaded."); if (slot === targetSlot) { // Slot specific logic. } });
- همچنین ببینید
googletag.events.SlotRenderEndedEvent
Event| خواص | |
|---|---|
advertiser Id | Advertiser ID of the rendered ad. |
campaign Id | Campaign ID of the rendered ad. |
company Ids | IDs of the companies that bid on the rendered backfill ad. |
creative Id | Creative ID of the rendered reservation ad. |
creative Template Id | Creative template ID of the rendered reservation ad. |
is Backfill | Whether an ad was a backfill ad. |
is Empty | Whether an ad was returned for the slot. |
label Ids | منسوخ شده. |
line Item Id | Line item ID of the rendered reservation ad. |
response Identifier | The response identifier is a unique identifier for the ad response. |
service Name | Name of the service that triggered the event. Inherited from |
size | Indicates the pixel size of the rendered creative. |
slot | The slot that triggered the event. Inherited from |
slot Content Changed | Whether the slot content was changed with the rendered ad. |
source Agnostic Creative Id | Creative ID of the rendered reservation or backfill ad. |
source Agnostic Line Item Id | Line item ID of the rendered reservation or backfill ad. |
yield Group Ids | IDs of the yield groups for the rendered backfill ad. |
- مثال
جاوا اسکریپت
// This listener is called when a slot has finished rendering. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotRenderEnded", (event) => { const slot = event.slot; console.group("Slot", slot.getSlotElementId(), "finished rendering."); // Log details of the rendered ad. console.log("Advertiser ID:", event.advertiserId); console.log("Campaign ID:", event.campaignId); console.log("Company IDs:", event.companyIds); console.log("Creative ID:", event.creativeId); console.log("Creative Template ID:", event.creativeTemplateId); console.log("Is backfill?:", event.isBackfill); console.log("Is empty?:", event.isEmpty); console.log("Line Item ID:", event.lineItemId); console.log("Size:", event.size); console.log("Slot content changed?", event.slotContentChanged); console.log("Source Agnostic Creative ID:", event.sourceAgnosticCreativeId); console.log("Source Agnostic Line Item ID:", event.sourceAgnosticLineItemId); console.log("Yield Group IDs:", event.yieldGroupIds); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } });
JavaScript (legacy)
// This listener is called when a slot has finished rendering. var targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotRenderEnded", function (event) { var slot = event.slot; console.group("Slot", slot.getSlotElementId(), "finished rendering."); // Log details of the rendered ad. console.log("Advertiser ID:", event.advertiserId); console.log("Campaign ID:", event.campaignId); console.log("Company IDs:", event.companyIds); console.log("Creative ID:", event.creativeId); console.log("Creative Template ID:", event.creativeTemplateId); console.log("Is backfill?:", event.isBackfill); console.log("Is empty?:", event.isEmpty); console.log("Line Item ID:", event.lineItemId); console.log("Size:", event.size); console.log("Slot content changed?", event.slotContentChanged); console.log("Source Agnostic Creative ID:", event.sourceAgnosticCreativeId); console.log("Source Agnostic Line Item ID:", event.sourceAgnosticLineItemId); console.log("Yield Group IDs:", event.yieldGroupIds); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } });
تایپ اسکریپت
// This listener is called when a slot has finished rendering. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotRenderEnded", (event) => { const slot = event.slot; console.group("Slot", slot.getSlotElementId(), "finished rendering."); // Log details of the rendered ad. console.log("Advertiser ID:", event.advertiserId); console.log("Campaign ID:", event.campaignId); console.log("Company IDs:", event.companyIds); console.log("Creative ID:", event.creativeId); console.log("Creative Template ID:", event.creativeTemplateId); console.log("Is backfill?:", event.isBackfill); console.log("Is empty?:", event.isEmpty); console.log("Line Item ID:", event.lineItemId); console.log("Size:", event.size); console.log("Slot content changed?", event.slotContentChanged); console.log("Source Agnostic Creative ID:", event.sourceAgnosticCreativeId); console.log("Source Agnostic Line Item ID:", event.sourceAgnosticLineItemId); console.log("Yield Group IDs:", event.yieldGroupIds); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } });
- همچنین ببینید
خواص
advertiserId
advertiserId : numbernull for empty slots, backfill ads, and creatives rendered by services other than PubAdsService . شناسه کمپین
campaignId : numbernull for empty slots, backfill ads, and creatives rendered by services other than PubAdsService . companyIds
companyIds : number []null for empty slots, reservation ads, and creatives rendered by services other than PubAdsService . creativeId
creativeId : numbernull for empty slots, backfill ads, and creatives rendered by services other than PubAdsService . creativeTemplateId
creativeTemplateId : numbernull for empty slots, backfill ads, and creatives rendered by services other than PubAdsService . isBackfill
isBackfill : booleantrue if the ad was a backfill ad, false otherwise. خالی است
isEmpty : booleantrue if no ad was returned, false otherwise. labelIds
labelIds : number []lineItemId
lineItemId : numbernull for empty slots, backfill ads, and creatives rendered by services other than PubAdsService . responseIdentifier
responseIdentifier : stringاندازه
size : string | number [][728, 90] . Value is null for empty ad slots. slotContentChanged
slotContentChanged : booleantrue if the content was changed, false otherwise. sourceAgnosticCreativeId
sourceAgnosticCreativeId : numbernull if the ad is not a reservation or line item backfill, or the creative is rendered by services other than PubAdsService . sourceAgnosticLineItemId
sourceAgnosticLineItemId : numbernull if the ad is not a reservation or line item backfill, or the creative is rendered by services other than PubAdsService . yieldGroupIds
yieldGroupIds : number []null for empty slots, reservation ads, and creatives rendered by services other than PubAdsService . googletag.events.SlotRequestedEvent
Event| خواص | |
|---|---|
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
- مثال
جاوا اسکریپت
// 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 (legacy)
// 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. } });
تایپ اسکریپت
// This listener is called when the specified service issues an ad // request for a slot. Each slot will fire this event, even though they // may be batched together in a single request if single request // architecture (SRA) is enabled. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotRequested", (event) => { const slot = event.slot; console.log("Slot", slot.getSlotElementId(), "has been requested."); if (slot === targetSlot) { // Slot specific logic. } });
- همچنین ببینید
googletag.events.SlotResponseReceived
Event| خواص | |
|---|---|
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
- مثال
جاوا اسکریپت
// 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 (legacy)
// 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. } });
تایپ اسکریپت
// This listener is called when an ad response has been received // for a slot. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotResponseReceived", (event) => { const slot = event.slot; console.log("Ad response for slot", slot.getSlotElementId(), "received."); if (slot === targetSlot) { // Slot specific logic. } });
- همچنین ببینید
googletag.events.SlotVisibilityChangedEvent
Event| خواص | |
|---|---|
in View Percentage | The percentage of the ad's area that is visible. |
service Name | Name of the service that triggered the event. Inherited from |
slot | The slot that triggered the event. Inherited from |
- مثال
جاوا اسکریپت
// 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 (legacy)
// 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. } });
تایپ اسکریپت
// This listener is called whenever the on-screen percentage of an // ad slot's area changes. const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]); googletag.pubads().addEventListener("slotVisibilityChanged", (event) => { const slot = event.slot; console.group("Visibility of slot", slot.getSlotElementId(), "changed."); // Log details of the event. console.log("Visible area:", `${event.inViewPercentage}%`); console.groupEnd(); if (slot === targetSlot) { // Slot specific logic. } });
- همچنین ببینید
خواص
inViewPercentage
inViewPercentage : numbergoogletag.secureSignals
| رابطها | |
|---|---|
Bidder Signal Provider | Returns a secure signal for a specific bidder. |
Publisher Signal Provider | Returns a secure signal for a specific publisher. |
Secure Signal Providers Array | An interface for managing secure signals. |
| نامهای مستعار نوع | |
|---|---|
Secure Signal Provider | Interface for returning a secure signal for a specific bidder or provider. |
نامهای مستعار نوع
SecureSignalProvider
SecureSignalProvider : BidderSignalProvider | PublisherSignalProviderid or networkCode must be provided, but not both. googletag.secureSignals.BidderSignalProvider
A bidder secure signal provider consists of 2 parts:
- A collector function, which returns a
Promisethat resolves to a secure signal. - An
idwhich identifies the bidder associated with the signal.
| خواص | |
|---|---|
collector Function | A function which returns a Promise that resolves to a secure signal. |
id | A unique identifier for the collector associated with this secure signal, as registered in Google Ad Manager. |
- مثال
جاوا اسکریپت
// id is provided googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, });
JavaScript (legacy)
// id is provided googletag.secureSignalProviders.push({ id: "collector123", collectorFunction: function () { // ...custom signal generation logic... return Promise.resolve("signal"); }, });
تایپ اسکریپت
// id is provided googletag.secureSignalProviders!.push({ id: "collector123", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, });
- همچنین ببینید
خواص
collectorFunction
collectorFunction : ( ( ) => Promise < string > )Promise that resolves to a secure signal. شناسه
id : stringgoogletag.secureSignals.PublisherSignalProvider
A publisher signal provider consists of 2 parts:
- A collector function, which returns a
Promisethat resolves to a secure signal. - A
networkCodewhich identifies the publisher associated with the signal.
| خواص | |
|---|---|
collector Function | A function which returns a Promise that resolves to a secure signal. |
network Code | The network code (as seen in the ad unit path) for the publisher associated with this secure signal. |
- مثال
جاوا اسکریپت
// networkCode is provided googletag.secureSignalProviders.push({ networkCode: "123456", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, });
JavaScript (legacy)
// networkCode is provided googletag.secureSignalProviders.push({ networkCode: "123456", collectorFunction: function () { // ...custom signal generation logic... return Promise.resolve("signal"); }, });
تایپ اسکریپت
// networkCode is provided googletag.secureSignalProviders!.push({ networkCode: "123456", collectorFunction: () => { // ...custom signal generation logic... return Promise.resolve("signal"); }, });
- همچنین ببینید
خواص
collectorFunction
collectorFunction : ( ( ) => Promise < string > )Promise that resolves to a secure signal. networkCode
networkCode : stringgoogletag.secureSignals.SecureSignalProvidersArray
| روشها | |
|---|---|
clear All Cache | Clears all signals for all collectors from cache. |
push | Adds a new secureSignals.SecureSignalProvider to the signal provider array and begins the signal generation process. |
روشها
clearAllCache
clearAllCache ( ) : voidCalling this method may reduce the likelihood of signals being included in ad requests for the current and potentially later page views. Due to this, it should only be called when meaningful state changes occur, such as events that indicate a new user (log in, log out, sign up, etc.).
فشار دادن
push ( provider : SecureSignalProvider ) : void| پارامترها | |
|---|---|
provider : SecureSignalProvider | The secureSignals.SecureSignalProvider object to be added to the array. |