diff --git a/adapters/triplelift_native/triplelift_native.go b/adapters/triplelift_native/triplelift_native.go index c3556cfa8bb..465ea32df59 100644 --- a/adapters/triplelift_native/triplelift_native.go +++ b/adapters/triplelift_native/triplelift_native.go @@ -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 } @@ -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 @@ -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) diff --git a/adapters/triplelift_native/triplelift_nativetest/exemplary/msn-params.json b/adapters/triplelift_native/triplelift_nativetest/exemplary/msn-params.json new file mode 100644 index 00000000000..7806a7bd6ae --- /dev/null +++ b/adapters/triplelift_native/triplelift_nativetest/exemplary/msn-params.json @@ -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": [] + } + \ No newline at end of file diff --git a/adapters/triplelift_native/triplelift_nativetest/exemplary/tagcode-params.json b/adapters/triplelift_native/triplelift_nativetest/exemplary/tagcode-params.json new file mode 100644 index 00000000000..c97febcfea2 --- /dev/null +++ b/adapters/triplelift_native/triplelift_nativetest/exemplary/tagcode-params.json @@ -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": [] + } + \ No newline at end of file diff --git a/adapters/triplelift_native/triplelift_nativetest/supplemental/badext.json b/adapters/triplelift_native/triplelift_nativetest/supplemental/badext.json index 7df178bdd00..f43deb8b7c5 100644 --- a/adapters/triplelift_native/triplelift_nativetest/supplemental/badext.json +++ b/adapters/triplelift_native/triplelift_nativetest/supplemental/badext.json @@ -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" }, {