From 0fd8dd2df6167fb677f3098aebfd583e271d6922 Mon Sep 17 00:00:00 2001 From: PubMatic-OpenWrap Date: Mon, 9 Jul 2018 22:44:36 +0530 Subject: [PATCH] Adding creative type check in pubmatic adapter (#601) --- adapters/pubmatic/pubmatic.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/adapters/pubmatic/pubmatic.go b/adapters/pubmatic/pubmatic.go index 8eb228a71f3..bb72a207ec1 100644 --- a/adapters/pubmatic/pubmatic.go +++ b/adapters/pubmatic/pubmatic.go @@ -13,6 +13,7 @@ import ( "github.com/golang/glog" "github.com/mxmCherry/openrtb" "github.com/prebid/prebid-server/adapters" + "github.com/prebid/prebid-server/openrtb_ext" "github.com/prebid/prebid-server/pbs" "golang.org/x/net/context/ctxhttp" ) @@ -227,6 +228,9 @@ func (a *PubmaticAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder DealId: bid.DealID, } + mediaType := getMediaTypeForImp(bid.ImpID, pbReq.Imp) + pbid.CreativeMediaType = string(mediaType) + bids = append(bids, &pbid) logf("[PUBMATIC] Returned Bid for PubID [%s] AdUnit [%s] BidID [%s] Size [%dx%d] Price [%f] \n", pubId, pbid.AdUnitCode, pbid.BidID, pbid.Width, pbid.Height, pbid.Price) @@ -236,6 +240,24 @@ func (a *PubmaticAdapter) Call(ctx context.Context, req *pbs.PBSRequest, bidder return bids, nil } +// getMediaTypeForImp figures out which media type this bid is for. +func getMediaTypeForImp(impId string, imps []openrtb.Imp) openrtb_ext.BidType { + mediaType := openrtb_ext.BidTypeBanner + for _, imp := range imps { + if imp.ID == impId { + if imp.Video != nil { + mediaType = openrtb_ext.BidTypeVideo + } else if imp.Audio != nil { + mediaType = openrtb_ext.BidTypeAudio + } else if imp.Native != nil { + mediaType = openrtb_ext.BidTypeNative + } + return mediaType + } + } + return mediaType +} + func logf(msg string, args ...interface{}) { if glog.V(2) { glog.Infof(msg, args)