diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java index fae031209..020c6a70e 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java @@ -37,9 +37,11 @@ import org.prebid.mobile.api.exceptions.AdException; import org.prebid.mobile.api.original.OnFetchDemandResult; import org.prebid.mobile.configuration.AdUnitConfiguration; +import org.prebid.mobile.rendering.bidding.data.bid.Bid; import org.prebid.mobile.rendering.bidding.data.bid.BidResponse; import org.prebid.mobile.rendering.bidding.listeners.BidRequesterListener; import org.prebid.mobile.rendering.bidding.loader.BidLoader; +import org.prebid.mobile.rendering.networking.tracking.ServerConnection; import org.prebid.mobile.rendering.sdk.PrebidContextHolder; import org.prebid.mobile.tasksmanager.TasksManager; diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java index f2295545c..f2a8e8c74 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java @@ -8,8 +8,10 @@ import org.prebid.mobile.api.data.AdFormat; import org.prebid.mobile.api.exceptions.AdException; import org.prebid.mobile.configuration.NativeAdUnitConfiguration; +import org.prebid.mobile.rendering.bidding.data.bid.Bid; import org.prebid.mobile.rendering.bidding.data.bid.BidResponse; import org.prebid.mobile.rendering.bidding.listeners.BidRequesterListener; +import org.prebid.mobile.rendering.networking.tracking.ServerConnection; import java.util.EnumSet; import java.util.HashMap; @@ -49,6 +51,7 @@ public void onFetchCompleted(BidResponse response) { String cacheId = CacheManager.save(response.getWinningBidJson()); Util.saveCacheId(cacheId, adObject); + notifyWinEvent(response); originalListener.onComplete(ResultCode.SUCCESS); } @@ -234,5 +237,13 @@ public NativeAdUnitConfiguration getNativeConfiguration() { public void setOrtbConfig(@Nullable String ortbConfig) {configuration.setOrtbConfig(ortbConfig);} + private void notifyWinEvent(BidResponse response) { + if (response == null) return; + + Bid winningBid = response.getWinningBid(); + if (winningBid == null) return; + + ServerConnection.fireAndForget(winningBid.getNurl()); + } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/loading/CreativeFactory.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/loading/CreativeFactory.java index 069ad7f9e..c9f3092f5 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/loading/CreativeFactory.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/loading/CreativeFactory.java @@ -122,24 +122,29 @@ private void attemptAuidCreative() throws Exception { creative = new HTMLCreative(contextReference.get(), creativeModel, omAdSessionManager, interstitialManager); creative.setResolutionListener(new CreativeFactoryCreativeResolutionListener(this)); - ArrayList riUrls = new ArrayList<>(); - ArrayList rcUrls = new ArrayList<>(); - - //get the tracking url & do the registration here. add in the tracking stuff here - //This needs to be more generalized and allow for multiple click urls - if (!creativeModel.isRequireImpressionUrl() || Utils.isNotBlank(creativeModel.getImpressionUrl())) { - if (!TextUtils.isEmpty(creativeModel.getImpressionUrl())) { - riUrls.add(creativeModel.getImpressionUrl()); - creativeModel.registerTrackingEvent(TrackingEvent.Events.IMPRESSION, riUrls); - } - // - if (!TextUtils.isEmpty(creativeModel.getClickUrl())) { - rcUrls.add(creativeModel.getClickUrl()); - creativeModel.registerTrackingEvent(TrackingEvent.Events.CLICK, rcUrls); - } - } else { + ArrayList impressionUrls = new ArrayList<>(); + String viewableUrl = creativeModel.getViewableUrl(); + if (Utils.isNotBlank(viewableUrl)) { + impressionUrls.add(viewableUrl); + } + String impressionUrl = creativeModel.getImpressionUrl(); + if (Utils.isNotBlank(impressionUrl)) { + impressionUrls.add(impressionUrl); + } + + + if (creativeModel.isRequireImpressionUrl() && impressionUrls.isEmpty()) { listener.onFailure(new AdException(AdException.INTERNAL_ERROR, "Tracking info not found")); + } else { + creativeModel.registerTrackingEvent(TrackingEvent.Events.IMPRESSION, impressionUrls); + + ArrayList clickUrls = new ArrayList<>(); + if (Utils.isNotBlank(creativeModel.getClickUrl())) { + clickUrls.add(creativeModel.getClickUrl()); + } + creativeModel.registerTrackingEvent(TrackingEvent.Events.CLICK, clickUrls); } + long creativeDownloadTimeout = PrebidMobile.getCreativeFactoryTimeout(); if (creativeModel.getAdConfiguration().isAdType(AdFormat.INTERSTITIAL)) { creativeDownloadTimeout = PrebidMobile.getCreativeFactoryTimeoutPreRenderContent(); @@ -163,8 +168,9 @@ private void attemptVastCreative() { for (VideoAdEvent.Event videoEvent : VideoAdEvent.Event.values()) { videoCreativeModel.registerVideoEvent(videoEvent, videoCreativeModel.getVideoEventUrls().get(videoEvent)); } - ArrayList impressions = new ArrayList<>(1); + ArrayList impressions = new ArrayList<>(2); impressions.add(creativeModel.getImpressionUrl()); + impressions.add(creativeModel.getViewableUrl()); videoCreativeModel.registerTrackingEvent( TrackingEvent.Events.IMPRESSION, impressions diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModel.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModel.java index 30f98e18d..e0ade9ac0 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModel.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModel.java @@ -67,6 +67,7 @@ public class CreativeModel { //all - resolved ri url of an ad private String impressionUrl; + private String viewableUrl; // Determines whether an impression is needed // For end cards, an impression is not necessary @@ -217,6 +218,14 @@ public void setImpressionUrl(String impressionUrl) { this.impressionUrl = impressionUrl; } + public String getViewableUrl() { + return viewableUrl; + } + + public void setViewableUrl(String viewableUrl) { + this.viewableUrl = viewableUrl; + } + public boolean isRequireImpressionUrl() { return requireImpressionUrl; } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModelMakerBids.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModelMakerBids.java index 34399c5a1..73a54e7ac 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModelMakerBids.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModelMakerBids.java @@ -19,6 +19,8 @@ import android.content.Context; import android.text.TextUtils; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import org.prebid.mobile.LogUtil; import org.prebid.mobile.api.data.AdFormat; import org.prebid.mobile.api.exceptions.AdException; @@ -39,6 +41,9 @@ public class CreativeModelMakerBids { private static final String TAG = CreativeModelMakerBids.class.getSimpleName(); + @Nullable + private String viewableUrl; + @NonNull private final AdLoadListener listener; private final VastParserExtractor parserExtractor = new VastParserExtractor(this::handleExtractorResult); @@ -81,6 +86,8 @@ public void makeModels( adConfiguration.getRewardManager().setRewardedExt(winningBid.getRewardedExt()); } + viewableUrl = winningBid.getBurl(); + if (bidResponse.isVideo()) { makeVideoModels(adConfiguration, winningBid.getAdm()); } else { @@ -117,6 +124,7 @@ private void parseAcj(AdUnitConfiguration adConfiguration, BidResponse bidRespon model.setWidth(bid != null ? bid.getWidth() : 0); model.setHeight(bid != null ? bid.getHeight() : 0); model.setRequireImpressionUrl(false); + model.setViewableUrl(viewableUrl); adConfiguration.setInterstitialSize(model.getWidth(), model.getHeight()); result.creativeModels.add(model); @@ -146,7 +154,8 @@ private void handleExtractorResult(VastExtractorResult result) { return; } - CreativeModelsMaker modelsMaker = new CreativeModelsMakerVast(loadIdentifier, listener); - modelsMaker.makeModels(adConfiguration, result.getVastResponseParserArray()); + CreativeModelsMakerVast vastModelMaker = new CreativeModelsMakerVast(loadIdentifier, listener); + vastModelMaker.setViewableUrl(viewableUrl); + vastModelMaker.makeModels(adConfiguration, result.getVastResponseParserArray()); } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModelsMakerVast.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModelsMakerVast.java index cad0b910a..f3c942496 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModelsMakerVast.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/CreativeModelsMakerVast.java @@ -52,6 +52,7 @@ public class CreativeModelsMakerVast extends CreativeModelsMaker { private AdResponseParserVast latestVastWrapperParser; private String adLoaderIdentifier; + private String viewableUrl; public CreativeModelsMakerVast( String adLoaderIdentifier, @@ -91,6 +92,10 @@ public void makeModels(AdUnitConfiguration adConfiguration, AdResponseParserBase makeModelsContinued(); } + public void setViewableUrl(String url) { + this.viewableUrl = url; + } + private void makeModelsContinued() { try { // TODO: If we want to support a VAST Buffet, we'll need to put the following in a @@ -129,6 +134,7 @@ private void makeModelsContinued() { videoModel.setAuid(rootVastParser.getVast().getAds().get(0).getId()); videoModel.setWidth(latestVastWrapperParser.getWidth()); videoModel.setHeight(latestVastWrapperParser.getHeight()); + videoModel.setViewableUrl(viewableUrl); //put tracking urls into element. for (VideoAdEvent.Event videoEvent : VideoAdEvent.Event.values()) { videoModel.getVideoEventUrls().put(videoEvent, rootVastParser.getTrackingByType(videoEvent)); diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/video/VideoCreative.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/video/VideoCreative.java index a1bd4d866..77200929a 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/video/VideoCreative.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/video/VideoCreative.java @@ -32,6 +32,7 @@ import org.prebid.mobile.rendering.listeners.VideoCreativeViewListener; import org.prebid.mobile.rendering.loading.FileDownloadListener; import org.prebid.mobile.rendering.models.CreativeVisibilityTracker; +import org.prebid.mobile.rendering.models.TrackingEvent; import org.prebid.mobile.rendering.models.internal.InternalPlayerState; import org.prebid.mobile.rendering.models.internal.VisibilityTrackerOption; import org.prebid.mobile.rendering.models.ntv.NativeEventTracker; @@ -407,6 +408,7 @@ private void notifyCreativeViewListener(VideoAdEvent.Event trackingEvent) { switch (trackingEvent) { case AD_START: trackVideoAdStart(); + model.trackEventNamed(TrackingEvent.Events.IMPRESSION); break; case AD_CLICK: creativeViewListener.creativeWasClicked(this, videoCreativeView.getCallToActionUrl());