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

Implement Dchain Support #3560

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ func (a *PubmaticAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externa
BidVideo: &openrtb_ext.ExtBidPrebidVideo{},
}

if dchain, _, _, err := jsonparser.Get(bid.Ext, "dchain"); err == nil && len(dchain) > 0 {
typedBid.BidMeta = &openrtb_ext.ExtBidPrebidMeta{
DChain: dchain,
}
}

var bidExt *pubmaticBidExt
err := json.Unmarshal(bid.Ext, &bidExt)
if err != nil {
Expand Down
59 changes: 59 additions & 0 deletions dchain/dchain.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package dchain

import (
"encoding/json"
"strconv"

"github.com/prebid/prebid-server/v2/openrtb_ext"
)

type Dchain struct {
Ver string `json:"ver,omitempty"`
Complete int `json:"complete,omitempty"`
Nodes []DchainNodes `json:"nodes,omitempty"`
Ext json.RawMessage `json:"ext,omitempty"`
}

type DchainNodes struct {
Asi string `json:"asi,omitempty"`
Bsid string `json:"bsid,omitempty"`
Rid string `json:"rid,omitempty"`
Name string `json:"name,omitempty"`
Domain string `json:"domain,omitempty"`
Ext json.RawMessage `json:"ext,omitempty"`
}

func IsValidDchain(dchain Dchain) bool {
if dchain.Complete != 0 && dchain.Complete != 1 {
return false
}
if dchain.Nodes == nil || len(dchain.Nodes) == 0 {
return false
}
return true
}

func AddDchainNode(prebidMeta *openrtb_ext.ExtBidPrebidMeta) {
var dchain Dchain
if err := json.Unmarshal(prebidMeta.DChain, &dchain); err == nil && IsValidDchain(dchain) {
dchain.Nodes = append(dchain.Nodes,
DchainNodes{Asi: prebidMeta.AdapterCode},
)
prebidMeta.DChain, _ = json.Marshal(dchain)
return
}
basicDchain := Dchain{
Ver: "1.0",
Complete: 0,
Nodes: []DchainNodes{},
}

if prebidMeta.NetworkID != 0 && prebidMeta.NetworkName != "" {
basicDchain.Nodes = append(basicDchain.Nodes,
DchainNodes{Name: prebidMeta.NetworkName, Bsid: strconv.Itoa(prebidMeta.NetworkID)},
)
}

basicDchain.Nodes = append(basicDchain.Nodes, DchainNodes{Name: prebidMeta.AdapterCode})
prebidMeta.DChain, _ = json.Marshal(basicDchain)
}
5 changes: 5 additions & 0 deletions exchange/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strings"
"time"

"github.com/prebid/prebid-server/v2/dchain"
"github.com/prebid/prebid-server/v2/privacy"

"github.com/prebid/prebid-server/v2/adapters"
Expand Down Expand Up @@ -1347,6 +1348,10 @@ func makeBidExtJSON(ext json.RawMessage, prebid *openrtb_ext.ExtBidPrebid, impEx

prebid.Meta.AdapterCode = adapter.String()

if prebid.Meta.DChain != nil {
dchain.AddDchainNode(prebid.Meta)
}

// ext.prebid.storedrequestattributes and ext.prebid.passthrough
if impExtInfo, ok := impExtInfoMap[impId]; ok {
prebid.Passthrough = impExtInfoMap[impId].Passthrough
Expand Down
Loading