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: Added parameters dctr & pmzoneid #1865

Merged
merged 5 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
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: 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"
sachin-pubmatic marked this conversation as resolved.
Show resolved Hide resolved
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: 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": "a1,b2",
"dctr": "abcd",
sachin-pubmatic marked this conversation as resolved.
Show resolved Hide resolved
"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": "abcd",
"pmZoneId": "a1,b2",
"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