Birden fazla reklam isteğini işleme
Koleksiyonlar ile düzeninizi koruyun
İçeriği tercihlerinize göre kaydedin ve kategorilere ayırın.
IMA SDK'sının çoğu kullanımında tek seferde yalnızca tek bir reklam isteğinin yönetilmesi gerekir. Ancak kullanıcı bir video seçmeden önce reklam verilerini ön yükleme gibi bazı uç durum uygulamaları, birden fazla eşzamanlı istek yapılmasını gerektirebilir. Reklam istekleri eşzamanlı olarak yapılmadığından, doğru reklam yöneticisinin doğru bağlamla ilişkilendirildiğinden emin olmak zor bir iş gibi görünebilir.
HTML5 için IMA SDK'sı, birden fazla reklam yöneticisini ayırt etme sürecini basitleştirmek amacıyla yayıncıların herhangi bir reklam isteğinin UserContext alanına herhangi bir değer veya nesne iletmesine olanak tanır. Bu değer veya nesne daha sonra AdsManagerLoadedEvent işleyicisinde getUserRequestContext() yöntemi kullanılarak alınabilir.
Örnek
...
adsLoader.addEventListener(
google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,
onAdsManagerLoaded,
false);
adsLoader.addEventListener(
google.ima.AdErrorEvent.Type.AD_ERROR,
onAdsManagerError,
false);
const contextA = {id: "Request A", element: videoElementA};
const contextB = {id: "Request B", element: videoElementB}
adsLoader.requestAds(adsRequestA, contextA);
adsLoader.requestAds(adsRequestB, contextB);
...
function onAdsManagerLoaded(adsManagerLoadedEvent) {
const context = adsManagerLoadedEvent.getUserRequestContext();
adsManager = adsManagerLoadedEvent.getAdsManager(context.element);
console.log("Successfully loaded ID: " + context.id);
}
function onAdsManagerError(adsManagerErrorEvent) {
const context = adsManagerErrorEvent.getUserRequestContext();
console.log("Error with AdRequest ID: " + context.id);
}
...
Aksi belirtilmediği sürece bu sayfanın içeriği Creative Commons Atıf 4.0 Lisansı altında ve kod örnekleri Apache 2.0 Lisansı altında lisanslanmıştır. Ayrıntılı bilgi için Google Developers Site Politikaları'na göz atın. Java, Oracle ve/veya satış ortaklarının tescilli ticari markasıdır.
Son güncelleme tarihi: 2025-08-31 UTC.
[null,null,["Son güncelleme tarihi: 2025-08-31 UTC."],[[["\u003cp\u003eThe IMA SDK allows for multiple concurrent ad requests, useful for preloading ads or managing multiple video players.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use the \u003ccode\u003eUserContext\u003c/code\u003e field to associate a custom object with each ad request for easy identification.\u003c/p\u003e\n"],["\u003cp\u003eThis object can be retrieved later using \u003ccode\u003egetUserRequestContext()\u003c/code\u003e in the \u003ccode\u003eAdsManagerLoadedEvent\u003c/code\u003e and \u003ccode\u003eAdErrorEvent\u003c/code\u003e handlers.\u003c/p\u003e\n"],["\u003cp\u003eThis approach simplifies associating the correct AdsManager with its corresponding video element and context.\u003c/p\u003e\n"]]],[],null,["# Handle multiple ad requests\n\nMost uses of the IMA SDK only require managing a single ad request at a time. However some edge case implementations, such as preloading ad data before the user selects a video, may require making multiple concurrent requests. Since ad requests are made asynchronously, ensuring the proper ad manager is associated with the correct context can seem to be a daunting task.\n\nTo simplify the process of differentiating multiple ad managers, the IMA SDK for HTML5 allows publishers to pass in any value or object to the [UserContext](https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/reference/js/google.ima.AdsLoader#requestAds) field of any ad request. This value or object can then be retrieved in the [AdsManagerLoadedEvent](https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/reference/js/google.ima.AdsManagerLoadedEvent) handler, by using the method [getUserRequestContext()](https://developers.google.com/interactive-media-ads/docs/sdks/html5/client-side/reference/js/google.ima.AdsManagerLoadedEvent#getUserRequestContext).\n\nExample\n-------\n\n ...\n adsLoader.addEventListener(\n google.ima.AdsManagerLoadedEvent.Type.ADS_MANAGER_LOADED,\n onAdsManagerLoaded,\n false);\n adsLoader.addEventListener(\n google.ima.AdErrorEvent.Type.AD_ERROR,\n onAdsManagerError,\n false);\n const contextA = {id: \"Request A\", element: videoElementA};\n const contextB = {id: \"Request B\", element: videoElementB}\n adsLoader.requestAds(adsRequestA, contextA);\n adsLoader.requestAds(adsRequestB, contextB);\n ...\n\n function onAdsManagerLoaded(adsManagerLoadedEvent) {\n const context = adsManagerLoadedEvent.getUserRequestContext();\n adsManager = adsManagerLoadedEvent.getAdsManager(context.element);\n console.log(\"Successfully loaded ID: \" + context.id);\n }\n\n function onAdsManagerError(adsManagerErrorEvent) {\n const context = adsManagerErrorEvent.getUserRequestContext();\n console.log(\"Error with AdRequest ID: \" + context.id);\n }\n ..."]]