Skip to content

Commit

Permalink
Setupad adapter: param change and minor fixes (#11770)
Browse files Browse the repository at this point in the history
* Fix analytics params and set account_id param mandatory

* Remove unused param

* Remove unneeded function logic and refactor
  • Loading branch information
eldzis committed Jun 16, 2024
1 parent f43411f commit eedcb05
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
45 changes: 25 additions & 20 deletions modules/setupadBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BANNER } from '../src/mediaTypes.js';
const BIDDER_CODE = 'setupad';
const ENDPOINT = 'https://prebid.setupad.io/openrtb2/auction';
const SYNC_ENDPOINT = 'https://cookie.stpd.cloud/sync?';
const REPORT_ENDPOINT = 'https://adapter-analytics.setupad.io/api/adapter-analytics';
const REPORT_ENDPOINT = 'https://adapter-analytics.setupad.io/api/adapter-analytics?';
const GVLID = 1241;
const TIME_TO_LIVE = 360;
const biddersCreativeIds = {};
Expand All @@ -28,7 +28,12 @@ export const spec = {
gvlid: GVLID,

isBidRequestValid: function (bid) {
return !!(bid.params.placement_id && isStr(bid.params.placement_id));
return !!(
bid.params.placement_id &&
isStr(bid.params.placement_id) &&
bid.params.account_id &&
isStr(bid.params.account_id)
);
},

buildRequests: function (validBidRequests, bidderRequest) {
Expand Down Expand Up @@ -225,17 +230,23 @@ export const spec = {

if (!placementIds) return;

let extraBidParams = '';

// find the winning bidder by using creativeId as identification
if (biddersCreativeIds.hasOwnProperty(bid.creativeId) && biddersCreativeIds[bid.creativeId]) {
bidder = biddersCreativeIds[bid.creativeId];
}

// Add extra parameters
extraBidParams = `&cpm=${bid.originalCpm}&currency=${bid.originalCurrency}`;
const queryParams = [];
queryParams.push(`event=bidWon`);
queryParams.push('bidder=' + bidder);
queryParams.push('placementIds=' + placementIds);
queryParams.push('auctionId=' + auctionId);
queryParams.push('cpm=' + bid.originalCpm);
queryParams.push('currency=' + bid.originalCurrency);
queryParams.push('timestamp=' + Date.now());

const strQueryParams = queryParams.join('&');

const url = `${REPORT_ENDPOINT}?event=bidWon&bidder=${bidder}&placementIds=${placementIds}&auctionId=${auctionId}${extraBidParams}&timestamp=${Date.now()}`;
const url = REPORT_ENDPOINT + strQueryParams;
triggerPixel(url);
},
};
Expand All @@ -251,21 +262,15 @@ function getBidders(serverResponse) {
}

function getAd(bid) {
let ad, adUrl;

switch (deepAccess(bid, 'ext.prebid.type')) {
default:
if (bid.adm && bid.nurl) {
ad = bid.adm;
ad += createTrackPixelHtml(decodeURIComponent(bid.nurl));
} else if (bid.adm) {
ad = bid.adm;
} else if (bid.nurl) {
adUrl = bid.nurl;
}
const { adm, nurl } = bid;
let ad = adm;

if (nurl) {
const trackingPixel = createTrackPixelHtml(decodeURIComponent(nurl));
ad += trackingPixel;
}

return { ad, adUrl };
return { ad };
}

registerBidder(spec);
2 changes: 1 addition & 1 deletion modules/setupadBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const adUnits = [
bidder: 'setupad',
params: {
placement_id: '123', //required
account_id: '123', //optional
account_id: '123', //required
},
},
],
Expand Down
15 changes: 15 additions & 0 deletions test/spec/modules/setupadBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,26 @@ describe('SetupadAdapter', function () {
bidder: 'setupad',
params: {
placement_id: '123',
account_id: '123',
},
};

it('should return true when required params found', function () {
expect(spec.isBidRequestValid(bid)).to.equal(true);
});

it('should return false when placement_id is missing', function () {
const bidWithoutPlacementId = { ...bid };
delete bidWithoutPlacementId.params.placement_id;
expect(spec.isBidRequestValid(bidWithoutPlacementId)).to.equal(false);
});

it('should return false when account_id is missing', function () {
const bidWithoutAccountId = { ...bid };
delete bidWithoutAccountId.params.account_id;
expect(spec.isBidRequestValid(bidWithoutAccountId)).to.equal(false);
});

it('should return false when required params are not passed', function () {
delete bid.params.placement_id;
expect(spec.isBidRequestValid(bid)).to.equal(false);
Expand Down

0 comments on commit eedcb05

Please sign in to comment.