Skip to content

Commit

Permalink
AdTrue Bid Adapter: getUserSyncs logic update (#6338)
Browse files Browse the repository at this point in the history
* add AdTrue bid adapter

* add AdTrue Bid Adapter unit tests

* add AdTrue Bid Adapter unit tests

* add AdTrue bid adapter

* add AdTrue Bid Adapter unit tests

* add AdTrue Bid Adapter unit tests

* add AdTrue bid adapter

* adtrue usersync udpate

* adtrue usersync udpate

* #adtrue bidder usersync udpate

* #Refactoring code & add unit test

* Update package.json

* Update package-lock.json

* 1. Merge branch 'master' of https://github.com/prebid/Prebid.js
2.AdTrue Bid Adapter Refactoring code

* 1. Merge branch 'master' of https://github.com/prebid/Prebid.js
2.AdTrue Bid Adapter Refactoring code

* removing a package-lock.json from PR

* - removing a package-lock.json from PR
- AdTrue bidder: refactoring code & add unit test

* - removing a package-lock.json from PR
- AdTrue bidder: refactoring code & add unit test

* - removing a package-lock.json from PR
- AdTrue bidder: refactoring code & add unit test

* update package-lock.json from upstream
  • Loading branch information
haibau authored and idettman committed May 21, 2021
1 parent 22ad110 commit 476ac6f
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 61 deletions.
70 changes: 36 additions & 34 deletions modules/adtrueBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ const UNDEFINED = undefined;
const DEFAULT_WIDTH = 0;
const DEFAULT_HEIGHT = 0;
const NET_REVENUE = false;
const USER_SYNC_URL_IFRAME = 'https://hb.adtrue.com/prebid/usersync?t=iframe&p=';
const USER_SYNC_URL_IMAGE = 'https://hb.adtrue.com/prebid/usersync?t=img&p=';
let publisherId = 0;
let zoneId = 0;
let NATIVE_ASSET_ID_TO_KEY_MAP = {};
const DATA_TYPES = {
'NUMBER': 'number',
Expand All @@ -25,6 +24,11 @@ const DATA_TYPES = {
'ARRAY': 'array',
'OBJECT': 'object'
};
const SYNC_TYPES = Object.freeze({
1: 'iframe',
2: 'image'
});

const VIDEO_CUSTOM_PARAMS = {
'mimes': DATA_TYPES.ARRAY,
'minduration': DATA_TYPES.NUMBER,
Expand Down Expand Up @@ -440,6 +444,14 @@ export const spec = {
utils.logWarn(LOG_WARN_PREFIX + 'Error: missing publisherId');
return false;
}
if (!utils.isStr(bid.params.publisherId)) {
utils.logWarn(LOG_WARN_PREFIX + 'Error: publisherId is mandatory and cannot be numeric');
return false;
}
if (!utils.isStr(bid.params.zoneId)) {
utils.logWarn(LOG_WARN_PREFIX + 'Error: zoneId is mandatory and cannot be numeric');
return false;
}
return true;
}
return false;
Expand Down Expand Up @@ -478,6 +490,7 @@ export const spec = {
return;
}
publisherId = conf.pubId.trim();
zoneId = conf.zoneId.trim();

payload.site.publisher.id = conf.pubId.trim();
payload.ext.wrapper = {};
Expand All @@ -498,9 +511,7 @@ export const spec = {
if (typeof config.getConfig('device') === 'object') {
payload.device = Object.assign(payload.device, config.getConfig('device'));
}

utils.deepSetValue(payload, 'source.tid', conf.transactionId);

// test bids
if (window.location.href.indexOf('adtrueTest=true') !== -1) {
payload.test = 1;
Expand All @@ -509,7 +520,6 @@ export const spec = {
if (validBidRequests[0].schain) {
utils.deepSetValue(payload, 'source.ext.schain', validBidRequests[0].schain);
}

// Attaching GDPR Consent Params
if (bidderRequest && bidderRequest.gdprConsent) {
utils.deepSetValue(payload, 'user.ext.consent', bidderRequest.gdprConsent.consentString);
Expand All @@ -520,7 +530,6 @@ export const spec = {
if (bidderRequest && bidderRequest.uspConsent) {
utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent);
}

// coppa compliance
if (config.getConfig('coppa') === true) {
utils.deepSetValue(payload, 'regs.coppa', 1);
Expand Down Expand Up @@ -576,7 +585,6 @@ export const spec = {
}
});
}

newBid.meta = {};
if (bid.ext && bid.ext.dspid) {
newBid.meta.networkId = bid.ext.dspid;
Expand All @@ -588,14 +596,12 @@ export const spec = {
newBid.meta.advertiserDomains = bid.adomain;
newBid.meta.clickUrl = bid.adomain[0];
}

// adserverTargeting
if (seatbidder.ext && seatbidder.ext.buyid) {
newBid.adserverTargeting = {
'hb_buyid_adtrue': seatbidder.ext.buyid
};
}

bidResponses.push(newBid);
});
});
Expand All @@ -606,32 +612,28 @@ export const spec = {
return bidResponses;
},
getUserSyncs: function (syncOptions, responses, gdprConsent, uspConsent) {
let syncurl = '' + publisherId;

if (gdprConsent) {
syncurl += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
syncurl += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '');
}
if (uspConsent) {
syncurl += '&us_privacy=' + encodeURIComponent(uspConsent);
}

// coppa compliance
if (config.getConfig('coppa') === true) {
syncurl += '&coppa=1';
}

if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: USER_SYNC_URL_IFRAME + syncurl
}];
} else {
return [{
type: 'image',
url: USER_SYNC_URL_IMAGE + syncurl
}];
if (!responses || responses.length === 0 || (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled)) {
return [];
}
return responses.reduce((accum, rsp) => {
let cookieSyncs = utils.deepAccess(rsp, 'body.ext.cookie_sync');
if (cookieSyncs) {
let cookieSyncObjects = cookieSyncs.map(cookieSync => {
return {
type: SYNC_TYPES[cookieSync.type],
url: cookieSync.url +
'&publisherId=' + publisherId +
'&zoneId=' + zoneId +
'&gdpr=' + (gdprConsent && gdprConsent.gdprApplies ? 1 : 0) +
'&gdpr_consent=' + encodeURIComponent((gdprConsent ? gdprConsent.consentString : '')) +
'&us_privacy=' + encodeURIComponent((uspConsent || '')) +
'&coppa=' + (config.getConfig('coppa') === true ? 1 : 0)
};
});
return accum.concat(cookieSyncObjects);
}
}, []);
}
};

registerBidder(spec);
115 changes: 88 additions & 27 deletions test/spec/modules/adtrueBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe('AdTrueBidAdapter', function () {
const adapter = newBidder(spec)
let bidRequests;
let bidResponses;
let bidResponses2;
beforeEach(function () {
bidRequests = [
{
Expand Down Expand Up @@ -48,34 +49,85 @@ describe('AdTrueBidAdapter', function () {
}
];
bidResponses = {
'body': {
'id': '1610681506302',
'seatbid': [
body: {
id: '1610681506302',
seatbid: [
{
'bid': [
bid: [
{
'id': '1',
'impid': '201fb513ca24e9',
'price': 2.880000114440918,
'burl': 'https://hb.adtrue.com/prebid/win-notify?impid=1610681506302&wp=${AUCTION_PRICE}',
'adm': '<a href=\'https://adtrue.com?ref=pbjs\' target=\'_blank\'><img src=\'http://cdn.adtrue.com/img/prebid_sample_300x250.jpg?v=1.2\' style=\' width: 300px; \' /></a>',
'adid': '1610681506302',
'adomain': [
id: '1',
impid: '201fb513ca24e9',
price: 2.880000114440918,
burl: 'https://hb.adtrue.com/prebid/win-notify?impid=1610681506302&wp=${AUCTION_PRICE}',
adm: '<a href=\'https://adtrue.com?ref=pbjs\' target=\'_blank\'><img src=\'http://cdn.adtrue.com/img/prebid_sample_300x250.jpg?v=1.2\' style=\' width: 300px; \' /></a>',
adid: '1610681506302',
adomain: [
'adtrue.com'
],
'cid': 'f6l0r6n',
'crid': 'abc77au4',
'attr': [],
'w': 300,
'h': 250
cid: 'f6l0r6n',
crid: 'abc77au4',
attr: [],
w: 300,
h: 250
}
],
'seat': 'adtrue',
'group': 0
seat: 'adtrue',
group: 0
}
],
'bidid': '1610681506302',
'cur': 'USD'
bidid: '1610681506302',
cur: 'USD',
ext: {
cookie_sync: [
{
type: 1,
url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue'
}
]
}
}
};
bidResponses2 = {
body: {
id: '1610681506302',
seatbid: [
{
bid: [
{
id: '1',
impid: '201fb513ca24e9',
price: 2.880000114440918,
burl: 'https://hb.adtrue.com/prebid/win-notify?impid=1610681506302&wp=${AUCTION_PRICE}',
adm: '<a href=\'https://adtrue.com?ref=pbjs\' target=\'_blank\'><img src=\'http://cdn.adtrue.com/img/prebid_sample_300x250.jpg?v=1.2\' style=\' width: 300px; \' /></a>',
adid: '1610681506302',
adomain: [
'adtrue.com'
],
cid: 'f6l0r6n',
crid: 'abc77au4',
attr: [],
w: 300,
h: 250
}
],
seat: 'adtrue',
group: 0
}
],
bidid: '1610681506302',
cur: 'USD',
ext: {
cookie_sync: [
{
type: 2,
url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue&type=image'
},
{
type: 1,
url: 'https://hb.adtrue.com/prebid/usersync?bidder=appnexus'
}
]
}
}
};
});
Expand Down Expand Up @@ -349,8 +401,6 @@ describe('AdTrueBidAdapter', function () {
});
});
describe('getUserSyncs', function () {
let USER_SYNC_URL_IFRAME = 'https://hb.adtrue.com/prebid/usersync?t=iframe&p=1212';
let USER_SYNC_URL_IMAGE = 'https://hb.adtrue.com/prebid/usersync?t=img&p=1212';
let sandbox;
beforeEach(function () {
sandbox = sinon.sandbox.create();
Expand All @@ -359,12 +409,23 @@ describe('AdTrueBidAdapter', function () {
sandbox.restore();
});
it('execute as per config', function () {
expect(spec.getUserSyncs({iframeEnabled: true}, {}, undefined, undefined)).to.deep.equal([{
type: 'iframe', url: USER_SYNC_URL_IFRAME
}]);
expect(spec.getUserSyncs({iframeEnabled: false}, {}, undefined, undefined)).to.deep.equal([{
type: 'image', url: USER_SYNC_URL_IMAGE
expect(spec.getUserSyncs({iframeEnabled: true}, [bidResponses], undefined, undefined)).to.deep.equal([{
type: 'iframe',
url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue&publisherId=1212&zoneId=21423&gdpr=0&gdpr_consent=&us_privacy=&coppa=0'
}]);
});
// Multiple user sync output
it('execute as per config', function () {
expect(spec.getUserSyncs({iframeEnabled: true}, [bidResponses2], undefined, undefined)).to.deep.equal([
{
type: 'image',
url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue&type=image&publisherId=1212&zoneId=21423&gdpr=0&gdpr_consent=&us_privacy=&coppa=0'
},
{
type: 'iframe',
url: 'https://hb.adtrue.com/prebid/usersync?bidder=appnexus&publisherId=1212&zoneId=21423&gdpr=0&gdpr_consent=&us_privacy=&coppa=0'
}
]);
});
});
});

0 comments on commit 476ac6f

Please sign in to comment.