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

Adnuntius Adapter: Set no cookies as a parameter #2352

Merged
merged 3 commits into from
Sep 6, 2022

Conversation

mikael-lundin
Copy link
Contributor

This will allow prebid server partners to be able to tell the ad server not to set cookies as a parameter with the ad request.

@bsardo bsardo requested a review from guscarreon August 17, 2022 17:56
@bsardo bsardo self-requested a review August 17, 2022 17:56
@bsardo bsardo self-assigned this Aug 17, 2022
Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good. Left a couple of optimization nitpicks

@@ -122,7 +122,7 @@ func makeEndpointUrl(ortbRequest openrtb2.BidRequest, a *adapter) (string, []err
q.Set("consentString", consent)
}

if deviceExt.NoCookies {
if deviceExt.NoCookies || noCookies {
q.Set("noCookies", "true")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that extDeviceAdnuntius only comes with the NoCookies field:

type extDeviceAdnuntius struct {
	NoCookies bool `json:"noCookies,omitempty"`
}
adapters/adnuntius/adnuntius.go

we may not need to unmarshal at all if noCookies is true. Do you think that condition is worth adding as a small optimization? I guess something similar to:

 98   func makeEndpointUrl(ortbRequest openrtb2.BidRequest, a *adapter, noCookies bool) (string, []error) {
 99       uri, err := url.Parse(a.endpoint)
100       if err != nil {
101           return "", []error{fmt.Errorf("failed to parse Adnuntius endpoint: %v", err)}
102       }
103  
104       gdpr, consent, err := getGDPR(&ortbRequest)
105       if err != nil {
106           return "", []error{fmt.Errorf("failed to parse Adnuntius endpoint: %v", err)}
107       }
108  
109 -     var deviceExt extDeviceAdnuntius
110 -     if ortbRequest.Device != nil && ortbRequest.Device.Ext != nil {
111 -         if err := json.Unmarshal(ortbRequest.Device.Ext, &deviceExt); err != nil {
112 -             return "", []error{fmt.Errorf("failed to parse Adnuntius endpoint: %v", err)}
113 -         }
114 -     }
115  
116       _, offset := a.time.Now().Zone()
117       tzo := -offset / minutesInHour
118  
119       q := uri.Query()
120       if gdpr != "" && consent != "" {
121           q.Set("gdpr", gdpr)
122           q.Set("consentString", consent)
123       }
124  
125 -     if deviceExt.NoCookies || noCookies {
    +     cookiesEnabled := noCookes
    +     if !cookiesEnabled {
    +         var deviceExt extDeviceAdnuntius
    +         if ortbRequest.Device != nil && ortbRequest.Device.Ext != nil {
    +             if err := json.Unmarshal(ortbRequest.Device.Ext, &deviceExt); err != nil {
    +                 return "", []error{fmt.Errorf("failed to parse Adnuntius endpoint: %v", err)}
    +             }
    +         }
    +         cookiesEnabled = deviceExt.NoCookies
    +     }
    +     
    +     if cookiesEnabled {
126           q.Set("noCookies", "true")
127       }
128  
129       q.Set("tzo", fmt.Sprint(tzo))
adapters/adnuntius/adnuntius.go

Thouhgts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally the idea was that you could set noCookies it in both places, but maybe I should just get rid of the deviceExt part. No one is using it as of now. will change that. Just a general question since I'm pretty new to golang, is unmarshaling crazy expensive or just a bit expensive?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unmarshal library we are currently using is very robust and reliable, but expensive. extDeviceAdnuntius is not a huge struct so I don't think it'd be crazy expensive, but if noCookies is already true, there seems to be no reason to unmarshal deviceExt. I think it doesn't hurt to set noCookies in either place. For backwards compatibility I think it makes sense to leave deviceExt.

I just think that if noCookies is true, the OR in line 125 would evaluate to true regardless of the value of deviceExt.NoCookies. Therefore, I think it makes sense to unmarshal deviceExt only if needed. That is, only if noCookies is false. I leave it up to you.

@@ -202,6 +200,13 @@ func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters
})
}

endpoint, err := makeEndpointUrl(ortbRequest, a, noCookies)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As of this version of the code, noCookies doesn't seem to get modified anywhere else. Can we discard it altogether?

159   func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters.RequestData, []error) {
160       var requestData []*adapters.RequestData
161       networkAdunitMap := make(map[string][]adnAdunit)
162       headers := setHeaders(ortbRequest)
163 -     var noCookies bool = false
164
165       for _, imp := range ortbRequest.Imp {
166           if imp.Banner == nil {
167               return nil, []error{&errortypes.BadInput{
168                   Message: fmt.Sprintf("ignoring imp id=%s, Adnuntius supports only Banner", imp.ID),
169               }}
170           }
*-- 11 lines: 171           var bidderExt adapters.ExtImpBidder--------------------------------------------------------------
182               }}
183           }
184
185 -         if adnuntiusExt.NoCookies == true {
186 -             noCookies = true
187 -         }
188
189           network := defaultNetwork
190           if adnuntiusExt.Network != "" {
*--  8 lines: 191               network = adnuntiusExt.Network---------------------------------------------------------------
199                   Dimensions: getImpSizes(imp),
200               })
201       }
202
203 -     endpoint, err := makeEndpointUrl(ortbRequest, a, noCookies)
    +     endpoint, err := makeEndpointUrl(ortbRequest, a, adnuntiusExt.NoCookies)
204       if err != nil {
205           return nil, []error{&errortypes.BadInput{
206               Message: fmt.Sprintf("failed to parse URL: %s", err),
207           }}
208       }
adapters/adnuntius/adnuntius.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea here is that the noCookies is set as per imp. that means that there might be 3 imps that where only one have the noCookies option. that means that the entire request to the endpoint would need the parameter set in the url. That's kind of why I opted to set a variable before the for loop so that if there's one we set it for all.

If that makes sense :D

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh I missed it is outside of the for loop. It does make sense, my bad. Yep, let's leaving as is.

@bsardo bsardo requested review from AlexBVolcy and removed request for bsardo August 23, 2022 17:21
@bsardo bsardo assigned AlexBVolcy and unassigned bsardo Aug 23, 2022
Copy link
Contributor

@AlexBVolcy AlexBVolcy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one minor comment

Comment on lines +204 to +208
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("failed to parse URL: %s", err),
}}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this error case isn't covered by tests, would it be possible to update your tests for this fail to parse URL case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, will add that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't find a way to trigger this, so I removed the check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, I think we should still be handling the error regardless. So even if you can't cover it for a test, we still want to have the error check if you can re-add it please.

guscarreon
guscarreon previously approved these changes Aug 29, 2022
Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I believe the error check mentioned below should be added back. Other than that I agree with these changes.

@@ -202,6 +207,8 @@ func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters
})
}

endpoint, _ := makeEndpointUrl(ortbRequest, a, noCookies)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the error check removed? Can we add it again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding it back in! :)

Copy link
Contributor

@guscarreon guscarreon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bsardo bsardo merged commit 6dd6bfb into prebid:master Sep 6, 2022
jorgeluisrocha pushed a commit to jwplayer/prebid-server that referenced this pull request Sep 28, 2022
gwi-mmuths added a commit to gwinteractive/prebid-server that referenced this pull request Oct 10, 2022
* origin/master: (316 commits)
  Fix alt bidder code test broken by imp wrapper commit (prebid#2405)
  ImpWrapper (prebid#2375)
  Update sspBC adapter to v5.7 (prebid#2394)
  Change errors to warnings (prebid#2385)
  TheMediaGrid: support native mediaType (prebid#2377)
  Huaweiadsadapter gdpr (prebid#2345)
  Add alternatebiddercodes in Prebid request ext (prebid#2339)
  Changed FS bidder names to mixed case (prebid#2390)
  Load bidders names from file system in lowercase (prebid#2388)
  consumable adapter: add schain and coppa support (prebid#2361)
  Adapter aliases: moved adapter related configs to bidder.yaml files (prebid#2353)
  pubmatic adapter: add param prebiddealpriority (prebid#2281)
  Yieldlab Adapter: Add support for ad unit sizes (prebid#2364)
  GDPR: add enforce_algo config flag and convert enforce_purpose to bool (prebid#2330)
  Resolves CVE-2022-27664 (prebid#2376)
  AMP Endpoint: support parameters consentType and gdprApplies (prebid#2338)
  Dianomi - added usync for redirect (prebid#2368)
  Create issue_prioritization.yml (prebid#2372)
  Update yaml files for gzip supported bidders (prebid#2365)
  Adnuntius Adapter: Set no cookies as a parameter (prebid#2352)
  ...
shunj-nb pushed a commit to ParticleMedia/prebid-server that referenced this pull request Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants