Skip to content

Commit 450aac9

Browse files
author
softcoder594
committed
optable-targeting: remove reg attribute from targeting query
1 parent f9d6dc8 commit 450aac9

7 files changed

Lines changed: 38 additions & 191 deletions

File tree

extra/modules/optable-targeting/src/main/java/org/prebid/server/hooks/modules/optable/targeting/model/OptableAttributes.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
@Builder(toBuilder = true)
1111
public class OptableAttributes {
1212

13-
String reg;
14-
1513
String gpp;
1614

1715
Set<Integer> gppSid;
1816

19-
String tcf;
17+
String gdprConsent;
18+
19+
boolean gdprApplies;
2020

2121
List<String> ips;
2222

2323
Long timeout;
2424

25-
public static OptableAttributes of(String reg) {
26-
return OptableAttributes.builder().reg(reg).build();
25+
public static OptableAttributes of() {
26+
return OptableAttributes.builder().build();
2727
}
2828
}

extra/modules/optable-targeting/src/main/java/org/prebid/server/hooks/modules/optable/targeting/v1/OptableTargetingProcessedAuctionRequestHook.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public Future<InvocationResult<AuctionRequestPayload>> call(AuctionRequestPayloa
5757
}
5858

5959
final long timeout = getHookRemainTime(invocationContext);
60-
final OptableAttributes attributes = optableAttributesResolver.reloveAttributes(
60+
final OptableAttributes attributes = optableAttributesResolver.resolveAttributes(
6161
invocationContext.auctionContext(),
6262
properties.getTimeout());
6363

extra/modules/optable-targeting/src/main/java/org/prebid/server/hooks/modules/optable/targeting/v1/core/OptableAttributesResolver.java

Lines changed: 9 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import com.iab.gpp.encoder.GppModel;
44
import lombok.AllArgsConstructor;
5-
import org.apache.commons.lang3.StringUtils;
65
import org.prebid.server.auction.gpp.model.GppContext;
76
import org.prebid.server.auction.model.AuctionContext;
8-
import org.prebid.server.geolocation.model.GeoInfo;
97
import org.prebid.server.hooks.modules.optable.targeting.model.OptableAttributes;
108
import org.prebid.server.privacy.model.PrivacyContext;
119

@@ -18,60 +16,19 @@ public class OptableAttributesResolver {
1816

1917
private final IpResolver ipResolver;
2018

21-
private static final int SECTION_ID_CANADA = 5;
22-
23-
private static final Set<Integer> SECTION_ID_EUROPE = Set.of(1, 2);
24-
25-
private static final Set<Integer> SECTION_ID_US =
26-
Set.of(6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22);
27-
28-
private static final Set<String> GDPR_COUNTRIES = Set.of("Belgium", "Bulgaria", "Cyprus", "Denmark",
29-
"Germany", "Estonia", "Finland", "France", "Greece", "Hungary", "Ireland", "Italy", "Croatia", "Latvia",
30-
"Liechtenstein", "Lithuania", "Luxembourg", "Malta", "The Netherlands", "Norway",
31-
"Austria", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Switzerland", "UK");
32-
33-
private static final Set<String> GDPR_REGIONS = Set.of("Azores", "Canary", "Islands", "Guadeloupe", "French Guiana",
34-
"Madeira", "Martinique", "Mayotte", "Reunion", "Saint Martin");
35-
36-
public OptableAttributes reloveAttributes(AuctionContext auctionContext, Long timeout) {
19+
public OptableAttributes resolveAttributes(AuctionContext auctionContext, Long timeout) {
3720
final List<String> ips = ipResolver.resolveIp(auctionContext);
3821

39-
OptableAttributes optableAttributes = getTcfPrivacyAttributes(auctionContext);
22+
OptableAttributes optableAttributes = getGdprPrivacyAttributes(auctionContext);
4023
if (optableAttributes == null) {
4124
optableAttributes = getGppPrivacyAttributes(auctionContext);
4225
}
43-
if (optableAttributes == null) {
44-
optableAttributes = getGeoIpPrivacyAttributes(auctionContext);
45-
}
4626

4727
return optableAttributes != null
4828
? optableAttributes.toBuilder().ips(ips).timeout(timeout).build()
4929
: OptableAttributes.builder().ips(ips).timeout(timeout).build();
5030
}
5131

52-
private OptableAttributes getGeoIpPrivacyAttributes(AuctionContext auctionContext) {
53-
final Optional<GeoInfo> geoInfoOpt = Optional.ofNullable(auctionContext).map(AuctionContext::getGeoInfo);
54-
55-
final String country = geoInfoOpt.map(GeoInfo::getCountry).orElse(null);
56-
final String region = geoInfoOpt.map(GeoInfo::getRegion).orElse(null);
57-
58-
if (StringUtils.isNotEmpty(country)) {
59-
if (country.equalsIgnoreCase("US") || country.equalsIgnoreCase("United States")) {
60-
return OptableAttributes.of("us");
61-
} else if (country.equalsIgnoreCase("Quebec") || country.equalsIgnoreCase("Canada")) {
62-
return OptableAttributes.of("can");
63-
} else if (GDPR_COUNTRIES.contains(country)) {
64-
return OptableAttributes.of("gdpr");
65-
}
66-
}
67-
68-
if (StringUtils.isNotEmpty(region) && GDPR_REGIONS.contains(region)) {
69-
return OptableAttributes.of("gdpr");
70-
}
71-
72-
return null;
73-
}
74-
7532
private OptableAttributes getGppPrivacyAttributes(AuctionContext auctionContext) {
7633
final Optional<GppContext> gppContextOpt = Optional.ofNullable(auctionContext)
7734
.map(AuctionContext::getGppContext);
@@ -89,38 +46,26 @@ private OptableAttributes getGppPrivacyAttributes(AuctionContext auctionContext)
8946
.map(GppContext.Scope::getSectionsIds)
9047
.orElse(Set.of());
9148

92-
return OptableAttributes.of(sidsToReg(sids)).toBuilder().gpp(gppConsent).gppSid(sids).build();
49+
return OptableAttributes.builder().gpp(gppConsent).gppSid(sids).build();
9350

9451
}
9552

9653
return null;
9754
}
9855

99-
private OptableAttributes getTcfPrivacyAttributes(AuctionContext auctionContext) {
56+
private OptableAttributes getGdprPrivacyAttributes(AuctionContext auctionContext) {
10057
return Optional.ofNullable(auctionContext)
10158
.map(AuctionContext::getPrivacyContext)
10259
.map(PrivacyContext::getTcfContext)
10360
.map(ctx -> {
61+
10462
if (ctx.isConsentValid()) {
105-
return OptableAttributes.of("gdpr").toBuilder().tcf(ctx.getConsentString()).build();
63+
return OptableAttributes.builder()
64+
.gdprConsent(ctx.getConsentString())
65+
.gdprApplies(ctx.isInGdprScope())
66+
.build();
10667
}
10768
return null;
10869
}).orElse(null);
10970
}
110-
111-
private String sidsToReg(Set<Integer> sids) {
112-
if (sids == null) {
113-
return null;
114-
}
115-
116-
if (sids.contains(SECTION_ID_CANADA)) {
117-
return "can";
118-
} else if (sids.stream().anyMatch(SECTION_ID_EUROPE::contains)) {
119-
return "gdpr";
120-
} else if (sids.stream().anyMatch(SECTION_ID_US::contains)) {
121-
return "us";
122-
}
123-
124-
return null;
125-
}
12671
}

extra/modules/optable-targeting/src/main/java/org/prebid/server/hooks/modules/optable/targeting/v1/core/QueryBuilder.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,19 @@ private List<Id> reorderIds(List<Id> ids) {
5454
}
5555

5656
private void addAttributes(StringBuilder sb, OptableAttributes optableAttributes) {
57-
Optional.ofNullable(optableAttributes.getReg()).ifPresent(reg -> sb.append("&reg=").append(reg));
58-
Optional.ofNullable(optableAttributes.getTcf()).ifPresent(tcf -> sb.append("&tcf=").append(tcf));
59-
Optional.ofNullable(optableAttributes.getGpp()).ifPresent(tcf -> sb.append("&gpp=").append(tcf));
57+
Optional.ofNullable(optableAttributes.getGdprConsent()).ifPresent(consent ->
58+
sb.append("&gdpr_consent=").append(consent));
59+
Optional.of(optableAttributes.isGdprApplies()).ifPresent(applies ->
60+
sb.append("&gdprApplies=").append(applies ? 1 : 0));
61+
Optional.ofNullable(optableAttributes.getGpp()).ifPresent(tcf ->
62+
sb.append("&gpp=").append(tcf));
6063
Optional.ofNullable(optableAttributes.getGppSid()).ifPresent(gppSids -> {
6164
if (CollectionUtils.isNotEmpty(gppSids)) {
6265
sb.append("&gpp_sid=").append(gppSids.stream().findFirst());
6366
}
6467
});
65-
Optional.ofNullable(optableAttributes.getTimeout()).ifPresent(timeout -> {
66-
sb.append("&timeout=").append(timeout).append("ms");
67-
});
68+
Optional.ofNullable(optableAttributes.getTimeout()).ifPresent(timeout ->
69+
sb.append("&timeout=").append(timeout).append("ms"));
6870
}
6971

7072
private void buildQueryString(StringBuilder sb, List<Id> ids) {

extra/modules/optable-targeting/src/test/java/org/prebid/server/hooks/modules/optable/targeting/v1/core/OptableAttributesResolverTest.java

Lines changed: 10 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@ public void setUp() {
5151
public void shouldResolveTcfAttributesWhenConsentIsValid() {
5252
// given
5353
when(tcfContext.isConsentValid()).thenReturn(true);
54+
when(tcfContext.isInGdprScope()).thenReturn(true);
5455
when(tcfContext.getConsentString()).thenReturn("consent");
5556
final AuctionContext auctionContext = givenAuctionContext(tcfContext);
5657

5758
// when
58-
final OptableAttributes result = target.reloveAttributes(auctionContext, properties.getTimeout());
59+
final OptableAttributes result = target.resolveAttributes(auctionContext, properties.getTimeout());
5960

6061
// then
6162
assertThat(result).isNotNull()
62-
.returns("gdpr", OptableAttributes::getReg)
63-
.returns("consent", OptableAttributes::getTcf);
63+
.returns(true, OptableAttributes::isGdprApplies)
64+
.returns("consent", OptableAttributes::getGdprConsent);
6465
}
6566

6667
@Test
@@ -71,17 +72,17 @@ public void shouldNotResolveTcfAttributesWhenConsentIsNotValid() {
7172
final AuctionContext auctionContext = givenAuctionContext(tcfContext);
7273

7374
// when
74-
final OptableAttributes result = target.reloveAttributes(auctionContext, properties.getTimeout());
75+
final OptableAttributes result = target.resolveAttributes(auctionContext, properties.getTimeout());
7576

7677
// then
7778
assertThat(result).isNotNull()
78-
.returns(null, OptableAttributes::getReg)
79-
.returns(null, OptableAttributes::getTcf)
79+
.returns(false, OptableAttributes::isGdprApplies)
80+
.returns(null, OptableAttributes::getGdprConsent)
8081
.returns(List.of("8.8.8.8"), OptableAttributes::getIps);
8182
}
8283

8384
@Test
84-
public void shouldResolveGppGdprAttributes() {
85+
public void shouldResolveGppAttributes() {
8586
// given
8687
final GppModel gppModel = mock();
8788
when(gppModel.encode()).thenReturn("consent");
@@ -90,117 +91,15 @@ public void shouldResolveGppGdprAttributes() {
9091

9192
// when
9293

93-
final OptableAttributes result = target.reloveAttributes(auctionContext, properties.getTimeout());
94+
final OptableAttributes result = target.resolveAttributes(auctionContext, properties.getTimeout());
9495

9596
// then
9697
assertThat(result).isNotNull()
97-
.returns("gdpr", OptableAttributes::getReg)
98+
.returns(false, OptableAttributes::isGdprApplies)
9899
.returns("consent", OptableAttributes::getGpp)
99100
.returns(Set.of(1), OptableAttributes::getGppSid);
100101
}
101102

102-
@Test
103-
public void shouldResolveGppCanadaAttributes() {
104-
// given
105-
final GppModel gppModel = mock();
106-
when(gppModel.encode()).thenReturn("consent");
107-
when(gppContext.scope()).thenReturn(GppContext.Scope.of(gppModel, Set.of(5)));
108-
final AuctionContext auctionContext = givenAuctionContext(gppContext);
109-
110-
// when
111-
112-
final OptableAttributes result = target.reloveAttributes(auctionContext, properties.getTimeout());
113-
114-
// then
115-
assertThat(result).isNotNull()
116-
.returns("can", OptableAttributes::getReg)
117-
.returns("consent", OptableAttributes::getGpp)
118-
.returns(Set.of(5), OptableAttributes::getGppSid);
119-
}
120-
121-
@Test
122-
public void shouldResolveGppUSAttributes() {
123-
// given
124-
final GppModel gppModel = mock();
125-
when(gppModel.encode()).thenReturn("consent");
126-
when(gppContext.scope()).thenReturn(GppContext.Scope.of(gppModel, Set.of(8)));
127-
final AuctionContext auctionContext = givenAuctionContext(gppContext);
128-
129-
// when
130-
131-
final OptableAttributes result = target.reloveAttributes(auctionContext, properties.getTimeout());
132-
133-
// then
134-
assertThat(result).isNotNull()
135-
.returns("us", OptableAttributes::getReg)
136-
.returns("consent", OptableAttributes::getGpp)
137-
.returns(Set.of(8), OptableAttributes::getGppSid);
138-
}
139-
140-
@Test
141-
public void shouldResolveGeoInfoUSAttributes() {
142-
// given
143-
when(geoInfo.getCountry()).thenReturn("United States");
144-
final AuctionContext auctionContext = givenAuctionContext(geoInfo);
145-
146-
// when
147-
final OptableAttributes result = target.reloveAttributes(auctionContext, properties.getTimeout());
148-
149-
// then
150-
assertThat(result).isNotNull()
151-
.returns("us", OptableAttributes::getReg)
152-
.returns(null, OptableAttributes::getGpp)
153-
.returns(null, OptableAttributes::getTcf);
154-
}
155-
156-
@Test
157-
public void shouldResolveGeoInfoGDPRAttributes() {
158-
// given
159-
when(geoInfo.getCountry()).thenReturn("Malta");
160-
final AuctionContext auctionContext = givenAuctionContext(geoInfo);
161-
162-
// when
163-
final OptableAttributes result = target.reloveAttributes(auctionContext, properties.getTimeout());
164-
165-
// then
166-
assertThat(result).isNotNull()
167-
.returns("gdpr", OptableAttributes::getReg)
168-
.returns(null, OptableAttributes::getGpp)
169-
.returns(null, OptableAttributes::getTcf);
170-
}
171-
172-
@Test
173-
public void shouldResolveGeoInfoCanadaAttributes() {
174-
// given
175-
when(geoInfo.getCountry()).thenReturn("Quebec");
176-
final AuctionContext auctionContext = givenAuctionContext(geoInfo);
177-
178-
// when
179-
final OptableAttributes result = target.reloveAttributes(auctionContext, properties.getTimeout());
180-
181-
// then
182-
assertThat(result).isNotNull()
183-
.returns("can", OptableAttributes::getReg)
184-
.returns(null, OptableAttributes::getGpp)
185-
.returns(null, OptableAttributes::getTcf);
186-
}
187-
188-
@Test
189-
public void shouldResolveGeoInfoGDPRForRegionAttributes() {
190-
// given
191-
when(geoInfo.getRegion()).thenReturn("Mayotte");
192-
final AuctionContext auctionContext = givenAuctionContext(geoInfo);
193-
194-
// when
195-
final OptableAttributes result = target.reloveAttributes(auctionContext, properties.getTimeout());
196-
197-
// then
198-
assertThat(result).isNotNull()
199-
.returns("gdpr", OptableAttributes::getReg)
200-
.returns(null, OptableAttributes::getGpp)
201-
.returns(null, OptableAttributes::getTcf);
202-
}
203-
204103
public AuctionContext givenAuctionContext(TcfContext tcfContext) {
205104
return AuctionContext.builder()
206105
.privacyContext(PrivacyContext.of(Privacy.builder().build(), tcfContext,

extra/modules/optable-targeting/src/test/java/org/prebid/server/hooks/modules/optable/targeting/v1/core/OptableTargetingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public void shouldNotFailWhenApiClientReturnsFailFuture() {
107107
}
108108

109109
private OptableAttributes givenOptableAttributes() {
110-
return OptableAttributes.of("gdpr").toBuilder()
110+
return OptableAttributes.builder()
111111
.gpp("gpp")
112112
.gppSid(Set.of(2))
113113
.build();

extra/modules/optable-targeting/src/test/java/org/prebid/server/hooks/modules/optable/targeting/v1/core/QueryBuilderTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void shouldBuildQueryStringWithExtraAttributes() {
4242
final String query = target.build(ids, optableAttributes);
4343

4444
// then
45-
assertThat(query).contains("&reg=gdpr", "&tcf=tcf", "&timeout=100ms");
45+
assertThat(query).contains("&gdprApplies=1", "&gdpr_consent=tcf", "&timeout=100ms");
4646
}
4747

4848
@Test
@@ -72,9 +72,10 @@ public void shouldNotBuildQueryStringWhenIdsListIsEmpty() {
7272
}
7373

7474
private OptableAttributes givenOptableAttributes() {
75-
return OptableAttributes.of("gdpr").toBuilder()
75+
return OptableAttributes.builder()
7676
.timeout(100L)
77-
.tcf("tcf")
77+
.gdprApplies(true)
78+
.gdprConsent("tcf")
7879
.build();
7980
}
8081
}

0 commit comments

Comments
 (0)