From 4975e50cacc2e6f98aa7b0115e34adb81ae49409 Mon Sep 17 00:00:00 2001 From: ckbo3hrk Date: Thu, 18 Apr 2024 15:43:26 +0300 Subject: [PATCH 1/3] Adkernel: bid.mtype support --- adapters/adkernel/adkernel.go | 48 +++++++------------ .../exemplary/multiformat-impression.json | 3 ++ .../exemplary/single-banner-impression.json | 1 + .../exemplary/single-video-impression.json | 1 + 4 files changed, 21 insertions(+), 32 deletions(-) diff --git a/adapters/adkernel/adkernel.go b/adapters/adkernel/adkernel.go index 09a2358a951..995ba0d437d 100644 --- a/adapters/adkernel/adkernel.go +++ b/adapters/adkernel/adkernel.go @@ -259,48 +259,32 @@ func (adapter *adkernelAdapter) MakeBids(internalRequest *openrtb2.BidRequest, e bidResponse.Currency = bidResp.Cur for i := 0; i < len(seatBid.Bid); i++ { bid := seatBid.Bid[i] - origImpId := bid.ImpID - typeSuffix := "" - if strings.HasSuffix(origImpId, mf_suffix) { - sfxStart := len(origImpId) - len(mf_suffix) - 1 - typeSuffix = origImpId[sfxStart:] - bid.ImpID = origImpId[:sfxStart] + if strings.HasSuffix(bid.ImpID, mf_suffix) { + sfxStart := len(bid.ImpID) - len(mf_suffix) - 1 + bid.ImpID = bid.ImpID[:sfxStart] } bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ Bid: &bid, - BidType: getMediaTypeForImpID(bid.ImpID, typeSuffix, internalRequest.Imp), + BidType: getMediaTypeForBid(&bid), }) } return bidResponse, nil } // getMediaTypeForImp figures out which media type this bid is for -func getMediaTypeForImpID(impID string, typeSuffix string, imps []openrtb2.Imp) openrtb_ext.BidType { - if len(typeSuffix) > 0 { - if typeSuffix == mf_suffix_banner { - return openrtb_ext.BidTypeBanner - } else if typeSuffix == mf_suffix_video { - return openrtb_ext.BidTypeVideo - } else if typeSuffix == mf_suffix_audio { - return openrtb_ext.BidTypeAudio - } else if typeSuffix == mf_suffix_native { - return openrtb_ext.BidTypeNative - } - } - for _, imp := range imps { - if imp.ID == impID { - if imp.Banner != nil { - return openrtb_ext.BidTypeBanner - } else if imp.Video != nil { - return openrtb_ext.BidTypeVideo - } else if imp.Audio != nil { - return openrtb_ext.BidTypeAudio - } else if imp.Native != nil { - return openrtb_ext.BidTypeNative - } - } +func getMediaTypeForBid(bid *openrtb2.Bid) openrtb_ext.BidType { + switch bid.MType { + case openrtb2.MarkupBanner: + return openrtb_ext.BidTypeBanner + case openrtb2.MarkupAudio: + return openrtb_ext.BidTypeAudio + case openrtb2.MarkupNative: + return openrtb_ext.BidTypeNative + case openrtb2.MarkupVideo: + return openrtb_ext.BidTypeVideo + default: + return openrtb_ext.BidTypeBanner } - return openrtb_ext.BidTypeVideo } func newBadInputError(message string) error { diff --git a/adapters/adkernel/adkerneltest/exemplary/multiformat-impression.json b/adapters/adkernel/adkerneltest/exemplary/multiformat-impression.json index 49c5249f0cc..d4509ae56da 100644 --- a/adapters/adkernel/adkerneltest/exemplary/multiformat-impression.json +++ b/adapters/adkernel/adkerneltest/exemplary/multiformat-impression.json @@ -90,6 +90,7 @@ "crid": "2002", "adid": "2002", "adm": "", + "mtype": 1, "adomain": [ "tag-example.com" ] @@ -102,6 +103,7 @@ "crid": "702", "adid": "702", "adm": "", + "mtype": 4, "adomain": [ "tag-example.com" ] @@ -114,6 +116,7 @@ "crid": "172", "adid": "172", "nurl": "http://adkernel.com/win?f=nurl", + "mtype": 3, "adomain": [ "tag-example.com" ] diff --git a/adapters/adkernel/adkerneltest/exemplary/single-banner-impression.json b/adapters/adkernel/adkerneltest/exemplary/single-banner-impression.json index 6a01b847c5f..e8d31967ccc 100644 --- a/adapters/adkernel/adkerneltest/exemplary/single-banner-impression.json +++ b/adapters/adkernel/adkerneltest/exemplary/single-banner-impression.json @@ -64,6 +64,7 @@ "adid": "19005", "adm": "", "cat": ["IAB2"], + "mtype": 1, "adomain": ["test.com"], "h": 250, "w": 300 diff --git a/adapters/adkernel/adkerneltest/exemplary/single-video-impression.json b/adapters/adkernel/adkerneltest/exemplary/single-video-impression.json index cd458826702..66bd9a90b74 100644 --- a/adapters/adkernel/adkerneltest/exemplary/single-video-impression.json +++ b/adapters/adkernel/adkerneltest/exemplary/single-video-impression.json @@ -75,6 +75,7 @@ "cat": [ "IAB2" ], + "mtype": 2, "adomain": [ "video-example.com" ] From 188b0e73907e64edef7985c30b99c575bfce113d Mon Sep 17 00:00:00 2001 From: ckbo3hrk Date: Thu, 18 Apr 2024 16:25:28 +0300 Subject: [PATCH 2/3] Adkernel: bid.mtype support #2 --- .../adkerneltest/exemplary/multiformat-impression.json | 9 ++++++--- .../adkerneltest/exemplary/single-banner-impression.json | 3 ++- .../adkerneltest/exemplary/single-video-impression.json | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/adapters/adkernel/adkerneltest/exemplary/multiformat-impression.json b/adapters/adkernel/adkerneltest/exemplary/multiformat-impression.json index d4509ae56da..f74a7b0465e 100644 --- a/adapters/adkernel/adkerneltest/exemplary/multiformat-impression.json +++ b/adapters/adkernel/adkerneltest/exemplary/multiformat-impression.json @@ -144,7 +144,8 @@ ], "cid": "1001", "adid": "2002", - "crid": "2002" + "crid": "2002", + "mtype": 1 }, "type": "banner" }, @@ -159,7 +160,8 @@ ], "cid": "601", "crid": "702", - "adid": "702" + "adid": "702", + "mtype": 4 }, "type": "native" }, @@ -174,7 +176,8 @@ ], "cid": "161", "crid": "172", - "adid": "172" + "adid": "172", + "mtype": 3 }, "type": "audio" } diff --git a/adapters/adkernel/adkerneltest/exemplary/single-banner-impression.json b/adapters/adkernel/adkerneltest/exemplary/single-banner-impression.json index e8d31967ccc..328633523e0 100644 --- a/adapters/adkernel/adkerneltest/exemplary/single-banner-impression.json +++ b/adapters/adkernel/adkerneltest/exemplary/single-banner-impression.json @@ -93,7 +93,8 @@ "crid": "19005", "w": 300, "h": 250, - "cat": ["IAB2"] + "cat": ["IAB2"], + "mtype": 1 }, "type": "banner" } diff --git a/adapters/adkernel/adkerneltest/exemplary/single-video-impression.json b/adapters/adkernel/adkerneltest/exemplary/single-video-impression.json index 66bd9a90b74..f50d6017bee 100644 --- a/adapters/adkernel/adkerneltest/exemplary/single-video-impression.json +++ b/adapters/adkernel/adkerneltest/exemplary/single-video-impression.json @@ -106,7 +106,8 @@ "crid": "2002", "cat": [ "IAB2" - ] + ], + "mtype": 2 }, "type": "video" } From 07e4cfe52e665983f775abe1e4f66d717d05a7f9 Mon Sep 17 00:00:00 2001 From: ckbo3hrk Date: Mon, 22 Apr 2024 11:27:19 +0300 Subject: [PATCH 3/3] Update adkernel.go code review fix --- adapters/adkernel/adkernel.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/adapters/adkernel/adkernel.go b/adapters/adkernel/adkernel.go index 995ba0d437d..fb71c3fe2c3 100644 --- a/adapters/adkernel/adkernel.go +++ b/adapters/adkernel/adkernel.go @@ -263,27 +263,33 @@ func (adapter *adkernelAdapter) MakeBids(internalRequest *openrtb2.BidRequest, e sfxStart := len(bid.ImpID) - len(mf_suffix) - 1 bid.ImpID = bid.ImpID[:sfxStart] } + bidType, err := getMediaTypeForBid(&bid) + if err != nil { + return nil, []error{err} + } bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ Bid: &bid, - BidType: getMediaTypeForBid(&bid), + BidType: bidType, }) } return bidResponse, nil } // getMediaTypeForImp figures out which media type this bid is for -func getMediaTypeForBid(bid *openrtb2.Bid) openrtb_ext.BidType { +func getMediaTypeForBid(bid *openrtb2.Bid) (openrtb_ext.BidType, error) { switch bid.MType { case openrtb2.MarkupBanner: - return openrtb_ext.BidTypeBanner + return openrtb_ext.BidTypeBanner, nil case openrtb2.MarkupAudio: - return openrtb_ext.BidTypeAudio + return openrtb_ext.BidTypeAudio, nil case openrtb2.MarkupNative: - return openrtb_ext.BidTypeNative + return openrtb_ext.BidTypeNative, nil case openrtb2.MarkupVideo: - return openrtb_ext.BidTypeVideo + return openrtb_ext.BidTypeVideo, nil default: - return openrtb_ext.BidTypeBanner + return "", &errortypes.BadServerResponse{ + Message: fmt.Sprintf("Unsupported MType %d", bid.MType), + } } }