Skip to content

Commit

Permalink
PubWise Bid Adapter: clean up and updates to adUnit parsing (#9066)
Browse files Browse the repository at this point in the history
* add pubwise bid adpater updates

* Update pubwiseBidAdapter_spec.js

* updates for feedback from review, adding imp.ext.tid and source.tid from appropriate locations
  • Loading branch information
GLStephen authored Oct 18, 2022
1 parent f113129 commit fcd1e3c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
26 changes: 14 additions & 12 deletions modules/pubwiseBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { _each, isStr, deepClone, isArray, deepSetValue, inIframe, logMessage, l
import { config } from '../src/config.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE } from '../src/mediaTypes.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
const VERSION = '0.1.0';
const VERSION = '0.2.0';
const GVLID = 842;
const NET_REVENUE = true;
const UNDEFINED = undefined;
Expand Down Expand Up @@ -117,9 +116,6 @@ export const spec = {
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function (validBidRequests, bidderRequest) {
// convert Native ORTB definition to old-style prebid native definition
validBidRequests = convertOrtbRequestToProprietaryNative(validBidRequests);

var refererInfo;
if (bidderRequest && bidderRequest.refererInfo) {
refererInfo = bidderRequest.refererInfo;
Expand Down Expand Up @@ -170,7 +166,7 @@ export const spec = {
payload.user.geo.lon = _parseSlotParam('lon', conf.lon);
payload.user.yob = _parseSlotParam('yob', conf.yob);
payload.device.geo = payload.user.geo;
payload.site.page = payload.site.page.trim();
payload.site.page = payload.site?.page?.trim();
payload.site.domain = _getDomainFromURL(payload.site.page);

// add the content object from config in request
Expand All @@ -184,7 +180,7 @@ export const spec = {
}

// passing transactionId in source.tid
deepSetValue(payload, 'source.tid', conf.transactionId);
deepSetValue(payload, 'source.tid', bidderRequest?.auctionId);

// schain
if (validBidRequests[0].schain) {
Expand Down Expand Up @@ -440,7 +436,10 @@ function _createImpressionObject(bid, conf) {
tagid: bid.params.adUnit || undefined,
bidfloor: _parseSlotParam('bidFloor', bid.params.bidFloor), // capitalization dicated by 3.2.4 spec
secure: 1,
bidfloorcur: bid.params.currency ? _parseSlotParam('currency', bid.params.currency) : DEFAULT_CURRENCY // capitalization dicated by 3.2.4 spec
bidfloorcur: bid.params.currency ? _parseSlotParam('currency', bid.params.currency) : DEFAULT_CURRENCY, // capitalization dicated by 3.2.4 spec
ext: {
tid: (bid.transactionId ? bid.transactionId : '')
}
};

if (bid.hasOwnProperty('mediaTypes')) {
Expand Down Expand Up @@ -494,7 +493,11 @@ function _parseSlotParam(paramName, paramValue) {

function _parseAdSlot(bid) {
_logInfo('parseAdSlot bid', bid)
bid.params.adUnit = '';
if (bid.adUnitCode) {
bid.params.adUnit = bid.adUnitCode;
} else {
bid.params.adUnit = '';
}
bid.params.width = 0;
bid.params.height = 0;
bid.params.adSlot = _cleanSlotName(bid.params.adSlot);
Expand Down Expand Up @@ -532,9 +535,8 @@ function _cleanSlotName(slotName) {

function _initConf(refererInfo) {
return {
// TODO: do the fallbacks make sense here?
pageURL: refererInfo?.page || window.location.href,
refURL: refererInfo?.ref || window.document.referrer
pageURL: refererInfo?.page,
refURL: refererInfo?.ref
};
}

Expand Down
10 changes: 6 additions & 4 deletions test/spec/modules/pubwiseBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const sampleBidderBannerRequest = {
'bidFloor': '1.00',
'currency': 'USD',
'adSlot': '',
'adUnit': '',
'adUnit': 'div-gpt-ad-1460505748561-0',
'bcat': [
'IAB25-3',
'IAB26-1',
Expand Down Expand Up @@ -535,13 +535,15 @@ describe('PubWiseAdapter', function () {

describe('Handling Request Construction', function () {
it('bid requests are not mutable', function() {
let sourceBidRequest = utils.deepClone(sampleValidBidRequests)
spec.buildRequests(sampleValidBidRequests, {auctinId: 'placeholder'});
let sourceBidRequest = utils.deepClone(sampleValidBidRequests);
spec.buildRequests(sampleValidBidRequests, {auctionId: 'placeholder'});
expect(sampleValidBidRequests).to.deep.equal(sourceBidRequest, 'Should be unedited as they are used elsewhere');
});
it('should handle complex bidRequest', function() {
let request = spec.buildRequests(sampleValidBidRequests, sampleBidderRequest);
expect(request.bidderRequest).to.equal(sampleBidderRequest);
expect(request.bidderRequest).to.equal(sampleBidderRequest, "Bid Request Doesn't Match Sample");
expect(request.data.source.tid).to.equal(sampleBidderRequest.auctionId, 'AuctionId -> source.tid Mismatch');
expect(request.data.imp[0].ext.tid).to.equal(sampleBidderRequest.bids[0].transactionId, 'TransactionId -> ext.tid Mismatch');
});
it('must conform to API for buildRequests', function() {
let request = spec.buildRequests(sampleValidBidRequests);
Expand Down

0 comments on commit fcd1e3c

Please sign in to comment.