مرجع GPT

این مرجع از نماد 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 تعداد نامحدودی از مقادیر از نوع مشخص شده را می پذیرند.

googletag

فضای نام جهانی که تگ Google Publisher برای API خود استفاده می کند.
فضاهای نام
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
پرچمی که نشان می دهد GPT API بارگیری شده و آماده فراخوانی است.
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
کنسول Google Publisher را غیرفعال می کند.
display
به خدمات اسلات دستور می دهد تا اسلات را ارائه دهند.
enable Services
همه سرویس‌های GPT را که برای اسلات تبلیغاتی در صفحه تعریف شده‌اند، فعال می‌کند.
get Config
گزینه های پیکربندی کلی را برای صفحه تنظیم شده توسط setConfig دریافت می کند.
get Version
نسخه فعلی GPT را برمی‌گرداند.
open Console
Google Publisher Console را باز می کند.
pubads
مرجعی را به PubAdsService برمی گرداند.
set Ad Iframe Title
عنوان را برای همه iframe های کانتینر آگهی ایجاد شده توسط PubAdsService از این مرحله به بعد تنظیم می کند.
set Config
گزینه های پیکربندی کلی صفحه را تنظیم می کند.
size Mapping
یک SizeMappingBuilder جدید ایجاد می کند.

نام مستعار را تایپ کنید


جنرال سایز

GeneralSize : SingleSize | MultiSize
یک پیکربندی اندازه معتبر برای یک اسلات، که می تواند یک یا چند اندازه باشد.

چند سایز

MultiSize : SingleSize []
لیستی از اندازه های معتبر تکی.

NamedSize

NamedSize : "fluid" | [ "fluid" ]
اندازه های نامگذاری شده ای که یک اسلات می تواند داشته باشد. در اکثر موارد اندازه یک مستطیل با اندازه ثابت است، اما مواردی وجود دارد که به انواع دیگر مشخصات اندازه نیاز داریم. فقط موارد زیر اندازه های نامگذاری شده معتبر هستند:
  • مایع : ظرف تبلیغات 100% عرض div والد را می گیرد و سپس ارتفاع آن را تغییر می دهد تا متناسب با محتوای خلاقانه باشد. مشابه رفتار عناصر بلوک معمولی در یک صفحه. برای تبلیغات بومی استفاده می شود ( مقاله مرتبط را ببینید). توجه داشته باشید که هم fluid و هم ['fluid'] اشکال قابل قبولی برای اعلام اندازه شکاف به عنوان سیال هستند.

تک سایز

SingleSize : SingleSizeArray | NamedSize
یک اندازه معتبر برای یک اسلات.

SingleSizeArray

SingleSizeArray : [ number , number ]
آرایه ای از دو عدد که نشان دهنده [عرض، ارتفاع] است.

SizeMapping

SizeMapping : [ SingleSizeArray , GeneralSize ]
نگاشت اندازه نمایش به اندازه تبلیغات. برای تبلیغات ریسپانسیو استفاده می شود.

SizeMappingArray

SizeMappingArray : SizeMapping []
لیستی از نگاشت اندازه

متغیرها


Const apiReady

apiReady : boolean | undefined
پرچمی که نشان می دهد GPT API بارگیری شده و آماده فراخوانی است. تا زمانی که API آماده شود، این ویژگی به سادگی undefined است.

توجه داشته باشید که روش توصیه شده برای مدیریت async این است که از googletag.cmd برای قرار دادن تماس‌ها در صف برای زمانی که GPT آماده است استفاده کنید. این تماس‌های برگشتی نیازی به بررسی googletag.apiReady ندارند، زیرا اجرای آنها پس از راه‌اندازی API تضمین می‌شود.

cmd Const

cmd : ( ( this : typeof globalThis ) => void ) [] | CommandArray
ارجاع به صف فرمان جهانی برای اجرای ناهمزمان تماس های مربوط به GPT.

متغیر googletag.cmd به یک آرایه خالی جاوا اسکریپت توسط نحو تگ GPT در صفحه مقداردهی اولیه می شود و cmd.push روش استاندارد Array.push است که یک عنصر را به انتهای آرایه اضافه می کند. هنگامی که جاوا اسکریپت GPT بارگذاری می شود، از طریق آرایه نگاه می کند و همه توابع را به ترتیب اجرا می کند. سپس اسکریپت cmd با یک شی CommandArray جایگزین می کند که متد فشار آن برای اجرای آرگومان تابع ارسال شده به آن تعریف شده است. این مکانیسم به 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());
});

TypeScript

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

Const pubadsReady

pubadsReady : boolean | undefined
پرچمی که نشان می دهد PubAdsService فعال، بارگیری شده و کاملاً عملیاتی است. این ویژگی تا زمانی که enableServices فراخوانی نشود و PubAdsService بارگیری و مقداردهی اولیه شود، به سادگی undefined است.

SecuritySignalProviders

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");
  },
});

TypeScript

window.googletag = window.googletag || { cmd: [] };
googletag.secureSignalProviders = googletag.secureSignalProviders || [];
googletag.secureSignalProviders.push({
  id: "collector123",
  collectorFunction: () => {
    return Promise.resolve("signal");
  },
});
همچنین ببینید

توابع


companionAds

companionAds ( ) : CompanionAdsService
مرجعی را به CompanionAdsService برمی گرداند.
برمی گرداند
CompanionAdsService سرویس تبلیغات همراه.

تعریف OutOfPageSlot

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);

TypeScript

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

// Define a GPT managed web interstitial ad slot.
googletag.defineOutOfPageSlot("/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL);
همچنین ببینید
پارامترها
adUnitPath : string مسیر کامل واحد تبلیغات با کد شبکه و کد واحد تبلیغات.
Optional div : string | OutOfPageFormat شناسه div که حاوی این واحد تبلیغات یا OutOfPageFormat است.
برمی گرداند
Slot | null اسلات تازه ایجاد شده، یا اگر شکافی ایجاد نشود، null .

تعریف اسلات

defineSlot ( adUnitPath : string , size : GeneralSize , div ?: string ) : Slot | null
یک جایگاه تبلیغاتی با یک مسیر و اندازه واحد تبلیغاتی معین می سازد و آن را با شناسه یک عنصر div در صفحه ای که حاوی آگهی است مرتبط می کند.
مثال

جاوا اسکریپت

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

جاوا اسکریپت (میراث)

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

TypeScript

googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
همچنین ببینید
پارامترها
adUnitPath : string مسیر کامل واحد تبلیغات با کد شبکه و کد واحد.
size : GeneralSize عرض و ارتفاع شکاف اضافه شده. این اندازه ای است که در درخواست تبلیغ استفاده می شود اگر نگاشت اندازه واکنشگرا ارائه نشده باشد یا اندازه نمای درگاه کوچکتر از کوچکترین اندازه ارائه شده در نقشه باشد.
Optional div : string شناسه div که حاوی این واحد تبلیغاتی است.
برمی گرداند
Slot | null اسلات تازه ایجاد شده، یا اگر شکافی ایجاد نشود، null .

اسلات ها را نابود می کند

destroySlots ( slots ?: Slot [] ) : boolean
اسلات های داده شده را از بین می برد و تمام اشیاء مرتبط و مراجع آن اسلات ها را از GPT حذف می کند. این API از اسلات های پس انداز و اسلات های همراه پشتیبانی نمی کند.

فراخوانی این 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();

TypeScript

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

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

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

// This call to destroy all slots.
googletag.destroySlots();
پارامترها
Optional slots : Slot [] آرایه ای از اسلات برای از بین بردن. آرایه اختیاری است. تمام اسلات ها در صورت نامشخص بودن از بین می روند.
برمی گرداند
boolean true اگر شکاف ها از بین رفته باشند، در غیر این صورت false .

disablePublisherConsole

disablePublisherConsole ( ) : void
کنسول Google Publisher را غیرفعال می کند.
همچنین ببینید

نمایش داده شود

display ( divOrSlot : string | Element | Slot ) : void
به خدمات اسلات دستور می دهد تا اسلات را ارائه دهند. هر جایگاه تبلیغاتی باید فقط یک بار در هر صفحه نمایش داده شود. همه اسلات ها قبل از نمایش باید تعریف شده و دارای یک سرویس مرتبط با آنها باشند. تماس نمایشی نباید تا زمانی که عنصر در DOM وجود داشته باشد اتفاق بیفتد. راه معمول برای دستیابی به آن، قرار دادن آن در یک بلوک اسکریپت در عنصر div است که در فراخوانی متد نامگذاری شده است.

اگر از معماری تک درخواست (SRA) استفاده شود، تمام اسلات های تبلیغاتی واکشی نشده در زمانی که این روش فراخوانی می شود، به یکباره واکشی می شوند. برای اینکه یک شکاف آگهی نمایش داده نشود، کل div باید حذف شود.
همچنین ببینید
پارامترها
divOrSlot : string | Element | Slot شناسه عنصر div حاوی شکاف آگهی یا عنصر div یا شی شکاف. اگر یک عنصر div ارائه شده باشد، باید یک ویژگی 'id' داشته باشد که با شناسه ارسال شده به defineSlot مطابقت داشته باشد.

enableServices

enableServices ( ) : void
همه سرویس‌های GPT را که برای اسلات تبلیغاتی در صفحه تعریف شده‌اند، فعال می‌کند.

getConfig

getConfig ( keys : string | string [] ) : Pick < PageSettingsConfig , "adsenseAttributes" | "disableInitialLoad" | "targeting" >
گزینه های پیکربندی کلی را برای صفحه تنظیم شده توسط setConfig دریافت می کند.

همه ویژگی های setConfig() توسط این روش پشتیبانی نمی شوند. ویژگی های پشتیبانی شده عبارتند از:
مثال

جاوا اسکریپت

// 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"]);

TypeScript

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

// Get the value of the `adsenseAttributes` and `disableInitialLoad` settings.
const config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);
پارامترها
keys : string | string [] کلیدهای تنظیمات پیکربندی را دریافت کنید.
برمی گرداند
Pick < PageSettingsConfig , "adsenseAttributes" | "disableInitialLoad" | "targeting" > گزینه های پیکربندی برای اسلات.

getVersion

getVersion ( ) : string
نسخه فعلی GPT را برمی‌گرداند.
همچنین ببینید
برمی گرداند
string رشته نسخه GPT در حال اجرا.

openConsole

openConsole ( div ?: string ) : void
Google Publisher Console را باز می کند.
مثال

جاوا اسکریپت

// 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();

TypeScript

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

// Calling without div ID.
googletag.openConsole();
همچنین ببینید
پارامترها
Optional div : string شناسه div اسلات آگهی. این مقدار اختیاری است. هنگامی که ارائه شد، کنسول ناشر تلاش می کند تا با جزئیات فضای تبلیغاتی مشخص شده باز شود.

pubads

pubads ( ) : PubAdsService
مرجعی را به PubAdsService برمی گرداند.
برمی گرداند
PubAdsService سرویس تبلیغات ناشر.

setAdIframeTitle

setAdIframeTitle ( title : string ) : void
عنوان را برای همه iframe های کانتینر آگهی ایجاد شده توسط PubAdsService از این مرحله به بعد تنظیم می کند.
مثال

جاوا اسکریپت

googletag.setAdIframeTitle("title");

جاوا اسکریپت (میراث)

googletag.setAdIframeTitle("title");

TypeScript

googletag.setAdIframeTitle("title");
پارامترها
title : string عنوان جدید برای همه iframe های کانتینر تبلیغاتی.

setConfig

setConfig ( config : PageSettingsConfig ) : void
گزینه های پیکربندی کلی صفحه را تنظیم می کند.
پارامترها
config : PageSettingsConfig

اندازه نقشه برداری

sizeMapping ( ) : SizeMappingBuilder
یک SizeMappingBuilder جدید ایجاد می کند.
همچنین ببینید
برمی گرداند
SizeMappingBuilder یک سازنده جدید

googletag.CommandArray

آرایه فرمان دنباله ای از توابع را می پذیرد و آنها را به ترتیب فراخوانی می کند. در نظر گرفته شده است که جایگزین یک آرایه استاندارد شود که برای قرار دادن توابع در صف قرار دادن به محض بارگذاری GPT استفاده می شود.
روش ها
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());
});

TypeScript

googletag.cmd.push(() => {
  googletag.defineSlot("/1234567/sports", [160, 600])!.addService(googletag.pubads());
});
پارامترها
Rest ... f : ( ( this : typeof globalThis ) => void ) [] یک تابع جاوا اسکریپت که باید اجرا شود. اتصال زمان اجرا همیشه globalThis خواهد بود. در نظر بگیرید که یک تابع فلش را برای حفظ this مقدار از بافت واژگانی محصور در نظر بگیرید.
برمی گرداند
number تعداد دستورات پردازش شده تاکنون این با مقدار برگشتی Array.push (طول فعلی آرایه) سازگار است.

googletag.CompanionAdsService

Service را گسترش می دهد
سرویس تبلیغات همراه. این سرویس توسط تبلیغات ویدیویی برای نمایش تبلیغات همراه استفاده می شود.
روش ها
add Event Listener
شنونده‌ای را ثبت می‌کند که به شما امکان می‌دهد یک تابع جاوا اسکریپت را هنگامی که یک رویداد GPT خاص در صفحه اتفاق می‌افتد تنظیم و فراخوانی کنید.
get Slots
لیست اسلات های مرتبط با این سرویس را دریافت کنید.
remove Event Listener
شنونده قبلا ثبت نام شده را حذف می کند.
set Refresh Unfilled Slots
تعیین می کند که آیا اسلات های همراهی که پر نشده اند به طور خودکار پر شوند یا خیر.
همچنین ببینید

روش ها


setRefreshUnfilledSlots

setRefreshUnfilledSlots ( value : boolean ) : void
تعیین می کند که آیا اسلات های همراهی که پر نشده اند به طور خودکار پر شوند یا خیر.

این روش را می توان چندین بار در طول عمر صفحه فراخوانی کرد تا Backfill را روشن و خاموش کند. فقط اسلات هایی که در PubAdsService نیز ثبت شده باشند پر می شوند. به دلیل محدودیت‌های خط‌مشی، این روش برای پر کردن جایگاه‌های خالی همراه هنگام ارائه یک ویدیوی Ad Exchange طراحی نشده است.
مثال

جاوا اسکریپت

googletag.companionAds().setRefreshUnfilledSlots(true);

جاوا اسکریپت (میراث)

googletag.companionAds().setRefreshUnfilledSlots(true);

TypeScript

googletag.companionAds().setRefreshUnfilledSlots(true);
پارامترها
value : boolean true برای پر کردن خودکار اسلات های پر نشده، false تا بدون تغییر باقی بماند.

googletag.PrivacySettingsConfig

شی پیکربندی برای تنظیمات حریم خصوصی.
خواص
child Directed Treatment ?
نشان می‌دهد که آیا این صفحه باید به‌عنوان کارگردانی کودک در نظر گرفته شود .
limited Ads ?
برای کمک به نیازهای انطباق با مقررات ناشر، سرویس را در حالت تبلیغات محدود اجرا می کند.
non Personalized Ads ?
برای کمک به نیازهای انطباق با مقررات ناشر، سرویس را در حالت تبلیغات غیرشخصی اجرا می کند.
restrict Data Processing ?
برای کمک به نیازهای انطباق با مقررات ناشر، سرویس را برای اجرا در حالت پردازش محدود فعال می‌کند.
traffic Source ?
نشان می دهد که آیا درخواست ها ترافیک خریداری شده یا ارگانیک را نشان می دهند.
under Age Of Consent ?
نشان می‌دهد که آیا باید درخواست‌های تبلیغات را به‌عنوان کاربران زیر سن رضایت علامت‌گذاری کرد.
همچنین ببینید

خواص


Optional childDirectedTreatment

childDirectedTreatment ?: boolean
نشان می‌دهد که آیا این صفحه باید به‌عنوان کارگردانی کودک در نظر گرفته شود . برای پاک کردن تنظیمات، روی null تنظیم کنید.

تبلیغات محدود Optional

limitedAds ?: boolean
برای کمک به نیازهای انطباق با مقررات ناشر، سرویس را در حالت تبلیغات محدود اجرا می کند.

می‌توانید به GPT دستور دهید تا تبلیغات محدود را به دو روش درخواست کند:
  • به طور خودکار، با استفاده از یک سیگنال از یک پلت فرم مدیریت رضایت IAB TCF v2.0 .
  • به صورت دستی، با تنظیم مقدار این فیلد روی true .
پیکربندی دستی تبلیغات محدود تنها زمانی امکان پذیر است که GPT از URL تبلیغات محدود بارگیری شود. تلاش برای تغییر این تنظیم هنگامی که GPT از URL استاندارد بارگیری شده است، یک هشدار کنسول ناشر ایجاد می کند.

توجه داشته باشید که هنگام استفاده از 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,
});

TypeScript

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

تبلیغات غیرشخصی Optional

nonPersonalizedAds ?: boolean
برای کمک به نیازهای انطباق با مقررات ناشر، سرویس را در حالت تبلیغات غیرشخصی اجرا می کند.

محدودیت Optional پردازش داده

restrictDataProcessing ?: boolean
برای کمک به نیازهای انطباق با مقررات ناشر، سرویس را برای اجرا در حالت پردازش محدود فعال می‌کند.

منبع ترافیک Optional

trafficSource ?: TrafficSource
نشان می دهد که آیا درخواست ها ترافیک خریداری شده یا ارگانیک را نشان می دهند. این مقدار بعد منبع ترافیک را در گزارش Ad Manager پر می کند. اگر تنظیم نشده باشد، منبع ترافیک به طور پیش‌فرض در گزارش undefined .
مثال

جاوا اسکریپت

// 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,
});

TypeScript

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

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

Optional underAgeOfConsent

underAgeOfConsent ?: boolean
نشان می‌دهد که آیا باید درخواست‌های تبلیغات را به‌عنوان کاربران زیر سن رضایت علامت‌گذاری کرد. برای پاک کردن تنظیمات، روی null تنظیم کنید.

googletag.PubAdsService

Service را گسترش می دهد
سرویس تبلیغات ناشر. این سرویس برای واکشی و نمایش تبلیغات از حساب Google Ad Manager شما استفاده می شود.
روش ها
add Event 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 تنظیم می‌کند که برای همه جایگاه‌های تبلیغاتی تحت سرویس Publisher Ads اعمال می‌شود.
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();

TypeScript

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!;
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!;
googletag.display("div-2");

// This call to clear only slot1.
googletag.pubads().clear([slot1]);

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

// This call to clear all slots.
googletag.pubads().clear();
پارامترها
Optional slots : Slot [] آرایه ای از اسلات برای پاک کردن. آرایه اختیاری است. اگر نامشخص باشد تمام اسلات ها پاک خواهند شد.
برمی گرداند
boolean اگر شکاف‌ها پاک شده باشند، true برمی‌گرداند، در غیر این صورت false برمی‌گرداند.

clearCategoryExclusions

clearCategoryExclusions ( ) : PubAdsService
همه برچسب‌های حذف دسته تبلیغات در سطح صفحه را پاک می‌کند. اگر می خواهید اسلات را تازه کنید، این کار مفید است.
مثال

جاوا اسکریپت

// 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.

TypeScript

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

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

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

// Make ad requests. Any ad can be returned.
همچنین ببینید
برمی گرداند
PubAdsService شیء سرویسی که متد بر روی آن فراخوانی شده است.

هدف گذاری روشن

clearTargeting ( 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.

TypeScript

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

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

googletag.pubads().clearTargeting();
// All targeting has been cleared.
همچنین ببینید
پارامترها
Optional key : string کلید پارامتر هدف. کلید اختیاری است. تمام پارامترهای هدف گیری در صورت نامشخص بودن پاک خواهند شد.
برمی گرداند
PubAdsService شیء سرویسی که متد بر روی آن فراخوانی شده است.

collapseEmptyDivs

collapseEmptyDivs ( collapseBeforeAdFetch ?: boolean ) : boolean
جمع کردن div های اسلات را فعال می کند تا زمانی که محتوای تبلیغاتی برای نمایش وجود ندارد، فضایی را در صفحه اشغال نکنند. این حالت باید قبل از فعال شدن سرویس تنظیم شود.
همچنین ببینید
پارامترها
Optional collapseBeforeAdFetch : boolean حتی قبل از واکشی تبلیغات، شکاف‌ها جمع شوند یا خیر. این پارامتر اختیاری است. اگر ارائه نشود، false به عنوان مقدار پیش فرض استفاده می شود.
برمی گرداند
boolean اگر حالت جمع‌کردن div فعال باشد، true برمی‌گرداند و اگر فعال کردن حالت جمع‌کردن غیرممکن باشد، false برمی‌گرداند زیرا متد پس از فعال شدن سرویس فراخوانی شده است.

disableInitialLoad

disableInitialLoad ( ) : void
درخواست‌های تبلیغات را هنگام بارگیری صفحه غیرفعال می‌کند، اما اجازه می‌دهد تا تبلیغات با تماس PubAdsService.refresh درخواست شود. این باید قبل از فعال کردن سرویس تنظیم شود. حالت Async باید استفاده شود. در غیر این صورت درخواست تبلیغات با استفاده از refresh غیرممکن خواهد بود.
همچنین ببینید

نمایش داده شود

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");

TypeScript

googletag.pubads().display("/1234567/sports", [728, 90], "div-1");
همچنین ببینید
پارامترها
adUnitPath : string مسیر واحد تبلیغاتی اسلات که باید ارائه شود.
size : GeneralSize عرض و ارتفاع شکاف.
Optional div : string | Element یا شناسه div حاوی اسلات یا خود عنصر div.
Optional clickUrl : string نشانی وب کلیک کنید تا در این اسلات استفاده کنید.

فعال کردن LazyLoad

enableLazyLoad ( config ?: {
  fetchMarginPercent ?: number ;
  mobileScaling ?: number ;
  renderMarginPercent ?: number ;
} ) : void
بارگیری تنبل را در GPT همانطور که توسط شی پیکربندی تعریف شده است فعال می کند. برای مثال های دقیق تر، نمونه بارگیری Lazy را ببینید.

توجه: واکشی تنبل در 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,
});

TypeScript

googletag.pubads().enableLazyLoad({
  // Fetch slots within 5 viewports.
  fetchMarginPercent: 500,
  // Render slots within 2 viewports.
  renderMarginPercent: 200,
  // Double the above values on mobile.
  mobileScaling: 2.0,
});
همچنین ببینید
پارامترها
Optional config : {
  fetchMarginPercent ?: number ;
  mobileScaling ?: number ;
  renderMarginPercent ?: number ;
}
شیء پیکربندی امکان سفارشی سازی رفتار تنبل را فراهم می کند. هر پیکربندی حذف شده از یک مجموعه پیش‌فرض توسط Google استفاده می‌کند که به مرور زمان تنظیم می‌شود. برای غیرفعال کردن یک تنظیم خاص، مانند حاشیه واکشی، مقدار را روی -1 تنظیم کنید.
  • fetchMarginPercent

    حداقل فاصله یک شکاف از نمای فعلی باید قبل از واکشی تبلیغ به عنوان درصدی از اندازه درگاه نمایش باشد. مقدار 0 به معنای "زمانی که شکاف وارد نمای نمایش می شود"، 100 به معنای "زمانی که تبلیغ 1 پورت دید فاصله دارد" و غیره است.
  • renderMarginPercent

    حداقل فاصله از نمای فعلی یک شکاف باید قبل از ارائه یک تبلیغ باشد. این امکان واکشی از پیش آگهی را فراهم می کند، اما منتظر ارائه و دانلود منابع فرعی دیگر هستیم. این مقدار درست مانند fetchMarginPercent به عنوان درصدی از viewport کار می کند.
  • mobileScaling

    یک ضریب به حاشیه در دستگاه های تلفن همراه اعمال می شود. این اجازه می دهد تا حاشیه های مختلف در تلفن همراه در مقابل دسکتاپ. به عنوان مثال، مقدار 2.0 همه حاشیه‌ها را در دستگاه‌های تلفن همراه در 2 ضرب می‌کند و حداقل فاصله‌ای را که یک اسلات می‌تواند قبل از واکشی و رندر داشته باشد افزایش می‌دهد.

فعال کردن SingleRequest

enableSingleRequest ( ) : boolean
حالت درخواست تک را برای واکشی چند آگهی به طور همزمان فعال می کند. این امر مستلزم آن است که قبل از فعال کردن سرویس، تمام جایگاه‌های تبلیغات ناشر تعریف و به PubAdsService اضافه شوند. حالت تک درخواست باید قبل از فعال شدن سرویس تنظیم شود.
همچنین ببینید
برمی گرداند
boolean در صورت فعال بودن حالت درخواست تکی، true و در صورتی که فعال کردن حالت درخواست تک غیرممکن باشد، false ، زیرا متد پس از فعال شدن سرویس فراخوانی شده است.

فعال کردن VideoAds

enableVideoAds ( ) : void
به GPT سیگنال می دهد که تبلیغات ویدیویی در صفحه وجود خواهد داشت. این محدودیت‌های حذف رقابتی در تبلیغات نمایشی و ویدیویی را فعال می‌کند. اگر محتوای ویدیویی شناخته شده است، با PubAdsService.setVideoContent تماس بگیرید تا بتوانید از حذف محتوا برای تبلیغات نمایشی استفاده کنید.

دریافت کنید

get ( key : string ) : string
مقدار مشخصه AdSense مرتبط با کلید داده شده را برمی گرداند.
مثال

جاوا اسکریپت

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'.

TypeScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().get("adsense_background_color");
// Returns '#FFFFFF'.
همچنین ببینید
پارامترها
key : string نام ویژگی مورد نظر برای جستجو
برمی گرداند
string مقدار فعلی برای کلید مشخصه، یا اگر کلید موجود نباشد، null .

getAttributeKeys

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'].

TypeScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().set("adsense_border_color", "#AABBCC");
googletag.pubads().getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].
برمی گرداند
string [] مجموعه ای از کلیدهای ویژگی روی این سرویس تنظیم شده است. سفارش تعریف نشده است.

getTargeting

getTargeting ( key : string ) : string []
یک پارامتر هدف‌یابی در سطح خدمات سفارشی را که تنظیم شده است، برمی‌گرداند.
مثال

جاوا اسکریپت

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).

TypeScript

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

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

googletag.pubads().getTargeting("age");
// Returns [] (empty array).
پارامترها
key : string کلید هدف گیری که باید جستجو کنید.
برمی گرداند
string [] مقادیر مرتبط با این کلید، یا یک آرایه خالی اگر چنین کلیدی وجود نداشته باشد.

getTargetingKeys

getTargetingKeys ( ) : string []
فهرستی از تمام کلیدهای هدف گذاری در سطح سرویس سفارشی که تنظیم شده اند را برمی گرداند.
مثال

جاوا اسکریپت

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'].

TypeScript

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

googletag.pubads().getTargetingKeys();
// Returns ['interests', 'colors'].
برمی گرداند
string [] مجموعه ای از کلیدهای هدف گیری سفارش تعریف نشده است.

isInitialLoadDisabled

isInitialLoadDisabled ( ) : boolean
نشان می‌دهد که آیا درخواست‌های اولیه برای تبلیغات با موفقیت در تماس قبلی PubAdsService.disableInitialLoad غیرفعال شده است یا خیر.
برمی گرداند
boolean اگر تماس قبلی با PubAdsService.disableInitialLoad موفقیت آمیز بود، true است، در غیر این صورت false .

تازه کردن

refresh ( slots ?: Slot [] , options ?: {
  changeCorrelator : boolean ;
} ) : void
تبلیغات جدید را برای خاص یا همه اسلات های موجود در صفحه واکشی و نمایش می دهد. فقط در حالت رندر ناهمزمان کار می کند.

برای رفتار مناسب در همه مرورگرها، refresh تماس باید قبل از یک تماس برای display جایگاه آگهی باشد. اگر تماس برای display حذف شود، ممکن است بازخوانی غیرمنتظره عمل کند. در صورت تمایل، از روش 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 });

TypeScript

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!;
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!;
googletag.display("div-2");

// This call to refresh fetches a new ad for slot1 only.
googletag.pubads().refresh([slot1]);

// This call to refresh fetches a new ad for both slot1 and slot2.
googletag.pubads().refresh([slot1, slot2]);

// This call to refresh fetches a new ad for each slot.
googletag.pubads().refresh();

// This call to refresh fetches a new ad for slot1, without changing
// the correlator.
googletag.pubads().refresh([slot1], { changeCorrelator: false });

// This call to refresh fetches a new ad for each slot, without
// changing the correlator.
googletag.pubads().refresh(null, { changeCorrelator: false });
همچنین ببینید
پارامترها
Optional slots : Slot [] شکاف ها برای تازه کردن. آرایه اختیاری است. اگر نامشخص باشد، تمام اسلات ها به روز می شوند.
Optional options : {
  changeCorrelator : boolean ;
}
گزینه های پیکربندی مرتبط با این تماس تازه.
  • changeCorrelator

    مشخص می کند که آیا یک همبسته جدید برای واکشی تبلیغات ایجاد شود یا خیر. سرورهای تبلیغاتی ما این مقدار همبسته را برای مدت کوتاهی حفظ می‌کنند (در حال حاضر به مدت 30 ثانیه، اما ممکن است تغییر کنند)، به‌طوری‌که درخواست‌هایی با همبستگی مشابه که نزدیک به هم دریافت می‌شوند، یک نمای صفحه در نظر گرفته می‌شوند. به‌طور پیش‌فرض برای هر به‌روزرسانی یک همبسته جدید ایجاد می‌شود.

    توجه: این گزینه هیچ تأثیری بر نمای طولانی مدت GPT ندارد، که به طور خودکار تبلیغات موجود در صفحه را منعکس می کند و زمان انقضا ندارد.

مجموعه

set ( key : string , value : string ) : PubAdsService
مقادیری را برای ویژگی‌های AdSense تنظیم می‌کند که برای همه جایگاه‌های تبلیغاتی تحت سرویس Publisher Ads اعمال می‌شود.

بیش از یک بار فراخوانی این کلید برای همان کلید، مقادیر تنظیم شده قبلی را برای آن کلید لغو می کند. همه مقادیر باید قبل از تماس display یا refresh تنظیم شوند.
مثال

جاوا اسکریپت

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

جاوا اسکریپت (میراث)

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

TypeScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
همچنین ببینید
پارامترها
key : string نام صفت.
value : string ارزش صفت.
برمی گرداند
PubAdsService شیء سرویسی که متد بر روی آن فراخوانی شده است.

setCategoryExclusion

setCategoryExclusion ( categoryExclusion : string ) : PubAdsService
یک استثناء طبقه بندی آگهی در سطح صفحه برای نام برچسب داده شده تنظیم می کند.
مثال

جاوا اسکریپت

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

جاوا اسکریپت (میراث)

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

TypeScript

// Label = AirlineAd.
googletag.pubads().setCategoryExclusion("AirlineAd");
همچنین ببینید
پارامترها
categoryExclusion : string برچسب حذف دسته آگهی برای افزودن.
برمی گرداند
PubAdsService شیء سرویسی که متد بر روی آن فراخوانی شده است.

setCentering

setCentering ( centerAds : boolean ) : void
مرکز افقی تبلیغات را فعال و غیرفعال می کند. مرکز به طور پیش فرض غیرفعال است. در gpt_mobile.js قدیمی، وسط به طور پیش فرض فعال است.

این روش باید قبل از فراخوانی display یا refresh فراخوانی شود زیرا فقط تبلیغاتی که پس از فراخوانی این روش درخواست می شوند در مرکز قرار می گیرند.
مثال

جاوا اسکریپت

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

جاوا اسکریپت (میراث)

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

TypeScript

// Make ads centered.
googletag.pubads().setCentering(true);
پارامترها
centerAds : boolean true در مرکز تبلیغات، false برای تراز چپ آنها.

setForceSafeFrame

setForceSafeFrame ( forceSafeFrame : boolean ) : PubAdsService
پیکربندی می‌کند که آیا همه آگهی‌های موجود در صفحه باید با استفاده از ظرف SafeFrame ارائه شوند یا خیر.

لطفاً هنگام استفاده از این API موارد زیر را در نظر داشته باشید:
  • این تنظیم فقط برای درخواست‌های آگهی بعدی که برای اسلات‌های مربوطه انجام می‌شود، اعمال می‌شود.
  • تنظیم سطح شکاف، اگر مشخص شود، همیشه تنظیمات سطح صفحه را لغو می کند.
  • اگر روی true تنظیم شود (در سطح شکاف یا سطح صفحه)، تبلیغ همیشه با استفاده از یک محفظه SafeFrame مستقل از انتخاب انجام شده در رابط کاربری Google Ad Manager ارائه می‌شود.
  • با این حال، اگر روی false تنظیم شود یا نامشخص باقی بماند، بسته به نوع خلاقیت و انتخاب انجام شده در رابط کاربری Google Ad Manager، آگهی با استفاده از یک محفظه SafeFrame ارائه می‌شود.
  • این 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");

TypeScript

googletag.pubads().setForceSafeFrame(true);

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

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

googletag.display("div-1");
googletag.display("div-2");
همچنین ببینید
پارامترها
forceSafeFrame : boolean true تا همه تبلیغات موجود در صفحه در SafeFrames ارائه شوند و false برای تغییر تنظیمات قبلی به false. تنظیم این روی false زمانی که قبلا مشخص نشده باشد، چیزی را تغییر نخواهد داد.
برمی گرداند
PubAdsService شیء سرویسی که متد بر روی آن فراخوانی شده است.

setLocation

setLocation ( address : string ) : PubAdsService
اطلاعات مکان را از وب‌سایت‌ها ارسال می‌کند تا بتوانید موارد خط را به مکان‌های خاص هدف‌گیری جغرافیایی کنید.
مثال

جاوا اسکریپت

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

جاوا اسکریپت (میراث)

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

TypeScript

// Postal code:
googletag.pubads().setLocation("10001,US");
پارامترها
address : string آدرس فرم آزاد.
برمی گرداند
PubAdsService شیء سرویسی که متد بر روی آن فراخوانی شده است.

setPrivacySettings

setPrivacySettings ( privacySettings : PrivacySettingsConfig ) : PubAdsService
به پیکربندی تمام تنظیمات حریم خصوصی از یک API با استفاده از یک شیء پیکربندی اجازه می‌دهد.
مثال

جاوا اسکریپت

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,
});

TypeScript

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

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

// Clear the configuration for childDirectedTreatment.
googletag.pubads().setPrivacySettings({
  childDirectedTreatment: null,
});
همچنین ببینید
پارامترها
privacySettings : PrivacySettingsConfig شیء حاوی تنظیمات حریم خصوصی.
برمی گرداند
PubAdsService شیء سرویسی که تابع روی آن فراخوانی شده است.

setPublisherProvidedId

setPublisherProvidedId ( ppid : string ) : PubAdsService
مقدار شناسه ارائه شده توسط ناشر را تنظیم می کند.
مثال

جاوا اسکریپت

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

جاوا اسکریپت (میراث)

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

TypeScript

googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
همچنین ببینید
پارامترها
ppid : string شناسه الفبایی که توسط ناشر ارائه شده است. باید بین 32 تا 150 کاراکتر باشد.
برمی گرداند
PubAdsService شیء سرویسی که متد بر روی آن فراخوانی شده است.

setSafeFrameConfig

setSafeFrameConfig ( config : SafeFrameConfig ) : PubAdsService
تنظیمات برگزیده سطح صفحه را برای پیکربندی SafeFrame تنظیم می کند. هر کلید ناشناخته در شیء پیکربندی نادیده گرفته می شود. اگر یک مقدار نامعتبر برای یک کلید شناخته شده ارسال شود، کل پیکربندی نادیده گرفته می شود.

این تنظیمات برگزیده در سطح صفحه، در صورت مشخص شدن، با اولویت‌های سطح شکاف لغو می‌شوند.
مثال

جاوا اسکریپت

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");

TypeScript

googletag.pubads().setForceSafeFrame(true);

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

const slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

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

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

googletag.display("div-1");
googletag.display("div-2");
همچنین ببینید
پارامترها
config : SafeFrameConfig شی پیکربندی.
برمی گرداند
PubAdsService شیء سرویسی که متد بر روی آن فراخوانی شده است.

setTargeting

setTargeting ( key : string , value : string | string [] ) : PubAdsService
پارامترهای هدف‌یابی سفارشی را برای یک کلید مشخص تنظیم می‌کند که برای همه جایگاه‌های تبلیغاتی سرویس آگهی‌های ناشر اعمال می‌شود. چندین بار فراخوانی این کلید برای یک کلید، مقادیر قدیمی را بازنویسی می کند. این کلیدها در حساب Google Ad Manager شما تعریف شده اند.
مثال

جاوا اسکریپت

// 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"]);

TypeScript

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

// Example with multiple values for a key inside in an array.
googletag.pubads().setTargeting("interests", ["sports", "music"]);
همچنین ببینید
پارامترها
key : string کلید پارامتر هدف.
value : string | string [] مقدار پارامتر هدف یا آرایه ای از مقادیر.
برمی گرداند
PubAdsService شیء سرویسی که متد بر روی آن فراخوانی شده است.

setVideoContent

setVideoContent ( videoContentId : string , videoCmsId : string ) : void
اطلاعات محتوای ویدیویی را برای ارسال به همراه درخواست‌های آگهی برای اهداف هدف‌یابی و حذف محتوا تنظیم می‌کند. با فراخوانی این روش، تبلیغات ویدیویی به طور خودکار فعال می شوند. برای videoContentId و videoCmsId ، از مقادیری استفاده کنید که به سرویس جذب محتوای Google Ad Manager ارائه شده است.
همچنین ببینید
پارامترها
videoContentId : string شناسه محتوای ویدیویی
videoCmsId : string شناسه CMS ویدیو.

updateCorrelator

updateCorrelator ( ) : PubAdsService
همبستگی که با درخواست های تبلیغاتی ارسال می شود را تغییر می دهد و عملاً یک نمای صفحه جدید را شروع می کند. همبسته برای همه درخواست‌های تبلیغاتی که از یک نمای صفحه می‌آیند یکسان است و در بین بازدیدهای صفحه منحصر به فرد است. فقط برای حالت ناهمگام اعمال می شود.

توجه: این هیچ تأثیری بر نمای طولانی مدت GPT ندارد، که به طور خودکار تبلیغات را در صفحه منعکس می کند و زمان انقضا ندارد.
مثال

جاوا اسکریپت

// 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.

TypeScript

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

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

// The correlator will now be a new randomly selected value, different
// from 12345. All subsequent ad requests made by this page will use
// the new value.
برمی گرداند
PubAdsService شیء سرویسی که تابع روی آن فراخوانی شده است.

googletag.ResponseInformation

شیئی که نشان دهنده یک پاسخ آگهی واحد است.
خواص
advertiser Id
شناسه آگهی دهنده
campaign Id
شناسه کمپین
creative Id
شناسه خلاق.
creative Template Id
شناسه قالب آگهی.
line Item Id
شناسه مورد خط.
همچنین ببینید

خواص


شناسه تبلیغ

advertiserId : number
شناسه آگهی دهنده

شناسه کمپین

campaignId : number
شناسه کمپین

شناسه خلاق

creativeId : number
شناسه خلاق.

creativeTemplateId

creativeTemplateId : number
شناسه قالب آگهی.

lineItemId

lineItemId : number
شناسه مورد خط.

googletag.RewardedPayload

شیئی که نشان دهنده پاداش مرتبط با یک تبلیغ پاداش است
خواص
amount
تعداد مواردی که در جایزه گنجانده شده است.
type
نوع کالایی که در جایزه گنجانده شده است (مثلاً "سکه").
همچنین ببینید

خواص


مقدار

amount : number
تعداد مواردی که در جایزه گنجانده شده است.

نوع

type : string
نوع کالایی که در جایزه گنجانده شده است (مثلاً "سکه").

googletag.Service

کلاس سرویس پایه که شامل متدهای مشترک برای همه سرویس ها است.
روش ها
add Event Listener
شنونده‌ای را ثبت می‌کند که به شما امکان می‌دهد یک تابع جاوا اسکریپت را هنگامی که یک رویداد GPT خاص در صفحه اتفاق می‌افتد تنظیم و فراخوانی کنید.
get Slots
لیست اسلات های مرتبط با این سرویس را دریافت کنید.
remove Event Listener
شنونده قبلا ثبت نام شده را حذف می کند.

روش ها


addEventListener

addEventListener < K extends keyof EventTypeMap > ( eventType : K , listener : ( ( arg : EventTypeMap [ K ] ) => void ) ) : Service
شنونده‌ای را ثبت می‌کند که به شما امکان می‌دهد یک تابع جاوا اسکریپت را هنگامی که یک رویداد GPT خاص در صفحه اتفاق می‌افتد تنظیم و فراخوانی کنید. رویدادهای زیر پشتیبانی می شوند: یک شی از نوع رویداد مناسب هنگام فراخوانی به شنونده ارسال می شود.
مثال

جاوا اسکریپت

// 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.
  }
});

جاوا اسکریپت (میراث)

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

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

TypeScript

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

// 2. Adding an event listener with slot specific logic.
// Listeners operate at service level, which means that you cannot add
// a listener for an event for a specific slot only. You can, however,
// programmatically filter a listener to respond only to a certain ad
// slot, using this pattern:
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotOnload", (event) => {
  if (event.slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید
پارامترها
eventType : K رشته ای که نشان دهنده نوع رویداد تولید شده توسط GPT است. انواع رویداد به حروف بزرگ و کوچک حساس هستند.
listener : ( ( arg : EventTypeMap [ K ] ) => void ) عملکردی که یک آرگومان شیء یک رویداد واحد را می گیرد.
برمی گرداند
Service شیء خدماتی که در آن روش خوانده شده است.

getlots

getSlots ( ) : Slot []
لیست شکافهای مرتبط با این سرویس را دریافت کنید.
برمی گرداند
Slot [] شکاف هایی به ترتیب اضافه شده به سرویس.

remeventlistener

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();
});

جاوا اسکریپت (میراث)

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

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

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

TypeScript

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

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

  // Add onViewableListener as a listener for impressionViewable events.
  googletag.pubads().addEventListener("impressionViewable", onViewableListener);
  googletag.enableServices();
});
پارامترها
eventType : K رشته ای که نشان دهنده نوع رویداد ایجاد شده توسط GPT است. انواع رویداد حساس به مورد هستند.
listener : ( ( event : EventTypeMap [ K ] ) => void ) عملکردی که یک آرگومان شیء یک رویداد واحد را می گیرد.

googletag.sizemappingBuilder

سازنده برای اشیاء مشخصات نقشه برداری اندازه. این سازنده برای کمک به ساخت آسان مشخصات اندازه ارائه شده است.
روش ها
add Size
یک نقشه برداری از یک آرایه تک اندازه (نمایانگر نمای) به یک آرایه تک یا چند اندازه که نمایانگر شکاف است ، اضافه می کند.
build
مشخصات نقشه اندازه را از نقشه های اضافه شده به این سازنده ایجاد می کند.
همچنین ببینید

روش ها


اضافه کردن

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 &lt; 640x480
  .build();

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

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

جاوا اسکریپت (میراث)

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

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

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

TypeScript

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

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

// Mapping 2 will not show any ads for the following viewport sizes:
// [1024, 768] > size >= [980, 690] and
// [640, 480] > size >= [0, 0]
پارامترها
viewportSize : SingleSizeArray اندازه نمای این ورودی نقشه برداری.
slotSize : GeneralSize اندازه شکاف برای این ورودی نقشه برداری.
برمی گرداند
SizeMappingBuilder اشاره ای به این سازنده.

ساختن

build ( ) : SizeMappingArray
مشخصات نقشه اندازه را از نقشه های اضافه شده به این سازنده ایجاد می کند.

در صورت تهیه هرگونه نقشه های نامعتبر ، این روش null باز می گردد. در غیر این صورت مشخصات خود را در قالب صحیح باز می گرداند تا به Slot.DefinesizEmapping منتقل شود.

توجه: رفتار سازنده پس از فراخوانی این روش تعریف نشده است.
برمی گرداند
SizeMappingArray نتیجه ساخته شده توسط این سازنده. در صورت تهیه نقشه های اندازه نامعتبر ، می تواند تهی باشد.

googletag.slot

شکاف یک شیء است که یک شکاف تبلیغاتی را در یک صفحه نشان می دهد.
روش ها
add Service
خدماتی را به این شکاف اضافه می کند.
clear Category Exclusions
منسوخ شده است. تمام برچسب های محرومیت دسته AD در سطح اسلات را برای این شکاف پاک می کند.
clear Targeting
منسوخ شده است. پارامترهای هدفمند هدف خاص یا همه سطح سفارشی را برای این شکاف پاک می کند.
define Size Mapping
مجموعه ای از نگاشتها را از حداقل اندازه منظره به اندازه شکاف برای این شکاف تنظیم می کند.
get
منسوخ شده است. مقدار را برای ویژگی AdSense مرتبط با کلید داده شده برای این شکاف برمی گرداند.
get Ad Unit Path
مسیر کامل واحد AD را با کد شبکه و مسیر واحد AD برمی گرداند.
get Attribute Keys
منسوخ شده است. لیست کلیدهای ویژگی تنظیم شده در این شکاف را برمی گرداند.
get Category Exclusions
منسوخ شده است. برچسب های محرومیت دسته AD را برای این شکاف برمی گرداند.
get Config
گزینه های پیکربندی کلی برای شکاف تنظیم شده توسط SetConfig می شود.
get Response Information
اطلاعات پاسخ آگهی را برمی گرداند.
get Slot Element Id
شناسه div شکاف ارائه شده هنگام تعریف شکاف را برمی گرداند.
get Targeting
منسوخ شده است. یک پارامتر هدفمند سفارشی خاص را که در این شکاف تنظیم شده است ، برمی گرداند.
get Targeting Keys
منسوخ شده است. لیست کلیه کلیدهای هدفمند سفارشی را که روی این شکاف تنظیم شده است ، برمی گرداند.
set
منسوخ شده است. مقداری را برای یک ویژگی AdSense در این شکاف AD تعیین می کند.
set Category Exclusion
منسوخ شده است. برچسب محرومیت دسته AD سطح آگهی را در این شکاف تنظیم می کند.
set Click Url
منسوخ شده است. URL کلیک را تنظیم می کند که کاربران پس از کلیک بر روی آگهی هدایت می شوند.
set Collapse Empty Div
منسوخ شده است. تنظیم می کند که آیا div شکاف باید در صورت عدم وجود تبلیغ در شکاف پنهان شود.
set Config
گزینه های پیکربندی عمومی را برای این شکاف تنظیم می کند.
set Force Safe Frame
منسوخ شده است. پیکربندی می کند که آیا تبلیغات در این شکاف باید با استفاده از یک ظرف SafeFrame مجبور به ارائه شود.
set Safe Frame Config
منسوخ شده است. تنظیمات سطح شکاف را برای پیکربندی SafeFrame تنظیم می کند.
set Targeting
منسوخ شده است. یک پارامتر هدفمند سفارشی را برای این شکاف تنظیم می کند.
update Targeting From Map
منسوخ شده است. پارامترهای هدفمند سفارشی را برای این شکاف ، از یک کلید: نقشه Value در یک شیء JSON تنظیم می کند.

روش ها


سرویس اضافه کردن

addService ( service : Service ) : Slot
خدماتی را به این شکاف اضافه می کند.
مثال

جاوا اسکریپت

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

جاوا اسکریپت (میراث)

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

TypeScript

googletag.defineSlot("/1234567/sports", [160, 600], "div")!.addService(googletag.pubads());
همچنین ببینید
پارامترها
service : Service سرویس اضافه شده
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

ClearCategorexclusions

clearCategoryExclusions ( ) : Slot
تمام برچسب های محرومیت دسته AD در سطح اسلات را برای این شکاف پاک می کند.
مثال

جاوا اسکریپت

// 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.

جاوا اسکریپت (میراث)

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

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

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

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

TypeScript

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

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

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

// Make an ad request. Any ad can be returned for the slot.
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

تدوین

clearTargeting ( 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.

جاوا اسکریپت (میراث)

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

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

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

TypeScript

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

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

slot.clearTargeting();
// All targeting has been cleared.
همچنین ببینید
پارامترها
Optional key : string کلید پارامتر هدفمند. کلید اختیاری است ؛ اگر مشخص نشده باشد ، تمام پارامترهای هدفمند پاک می شوند.
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

تعریف کردن

defineSizeMapping ( 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);

جاوا اسکریپت (میراث)

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

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

slot.defineSizeMapping(mapping);

TypeScript

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

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

slot.defineSizeMapping(mapping!);
همچنین ببینید
پارامترها
sizeMapping : SizeMappingArray آرایه ای از نقشه های اندازه. برای ایجاد آن می توانید از SizemappingBuilder استفاده کنید. نقشه برداری هر اندازه مجموعه ای از دو عنصر است: SingleSearray و GeneralSize .
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

دریافت کنید

get ( key : string ) : string
مقدار را برای ویژگی AdSense مرتبط با کلید داده شده برای این شکاف برمی گرداند. برای دیدن ویژگی های سطح خدمات که توسط این شکاف به ارث رسیده اند ، از pubadsservice.get استفاده کنید.
مثال

جاوا اسکریپت

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

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

جاوا اسکریپت (میراث)

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

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

TypeScript

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

slot.get("adsense_background_color");
// Returns '#FFFFFF'.
همچنین ببینید
پارامترها
key : string نام این ویژگی برای جستجوی.
برمی گرداند
string مقدار فعلی برای کلید ویژگی ، یا اگر کلید موجود نیست ، null .

گچ

getAdUnitPath ( ) : string
مسیر کامل واحد AD را با کد شبکه و مسیر واحد AD برمی گرداند.
مثال

جاوا اسکریپت

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

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

جاوا اسکریپت (میراث)

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

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

TypeScript

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

slot.getAdUnitPath();
// Returns '/1234567/sports'.
برمی گرداند
string مسیر واحد تبلیغ.

GetAttributeKeys

getAttributeKeys ( ) : string []
لیست کلیدهای ویژگی تنظیم شده در این شکاف را برمی گرداند. برای دیدن کلیدهای ویژگی های سطح خدمات که توسط این شکاف به ارث رسیده اند ، از pubadsservice.getAttributeKeys استفاده کنید.
مثال

جاوا اسکریپت

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'].

جاوا اسکریپت (میراث)

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

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

TypeScript

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

slot.getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].
برمی گرداند
string [] مجموعه کلیدهای ویژگی. سفارش تعریف نشده است.

getCategorExclusions

getCategoryExclusions ( ) : string []
برچسب های محرومیت دسته AD را برای این شکاف برمی گرداند.
مثال

جاوا اسکریپت

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

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

جاوا اسکریپت (میراث)

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

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

TypeScript

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

slot.getCategoryExclusions();
// Returns ['AirlineAd', 'TrainAd'].
برمی گرداند
string [] برچسب های محرومیت دسته آگهی برای این شکاف یا یک آرایه خالی در صورت تنظیم هیچ یک از آنها.

getConfig

getConfig ( keys : string | string [] ) : Pick < SlotSettingsConfig , "adsenseAttributes" | "targeting" | "categoryExclusion" >
گزینه های پیکربندی کلی برای شکاف تنظیم شده توسط SetConfig می شود.

همه خصوصیات setConfig() با این روش پشتیبانی نمی شوند. خصوصیات پشتیبانی شده عبارتند از:
مثال

جاوا اسکریپت

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"]);

جاوا اسکریپت (میراث)

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

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

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

TypeScript

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

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

// Get the value of the `adsenseAttributes` and `categoryExclusion` settings.
const config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);
پارامترها
keys : string | string [] کلیدهای گزینه های پیکربندی برای بدست آوردن.
برمی گرداند
Pick < SlotSettingsConfig , "adsenseAttributes" | "targeting" | "categoryExclusion" > گزینه های پیکربندی برای شکاف.

اطلاعات

getResponseInformation ( ) : ResponseInformation
اطلاعات پاسخ آگهی را برمی گرداند. این بر اساس آخرین پاسخ تبلیغات برای شکاف است. اگر این امر زمانی خوانده شود که شکاف AD نداشته باشد ، null بازگردانده می شود.
برمی گرداند
ResponseInformation آخرین اطلاعات پاسخ تبلیغات یا null در صورتی که شکاف AD نداشته باشد.

getSlotElementId

getSlotElementId ( ) : string
شناسه div شکاف ارائه شده هنگام تعریف شکاف را برمی گرداند.
مثال

جاوا اسکریپت

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

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

جاوا اسکریپت (میراث)

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

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

TypeScript

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

slot.getSlotElementId();
// Returns 'div'.
برمی گرداند
string Slot div ID.

دستکاری

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).

جاوا اسکریپت (میراث)

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

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

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

TypeScript

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

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

slot.getTargeting("age");
// Returns [] (empty array).
پارامترها
key : string کلید هدفمند برای جستجوی.
برمی گرداند
string [] مقادیر مرتبط با این کلید یا یک آرایه خالی در صورت وجود چنین کلید.

GetTargetingKeys

getTargetingKeys ( ) : string []
لیست کلیه کلیدهای هدفمند سفارشی را که روی این شکاف تنظیم شده است ، برمی گرداند. کلیدهای هدفمند سطح خدمات گنجانده نشده است.
مثال

جاوا اسکریپت

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'].

جاوا اسکریپت (میراث)

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

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

TypeScript

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

slot.getTargetingKeys();
// Returns ['interests', 'allow_expandable'].
برمی گرداند
string [] مجموعه کلیدهای هدفمند. سفارش تعریف نشده است.

مجموعه

set ( key : string , value : string ) : Slot
مقداری را برای یک ویژگی AdSense در این شکاف AD تعیین می کند. با این کار مقادیر تعیین شده در سطح سرویس برای این کلید غلبه می کند.

فراخوانی این روش بیش از یک بار برای همان کلید ، مقادیر قبلی را برای آن کلید نادیده می گیرد. تمام مقادیر باید قبل از فراخوانی display یا refresh تنظیم شوند.
مثال

جاوا اسکریپت

// 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());

TypeScript

// Setting an attribute on a single ad slot.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .set("adsense_background_color", "#FFFFFF")
  .addService(googletag.pubads());
همچنین ببینید
پارامترها
key : string نام ویژگی.
value : string مقدار ویژگی
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

setCategorexclusion

setCategoryExclusion ( categoryExclusion : string ) : Slot
برچسب محرومیت دسته AD سطح آگهی را در این شکاف تنظیم می کند.
مثال

جاوا اسکریپت

// 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());

TypeScript

// Label = AirlineAd
googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setCategoryExclusion("AirlineAd")
  .addService(googletag.pubads());
همچنین ببینید
پارامترها
categoryExclusion : string برچسب محرومیت دسته AD برای افزودن.
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

setclickurl

setClickUrl ( value : string ) : Slot
URL کلیک را تنظیم می کند که کاربران پس از کلیک بر روی آگهی هدایت می شوند.

سرورهای Google Ad Manager هنوز هم یک کلیک را ضبط می کنند حتی اگر URL کلیک جایگزین شود. هر URL صفحه فرود در ارتباط با خلاقیتی که ارائه می شود به مقدار ارائه شده اضافه می شود. تماسهای بعدی مقدار را بازنویسی می کنند. این فقط برای درخواست های غیر SRA کار می کند.
مثال

جاوا اسکریپت

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());

TypeScript

googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setClickUrl("http://www.example.com?original_click_url=")
  .addService(googletag.pubads());
پارامترها
value : string برای تنظیم URL کلیک کنید.
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

setCollapSeemptyDiv

setCollapseEmptyDiv ( collapse : boolean , collapseBeforeAdFetch ?: boolean ) : Slot
تنظیم می کند که آیا div شکاف باید در صورت عدم وجود تبلیغ در شکاف پنهان شود. این تنظیمات سطح خدمات را نادیده می گیرد.
مثال

جاوا اسکریپت

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.

TypeScript

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

googletag
  .defineSlot("/1234567/sports", [160, 600], "div-2")!
  .setCollapseEmptyDiv(true)
  .addService(googletag.pubads());
// The above will cause the div for this slot to be collapsed
// only after GPT detects that no ads are available for the slot.
همچنین ببینید
پارامترها
collapse : boolean در صورت بازگشت هیچ آگهی ، شکاف را فرو می ریزید.
Optional collapseBeforeAdFetch : boolean این که آیا حتی قبل از اینکه یک آگهی انجام شود ، شکاف را فرو می ریزد. اگر فروپاشی true نیست ، نادیده گرفته می شود.
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

setConfig

setConfig ( slotConfig : SlotSettingsConfig ) : void
گزینه های پیکربندی عمومی را برای این شکاف تنظیم می کند.
پارامترها
slotConfig : SlotSettingsConfig شیء پیکربندی.

setforcesafeframe

setForceSafeFrame ( forceSafeFrame : boolean ) : Slot
پیکربندی می کند که آیا تبلیغات در این شکاف باید با استفاده از یک ظرف SafeFrame مجبور به ارائه شود.

لطفاً هنگام استفاده از این API موارد زیر را در ذهن داشته باشید:
  • این تنظیم فقط برای درخواست های تبلیغاتی بعدی که برای اسلات های مربوطه انجام می شود ، اعمال می شود.
  • تنظیم سطح شکاف ، در صورت مشخص شدن ، همیشه تنظیم سطح صفحه را نادیده می گیرد.
  • در صورت تنظیم true (در سطح شکاف یا سطح صفحه) ، تبلیغ همیشه با استفاده از یک کانتینر SafeFrame مستقل از انتخاب ساخته شده در UI Google Ad Manager انجام می شود.
  • با این حال ، اگر روی false یا مانده به صورت نامشخص تنظیم شود ، بسته به نوع خلاق و انتخاب انجام شده در UI Google Ad Manager ، با استفاده از یک ظرف SafeFrame انجام می شود.
  • این API باید با احتیاط مورد استفاده قرار گیرد زیرا می تواند بر رفتار خلاقانی که تلاش می کنند از Iframes خود خارج شوند یا به آنها اعتماد کند که مستقیماً در صفحه ناشران ارائه می شود ، تأثیر بگذارد.
مثال

جاوا اسکریپت

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

جاوا اسکریپت (میراث)

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

TypeScript

googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .setForceSafeFrame(true)
  .addService(googletag.pubads());
همچنین ببینید
پارامترها
forceSafeFrame : boolean true که تمام تبلیغات موجود در این شکاف را در Safeframes و false برای امتناع از یک تنظیم سطح صفحه (در صورت وجود) انجام دهید. تنظیم این false در هنگام مشخص شدن در سطح صفحه ، چیزی تغییر نخواهد کرد.
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

setSafeFrameConfig

setSafeFrameConfig ( config : SafeFrameConfig ) : Slot
تنظیمات سطح شکاف را برای پیکربندی SafeFrame تنظیم می کند. هرگونه کلیدهای ناشناخته در شیء پیکربندی نادیده گرفته می شود. اگر یک مقدار نامعتبر برای یک کلید شناخته شده منتقل شود ، کل پیکربندی نادیده گرفته می شود.

این ترجیحات سطح شکاف ، در صورت مشخص شدن ، ترجیحات سطح صفحه را نادیده می گیرد.
مثال

جاوا اسکریپت

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");

TypeScript

googletag.pubads().setForceSafeFrame(true);

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

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

googletag.display("div-1");
googletag.display("div-2");
همچنین ببینید
پارامترها
config : SafeFrameConfig شیء پیکربندی.
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

سرنگونی

setTargeting ( key : string , value : string | string [] ) : Slot
یک پارامتر هدفمند سفارشی را برای این شکاف تنظیم می کند. فراخوانی این روش چندین بار برای همان کلید ، مقادیر قدیمی را رونویسی می کند. مقادیر تنظیم شده در اینجا پارامترهای هدفمند تعیین شده در سطح سرویس را بازنویسی می کنند. این کلیدها در حساب Google Ad Manager شما تعریف شده اند.
مثال

جاوا اسکریپت

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"]);

جاوا اسکریپت (میراث)

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

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

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

TypeScript

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

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

// Example with multiple values for a key inside in an array.
slot.setTargeting("interests", ["sports", "music"]);
همچنین ببینید
پارامترها
key : string کلید پارامتر هدفمند.
value : string | string [] هدف قرار دادن مقدار پارامتر یا آرایه مقادیر.
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

به روزرسانی

updateTargetingFromMap ( map : {
  [ adUnitPath : string ] : string | string [] ;
} ) : Slot
پارامترهای هدفمند سفارشی را برای این شکاف ، از یک کلید: نقشه Value در یک شیء JSON تنظیم می کند. این همان فراخوانی slot.settargeting برای تمام مقادیر کلیدی شی است. این کلیدها در حساب Google Ad Manager شما تعریف شده اند.

یادداشت ها:
  • در صورت رونویسی ، فقط آخرین مقدار نگهداری می شود.
  • اگر مقدار آرایه ای باشد ، هر مقدار قبلی رونویسی می شود ، ادغام نمی شود.
  • مقادیر تنظیم شده در اینجا پارامترهای هدفمند تعیین شده در سطح سرویس را بازنویسی می کنند.
مثال

جاوا اسکریپت

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

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

جاوا اسکریپت (میراث)

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

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

TypeScript

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

slot.updateTargetingFromMap({
  color: "red",
  interests: ["sports", "music", "movies"],
});
پارامترها
map : {
  [ adUnitPath : string ] : string | string [] ;
}
کلید پارامتر هدفمند: نقشه مقدار.
برمی گرداند
Slot شیء شکاف که در آن روش خوانده شده است.

googletag.config

رابط اصلی پیکربندی برای تنظیمات سطح صفحه.
رابط ها
Ad Expansion Config
تنظیمات برای کنترل گسترش تبلیغ.
Ad Sense Attributes Config
تنظیمات برای کنترل رفتار تبلیغات AdSense.
Component Auction Config
یک شیء که یک حراج مؤلفه واحد را در یک حراج تبلیغ در دستگاه ارائه می دهد.
Interstitial Config
شیئی که رفتار یک شکاف تبلیغاتی بینابینی را تعریف می کند.
Lazy Load Config
تنظیمات برای کنترل استفاده از بارگذاری تنبل در GPT.
Page Settings Config
رابط اصلی پیکربندی برای تنظیمات سطح صفحه.
Privacy Treatments Config
تنظیمات برای کنترل درمان های حریم خصوصی ناشر.
Publisher Provided Signals Config
ناشر شیء سیگنال ها (PPS) را ارائه داد.
Safe Frame Config
تنظیمات برای کنترل SafeFrame در GPT.
Slot Settings Config
رابط اصلی پیکربندی برای تنظیمات سطح شکاف.
Taxonomy Data
یک شیء حاوی مقادیر برای یک طبقه بندی واحد.
Video Ads Config
تنظیمات برای پیکربندی تنظیمات مربوط به آگهی ویدیویی.
نام مستعار
Interstitial Trigger
محرکهای تبلیغاتی بینابینی پشتیبانی می کنند.
Privacy Treatment
از درمان های حریم خصوصی ناشر پشتیبانی می شود.
Taxonomy
طبقه بندی های پشتیبانی شده برای ناشر سیگنال ها (PPS) ارائه می دهند .

نام مستعار


بینابین

InterstitialTrigger : "unhideWindow" | "navBar"
محرکهای تبلیغاتی بینابینی پشتیبانی می کنند.

حریم خصوصی

PrivacyTreatment : "disablePersonalization"
از درمان های حریم خصوصی ناشر پشتیبانی می شود.

طبقه بندی

Taxonomy : "IAB_AUDIENCE_1_1" | "IAB_CONTENT_2_2"
طبقه بندی های پشتیبانی شده برای ناشر سیگنال ها (PPS) ارائه می دهند .
همچنین ببینید

googletag.config.adexpansionconfig

تنظیمات برای کنترل گسترش تبلیغ.
خواص
enabled ?
آیا گسترش تبلیغات فعال است یا غیرفعال است.
مثال

جاوا اسکریپت

// 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 },
});

TypeScript

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

خواص


Optional فعال

enabled ?: boolean
آیا گسترش تبلیغات فعال است یا غیرفعال است.

تنظیم این مقدار بر پیش فرض پیکربندی شده در Google Ad Manager غلبه می کند.
همچنین ببینید

googletag.config.adsenseattributeSconfig

تنظیمات برای کنترل رفتار تبلیغات AdSense.

از این ویژگی ها می توان برای غلبه بر تنظیمات سمت سرور بر اساس هرگونه درخواست استفاده کرد.
خواص
adsense _ad _format ?
قالب تبلیغ AdSense.
adsense _channel _ids ?
شناسه کانال AdSense.
adsense _test _mode ?
آیا حالت تست فعال است یا خیر.
document _language ?
زبان صفحه ای که تبلیغات در آن نمایش داده می شود.
page _url ?
URL صفحه ای که در آن تبلیغات نمایش داده می شود.
همچنین ببینید

خواص


ADSENSE_AD_FORMAT Optional

adsense_ad_format ?: "120x240_as" | "120x600_as" | "125x125_as" | "160x600_as" | "180x150_as" | "200x200_as" | "234x60_as" | "250x250_as" | "300x250_as" | "336x280_as" | "468x60_as" | "728x90_as"
قالب تبلیغ AdSense.

Optional adsense_channel_ids

adsense_channel_ids ?: string
شناسه کانال AdSense.

مقادیر مجاز شناسه های کانال هستند که توسط '+' از هم جدا شده اند.

مثال: 271828183+314159265
همچنین ببینید

Optional adsense_test_mode

adsense_test_mode ?: "on"
آیا حالت تست فعال است یا خیر.

هنگامی که on قرار گرفت ، تبلیغات به عنوان تست فقط مشخص می شوند و در شمارش یا صورتحساب درج نمی شوند. این تنظیم باید برای تولید ، ترافیک غیر آزمون غیرقانونی باشد.

document_language Optional

document_language ?: string
زبان صفحه ای که تبلیغات در آن نمایش داده می شود.

مقادیر مجاز کدهای زبان ISO 639-1 معتبر هستند.

مثال: en
همچنین ببینید

page_url Optional

page_url ?: string
URL صفحه ای که در آن تبلیغات نمایش داده می شود.

مقادیر مجاز URL های معتبر هستند.

مثال: http://www.example.com

googletag.config.componentauctionconfig

یک شیء که یک حراج مؤلفه واحد را در یک حراج تبلیغ در دستگاه ارائه می دهد.
خواص
auction Config
یک شی پیکربندی حراج برای این حراج مؤلفه.
config Key
کلید پیکربندی مرتبط با این حراج مؤلفه.
همچنین ببینید

خواص


حراج

auctionConfig : {
  auctionSignals ?: unknown ;
  decisionLogicURL : string ;
  interestGroupBuyers ?: string [] ;
  perBuyerExperimentGroupIds ?: {
    [ buyer : string ] : number ;
  } ;
  perBuyerGroupLimits ?: {
    [ buyer : string ] : number ;
  } ;
  perBuyerSignals ?: {
    [ buyer : string ] : unknown ;
  } ;
  perBuyerTimeouts ?: {
    [ buyer : string ] : number ;
  } ;
  seller : string ;
  sellerExperimentGroupId ?: number ;
  sellerSignals ?: unknown ;
  sellerTimeout ?: number ;
  trustedScoringSignalsURL ?: string ;
}
یک شی پیکربندی حراج برای این حراج مؤلفه.

اگر این مقدار روی null تنظیم شود ، هر پیکربندی موجود برای configKey مشخص حذف می شود.
مثال

جاوا اسکریپت

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,
    },
  ],
});

جاوا اسکریپت (میراث)

var componentAuctionConfig = {
  // Seller URL should be https and the same as decisionLogicURL's origin
  seller: "https://testSeller.com",
  decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js",
  interestGroupBuyers: ["https://example-buyer.com"],
  auctionSignals: { auction_signals: "auction_signals" },
  sellerSignals: { seller_signals: "seller_signals" },
  perBuyerSignals: {
    // listed on interestGroupBuyers
    "https://example-buyer.com": {
      per_buyer_signals: "per_buyer_signals",
    },
  },
};

var auctionSlot = googletag.defineSlot("/1234567/example", [160, 600]);

// To add configKey to the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: componentAuctionConfig,
    },
  ],
});

// To remove configKey from the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: null,
    },
  ],
});

TypeScript

const componentAuctionConfig = {
  // Seller URL should be https and the same as decisionLogicURL's origin
  seller: "https://testSeller.com",
  decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js",
  interestGroupBuyers: ["https://example-buyer.com"],
  auctionSignals: { auction_signals: "auction_signals" },
  sellerSignals: { seller_signals: "seller_signals" },
  perBuyerSignals: {
    // listed on interestGroupBuyers
    "https://example-buyer.com": {
      per_buyer_signals: "per_buyer_signals",
    },
  },
};

const auctionSlot = googletag.defineSlot("/1234567/example", [160, 600])!;

// To add configKey to the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: componentAuctionConfig,
    },
  ],
});

// To remove configKey from the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: null,
    },
  ],
});
همچنین ببینید

عکسبرداری

configKey : string
کلید پیکربندی مرتبط با این حراج مؤلفه.

این مقدار باید غیر خالی باشد و باید بی نظیر باشد. اگر دو اشیاء ComponentAuctionConfig همان مقدار کلید پیکربندی را به اشتراک بگذارند ، آخرین مورد تنظیم شده ، تنظیمات قبلی را بازنویسی می کند.

googletag.config.interstititialConfig

شیئی که رفتار یک شکاف تبلیغاتی بینابینی را تعریف می کند.
خواص
require Storage Access ?
این که آیا رضایت ذخیره سازی محلی برای نمایش این تبلیغ بینابینی مورد نیاز است.
triggers ?
پیکربندی ماشه بینابینی برای این تبلیغ بینابینی.

خواص


نیازهای Optional

requireStorageAccess ?: boolean
این که آیا رضایت ذخیره سازی محلی برای نمایش این تبلیغ بینابینی مورد نیاز است.

GPT از ذخیره محلی برای اجرای کلاه فرکانس برای تبلیغات بینابینی استفاده می کند. با این حال ، کاربرانی که رضایت ذخیره محلی را ارائه نداده اند ، هنوز واجد شرایط دریافت تبلیغات بینابینی هستند. تنظیم این خاصیت برای انتخاب true از رفتار پیش فرض ، و تضمین می کند که تبلیغات بین المللی فقط به کاربرانی که رضایت ذخیره محلی ارائه داده اند نشان داده می شود.
مثال

جاوا اسکریپت

// 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
  },
});

جاوا اسکریپت (میراث)

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

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

TypeScript

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

interstitialSlot.setConfig({
  interstitial: {
    requireStorageAccess: true, // defaults to false
  },
});
همچنین ببینید

محرکهای Optional

triggers ?: Partial < Record < InterstitialTrigger , boolean > >
پیکربندی ماشه بینابینی برای این تبلیغ بینابینی.

تنظیم مقدار یک ماشه بینابینی در true باعث فعال شدن آن می شود و false آن را غیرفعال می کند. با این کار مقادیر پیش فرض پیکربندی شده در Google Ad Manager غلبه می کند.
مثال

جاوا اسکریپت

// 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,
    },
  },
});

جاوا اسکریپت (میراث)

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

// Enable optional interstitial triggers.
// Change this value to false to disable.
var enableTriggers = true;

interstitialSlot.setConfig({
  interstitial: {
    triggers: {
      navBar: enableTriggers,
      unhideWindow: enableTriggers,
    },
  },
});

TypeScript

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

// Enable optional interstitial triggers.
// Change this value to false to disable.
const enableTriggers = true;

interstitialSlot.setConfig({
  interstitial: {
    triggers: {
      navBar: enableTriggers,
      unhideWindow: enableTriggers,
    },
  },
});
همچنین ببینید

googletag.config.LazyloadConfig

تنظیمات برای کنترل استفاده از بارگذاری تنبل در GPT.
خواص
fetch Margin Percent ?
حداقل فاصله از Viewport فعلی یک شکاف باید قبل از درخواست AD باشد ، که به عنوان درصدی از اندازه Viewport بیان شده است.
mobile Scaling ?
چند برابر برای حاشیه دستگاه های تلفن همراه اعمال می شود.
render Margin Percent ?
حداقل فاصله از نمای فعلی یک شکاف باید قبل از ارائه تبلیغات باشد ، که به عنوان درصدی از اندازه نمای بیان شده است.
همچنین ببینید

خواص


Optional fetchmarginpercent

fetchMarginPercent ?: number
حداقل فاصله از Viewport فعلی یک شکاف باید قبل از درخواست AD باشد ، که به عنوان درصدی از اندازه Viewport بیان شده است.

این تنظیم در رابطه با RenderMarginPercent استفاده می شود ، این تنظیم امکان پیشگیری از یک تبلیغ را فراهم می کند ، اما در انتظار ارائه و بارگیری سایر منابع دیگر است. به این ترتیب ، این مقدار همیشه باید بیشتر از یا مساوی با RenderMarginPercent باشد.

مقدار 0 به معنای "هنگامی که شکاف وارد نمای Viewport می شود" ، 100 به معنای "وقتی تبلیغ 1 Viewport از دور است" و غیره.

Mobilescaling Optional

mobileScaling ?: number
چند برابر برای حاشیه دستگاه های تلفن همراه اعمال می شود. این ضرب در هر دو FetchMarginPercent و RenderMarginPercent اعمال می شود.

این امر باعث می شود حاشیه های مختلف در دسک تاپ موبایل در مقابل ، جایی که اندازه نمای و سرعت پیمایش متفاوت است. به عنوان مثال ، یک مقدار 2.0 تمام حاشیه ها را در 2 دستگاه های تلفن همراه ضرب می کند ، افزایش حداقل فاصله یک شکاف می تواند قبل از واکشی و ارائه باشد.

rendermarginpercent Optional

renderMarginPercent ?: number
حداقل فاصله از نمای فعلی یک شکاف باید قبل از ارائه تبلیغات باشد ، که به عنوان درصدی از اندازه نمای بیان شده است.

این تنظیم در رابطه با FetchMarginPercent استفاده می شود ، این تنظیم امکان پیشگیری از یک تبلیغ را فراهم می کند ، اما در انتظار ارائه و بارگیری سایر منابع دیگر است. به همین ترتیب ، این مقدار همیشه باید کمتر از یا مساوی با fetchmarginpercent باشد.

مقدار 0 به معنای "هنگامی که شکاف وارد نمای Viewport می شود" ، 100 به معنای "وقتی تبلیغ 1 Viewport از دور است" و غیره.

googletag.config.pagesettingsconfig

رابط اصلی پیکربندی برای تنظیمات سطح صفحه.

اجازه می دهد تا چندین ویژگی را با یک تماس API تنظیم کنید.

کلیه خصوصیات ذکر شده در زیر نمونه هایی هستند و ویژگی های واقعی استفاده از SetConfig را منعکس نمی کنند. برای مجموعه ویژگی ها ، قسمتهای موجود در نوع PagesettingsConfig را در زیر مشاهده کنید.

مثال ها:
  • فقط ویژگی های مشخص شده در تماس googletag.setConfig اصلاح شده است.
      // Configure feature alpha.
      googletag.setConfig({
          alpha: {...}
      });
    
      // Configure feature bravo. Feature alpha is unchanged.
      googletag.setConfig({
         bravo: {...}
      });
  • تمام تنظیمات برای یک ویژگی معین با هر تماس به Googletag.setConfig به روز می شود.
      // Configure feature charlie to echo = 1, foxtrot = true.
      googletag.setConfig({
          charlie: {
              echo: 1,
              foxtrot: true,
          }
      });
    
      // Update feature charlie to echo = 2. Since foxtrot was not specified,
      // the value is cleared.
      googletag.setConfig({
          charlie: {
              echo: 2
          }
      });
  • تمام تنظیمات یک ویژگی را می توان با عبور null پاک کرد.
      // Configure features delta, golf, and hotel.
      googletag.setConfig({
          delta: {...},
          golf: {...},
          hotel: {...},
      });
    
      // Feature delta and hotel are cleared, but feature golf remains set.
      googletag.setConfig({
          delta: null,
          hotel: null,
      });
خواص
ad Expansion ?
تنظیمات برای کنترل گسترش تبلیغ.
adsense Attributes ?
تنظیم برای پیکربندی ویژگی های AdSense.
ad Yield ?
منسوخ شده است.
category Exclusion ?
تنظیم برای پیکربندی استثناء دسته بندی تبلیغات.
centering ?
تنظیم برای کنترل مرکز افقی تبلیغات.
collapse Div ?
تنظیم برای کنترل رفتار فروپاشی شکافهای AD.
disable Initial Load ?
تنظیم برای کنترل هنگام درخواست تبلیغات.
lazy Load ?
تنظیمات برای کنترل استفاده از بارگذاری تنبل در GPT.
location ?
تنظیم موارد خط هدف جغرافیایی به مکان های جغرافیایی.
pps ?
تنظیمات برای کنترل ناشر سیگنال ها (PPS) را ارائه داد.
privacy Treatments ?
تنظیمات برای کنترل درمان های حریم خصوصی ناشر.
safe Frame ?
تنظیمات برای کنترل استفاده از SafeFrame در GPT.
single Request ?
تنظیم برای فعال یا غیرفعال کردن معماری درخواست تک (SRA).
targeting ?
تنظیم برای کنترل هدف گذاری ارزش کلید.
thread Yield ?
تنظیم برای کنترل اینکه آیا GPT باید هنگام درخواست و ارائه خلاقیت ، موضوع JS را به دست آورد.
video Ads ?
تنظیمات برای کنترل تبلیغات ویدیویی.

خواص


adexpansion Optional

adExpansion ?: AdExpansionConfig
تنظیمات برای کنترل گسترش تبلیغ.

adsenseattributes Optional

adsenseAttributes ?: AdSenseAttributesConfig
تنظیم برای پیکربندی ویژگی های AdSense.

ویژگی های AdSense پیکربندی شده از طریق این تنظیم برای کلیه شکافهای تبلیغاتی در صفحه اعمال می شود. این تنظیم ممکن است چندین بار نامیده شود تا مقادیر چند ویژگی را تعریف کند ، یا مقادیر موجود را بازنویسی کند.

تغییرات ویژگی AdSense فقط در مورد تبلیغات درخواست شده پس از فراخوانی این روش اعمال می شود. به همین دلیل ، توصیه می شود قبل از هرگونه تماس با googletag.display یا 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 });

جاوا اسکریپت (میراث)

// Set the document language and page URL.
googletag.setConfig({
  adsenseAttributes: { document_language: "en", page_url: "http://www.example.com" },
});

// Clear the page URL only.
googletag.setConfig({ adsenseAttributes: { page_url: null } });

// Clear all AdSense attributes.
googletag.setConfig({ adsenseAttributes: null });

TypeScript

// Set the document language and page URL.
googletag.setConfig({
  adsenseAttributes: { document_language: "en", page_url: "http://www.example.com" },
});

// Clear the page URL only.
googletag.setConfig({ adsenseAttributes: { page_url: null } });

// Clear all AdSense attributes.
googletag.setConfig({ adsenseAttributes: null });

Adyield Optional

adYield ?: "DISABLED" | "ENABLED_ALL_SLOTS"

دسته بندی Optional xclusion

categoryExclusion ?: string []
تنظیم برای پیکربندی استثناء دسته بندی تبلیغات.
مثال

جاوا اسکریپت

// 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 });

TypeScript

// Label = AirlineAd.
googletag.setConfig({ categoryExclusion: ["AirlineAd"] });

// Clearing category exclusion setting.
googletag.setConfig({ categoryExclusion: null });
همچنین ببینید

مرکز Optional

centering ?: boolean
تنظیم برای کنترل مرکز افقی تبلیغات. مرکز به طور پیش فرض غیرفعال است.

تغییرات مرکز افقی فقط در مورد تبلیغات درخواست شده پس از فراخوانی این روش اعمال می شود. به همین دلیل ، توصیه می شود قبل از هرگونه تماس با googletag.display یا pubadsservice.refresh ، این روش را فراخوانی کنید.
مثال

جاوا اسکریپت

// 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 });

TypeScript

// Make ads centered.
googletag.setConfig({ centering: true });

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

Optional فروپاشی

collapseDiv ?: "DISABLED" | "BEFORE_FETCH" | "ON_NO_FILL"
تنظیم برای کنترل رفتار فروپاشی شکافهای AD.

یک شکاف تبلیغاتی فروپاشی هیچ فضایی در صفحه نمی گیرد.

مقادیر پشتیبانی شده:
  • null (پیش فرض): شکاف از بین نمی رود.
  • DISABLED : شکاف فروپاشی نخواهد کرد ، خواه یک تبلیغ بازگردانده شود یا خیر.
  • BEFORE_FETCH : شکاف شروع به فروپاشی می کند و هنگام بازگشت یک تبلیغ گسترش می یابد.
  • ON_NO_FILL : شکاف شروع می شود و در صورت عدم بازگشت تبلیغ ، فروپاشی می شود.
مثال

جاوا اسکریپت

// 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 });

TypeScript

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

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

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

// Clear the collapse setting.
googletag.setConfig({ collapseDiv: null });
همچنین ببینید

بارگیری Optional

disableInitialLoad ?: boolean
تنظیم برای کنترل هنگام درخواست تبلیغات.

به طور پیش فرض ، روش googletag.display هر دو اسلات تبلیغاتی را ثبت می کند و تبلیغات را برای آنها درخواست می کند. با این حال ، مواقعی وجود دارد که ممکن است ترجیح داده شود این اقدامات را جدا کند ، تا بتوانید هنگام بارگیری محتوای AD دقیق تر کنترل کنید.

با فعال کردن این تنظیم ، هنگام فراخوانی روش display() ، از تبلیغات برای اسلات های ثبت شده درخواست نمی شود. در عوض ، برای شروع درخواست تبلیغ ، باید یک تماس جداگانه به pubadsservice.refresh انجام شود.

این روش باید قبل از فراخوانی Googletag.Enableservice فراخوانی شود.
مثال

جاوا اسکریپت

// Prevent requesting ads when `display()` is called.
googletag.setConfig({ disableInitialLoad: true });

جاوا اسکریپت (میراث)

// Prevent requesting ads when `display()` is called.
googletag.setConfig({ disableInitialLoad: true });

TypeScript

// Prevent requesting ads when `display()` is called.
googletag.setConfig({ disableInitialLoad: true });
همچنین ببینید

lazyload Optional

lazyLoad ?: LazyLoadConfig
تنظیمات برای کنترل استفاده از بارگذاری تنبل در GPT.

بارگیری تنبل تکنیکی برای تأخیر در درخواست و ارائه تبلیغات تا زمانی که به نمای کاربر نزدیک شود. برای مثال بیشتر ، به نمونه بارگذاری تنبل مراجعه کنید.

توجه: اگر singleRequest فعال باشد ، تنبل تنبل فقط هنگامی کار می کند که همه شکاف ها خارج از حاشیه واکشی باشند.

هر تنظیمات بار تنبل که هنگام فراخوانی setConfig() مشخص نشده است از یک مقدار پیش فرض تعیین شده توسط Google استفاده می کند. این پیش فرض ها ممکن است با گذشت زمان تنظیم شوند. برای غیرفعال کردن یک تنظیم خاص ، مقدار را روی 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 });

جاوا اسکریپت (میراث)

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

// Clear fetch margin only.
googletag.setConfig({
  lazyLoad: { fetchMarginPercent: null },
});

// Clear all lazy loading settings.
googletag.setConfig({ lazyLoad: null });

TypeScript

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

// Clear fetch margin only.
googletag.setConfig({
  lazyLoad: { fetchMarginPercent: null },
});

// Clear all lazy loading settings.
googletag.setConfig({ lazyLoad: null });
همچنین ببینید

مکان Optional

location ?: string
تنظیم موارد خط هدف جغرافیایی به مکان های جغرافیایی.
مثال

جاوا اسکریپت

// 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 });

TypeScript

// Geo-target line items to US postal code 10001.
googletag.setConfig({ location: "10001,US" });

// Clear the location setting.
googletag.setConfig({ location: null });
همچنین ببینید

PPS Optional

تنظیمات برای کنترل ناشر سیگنال ها (PPS) را ارائه داد.

درمان های حریم خصوصی Optional

privacyTreatments ?: PrivacyTreatmentsConfig
تنظیمات برای کنترل درمان های حریم خصوصی ناشر.

SafeFrame Optional

safeFrame ?: SafeFrameConfig
تنظیمات برای کنترل استفاده از SafeFrame در GPT.

مقادیر پیکربندی شده از طریق این تنظیم برای کلیه شکافهای تبلیغاتی در صفحه اعمال می شود. شکافهای تبلیغاتی فردی ممکن است این مقادیر را از طریق 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 });

جاوا اسکریپت (میراث)

// Force SafeFrame for all ads on the page.
googletag.setConfig({
  safeFrame: { forceSafeFrame: true },
});

// Configure SafeFrame to allow overlay expansion.
googletag.setConfig({
  safeFrame: { allowOverlayExpansion: true },
});

// Clear forceSafeFrame setting.
googletag.setConfig({
  safeFrame: { forceSafeFrame: null },
});

// Clear all SafeFrame settings.
googletag.setConfig({ safeFrame: null });

TypeScript

// Force SafeFrame for all ads on the page.
googletag.setConfig({
  safeFrame: { forceSafeFrame: true },
});

// Configure SafeFrame to allow overlay expansion.
googletag.setConfig({
  safeFrame: { allowOverlayExpansion: true },
});

// Clear forceSafeFrame setting.
googletag.setConfig({
  safeFrame: { forceSafeFrame: null },
});

// Clear all SafeFrame settings.
googletag.setConfig({ safeFrame: null });

SingLerequest Optional

singleRequest ?: boolean
تنظیم برای فعال یا غیرفعال کردن معماری درخواست تک (SRA).

هنگامی که SRA فعال شد ، تمام اسلات های تبلیغاتی تعریف شده قبل از یک تماس googletag.display یا pubadsservice.refresh در یک درخواست تبلیغی واحد قرار می گیرند. این مزایای عملکرد را فراهم می کند ، اما همچنین برای اطمینان از مشروبات الکلی و محرومیت های رقابتی نیز لازم است.

هنگامی که SRA غیرفعال است ، از هر شکاف تبلیغاتی به صورت جداگانه درخواست می شود. این رفتار پیش فرض GPT است.

این روش باید قبل از تماس با Googletag.Enableservice فراخوانی شود.
مثال

جاوا اسکریپت

// Enable Single Request Architecture.
googletag.setConfig({ singleRequest: true });

جاوا اسکریپت (میراث)

// Enable Single Request Architecture.
googletag.setConfig({ singleRequest: true });

TypeScript

// Enable Single Request Architecture.
googletag.setConfig({ singleRequest: true });
همچنین ببینید

هدف گیری Optional

targeting ?: Record < string , string | string [] >
تنظیم برای کنترل هدف گذاری ارزش کلید.

هدف قرار دادن پیکربندی شده از طریق این تنظیم برای کلیه شکافهای تبلیغاتی در صفحه اعمال می شود. این تنظیم ممکن است چندین بار نامیده شود تا چندین ارزش کلید هدفمند را تعریف کند ، یا مقادیر موجود را بازنویسی کند. کلیدهای هدفمند در حساب Google Ad Manager شما تعریف شده اند.
مثال

جاوا اسکریپت

// 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 } });

TypeScript

// Setting a single targeting key-value.
googletag.setConfig({ targeting: { interests: "sports" } });

// Setting multiple values for a single targeting key
googletag.setConfig({ targeting: { interests: ["sports", "music"] } });

// Setting multiple targeting key-values at once.
googletag.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } });

// Clearing a single targeting key.
googletag.setConfig({ targeting: { interests: null } });
همچنین ببینید

Threadyield Optional

threadYield ?: "DISABLED" | "ENABLED_ALL_SLOTS"
تنظیم برای کنترل اینکه آیا GPT باید هنگام درخواست و ارائه خلاقیت ، موضوع JS را به دست آورد.

GPT فقط برای مرورگرهایی که از برنامه ریزی Sepost.posttask یا Scheduler.Yield API پشتیبانی می کنند ، ارائه می دهد.

مقادیر پشتیبانی شده:
  • null (پیش فرض): GPT موضوع JS را برای شکافهای خارج از نمای ارائه می دهد.
  • ENABLED_ALL_SLOTS : GPT بدون در نظر گرفتن اینکه شکاف در نمای است ، موضوع JS را برای همه شکاف ها به دست می آورد.
  • DISABLED : GPT موضوع JS را به همراه نخواهد داشت.
مثال

جاوا اسکریپت

// 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 });

TypeScript

// Disable yielding.
googletag.setConfig({ threadYield: "DISABLED" });

// Enable yielding for all slots.
googletag.setConfig({ threadYield: "ENABLED_ALL_SLOTS" });

// Enable yielding only for slots outside of the viewport (default).
googletag.setConfig({ threadYield: null });
همچنین ببینید

ویدیوهای Optional

videoAds ?: VideoAdsConfig
تنظیمات برای کنترل تبلیغات ویدیویی.
مثال

جاوا اسکریپت

// 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",
  },
});

TypeScript

// Enable video ads and set video content and content source IDs.
googletag.setConfig({
  videoAds: {
    enableVideoAds: true,
    videoContentId: "e1eGlRL7ju8",
    videoCmsId: "1234567",
  },
});
همچنین ببینید

googletag.config.PrivacyTreatmentsConfig

تنظیمات برای کنترل درمان های حریم خصوصی ناشر.
خواص
treatments
مجموعه ای از درمان های حریم خصوصی ناشر برای فعال کردن.

خواص


درمان ها

treatments : "disablePersonalization" []
مجموعه ای از درمان های حریم خصوصی ناشر برای فعال کردن.
مثال

جاوا اسکریپت

// Disable personalization across the entire page.
googletag.setConfig({
  privacyTreatments: { treatments: ["disablePersonalization"] },
});

جاوا اسکریپت (میراث)

// Disable personalization across the entire page.
googletag.setConfig({
  privacyTreatments: { treatments: ["disablePersonalization"] },
});

TypeScript

// Disable personalization across the entire page.
googletag.setConfig({
  privacyTreatments: { treatments: ["disablePersonalization"] },
});

googletag.config.PublisherProvideSignalSconfig

ناشر شیء سیگنال ها (PPS) را ارائه داد.
خواص
taxonomies
یک شیء حاوی نقشه های طبقه بندی یا تهی برای پاک کردن پیکربندی.
مثال

جاوا اسکریپت

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'
    },
  },
});

TypeScript

googletag.setConfig({
  pps: {
    taxonomies: {
      IAB_AUDIENCE_1_1: { values: ["6", "626"] },
      // '6' = 'Demographic | Age Range | 30-34'
      // '626' = 'Interest | Sports | Darts'
      IAB_CONTENT_2_2: { values: ["48", "127"] },
      // '48' = 'Books and Literature | Fiction'
      // '127' = 'Careers | Job Search'
    },
  },
});
همچنین ببینید

خواص


طبقه بندی

taxonomies : Partial < Record < Taxonomy , TaxonomyData > >
یک شیء حاوی نقشه های طبقه بندی یا تهی برای پاک کردن پیکربندی.

googletag.config.safeframeConfig

تنظیمات برای کنترل SafeFrame در GPT.
خواص
allow Overlay Expansion ?
این که آیا SafeFrame باید با پوشش محتوای صفحه ، محتوای تبلیغ را گسترش دهد.
allow Push Expansion ?
این که آیا SafeFrame باید با فشار دادن محتوای صفحه ، محتوای تبلیغ را گسترش دهد.
force Safe Frame ?
این که آیا AD (ها) باید با استفاده از یک ظرف Safeframe مجبور به ارائه شوند.
sandbox ?
این که آیا SafeFrame باید از ویژگی HTML5 Sandbox برای جلوگیری از پیمایش سطح بالا و بدون تعامل کاربر استفاده کند.
use Unique Domain ?
منسوخ شده است. این که آیا SafeFrame باید از زیر دامنه های تصادفی برای خلاقیت های رزرو استفاده کند.
همچنین ببینید

خواص


AllowOverlayExpansion Optional

allowOverlayExpansion ?: boolean
این که آیا SafeFrame باید با پوشش محتوای صفحه ، محتوای تبلیغ را گسترش دهد.

Optional AllowpushExpansion

allowPushExpansion ?: boolean
این که آیا SafeFrame باید با فشار دادن محتوای صفحه ، محتوای تبلیغ را گسترش دهد.

نیروهای Optional

forceSafeFrame ?: boolean
این که آیا AD (ها) باید با استفاده از یک ظرف Safeframe مجبور به ارائه شوند.

جعبه ماسه Optional

sandbox ?: boolean
این که آیا SafeFrame باید از ویژگی HTML5 Sandbox برای جلوگیری از پیمایش سطح بالا و بدون تعامل کاربر استفاده کند. تنها مقدار معتبر true است (نمی توان مجبور به false شد). توجه داشته باشید که ویژگی Sandbox افزونه ها را غیرفعال می کند (به عنوان مثال Flash).

استفاده Optional

useUniqueDomain ?: boolean
این که آیا SafeFrame باید از زیر دامنه های تصادفی برای خلاقیت های رزرو استفاده کند. برای پاک کردن مقدار ذخیره شده در null عبور کنید.

توجه: این ویژگی به طور پیش فرض فعال است.
همچنین ببینید

googletag.config.slotsettingsconfig

رابط اصلی پیکربندی برای تنظیمات سطح شکاف.

اجازه می دهد تا چندین ویژگی را با یک تماس API واحد برای یک شکاف واحد تنظیم کنید.

کلیه خصوصیات ذکر شده در زیر نمونه هایی هستند و ویژگی های واقعی استفاده از SetConfig را منعکس نمی کنند. برای مجموعه ویژگی ها ، زمینه های موجود در نوع slotsettingsconfig را در زیر مشاهده کنید.

مثال ها:
  • فقط ویژگی های مشخص شده در تماس slot.setConfig اصلاح شده است.
      const slot = googletag.defineSlot("/1234567/example", [160, 600]);
    
      // Configure feature alpha.
      slot.setConfig({
          alpha: {...}
      });
    
      // Configure feature bravo. Feature alpha is unchanged.
      slot.setConfig({
         bravo: {...}
      });
  • تمام تنظیمات برای یک ویژگی معین با هر تماس به Slot.SetConfig به روز می شود.
      // Configure feature charlie to echo = 1, foxtrot = true.
      slot.setConfig({
          charlie: {
              echo: 1,
              foxtrot: true,
          }
      });
    
      // Update feature charlie to echo = 2. Since foxtrot was not specified,
      // the value is cleared.
      slot.setConfig({
          charlie: {
              echo: 2
          }
      });
  • تمام تنظیمات یک ویژگی را می توان با عبور null پاک کرد.
      // Configure features delta, golf, and hotel.
      slot.setConfig({
          delta: {...},
          golf: {...},
          hotel: {...},
      });
    
      // Feature delta and hotel are cleared, but feature golf remains set.
      slot.setConfig({
          delta: null,
          hotel: null,
      });
خواص
ad Expansion ?
تنظیمات برای پیکربندی گسترش تبلیغ.
adsense Attributes ?
تنظیم برای پیکربندی ویژگی های AdSense.
category Exclusion ?
تنظیم برای پیکربندی استثناء دسته بندی تبلیغات.
click Url ?
تنظیم برای پیکربندی URL که کاربران پس از کلیک بر روی آگهی هدایت می شوند.
collapse Div ?
تنظیم برای پیکربندی رفتار فروپاشی شکاف آگهی.
component Auction ?
مجموعه ای از حراج های مؤلفه که در حراج تبلیغاتی در دستگاه قرار می گیرند.
interstitial ?
تنظیماتی که رفتار شکاف تبلیغاتی بینابینی را پیکربندی می کنند.
safe Frame ?
تنظیمات برای پیکربندی استفاده از SafeFrame در GPT.
targeting ?
تنظیم برای پیکربندی هدفگذاری ارزش کلید.

خواص


adexpansion Optional

adExpansion ?: AdExpansionConfig
تنظیمات برای پیکربندی گسترش تبلیغ.
همچنین ببینید

adsenseattributes Optional

adsenseAttributes ?: AdSenseAttributesConfig
تنظیم برای پیکربندی ویژگی های AdSense.

ویژگی های AdSense پیکربندی شده از طریق این تنظیم فقط در مورد شکاف AD اعمال می شود. این تنظیم ممکن است چندین بار نامیده شود تا مقادیر چند ویژگی را تعریف کند ، یا مقادیر موجود را بازنویسی کند.

تغییرات ویژگی AdSense فقط در مورد تبلیغات درخواست شده پس از فراخوانی این روش اعمال می شود. به همین دلیل ، توصیه می شود قبل از هرگونه تماس با googletag.display یا 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 });

جاوا اسکریپت (میراث)

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

// Set the AdSense ad format and channel IDs.
slot.setConfig({
  adsenseAttributes: {
    adsense_ad_format: "120x240_as",
    adsense_channel_ids: "271828183+314159265",
  },
});

// Clear the AdSense channel IDs only.
slot.setConfig({ adsenseAttributes: { adsense_channel_ids: null } });

// Clear all AdSense attributes.
slot.setConfig({ adsenseAttributes: null });

TypeScript

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

// Set the AdSense ad format and channel IDs.
slot.setConfig({
  adsenseAttributes: {
    adsense_ad_format: "120x240_as",
    adsense_channel_ids: "271828183+314159265",
  },
});

// Clear the AdSense channel IDs only.
slot.setConfig({ adsenseAttributes: { adsense_channel_ids: null } });

// Clear all AdSense attributes.
slot.setConfig({ adsenseAttributes: null });

دسته بندی Optional xclusion

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 });

جاوا اسکریپت (میراث)

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

// Label = AirlineAd
slot.setConfig({
  categoryExclusion: ["AirlineAd"],
});

// Clearing category exclusion setting.
slot.setConfig({ categoryExclusion: null });

TypeScript

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

// Label = AirlineAd
slot.setConfig({
  categoryExclusion: ["AirlineAd"],
});

// Clearing category exclusion setting.
slot.setConfig({ categoryExclusion: null });
همچنین ببینید

clickurl Optional

clickUrl ?: string
تنظیم برای پیکربندی URL که کاربران پس از کلیک بر روی آگهی هدایت می شوند.

سرورهای Google Ad Manager هنوز هم یک کلیک را ضبط می کنند حتی اگر URL کلیک جایگزین شود. هر URL صفحه فرود در ارتباط با خلاقیتی که ارائه می شود به مقدار ارائه شده اضافه می شود. تنظیم این مقدار بیش از یک بار ، هر مقدار قبلی پیکربندی شده را بازنویسی می کند. عبور در null مقدار را پاک می کند.

توجه: این تنظیم فقط در مورد درخواست های غیر SRA اعمال می شود.
مثال

جاوا اسکریپت

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,
});

جاوا اسکریپت (میراث)

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

// Sets the click URL to 'http://www.example.com?original_click_url='.
slot.setConfig({
  clickUrl: "http://www.example.com?original_click_url=",
});

// Clears the click URL.
slot.setConfig({
  clickUrl: null,
});

TypeScript

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

// Sets the click URL to 'http://www.example.com?original_click_url='.
slot.setConfig({
  clickUrl: "http://www.example.com?original_click_url=",
});

// Clears the click URL.
slot.setConfig({
  clickUrl: null,
});

Optional فروپاشی

collapseDiv ?: "DISABLED" | "BEFORE_FETCH" | "ON_NO_FILL"
تنظیم برای پیکربندی رفتار فروپاشی شکاف آگهی.

یک شکاف تبلیغاتی فروپاشی هیچ فضایی در صفحه نمی گیرد.

مقادیر پشتیبانی شده:
  • null (پیش فرض): شکاف از بین نمی رود.
  • DISABLED : شکاف فروپاشی نخواهد کرد ، خواه یک تبلیغ بازگردانده شود یا خیر.
  • BEFORE_FETCH : شکاف شروع به فروپاشی می کند و هنگام بازگشت یک تبلیغ گسترش می یابد.
  • ON_NO_FILL : شکاف شروع می شود و در صورت عدم بازگشت تبلیغ ، فروپاشی می شود.
مثال

جاوا اسکریپت

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,
});

جاوا اسکریپت (میراث)

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

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

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

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

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

TypeScript

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

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

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

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

// Clear the collapse setting.
slot.setConfig({
  collapseDiv: null,
});
همچنین ببینید

مؤلفه Optional

componentAuction ?: ComponentAuctionConfig []
مجموعه ای از حراج های مؤلفه که در حراج تبلیغاتی در دستگاه قرار می گیرند.

بینابینی Optional

interstitial ?: InterstitialConfig
تنظیماتی که رفتار شکاف تبلیغاتی بینابینی را پیکربندی می کنند.
همچنین ببینید

SafeFrame Optional

safeFrame ?: SafeFrameConfig
تنظیمات برای پیکربندی استفاده از SafeFrame در GPT.

مقادیر پیکربندی شده از طریق این تنظیم فقط برای شکاف AD اعمال می شود و مقادیر را که از طریق 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 });

جاوا اسکریپت (میراث)

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

// Force SafeFrame for the slot.
slot.setConfig({
  safeFrame: { forceSafeFrame: true },
});

// Configure SafeFrame to allow overlay expansion for the slot.
slot.setConfig({
  safeFrame: { allowOverlayExpansion: true },
});

// Clear forceSafeFrame setting for the slot.
slot.setConfig({
  safeFrame: { forceSafeFrame: null },
});

// Clear all SafeFrame settings for the slot.
slot.setConfig({ safeFrame: null });

TypeScript

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

// Force SafeFrame for the slot.
slot.setConfig({
  safeFrame: { forceSafeFrame: true },
});

// Configure SafeFrame to allow overlay expansion for the slot.
slot.setConfig({
  safeFrame: { allowOverlayExpansion: true },
});

// Clear forceSafeFrame setting for the slot.
slot.setConfig({
  safeFrame: { forceSafeFrame: null },
});

// Clear all SafeFrame settings for the slot.
slot.setConfig({ safeFrame: null });

هدف گیری Optional

targeting ?: Record < string , string | string [] >
تنظیم برای پیکربندی هدفگذاری ارزش کلید.

هدف قرار دادن پیکربندی شده از طریق این تنظیم فقط در شکاف AD اعمال می شود. این تنظیم ممکن است چندین بار نامیده شود تا چندین ارزش کلید هدفمند را تعریف کند ، یا مقادیر موجود را بازنویسی کند. کلیدهای هدفمند در حساب Google Ad Manager شما تعریف شده اند.
مثال

جاوا اسکریپت

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 });

جاوا اسکریپت (میراث)

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

// Setting a single targeting key-value.
slot.setConfig({ targeting: { interests: "sports" } });

// Setting multiple values for a single targeting key.
slot.setConfig({ targeting: { interests: ["sports", "music"] } });

// Setting multiple targeting key-values at once.
slot.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } });

// Clearing a single targeting key.
slot.setConfig({ targeting: { interests: null } });

// Clear all targeting keys.
slot.setConfig({ targeting: null });

TypeScript

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

// Setting a single targeting key-value.
slot.setConfig({ targeting: { interests: "sports" } });

// Setting multiple values for a single targeting key.
slot.setConfig({ targeting: { interests: ["sports", "music"] } });

// Setting multiple targeting key-values at once.
slot.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } });

// Clearing a single targeting key.
slot.setConfig({ targeting: { interests: null } });

// Clear all targeting keys.
slot.setConfig({ targeting: null });
همچنین ببینید

googletag.config.taxonomydata

یک شیء حاوی مقادیر برای یک طبقه بندی واحد.
خواص
values
لیستی از ارزشهای طبقه بندی .

خواص


ارزش ها

values : readonly string []
لیستی از ارزشهای طبقه بندی .

googletag.config.videoadsconfig

تنظیمات برای پیکربندی تنظیمات مربوط به آگهی ویدیویی.
خواص
enable Video Ads
آیا تبلیغات فیلم در صفحه حضور خواهد داشت.
video Cms Id ?
شناسه منبع محتوای ویدیویی.
video Content Id ?
شناسه محتوای ویدیویی.
همچنین ببینید

خواص


EnableVideoads

enableVideoAds : boolean
آیا تبلیغات فیلم در صفحه حضور خواهد داشت.

هنگامی که روی true تنظیم شده است ، این محدودیت های محرومیت محتوا را در تبلیغات نمایش و ویدیویی امکان پذیر می کند.

اگر محتوای ویدیویی شناخته شده است ، VideoContentID و VideoCMSID را بر روی مقادیر ارائه شده به سرویس مصرف محتوای Google Ad Manager برای استفاده از محرومیت محتوا برای تبلیغات نمایش تنظیم کنید.

VideoCmsid Optional

videoCmsId ?: string
شناسه منبع محتوای ویدیویی.

این یک مقدار منحصر به فرد است که توسط سرویس مصرف محتوای Google Ad Manager اختصاص داده شده است تا منبع محتوای ویدیویی مشخص شده توسط VideoContentID را شناسایی کند.
همچنین ببینید

VideoContentid Optional

videoContentId ?: string
شناسه محتوای ویدیویی.

این یک مقدار منحصر به فرد است که یک فیلم خاص را از منبع محتوا مشخص شده توسط VideoCMSID مشخص می کند. این مقدار توسط CMS که میزبان محتوای ویدیویی شما است اختصاص داده شده است.
همچنین ببینید

googletag.enums

این فضای نام است که GPT برای انواع enum استفاده می کند.
شمارش ها
Out Of Page Format
قالب های خارج از صفحه پشتیبانی شده توسط GPT.
Traffic Source
منابع ترافیکی پشتیبانی شده توسط GPT.

شمارش ها


پیش بینی

OutOfPageFormat
قالب های خارج از صفحه پشتیبانی شده توسط GPT.
همچنین ببینید
اعضای شمارش
BOTTOM_ ANCHOR
فرمت لنگر که در آن شکاف به پایین منظره می چسبد.
GAME_ MANUAL_ INTERSTITIAL
فرمت بازی دستی بازی.

توجه: کتابچه راهنمای بازی بینابینی یک قالب با دسترسی محدود است.
INTERSTITIAL
قالب خلاقانه بینابینی وب.
LEFT_ SIDE_ RAIL
قالب ریلی سمت چپ.
REWARDED
قالب پاداش
RIGHT_ SIDE_ RAIL
قالب ریلی سمت راست.
TOP_ ANCHOR
فرمت لنگر که در آن شکاف به بالای منظره می چسبد.

پیشخدمت

TrafficSource
منابع ترافیکی پشتیبانی شده توسط GPT.
همچنین ببینید
اعضای شمارش
ORGANIC
ورود مستقیم URL ، جستجوی سایت یا بارگیری برنامه.
PURCHASED
ترافیک از خواص غیر از متعلق به (فعالیت خریداری شده یا در غیر این صورت تحریک شده) هدایت می شود.

googletag.events

این فضای نام است که GPT برای رویدادها استفاده می کند. کد شما می تواند با استفاده از service.addeventlistener به این رویدادها واکنش نشان دهد.
رابط ها
Event
رابط پایه برای همه رویدادهای GPT.
Event Type Map
این یک نوع شبه است که یک نام رویداد را به نوع شیء رویداد مربوطه برای Service.AddeventListener و Service.RemoveEventListener ترسیم می کند.
Game Manual Interstitial Slot Closed Event
این رویداد هنگامی اخراج می شود که یک شکاف بینابینی دستی توسط کاربر بسته شده است.
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.
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

Base Interface for all GPT events. All GPT events below will have the following fields.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
همچنین ببینید

خواص


serviceName

serviceName : string
Name of the service that triggered the event.

شکاف

slot : Slot
The slot that triggered the event.

googletag.events.EventTypeMap

This is a pseudo-type that maps an event name to its corresponding event object type for Service.addEventListener and Service.removeEventListener . It is documented for reference and type safety purposes only.
خواص
game Manual Interstitial Slot Closed
game Manual Interstitial Slot Ready
impression Viewable
rewarded Slot Closed
rewarded Slot Granted
rewarded Slot Ready
slot Onload
slot Render Ended
slot Requested
slot Response Received
slot Visibility Changed

خواص


gameManualInterstitialSlotClosed


gameManualInterstitialSlotReady


impressionViewable

impressionViewable : ImpressionViewableEvent
Alias for events.ImpressionViewableEvent .

rewardedSlotClosed

rewardedSlotClosed : RewardedSlotClosedEvent
Alias for events.RewardedSlotClosedEvent .

rewardedSlotGranted

rewardedSlotGranted : RewardedSlotGrantedEvent
Alias for events.RewardedSlotGrantedEvent .

rewardedSlotReady

rewardedSlotReady : RewardedSlotReadyEvent
Alias for events.RewardedSlotReadyEvent .

slotOnload

slotOnload : SlotOnloadEvent
Alias for events.SlotOnloadEvent .

slotRenderEnded

slotRenderEnded : SlotRenderEndedEvent
Alias for events.SlotRenderEndedEvent .

slotRequested

slotRequested : SlotRequestedEvent
Alias for events.SlotRequestedEvent .

slotResponseReceived

slotResponseReceived : SlotResponseReceived
Alias for events.SlotResponseReceived .

slotVisibilityChanged


googletag.events.GameManualInterstitialSlotClosedEvent

Extends Event
This event is fired when a game manual interstitial slot has been closed by the user.

Note: Game manual interstitial is a limited-access format.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
    }
  });
}

TypeScript

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

googletag.events.GameManualInterstitialSlotReadyEvent

Extends Event
This event is fired when a game manual interstitial slot is ready to be shown to the user.

Note: Game manual interstitial is a limited-access format.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
روش ها
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.
    }
  });
}

TypeScript

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

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

روش ها


makeGameManualInterstitialVisible

makeGameManualInterstitialVisible ( ) : void
Displays the game manual interstitial ad to the user.

googletag.events.ImpressionViewableEvent

Extends Event
This event is fired when an impression becomes viewable, according to the Active View criteria .
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

googletag.events.RewardedSlotClosedEvent

Extends Event
This event is fired when a rewarded ad slot is closed by the user. It may fire either before or after a reward has been granted. To determine whether a reward has been granted, use events.RewardedSlotGrantedEvent instead.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

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.
    }
  });
}

TypeScript

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

googletag.events.RewardedSlotGrantedEvent

Extends Event
This event is fired when a reward is granted for viewing a rewarded ad . If the ad is closed before the criteria for granting a reward is met, this event will not fire.
خواص
payload
An object containing information about the reward that was granted.
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

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.
    }
  });
}

TypeScript

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

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

خواص


محموله

payload : RewardedPayload
An object containing information about the reward that was granted.

googletag.events.RewardedSlotReadyEvent

Extends Event
This event is fired when a rewarded ad is ready to be displayed. The publisher is responsible for presenting the user an option to view the ad before displaying it.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
روش ها
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.
    }
  });
}

TypeScript

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

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

روش ها


makeRewardedVisible

makeRewardedVisible ( ) : void
Displays the rewarded ad. This method should not be called until the user has consented to view the ad.

googletag.events.SlotOnloadEvent

Extends Event
This event is fired when the creative's iframe fires its load event. When rendering rich media ads in sync rendering mode, no iframe is used so no SlotOnloadEvent will be fired.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

googletag.events.SlotRenderEndedEvent

Extends Event
This event is fired when the creative code is injected into a slot. This event will occur before the creative's resources are fetched, so the creative may not be visible yet. If you need to know when all creative resources for a slot have finished loading, consider the events.SlotOnloadEvent instead.
خواص
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.
size
Indicates the pixel size of the rendered creative.
slot
The slot that triggered the event.
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.
  }
});

TypeScript

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

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

خواص


advertiserId

advertiserId : number
Advertiser ID of the rendered ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

شناسه کمپین

campaignId : number
Campaign ID of the rendered ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

companyIds

companyIds : number []
IDs of the companies that bid on the rendered backfill ad. Value is null for empty slots, reservation ads, and creatives rendered by services other than PubAdsService .

creativeId

creativeId : number
Creative ID of the rendered reservation ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

creativeTemplateId

creativeTemplateId : number
Creative template ID of the rendered reservation ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

isBackfill

isBackfill : boolean
Whether an ad was a backfill ad. Value is true if the ad was a backfill ad, false otherwise.

خالی است

isEmpty : boolean
Whether an ad was returned for the slot. Value is true if no ad was returned, false otherwise.

labelIds

labelIds : number []

lineItemId

lineItemId : number
Line item ID of the rendered reservation ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

responseIdentifier

responseIdentifier : string
The response identifier is a unique identifier for the ad response. This value can be used to identify and block the ad in the Ad Review Center (ARC) .

اندازه

size : string | number []
Indicates the pixel size of the rendered creative. Example: [728, 90] . Value is null for empty ad slots.

slotContentChanged

slotContentChanged : boolean
Whether the slot content was changed with the rendered ad. Value is true if the content was changed, false otherwise.

sourceAgnosticCreativeId

sourceAgnosticCreativeId : number
Creative ID of the rendered reservation or backfill ad. Value is null if the ad is not a reservation or line item backfill, or the creative is rendered by services other than PubAdsService .

sourceAgnosticLineItemId

sourceAgnosticLineItemId : number
Line item ID of the rendered reservation or backfill ad. Value is null if the ad is not a reservation or line item backfill, or the creative is rendered by services other than PubAdsService .

yieldGroupIds

yieldGroupIds : number []
IDs of the yield groups for the rendered backfill ad. Value is null for empty slots, reservation ads, and creatives rendered by services other than PubAdsService .

googletag.events.SlotRequestedEvent

Extends Event
This event is fired when an ad has been requested for a particular slot.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

googletag.events.SlotResponseReceived

Extends Event
This event is fired when an ad response has been received for a particular slot.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

googletag.events.SlotVisibilityChangedEvent

Extends Event
This event is fired whenever the on-screen percentage of an ad slot's area changes. The event is throttled and will not fire more often than once every 200ms.
خواص
in View Percentage
The percentage of the ad's area that is visible.
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

خواص


inViewPercentage

inViewPercentage : number
The percentage of the ad's area that is visible. Value is a number between 0 and 100.

googletag.secureSignals

This is the namespace that GPT uses for managing secure signals.
رابط ها
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.
Type Aliases
Secure Signal Provider
Interface for returning a secure signal for a specific bidder or provider.

Type Aliases


SecureSignalProvider

Interface for returning a secure signal for a specific bidder or provider. One of id or networkCode must be provided, but not both.

googletag.secureSignals.BidderSignalProvider

Returns a secure signal for a specific bidder.

A bidder secure signal provider consists of 2 parts:

  1. A collector function, which returns a Promise that resolves to a secure signal.
  2. An id which identifies the bidder associated with the signal.
To return a secure signal for a publisher, use secureSignals.PublisherSignalProvider instead.
خواص
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");
  },
});

TypeScript

// id is provided
googletag.secureSignalProviders!.push({
  id: "collector123",
  collectorFunction: () => {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});
همچنین ببینید

خواص


collectorFunction

collectorFunction : ( ( ) => Promise < string > )
A function which returns a Promise that resolves to a secure signal.

شناسه

id : string
A unique identifier for the collector associated with this secure signal, as registered in Google Ad Manager.

googletag.secureSignals.PublisherSignalProvider

Returns a secure signal for a specific publisher.

A publisher signal provider consists of 2 parts:

  1. A collector function, which returns a Promise that resolves to a secure signal.
  2. A networkCode which identifies the publisher associated with the signal.
To return a secure signal for a bidder, use secureSignals.BidderSignalProvider instead.
خواص
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");
  },
});

TypeScript

// networkCode is provided
googletag.secureSignalProviders!.push({
  networkCode: "123456",
  collectorFunction: () => {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});
همچنین ببینید

خواص


collectorFunction

collectorFunction : ( ( ) => Promise < string > )
A function which returns a Promise that resolves to a secure signal.

networkCode

networkCode : string
The network code (as seen in the ad unit path) for the publisher associated with this secure signal.

googletag.secureSignals.SecureSignalProvidersArray

An interface for managing secure signals.
روش ها
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 ( ) : void
Clears all signals for all collectors from cache.

Calling 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
Adds a new secureSignals.SecureSignalProvider to the signal provider array and begins the signal generation process.
پارامترها
provider : SecureSignalProvider The secureSignals.SecureSignalProvider object to be added to the array.
،

This reference uses TypeScript notation to describe types. The following table provides a brief explanation by example.

Type expression
string The primitive string type.
string[] An array type, where values may only be strings.
number | string A union type, where the value may be either a number or a string.
Array<number | string> An array type, where values are a complex (union) type.
[number, string] A tuple type, where the value is a two-element array that must contain a number and a string in that order.
Slot An object type, where the value is an instance of googletag.Slot .
() => void A function type with no defined arguments and no return value.

To learn more about supported types and type expressions, refer to the TypeScript Handbook .

Type annotations

A colon after a variable, parameter name, property name, or function signature denotes a type annotation. Type annotations describe the types the element to the left of the colon can accept or return. The following table shows examples of type annotations you may see in this reference.

Type annotation
param: string Indicates that param accepts or returns a string value. This syntax is used for variables, parameters, properties, and return types.
param?: number | string Indicates that param is optional, but accepts either a number or a string when specified. This syntax is used for parameters and properties.
...params: Array<() => void> Indicates that params is a rest parameter that accepts functions. Rest parameters accept an unbounded number of values of the specified type.

googletag

The global namespace the Google Publisher Tag uses for its API.
فضاهای نام
config
Main configuration interface for page-level settings.
enums
This is the namespace that GPT uses for enum types.
events
This is the namespace that GPT uses for Events.
secure Signals
This is the namespace that GPT uses for managing secure signals.
رابط ها
Command Array
The command array accepts a sequence of functions and invokes them in order.
Companion Ads Service
Companion Ads service.
Privacy Settings Config
Configuration object for privacy settings.
Pub Ads Service
Publisher Ads service.
Response Information
An object representing a single ad response.
Rewarded Payload
An object representing the reward associated with a rewarded ad .
Service
Base service class that contains methods common for all services.
Size Mapping Builder
Builder for size mapping specification objects.
Slot
Slot is an object representing a single ad slot on a page.
Type Aliases
General Size
A valid size configuration for a slot, which can be one or multiple sizes.
Multi Size
A list of single valid sizes.
Named Size
Named sizes that a slot can have.
Single Size
A single valid size for a slot.
Single Size Array
Array of two numbers representing [width, height].
Size Mapping
A mapping of viewport size to ad sizes.
Size Mapping Array
A list of size mappings.
متغیرها
api Ready
Flag indicating that the GPT API is loaded and ready to be called.
cmd
Reference to the global command queue for asynchronous execution of GPT-related calls.
pubads Ready
Flag indicating that PubAdsService is enabled, loaded and fully operational.
secure Signal Providers
Reference to the secure signal providers array.
توابع
companion Ads
Returns a reference to the CompanionAdsService .
define Out Of Page Slot
Constructs an out-of-page ad slot with the given ad unit path.
define Slot
Constructs an ad slot with a given ad unit path and size and associates it with the ID of a div element on the page that will contain the ad.
destroy Slots
Destroys the given slots, removing all related objects and references of those slots from GPT.
disable Publisher Console
Disables the Google Publisher Console.
display
Instructs slot services to render the slot.
enable Services
Enables all GPT services that have been defined for ad slots on the page.
get Config
Gets general configuration options for the page set by setConfig .
get Version
Returns the current version of GPT.
open Console
Opens the Google Publisher Console.
pubads
Returns a reference to the PubAdsService .
set Ad Iframe Title
Sets the title for all ad container iframes created by PubAdsService , from this point onwards.
set Config
Sets general configuration options for the page.
size Mapping
Creates a new SizeMappingBuilder .

Type Aliases


GeneralSize

GeneralSize : SingleSize | MultiSize
A valid size configuration for a slot, which can be one or multiple sizes.

MultiSize

MultiSize : SingleSize []
A list of single valid sizes.

NamedSize

NamedSize : "fluid" | [ "fluid" ]
Named sizes that a slot can have. In most cases size is a fixed-size rectangle but there are some cases when we need other kinds of size specifications. Only the following are valid named sizes:
  • fluid : the ad container takes 100% width of parent div and then resizes its height to fit creative content. Similar to how regular block elements on a page behave. Used for native ads (see related article ). Note that both fluid and ['fluid'] are acceptable forms to declare a slot size as fluid.

SingleSize

SingleSize : SingleSizeArray | NamedSize
A single valid size for a slot.

SingleSizeArray

SingleSizeArray : [ number , number ]
Array of two numbers representing [width, height].

SizeMapping

SizeMapping : [ SingleSizeArray , GeneralSize ]
A mapping of viewport size to ad sizes. Used for responsive ads.

SizeMappingArray

SizeMappingArray : SizeMapping []
A list of size mappings.

متغیرها


Const apiReady

apiReady : boolean | undefined
Flag indicating that the GPT API is loaded and ready to be called. This property will be simply undefined until the API is ready.

Note that the recommended way of handling async is to use googletag.cmd to queue callbacks for when GPT is ready. These callbacks do not have to check googletag.apiReady as they are guaranteed to execute once the API is set up.

Const cmd

cmd : ( ( this : typeof globalThis ) => void ) [] | CommandArray
Reference to the global command queue for asynchronous execution of GPT-related calls.

The googletag.cmd variable is initialized to an empty JavaScript array by the GPT tag syntax on the page, and cmd.push is the standard Array.push method that adds an element to the end of the array. When the GPT JavaScript is loaded, it looks through the array and executes all the functions in order. The script then replaces cmd with a CommandArray object whose push method is defined to execute the function argument passed to it. This mechanism allows GPT to reduce perceived latency by fetching the JavaScript asynchronously while allowing the browser to continue rendering the page.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

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

Const pubadsReady

pubadsReady : boolean | undefined
Flag indicating that PubAdsService is enabled, loaded and fully operational. This property will be simply undefined until enableServices is called and PubAdsService is loaded and initialized.

secureSignalProviders

secureSignalProviders : SecureSignalProvider [] | SecureSignalProvidersArray | undefined
Reference to the secure signal providers array.

The secure signal providers array accepts a sequence of signal-generating functions and invokes them in order. It is intended to replace a standard array that is used to enqueue signal-generating functions to be invoked once GPT is loaded.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

window.googletag = window.googletag || { cmd: [] };
googletag.secureSignalProviders = googletag.secureSignalProviders || [];
googletag.secureSignalProviders.push({
  id: "collector123",
  collectorFunction: () => {
    return Promise.resolve("signal");
  },
});
همچنین ببینید

توابع


companionAds

companionAds ( ) : CompanionAdsService
Returns a reference to the CompanionAdsService .
برمی گرداند
CompanionAdsService The Companion Ads service.

defineOutOfPageSlot

defineOutOfPageSlot ( adUnitPath : string , div ?: string | OutOfPageFormat ) : Slot | null
Constructs an out-of-page ad slot with the given ad unit path.

For custom out-of-page ads, div is the ID of the div element that will contain the ad. See the article on out-of-page creatives for more details.

For GPT managed out-of-page ads, div is a supported 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);

JavaScript (legacy)

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

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

TypeScript

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

// Define a GPT managed web interstitial ad slot.
googletag.defineOutOfPageSlot("/1234567/sports", googletag.enums.OutOfPageFormat.INTERSTITIAL);
همچنین ببینید
پارامترها
adUnitPath : string Full ad unit path with the network code and ad unit code.
Optional div : string | OutOfPageFormat ID of the div that will contain this ad unit or OutOfPageFormat.
برمی گرداند
Slot | null The newly created slot, or null if a slot cannot be created.

defineSlot

defineSlot ( adUnitPath : string , size : GeneralSize , div ?: string ) : Slot | null
Constructs an ad slot with a given ad unit path and size and associates it with the ID of a div element on the page that will contain the ad.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
همچنین ببینید
پارامترها
adUnitPath : string Full ad unit path with the network code and unit code.
size : GeneralSize Width and height of the added slot. This is the size that is used in the ad request if no responsive size mapping is provided or the size of the viewport is smaller than the smallest size provided in the mapping.
Optional div : string ID of the div that will contain this ad unit.
برمی گرداند
Slot | null The newly created slot, or null if a slot cannot be created.

destroySlots

destroySlots ( slots ?: Slot [] ) : boolean
Destroys the given slots, removing all related objects and references of those slots from GPT. This API does not support passback slots and companion slots.

Calling this API on a slot clears the ad and removes the slot object from the internal state maintained by GPT. Calling any more functions on the slot object will result in undefined behavior. Note the browser may still not free the memory associated with that slot if a reference to it is maintained by the publisher page. Calling this API makes the div associated with that slot available for reuse.

In particular, destroying a slot removes the ad from GPT's long-lived pageview , so future requests will not be influenced by roadblocks or competitive exclusions involving this ad. Failure to call this function before removing a slot's div from the page will result in undefined behavior.
مثال

جاوا اسکریپت

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

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

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

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

JavaScript (legacy)

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

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

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

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

TypeScript

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

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

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

// This call to destroy all slots.
googletag.destroySlots();
پارامترها
Optional slots : Slot [] The array of slots to destroy. Array is optional; all slots will be destroyed if it is unspecified.
برمی گرداند
boolean true if slots have been destroyed, false otherwise.

disablePublisherConsole

disablePublisherConsole ( ) : void
Disables the Google Publisher Console.
همچنین ببینید

نمایش داده شود

display ( divOrSlot : string | Element | Slot ) : void
Instructs slot services to render the slot. Each ad slot should only be displayed once per page. All slots must be defined and have a service associated with them before being displayed. The display call must not happen until the element is present in the DOM. The usual way to achieve that is to place it within a script block within the div element named in the method call.

If single request architecture (SRA) is being used, all unfetched ad slots at the time this method is called will be fetched at once. To force an ad slot not to display, the entire div must be removed.
همچنین ببینید
پارامترها
divOrSlot : string | Element | Slot Either the ID of the div element containing the ad slot or the div element, or the slot object. If a div element is provided, it must have an 'id' attribute which matches the ID passed into defineSlot .

enableServices

enableServices ( ) : void
Enables all GPT services that have been defined for ad slots on the page.

getConfig

getConfig ( keys : string | string [] ) : Pick < PageSettingsConfig , "adsenseAttributes" | "disableInitialLoad" | "targeting" >
Gets general configuration options for the page set by setConfig .

Not all setConfig() properties are supported by this method. Supported properties are:
مثال

جاوا اسکریپت

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

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

JavaScript (legacy)

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

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

TypeScript

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

// Get the value of the `adsenseAttributes` and `disableInitialLoad` settings.
const config = googletag.getConfig(["adsenseAttributes", "disableInitialLoad"]);
پارامترها
keys : string | string [] The keys of the configuration options to get.
برمی گرداند
Pick < PageSettingsConfig , "adsenseAttributes" | "disableInitialLoad" | "targeting" > The configuration options for the slot.

getVersion

getVersion ( ) : string
Returns the current version of GPT.
همچنین ببینید
برمی گرداند
string The currently executing GPT version string.

openConsole

openConsole ( div ?: string ) : void
Opens the Google Publisher Console.
مثال

جاوا اسکریپت

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

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

JavaScript (legacy)

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

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

TypeScript

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

// Calling without div ID.
googletag.openConsole();
همچنین ببینید
پارامترها
Optional div : string An ad slot div ID. This value is optional. When provided, the Publisher Console will attempt to open with details of the specified ad slot in view.

pubads

pubads ( ) : PubAdsService
Returns a reference to the PubAdsService .
برمی گرداند
PubAdsService The Publisher Ads service.

setAdIframeTitle

setAdIframeTitle ( title : string ) : void
Sets the title for all ad container iframes created by PubAdsService , from this point onwards.
مثال

جاوا اسکریپت

googletag.setAdIframeTitle("title");

JavaScript (legacy)

googletag.setAdIframeTitle("title");

TypeScript

googletag.setAdIframeTitle("title");
پارامترها
title : string The new title for all ad container iframes.

setConfig

setConfig ( config : PageSettingsConfig ) : void
Sets general configuration options for the page.
پارامترها
config : PageSettingsConfig

sizeMapping

sizeMapping ( ) : SizeMappingBuilder
Creates a new SizeMappingBuilder .
همچنین ببینید
برمی گرداند
SizeMappingBuilder A new builder.

googletag.CommandArray

The command array accepts a sequence of functions and invokes them in order. It is intended to replace a standard array that is used to enqueue functions to be invoked once GPT is loaded.
روش ها
push
Executes the sequence of functions specified in the arguments in order.

روش ها


فشار دهید

push ( ... f : ( ( this : typeof globalThis ) => void ) [] ) : number
Executes the sequence of functions specified in the arguments in order.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

googletag.cmd.push(() => {
  googletag.defineSlot("/1234567/sports", [160, 600])!.addService(googletag.pubads());
});
پارامترها
Rest ... f : ( ( this : typeof globalThis ) => void ) [] A JavaScript function to be executed. The runtime binding will always be globalThis . Consider passing an arrow function to retain the this value of the enclosing lexical context.
برمی گرداند
number The number of commands processed so far. This is compatible with Array.push 's return value (the current length of the array).

googletag.CompanionAdsService

Extends Service
Companion Ads service. This service is used by video ads to show companion ads.
روش ها
add Event Listener
Registers a listener that allows you to set up and call a JavaScript function when a specific GPT event happens on the page.
get Slots
Get the list of slots associated with this service.
remove Event Listener
Removes a previously registered listener.
set Refresh Unfilled Slots
Sets whether companion slots that have not been filled will be automatically backfilled.
همچنین ببینید

روش ها


setRefreshUnfilledSlots

setRefreshUnfilledSlots ( value : boolean ) : void
Sets whether companion slots that have not been filled will be automatically backfilled.

This method can be called multiple times during the page's lifetime to turn backfill on and off. Only slots that are also registered with the PubAdsService will be backfilled. Due to policy restrictions, this method is not designed to fill empty companion slots when an Ad Exchange video is served.
مثال

جاوا اسکریپت

googletag.companionAds().setRefreshUnfilledSlots(true);

JavaScript (legacy)

googletag.companionAds().setRefreshUnfilledSlots(true);

TypeScript

googletag.companionAds().setRefreshUnfilledSlots(true);
پارامترها
value : boolean true to automatically backfill unfilled slots, false to leave them unchanged.

googletag.PrivacySettingsConfig

Configuration object for privacy settings.
خواص
child Directed Treatment ?
Indicates whether the page should be treated as child-directed .
limited Ads ?
Enables serving to run in limited ads mode to aid in publisher regulatory compliance needs.
non Personalized Ads ?
Enables serving to run in non-personalized ads mode to aid in publisher regulatory compliance needs.
restrict Data Processing ?
Enables serving to run in restricted processing mode to aid in publisher regulatory compliance needs.
traffic Source ?
Indicates whether requests represent purchased or organic traffic.
under Age Of Consent ?
Indicates whether to mark ad requests as coming from users under the age of consent .
همچنین ببینید

خواص


Optional childDirectedTreatment

childDirectedTreatment ?: boolean
Indicates whether the page should be treated as child-directed . Set to null to clear the configuration.

Optional limitedAds

limitedAds ?: boolean
Enables serving to run in limited ads mode to aid in publisher regulatory compliance needs.

You can instruct GPT to request limited ads in two ways:
  • Automatically, by using a signal from an IAB TCF v2.0 consent management platform.
  • Manually, by setting the value of this field to true .
Manually configuring limited ads is only possible when GPT is loaded from the limited ads URL . Attempting to modify this setting when GPT has been loaded from the standard URL will generate a Publisher Console warning .

Note that it is not necessary to manually enable limited ads when a CMP is in use.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

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

Optional nonPersonalizedAds

nonPersonalizedAds ?: boolean
Enables serving to run in non-personalized ads mode to aid in publisher regulatory compliance needs.

Optional restrictDataProcessing

restrictDataProcessing ?: boolean
Enables serving to run in restricted processing mode to aid in publisher regulatory compliance needs.

Optional trafficSource

trafficSource ?: TrafficSource
Indicates whether requests represent purchased or organic traffic. This value populates the Traffic source dimension in Ad Manager reporting. If not set, traffic source defaults to undefined in reporting.
مثال

جاوا اسکریپت

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

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

JavaScript (legacy)

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

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

TypeScript

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

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

Optional underAgeOfConsent

underAgeOfConsent ?: boolean
Indicates whether to mark ad requests as coming from users under the age of consent . Set to null to clear the configuration.

googletag.PubAdsService

Extends Service
Publisher Ads service. This service is used to fetch and show ads from your Google Ad Manager account.
روش ها
add Event Listener
Registers a listener that allows you to set up and call a JavaScript function when a specific GPT event happens on the page.
clear
Removes the ads from the given slots and replaces them with blank content.
clear Category Exclusions
منسوخ شده است. Clears all page-level ad category exclusion labels.
clear Targeting
منسوخ شده است. Clears custom targeting parameters for a specific key or for all keys.
collapse Empty Divs
منسوخ شده است. Enables collapsing of slot divs so that they don't take up any space on the page when there is no ad content to display.
disable Initial Load
منسوخ شده است. Disables requests for ads on page load, but allows ads to be requested with a PubAdsService.refresh call.
display
Constructs and displays an ad slot with the given ad unit path and size.
enable Lazy Load
منسوخ شده است. Enables lazy loading in GPT as defined by the config object.
enable Single Request
منسوخ شده است. Enables single request mode for fetching multiple ads at the same time.
enable Video Ads
منسوخ شده است. Signals to GPT that video ads will be present on the page.
get
منسوخ شده است. Returns the value for the AdSense attribute associated with the given key.
get Attribute Keys
منسوخ شده است. Returns the attribute keys that have been set on this service.
get Slots
Get the list of slots associated with this service.
get Targeting
منسوخ شده است. Returns a specific custom service-level targeting parameter that has been set.
get Targeting Keys
منسوخ شده است. Returns the list of all custom service-level targeting keys that have been set.
is Initial Load Disabled
منسوخ شده است. Returns whether or not initial requests for ads was successfully disabled by a previous PubAdsService.disableInitialLoad call.
refresh
Fetches and displays new ads for specific or all slots on the page.
remove Event Listener
Removes a previously registered listener.
set
منسوخ شده است. Sets values for AdSense attributes that apply to all ad slots under the Publisher Ads service.
set Category Exclusion
منسوخ شده است. Sets a page-level ad category exclusion for the given label name.
set Centering
منسوخ شده است. Enables and disables horizontal centering of ads.
set Force Safe Frame
منسوخ شده است. Configures whether all ads on the page should be forced to be rendered using a SafeFrame container.
set Location
منسوخ شده است. Passes location information from websites so you can geo-target line items to specific locations.
set Privacy Settings
Allows configuration of all privacy settings from a single API using a config object.
set Publisher Provided Id
Sets the value for the publisher-provided ID.
set Safe Frame Config
منسوخ شده است. Sets the page-level preferences for SafeFrame configuration.
set Targeting
منسوخ شده است. Sets custom targeting parameters for a given key that apply to all Publisher Ads service ad slots.
set Video Content
منسوخ شده است. Sets the video content information to be sent along with the ad requests for targeting and content exclusion purposes.
update Correlator
Changes the correlator that is sent with ad requests, effectively starting a new page view.

روش ها


روشن

clear ( slots ?: Slot [] ) : boolean
Removes the ads from the given slots and replaces them with blank content. The slots will be marked as unfetched.

In particular, clearing a slot removes the ad from GPT's long-lived pageview , so future requests will not be influenced by roadblocks or competitive exclusions involving this ad.
مثال

جاوا اسکریپت

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to clear only slot1.
googletag.pubads().clear([slot1]);

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

// This call to clear all slots.
googletag.pubads().clear();

JavaScript (legacy)

var slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
var slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to clear only slot1.
googletag.pubads().clear([slot1]);

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

// This call to clear all slots.
googletag.pubads().clear();

TypeScript

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!;
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!;
googletag.display("div-2");

// This call to clear only slot1.
googletag.pubads().clear([slot1]);

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

// This call to clear all slots.
googletag.pubads().clear();
پارامترها
Optional slots : Slot [] The array of slots to clear. Array is optional; all slots will be cleared if it is unspecified.
برمی گرداند
boolean Returns true if slots have been cleared, false otherwise.

clearCategoryExclusions

clearCategoryExclusions ( ) : PubAdsService
Clears all page-level ad category exclusion labels. This is useful if you want to refresh the slot.
مثال

جاوا اسکریپت

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

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

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

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

JavaScript (legacy)

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

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

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

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

TypeScript

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

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

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

// Make ad requests. Any ad can be returned.
همچنین ببینید
برمی گرداند
PubAdsService The service object on which the method was called.

clearTargeting

clearTargeting ( key ?: string ) : PubAdsService
Clears custom targeting parameters for a specific key or for all keys.
مثال

جاوا اسکریپت

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

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

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

JavaScript (legacy)

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

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

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

TypeScript

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

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

googletag.pubads().clearTargeting();
// All targeting has been cleared.
همچنین ببینید
پارامترها
Optional key : string Targeting parameter key. The key is optional; all targeting parameters will be cleared if it is unspecified.
برمی گرداند
PubAdsService The service object on which the method was called.

collapseEmptyDivs

collapseEmptyDivs ( collapseBeforeAdFetch ?: boolean ) : boolean
Enables collapsing of slot divs so that they don't take up any space on the page when there is no ad content to display. This mode must be set before the service is enabled.
همچنین ببینید
پارامترها
Optional collapseBeforeAdFetch : boolean Whether to collapse the slots even before the ads are fetched. This parameter is optional; if not provided, false will be used as the default value.
برمی گرداند
boolean Returns true if div collapse mode was enabled and false if it is impossible to enable collapse mode because the method was called after the service was enabled.

disableInitialLoad

disableInitialLoad ( ) : void
Disables requests for ads on page load, but allows ads to be requested with a PubAdsService.refresh call. This should be set prior to enabling the service. Async mode must be used; otherwise it will be impossible to request ads using refresh .
همچنین ببینید

نمایش داده شود

display ( adUnitPath : string , size : GeneralSize , div ?: string | Element , clickUrl ?: string ) : void
Constructs and displays an ad slot with the given ad unit path and size. This method does not work with single request mode.

Note: When this method is called, a snapshot of the slot and page state is created to ensure consistency when sending the ad request and rendering the response. Any changes that are made to the slot or page state after this method is called (including targeting, privacy settings, force SafeFrame, etc.) will only apply to subsequent display() or refresh() requests.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

googletag.pubads().display("/1234567/sports", [728, 90], "div-1");
همچنین ببینید
پارامترها
adUnitPath : string The ad unit path of slot to be rendered.
size : GeneralSize Width and height of the slot.
Optional div : string | Element Either the ID of the div containing the slot or the div element itself.
Optional clickUrl : string The click URL to use on this slot.

enableLazyLoad

enableLazyLoad ( config ?: {
  fetchMarginPercent ?: number ;
  mobileScaling ?: number ;
  renderMarginPercent ?: number ;
} ) : void
Enables lazy loading in GPT as defined by the config object. For more detailed examples, see the Lazy loading sample.

Note: Lazy fetching in SRA only works if all slots are outside the fetching margin.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

googletag.pubads().enableLazyLoad({
  // Fetch slots within 5 viewports.
  fetchMarginPercent: 500,
  // Render slots within 2 viewports.
  renderMarginPercent: 200,
  // Double the above values on mobile.
  mobileScaling: 2.0,
});
همچنین ببینید
پارامترها
Optional config : {
  fetchMarginPercent ?: number ;
  mobileScaling ?: number ;
  renderMarginPercent ?: number ;
}
Configuration object allows customization of lazy behavior. Any omitted configurations will use a default set by Google that will be tuned over time. To disable a particular setting, such as a fetching margin, set the value to -1 .
  • fetchMarginPercent

    The minimum distance from the current viewport a slot must be before we fetch the ad as a percentage of viewport size. A value of 0 means "when the slot enters the viewport", 100 means "when the ad is 1 viewport away", and so on.
  • renderMarginPercent

    The minimum distance from the current viewport a slot must be before we render an ad. This allows for prefetching the ad, but waiting to render and download other subresources. The value works just like fetchMarginPercent as a percentage of viewport.
  • mobileScaling

    A multiplier applied to margins on mobile devices. This allows varying margins on mobile vs. desktop. For example, a value of 2.0 will multiply all margins by 2 on mobile devices, increasing the minimum distance a slot can be before fetching and rendering.

enableSingleRequest

enableSingleRequest ( ) : boolean
Enables single request mode for fetching multiple ads at the same time. This requires all Publisher Ads slots to be defined and added to the PubAdsService prior to enabling the service. Single request mode must be set before the service is enabled.
همچنین ببینید
برمی گرداند
boolean Returns true if single request mode was enabled and false if it is impossible to enable single request mode because the method was called after the service was enabled.

enableVideoAds

enableVideoAds ( ) : void
Signals to GPT that video ads will be present on the page. This enables competitive exclusion constraints on display and video ads. If the video content is known, call PubAdsService.setVideoContent in order to be able to use content exclusion for display ads.

دریافت کنید

get ( key : string ) : string
Returns the value for the AdSense attribute associated with the given key.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().get("adsense_background_color");
// Returns '#FFFFFF'.
همچنین ببینید
پارامترها
key : string Name of the attribute to look for.
برمی گرداند
string Current value for the attribute key, or null if the key is not present.

getAttributeKeys

getAttributeKeys ( ) : string []
Returns the attribute keys that have been set on this service.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
googletag.pubads().set("adsense_border_color", "#AABBCC");
googletag.pubads().getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].
برمی گرداند
string [] Array of attribute keys set on this service. Ordering is undefined.

getTargeting

getTargeting ( key : string ) : string []
Returns a specific custom service-level targeting parameter that has been set.
مثال

جاوا اسکریپت

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

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

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

JavaScript (legacy)

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

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

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

TypeScript

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

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

googletag.pubads().getTargeting("age");
// Returns [] (empty array).
پارامترها
key : string 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 []
Returns the list of all custom service-level targeting keys that have been set.
مثال

جاوا اسکریپت

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

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

JavaScript (legacy)

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

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

TypeScript

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

googletag.pubads().getTargetingKeys();
// Returns ['interests', 'colors'].
برمی گرداند
string [] Array of targeting keys. Ordering is undefined.

isInitialLoadDisabled

isInitialLoadDisabled ( ) : boolean
Returns whether or not initial requests for ads was successfully disabled by a previous PubAdsService.disableInitialLoad call.
برمی گرداند
boolean Returns true if a previous call to PubAdsService.disableInitialLoad was successful, false otherwise.

تازه کردن

refresh ( slots ?: Slot [] , options ?: {
  changeCorrelator : boolean ;
} ) : void
Fetches and displays new ads for specific or all slots on the page. Works only in asynchronous rendering mode.

For proper behavior across all browsers, calling refresh must be preceded by a call to display the ad slot. If the call to display is omitted, refresh may behave unexpectedly. If desired, the PubAdsService.disableInitialLoad method can be used to stop display from fetching an ad.

Refreshing a slot removes the old ad from GPT's long-lived pageview , so future requests will not be influenced by roadblocks or competitive exclusions involving that ad.
مثال

جاوا اسکریپت

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to refresh fetches a new ad for slot1 only.
googletag.pubads().refresh([slot1]);

// This call to refresh fetches a new ad for both slot1 and slot2.
googletag.pubads().refresh([slot1, slot2]);

// This call to refresh fetches a new ad for each slot.
googletag.pubads().refresh();

// This call to refresh fetches a new ad for slot1, without changing
// the correlator.
googletag.pubads().refresh([slot1], { changeCorrelator: false });

// This call to refresh fetches a new ad for each slot, without
// changing the correlator.
googletag.pubads().refresh(null, { changeCorrelator: false });

JavaScript (legacy)

var slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1");
googletag.display("div-1");
var slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2");
googletag.display("div-2");

// This call to refresh fetches a new ad for slot1 only.
googletag.pubads().refresh([slot1]);

// This call to refresh fetches a new ad for both slot1 and slot2.
googletag.pubads().refresh([slot1, slot2]);

// This call to refresh fetches a new ad for each slot.
googletag.pubads().refresh();

// This call to refresh fetches a new ad for slot1, without changing
// the correlator.
googletag.pubads().refresh([slot1], { changeCorrelator: false });

// This call to refresh fetches a new ad for each slot, without
// changing the correlator.
googletag.pubads().refresh(null, { changeCorrelator: false });

TypeScript

const slot1 = googletag.defineSlot("/1234567/sports", [728, 90], "div-1")!;
googletag.display("div-1");
const slot2 = googletag.defineSlot("/1234567/news", [160, 600], "div-2")!;
googletag.display("div-2");

// This call to refresh fetches a new ad for slot1 only.
googletag.pubads().refresh([slot1]);

// This call to refresh fetches a new ad for both slot1 and slot2.
googletag.pubads().refresh([slot1, slot2]);

// This call to refresh fetches a new ad for each slot.
googletag.pubads().refresh();

// This call to refresh fetches a new ad for slot1, without changing
// the correlator.
googletag.pubads().refresh([slot1], { changeCorrelator: false });

// This call to refresh fetches a new ad for each slot, without
// changing the correlator.
googletag.pubads().refresh(null, { changeCorrelator: false });
همچنین ببینید
پارامترها
Optional slots : Slot [] The slots to refresh. Array is optional; all slots will be refreshed if it is unspecified.
Optional options : {
  changeCorrelator : boolean ;
}
Configuration options associated with this refresh call.
  • changeCorrelator

    Specifies whether or not a new correlator is to be generated for fetching ads. Our ad servers maintain this correlator value briefly (currently for 30 seconds, but subject to change), such that requests with the same correlator received close together will be considered a single page view. By default a new correlator is generated for every refresh.

    Note: this option has no effect on GPT's long-lived pageview , which automatically reflects the ads currently on the page and has no expiration time.

مجموعه

set ( key : string , value : string ) : PubAdsService
Sets values for AdSense attributes that apply to all ad slots under the Publisher Ads service.

Calling this 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 .
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

googletag.pubads().set("adsense_background_color", "#FFFFFF");
همچنین ببینید
پارامترها
key : string The name of the attribute.
value : string Attribute value.
برمی گرداند
PubAdsService The service object on which the method was called.

setCategoryExclusion

setCategoryExclusion ( categoryExclusion : string ) : PubAdsService
Sets a page-level ad category exclusion for the given label name.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

// Label = AirlineAd.
googletag.pubads().setCategoryExclusion("AirlineAd");
همچنین ببینید
پارامترها
categoryExclusion : string The ad category exclusion label to add.
برمی گرداند
PubAdsService The service object on which the method was called.

setCentering

setCentering ( centerAds : boolean ) : void
Enables and disables horizontal centering of ads. Centering is disabled by default. In legacy gpt_mobile.js, centering is enabled by default.

This method should be invoked before calling display or refresh because only ads that are requested after calling this method will be centered.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

// Make ads centered.
googletag.pubads().setCentering(true);
پارامترها
centerAds : boolean true to center ads, false to left-align them.

setForceSafeFrame

setForceSafeFrame ( forceSafeFrame : boolean ) : PubAdsService
Configures whether all ads on the page should be forced to be rendered using a SafeFrame container.

Please 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 false or 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.pubads().setForceSafeFrame(true);

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

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

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

JavaScript (legacy)

googletag.pubads().setForceSafeFrame(true);

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

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

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

TypeScript

googletag.pubads().setForceSafeFrame(true);

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

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

googletag.display("div-1");
googletag.display("div-2");
همچنین ببینید
پارامترها
forceSafeFrame : boolean true to force all ads on the page to be rendered in SafeFrames and false to change the previous setting to false. Setting this to false when unspecified earlier, won't change anything.
برمی گرداند
PubAdsService The service object on which the method was called.

setLocation

setLocation ( address : string ) : PubAdsService
Passes location information from websites so you can geo-target line items to specific locations.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

// Postal code:
googletag.pubads().setLocation("10001,US");
پارامترها
address : string Freeform address.
برمی گرداند
PubAdsService The service object on which the method was called.

setPrivacySettings

setPrivacySettings ( privacySettings : PrivacySettingsConfig ) : PubAdsService
Allows configuration of all privacy settings from a single API using a config object.
مثال

جاوا اسکریپت

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

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

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

JavaScript (legacy)

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

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

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

TypeScript

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

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

// Clear the configuration for childDirectedTreatment.
googletag.pubads().setPrivacySettings({
  childDirectedTreatment: null,
});
همچنین ببینید
پارامترها
privacySettings : PrivacySettingsConfig Object containing privacy settings config.
برمی گرداند
PubAdsService The service object on which the function was called.

setPublisherProvidedId

setPublisherProvidedId ( ppid : string ) : PubAdsService
Sets the value for the publisher-provided ID.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

googletag.pubads().setPublisherProvidedId("12JD92JD8078S8J29SDOAKC0EF230337");
همچنین ببینید
پارامترها
ppid : string An alphanumeric ID provided by the publisher. Must be between 32 and 150 characters.
برمی گرداند
PubAdsService The service object on which the method was called.

setSafeFrameConfig

setSafeFrameConfig ( config : SafeFrameConfig ) : PubAdsService
Sets the page-level preferences for SafeFrame configuration. Any unrecognized keys in the config object will be ignored. The entire config will be ignored if an invalid value is passed for a recognized key.

These page-level preferences will be overridden by slot-level preferences, if specified.
مثال

جاوا اسکریپت

googletag.pubads().setForceSafeFrame(true);

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

const slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

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

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

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

JavaScript (legacy)

googletag.pubads().setForceSafeFrame(true);

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

var slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

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

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

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

TypeScript

googletag.pubads().setForceSafeFrame(true);

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

const slotConfig = { allowOverlayExpansion: false };

googletag.pubads().setSafeFrameConfig(pageConfig);

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

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

googletag.display("div-1");
googletag.display("div-2");
همچنین ببینید
پارامترها
config : SafeFrameConfig The configuration object.
برمی گرداند
PubAdsService The service object on which the method was called.

setTargeting

setTargeting ( key : string , value : string | string [] ) : PubAdsService
Sets custom targeting parameters for a given key that apply to all Publisher Ads service ad slots. Calling this multiple times for the same key will overwrite old values. These keys are defined in your Google Ad Manager account.
مثال

جاوا اسکریپت

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

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

JavaScript (legacy)

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

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

TypeScript

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

// Example with multiple values for a key inside in an array.
googletag.pubads().setTargeting("interests", ["sports", "music"]);
همچنین ببینید
پارامترها
key : string Targeting parameter key.
value : string | string [] Targeting parameter value or array of values.
برمی گرداند
PubAdsService The service object on which the method was called.

setVideoContent

setVideoContent ( videoContentId : string , videoCmsId : string ) : void
Sets the video content information to be sent along with the ad requests for targeting and content exclusion purposes. Video ads will be automatically enabled when this method is called. For videoContentId and videoCmsId , use the values that are provided to the Google Ad Manager content ingestion service.
همچنین ببینید
پارامترها
videoContentId : string The video content ID.
videoCmsId : string The video CMS ID.

updateCorrelator

updateCorrelator ( ) : PubAdsService
Changes the correlator that is sent with ad requests, effectively starting a new page view. The correlator is the same for all the ad requests coming from one page view, and unique across page views. Only applies to async mode.

Note: this has no effect on GPT's long-lived pageview , which automatically reflects the ads actually on the page and has no expiration time.
مثال

جاوا اسکریپت

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

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

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

JavaScript (legacy)

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

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

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

TypeScript

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

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

// The correlator will now be a new randomly selected value, different
// from 12345. All subsequent ad requests made by this page will use
// the new value.
برمی گرداند
PubAdsService The service object on which the function was called.

googletag.ResponseInformation

An object representing a single ad response.
خواص
advertiser Id
The ID of the advertiser.
campaign Id
The ID of the campaign.
creative Id
The ID of the creative.
creative Template Id
The template ID of the ad.
line Item Id
The ID of the line item.
همچنین ببینید

خواص


advertiserId

advertiserId : number
The ID of the advertiser.

شناسه کمپین

campaignId : number
The ID of the campaign.

creativeId

creativeId : number
The ID of the creative.

creativeTemplateId

creativeTemplateId : number
The template ID of the ad.

lineItemId

lineItemId : number
The ID of the line item.

googletag.RewardedPayload

An object representing the reward associated with a rewarded ad
خواص
amount
The number of items included in the reward.
type
The type of item included in the reward (for example, "coin").
همچنین ببینید

خواص


مقدار

amount : number
The number of items included in the reward.

نوع

type : string
The type of item included in the reward (for example, "coin").

googletag.Service

Base service class that contains methods common for all services.
روش ها
add Event Listener
Registers a listener that allows you to set up and call a JavaScript function when a specific GPT event happens on the page.
get Slots
Get the list of slots associated with this service.
remove Event Listener
Removes a previously registered listener.

روش ها


addEventListener

addEventListener < K extends keyof EventTypeMap > ( eventType : K , listener : ( ( arg : EventTypeMap [ K ] ) => void ) ) : Service
Registers a listener that allows you to set up and call a JavaScript function when a specific GPT event happens on the page. رویدادهای زیر پشتیبانی می شوند: An object of the appropriate event type is passed to the listener when it is called.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

// 2. Adding an event listener with slot specific logic.
// Listeners operate at service level, which means that you cannot add
// a listener for an event for a specific slot only. You can, however,
// programmatically filter a listener to respond only to a certain ad
// slot, using this pattern:
const targetSlot = googletag.defineSlot("/1234567/example", [160, 600]);
googletag.pubads().addEventListener("slotOnload", (event) => {
  if (event.slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید
پارامترها
eventType : K 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

getSlots ( ) : Slot []
Get the list of slots associated with this service.
برمی گرداند
Slot [] Slots in the order in which they were added to the service.

removeEventListener

removeEventListener < K extends keyof EventTypeMap > ( eventType : K , listener : ( ( event : EventTypeMap [ K ] ) => void ) ) : void
Removes a previously registered listener.
مثال

جاوا اسکریپت

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();
});

TypeScript

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

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

  // Add onViewableListener as a listener for impressionViewable events.
  googletag.pubads().addEventListener("impressionViewable", onViewableListener);
  googletag.enableServices();
});
پارامترها
eventType : K 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

Builder for size mapping specification objects. This builder is provided to help easily construct size specifications.
روش ها
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
Adds a mapping from a single-size array (representing the viewport) to a single- or multi-size array representing the slot.
مثال

جاوا اسکریپت

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

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

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

JavaScript (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 &lt; 640x480
  .build();

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

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

TypeScript

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

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

// Mapping 2 will not show any ads for the following viewport sizes:
// [1024, 768] > size >= [980, 690] and
// [640, 480] > size >= [0, 0]
پارامترها
viewportSize : SingleSizeArray 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 ( ) : SizeMappingArray
Builds a size map specification from the mappings added to this builder.

If 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

Slot is an object representing a single ad slot on a page.
روش ها
add Service
Adds a Service to this slot.
clear Category Exclusions
منسوخ شده است. Clears all slot-level ad category exclusion labels for this slot.
clear Targeting
منسوخ شده است. 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
منسوخ شده است. 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
منسوخ شده است. Returns the list of attribute keys set on this slot.
get Category Exclusions
منسوخ شده است. 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
منسوخ شده است. Returns a specific custom targeting parameter set on this slot.
get Targeting Keys
منسوخ شده است. Returns the list of all custom targeting keys set on this slot.
set
منسوخ شده است. Sets a value for an AdSense attribute on this ad slot.
set Category Exclusion
منسوخ شده است. Sets a slot-level ad category exclusion label on this slot.
set Click Url
منسوخ شده است. Sets the click URL to which users will be redirected after clicking on the ad.
set Collapse Empty Div
منسوخ شده است. 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
منسوخ شده است. Configures whether ads in this slot should be forced to be rendered using a SafeFrame container.
set Safe Frame Config
منسوخ شده است. Sets the slot-level preferences for SafeFrame configuration.
set Targeting
منسوخ شده است. Sets a custom targeting parameter for this slot.
update Targeting From Map
منسوخ شده است. Sets custom targeting parameters for this slot, from a key:value map in a JSON object.

روش ها


addService

addService ( service : Service ) : Slot
Adds a Service to this slot.
مثال

جاوا اسکریپت

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

JavaScript (legacy)

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

TypeScript

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
Clears all slot-level ad category exclusion labels for this 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.

TypeScript

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

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

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

// Make an ad request. Any ad can be returned for the slot.
برمی گرداند
Slot The slot object on which the method was called.

clearTargeting

clearTargeting ( key ?: string ) : Slot
Clears specific or all custom slot-level targeting parameters for this 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.

TypeScript

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

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

slot.clearTargeting();
// All targeting has been cleared.
همچنین ببینید
پارامترها
Optional key : string 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
Sets an array of mappings from a minimum viewport size to slot size for this 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);

TypeScript

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

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

slot.defineSizeMapping(mapping!);
همچنین ببینید
پارامترها
sizeMapping : SizeMappingArray 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
Returns the value for the AdSense attribute associated with the given key for this slot. To see service-level attributes inherited by this slot, use PubAdsService.get .
مثال

جاوا اسکریپت

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'.

TypeScript

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

slot.get("adsense_background_color");
// Returns '#FFFFFF'.
همچنین ببینید
پارامترها
key : string 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
Returns the full path of the ad unit, with the network code and ad unit path.
مثال

جاوا اسکریپت

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'.

TypeScript

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

slot.getAdUnitPath();
// Returns '/1234567/sports'.
برمی گرداند
string Ad unit path.

getAttributeKeys

getAttributeKeys ( ) : string []
Returns the list of attribute keys set on this slot. To see the keys of service-level attributes inherited by this slot, use PubAdsService.getAttributeKeys .
مثال

جاوا اسکریپت

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'].

TypeScript

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

slot.getAttributeKeys();
// Returns ['adsense_background_color', 'adsense_border_color'].
برمی گرداند
string [] Array of attribute keys. Ordering is undefined.

getCategoryExclusions

getCategoryExclusions ( ) : string []
Returns the ad category exclusion labels for this slot.
مثال

جاوا اسکریپت

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'].

TypeScript

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

getConfig ( keys : string | string [] ) : Pick < SlotSettingsConfig , "adsenseAttributes" | "targeting" | "categoryExclusion" >
Gets general configuration options for the slot set by setConfig .

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"]);

TypeScript

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

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

// Get the value of the `adsenseAttributes` and `categoryExclusion` settings.
const config = slot.getConfig(["adsenseAttributes", "categoryExclusion"]);
پارامترها
keys : string | string [] The keys of the configuration options to get.
برمی گرداند
Pick < SlotSettingsConfig , "adsenseAttributes" | "targeting" | "categoryExclusion" > The configuration options for the slot.

getResponseInformation

getResponseInformation ( ) : ResponseInformation
Returns the ad response information. This is based on the last ad response for the slot. If this is called when the slot has no ad, null will be returned.
برمی گرداند
ResponseInformation The latest ad response information, or null if the slot has no ad.

getSlotElementId

getSlotElementId ( ) : string
Returns the ID of the slot div 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'.

TypeScript

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 []
Returns a specific custom targeting parameter set on this slot. Service-level targeting parameters are not included.
مثال

جاوا اسکریپت

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).

TypeScript

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

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

slot.getTargeting("age");
// Returns [] (empty array).
پارامترها
key : string 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 []
Returns the list of all custom targeting keys set on this slot. Service-level targeting keys are not included.
مثال

جاوا اسکریپت

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'].

TypeScript

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

slot.getTargetingKeys();
// Returns ['interests', 'allow_expandable'].
برمی گرداند
string [] Array of targeting keys. Ordering is undefined.

مجموعه

set ( key : string , value : string ) : Slot
Sets a value for an AdSense attribute on this ad slot. This will override any values set at the service level for this key.

Calling 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());

TypeScript

// Setting an attribute on a single ad slot.
googletag
  .defineSlot("/1234567/sports", [160, 600], "div")!
  .set("adsense_background_color", "#FFFFFF")
  .addService(googletag.pubads());
همچنین ببینید
پارامترها
key : string The name of the attribute.
value : string Attribute value.
برمی گرداند
Slot The slot object on which the method was called.

setCategoryExclusion

setCategoryExclusion ( categoryExclusion : string ) : Slot
Sets a slot-level ad category exclusion label on this 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());

TypeScript

// 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 ) : Slot
Sets the click URL to which users will be redirected after clicking on the ad.

The 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());

TypeScript

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 ) : Slot
Sets whether the slot div 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.

TypeScript

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

googletag
  .defineSlot("/1234567/sports", [160, 600], "div-2")!
  .setCollapseEmptyDiv(true)
  .addService(googletag.pubads());
// The above will cause the div for this slot to be collapsed
// only after GPT detects that no ads are available for the slot.
همچنین ببینید
پارامترها
collapse : boolean Whether to collapse the slot if no ad is returned.
Optional collapseBeforeAdFetch : boolean 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
Sets general configuration options for this slot.
پارامترها
slotConfig : SlotSettingsConfig The configuration object.

setForceSafeFrame

setForceSafeFrame ( forceSafeFrame : boolean ) : Slot
Configures whether ads in this slot should be forced to be rendered using a SafeFrame container.

Please 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 false or 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());

TypeScript

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 ) : Slot
Sets the slot-level preferences for SafeFrame configuration. Any unrecognized keys in the config object will be ignored. The entire config will be ignored if an invalid value is passed for a recognized key.

These 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");

TypeScript

googletag.pubads().setForceSafeFrame(true);

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

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

googletag.display("div-1");
googletag.display("div-2");
همچنین ببینید
پارامترها
config : SafeFrameConfig The configuration object.
برمی گرداند
Slot The slot object on which the method was called.

setTargeting

setTargeting ( key : string , value : string | string [] ) : Slot
Sets a custom targeting parameter for this slot. Calling this method multiple times for the same key will overwrite old values. Values set here will overwrite targeting parameters set at the service-level. These keys are defined in your Google Ad Manager account.
مثال

جاوا اسکریپت

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"]);

TypeScript

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

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

// Example with multiple values for a key inside in an array.
slot.setTargeting("interests", ["sports", "music"]);
همچنین ببینید
پارامترها
key : string 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
Sets custom targeting parameters for this slot, from a key:value map in a JSON object. This is the same as calling Slot.setTargeting for all the key values of the object. These keys are defined in your Google Ad Manager account.

یادداشت ها:
  • 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"],
});

TypeScript

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

slot.updateTargetingFromMap({
  color: "red",
  interests: ["sports", "music", "movies"],
});
پارامترها
map : {
  [ adUnitPath : string ] : string | string [] ;
}
Targeting parameter key:value map.
برمی گرداند
Slot The slot object on which the method was called.

googletag.config

Main configuration interface for page-level settings.
رابط ها
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.
Type Aliases
Interstitial Trigger
Supported interstitial ad triggers.
Privacy Treatment
Supported publisher privacy treatments.
Taxonomy
Supported taxonomies for publisher provided signals (PPS) .

Type Aliases


InterstitialTrigger

InterstitialTrigger : "unhideWindow" | "navBar"
Supported interstitial ad triggers.

PrivacyTreatment

PrivacyTreatment : "disablePersonalization"
Supported publisher privacy treatments.

طبقه بندی

Taxonomy : "IAB_AUDIENCE_1_1" | "IAB_CONTENT_2_2"
Supported taxonomies for publisher provided signals (PPS) .
همچنین ببینید

googletag.config.AdExpansionConfig

Settings to control ad expansion.
خواص
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 },
});

TypeScript

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

خواص


Optional enabled

enabled ?: boolean
Whether ad expansion is enabled or disabled.

Setting this value overrides the default configured in Google Ad Manager.
همچنین ببینید

googletag.config.AdSenseAttributesConfig

Settings to control the behavior of AdSense ads.

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"
AdSense ad format.

Optional adsense_channel_ids

adsense_channel_ids ?: string
AdSense channel IDs.

Allowed values are channel IDs separated by '+'.

Example: 271828183+314159265
همچنین ببینید

Optional adsense_test_mode

adsense_test_mode ?: "on"
Whether or not test mode is enabled.

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 ?: string
Language of the page on which ads are displayed.

Allowed values are valid ISO 639-1 language codes.

Example: en
همچنین ببینید

Optional page_url

page_url ?: string
URL of the page on which ads are displayed.

Allowed values are valid URLs.

Example: http://www.example.com

googletag.config.ComponentAuctionConfig

An object representing a single component auction in a on-device ad auction.
خواص
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 ;
}
An auction configuration object for this component auction.

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,
    },
  ],
});

TypeScript

const componentAuctionConfig = {
  // Seller URL should be https and the same as decisionLogicURL's origin
  seller: "https://testSeller.com",
  decisionLogicURL: "https://testSeller.com/ssp/decision-logic.js",
  interestGroupBuyers: ["https://example-buyer.com"],
  auctionSignals: { auction_signals: "auction_signals" },
  sellerSignals: { seller_signals: "seller_signals" },
  perBuyerSignals: {
    // listed on interestGroupBuyers
    "https://example-buyer.com": {
      per_buyer_signals: "per_buyer_signals",
    },
  },
};

const auctionSlot = googletag.defineSlot("/1234567/example", [160, 600])!;

// To add configKey to the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: componentAuctionConfig,
    },
  ],
});

// To remove configKey from the component auction:
auctionSlot.setConfig({
  componentAuction: [
    {
      configKey: "https://testSeller.com",
      auctionConfig: null,
    },
  ],
});
همچنین ببینید

configKey

configKey : string
The configuration key associated with this component auction.

This 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

An object which defines the behavior of a single interstitial ad slot.
خواص
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 ?: boolean
Whether local storage consent is required to display this interstitial ad.

GPT 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
  },
});

TypeScript

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

interstitialSlot.setConfig({
  interstitial: {
    requireStorageAccess: true, // defaults to false
  },
});
همچنین ببینید

Optional triggers

triggers ?: Partial < Record < InterstitialTrigger , boolean > >
The interstitial trigger configuration for this interstitial ad.

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,
    },
  },
});

TypeScript

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

// Enable optional interstitial triggers.
// Change this value to false to disable.
const enableTriggers = true;

interstitialSlot.setConfig({
  interstitial: {
    triggers: {
      navBar: enableTriggers,
      unhideWindow: enableTriggers,
    },
  },
});
همچنین ببینید

googletag.config.LazyLoadConfig

Settings to control the use of lazy loading in GPT.
خواص
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 ?: number
The minimum distance from the current viewport a slot must be before we request an ad, expressed as a percentage of viewport size.

Used 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 ?: number
A multiplier applied to margins on mobile devices. This multiplier is applied to both fetchMarginPercent and renderMarginPercent .

This 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 ?: number
The minimum distance from the current viewport a slot must be before we render an ad, expressed as a percentage of viewport size.

Used 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

Main configuration interface for page-level settings.

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
Settings to control ad expansion.

Optional adsenseAttributes

adsenseAttributes ?: AdSenseAttributesConfig
Setting to configure AdSense attributes.

AdSense 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 });

TypeScript

// Set the document language and page URL.
googletag.setConfig({
  adsenseAttributes: { document_language: "en", page_url: "http://www.example.com" },
});

// Clear the page URL only.
googletag.setConfig({ adsenseAttributes: { page_url: null } });

// Clear all AdSense attributes.
googletag.setConfig({ adsenseAttributes: null });

Optional adYield

adYield ?: "DISABLED" | "ENABLED_ALL_SLOTS"

Optional categoryExclusion

categoryExclusion ?: string []
Setting to configure ad category exclusions.
مثال

جاوا اسکریپت

// 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 });

TypeScript

// Label = AirlineAd.
googletag.setConfig({ categoryExclusion: ["AirlineAd"] });

// Clearing category exclusion setting.
googletag.setConfig({ categoryExclusion: null });
همچنین ببینید

Optional centering

centering ?: boolean
Setting to control the horizontal centering of ads. Centering is disabled by default.

Horizontal 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 });

TypeScript

// Make ads centered.
googletag.setConfig({ centering: true });

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

Optional collapseDiv

collapseDiv ?: "DISABLED" | "BEFORE_FETCH" | "ON_NO_FILL"
Setting to control the collapsing behavior of ad slots.

A 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 });

TypeScript

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

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

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

// Clear the collapse setting.
googletag.setConfig({ collapseDiv: null });
همچنین ببینید

Optional disableInitialLoad

disableInitialLoad ?: boolean
Setting to control when ads are requested.

By 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 });

TypeScript

// Prevent requesting ads when `display()` is called.
googletag.setConfig({ disableInitialLoad: true });
همچنین ببینید

Optional lazyLoad

lazyLoad ?: LazyLoadConfig
Settings to control the use of lazy loading in GPT.

Lazy 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 });

TypeScript

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

// Clear fetch margin only.
googletag.setConfig({
  lazyLoad: { fetchMarginPercent: null },
});

// Clear all lazy loading settings.
googletag.setConfig({ lazyLoad: null });
همچنین ببینید

Optional location

location ?: string
Setting to geo-target line items to geographic locations.
مثال

جاوا اسکریپت

// 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 });

TypeScript

// Geo-target line items to US postal code 10001.
googletag.setConfig({ location: "10001,US" });

// Clear the location setting.
googletag.setConfig({ location: null });
همچنین ببینید

Optional pps

Settings to control publisher provided signals (PPS).

Optional privacyTreatments

privacyTreatments ?: PrivacyTreatmentsConfig
Settings to control publisher privacy treatments.

Optional safeFrame

safeFrame ?: SafeFrameConfig
Settings to control the use of SafeFrame in GPT.

Values 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 });

TypeScript

// Force SafeFrame for all ads on the page.
googletag.setConfig({
  safeFrame: { forceSafeFrame: true },
});

// Configure SafeFrame to allow overlay expansion.
googletag.setConfig({
  safeFrame: { allowOverlayExpansion: true },
});

// Clear forceSafeFrame setting.
googletag.setConfig({
  safeFrame: { forceSafeFrame: null },
});

// Clear all SafeFrame settings.
googletag.setConfig({ safeFrame: null });

Optional singleRequest

singleRequest ?: boolean
Setting to enable or disable Single Request Architecture (SRA).

When 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 });

TypeScript

// Enable Single Request Architecture.
googletag.setConfig({ singleRequest: true });
همچنین ببینید

Optional targeting

targeting ?: Record < string , string | string [] >
Setting to control key-value targeting.

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 } });

TypeScript

// Setting a single targeting key-value.
googletag.setConfig({ targeting: { interests: "sports" } });

// Setting multiple values for a single targeting key
googletag.setConfig({ targeting: { interests: ["sports", "music"] } });

// Setting multiple targeting key-values at once.
googletag.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } });

// Clearing a single targeting key.
googletag.setConfig({ targeting: { interests: null } });
همچنین ببینید

Optional threadYield

threadYield ?: "DISABLED" | "ENABLED_ALL_SLOTS"
Setting to control whether GPT should yield the JS thread when requesting and rendering creatives.

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 });

TypeScript

// Disable yielding.
googletag.setConfig({ threadYield: "DISABLED" });

// Enable yielding for all slots.
googletag.setConfig({ threadYield: "ENABLED_ALL_SLOTS" });

// Enable yielding only for slots outside of the viewport (default).
googletag.setConfig({ threadYield: null });
همچنین ببینید

Optional videoAds

videoAds ?: VideoAdsConfig
Settings to control video ads.
مثال

جاوا اسکریپت

// 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",
  },
});

TypeScript

// Enable video ads and set video content and content source IDs.
googletag.setConfig({
  videoAds: {
    enableVideoAds: true,
    videoContentId: "e1eGlRL7ju8",
    videoCmsId: "1234567",
  },
});
همچنین ببینید

googletag.config.PrivacyTreatmentsConfig

Settings to control publisher privacy treatments.
خواص
treatments
An array of publisher privacy treatments to enable.

خواص


درمان ها

treatments : "disablePersonalization" []
An array of publisher privacy treatments to enable.
مثال

جاوا اسکریپت

// Disable personalization across the entire page.
googletag.setConfig({
  privacyTreatments: { treatments: ["disablePersonalization"] },
});

JavaScript (legacy)

// Disable personalization across the entire page.
googletag.setConfig({
  privacyTreatments: { treatments: ["disablePersonalization"] },
});

TypeScript

// Disable personalization across the entire page.
googletag.setConfig({
  privacyTreatments: { treatments: ["disablePersonalization"] },
});

googletag.config.PublisherProvidedSignalsConfig

Publisher provided signals (PPS) configuration object.
خواص
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'
    },
  },
});

TypeScript

googletag.setConfig({
  pps: {
    taxonomies: {
      IAB_AUDIENCE_1_1: { values: ["6", "626"] },
      // '6' = 'Demographic | Age Range | 30-34'
      // '626' = 'Interest | Sports | Darts'
      IAB_CONTENT_2_2: { values: ["48", "127"] },
      // '48' = 'Books and Literature | Fiction'
      // '127' = 'Careers | Job Search'
    },
  },
});
همچنین ببینید

خواص


taxonomies

taxonomies : Partial < Record < Taxonomy , TaxonomyData > >
An object containing Taxonomy mappings or null to clear the config.

googletag.config.SafeFrameConfig

Settings to control SafeFrame in GPT.
خواص
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 ?
منسوخ شده است. Whether SafeFrame should use randomized subdomains for Reservation creatives.
همچنین ببینید

خواص


Optional allowOverlayExpansion

allowOverlayExpansion ?: boolean
Whether SafeFrame should allow ad content to expand by overlaying page content.

Optional allowPushExpansion

allowPushExpansion ?: boolean
Whether SafeFrame should allow ad content to expand by pushing page content.

Optional forceSafeFrame

forceSafeFrame ?: boolean
Whether ad(s) should be forced to be rendered using a SafeFrame container.

Optional sandbox

sandbox ?: boolean
Whether SafeFrame should use the HTML5 sandbox attribute to prevent top level navigation without user interaction. The only valid value is true (cannot be forced to false ). Note that the sandbox attribute disables plugins (eg Flash).

Optional useUniqueDomain

useUniqueDomain ?: boolean
Whether SafeFrame should use randomized subdomains for Reservation creatives. Pass in null to clear the stored value.

Note: this feature is enabled by default.
همچنین ببینید

googletag.config.SlotSettingsConfig

Main configuration interface for slot-level settings.

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
Settings to configure ad expansion.
همچنین ببینید

Optional adsenseAttributes

adsenseAttributes ?: AdSenseAttributesConfig
Setting to configure AdSense attributes.

AdSense 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 });

TypeScript

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

// Set the AdSense ad format and channel IDs.
slot.setConfig({
  adsenseAttributes: {
    adsense_ad_format: "120x240_as",
    adsense_channel_ids: "271828183+314159265",
  },
});

// Clear the AdSense channel IDs only.
slot.setConfig({ adsenseAttributes: { adsense_channel_ids: null } });

// Clear all AdSense attributes.
slot.setConfig({ adsenseAttributes: null });

Optional categoryExclusion

categoryExclusion ?: string []
Setting to configure ad category exclusions.
مثال

جاوا اسکریپت

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 });

TypeScript

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

// Label = AirlineAd
slot.setConfig({
  categoryExclusion: ["AirlineAd"],
});

// Clearing category exclusion setting.
slot.setConfig({ categoryExclusion: null });
همچنین ببینید

Optional clickUrl

clickUrl ?: string
Setting to configure the URL to which users will be redirected after clicking on the ad.

The 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,
});

TypeScript

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

// Sets the click URL to 'http://www.example.com?original_click_url='.
slot.setConfig({
  clickUrl: "http://www.example.com?original_click_url=",
});

// Clears the click URL.
slot.setConfig({
  clickUrl: null,
});

Optional collapseDiv

collapseDiv ?: "DISABLED" | "BEFORE_FETCH" | "ON_NO_FILL"
Setting to configure the collapsing behavior of the ad slot.

A 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,
});

TypeScript

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

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

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

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

// Clear the collapse setting.
slot.setConfig({
  collapseDiv: null,
});
همچنین ببینید

Optional componentAuction

componentAuction ?: ComponentAuctionConfig []
An array of component auctions to be included in an on-device ad auction.

Optional interstitial

interstitial ?: InterstitialConfig
Settings that configure interstitial ad slot behavior.
همچنین ببینید

Optional safeFrame

safeFrame ?: SafeFrameConfig
Settings to configure the use of SafeFrame in GPT.

Values 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 });

TypeScript

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

// Force SafeFrame for the slot.
slot.setConfig({
  safeFrame: { forceSafeFrame: true },
});

// Configure SafeFrame to allow overlay expansion for the slot.
slot.setConfig({
  safeFrame: { allowOverlayExpansion: true },
});

// Clear forceSafeFrame setting for the slot.
slot.setConfig({
  safeFrame: { forceSafeFrame: null },
});

// Clear all SafeFrame settings for the slot.
slot.setConfig({ safeFrame: null });

Optional targeting

targeting ?: Record < string , string | string [] >
Setting to configure key-value targeting.

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 });

TypeScript

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

// Setting a single targeting key-value.
slot.setConfig({ targeting: { interests: "sports" } });

// Setting multiple values for a single targeting key.
slot.setConfig({ targeting: { interests: ["sports", "music"] } });

// Setting multiple targeting key-values at once.
slot.setConfig({ targeting: { interests: ["sports", "music"], color: "red" } });

// Clearing a single targeting key.
slot.setConfig({ targeting: { interests: null } });

// Clear all targeting keys.
slot.setConfig({ targeting: null });
همچنین ببینید

googletag.config.TaxonomyData

An object containing the values for a single Taxonomy .
خواص
values
A list of Taxonomy values.

خواص


ارزش ها

values : readonly string []
A list of Taxonomy values.

googletag.config.VideoAdsConfig

Settings to configure video ad related settings.
خواص
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 : boolean
Whether videos ads will be present on the page.

When 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 ?: string
The video content source ID.

This 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 ?: string
The video content ID.

This 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

This is the namespace that GPT uses for enum types.
شمارش ها
Out Of Page Format
Out-of-page formats supported by GPT.
Traffic Source
Traffic sources supported by GPT.

شمارش ها


OutOfPageFormat

OutOfPageFormat
Out-of-page formats supported by GPT.
همچنین ببینید
Enumeration Members
BOTTOM_ ANCHOR
Anchor format where slot sticks to the bottom of the viewport.
GAME_ MANUAL_ INTERSTITIAL
Game manual interstitial format.

Note: Game manual interstitial is a limited-access format.
INTERSTITIAL
Web interstitial creative format.
LEFT_ SIDE_ RAIL
Left side rail format.
REWARDED
Rewarded format.
RIGHT_ SIDE_ RAIL
Right side rail format.
TOP_ ANCHOR
Anchor format where slot sticks to the top of the viewport.

TrafficSource

TrafficSource
Traffic sources supported by GPT.
همچنین ببینید
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

This is the namespace that GPT uses for Events. Your code can react to these events using Service.addEventListener.
رابط ها
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.
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

Base Interface for all GPT events. All GPT events below will have the following fields.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
همچنین ببینید

خواص


serviceName

serviceName : string
Name of the service that triggered the event.

شکاف

slot : Slot
The slot that triggered the event.

googletag.events.EventTypeMap

This is a pseudo-type that maps an event name to its corresponding event object type for Service.addEventListener and Service.removeEventListener . It is documented for reference and type safety purposes only.
خواص
game Manual Interstitial Slot Closed
game Manual Interstitial Slot Ready
impression Viewable
rewarded Slot Closed
rewarded Slot Granted
rewarded Slot Ready
slot Onload
slot Render Ended
slot Requested
slot Response Received
slot Visibility Changed

خواص


gameManualInterstitialSlotClosed


gameManualInterstitialSlotReady


impressionViewable

impressionViewable : ImpressionViewableEvent
Alias for events.ImpressionViewableEvent .

rewardedSlotClosed

rewardedSlotClosed : RewardedSlotClosedEvent
Alias for events.RewardedSlotClosedEvent .

rewardedSlotGranted

rewardedSlotGranted : RewardedSlotGrantedEvent
Alias for events.RewardedSlotGrantedEvent .

rewardedSlotReady

rewardedSlotReady : RewardedSlotReadyEvent
Alias for events.RewardedSlotReadyEvent .

slotOnload

slotOnload : SlotOnloadEvent
Alias for events.SlotOnloadEvent .

slotRenderEnded

slotRenderEnded : SlotRenderEndedEvent
Alias for events.SlotRenderEndedEvent .

slotRequested

slotRequested : SlotRequestedEvent
Alias for events.SlotRequestedEvent .

slotResponseReceived

slotResponseReceived : SlotResponseReceived
Alias for events.SlotResponseReceived .

slotVisibilityChanged


googletag.events.GameManualInterstitialSlotClosedEvent

Extends Event
This event is fired when a game manual interstitial slot has been closed by the user.

Note: Game manual interstitial is a limited-access format.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
    }
  });
}

TypeScript

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

googletag.events.GameManualInterstitialSlotReadyEvent

Extends Event
This event is fired when a game manual interstitial slot is ready to be shown to the user.

Note: Game manual interstitial is a limited-access format.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
روش ها
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.
    }
  });
}

TypeScript

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

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

روش ها


makeGameManualInterstitialVisible

makeGameManualInterstitialVisible ( ) : void
Displays the game manual interstitial ad to the user.

googletag.events.ImpressionViewableEvent

Extends Event
This event is fired when an impression becomes viewable, according to the Active View criteria .
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

googletag.events.RewardedSlotClosedEvent

Extends Event
This event is fired when a rewarded ad slot is closed by the user. It may fire either before or after a reward has been granted. To determine whether a reward has been granted, use events.RewardedSlotGrantedEvent instead.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

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.
    }
  });
}

TypeScript

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

googletag.events.RewardedSlotGrantedEvent

Extends Event
This event is fired when a reward is granted for viewing a rewarded ad . If the ad is closed before the criteria for granting a reward is met, this event will not fire.
خواص
payload
An object containing information about the reward that was granted.
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

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.
    }
  });
}

TypeScript

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

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

خواص


محموله

payload : RewardedPayload
An object containing information about the reward that was granted.

googletag.events.RewardedSlotReadyEvent

Extends Event
This event is fired when a rewarded ad is ready to be displayed. The publisher is responsible for presenting the user an option to view the ad before displaying it.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
روش ها
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.
    }
  });
}

TypeScript

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

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

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

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

    if (slot === targetSlot) {
      // Slot specific logic.
    }
  });
}
همچنین ببینید

روش ها


makeRewardedVisible

makeRewardedVisible ( ) : void
Displays the rewarded ad. This method should not be called until the user has consented to view the ad.

googletag.events.SlotOnloadEvent

Extends Event
This event is fired when the creative's iframe fires its load event. When rendering rich media ads in sync rendering mode, no iframe is used so no SlotOnloadEvent will be fired.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

googletag.events.SlotRenderEndedEvent

Extends Event
This event is fired when the creative code is injected into a slot. This event will occur before the creative's resources are fetched, so the creative may not be visible yet. If you need to know when all creative resources for a slot have finished loading, consider the events.SlotOnloadEvent instead.
خواص
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.
size
Indicates the pixel size of the rendered creative.
slot
The slot that triggered the event.
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.
  }
});

TypeScript

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

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

خواص


advertiserId

advertiserId : number
Advertiser ID of the rendered ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

شناسه کمپین

campaignId : number
Campaign ID of the rendered ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

companyIds

companyIds : number []
IDs of the companies that bid on the rendered backfill ad. Value is null for empty slots, reservation ads, and creatives rendered by services other than PubAdsService .

creativeId

creativeId : number
Creative ID of the rendered reservation ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

creativeTemplateId

creativeTemplateId : number
Creative template ID of the rendered reservation ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

isBackfill

isBackfill : boolean
Whether an ad was a backfill ad. Value is true if the ad was a backfill ad, false otherwise.

خالی است

isEmpty : boolean
Whether an ad was returned for the slot. Value is true if no ad was returned, false otherwise.

labelIds

labelIds : number []

lineItemId

lineItemId : number
Line item ID of the rendered reservation ad. Value is null for empty slots, backfill ads, and creatives rendered by services other than PubAdsService .

responseIdentifier

responseIdentifier : string
The response identifier is a unique identifier for the ad response. This value can be used to identify and block the ad in the Ad Review Center (ARC) .

اندازه

size : string | number []
Indicates the pixel size of the rendered creative. Example: [728, 90] . Value is null for empty ad slots.

slotContentChanged

slotContentChanged : boolean
Whether the slot content was changed with the rendered ad. Value is true if the content was changed, false otherwise.

sourceAgnosticCreativeId

sourceAgnosticCreativeId : number
Creative ID of the rendered reservation or backfill ad. Value is null if the ad is not a reservation or line item backfill, or the creative is rendered by services other than PubAdsService .

sourceAgnosticLineItemId

sourceAgnosticLineItemId : number
Line item ID of the rendered reservation or backfill ad. Value is null if the ad is not a reservation or line item backfill, or the creative is rendered by services other than PubAdsService .

yieldGroupIds

yieldGroupIds : number []
IDs of the yield groups for the rendered backfill ad. Value is null for empty slots, reservation ads, and creatives rendered by services other than PubAdsService .

googletag.events.SlotRequestedEvent

Extends Event
This event is fired when an ad has been requested for a particular slot.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

googletag.events.SlotResponseReceived

Extends Event
This event is fired when an ad response has been received for a particular slot.
خواص
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

googletag.events.SlotVisibilityChangedEvent

Extends Event
This event is fired whenever the on-screen percentage of an ad slot's area changes. The event is throttled and will not fire more often than once every 200ms.
خواص
in View Percentage
The percentage of the ad's area that is visible.
service Name
Name of the service that triggered the event.
slot
The slot that triggered the event.
مثال

جاوا اسکریپت

// 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.
  }
});

TypeScript

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

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

  if (slot === targetSlot) {
    // Slot specific logic.
  }
});
همچنین ببینید

خواص


inViewPercentage

inViewPercentage : number
The percentage of the ad's area that is visible. Value is a number between 0 and 100.

googletag.secureSignals

This is the namespace that GPT uses for managing secure signals.
رابط ها
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.
Type Aliases
Secure Signal Provider
Interface for returning a secure signal for a specific bidder or provider.

Type Aliases


SecureSignalProvider

Interface for returning a secure signal for a specific bidder or provider. One of id or networkCode must be provided, but not both.

googletag.secureSignals.BidderSignalProvider

Returns a secure signal for a specific bidder.

A bidder secure signal provider consists of 2 parts:

  1. A collector function, which returns a Promise that resolves to a secure signal.
  2. An id which identifies the bidder associated with the signal.
To return a secure signal for a publisher, use secureSignals.PublisherSignalProvider instead.
خواص
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");
  },
});

TypeScript

// id is provided
googletag.secureSignalProviders!.push({
  id: "collector123",
  collectorFunction: () => {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});
همچنین ببینید

خواص


collectorFunction

collectorFunction : ( ( ) => Promise < string > )
A function which returns a Promise that resolves to a secure signal.

شناسه

id : string
A unique identifier for the collector associated with this secure signal, as registered in Google Ad Manager.

googletag.secureSignals.PublisherSignalProvider

Returns a secure signal for a specific publisher.

A publisher signal provider consists of 2 parts:

  1. A collector function, which returns a Promise that resolves to a secure signal.
  2. A networkCode which identifies the publisher associated with the signal.
To return a secure signal for a bidder, use secureSignals.BidderSignalProvider instead.
خواص
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");
  },
});

TypeScript

// networkCode is provided
googletag.secureSignalProviders!.push({
  networkCode: "123456",
  collectorFunction: () => {
    // ...custom signal generation logic...
    return Promise.resolve("signal");
  },
});
همچنین ببینید

خواص


collectorFunction

collectorFunction : ( ( ) => Promise < string > )
A function which returns a Promise that resolves to a secure signal.

networkCode

networkCode : string
The network code (as seen in the ad unit path) for the publisher associated with this secure signal.

googletag.secureSignals.SecureSignalProvidersArray

An interface for managing secure signals.
روش ها
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 ( ) : void
Clears all signals for all collectors from cache.

Calling 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
Adds a new secureSignals.SecureSignalProvider to the signal provider array and begins the signal generation process.
پارامترها
provider : SecureSignalProvider The secureSignals.SecureSignalProvider object to be added to the array.