Skip to content

Commit 2383a14

Browse files
wurfl-devicedetection module enhancements (#4182)
1 parent 41c0e01 commit 2383a14

File tree

5 files changed

+249
-122
lines changed

5 files changed

+249
-122
lines changed

extra/modules/wurfl-devicedetection/src/main/java/org/prebid/server/hooks/modules/com/scientiamobile/wurfl/devicedetection/v1/OrtbDeviceUpdater.java

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public AuctionRequestPayload apply(AuctionRequestPayload auctionRequestPayload)
5555
private Device update(Device ortbDevice) {
5656
final String make = tryUpdateField(ortbDevice.getMake(), this::getWurflMake);
5757
final String model = tryUpdateField(ortbDevice.getModel(), this::getWurflModel);
58+
final String hwv = tryUpdateField(ortbDevice.getHwv(), this::getWurflModel);
5859
final Integer deviceType = tryUpdateField(
5960
Optional.ofNullable(ortbDevice.getDevicetype())
6061
.filter(it -> it > 0)
@@ -72,6 +73,7 @@ private Device update(Device ortbDevice) {
7273
.make(make)
7374
.model(model)
7475
.devicetype(deviceType)
76+
.hwv(hwv)
7577
.os(os)
7678
.osv(osv)
7779
.h(h)
@@ -103,49 +105,72 @@ private String getWurflModel() {
103105
}
104106

105107
private Integer getWurflDeviceType() {
106-
try {
107-
if (wurflDevice.getVirtualCapabilityAsBool("is_mobile")) {
108-
// if at least one of these capabilities is not defined, the mobile device type is undefined
109-
final boolean isPhone = wurflDevice.getVirtualCapabilityAsBool("is_phone");
110-
final boolean isTablet = wurflDevice.getCapabilityAsBool("is_tablet");
111-
return isPhone || isTablet ? 1 : 6;
112-
}
113108

114-
if (wurflDevice.getVirtualCapabilityAsBool("is_full_desktop")) {
115-
return 2;
116-
}
109+
if (getWurflIsOtt()) {
110+
return 7;
111+
}
117112

118-
if (wurflDevice.getCapabilityAsBool("is_connected_tv")) {
119-
return 3;
120-
}
113+
if (getWurflIsConsole()) {
114+
return 6;
115+
}
121116

122-
if (wurflDevice.getCapabilityAsBool("is_phone")) {
123-
return 4;
124-
}
117+
if ("out_of_home_device".equals(getWurflPhysicalFormFactor())) {
118+
return 8;
119+
}
125120

126-
if (wurflDevice.getCapabilityAsBool("is_tablet")) {
127-
return 5;
128-
}
121+
final String formFactor = getWurflFormFactor();
122+
return switch (formFactor) {
123+
case "Desktop" -> 2;
124+
case "Smartphone", "Feature Phone" -> 4;
125+
case "Tablet" -> 5;
126+
case "Smart-TV" -> 3;
127+
case "Other Non-Mobile" -> 6;
128+
case "Other Mobile" -> 1;
129+
default -> null;
130+
};
131+
}
129132

130-
if (wurflDevice.getCapabilityAsBool("is_ott")) {
131-
return 7;
132-
}
133+
private Boolean getWurflIsOtt() {
134+
try {
135+
return wurflDevice.getCapabilityAsBool("is_ott");
136+
} catch (CapabilityNotDefinedException e) {
137+
logger.warn("Failed to get is_ott from WURFL device capabilities");
138+
return Boolean.FALSE;
139+
}
140+
}
133141

134-
final String physicalFormFactor = wurflDevice.getCapability("physical_form_factor");
135-
if (physicalFormFactor != null && physicalFormFactor.equals("out_of_home_device")) {
136-
return 8;
137-
}
138-
} catch (CapabilityNotDefinedException | VirtualCapabilityNotDefinedException | NumberFormatException e) {
139-
logger.warn("Failed to determine device type from WURFL device capabilities", e);
142+
private String getWurflFormFactor() {
143+
try {
144+
return wurflDevice.getVirtualCapability("form_factor");
145+
} catch (VirtualCapabilityNotDefinedException e) {
146+
logger.warn("Failed to get form_factor from WURFL device capabilities");
147+
return "";
148+
}
149+
}
150+
151+
private String getWurflPhysicalFormFactor() {
152+
try {
153+
return wurflDevice.getCapability("physical_form_factor");
154+
} catch (CapabilityNotDefinedException e) {
155+
logger.warn("Failed to get physical_form_factor from WURFL device capabilities");
156+
return "";
157+
}
158+
}
159+
160+
private Boolean getWurflIsConsole() {
161+
try {
162+
return wurflDevice.getCapabilityAsBool("is_console");
163+
} catch (CapabilityNotDefinedException e) {
164+
logger.warn("Failed to get is_console from WURFL device capabilities");
165+
return Boolean.FALSE;
140166
}
141-
return null;
142167
}
143168

144169
private String getWurflOs() {
145170
try {
146171
return wurflDevice.getVirtualCapability("advertised_device_os");
147172
} catch (VirtualCapabilityNotDefinedException e) {
148-
logger.warn("Failed to evaluate advertised device OS", e);
173+
logger.warn("Failed to evaluate advertised device OS");
149174
return null;
150175
}
151176
}
@@ -154,7 +179,7 @@ private String getWurflOsv() {
154179
try {
155180
return wurflDevice.getVirtualCapability("advertised_device_os_version");
156181
} catch (VirtualCapabilityNotDefinedException e) {
157-
logger.warn("Failed to evaluate advertised device OS version", e);
182+
logger.warn("Failed to evaluate advertised device OS version");
158183
}
159184
return null;
160185
}
@@ -163,7 +188,7 @@ private Integer getWurflH() {
163188
try {
164189
return wurflDevice.getCapabilityAsInt("resolution_height");
165190
} catch (NumberFormatException e) {
166-
logger.warn("Failed to get resolution height from WURFL device capabilities", e);
191+
logger.warn("Failed to get resolution height from WURFL device capabilities");
167192
return null;
168193
}
169194
}
@@ -172,7 +197,7 @@ private Integer getWurflW() {
172197
try {
173198
return wurflDevice.getCapabilityAsInt("resolution_width");
174199
} catch (NumberFormatException e) {
175-
logger.warn("Failed to get resolution width from WURFL device capabilities", e);
200+
logger.warn("Failed to get resolution width from WURFL device capabilities");
176201
return null;
177202
}
178203
}
@@ -181,7 +206,7 @@ private Integer getWurflPpi() {
181206
try {
182207
return wurflDevice.getVirtualCapabilityAsInt("pixel_density");
183208
} catch (VirtualCapabilityNotDefinedException e) {
184-
logger.warn("Failed to get pixel density from WURFL device capabilities", e);
209+
logger.warn("Failed to get pixel density from WURFL device capabilities");
185210
return null;
186211
}
187212
}
@@ -193,7 +218,7 @@ private BigDecimal getWurflPxRatio() {
193218
? new BigDecimal(densityAsString)
194219
: null;
195220
} catch (CapabilityNotDefinedException | NumberFormatException e) {
196-
logger.warn("Failed to get pixel ratio from WURFL device capabilities", e);
221+
logger.warn("Failed to get pixel ratio from WURFL device capabilities");
197222
return null;
198223
}
199224
}
@@ -202,7 +227,7 @@ private Integer getWurflJs() {
202227
try {
203228
return wurflDevice.getCapabilityAsBool("ajax_support_javascript") ? 1 : 0;
204229
} catch (CapabilityNotDefinedException | NumberFormatException e) {
205-
logger.warn("Failed to get JS support from WURFL device capabilities", e);
230+
logger.warn("Failed to get JS support from WURFL device capabilities");
206231
return null;
207232
}
208233
}

extra/modules/wurfl-devicedetection/src/main/java/org/prebid/server/hooks/modules/com/scientiamobile/wurfl/devicedetection/v1/WURFLDeviceDetectionRawAuctionRequestHook.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.prebid.server.hooks.modules.com.scientiamobile.wurfl.devicedetection.v1;
22

33
import com.iab.openrtb.request.Device;
4+
import org.prebid.server.proto.openrtb.ext.request.ExtDevice;
45
import com.iab.openrtb.request.BidRequest;
56
import org.prebid.server.log.Logger;
67
import org.prebid.server.log.LoggerFactory;
@@ -31,6 +32,7 @@ public class WURFLDeviceDetectionRawAuctionRequestHook implements RawAuctionRequ
3132
private static final Logger logger = LoggerFactory.getLogger(WURFLDeviceDetectionRawAuctionRequestHook.class);
3233

3334
public static final String CODE = "wurfl-devicedetection-raw-auction-request";
35+
private static final String WURFL_PROPERTY = "wurfl";
3436

3537
private final WURFLService wurflService;
3638
private final Set<String> allowedPublisherIDs;
@@ -62,6 +64,11 @@ public Future<InvocationResult<AuctionRequestPayload>> call(AuctionRequestPayloa
6264
return noActionResult();
6365
}
6466

67+
if (isDeviceAlreadyEnriched(device)) {
68+
logger.info("Device is already enriched, returning original bid request");
69+
return noActionResult();
70+
}
71+
6572
final Map<String, String> requestHeaders =
6673
invocationContext.moduleContext() instanceof AuctionRequestHeadersContext moduleContext
6774
? moduleContext.getHeaders()
@@ -87,6 +94,18 @@ public Future<InvocationResult<AuctionRequestPayload>> call(AuctionRequestPayloa
8794
.build());
8895
}
8996

97+
private boolean isDeviceAlreadyEnriched(Device device) {
98+
final ExtDevice extDevice = device.getExt();
99+
if (extDevice != null && extDevice.containsProperty(WURFL_PROPERTY)) {
100+
return true;
101+
}
102+
103+
// Check if other some of the other Device data are already set
104+
final Integer deviceType = device.getDevicetype();
105+
final String hwv = device.getHwv();
106+
return deviceType != null && deviceType > 0 && StringUtils.isNotEmpty(hwv);
107+
}
108+
90109
private boolean shouldEnrichDevice(AuctionInvocationContext invocationContext) {
91110
return CollectionUtils.isEmpty(allowedPublisherIDs) || isAccountValid(invocationContext.auctionContext());
92111
}

0 commit comments

Comments
 (0)