Skip to content

Commit

Permalink
transfer greenbidsId in ATag between RTD and analytics adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
EvgeniiMunin committed Jul 1, 2024
1 parent 165c543 commit 58ee63f
Show file tree
Hide file tree
Showing 18 changed files with 349 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ private InvocationResult<AllProcessedBidResponsesPayload> toInvocationResult(
.payloadUpdate(payload -> AllProcessedBidResponsesPayloadImpl.of(
Stream.concat(bidderResponsesWithoutIssues.stream(), notScannedBidderResponses.stream()).toList()));

System.out.println("ConfiantAdQualityBidResponsesScanHook/ InvocationResult: " + resultBuilder.build());

return resultBuilder.build();
}

Expand Down
2 changes: 1 addition & 1 deletion extra/modules/greenbids-real-time-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.prebid.server.hooks.modules</groupId>
<artifactId>all-modules</artifactId>
<version>3.3.0-SNAPSHOT</version>
<version>3.4.0-SNAPSHOT</version>
</parent>

<artifactId>greenbids-real-time-data</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.model;

import lombok.Value;

import java.util.Map;

@Value(staticConstructor = "of")
public class AnalyticsResult {

String status;

Map<String, Object> values;

String bidder;

String impId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.model;

import lombok.Value;

import java.util.List;

@Value(staticConstructor = "of")
public class RtdFilterResult {

String value;

List<AnalyticsResult> analyticsResults;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@
import com.iab.openrtb.request.BidRequest;
import com.iab.openrtb.request.Imp;
import io.vertx.core.Future;
import org.apache.commons.collections4.CollectionUtils;
import org.prebid.server.auction.model.AuctionContext;
import org.prebid.server.exception.PreBidException;
import org.prebid.server.hooks.execution.v1.auction.AuctionRequestPayloadImpl;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.AnalyticsResult;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.GreenbidsUserAgent;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.OnnxModelRunner;
import org.prebid.server.hooks.modules.greenbids.real.time.data.model.ThrottlingMessage;
import org.prebid.server.hooks.modules.greenbids.real.time.data.v1.model.InvocationResultImpl;
import org.prebid.server.hooks.modules.greenbids.real.time.data.v1.model.analytics.ActivityImpl;
import org.prebid.server.hooks.modules.greenbids.real.time.data.v1.model.analytics.AppliedToImpl;
import org.prebid.server.hooks.modules.greenbids.real.time.data.v1.model.analytics.ResultImpl;
import org.prebid.server.hooks.modules.greenbids.real.time.data.v1.model.analytics.TagsImpl;
import org.prebid.server.hooks.v1.InvocationAction;
import org.prebid.server.hooks.v1.InvocationResult;
import org.prebid.server.hooks.v1.InvocationStatus;
import org.prebid.server.hooks.v1.analytics.Result;
import org.prebid.server.hooks.v1.analytics.Tags;
import org.prebid.server.hooks.v1.auction.AuctionInvocationContext;
import org.prebid.server.hooks.v1.auction.AuctionRequestPayload;
import org.prebid.server.hooks.v1.auction.ProcessedAuctionRequestHook;
Expand All @@ -31,6 +39,7 @@
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand All @@ -42,7 +51,7 @@
public class GreenbidsRealTimeDataProcessedAuctionRequestHook implements ProcessedAuctionRequestHook {

private static final String CODE = "greenbids-real-time-data-processed-auction-request-hook";
private static final String ACTIVITY = "isKeptInAuction";
private static final String ACTIVITY = "greenbids-filter";
private static final String SUCCESS_STATUS = "success";

private final ObjectMapper mapper;
Expand Down Expand Up @@ -149,6 +158,10 @@ public Future<InvocationResult<AuctionRequestPayload>> call(
List<Imp> impsWithFilteredBidders = updateImps(bidRequest, impsBiddersFilterMap);
BidRequest updatedBidRequest = bidRequest.toBuilder().imp(impsWithFilteredBidders).build();

final String greenbidsId = "test-greenbids-id"; //UUID.randomUUID().toString();

final AnalyticsResult analyticsResult = AnalyticsResult.of(
"success", Map.of("greenbidsId", greenbidsId), null, null);

// update invocation result
InvocationResult<AuctionRequestPayload> invocationResult = InvocationResultImpl.<AuctionRequestPayload>builder()
Expand All @@ -158,19 +171,52 @@ public Future<InvocationResult<AuctionRequestPayload>> call(
.debugMessages(null)
.analyticsTags(null)
.payloadUpdate(payload -> AuctionRequestPayloadImpl.of(updatedBidRequest))
.analyticsTags(toAnalyticsTags(Collections.singletonList(analyticsResult)))
.build();

System.out.println(
"GreenbidsRealTimeDataProcessedAuctionRequestHook/call" + "\n" +
"impsBiddersFilterMap: " + impsBiddersFilterMap + "\n" +
"impsWithFilteredBidders: " + impsWithFilteredBidders + "\n" +
"updatedBidRequest: " + updatedBidRequest + "\n" +
"AnalyticsTag: " + toAnalyticsTags(Collections.singletonList(analyticsResult)) + "\n" +
"invocationResult: " + invocationResult
);

return Future.succeededFuture(invocationResult);
}

private Tags toAnalyticsTags(List<AnalyticsResult> analyticsResults) {
if (CollectionUtils.isEmpty(analyticsResults)) {
return null;
}

return TagsImpl.of(Collections.singletonList(ActivityImpl.of(
ACTIVITY,
SUCCESS_STATUS,
toResults(analyticsResults))));
}

private List<Result> toResults(List<AnalyticsResult> analyticsResults) {
return analyticsResults.stream()
.map(this::toResult)
.toList();
}

private Result toResult(AnalyticsResult analyticsResult) {
return ResultImpl.of(
analyticsResult.getStatus(),
toObjectNode(analyticsResult.getValues()),
AppliedToImpl.builder()
.bidders(Collections.singletonList(analyticsResult.getBidder()))
.impIds(Collections.singletonList(analyticsResult.getImpId()))
.build());
}

private ObjectNode toObjectNode(Map<String, Object> values) {
return values != null ? mapper.valueToTree(values) : null;
}

private List<Imp> updateImps(BidRequest bidRequest, Map<String, Map<String, Boolean>> impsBiddersFilterMap) {
return bidRequest.getImp().stream()
.map(imp -> updateImp(imp, impsBiddersFilterMap.get(imp.getId())))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.v1.model.analytics;

import lombok.Value;
import lombok.experimental.Accessors;
import org.prebid.server.hooks.v1.analytics.Activity;
import org.prebid.server.hooks.v1.analytics.Result;

import java.util.List;

@Accessors(fluent = true)
@Value(staticConstructor = "of")
public class ActivityImpl implements Activity {

String name;

String status;

List<Result> results;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.v1.model.analytics;

import lombok.Builder;
import lombok.Value;
import lombok.experimental.Accessors;
import org.prebid.server.hooks.v1.analytics.AppliedTo;

import java.util.List;

@Accessors(fluent = true)
@Value
@Builder
public class AppliedToImpl implements AppliedTo {

List<String> impIds;

List<String> bidders;

boolean request;

boolean response;

List<String> bidIds;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.v1.model.analytics;

import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Value;
import lombok.experimental.Accessors;
import org.prebid.server.hooks.v1.analytics.AppliedTo;
import org.prebid.server.hooks.v1.analytics.Result;

@Accessors(fluent = true)
@Value(staticConstructor = "of")
public class ResultImpl implements Result {
String status;

ObjectNode values;

AppliedTo appliedTo;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.prebid.server.hooks.modules.greenbids.real.time.data.v1.model.analytics;

import lombok.Value;
import lombok.experimental.Accessors;
import org.prebid.server.hooks.v1.analytics.Activity;
import org.prebid.server.hooks.v1.analytics.Tags;

import java.util.List;

@Accessors(fluent = true)
@Value(staticConstructor = "of")
public class TagsImpl implements Tags {

List<Activity> activities;
}
3 changes: 3 additions & 0 deletions sample/prebid-config-with-module.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ adapters:
enabled: true
metrics:
prefix: prebid
analytics:
greenbids:
enabled: true
cache:
scheme: http
host: localhost
Expand Down
18 changes: 16 additions & 2 deletions sample/requests/rubicon-storedresponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
"accountId": 1001,
"siteId": 267318,
"zoneId": 1861698
}
},
"appnexus": {
"placementId": 123456
},
"pubmatic": {
"publisherId": "156209",
"adSlot": "slot1@300x250"
}
}}},
"secure": 1,
"banner": {
Expand All @@ -37,10 +44,17 @@
},
"ext": {
"prebid": {
"trace": "verbose",
"targeting": {
"includewinners": true,
"includebidderkeys": true
}
},
"analytics": {
"greenbids": {
"pbuid": "PBUID_FROM_GREENBIDS",
"greenbidsSampling": 1.0
}
}
}
}
}
40 changes: 40 additions & 0 deletions sample/stored/1001-sar-320x50-imp-1.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,45 @@
],
"seat": "rubicon",
"group": 0
},
{
"bid": [
{
"h": 50,
"w": 320,
"id": "1",
"adm": "<img src=\"https://files.prebid.org/creatives/prebid320x50.png\">",
"ext": {
"prebid": {
"type": "banner"
}
},
"crid": "888888",
"impid": "1",
"price": 1.05
}
],
"seat": "pubmatic",
"group": 0
},
{
"bid": [
{
"h": 50,
"w": 320,
"id": "1",
"adm": "<img src=\"https://files.prebid.org/creatives/prebid320x50.png\">",
"ext": {
"prebid": {
"type": "banner"
}
},
"crid": "888888",
"impid": "1",
"price": 0.05
}
],
"seat": "appnexus",
"group": 0
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ private <T> void delegateEvent(T event,
// but to be sure lets use getOrDefault
final PrivacyEnforcementAction reporterPrivacyAction = privacyEnforcementActionMap
.getOrDefault(reporterVendorId, PrivacyEnforcementAction.restrictAll());
if (!reporterPrivacyAction.isBlockAnalyticsReport()) {
vertx.runOnContext(ignored -> processEventByReporter(analyticsReporter, updatedEvent));
}
//if (!reporterPrivacyAction.isBlockAnalyticsReport()) {
vertx.runOnContext(ignored -> processEventByReporter(analyticsReporter, updatedEvent));
//}
}
} else {
final Throwable privacyEnforcementException = privacyEnforcementMapResult.cause();
Expand Down
Loading

0 comments on commit 58ee63f

Please sign in to comment.