Skip to content

Commit

Permalink
populate the app ID in the FAN timeout notif url with the publisher ID
Browse files Browse the repository at this point in the history
and the auction with the request ID
  • Loading branch information
Aadesh Patel committed Apr 20, 2020
1 parent 79bb4dc commit d9cf142
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
]
},
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"imp": [
{
"id": "test-imp-id",
Expand Down Expand Up @@ -84,15 +84,15 @@
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"authentication_id": "4e24a2b23fbfb5e41a9093b921d6cddf497c24dd5f63879038cec2ab2f27d174",
"platformid": "test-platform-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"seatbid": [
{
"bid": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
]
},
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"imp": [
{
"id": "test-imp-id",
Expand Down Expand Up @@ -86,15 +86,15 @@
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"authentication_id": "4e24a2b23fbfb5e41a9093b921d6cddf497c24dd5f63879038cec2ab2f27d174",
"platformid": "test-platform-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"seatbid": [
{
"bid": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
]
},
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"imp": [
{
"id": "test-imp-id",
Expand Down Expand Up @@ -78,15 +78,15 @@
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"authentication_id": "4e24a2b23fbfb5e41a9093b921d6cddf497c24dd5f63879038cec2ab2f27d174",
"platformid": "test-platform-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"seatbid": [
{
"bid": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
]
},
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"imp": [
{
"id": "test-imp-id",
Expand Down Expand Up @@ -88,15 +88,15 @@
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"authentication_id": "4e24a2b23fbfb5e41a9093b921d6cddf497c24dd5f63879038cec2ab2f27d174",
"platformid": "test-platform-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"seatbid": [
{
"bid": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
]
},
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"imp": [
{
"id": "test-imp-id",
Expand Down Expand Up @@ -86,15 +86,15 @@
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"authentication_id": "4e24a2b23fbfb5e41a9093b921d6cddf497c24dd5f63879038cec2ab2f27d174",
"platformid": "test-platform-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"seatbid": [
{
"bid": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
]
},
"body": {
"id": "test-req-id",
"id": "test-imp-1",
"imp": [
{
"id": "test-imp-1",
Expand Down Expand Up @@ -103,15 +103,15 @@
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"authentication_id": "dfecd103a45daeb2a01728afb8ce78f6738f6007ecfebe1ca616b196e22b43e9",
"platformid": "test-platform-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-req-id",
"id": "test-imp-1",
"seatbid": [
{
"bid": [
Expand Down Expand Up @@ -147,7 +147,7 @@
]
},
"body": {
"id": "test-req-id",
"id": "test-imp-2",
"imp": [
{
"id": "test-imp-2",
Expand Down Expand Up @@ -180,15 +180,15 @@
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"authentication_id": "a5fead11a4db86d0f62f57c3d8001640227120c8ef236549f0db010c1dbab399",
"platformid": "test-platform-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-req-id",
"id": "test-imp-2",
"seatbid": [
{
"bid": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
]
},
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"imp": [
{
"id": "test-imp-id",
Expand Down Expand Up @@ -78,7 +78,7 @@
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"authentication_id": "4e24a2b23fbfb5e41a9093b921d6cddf497c24dd5f63879038cec2ab2f27d174",
"platformid": "test-platform-id"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"expectedRequest": {
"uri": "https://an.facebook.com/placementbid.ortb",
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"imp": [
{
"id": "test-imp-id",
Expand Down Expand Up @@ -72,15 +72,15 @@
},
"tmax": 500,
"ext": {
"authentication_id": "b2f9edfd707106adb6b692520081ad7e2a345444af1a895310228297a1b6247e",
"authentication_id": "4e24a2b23fbfb5e41a9093b921d6cddf497c24dd5f63879038cec2ab2f27d174",
"platformid": "test-platform-id"
}
}
},
"mockResponse": {
"status": 200,
"body": {
"id": "test-req-id",
"id": "test-imp-id",
"seatbid": [
{
"bid": [
Expand Down
32 changes: 29 additions & 3 deletions adapters/audienceNetwork/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func (this *FacebookAdapter) modifyRequest(out *openrtb.BidRequest) error {
return err
}

// Every outgoing FAN request has a single impression, so we can safely use the unique
// impression ID as the FAN request ID. We need to make sure that we update the request
// ID *BEFORE* we generate the auth ID since its a hash based on the request ID
out.ID = imp.ID

reqExt := facebookReqExt{
PlatformID: this.platformID,
AuthID: this.makeAuthID(out),
Expand Down Expand Up @@ -455,18 +460,39 @@ func NewFacebookBidder(client *http.Client, platformID string, appSecret string)
}

func (fa *FacebookAdapter) MakeTimeoutNotification(req *adapters.RequestData) (*adapters.RequestData, []error) {
// Note, facebook creates one request per imp, so all these requests will only have one imp in them
auction_id, err := jsonparser.GetString(req.Body, "imp", "[0]", "id")
var (
rID string
pubID string
err error
)

// Note, the facebook adserver can only handle single impression requests, so we have to split multi-imp requests into
// multiple request. In order to ensure that every split request has a unique ID, the split request IDs are set to the
// corresponding imp's ID
rID, err = jsonparser.GetString(req.Body, "id")
if err != nil {
return &adapters.RequestData{}, []error{err}
}

uri := fmt.Sprintf("https://www.facebook.com/audiencenetwork/nurl/?partner=%s&app=%s&auction=%s&ortb_loss_code=2", fa.platformID, fa.platformID, auction_id)
// The publisher ID is either in the app object or the site object, depending on the supply of the request so we need
// to check both
pubID, err = jsonparser.GetString(req.Body, "app", "publisher", "id")
if err != nil {
pubID, err = jsonparser.GetString(req.Body, "site", "publisher", "id")
if err != nil {
return &adapters.RequestData{}, []error{
errors.New("path [app|site].publisher.id not found in the request"),
}
}
}

uri := fmt.Sprintf("https://www.facebook.com/audiencenetwork/nurl/?partner=%s&app=%s&auction=%s&ortb_loss_code=2", fa.platformID, pubID, rID)
timeoutReq := adapters.RequestData{
Method: "GET",
Uri: uri,
Body: nil,
Headers: http.Header{},
}

return &timeoutReq, nil
}
5 changes: 2 additions & 3 deletions adapters/audienceNetwork/facebook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestJsonSamples(t *testing.T) {

func TestMakeTimeoutNotice(t *testing.T) {
req := adapters.RequestData{
Body: []byte(`{"imp":[{"id":"1234"}]}}`),
Body: []byte(`{"id":"1234","imp":[{"id":"1234"}],"app":{"publisher":{"id":"5678"}}}`),
}
fba := NewFacebookBidder(nil, "test-platform-id", "test-app-secret")

Expand All @@ -56,9 +56,8 @@ func TestMakeTimeoutNotice(t *testing.T) {

toReq, err := tb.MakeTimeoutNotification(&req)
assert.Nil(t, err, "Facebook MakeTimeoutNotification() return an error %v", err)
expectedUri := "https://www.facebook.com/audiencenetwork/nurl/?partner=test-platform-id&app=test-platform-id&auction=1234&ortb_loss_code=2"
expectedUri := "https://www.facebook.com/audiencenetwork/nurl/?partner=test-platform-id&app=5678&auction=1234&ortb_loss_code=2"
assert.Equal(t, expectedUri, toReq.Uri, "Facebook timeout notification not returning the expected URI.")

}

func TestMakeTimeoutNoticeBadRequest(t *testing.T) {
Expand Down

0 comments on commit d9cf142

Please sign in to comment.