-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/ap post processor #18
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package org.prebid.server.analytics.reporter.feedback; | ||
|
|
||
| import com.iab.openrtb.request.Imp; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| public class Feedback { | ||
| public Feedback(String _impressionId, String _bidder, BigDecimal _revenue) { | ||
| this._impressionId = _impressionId; | ||
| this._bidder = _bidder; | ||
| this._revenue = _revenue; | ||
| } | ||
|
|
||
| private int _siteId; | ||
|
|
||
| private String _country; | ||
|
|
||
| private String _platform; | ||
|
|
||
| private String _networkAdUnit; | ||
|
|
||
| private String _impressionId; | ||
|
|
||
| private String _bidder; | ||
|
|
||
| private BigDecimal _revenue; | ||
|
|
||
| public void sendFeedback() | ||
| { | ||
| //send feedback here | ||
| } | ||
|
|
||
|
|
||
| public String getImpId() { | ||
| return this._impressionId; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| package org.prebid.server.analytics.reporter.feedback; | ||
|
|
||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| import com.iab.openrtb.request.BidRequest; | ||
| import com.iab.openrtb.request.Imp; | ||
| import com.iab.openrtb.response.Bid; | ||
| import io.vertx.core.Future; | ||
| import io.vertx.core.json.JsonObject; | ||
| import org.prebid.server.analytics.AnalyticsReporter; | ||
| import org.prebid.server.analytics.model.AuctionEvent; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| public class FeedbackAnalyticsReporter implements AnalyticsReporter { | ||
| @Override | ||
| public <T> Future<Void> processEvent(T event) { | ||
|
|
||
| if (event instanceof AuctionEvent auctionEvent) { | ||
|
|
||
| List<Imp> bidRequests = auctionEvent.getAuctionContext().getBidRequest().getImp(); | ||
|
|
||
| Map<String, String> requestProperties = new HashMap<>(); | ||
| try { | ||
| bidRequests.forEach(bid -> { | ||
| requestProperties.put(bid.getId(), String.valueOf(bid.getExt().get("context").get("data").get("adslot"))); | ||
| }); | ||
|
|
||
| auctionEvent.getBidResponse().getSeatbid().forEach(seatBid -> { | ||
| Bid bid = seatBid.getBid().get(0); | ||
| String impId = bid.getImpid(); | ||
| String networkAdUnit = requestProperties.get(impId); | ||
| Feedback fb = new Feedback(networkAdUnit, seatBid.getSeat(), seatBid.getBid().get(0).getPrice()); | ||
| fb.sendFeedback(); | ||
| }); | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| ex.getMessage(); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
|
|
||
| //add dat | ||
| return Future.succeededFuture(); | ||
| } | ||
|
|
||
| @Override | ||
| public int vendorId() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "Feedback Analytics Reporter!"; | ||
|
|
||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| package org.prebid.server.auction; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonProcessingException; | ||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.fasterxml.jackson.databind.node.ObjectNode; | ||
| import com.iab.openrtb.request.BidRequest; | ||
| import com.iab.openrtb.response.BidResponse; | ||
| import com.iab.openrtb.response.SeatBid; | ||
| import io.vertx.core.Future; | ||
| import io.vertx.core.json.JsonObject; | ||
| import org.prebid.server.cookie.UidsCookie; | ||
| import org.prebid.server.model.HttpRequestContext; | ||
| import org.prebid.server.proto.response.AmpResponse; | ||
| import org.prebid.server.settings.model.Account; | ||
|
|
||
| import javax.management.ObjectName; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
|
|
||
| public class ApPostProcessor implements BidResponsePostProcessor { | ||
|
|
||
| public ApPostProcessor() | ||
| { | ||
| System.out.println("in constructor"); | ||
| } | ||
|
|
||
| @Override | ||
| public Future<BidResponse> postProcess(HttpRequestContext httpRequest, UidsCookie uidsCookie, | ||
| BidRequest bidRequest, BidResponse bidResponse, Account account) { | ||
|
|
||
| List<SeatBid> seatBids = bidResponse.getSeatbid(); | ||
| if(!seatBids.isEmpty()) { | ||
| seatBids.forEach(seatBid -> { | ||
| try { | ||
| modifyBidTargeting(seatBid); | ||
| } catch (JsonProcessingException e) { | ||
| return Future.succeededFuture(bidResponse); | ||
| } | ||
|
|
||
| }); | ||
| } | ||
|
|
||
|
|
||
| return Future.succeededFuture(bidResponse); | ||
| } | ||
|
|
||
|
|
||
| public SeatBid modifyBidTargeting(SeatBid ogseatBid) throws JsonProcessingException { | ||
| ogseatBid.getBid().forEach(bid -> { | ||
| JsonObject newPrebid = JsonObject.mapFrom(bid.getExt().get("prebid")); | ||
| JsonObject targeting = newPrebid.getJsonObject("targeting"); | ||
| targeting.put("ap_hb_pb",targeting.getValue("hb_pb")); | ||
| targeting.remove("hb_pb"); | ||
| targeting.put("ap_hb_bidder",targeting.getValue("hb_bidder")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be hb_ap_bidder. |
||
| targeting.remove("hb_bidder"); | ||
| targeting.put("ap_hb_size",targeting.getValue("hb_size")); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be hb_ap_size. |
||
| targeting.remove("hb_size"); | ||
|
|
||
| JsonNode newPrebidNode = null; | ||
| try { | ||
| newPrebidNode = new ObjectMapper().readTree(newPrebid.toString()); | ||
| } catch (JsonProcessingException e) { | ||
|
|
||
| } | ||
|
|
||
| bid.getExt().replace("prebid",newPrebidNode); | ||
|
|
||
|
|
||
| }); | ||
|
|
||
| return ogseatBid; | ||
| } | ||
|
|
||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be hb_ap_pb.
Also move these strings to constants