Enabling VAST ads

A VAST ad is a set of VideoAd objects that contain video ads. Video ads conform to the VAST (Video Ad Serving Template) standard.

The Yandex Mobile Ads SDK supports VAST 2.0 and 3.0.

To enable VAST ads:
  1. Load the Vmap object that contains a set of AdBreak objects and the Extensions list.
  2. Load video ads (a set of VideoAd objects) for the received AdBreak objects.

Loading VMAP

  1. Call the loadVmap method for the VmapLoader object. The loadVmap method accepts as parameters the Context and VmapRequestConfiguration object (its arguments are the mandatory PAGE_ID parameter and the optional CATEGORY_ID parameter).

    final VmapLoader vmapLoader = new VmapLoader(context);
    final VmapRequestConfiguration vmapRequestConfiguration =
            new VmapRequestConfiguration.Builder(PAGE_ID).setCategory(CATEGORY_ID).build();
    vmapLoader.loadVmap(context, vmapRequestConfiguration);
  2. To get the result of a request for the Vmap object, subscribe the VmapLoader.OnVmapLoadedListener.

    vmapLoader.setOnVmapLoadedListener(new VmapLoader.OnVmapLoadedListener() {
        @Override
        public void onVmapLoaded(@NonNull final Vmap vmap) {
        	final List<AdBreak> adBreaks = vmap.getAdBreaks();
            final List<Extension> extensions = vmap.getExtensions();
            
            //load video ads
        }
    
        @Override
        public void onVmapFailedToLoad(@NonNull final VmapError error) {
    
        }
    });
  3. The received Vmap object contains a set of AdBreak objects required for loading video ads and a variety of settings that can be useful for the player.

Loading video ads

  1. Call the loadAd method for the VideoAdLoader object. The loadAd method accepts the Context and a VastRequestConfiguration object as parameters. VastRequestConfiguration accepts the previously received AdBreak as an argument.

    final VideoAdLoader videoAdLoader = new VideoAdLoader(context);
    final VastRequestConfiguration vastRequestConfiguration =
            new VastRequestConfiguration.Builder(mAdBreak).build();
    mVideoAdLoader.loadAd(context, vastRequestConfiguration);
  2. Apart from the AdBreak object, VastRequestConfiguration can optionally accept a set of parameters obtained from Adfox. Using the Adfox parameters, the SDK can send a targeted request.

    final Map<String, String> parameters = new HashMap<>();
    parameters.put("puid1", "example1");
    parameters.put("puid2", "example2");
    
    final VastRequestConfiguration vastRequestConfiguration =
            new VastRequestConfiguration.Builder(mAdBreak)
                    .setParameters(parameters).build();
    mVideoAdLoader.loadAd(context, vastRequestConfiguration);
  3. To get the result of a request for video ads, subscribe the VideoAdLoader.OnVideoAdLoadedListener.

    videoAdLoader.setOnVideoAdLoadedListener(new VideoAdLoader.OnVideoAdLoadedListener() {
        @Override
        public void onRawVideoAdLoaded(@Nullable final String response) {
            //raw vast processing
        }
    
        @Override
        public void onVideoAdLoaded(@NonNull final List<VideoAd> videoAds) {
        	videoAds.get(0).getAdTitle();
            videoAds.get(0).getAdSystem();
            videoAds.get(0).getDescription();
            videoAds.get(0).getSurvey();
            videoAds.get(0).getCreatives().get(0).getMediaFiles();
            videoAds.get(0).getTrackingEvents();
        }
    
        @Override
        public void onVideoAdFailedToLoad(@NonNull final VideoAdError videoAdError) {
    
        }
    });
  4. A response is considered successful if it contains a list of VideoAd objects. Each object contains VAST ads.