-
Notifications
You must be signed in to change notification settings - Fork 813
Support bidder-specific device data #4197
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
Changes from all commits
bed560d
cee8f6c
7abb2a8
68ad2b8
a626f45
e65a0b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,9 +32,10 @@ const ( | |
) | ||
|
||
type ResolvedFirstPartyData struct { | ||
Site *openrtb2.Site | ||
App *openrtb2.App | ||
User *openrtb2.User | ||
Site *openrtb2.Site | ||
App *openrtb2.App | ||
User *openrtb2.User | ||
Device *openrtb2.Device | ||
} | ||
|
||
// ExtractGlobalFPD extracts request level FPD from the request and removes req.{site,app,user}.ext.data if exists | ||
|
@@ -159,13 +160,75 @@ func ResolveFPD(bidRequest *openrtb2.BidRequest, fpdBidderConfigData map[openrtb | |
} | ||
resolvedFpdConfig.Site = newSite | ||
|
||
newDevice, err := resolveDevice(fpdConfig, bidRequest.Device) | ||
if err != nil { | ||
errL = append(errL, err) | ||
} | ||
resolvedFpdConfig.Device = newDevice | ||
|
||
if len(errL) == 0 { | ||
resolvedFpd[openrtb_ext.BidderName(bidderName)] = resolvedFpdConfig | ||
} | ||
} | ||
return resolvedFpd, errL | ||
} | ||
|
||
// resolveDevice merges the device information from the FPD (First Party Data) configuration | ||
// with the device information provided in the bid request. It returns a new Device object | ||
// that contains the merged data. | ||
func resolveDevice(fpdConfig *openrtb_ext.ORTB2, bidRequestDevice *openrtb2.Device) (*openrtb2.Device, error) { | ||
var fpdConfigDevice json.RawMessage | ||
|
||
if fpdConfig != nil && fpdConfig.Device != nil { | ||
fpdConfigDevice = fpdConfig.Device | ||
} | ||
|
||
if bidRequestDevice == nil && fpdConfigDevice == nil { | ||
return nil, nil | ||
} | ||
|
||
var newDevice *openrtb2.Device | ||
if bidRequestDevice != nil { | ||
newDevice = ptrutil.Clone(bidRequestDevice) | ||
} else { | ||
newDevice = &openrtb2.Device{} | ||
} | ||
|
||
if fpdConfigDevice != nil { | ||
if err := jsonutil.MergeClone(newDevice, fpdConfigDevice); err != nil { | ||
return nil, formatMergeCloneError(err) | ||
} | ||
} | ||
|
||
err := validateDevice(newDevice) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return newDevice, nil | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add device validation before returning it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added in 7abb2a8 |
||
|
||
func validateDevice(device *openrtb2.Device) error { | ||
if device == nil { | ||
return nil | ||
} | ||
|
||
// The following fields were previously uints in the OpenRTB library we use, but have | ||
// since been changed to ints. We decided to maintain the non-negative check. | ||
if device.W < 0 { | ||
return errors.New("request.device.w must be a positive number") | ||
} | ||
if device.H < 0 { | ||
return errors.New("request.device.h must be a positive number") | ||
} | ||
if device.PPI < 0 { | ||
return errors.New("request.device.ppi must be a positive number") | ||
} | ||
if device.Geo != nil && device.Geo.Accuracy < 0 { | ||
return errors.New("request.device.geo.accuracy must be a positive number") | ||
} | ||
return nil | ||
} | ||
|
||
func resolveUser(fpdConfig *openrtb_ext.ORTB2, bidRequestUser *openrtb2.User, globalFPD map[string][]byte, openRtbGlobalFPD map[string][]openrtb2.Data, bidderName string) (*openrtb2.User, error) { | ||
var fpdConfigUser json.RawMessage | ||
|
||
|
@@ -377,6 +440,7 @@ func ExtractBidderConfigFPD(reqExt *openrtb_ext.RequestExt) (map[openrtb_ext.Bid | |
fpdBidderData.Site = bidderConfig.Config.ORTB2.Site | ||
fpdBidderData.App = bidderConfig.Config.ORTB2.App | ||
fpdBidderData.User = bidderConfig.Config.ORTB2.User | ||
fpdBidderData.Device = bidderConfig.Config.ORTB2.Device | ||
} | ||
|
||
fpd[bidderName] = fpdBidderData | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add the following test case:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added in e65a0b2