-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Initial Consumable Bidder Adapter commit #2381
Conversation
This pull request introduces 1 alert when merging 218076e into cea9243 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
This pull request introduces 1 alert when merging 5c2f90a into cea9243 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
modules/consumableBidAdapter.js
Outdated
let tagName = item.match(tagNameRegExp)[0]; | ||
let url = item.match(srcRegExp)[2]; | ||
|
||
if (tagName && tagName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
believe this should be if (tagName && url)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this. Fixed.
modules/consumableBidAdapter.js
Outdated
buildRequests: function (bids) { | ||
return bids.map(bid => { | ||
return formatBidRequest(bid); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd remove the extra function call, these three lines are equivalent to return bids.map(formatBidRequest);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
modules/consumableBidAdapter.js
Outdated
|
||
return pubapiTemplate({ | ||
host: server, | ||
network: params.network, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't mutate the params object, just network: params.network || '10947.1'
here should work. Same with bidRequest.network
below. Might want to use a named constant rather than a magic number if doing more than once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback. Now using a constant and no longer mutating the params object as suggested.
modules/consumableBidAdapter.js
Outdated
}); | ||
return result.join(''); | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of code for a simple templated function. May I suggest something like
const pubapiTemplate = ({host, network, placement, alias}) => `//${host}/pubapi/3.0/${network}/${placement}/0/0/ADTECH;v=2;cmd=bid;cors=yes;alias=${alias};misc=${new Date().getTime()}`
which could replace template
, isInteger
, and pubapiTemplate
above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Simplified based on your suggestions.
modules/consumableBidAdapter.js
Outdated
} | ||
|
||
function parsePixelItems(pixels) { | ||
let itemsRegExp = /(img|iframe)[\s\S]*?src\s*=\s*("|')(.*?)\2/gi; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[\s\S]
is all whitespace and all non-whitespace, which i'm pretty sure is equivalent to .
that's going to give you more than you're hoping for, like for the test string you have below <script>document.write('<img src="img.org"></iframe><iframe src="pixels1.org"></iframe>');</script>
gives you iframe><iframe src="pixels1.org"
as a match which is obviously not correct including the previous tag (and whatever might be between) and could cause errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue turned out to be matching on the tag name without the opening bracket. The regex should work now for the example given and other test cases.
modules/consumableBidAdapter.js
Outdated
return pubapiTemplate({ | ||
host: server, | ||
network: params.network, | ||
placement: parseInt(params.placement), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should always specify the radix when using parseInt
, or use parseFloat
if applicable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Radix is now supplied.
modules/consumableBidAdapter.js
Outdated
host: server, | ||
network: params.network, | ||
placement: parseInt(params.placement), | ||
misc: new Date().getTime() // cache busting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should just be handled by your templating function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to the templating function.
modules/consumableBidAdapter.js
Outdated
bidRequest = { | ||
url: _buildConsumableUrl(bid), | ||
method: 'GET', | ||
ttl: CONSUMABLE_TTL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's no reason to return this for the bid request, the bidderFactory won't use it. I see you use it in interpretResponse
but you can just use CONSUMABLE_TTL
directly as it's a constant and you don't seem to be modifying it in the body of interpretResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed and using the constant directly as suggested.
modules/consumableBidAdapter.js
Outdated
'catch(e){continue;}' + | ||
'}}</script>'; | ||
}, | ||
_parseBidResponse: function (response, bidRequest) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You shouldn't expose this, it's a private method. Also, using a private method (regular function scoped to this module, in this case) allows the minify to mangle the name resulting in smaller code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this method so it's no longer exposed.
modules/consumableBidAdapter.js
Outdated
} | ||
} | ||
}, | ||
_formatPixels: function (pixels) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should not be exposed either. You can test it as part of interpretResponse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved this method so it's no longer exposed.
modules/consumableBidAdapter.js
Outdated
_parseBidResponse: function (response, bidRequest) { | ||
let bidData; | ||
try { | ||
bidData = response.seatbid[0].bid[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If your endpoint is returning arrays (which it appears to be by this code) I suggest handling the responses as arrays w/ forEach
or map
(if you're returning the results directly) rather than picking off the first bid and bailing early if not present. interpretResponse
allows you to return multiple bids. Even if you only want to return one bid for now, a forEach
or map
implementation will still behave correctly (as you have here) but will also be forward compatible should you decide to do multiple bids in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestion. I'd like to wait on this to roll it into a larger refactor. It should work fine as-is as we're only concerned with the first bid in the array returned.
This pull request introduces 1 alert when merging 5fd65d7 into 2e27a33 - view on lgtm.com new alerts:
Comment posted by lgtm.com |
Please let me know if everything looks ok now after the latest round of edits based on the reviews. We have a number of publishers who are eager for the adapter. Thank you. |
Checking in again. Any updates on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Initial Consumable Bidder Adapter commit * fix tests and lint errors for Consumable bidder adapter and specs * changes based on reviews by @snapwich and @mkendall07
Type of change
Description of change
Adding Consumable's bidder adapter for Prebid.js.
Be sure to test the integration with your adserver using the Hello World sample page.
done
contact email of the adapter’s maintainer: naffis@consumable.com
official adapter submission
Other information