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

UOE-6525: In-app OTT Add Support for dctr and pmzoneid #170

Merged
merged 8 commits into from
Jul 27, 2021
43 changes: 38 additions & 5 deletions adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"strings"

Expand Down Expand Up @@ -82,6 +83,13 @@ const (
INVALID_HEIGHT = "Invalid Height"
INVALID_MEDIATYPE = "Invalid MediaType"
INVALID_ADSLOT = "Invalid AdSlot"

dctrKeyName = "key_val"
dctrKeywordName = "dctr"
pmZoneIDKeyName = "pmZoneId"
pmZoneIDRequestParamName = "pmzoneid"

urlEncodedEqualChar = "%3D"
)

func PrepareLogMessage(tID, pubId, adUnitId, bidID, details string, args ...interface{}) string {
Expand Down Expand Up @@ -621,7 +629,14 @@ func parseImpressionObject(imp *openrtb2.Imp, wrapExt *pubmaticWrapperExt, pubID

impExtMap := make(map[string]interface{})
if pubmaticExt.Keywords != nil && len(pubmaticExt.Keywords) != 0 {
populateKeywordsInExt(pubmaticExt.Keywords, impExtMap)
addKeywordsToExt(pubmaticExt.Keywords, impExtMap)
}
//Give preference to direct values of 'dctr' & 'pmZoneId' params in extension
if pubmaticExt.Dctr != "" {
impExtMap[dctrKeyName] = pubmaticExt.Dctr
}
if pubmaticExt.PmZoneID != "" {
impExtMap[pmZoneIDKeyName] = pubmaticExt.PmZoneID
}

if bidderExt.Prebid != nil {
Expand All @@ -638,23 +653,41 @@ func parseImpressionObject(imp *openrtb2.Imp, wrapExt *pubmaticWrapperExt, pubID
impExtMap[ImpExtAdUnitKey] = bidderExt.Data.AdServer.AdSlot
}

if len(impExtMap) != 0 {
imp.Ext = nil
if len(impExtMap) > 0 {
impExtBytes, err := json.Marshal(impExtMap)
if err == nil {
imp.Ext = json.RawMessage(impExtBytes)
imp.Ext = impExtBytes
}
}

return nil

}

func populateKeywordsInExt(keywords []*openrtb_ext.ExtImpPubmaticKeyVal, impExtMap map[string]interface{}) {
func addKeywordsToExt(keywords []*openrtb_ext.ExtImpPubmaticKeyVal, extMap map[string]interface{}) {
for _, keyVal := range keywords {
if len(keyVal.Values) == 0 {
logf("No values present for key = %s", keyVal.Key)
continue
} else {
impExtMap[keyVal.Key] = strings.Join(keyVal.Values[:], ",")
val := strings.Join(keyVal.Values[:], ",")

key := keyVal.Key
if strings.EqualFold(key, pmZoneIDRequestParamName) {
key = pmZoneIDKeyName
} else if key == dctrKeywordName {
key = dctrKeyName
// URL-decode dctr value if it is url-encoded
if strings.Contains(val, urlEncodedEqualChar) {
urlDecodedVal, err := url.QueryUnescape(val)
if err == nil {
val = urlDecodedVal
}
}
}

extMap[key] = val
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
"w": 300
},
"ext": {
"pmZoneID": "Zone1,Zone2",
"pmZoneId": "Zone1,Zone2",
"preference": "sports,movies"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"maxbitrate": 10
},
"ext": {
"pmZoneID": "Zone1,Zone2",
"pmZoneId": "Zone1,Zone2",
"reward": 1
}
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/pubmatic/pubmatictest/exemplary/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"maxbitrate": 10
},
"ext": {
"pmZoneID": "Zone1,Zone2"
"pmZoneId": "Zone1,Zone2"
}
}
],
Expand Down
5 changes: 4 additions & 1 deletion adapters/pubmatic/pubmatictest/params/race/banner.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
{
"publisherId": "156209",
"adSlot": "pubmatic_test2@300x250",
"pmzoneid": "drama,sport",
"dctr": "abBucket=4|adType=page|entity=|paidByCategory=|sku=|userLevel=free|platform=android|majorVersion=3.54|version=3.54.0|mobileApplication=true|showId=20166|show=Kisah Untuk Geri|genre=Drama|contentUrl=https://www.iflix.com/title/show/20166|rating=TV-MA|contentLanguage=id",
"keywords": {
"pmZoneID": "Zone1,Zone2",
"pmzoneid": "Zone1,Zone2",
"dctr": "abBucket=4|adType=page|entity=|paidByCategory=|sku=|userLevel=free|platform=android|majorVersion=3.54|version=3.54.0|mobileApplication=true|showId=20166|show=Kisah Untuk Geri|genre=Drama|contentUrl=https://www.iflix.com/title/show/20166|rating=TV-MA|contentLanguage=id",
"preference": "sports,movies"
},
"wrapper": {
Expand Down
3 changes: 2 additions & 1 deletion adapters/pubmatic/pubmatictest/params/race/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"publisherId": "156209",
"adSlot": "pubmatic_test2@300x250",
"keywords": {
"pmZoneID": "Zone1,Zone2",
"pmzoneid": "Zone1,Zone2",
"dctr": "abBucket=4|adType=page|entity=|paidByCategory=|sku=|userLevel=free|platform=android|majorVersion=3.54|version=3.54.0|mobileApplication=true|showId=20166|show=Kisah Untuk Geri|genre=Drama|contentUrl=https://www.iflix.com/title/show/20166|rating=TV-MA|contentLanguage=id",
"preference": "sports,movies"
},
"wrapper": {
Expand Down
2 changes: 1 addition & 1 deletion adapters/pubmatic/pubmatictest/supplemental/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"w": 300
},
"ext": {
"pmZoneID": "Zone1,Zone2",
"pmZoneId": "Zone1,Zone2",
"preference": "sports,movies",
"skadn": {
"skadnetids": ["k674qkevps.skadnetwork"],
Expand Down
162 changes: 162 additions & 0 deletions adapters/pubmatic/pubmatictest/supplemental/dctrAndPmZoneID.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"mockBidRequest": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
]
},
"ext": {
"bidder": {
"adSlot": "AdTag_Div1@300x250",
"publisherId": " 999 ",
"pmzoneid": "drama,sport",
"dctr": "abBucket=4|adType=page|entity=|paidByCategory=|sku=|userLevel=free|platform=android|majorVersion=3.54|version=3.54.0|mobileApplication=true|showId=20166|show=Kisah Untuk Geri|genre=Drama|contentUrl=https://www.iflix.com/title/show/20166|rating=TV-MA|contentLanguage=id",
"keywords": [
{
"key": "pmZoneID",
"value": [
"Zone1",
"Zone2"
]
},
{
"key": "preference",
"value": [
"sports",
"movies"
]
}
],
"wrapper": {
"version": 1,
"profile": 5123
}
}
}
}
],
"device": {
"ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
},
"site": {
"id": "siteID",
"publisher": {
"id": "1234"
}
}
},
"httpCalls": [
{
"expectedRequest": {
"uri": "https://hbopenbid.pubmatic.com/translator?source=prebid-server",
"body": {
"id": "test-request-id",
"imp": [
{
"id": "test-imp-id",
"tagid": "AdTag_Div1",
"banner": {
"format": [
{
"w": 300,
"h": 250
}
],
"h": 250,
"w": 300
},
"ext": {
"key_val": "abBucket=4|adType=page|entity=|paidByCategory=|sku=|userLevel=free|platform=android|majorVersion=3.54|version=3.54.0|mobileApplication=true|showId=20166|show=Kisah Untuk Geri|genre=Drama|contentUrl=https://www.iflix.com/title/show/20166|rating=TV-MA|contentLanguage=id",
"pmZoneId": "drama,sport",
"preference": "sports,movies"
}
}
],
"device": {
"ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"
},
"site": {
"id": "siteID",
"publisher": {
"id": "999"
}
},
"ext": {
"wrapper": {
"profile": 5123,
"version": 1
}
}
}
},
"mockResponse": {
"status": 200,
"body": {
"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": "test deal",
"ext": {
"dspid": 6,
"deal_channel": 1
}
}
]
}
],
"bidid": "5778926625248726496",
"cur": "USD"
}
}
}
],
"expectedBidResponses": [
{
"currency": "USD",
"bids": [
{
"bid": {
"id": "7706636740145184841",
"impid": "test-imp-id",
"price": 0.5,
"adid": "29681110",
"adm": "some-test-ad",
"adomain": [
"pubmatic.com"
],
"crid": "29681110",
"w": 300,
"h": 250,
"dealid": "test deal",
"ext": {
"dspid": 6,
"deal_channel": 1
}
},
"type": "banner"
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"w": 300
},
"ext": {
"pmZoneID": "Zone1,Zone2",
"pmZoneId": "Zone1,Zone2",
"preference": "sports,movies",
"dfp_ad_unit_code": "/1111/home"
}
Expand Down
Loading