• इस पेज पर, यह जानकारी उपलब्ध है
  • उदाहरण

UserContext के साथ कई विज्ञापन अनुरोधों को मैनेज करना

  • इस पेज पर, यह जानकारी उपलब्ध है
  • उदाहरण

IMA SDK टूल के ज़्यादातर इस्तेमाल के लिए, एक बार में सिर्फ़ एक विज्ञापन अनुरोध मैनेज करना ज़रूरी होता है. हालांकि, कुछ खास मामलों में, एक साथ कई अनुरोध करने पड़ सकते हैं. जैसे, उपयोगकर्ता के वीडियो चुनने से पहले, विज्ञापन डेटा को प्रीलोड करना. विज्ञापन अनुरोध, एक साथ नहीं किए जाते. इसलिए, यह पक्का करना कि सही विज्ञापन मैनेजर, सही संदर्भ से जुड़ा हो, मुश्किल लग सकता है.

Android के लिए IMA SDK टूल, पब्लिशर को किसी भी विज्ञापन अनुरोध के UserRequestContext फ़ील्ड में कोई भी वैल्यू या ऑब्जेक्ट पास करने की सुविधा देता है. इससे, एक से ज़्यादा विज्ञापन मैनेजर के बीच अंतर करने की प्रोसेस को आसान बनाया जा सकता है. इसके बाद, getUserRequestContext() तरीके का इस्तेमाल करके, AdsManagerLoadedEvent हैंडलर में इस वैल्यू या ऑब्जेक्ट को वापस पाया जा सकता है.

उदाहरण

...

adsLoader = sdkFactory.createAdsLoader(context, imaSdkSettings, adDisplayContainer);

Map<String, String> userContextA = new HashMap<String, String>();
Map<String, String> userContextB = new HashMap<String, String>();
userContextA.put("id", "Request A");
userContextB.put("id", "Request B");
userContextA.put("element", "videoElementA");
userContextB.put("element", "videoElementB");
adRequestA.setUserRequestContext(userContextA);
adRequestB.setUserRequestContext(userContextB);

adsLoader.addAdsLoadedListener(
    new AdsLoader.AdsLoadedListener() {
      @Override
      public void onAdsManagerLoaded(AdsManagerLoadedEvent adsManagerLoadedEvent) {
        Map<String, String> context = adsManagerLoadedEvent.getUserRequestContext();
        adsManager = adsManagerLoadedEvent.getAdsManager();
        Log.i("ImaExample", "Successfully loaded ID: " + context.get("id"));
      }
    });

adsLoader.addAdErrorListener(
    new AdErrorEvent.AdErrorListener() {
      @Override
      public void onAdError(AdErrorEvent adErrorEvent) {
        Map<String, String> context = adErrorEvent.getUserRequestContext();
        Log.i("ImaExample", "Error with AdRequest. ID: " + context.get("id"));
        Log.i("ImaExample", "Ad Error: " + adErrorEvent.getError().getMessage());
      }
    });

adsLoader.requestAds(adRequestA);
adsLoader.requestAds(adRequestB);

...