Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public AuctionRequestPayload apply(AuctionRequestPayload auctionRequestPayload)
private Device update(Device ortbDevice) {
final String make = tryUpdateField(ortbDevice.getMake(), this::getWurflMake);
final String model = tryUpdateField(ortbDevice.getModel(), this::getWurflModel);
final String hwv = tryUpdateField(ortbDevice.getHwv(), this::getWurflModel);
final Integer deviceType = tryUpdateField(
Optional.ofNullable(ortbDevice.getDevicetype())
.filter(it -> it > 0)
Expand All @@ -72,6 +73,7 @@ private Device update(Device ortbDevice) {
.make(make)
.model(model)
.devicetype(deviceType)
.hwv(hwv)
.os(os)
.osv(osv)
.h(h)
Expand Down Expand Up @@ -103,49 +105,72 @@ private String getWurflModel() {
}

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

if (wurflDevice.getVirtualCapabilityAsBool("is_full_desktop")) {
return 2;
}
if (getWurflIsOtt()) {
return 7;
}

if (wurflDevice.getCapabilityAsBool("is_connected_tv")) {
return 3;
}
if (getWurflIsConsole()) {
return 6;
}

if (wurflDevice.getCapabilityAsBool("is_phone")) {
return 4;
}
if ("out_of_home_device".equals(getWurflPhysicalFormFactor())) {
return 8;
}

if (wurflDevice.getCapabilityAsBool("is_tablet")) {
return 5;
}
final String formFactor = getWurflFormFactor();
return switch (formFactor) {
case "Desktop" -> 2;
case "Smartphone", "Feature Phone" -> 4;
case "Tablet" -> 5;
case "Smart-TV" -> 3;
case "Other Non-Mobile" -> 6;
case "Other Mobile" -> 1;
default -> null;
};
}

if (wurflDevice.getCapabilityAsBool("is_ott")) {
return 7;
}
private Boolean getWurflIsOtt() {
try {
return wurflDevice.getCapabilityAsBool("is_ott");
} catch (CapabilityNotDefinedException e) {
logger.warn("Failed to get is_ott from WURFL device capabilities");
return Boolean.FALSE;
}
}

final String physicalFormFactor = wurflDevice.getCapability("physical_form_factor");
if (physicalFormFactor != null && physicalFormFactor.equals("out_of_home_device")) {
return 8;
}
} catch (CapabilityNotDefinedException | VirtualCapabilityNotDefinedException | NumberFormatException e) {
logger.warn("Failed to determine device type from WURFL device capabilities", e);
private String getWurflFormFactor() {
try {
return wurflDevice.getVirtualCapability("form_factor");
} catch (VirtualCapabilityNotDefinedException e) {
logger.warn("Failed to get form_factor from WURFL device capabilities");
return "";
}
}

private String getWurflPhysicalFormFactor() {
try {
return wurflDevice.getCapability("physical_form_factor");
} catch (CapabilityNotDefinedException e) {
logger.warn("Failed to get physical_form_factor from WURFL device capabilities");
return "";
}
}

private Boolean getWurflIsConsole() {
try {
return wurflDevice.getCapabilityAsBool("is_console");
} catch (CapabilityNotDefinedException e) {
logger.warn("Failed to get is_console from WURFL device capabilities");
return Boolean.FALSE;
}
return null;
}

private String getWurflOs() {
try {
return wurflDevice.getVirtualCapability("advertised_device_os");
} catch (VirtualCapabilityNotDefinedException e) {
logger.warn("Failed to evaluate advertised device OS", e);
logger.warn("Failed to evaluate advertised device OS");
return null;
}
}
Expand All @@ -154,7 +179,7 @@ private String getWurflOsv() {
try {
return wurflDevice.getVirtualCapability("advertised_device_os_version");
} catch (VirtualCapabilityNotDefinedException e) {
logger.warn("Failed to evaluate advertised device OS version", e);
logger.warn("Failed to evaluate advertised device OS version");
}
return null;
}
Expand All @@ -163,7 +188,7 @@ private Integer getWurflH() {
try {
return wurflDevice.getCapabilityAsInt("resolution_height");
} catch (NumberFormatException e) {
logger.warn("Failed to get resolution height from WURFL device capabilities", e);
logger.warn("Failed to get resolution height from WURFL device capabilities");
return null;
}
}
Expand All @@ -172,7 +197,7 @@ private Integer getWurflW() {
try {
return wurflDevice.getCapabilityAsInt("resolution_width");
} catch (NumberFormatException e) {
logger.warn("Failed to get resolution width from WURFL device capabilities", e);
logger.warn("Failed to get resolution width from WURFL device capabilities");
return null;
}
}
Expand All @@ -181,7 +206,7 @@ private Integer getWurflPpi() {
try {
return wurflDevice.getVirtualCapabilityAsInt("pixel_density");
} catch (VirtualCapabilityNotDefinedException e) {
logger.warn("Failed to get pixel density from WURFL device capabilities", e);
logger.warn("Failed to get pixel density from WURFL device capabilities");
return null;
}
}
Expand All @@ -193,7 +218,7 @@ private BigDecimal getWurflPxRatio() {
? new BigDecimal(densityAsString)
: null;
} catch (CapabilityNotDefinedException | NumberFormatException e) {
logger.warn("Failed to get pixel ratio from WURFL device capabilities", e);
logger.warn("Failed to get pixel ratio from WURFL device capabilities");
return null;
}
}
Expand All @@ -202,7 +227,7 @@ private Integer getWurflJs() {
try {
return wurflDevice.getCapabilityAsBool("ajax_support_javascript") ? 1 : 0;
} catch (CapabilityNotDefinedException | NumberFormatException e) {
logger.warn("Failed to get JS support from WURFL device capabilities", e);
logger.warn("Failed to get JS support from WURFL device capabilities");
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.hooks.modules.com.scientiamobile.wurfl.devicedetection.v1;

import com.iab.openrtb.request.Device;
import org.prebid.server.proto.openrtb.ext.request.ExtDevice;
import com.iab.openrtb.request.BidRequest;
import org.prebid.server.log.Logger;
import org.prebid.server.log.LoggerFactory;
Expand Down Expand Up @@ -31,6 +32,7 @@ public class WURFLDeviceDetectionRawAuctionRequestHook implements RawAuctionRequ
private static final Logger logger = LoggerFactory.getLogger(WURFLDeviceDetectionRawAuctionRequestHook.class);

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

private final WURFLService wurflService;
private final Set<String> allowedPublisherIDs;
Expand Down Expand Up @@ -62,6 +64,11 @@ public Future<InvocationResult<AuctionRequestPayload>> call(AuctionRequestPayloa
return noActionResult();
}

if (isDeviceAlreadyEnriched(device)) {
logger.info("Device is already enriched, returning original bid request");
return noActionResult();
}

final Map<String, String> requestHeaders =
invocationContext.moduleContext() instanceof AuctionRequestHeadersContext moduleContext
? moduleContext.getHeaders()
Expand All @@ -87,6 +94,18 @@ public Future<InvocationResult<AuctionRequestPayload>> call(AuctionRequestPayloa
.build());
}

private boolean isDeviceAlreadyEnriched(Device device) {
final ExtDevice extDevice = device.getExt();
if (extDevice != null && extDevice.containsProperty(WURFL_PROPERTY)) {
return true;
}

// Check if other some of the other Device data are already set
final Integer deviceType = device.getDevicetype();
final String hwv = device.getHwv();
return deviceType != null && deviceType > 0 && StringUtils.isNotEmpty(hwv);
}

private boolean shouldEnrichDevice(AuctionInvocationContext invocationContext) {
return CollectionUtils.isEmpty(allowedPublisherIDs) || isAccountValid(invocationContext.auctionContext());
}
Expand Down
Loading
Loading