-
Notifications
You must be signed in to change notification settings - Fork 220
DATA-22937: LI analytics adapter #4154
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
Merged
Merged
Changes from 34 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
bf8c1fa
WIP - LiveIntent Module
3link 8429f34
Adjust the hook code
3link 459028d
WIP - polish, add config tests
3link c846d1c
Add unit tests
3link 8348d46
Add auth token
3link c0f6566
Add README.md
3link 4f90c17
Fix stage
3link c6dc20e
Add logging
3link a863d0a
Add docs
3link 62a4508
Format
3link e45ccbc
Impro docs
3link 3dbb46a
Add IdResResponse decode test
3link 69fc413
Improve code style
3link c1ad22f
Fix Collections API usage
3link 26288b7
Clean up/format
3link 4192fa8
Merge branch 'prebid:master' into cm-1776
SuperIzya 1f1a7cf
Format
3link c9659ad
Add treatment rate
3link 3ed7ee8
Remove superflous JsonProperty annotation
3link bedb969
Separate field by line
3link d94e06f
Use RandomGenerator + ThreadLocalRandom instead of Random
3link 61ceeed
Apply code style
3link fa66d18
Apply style guide: method order
3link 09450d2
Add empty lines to separate test stages
3link b588f6a
Use NoArgsConstructor instead of Jacksonized
3link 1ae6da8
Merge branch 'master' into cm-1776
3link f597339
Bump dependency version
3link 5f15bf1
cm-1776: PR issues fixed
587d6fb
DATA-22937: WIP
5bbb155
DATA-22937: LI Analytic module.
432625a
DATA-22937: LI Analytic module.
bc299e9
DATA-22937: LI Analytic module.
7d50a0b
Merge branch 'master' into DATA-22937
61cdcaf
DATA-22937: Minor fixes after merge with master
9c39379
DATA-22937: PR issues fixed
704b89a
DATA-22937: PR issues fixed
a7b75b7
DATA-22937: PR issues fixed
2d9cc59
DATA-36551: PR compilation issues fixed
58fc8c0
DATA-22937: PR issues fixed
d946509
DATA-22937: PR issues fixed
d2eefef
DATA-22937: PR issues fixed
359ed36
DATA-22937: Fixing linting
be5bf0b
DATA-22937: PR issues fixed
3f65d47
DATA-22937: Build fixed
7d11882
update test
peixunzhang 3e02eff
formatting
peixunzhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
...ebid/server/hooks/modules/liveintent/omni/channel/identity/model/config/ModuleConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.config; | ||
|
|
||
| import lombok.Data; | ||
|
|
||
| @Data | ||
| public final class ModuleConfig { | ||
|
|
||
| long requestTimeoutMs; | ||
|
|
||
| String identityResolutionEndpoint; | ||
|
|
||
| String authToken; | ||
|
|
||
| float treatmentRate; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...server/hooks/modules/liveintent/omni/channel/identity/model/config/IdResResponseTest.java
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.config; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import com.iab.openrtb.request.Eid; | ||
| import com.iab.openrtb.request.Uid; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.IdResResponse; | ||
| import org.prebid.server.json.JacksonMapper; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class IdResResponseTest { | ||
|
|
||
| private JacksonMapper jacksonMapper; | ||
|
|
||
| @BeforeEach | ||
| public void setUp() { | ||
| final ObjectMapper mapper = new ObjectMapper(); | ||
| jacksonMapper = new JacksonMapper(mapper); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldDecodeFromString() { | ||
| // given | ||
| final IdResResponse result = jacksonMapper.decodeValue( | ||
| "{\"eids\": [ { \"source\": \"liveintent.com\", " | ||
| + "\"uids\": [ { \"atype\": 3, \"id\" : \"some_id\" } ] } ] }", | ||
| IdResResponse.class); | ||
|
|
||
| // when and then | ||
| assertThat(result.getEids()).isEqualTo(List.of( | ||
| Eid.builder() | ||
| .source("liveintent.com") | ||
| .uids(List.of(Uid.builder().atype(3).id("some_id").build())) | ||
| .build())); | ||
| } | ||
| } |
35 changes: 35 additions & 0 deletions
35
.../server/hooks/modules/liveintent/omni/channel/identity/model/config/ModuleConfigTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package org.prebid.server.hooks.modules.liveintent.omni.channel.identity.model.config; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| public class ModuleConfigTest { | ||
|
|
||
| @Test | ||
| public void shouldReturnRequestTimeoutMs() { | ||
| final ModuleConfig moduleConfig = new ModuleConfig(); | ||
| moduleConfig.setRequestTimeoutMs(5); | ||
| assertThat(moduleConfig.getRequestTimeoutMs()).isEqualTo(5); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReturnIdentityResolutionEndpoint() { | ||
| // given | ||
| final ModuleConfig moduleConfig = new ModuleConfig(); | ||
| moduleConfig.setIdentityResolutionEndpoint("https://test.com/idres"); | ||
|
|
||
| // when and then | ||
| assertThat(moduleConfig.getIdentityResolutionEndpoint()).isEqualTo("https://test.com/idres"); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldReturnAuthToken() { | ||
| // given | ||
| final ModuleConfig moduleConfig = new ModuleConfig(); | ||
| moduleConfig.setAuthToken("secret_token"); | ||
|
|
||
| // when and then | ||
| assertThat(moduleConfig.getAuthToken()).isEqualTo("secret_token"); | ||
| } | ||
| } |
159 changes: 159 additions & 0 deletions
159
...ain/java/org/prebid/server/analytics/reporter/liveintent/LiveIntentAnalyticsReporter.java
SuperIzya marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| package org.prebid.server.analytics.reporter.liveintent; | ||
|
|
||
| import com.iab.openrtb.request.BidRequest; | ||
| import com.iab.openrtb.response.BidResponse; | ||
| import io.vertx.core.Future; | ||
| import org.prebid.server.analytics.AnalyticsReporter; | ||
| import org.prebid.server.analytics.model.AuctionEvent; | ||
| import org.prebid.server.analytics.model.NotificationEvent; | ||
| import org.prebid.server.analytics.reporter.liveintent.model.LiveIntentAnalyticsProperties; | ||
| import org.prebid.server.analytics.reporter.liveintent.model.PbsjBid; | ||
| import org.prebid.server.auction.model.AuctionContext; | ||
| import org.prebid.server.exception.PreBidException; | ||
| import org.prebid.server.hooks.execution.model.ExecutionStatus; | ||
| import org.prebid.server.hooks.execution.model.GroupExecutionOutcome; | ||
| import org.prebid.server.hooks.execution.model.HookExecutionContext; | ||
| import org.prebid.server.hooks.execution.model.HookExecutionOutcome; | ||
| import org.prebid.server.hooks.execution.model.Stage; | ||
| import org.prebid.server.hooks.execution.model.StageExecutionOutcome; | ||
| import org.prebid.server.hooks.v1.analytics.Activity; | ||
| import org.prebid.server.hooks.v1.analytics.Tags; | ||
| import org.prebid.server.json.JacksonMapper; | ||
| import org.prebid.server.log.Logger; | ||
| import org.prebid.server.log.LoggerFactory; | ||
| import org.prebid.server.proto.openrtb.ext.request.ExtRequestPrebid; | ||
| import org.prebid.server.vertx.httpclient.HttpClient; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
||
| public class LiveIntentAnalyticsReporter implements AnalyticsReporter { | ||
|
|
||
| private final HttpClient httpClient; | ||
| private final LiveIntentAnalyticsProperties properties; | ||
| private final JacksonMapper jacksonMapper; | ||
|
|
||
| private static final Logger logger = LoggerFactory.getLogger(LiveIntentAnalyticsReporter.class); | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| public LiveIntentAnalyticsReporter( | ||
| LiveIntentAnalyticsProperties properties, | ||
| HttpClient httpClient, | ||
| JacksonMapper jacksonMapper | ||
| ) { | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this.httpClient = Objects.requireNonNull(httpClient); | ||
| this.properties = Objects.requireNonNull(properties); | ||
| this.jacksonMapper = Objects.requireNonNull(jacksonMapper); | ||
| } | ||
SuperIzya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public <T> Future<Void> processEvent(T event) { | ||
| if (event instanceof AuctionEvent auctionEvent) { | ||
| return processAuctionEvent(auctionEvent.getAuctionContext()); | ||
| } else if (event instanceof NotificationEvent notificationEvent) { | ||
| return processNotificationEvent(notificationEvent); | ||
| } | ||
|
|
||
| return Future.succeededFuture(); | ||
| } | ||
|
|
||
| private Future<Void> processNotificationEvent(NotificationEvent notificationEvent) { | ||
| final String url = properties.getAnalyticsEndpoint() + "/analytic-events/pbsj-winning-bid?" | ||
| + "b=" + notificationEvent.getBidder() | ||
| + "&bidId=" + notificationEvent.getBidId(); | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return httpClient.get(url, properties.getTimeoutMs()).mapEmpty(); | ||
| } | ||
|
|
||
| private Future<Void> processAuctionEvent(AuctionContext auctionContext) { | ||
| try { | ||
| final BidRequest bidRequest = Optional.ofNullable(auctionContext.getBidRequest()) | ||
| .orElseThrow(() -> new PreBidException("Bid request should not be empty")); | ||
| final BidResponse bidResponse = Optional.ofNullable(auctionContext.getBidResponse()) | ||
| .orElseThrow(() -> new PreBidException("Bid response should not be empty")); | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| final Optional<ExtRequestPrebid> requestPrebid = Optional.ofNullable(bidRequest.getExt()) | ||
| .flatMap(ext -> Optional.of(ext.getPrebid())); | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| final List<Activity> activities = getActivities(auctionContext); | ||
|
|
||
| final List<PbsjBid> pbsjBids = bidResponse.getSeatbid().stream() | ||
| .flatMap(seatBid -> seatBid.getBid().stream()) | ||
| .flatMap(bid -> | ||
| bidRequest.getImp().stream() | ||
| .filter(impItem -> impItem.getId().equals(bid.getImpid())) | ||
| .map(imp -> | ||
| PbsjBid.builder() | ||
| .bidId(bid.getId()) | ||
| .price(bid.getPrice()) | ||
| .adUnitId(imp.getTagid()) | ||
| .enriched(isEnriched(activities)) | ||
| .currency(bidResponse.getCur()) | ||
| .treatmentRate(getTreatmentRate(activities)) | ||
| .timestamp(requestPrebid.map(ExtRequestPrebid::getAuctiontimestamp).orElse(0L)) | ||
| .partnerId(properties.getPartnerId()) | ||
| .build() | ||
| ) | ||
| ).toList(); | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return httpClient.post( | ||
| properties.getAnalyticsEndpoint() + "/analytic-events/pbsj-bids", | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| jacksonMapper.encodeToString(pbsjBids), | ||
| properties.getTimeoutMs() | ||
| ).mapEmpty(); | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } catch (Exception e) { | ||
| logger.error("Error processing event: {}", e.getMessage()); | ||
| return Future.failedFuture(e); | ||
| } | ||
| } | ||
|
|
||
| private List<Activity> getActivities(AuctionContext auctionContext) { | ||
| return Optional.ofNullable(auctionContext) | ||
| .map(AuctionContext::getHookExecutionContext) | ||
| .map(HookExecutionContext::getStageOutcomes) | ||
| .map(stages -> stages.get(Stage.processed_auction_request)).stream() | ||
| .flatMap(Collection::stream) | ||
| .filter(stageExecutionOutcome -> "auction-request".equals(stageExecutionOutcome.getEntity())) | ||
| .map(StageExecutionOutcome::getGroups) | ||
| .flatMap(Collection::stream) | ||
| .map(GroupExecutionOutcome::getHooks) | ||
| .flatMap(Collection::stream) | ||
| .filter(hook -> | ||
| "liveintent-omni-channel-identity-enrichment-hook".equals(hook.getHookId().getModuleCode()) | ||
| && hook.getStatus() == ExecutionStatus.success | ||
| ) | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .map(HookExecutionOutcome::getAnalyticsTags) | ||
| .map(Tags::activities) | ||
| .flatMap(Collection::stream) | ||
| .toList(); | ||
SuperIzya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| private Float getTreatmentRate(List<Activity> activities) { | ||
| return activities | ||
| .stream() | ||
| .filter(activity -> "liveintent-treatment-rate".equals(activity.name())) | ||
| .findFirst() | ||
| .map(activity -> { | ||
| try { | ||
| return Float.parseFloat(activity.status()); | ||
| } catch (NumberFormatException e) { | ||
| logger.warn("Invalid treatment rate value: {}", activity.status()); | ||
| throw e; | ||
| } | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }) | ||
| .orElse(null); | ||
| } | ||
|
|
||
| private boolean isEnriched(List<Activity> activities) { | ||
| return activities.stream().anyMatch(activity -> "liveintent-enriched".equals(activity.name())); | ||
| } | ||
|
|
||
| @Override | ||
| public int vendorId() { | ||
| return 0; | ||
| } | ||
|
|
||
| @Override | ||
| public String name() { | ||
| return "liveintentAnalytics"; | ||
| } | ||
| } | ||
15 changes: 15 additions & 0 deletions
15
.../org/prebid/server/analytics/reporter/liveintent/model/LiveIntentAnalyticsProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package org.prebid.server.analytics.reporter.liveintent.model; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.Value; | ||
|
|
||
| @Data | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @Builder(toBuilder = true) | ||
| @Value | ||
| public class LiveIntentAnalyticsProperties { | ||
|
|
||
| String partnerId; | ||
| String analyticsEndpoint; | ||
| long timeoutMs; | ||
SuperIzya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
22 changes: 22 additions & 0 deletions
22
src/main/java/org/prebid/server/analytics/reporter/liveintent/model/PbsjBid.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package org.prebid.server.analytics.reporter.liveintent.model; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Data; | ||
| import lombok.Value; | ||
|
|
||
| import java.math.BigDecimal; | ||
|
|
||
| @Data | ||
| @Builder(toBuilder = true) | ||
| @Value | ||
| public class PbsjBid { | ||
|
|
||
| String bidId; | ||
| boolean enriched; | ||
| BigDecimal price; | ||
| String adUnitId; | ||
| String currency; | ||
| Float treatmentRate; | ||
| Long timestamp; | ||
| String partnerId; | ||
SuperIzya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.