Skip to content

Commit

Permalink
Support for ID5 + receive meta data (prebid#4352)
Browse files Browse the repository at this point in the history
* Livewrapped bid and analytics adapter

* Fixed some tests for browser compatibility

* Fixed some tests for browser compatibility

* Changed analytics adapter code name

* Fix double quote in debug message

* modified how gdpr is being passed

* Added support for Publisher Common ID Module

* Corrections for ttr in analytics

* ANalytics updates

* Auction start time stamp changed

* Detect recovered ad blocked requests
Make it possible to pass dynamic parameters to adapter

* Collect info on ad units receiving any valid bid

* Support for ID5
Pass metadata from adapter

* Typo in test + eids on wrong level
  • Loading branch information
bjorn-lw authored and sa1omon committed Nov 28, 2019
1 parent e8448c3 commit e221b51
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 7 deletions.
38 changes: 36 additions & 2 deletions modules/livewrappedBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export const spec = {
gdprConsent: bidderRequest.gdprConsent ? bidderRequest.gdprConsent.consentString : undefined,
cookieSupport: !utils.isSafariBrowser() && utils.cookiesAreEnabled(),
rcv: getAdblockerRecovered(),
adRequests: [...adRequests]
adRequests: [...adRequests],
rtbData: HandleEids(bidRequests)
};
const payloadString = JSON.stringify(payload);
return {
Expand Down Expand Up @@ -101,7 +102,8 @@ export const spec = {
ttl: ad.ttl,
creativeId: ad.creativeId,
netRevenue: true,
currency: serverResponse.body.currency
currency: serverResponse.body.currency,
meta: ad.meta
};

bidResponses.push(bidResponse);
Expand Down Expand Up @@ -198,4 +200,36 @@ function getAdblockerRecovered() {
} catch (e) {}
}

function AddExternalUserId(eids, value, source, atype, rtiPartner) {
if (utils.isStr(value)) {
var eid = {
source,
uids: [{
id: value,
atype
}]
};

if (rtiPartner) {
eid.uids[0] = {ext: {rtiPartner}};
}

eids.push(eid);
}
}

function HandleEids(bidRequests) {
let eids = [];
const bidRequest = bidRequests[0];
if (bidRequest && bidRequest.userId) {
AddExternalUserId(eids, utils.deepAccess(bidRequest, `userId.pubcid`), 'pubcommon', 1); // Also add this to eids
AddExternalUserId(eids, utils.deepAccess(bidRequest, `userId.id5id`), 'id5-sync.com', 1);
}
if (eids.length > 0) {
return {user: {ext: {eids}}};
}

return undefined;
}

registerBidder(spec);
93 changes: 88 additions & 5 deletions test/spec/modules/livewrappedBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,44 @@ describe('Livewrapped adapter tests', function () {
});
});

it('should make use of Id5-Id if available', function() {
sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false);
sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true);
let testbidRequest = clone(bidderRequest);
delete testbidRequest.bids[0].params.userId;
testbidRequest.bids[0].userId = {};
testbidRequest.bids[0].userId.id5id = 'id5-user-id';
let result = spec.buildRequests(testbidRequest.bids, testbidRequest);
let data = JSON.parse(result.data);

expect(data.rtbData.user.ext.eids).to.deep.equal([{
'source': 'id5-sync.com',
'uids': [{
'id': 'id5-user-id',
'atype': 1
}]
}]);
});

it('should make use of publisher common Id if available', function() {
sandbox.stub(utils, 'isSafariBrowser').callsFake(() => false);
sandbox.stub(utils, 'cookiesAreEnabled').callsFake(() => true);
let testbidRequest = clone(bidderRequest);
delete testbidRequest.bids[0].params.userId;
testbidRequest.bids[0].userId = {};
testbidRequest.bids[0].userId.pubcid = 'publisher-common-id';
let result = spec.buildRequests(testbidRequest.bids, testbidRequest);
let data = JSON.parse(result.data);

expect(data.rtbData.user.ext.eids).to.deep.equal([{
'source': 'pubcommon',
'uids': [{
'id': 'publisher-common-id',
'atype': 1
}]
}]);
});

describe('interpretResponse', function () {
it('should handle single success response', function() {
let lwResponse = {
Expand All @@ -591,7 +629,8 @@ describe('Livewrapped adapter tests', function () {
bidId: '32e50fad901ae89',
auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf',
creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077',
ttl: 120
ttl: 120,
meta: undefined
}
],
currency: 'USD'
Expand All @@ -607,7 +646,8 @@ describe('Livewrapped adapter tests', function () {
ttl: 120,
creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077',
netRevenue: true,
currency: 'USD'
currency: 'USD',
meta: undefined
}];

let bids = spec.interpretResponse({body: lwResponse});
Expand All @@ -628,7 +668,8 @@ describe('Livewrapped adapter tests', function () {
bidId: '32e50fad901ae89',
auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf',
creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077',
ttl: 120
ttl: 120,
meta: undefined
},
{
id: '38e5ddf4-3c01-11e8-86a7-0a44794250d4',
Expand All @@ -640,7 +681,8 @@ describe('Livewrapped adapter tests', function () {
bidId: '42e50fad901ae89',
auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf',
creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077',
ttl: 120
ttl: 120,
meta: undefined
}
],
currency: 'USD'
Expand All @@ -656,7 +698,8 @@ describe('Livewrapped adapter tests', function () {
ttl: 120,
creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077',
netRevenue: true,
currency: 'USD'
currency: 'USD',
meta: undefined
}, {
requestId: '42e50fad901ae89',
bidderCode: 'livewrapped',
Expand All @@ -667,7 +710,47 @@ describe('Livewrapped adapter tests', function () {
ttl: 120,
creativeId: '62cbd598-2715-4c43-a06f-229fc170f945:427077',
netRevenue: true,
currency: 'USD',
meta: undefined
}];

let bids = spec.interpretResponse({body: lwResponse});

expect(bids).to.deep.equal(expectedResponse);
})

it('should return meta-data', function() {
let lwResponse = {
ads: [
{
id: '28e5ddf4-3c01-11e8-86a7-0a44794250d4',
callerId: 'site_outsider_0',
tag: '<span>ad</span>',
width: 300,
height: 250,
cpmBid: 2.565917,
bidId: '32e50fad901ae89',
auctionId: '13e674db-d4d8-4e19-9d28-ff38177db8bf',
creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077',
ttl: 120,
meta: {metadata: 'metadata'}
}
],
currency: 'USD'
};

let expectedResponse = [{
requestId: '32e50fad901ae89',
bidderCode: 'livewrapped',
cpm: 2.565917,
width: 300,
height: 250,
ad: '<span>ad</span>',
ttl: 120,
creativeId: '52cbd598-2715-4c43-a06f-229fc170f945:427077',
netRevenue: true,
currency: 'USD',
meta: {metadata: 'metadata'}
}];

let bids = spec.interpretResponse({body: lwResponse});
Expand Down

0 comments on commit e221b51

Please sign in to comment.