Skip to content
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

Include EIDs from user.ext.eids in 2.6 upgrade function #4226

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 39 additions & 6 deletions openrtb_ext/convert_up.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,50 @@ func moveUSPrivacyFrom25To26(r *RequestWrapper) {

// moveEIDFrom25To26 modifies the request to move the OpenRTB 2.5 external identifiers
// (req.user.ext.eids) to the OpenRTB 2.6 location (req.user.eids). If the OpenRTB 2.6
// location is already present the OpenRTB 2.5 external identifiers is dropped.
// location is already present the OpenRTB 2.5 external identifiers are appended for
// sources not already in the eids array
func moveEIDFrom25To26(r *RequestWrapper) {
// read and clear 2.5 location
// Read 2.5 location
userExt, _ := r.GetUserExt()
eid25 := userExt.GetEid()
eids25 := userExt.GetEid()

// Clear 2.5 location
userExt.SetEid(nil)

// move to 2.6 location
if eid25 != nil && r.User.EIDs == nil {
r.User.EIDs = *eid25
// If there's no eids25, there's nothing to move or merge
if eids25 == nil || len(*eids25) == 0 {
return
}

// If there's no 2.6 location, simply set eids
if r.User.EIDs == nil {
r.User.EIDs = *eids25
return
}

// If 2.6 location is present, append only new eids based on 'source'.
existingEIDs := r.User.EIDs
for _, eid25 := range *eids25 {
// If source is empty, append
if eid25.Source == "" {
existingEIDs = append(existingEIDs, eid25)
continue
}

found := false
for _, eid26 := range existingEIDs {
// Compare strings directly
if eid25.Source == eid26.Source {
found = true
break
}
}

if !found {
existingEIDs = append(existingEIDs, eid25)
}
}
r.User.EIDs = existingEIDs
}

// moveRewardedFromPrebidExtTo26 modifies the impression to move the Prebid specific
Expand Down
29 changes: 26 additions & 3 deletions openrtb_ext/convert_up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,32 @@ func TestMoveEIDFrom25To26(t *testing.T) {
expectedRequest: openrtb2.BidRequest{User: &openrtb2.User{EIDs: eid1}},
},
{
description: "2.5 Dropped",
givenRequest: openrtb2.BidRequest{User: &openrtb2.User{EIDs: eid1, Ext: eid2Json}},
expectedRequest: openrtb2.BidRequest{User: &openrtb2.User{EIDs: eid1}},
description: "2.5 Appended Because Different Source from all 2.6 eids",
givenRequest: openrtb2.BidRequest{
User: &openrtb2.User{
EIDs: []openrtb2.EID{{Source: "1"}},
Ext: eid2Json,
},
},
expectedRequest: openrtb2.BidRequest{
User: &openrtb2.User{
EIDs: []openrtb2.EID{{Source: "1"}, {Source: "2"}},
},
},
},
{
description: "2.5 Not Appended Because Same Source exists IN 2.6",
givenRequest: openrtb2.BidRequest{
User: &openrtb2.User{
EIDs: []openrtb2.EID{{Source: "1"}},
Ext: eid1Json,
},
},
expectedRequest: openrtb2.BidRequest{
User: &openrtb2.User{
EIDs: []openrtb2.EID{{Source: "1"}},
},
},
},
{
description: "2.6 Left Alone",
Expand Down
Loading