Skip to content

Commit

Permalink
Triplelift Native: Mapping tag_code (#3745)
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickloughrey authored Jul 24, 2024
1 parent d1596c8 commit 536821f
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 5 deletions.
37 changes: 33 additions & 4 deletions adapters/triplelift_native/triplelift_native.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,30 @@ type TripleliftNativeExtInfo struct {
PublisherWhitelistMap map[string]struct{}
}

type ExtImpData struct {
TagCode string `json:"tag_code"`
}

type ExtImp struct {
*adapters.ExtImpBidder
Data *ExtImpData `json:"data,omitempty"`
}

func getBidType(ext TripleliftRespExt) openrtb_ext.BidType {
return openrtb_ext.BidTypeNative
}

func processImp(imp *openrtb2.Imp) error {
func processImp(imp *openrtb2.Imp, request *openrtb2.BidRequest) error {
// get the triplelift extension
var ext adapters.ExtImpBidder
var ext ExtImp
var tlext openrtb_ext.ExtImpTriplelift
var siteCopy openrtb2.Site
var extData ExtImpData

if request.Site != nil {
siteCopy = *request.Site
}

if err := json.Unmarshal(imp.Ext, &ext); err != nil {
return err
}
Expand All @@ -53,7 +69,20 @@ func processImp(imp *openrtb2.Imp) error {
if tlext.InvCode == "" {
return fmt.Errorf("no inv_code specified")
}
imp.TagID = tlext.InvCode

if ext.Data != nil {
extData = *ext.Data
}

if extData.TagCode != "" {
if siteCopy.Publisher.Domain == "msn.com" {
imp.TagID = extData.TagCode
} else {
imp.TagID = tlext.InvCode
}
} else {
imp.TagID = tlext.InvCode
}
// floor is optional
if tlext.Floor == nil {
return nil
Expand Down Expand Up @@ -89,7 +118,7 @@ func (a *TripleliftNativeAdapter) MakeRequests(request *openrtb2.BidRequest, ext
var validImps []openrtb2.Imp
// pre-process the imps
for _, imp := range tlRequest.Imp {
if err := processImp(&imp); err == nil {
if err := processImp(&imp, request); err == nil {
validImps = append(validImps, imp)
} else {
errs = append(errs, err)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"mockBidRequest": {
"id": "test-request-id",
"site": { "publisher": {"id":"foo","name":"foo", "domain": "msn.com"}},
"imp": [
{
"native": {
"request" : "{\"plcmtcnt\":1,\"plcmttype\":2,\"privacy\":1,\"context\":1,\"contextsubtype\":12,\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]},{\"event\":2,\"methods\":[1]}],\"assets\":[{\"data\":{\"type\":12},\"required\":1},{\"title\":{\"len\":50},\"required\":1},{\"img\":{\"w\":80,\"h\":80,\"type\":1},\"required\":1},{\"img\":{\"w\":1200,\"h\":627,\"type\":3},\"required\":1},{\"data\":{\"type\":3},\"required\":0},{\"data\":{\"len\":100,\"type\":2},\"required\":1},{\"video\":{\"mimes\":[\"video/mpeg\",\"video/mp4\"],\"minduration\":2,\"protocols\":[2,5],\"maxduration\":2,\"ext\":{\"playbackmethod\":[1,2]}},\"required\":1}],\"ver\":\"1.2\"}"
},
"id": "test-imp-id",
"ext": {
"bidder": {
"inventoryCode": "foo",
"floor" : 20
},
"data": {
"tag_code": "bar"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://tlx.3lift.net/s2sn/auction?supplier_id=20",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"native": {
"request" : "{\"plcmtcnt\":1,\"plcmttype\":2,\"privacy\":1,\"context\":1,\"contextsubtype\":12,\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]},{\"event\":2,\"methods\":[1]}],\"assets\":[{\"data\":{\"type\":12},\"required\":1},{\"title\":{\"len\":50},\"required\":1},{\"img\":{\"w\":80,\"h\":80,\"type\":1},\"required\":1},{\"img\":{\"w\":1200,\"h\":627,\"type\":3},\"required\":1},{\"data\":{\"type\":3},\"required\":0},{\"data\":{\"len\":100,\"type\":2},\"required\":1},{\"video\":{\"mimes\":[\"video/mpeg\",\"video/mp4\"],\"minduration\":2,\"protocols\":[2,5],\"maxduration\":2,\"ext\":{\"playbackmethod\":[1,2]}},\"required\":1}],\"ver\":\"1.2\"}"
},
"tagid": "bar",
"bidfloor": 20,
"ext": {
"bidder": {
"inventoryCode": "foo",
"floor" : 20
},
"data": {
"tag_code": "bar"
}
}
}
],
"site": {
"publisher": {
"id":"foo",
"name":"foo",
"domain": "msn.com"
}
}
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 204
}
}
],
"expectedBidResponses": []
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"mockBidRequest": {
"id": "test-request-id",
"site": { "publisher": {"id":"foo","name":"foo", "domain": "foo.com"}},
"imp": [
{
"native":{
"request" : "{\"plcmtcnt\":1,\"plcmttype\":2,\"privacy\":1,\"context\":1,\"contextsubtype\":12,\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]},{\"event\":2,\"methods\":[1]}],\"assets\":[{\"data\":{\"type\":12},\"required\":1},{\"title\":{\"len\":50},\"required\":1},{\"img\":{\"w\":80,\"h\":80,\"type\":1},\"required\":1},{\"img\":{\"w\":1200,\"h\":627,\"type\":3},\"required\":1},{\"data\":{\"type\":3},\"required\":0},{\"data\":{\"len\":100,\"type\":2},\"required\":1},{\"video\":{\"mimes\":[\"video/mpeg\",\"video/mp4\"],\"minduration\":2,\"protocols\":[2,5],\"maxduration\":2,\"ext\":{\"playbackmethod\":[1,2]}},\"required\":1}],\"ver\":\"1.2\"}"
},
"id": "test-imp-id",
"ext": {
"bidder": {
"inventoryCode": "foo",
"floor" : 20
},
"data": {
"tag_code": "bar"
}
}
}
]
},
"httpCalls": [
{
"expectedRequest": {
"uri": "http://tlx.3lift.net/s2sn/auction?supplier_id=20",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"native": {
"request" : "{\"plcmtcnt\":1,\"plcmttype\":2,\"privacy\":1,\"context\":1,\"contextsubtype\":12,\"eventtrackers\":[{\"event\":1,\"methods\":[1,2]},{\"event\":2,\"methods\":[1]}],\"assets\":[{\"data\":{\"type\":12},\"required\":1},{\"title\":{\"len\":50},\"required\":1},{\"img\":{\"w\":80,\"h\":80,\"type\":1},\"required\":1},{\"img\":{\"w\":1200,\"h\":627,\"type\":3},\"required\":1},{\"data\":{\"type\":3},\"required\":0},{\"data\":{\"len\":100,\"type\":2},\"required\":1},{\"video\":{\"mimes\":[\"video/mpeg\",\"video/mp4\"],\"minduration\":2,\"protocols\":[2,5],\"maxduration\":2,\"ext\":{\"playbackmethod\":[1,2]}},\"required\":1}],\"ver\":\"1.2\"}"
},
"tagid": "foo",
"bidfloor": 20,
"ext": {
"bidder": {
"inventoryCode": "foo",
"floor" : 20
},
"data": {
"tag_code": "bar"
}
}
}
],
"site": {
"publisher": {
"id": "foo",
"name": "foo",
"domain": "foo.com"
}
}
},
"impIDs":["test-imp-id"]
},
"mockResponse": {
"status": 204
}
}
],
"expectedBidResponses": []
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"expectedMakeRequestsErrors": [
{
"value": "json: cannot unmarshal string into Go value of type adapters.ExtImpBidder",
"value": "json: cannot unmarshal string into Go value of type triplelift_native.ExtImp",
"comparison": "literal"
},
{
Expand Down

0 comments on commit 536821f

Please sign in to comment.