Search in sources :

Example 1 with TrackingManager

use of org.prebid.mobile.rendering.networking.tracking.TrackingManager 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 TrackingManager

use of org.prebid.mobile.rendering.networking.tracking.TrackingManager in project prebid-mobile-android by prebid.

the class CreativeModelTest method testTrackGenericEvent.

@Test
public void testTrackGenericEvent() throws Exception {
    TrackingManager trackingManager = TrackingManager.getInstance();
    TrackingManager mockTrackingManager = spy(trackingManager);
    OmEventTracker mockOmEventTracker = mock(OmEventTracker.class);
    AdConfiguration mockConfig = mock(AdConfiguration.class);
    CreativeModel creativeModel = new CreativeModel(mockTrackingManager, mockOmEventTracker, mockConfig);
    ArrayList<String> urls = new ArrayList<String>();
    urls.add("www.default.url");
    creativeModel.registerTrackingEvent(TrackingEvent.Events.DEFAULT, urls);
    creativeModel.trackDisplayAdEvent(TrackingEvent.Events.DEFAULT);
    verify(mockTrackingManager, times(1)).fireEventTrackingURLs((ArrayList<String>) anyObject());
}
Also used : TrackingManager(org.prebid.mobile.rendering.networking.tracking.TrackingManager) OmEventTracker(org.prebid.mobile.rendering.video.OmEventTracker) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with TrackingManager

use of org.prebid.mobile.rendering.networking.tracking.TrackingManager in project prebid-mobile-android by prebid.

the class CreativeModelTest method testRegisterTrackingEvent.

@Test
public void testRegisterTrackingEvent() throws Exception {
    TrackingManager trackingManager = TrackingManager.getInstance();
    OmEventTracker mockOmEventTracker = mock(OmEventTracker.class);
    AdConfiguration mockConfig = mock(AdConfiguration.class);
    CreativeModel creativeModel = new CreativeModel(trackingManager, mockOmEventTracker, mockConfig);
    ArrayList<String> urls = new ArrayList<String>();
    urls.add("www.impression.url");
    creativeModel.registerTrackingEvent(TrackingEvent.Events.IMPRESSION, urls);
    assertTrue(creativeModel.mTrackingURLs.size() == 1);
}
Also used : TrackingManager(org.prebid.mobile.rendering.networking.tracking.TrackingManager) OmEventTracker(org.prebid.mobile.rendering.video.OmEventTracker) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with TrackingManager

use of org.prebid.mobile.rendering.networking.tracking.TrackingManager in project prebid-mobile-android by prebid.

the class CreativeModelTest method testTrackImpressionEvent.

@Test
public void testTrackImpressionEvent() throws Exception {
    TrackingManager trackingManager = TrackingManager.getInstance();
    TrackingManager mockTrackingManager = spy(trackingManager);
    OmEventTracker mockOmEventTracker = mock(OmEventTracker.class);
    AdConfiguration mockConfig = mock(AdConfiguration.class);
    CreativeModel creativeModel = new CreativeModel(mockTrackingManager, mockOmEventTracker, mockConfig);
    ArrayList<String> urls = new ArrayList<String>();
    urls.add("www.impression.url");
    creativeModel.registerTrackingEvent(TrackingEvent.Events.IMPRESSION, urls);
    creativeModel.trackDisplayAdEvent(TrackingEvent.Events.IMPRESSION);
    verify(mockTrackingManager, times(1)).fireEventTrackingImpressionURLs((ArrayList<String>) anyObject());
    verify(mockOmEventTracker, times(1)).trackOmHtmlAdEvent(TrackingEvent.Events.IMPRESSION);
}
Also used : TrackingManager(org.prebid.mobile.rendering.networking.tracking.TrackingManager) OmEventTracker(org.prebid.mobile.rendering.video.OmEventTracker) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)4 TrackingManager (org.prebid.mobile.rendering.networking.tracking.TrackingManager)4 OmEventTracker (org.prebid.mobile.rendering.video.OmEventTracker)4 Test (org.junit.Test)3 AdException (org.prebid.mobile.rendering.errors.AdException)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 Companion (org.prebid.mobile.rendering.video.vast.Companion)1 Impression (org.prebid.mobile.rendering.video.vast.Impression)1 Tracking (org.prebid.mobile.rendering.video.vast.Tracking)1