Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track nurl and burl #812

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,29 @@ private void attemptAuidCreative() throws Exception {
creative = new HTMLCreative(contextReference.get(), creativeModel, omAdSessionManager, interstitialManager);
creative.setResolutionListener(new CreativeFactoryCreativeResolutionListener(this));

ArrayList<String> riUrls = new ArrayList<>();
ArrayList<String> 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<String> 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<String> 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();
Expand All @@ -163,8 +168,9 @@ private void attemptVastCreative() {
for (VideoAdEvent.Event videoEvent : VideoAdEvent.Event.values()) {
videoCreativeModel.registerVideoEvent(videoEvent, videoCreativeModel.getVideoEventUrls().get(videoEvent));
}
ArrayList<String> impressions = new ArrayList<>(1);
ArrayList<String> impressions = new ArrayList<>(2);
impressions.add(creativeModel.getImpressionUrl());
impressions.add(creativeModel.getViewableUrl());
videoCreativeModel.registerTrackingEvent(
TrackingEvent.Events.IMPRESSION,
impressions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -81,6 +86,8 @@ public void makeModels(
adConfiguration.getRewardManager().setRewardedExt(winningBid.getRewardedExt());
}

viewableUrl = winningBid.getBurl();

if (bidResponse.isVideo()) {
makeVideoModels(adConfiguration, winningBid.getAdm());
} else {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class CreativeModelsMakerVast extends CreativeModelsMaker {
private AdResponseParserVast latestVastWrapperParser;

private String adLoaderIdentifier;
private String viewableUrl;

public CreativeModelsMakerVast(
String adLoaderIdentifier,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down