Search in sources :

Example 1 with Companion

use of org.prebid.mobile.rendering.video.vast.Companion in project prebid-mobile-android by prebid.

the class CreativeModelsMakerVast method makeModelsContinued.

private void makeModelsContinued() {
    try {
        // TODO: If we want to support a VAST Buffet, we'll need to put the following in a
        // TODO: loop and make a model for each Ad object in the Buffet
        // TODO: Until then, we'll only make one model
        /**
         * We pre parse the impressions and trackings for faster reading at
         * video time. DO NOT REMOVE THESE LINES
         */
        mRootVastParser.getAllTrackings(mRootVastParser, 0);
        mRootVastParser.getImpressions(mRootVastParser, 0);
        mRootVastParser.getClickTrackings(mRootVastParser, 0);
        final String videoErrorUrl = mRootVastParser.getError(mRootVastParser, 0);
        final String vastClickThroughUrl = mRootVastParser.getClickThroughUrl(mRootVastParser, 0);
        final String videoDuration = mLatestVastWrapperParser.getVideoDuration(mLatestVastWrapperParser, 0);
        final String skipOffset = mLatestVastWrapperParser.getSkipOffset(mLatestVastWrapperParser, 0);
        final AdVerifications adVerifications = mRootVastParser.getAdVerification(mLatestVastWrapperParser, 0);
        Result result = new Result();
        result.loaderIdentifier = mAdLoaderIdentifier;
        TrackingManager trackingManager = TrackingManager.getInstance();
        OmEventTracker omEventTracker = new OmEventTracker();
        VideoCreativeModel videoModel = new VideoCreativeModel(trackingManager, omEventTracker, mAdConfiguration);
        videoModel.setName(VIDEO_CREATIVE_TAG);
        videoModel.setMediaUrl(mLatestVastWrapperParser.getMediaFileUrl(mLatestVastWrapperParser, 0));
        videoModel.setMediaDuration(Utils.getMsFrom(videoDuration));
        videoModel.setSkipOffset(Utils.getMsFrom(skipOffset));
        videoModel.setAdVerifications(adVerifications);
        videoModel.setAuid(mRootVastParser.getVast().getAds().get(0).getId());
        videoModel.setWidth(mLatestVastWrapperParser.getWidth());
        videoModel.setHeight(mLatestVastWrapperParser.getHeight());
        // put tracking urls into element.
        for (VideoAdEvent.Event videoEvent : VideoAdEvent.Event.values()) {
            videoModel.getVideoEventUrls().put(videoEvent, mRootVastParser.getTrackingByType(videoEvent));
        }
        // put impression urls into element
        ArrayList<String> impUrls = new ArrayList<>();
        for (Impression impression : mRootVastParser.getImpressions()) {
            impUrls.add(impression.getValue());
        }
        videoModel.getVideoEventUrls().put(VideoAdEvent.Event.AD_IMPRESSION, impUrls);
        // put click urls into element
        ArrayList<String> clickTrackingUrls = new ArrayList<>();
        for (ClickTracking clickTracking : mRootVastParser.getClickTrackings()) {
            clickTrackingUrls.add(clickTracking.getValue());
        }
        videoModel.getVideoEventUrls().put(VideoAdEvent.Event.AD_CLICK, clickTrackingUrls);
        // put error vastURL into element
        ArrayList<String> errorUrls = new ArrayList<>();
        errorUrls.add(videoErrorUrl);
        videoModel.getVideoEventUrls().put(VideoAdEvent.Event.AD_ERROR, errorUrls);
        // put click through url into element
        videoModel.setVastClickthroughUrl(vastClickThroughUrl);
        result.creativeModels = new ArrayList<>();
        result.creativeModels.add(videoModel);
        CreativeModel endCardModel = new CreativeModel(trackingManager, omEventTracker, mAdConfiguration);
        endCardModel.setName(HTML_CREATIVE_TAG);
        endCardModel.setHasEndCard(true);
        // Create CompanionAd object
        Companion companionAd = AdResponseParserVast.getCompanionAd(mLatestVastWrapperParser.getVast().getAds().get(0).getInline());
        if (companionAd != null) {
            switch(AdResponseParserVast.getCompanionResourceFormat(companionAd)) {
                case RESOURCE_FORMAT_HTML:
                    endCardModel.setHtml(companionAd.getHtmlResource().getValue());
                    break;
                case RESOURCE_FORMAT_IFRAME:
                    endCardModel.setHtml(companionAd.getIFrameResource().getValue());
                    break;
                case RESOURCE_FORMAT_STATIC:
                    endCardModel.setHtml(String.format("<div id=\"ad\" align=\"center\">\n" + "<a href=\"%s\">\n" + "<img src=\"%s\"></a>\n" + "</div>", companionAd.getCompanionClickThrough().getValue(), companionAd.getStaticResource().getValue()));
                    break;
            }
            if (companionAd.getCompanionClickThrough() != null) {
                endCardModel.setClickUrl(companionAd.getCompanionClickThrough().getValue());
            }
            if (companionAd.getCompanionClickTracking() != null) {
                clickTrackingUrls = new ArrayList<>();
                clickTrackingUrls.add(companionAd.getCompanionClickTracking().getValue());
                endCardModel.registerTrackingEvent(TrackingEvent.Events.CLICK, clickTrackingUrls);
            }
            Tracking creativeViewTracking = AdResponseParserVast.findTracking(companionAd.getTrackingEvents());
            if (creativeViewTracking != null && Utils.isNotBlank(creativeViewTracking.getValue())) {
                ArrayList<String> creativeViewTrackingUrls = new ArrayList<>();
                creativeViewTrackingUrls.add(creativeViewTracking.getValue());
                endCardModel.registerTrackingEvent(TrackingEvent.Events.IMPRESSION, creativeViewTrackingUrls);
            }
            endCardModel.setWidth(Integer.parseInt(companionAd.getWidth()));
            endCardModel.setHeight(Integer.parseInt(companionAd.getHeight()));
            endCardModel.setAdConfiguration(new AdConfiguration());
            endCardModel.getAdConfiguration().setAdUnitIdentifierType(AdConfiguration.AdUnitIdentifierType.INTERSTITIAL);
            endCardModel.setRequireImpressionUrl(false);
            result.creativeModels.add(endCardModel);
            // Flag that video creative has a corresponding end card
            videoModel.setHasEndCard(true);
        }
        mAdConfiguration.setInterstitialSize(videoModel.getWidth() + "x" + videoModel.getHeight());
        mListener.onCreativeModelReady(result);
    } catch (Exception e) {
        LogUtil.error(TAG, "Video failed with: " + e.getMessage());
        notifyErrorListener("Video failed: " + e.getMessage());
    }
}
Also used : ClickTracking(org.prebid.mobile.rendering.video.vast.ClickTracking) ClickTracking(org.prebid.mobile.rendering.video.vast.ClickTracking) Tracking(org.prebid.mobile.rendering.video.vast.Tracking) TrackingManager(org.prebid.mobile.rendering.networking.tracking.TrackingManager) VideoCreativeModel(org.prebid.mobile.rendering.video.VideoCreativeModel) ArrayList(java.util.ArrayList) Impression(org.prebid.mobile.rendering.video.vast.Impression) AdException(org.prebid.mobile.rendering.errors.AdException) Companion(org.prebid.mobile.rendering.video.vast.Companion) OmEventTracker(org.prebid.mobile.rendering.video.OmEventTracker) VideoAdEvent(org.prebid.mobile.rendering.video.VideoAdEvent) AdVerifications(org.prebid.mobile.rendering.video.vast.AdVerifications) VideoCreativeModel(org.prebid.mobile.rendering.video.VideoCreativeModel)

Example 2 with Companion

use of org.prebid.mobile.rendering.video.vast.Companion in project prebid-mobile-android by prebid.

the class AdResponseParserVastTest method testGetCompanionAd.

@Test
public void testGetCompanionAd() {
    InLine mockInLine;
    ArrayList<Companion> companions;
    Companion mockCompanionA;
    Companion mockCompanionB;
    Companion result;
    // Null creatives
    mockInLine = setupInLine();
    mockInLine.setCreatives(null);
    result = AdResponseParserVast.getCompanionAd(mockInLine);
    assertNull(result);
    // Empty creatives list
    mockInLine = setupInLine();
    mockInLine.setCreatives(new ArrayList<>());
    result = AdResponseParserVast.getCompanionAd(mockInLine);
    assertNull(result);
    // Empty companion ad list
    mockInLine = setupInLine();
    mockInLine.getCreatives().get(0).setCompanionAds(new ArrayList<>());
    result = AdResponseParserVast.getCompanionAd(mockInLine);
    assertNull(result);
    // One companion
    mockInLine = setupInLine();
    companions = mockInLine.getCreatives().get(0).getCompanionAds();
    mockCompanionA = mock(Companion.class);
    companions.add(mockCompanionA);
    result = AdResponseParserVast.getCompanionAd(mockInLine);
    assertEquals(mockCompanionA, result);
    // Companion B format better than Companion A format
    mockInLine = setupInLine();
    companions = mockInLine.getCreatives().get(0).getCompanionAds();
    mockCompanionA = mock(Companion.class);
    when(mockCompanionA.getWidth()).thenReturn("2");
    when(mockCompanionA.getHeight()).thenReturn("2");
    when(mockCompanionA.getStaticResource()).thenReturn(mock(StaticResource.class));
    companions.add(mockCompanionA);
    mockCompanionB = mock(Companion.class);
    when(mockCompanionB.getWidth()).thenReturn("1");
    when(mockCompanionB.getHeight()).thenReturn("1");
    when(mockCompanionB.getHtmlResource()).thenReturn(mock(HTMLResource.class));
    companions.add(mockCompanionB);
    result = AdResponseParserVast.getCompanionAd(mockInLine);
    assertEquals(mockCompanionB, result);
    // Same format for Companion A & B, but B has better resolution
    mockInLine = setupInLine();
    companions = mockInLine.getCreatives().get(0).getCompanionAds();
    mockCompanionA = mock(Companion.class);
    when(mockCompanionA.getWidth()).thenReturn("1");
    when(mockCompanionA.getHeight()).thenReturn("1");
    when(mockCompanionA.getStaticResource()).thenReturn(mock(StaticResource.class));
    companions.add(mockCompanionA);
    mockCompanionB = mock(Companion.class);
    when(mockCompanionB.getWidth()).thenReturn("2");
    when(mockCompanionB.getHeight()).thenReturn("2");
    when(mockCompanionB.getStaticResource()).thenReturn(mock(StaticResource.class));
    companions.add(mockCompanionB);
    result = AdResponseParserVast.getCompanionAd(mockInLine);
    assertEquals(mockCompanionB, result);
}
Also used : Companion(org.prebid.mobile.rendering.video.vast.Companion) HTMLResource(org.prebid.mobile.rendering.video.vast.HTMLResource) StaticResource(org.prebid.mobile.rendering.video.vast.StaticResource) InLine(org.prebid.mobile.rendering.video.vast.InLine) Test(org.junit.Test)

Aggregations

Companion (org.prebid.mobile.rendering.video.vast.Companion)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 AdException (org.prebid.mobile.rendering.errors.AdException)1 TrackingManager (org.prebid.mobile.rendering.networking.tracking.TrackingManager)1 OmEventTracker (org.prebid.mobile.rendering.video.OmEventTracker)1 VideoAdEvent (org.prebid.mobile.rendering.video.VideoAdEvent)1 VideoCreativeModel (org.prebid.mobile.rendering.video.VideoCreativeModel)1 AdVerifications (org.prebid.mobile.rendering.video.vast.AdVerifications)1 ClickTracking (org.prebid.mobile.rendering.video.vast.ClickTracking)1 HTMLResource (org.prebid.mobile.rendering.video.vast.HTMLResource)1 Impression (org.prebid.mobile.rendering.video.vast.Impression)1 InLine (org.prebid.mobile.rendering.video.vast.InLine)1 StaticResource (org.prebid.mobile.rendering.video.vast.StaticResource)1 Tracking (org.prebid.mobile.rendering.video.vast.Tracking)1