Skip to content

Commit

Permalink
PubMatic: Added parameters dctr & pmzoneid (prebid#1865)
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-pubmatic authored and jizeyopera committed Oct 13, 2021
1 parent 8818b69 commit 2520529
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 15 deletions.
37 changes: 27 additions & 10 deletions adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ const (
INVALID_HEIGHT = "Invalid Height"
INVALID_MEDIATYPE = "Invalid MediaType"
INVALID_ADSLOT = "Invalid AdSlot"

dctrKeyName = "key_val"
pmZoneIDKeyName = "pmZoneId"
pmZoneIDKeyNameOld = "pmZoneID"
)

func PrepareLogMessage(tID, pubId, adUnitId, bidID, details string, args ...interface{}) string {
Expand Down Expand Up @@ -485,30 +489,43 @@ func parseImpressionObject(imp *openrtb2.Imp, wrapExt *string, pubID *string) er
imp.Banner = bannerCopy
}

extMap := make(map[string]interface{}, 0)
if pubmaticExt.Keywords != nil && len(pubmaticExt.Keywords) != 0 {
kvstr := makeKeywordStr(pubmaticExt.Keywords)
imp.Ext = json.RawMessage([]byte(kvstr))
} else {
imp.Ext = nil
addKeywordsToExt(pubmaticExt.Keywords, extMap)
}
//Give preference to direct values of 'dctr' & 'pmZoneId' params in extension
if pubmaticExt.Dctr != "" {
extMap[dctrKeyName] = pubmaticExt.Dctr
}
if pubmaticExt.PmZoneID != "" {
extMap[pmZoneIDKeyName] = pubmaticExt.PmZoneID
}

imp.Ext = nil
if len(extMap) > 0 {
ext, err := json.Marshal(extMap)
if err == nil {
imp.Ext = ext
}
}

return nil

}

func makeKeywordStr(keywords []*openrtb_ext.ExtImpPubmaticKeyVal) string {
eachKv := make([]string, 0, len(keywords))
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 {
eachKv = append(eachKv, fmt.Sprintf("\"%s\":\"%s\"", keyVal.Key, strings.Join(keyVal.Values[:], ",")))
key := keyVal.Key
if keyVal.Key == pmZoneIDKeyNameOld {
key = pmZoneIDKeyName
}
extMap[key] = strings.Join(keyVal.Values[:], ",")
}
}

kvStr := "{" + strings.Join(eachKv, ",") + "}"
return kvStr
}

func prepareImpressionExt(keywords map[string]string) string {
Expand Down
2 changes: 1 addition & 1 deletion adapters/pubmatic/pubmatictest/exemplary/banner.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"w": 300
},
"ext": {
"pmZoneID": "Zone1,Zone2",
"pmZoneId": "Zone1,Zone2",
"preference": "sports,movies"
}
}
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
2 changes: 2 additions & 0 deletions adapters/pubmatic/pubmatictest/params/race/banner.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"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",
"preference": "sports,movies"
Expand Down
2 changes: 2 additions & 0 deletions adapters/pubmatic/pubmatictest/params/race/video.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"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",
"preference": "sports,movies"
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 @@ -61,7 +61,7 @@
"w": 300
},
"ext": {
"pmZoneID": "Zone1,Zone2",
"pmZoneId": "Zone1,Zone2",
"preference": "sports,movies"
}
}
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"
}
]
}
]
}
2 changes: 1 addition & 1 deletion adapters/pubmatic/pubmatictest/supplemental/noAdSlot.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"h": 250
},
"ext": {
"pmZoneID": "Zone1,Zone2",
"pmZoneId": "Zone1,Zone2",
"preference": "sports,movies"
}
}],
Expand Down
Loading

0 comments on commit 2520529

Please sign in to comment.