एक से ज़्यादा विज्ञापन अनुरोधों को मैनेज करना
संग्रह की मदद से व्यवस्थित रहें
अपनी प्राथमिकताओं के आधार पर, कॉन्टेंट को सेव करें और कैटगरी में बांटें.
IMA SDK टूल के ज़्यादातर इस्तेमाल के लिए, एक बार में सिर्फ़ एक विज्ञापन अनुरोध मैनेज करना ज़रूरी होता है. हालांकि, कुछ खास मामलों में, एक साथ कई अनुरोध करने पड़ सकते हैं. जैसे, उपयोगकर्ता के वीडियो चुनने से पहले, विज्ञापन डेटा को प्रीलोड करना. विज्ञापन अनुरोध, एक साथ नहीं किए जाते. इसलिए, यह पक्का करना कि सही विज्ञापन मैनेजर, सही संदर्भ से जुड़ा हो, मुश्किल लग सकता है.
कई विज्ञापन मैनेजर के बीच अंतर करने की प्रोसेस को आसान बनाने के लिए, HTML5 के लिए IMA SDK टूल की मदद से पब्लिशर, किसी भी विज्ञापन अनुरोध के UserContext फ़ील्ड में कोई भी वैल्यू या ऑब्जेक्ट पास कर सकते हैं. इसके बाद, getUserRequestContext() तरीके का इस्तेमाल करके, AdsManagerLoadedEvent हैंडलर में इस वैल्यू या ऑब्जेक्ट को वापस पाया जा सकता है.
उदाहरण
...
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);
}
...
जब तक कुछ अलग से न बताया जाए, तब तक इस पेज की सामग्री को Creative Commons Attribution 4.0 License के तहत और कोड के नमूनों को Apache 2.0 License के तहत लाइसेंस मिला है. ज़्यादा जानकारी के लिए, Google Developers साइट नीतियां देखें. Oracle और/या इससे जुड़ी हुई कंपनियों का, Java एक रजिस्टर किया हुआ ट्रेडमार्क है.
आखिरी बार 2025-08-31 (UTC) को अपडेट किया गया.
[null,null,["आखिरी बार 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 ..."]]