use of org.prebid.mobile.rendering.video.OmEventTracker 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());
}
}
use of org.prebid.mobile.rendering.video.OmEventTracker 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());
}
use of org.prebid.mobile.rendering.video.OmEventTracker 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);
}
use of org.prebid.mobile.rendering.video.OmEventTracker in project prebid-mobile-android by prebid.
the class CreativeModelMakerBids method parseAcj.
private void parseAcj(AdConfiguration adConfiguration, BidResponse bidResponse) {
CreativeModelsMaker.Result result = new CreativeModelsMaker.Result();
result.creativeModels = new ArrayList<>();
Bid bid = bidResponse.getWinningBid();
String adHtml = getAdHtml(adConfiguration, bid);
CreativeModel model = new CreativeModel(TrackingManager.getInstance(), new OmEventTracker(), adConfiguration);
model.setName("HTML");
model.setHtml(adHtml);
model.setWidth(bid != null ? bid.getWidth() : 0);
model.setHeight(bid != null ? bid.getHeight() : 0);
model.setRequireImpressionUrl(false);
adConfiguration.setInterstitialSize(model.getWidth(), model.getHeight());
result.creativeModels.add(model);
result.transactionState = "bid";
mListener.onCreativeModelReady(result);
}
use of org.prebid.mobile.rendering.video.OmEventTracker 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);
}
Aggregations