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

generate bid.adId uniquely instead of using bidRequest.bidId #3440

Merged
merged 5 commits into from
Feb 6, 2019

Conversation

jsnellbaker
Copy link
Collaborator

Type of change

  • Refactoring (no functional changes, no api changes)
  • Other

Description of change

This PR modifies the manner in which bid.adId is generated in bidfactory.js. Previously it was directly copied from the bidRequest.bidId and if that wasn't available a new string was generated.

The new logic is:

  • we always generate a new string value for the bid.adId
  • the bidRequest.bidId is set to the bid.requestId

Reason for change

The reason for this change is to help allow multiple bid responses be associated to the same bid object. When the bid.adId was set equal to the bidRequest.bidId, it implied a 1:1 relationship between the two objects. Given some of the upcoming changes related to #3379, we want prebid be able to support having multiple bid responses associated to a single bidRequest.bids object. While the rest of core would support this type of association, the bid.adId would be copied into the multiple bid response objects, which would cause issues when trying to render the bid (as it would grab the first bid that matched rather than the bid that won). By generating unique strings, it addresses this problem.

Additional context/information

The bid.requestId is meant to be the tie between the bid response object and the bidRequest.bids object. The bid.requestId is a typically populated from adapter files when they're creating the initial bid object (ie when they're reading their adserver's bid response). So the bid.requestId we're setting in the bidfactory.js is meant to be a back-up in the rare case some adapters don't set the value (like in serverbidServerBidAdapter.js).

The changes to the function calls for getBidRequest() are to line up with the above logic that bid.requestId is the lookup field.

The change in the getBidRequest() function is to prevent some false positive results for the unit tests; an undefined id value would match the inner some check if one of those sub-fields (eg bid_id) didn't exist in the sample/test request object.

Copy link
Collaborator

@harpere harpere left a comment

Choose a reason for hiding this comment

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

one comment that we might want to address. Otherwise LGTM.

var _bidSrc = (bidRequest && bidRequest.src) || 'client';
var _statusCode = statusCode || 0;

this.bidderCode = (bidRequest && bidRequest.bidder) || '';
this.width = 0;
this.height = 0;
this.statusMessage = _getStatus();
this.adId = _bidId;
this.adId = utils.getUniqueIdentifierStr();
this.requestId = bidRequest && bidRequest.bidId;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I noticed that the currency file calls bidfactory.createBid() when conversions fail. There might be some (minor) repercussions since the adId will no longer be maintained in the new bid. Might want to at least change this line in the currency module, from bidId: bid.adId to bidId: bid.requestId to maintain the requestId - though that isn't maintained currently.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for the feedback regarding the currency file. I pushed an update for that reference.

Copy link
Collaborator

@jaiminpanchal27 jaiminpanchal27 left a comment

Choose a reason for hiding this comment

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

LGTM.
Just one thought, we need to make sure that we only accept multiple bid responses for longform mediaType.

@jsnellbaker
Copy link
Collaborator Author

As an update in regards to previous comment - based on some internal discussion, we will not be limiting this to only adpod (formerly longform) video mediaTypes.

A 1:1 relationship between request.bids and the bid responses was not a strictly enforced requirement from the code-perspective; so we're not going enforce it now as part of this change.

@jsnellbaker jsnellbaker merged commit 8c210bc into master Feb 6, 2019
@jsnellbaker jsnellbaker deleted the separate_adId_and_bidId branch March 18, 2019 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants