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

Pubmatic: Set bid.meta.mediaType=video when bid.ext.ibv=true #4189

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
37 changes: 23 additions & 14 deletions adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type pubmaticBidExt struct {
VideoCreativeInfo *pubmaticBidExtVideo `json:"video,omitempty"`
Marketplace string `json:"marketplace,omitempty"`
PrebidDealPriority int `json:"prebiddealpriority,omitempty"`
InBannerVideo bool `json:"ibv,omitempty"`
}

type pubmaticWrapperExt struct {
Expand Down Expand Up @@ -461,6 +462,7 @@ func (a *PubmaticAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externa
bid.Cat = bid.Cat[0:1]
}

MType := getMediaTypeForBid(&bid)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
typedBid := &adapters.TypedBid{
Bid: &bid,
BidType: openrtb_ext.BidTypeBanner,
Expand All @@ -473,14 +475,19 @@ func (a *PubmaticAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externa
errs = append(errs, err)
} else if bidExt != nil {
typedBid.Seat = openrtb_ext.BidderName(bidExt.Marketplace)
typedBid.BidType = getBidType(bidExt)
typedBid.BidType = getMediaTypeForBid(&bid)
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
if bidExt.PrebidDealPriority > 0 {
typedBid.DealPriority = bidExt.PrebidDealPriority
}

if bidExt.VideoCreativeInfo != nil && bidExt.VideoCreativeInfo.Duration != nil {
typedBid.BidVideo.Duration = *bidExt.VideoCreativeInfo.Duration
}

if bidExt.InBannerVideo {
MType = openrtb_ext.BidTypeVideo
}
typedBid.BidMeta = &openrtb_ext.ExtBidPrebidMeta{MediaType: string(MType)}
}

if typedBid.BidType == openrtb_ext.BidTypeNative {
Expand Down Expand Up @@ -637,24 +644,26 @@ func getStringArray(array []interface{}) []string {
return aString
}

// getBidType returns the bid type specified in the response bid.ext
func getBidType(bidExt *pubmaticBidExt) openrtb_ext.BidType {
// getMediaType returns the bid type specified in the response bid.ext
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
func getMediaTypeForBid(bid *openrtb2.Bid) openrtb_ext.BidType {
// setting "banner" as the default bid type
bidType := openrtb_ext.BidTypeBanner
if bidExt != nil && bidExt.BidType != nil {
switch *bidExt.BidType {
case 0:
bidType = openrtb_ext.BidTypeBanner
case 1:
bidType = openrtb_ext.BidTypeVideo
case 2:
bidType = openrtb_ext.BidTypeNative
mType := openrtb_ext.BidTypeBanner
if bid != nil {
switch bid.MType {
case openrtb2.MarkupBanner:
mType = openrtb_ext.BidTypeBanner
case openrtb2.MarkupVideo:
mType = openrtb_ext.BidTypeVideo
case openrtb2.MarkupAudio:
mType = openrtb_ext.BidTypeAudio
case openrtb2.MarkupNative:
mType = openrtb_ext.BidTypeNative
default:
// default value is banner
bidType = openrtb_ext.BidTypeBanner
mType = openrtb_ext.BidTypeBanner
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
}
}
return bidType
return mType
}

// Builder builds a new instance of the Pubmatic adapter for the given bidder with the given config.
Expand Down
147 changes: 115 additions & 32 deletions adapters/pubmatic/pubmatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,47 @@ func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "pubmatictest", bidder)
}

func TestGetBidTypeVideo(t *testing.T) {
pubmaticExt := &pubmaticBidExt{}
pubmaticExt.BidType = new(int)
*pubmaticExt.BidType = 1
actualBidTypeValue := getBidType(pubmaticExt)
if actualBidTypeValue != openrtb_ext.BidTypeVideo {
t.Errorf("Expected Bid Type value was: %v, actual value is: %v", openrtb_ext.BidTypeVideo, actualBidTypeValue)
func TestGetMediaTypeForBidBanner(t *testing.T) {
pm-priyanka-bagade marked this conversation as resolved.
Show resolved Hide resolved
Bid := openrtb2.Bid{}
Bid.MType = 1
actualBidTypeValue := string(getMediaTypeForBid(&Bid))
if actualBidTypeValue != string(openrtb_ext.BidTypeBanner) {
t.Errorf("Expected Bid Type value was: %v, actual value is: %v", openrtb_ext.BidTypeBanner, actualBidTypeValue)
}
}

func TestGetBidTypeForMissingBidTypeExt(t *testing.T) {
pubmaticExt := &pubmaticBidExt{}
actualBidTypeValue := getBidType(pubmaticExt)
// banner is the default bid type when no bidType key is present in the bid.ext
if actualBidTypeValue != "banner" {
t.Errorf("Expected Bid Type value was: banner, actual value is: %v", actualBidTypeValue)
func TestGetMediaTypeForBidVideo(t *testing.T) {
Bid := openrtb2.Bid{}
Bid.MType = 2
actualBidTypeValue := string(getMediaTypeForBid(&Bid))
if actualBidTypeValue != string(openrtb_ext.BidTypeVideo) {
t.Errorf("Expected Bid Type value was: %v, actual value is: %v", openrtb_ext.BidTypeVideo, actualBidTypeValue)
}
}

func TestGetBidTypeBanner(t *testing.T) {
pubmaticExt := &pubmaticBidExt{}
pubmaticExt.BidType = new(int)
*pubmaticExt.BidType = 0
actualBidTypeValue := getBidType(pubmaticExt)
if actualBidTypeValue != openrtb_ext.BidTypeBanner {
t.Errorf("Expected Bid Type value was: %v, actual value is: %v", openrtb_ext.BidTypeBanner, actualBidTypeValue)
func TestGetMediaTypeForBidAudio(t *testing.T) {
Bid := openrtb2.Bid{}
Bid.MType = 3
actualBidTypeValue := string(getMediaTypeForBid(&Bid))
if actualBidTypeValue != string(openrtb_ext.BidTypeAudio) {
t.Errorf("Expected Bid Type value was: %v, actual value is: %v", openrtb_ext.BidTypeAudio, actualBidTypeValue)
}
}

func TestGetBidTypeNative(t *testing.T) {
pubmaticExt := &pubmaticBidExt{}
pubmaticExt.BidType = new(int)
*pubmaticExt.BidType = 2
actualBidTypeValue := getBidType(pubmaticExt)
if actualBidTypeValue != openrtb_ext.BidTypeNative {
func TestGetMediaTypeForBidNative(t *testing.T) {
Bid := openrtb2.Bid{}
Bid.MType = 4
actualBidTypeValue := string(getMediaTypeForBid(&Bid))
if actualBidTypeValue != string(openrtb_ext.BidTypeNative) {
t.Errorf("Expected Bid Type value was: %v, actual value is: %v", openrtb_ext.BidTypeNative, actualBidTypeValue)
}
}

func TestGetBidTypeForUnsupportedCode(t *testing.T) {
pubmaticExt := &pubmaticBidExt{}
pubmaticExt.BidType = new(int)
*pubmaticExt.BidType = 99
actualBidTypeValue := getBidType(pubmaticExt)
if actualBidTypeValue != openrtb_ext.BidTypeBanner {
func TestGetMediaTypeForBidForUnsupportedCode(t *testing.T) {
Bid := openrtb2.Bid{}
Bid.MType = 44
actualBidTypeValue := string(getMediaTypeForBid(&Bid))
if actualBidTypeValue != string(openrtb_ext.BidTypeBanner) {
t.Errorf("Expected Bid Type value was: %v, actual value is: %v", openrtb_ext.BidTypeBanner, actualBidTypeValue)
}
}
Expand Down Expand Up @@ -421,6 +417,24 @@ func TestPubmaticAdapter_MakeBids(t *testing.T) {
DealPriority: 1,
BidType: openrtb_ext.BidTypeBanner,
BidVideo: &openrtb_ext.ExtBidPrebidVideo{},
BidMeta: &openrtb_ext.ExtBidPrebidMeta{
AdapterCode: "",
AdvertiserDomains: nil,
AdvertiserID: 0,
AdvertiserName: "",
AgencyID: 0,
AgencyName: "",
DChain: nil,
DemandSource: "",
MediaType: "banner",
NetworkID: 0,
NetworkName: "",
RendererName: "",
RendererVersion: "",
RendererData: nil,
RendererUrl: "",
SecondaryCategoryIDs: nil,
},
},
},
Currency: "USD",
Expand Down Expand Up @@ -453,6 +467,75 @@ func TestPubmaticAdapter_MakeBids(t *testing.T) {
},
BidType: openrtb_ext.BidTypeBanner,
BidVideo: &openrtb_ext.ExtBidPrebidVideo{},
BidMeta: &openrtb_ext.ExtBidPrebidMeta{
AdapterCode: "",
AdvertiserDomains: nil,
AdvertiserID: 0,
AdvertiserName: "",
AgencyID: 0,
AgencyName: "",
DChain: nil,
DemandSource: "",
MediaType: "banner",
NetworkID: 0,
NetworkName: "",
RendererName: "",
RendererVersion: "",
RendererData: nil,
RendererUrl: "",
SecondaryCategoryIDs: nil,
},
},
},
Currency: "USD",
},
},
{
name: "bid_ext_InBannerVideo_is_true",
args: args{
response: &adapters.ResponseData{
StatusCode: http.StatusOK,
Body: []byte(`{"id": "test-request-id", "seatbid":[{"seat": "958", "bid":[{"id": "7706636740145184841", "impid": "test-imp-id", "price": 0.500000, "adid": "29681110", "adm": "some-test-ad", "adomain":["pubmatic.com"], "crid": "29681110", "h": 250, "w": 300, "dealid": "testdeal", "mtype": 1, "ext":{"dspid": 6, "deal_channel": 1, "prebiddealpriority": -1, "ibv": true}}]}], "bidid": "5778926625248726496", "cur": "USD"}`),
},
},
wantErr: nil,
wantResp: &adapters.BidderResponse{
Bids: []*adapters.TypedBid{
{
Bid: &openrtb2.Bid{
ID: "7706636740145184841",
ImpID: "test-imp-id",
Price: 0.500000,
AdID: "29681110",
AdM: "some-test-ad",
ADomain: []string{"pubmatic.com"},
CrID: "29681110",
H: 250,
W: 300,
DealID: "testdeal",
MType: 1,
Ext: json.RawMessage(`{"dspid": 6, "deal_channel": 1, "prebiddealpriority": -1, "ibv": true}`),
},
BidType: openrtb_ext.BidTypeBanner,
BidVideo: &openrtb_ext.ExtBidPrebidVideo{},
BidMeta: &openrtb_ext.ExtBidPrebidMeta{
AdapterCode: "",
AdvertiserDomains: nil,
AdvertiserID: 0,
AdvertiserName: "",
AgencyID: 0,
AgencyName: "",
DChain: nil,
DemandSource: "",
MediaType: "video",
NetworkID: 0,
NetworkName: "",
RendererName: "",
RendererVersion: "",
RendererData: nil,
RendererUrl: "",
SecondaryCategoryIDs: nil,
},
},
},
Currency: "USD",
Expand Down
2 changes: 2 additions & 0 deletions adapters/pubmatic/pubmatictest/exemplary/banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"h": 250,
"w": 300,
"dealid":"test deal",
"mtype": 1,
"ext": {
"dspid": 6,
"deal_channel": 1,
Expand Down Expand Up @@ -142,6 +143,7 @@
"w": 300,
"h": 250,
"dealid":"test deal",
"mtype": 1,
"ext": {
"dspid": 6,
"deal_channel": 1,
Expand Down
2 changes: 2 additions & 0 deletions adapters/pubmatic/pubmatictest/exemplary/native.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
"adid": "some-test-id",
"adm": "{\"native\":{\"assets\":[{\"id\":2,\"img\":{\"h\":90,\"url\":\"//ads.pubmatic.com/AdTag/native/728x90.png\",\"w\":728}},{\"data\":{\"value\":\"Sponsored By PubMatic\"},\"id\":4},{\"id\":3,\"img\":{\"h\":90,\"url\":\"//ads.pubmatic.com/AdTag/native/728x90.png\",\"w\":728}},{\"id\":1,\"title\":{\"text\":\"Native Test Title\"}},{\"data\":{\"value\":\"Sponsored By PubMatic\"},\"id\":5}],\"imptrackers\":[\"http://clicktracker.com/AdTag/9bde02d0-6017-11e4-9df7-005056967c35\"],\"jstracker\":\"<script src='\\\/\\\/ads.pubmatic.com\\\/AdTag\\\/native\\\/tempReseponse.js'><script src='\\\/\\\/ads.pubmatic.com\\\/AdTag\\\/native\\\/tempReseponse.js'>\",\"link\":{\"clicktrackers\":[\"http://clicktracker.com/AdTag/9bde02d0-6017-11e4-9df7-005056967c35\"],\"fallback\":\"http://www.pubmatic.com\",\"url\":\"//www.pubmatic.com\"}}}",
"crid": "29681110",
"mtype":4,
"ext": {
"deal_channel": 1,
"bidtype": 2
Expand All @@ -102,6 +103,7 @@
"adid": "some-test-id",
"adm": "{\"assets\":[{\"id\":2,\"img\":{\"h\":90,\"url\":\"//ads.pubmatic.com/AdTag/native/728x90.png\",\"w\":728}},{\"data\":{\"value\":\"Sponsored By PubMatic\"},\"id\":4},{\"id\":3,\"img\":{\"h\":90,\"url\":\"//ads.pubmatic.com/AdTag/native/728x90.png\",\"w\":728}},{\"id\":1,\"title\":{\"text\":\"Native Test Title\"}},{\"data\":{\"value\":\"Sponsored By PubMatic\"},\"id\":5}],\"imptrackers\":[\"http://clicktracker.com/AdTag/9bde02d0-6017-11e4-9df7-005056967c35\"],\"jstracker\":\"<script src='\\\/\\\/ads.pubmatic.com\\\/AdTag\\\/native\\\/tempReseponse.js'><script src='\\\/\\\/ads.pubmatic.com\\\/AdTag\\\/native\\\/tempReseponse.js'>\",\"link\":{\"clicktrackers\":[\"http://clicktracker.com/AdTag/9bde02d0-6017-11e4-9df7-005056967c35\"],\"fallback\":\"http://www.pubmatic.com\",\"url\":\"//www.pubmatic.com\"}}",
"crid": "29681110",
"mtype":4,
"ext": {
"deal_channel": 1,
"bidtype": 2
Expand Down
2 changes: 2 additions & 0 deletions adapters/pubmatic/pubmatictest/exemplary/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"w": 300,
"dealid":"test deal",
"cat" : ["IAB-1", "IAB-2"],
"mtype":2,
"ext": {
"dspid": 6,
"deal_channel": 1,
Expand Down Expand Up @@ -160,6 +161,7 @@
"w": 300,
"h": 250,
"dealid":"test deal",
"mtype":2,
"ext": {
"dspid": 6,
"deal_channel": 1,
Expand Down
Loading
Loading