Skip to content

Commit

Permalink
Triplelift Bid Adapter: copying ad unit impression data (#9865)
Browse files Browse the repository at this point in the history
* TL-35335: Cast playbackmethod as array

* TL-36204: Copy tid to imp extension obj

* Added support for entire ortb2Imp obj

* Only setting what exists in ortb2Imp.ext

* Added additional test to check copy of entire ext obj

* Revert "TL-36204: Copy tid to imp extension object"

* TL-36204: Copying ortb2Imp.ext to impression ext obj

* Added edge case logic and additional test

* recos for tid change

* Added spread operator to replace deepClone

---------

Co-authored-by: nllerandi3lift <75995508+nllerandi3lift@users.noreply.github.com>
Co-authored-by: Nick Llerandi <nllerandi@triplelift.com>
  • Loading branch information
3 people authored May 1, 2023
1 parent 0cf7c75 commit 48cd245
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
7 changes: 7 additions & 0 deletions modules/tripleliftBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,15 @@ function _buildPostBody(bidRequests, bidderRequest) {
}

if (!isEmpty(bidRequest.ortb2Imp)) {
// legacy method for extracting ortb2Imp.ext
imp.fpd = _getAdUnitFpd(bidRequest.ortb2Imp);

// preferred method for extracting ortb2Imp.ext
if (!isEmpty(bidRequest.ortb2Imp.ext)) {
imp.ext = { ...bidRequest.ortb2Imp.ext };
}
}

return imp;
});

Expand Down
61 changes: 53 additions & 8 deletions test/spec/modules/tripleliftBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,13 @@ describe('triplelift adapter', function () {
sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']],
bidId: '30b31c1838de1e',
bidderRequestId: '22edbae2733bf6',
transactionId: '173f49a8-7549-4218-a23c-e7ba59b47229',
auctionId: '1d1a030790a475',
userId: {},
schain,
ortb2Imp: {
ext: {
data: {
pbAdSlot: 'homepage-top-rect',
adUnitSpecificAttribute: 123
}
tid: '173f49a8-7549-4218-a23c-e7ba59b47229'
}
}
},
Expand Down Expand Up @@ -178,6 +176,15 @@ describe('triplelift adapter', function () {
auctionId: '1d1a030790a475',
userId: {},
schain,
ortb2Imp: {
ext: {
data: {
pbAdSlot: 'homepage-top-rect',
adUnitSpecificAttribute: 123
},
tid: '173f49a8-7549-4218-a23c-e7ba59b47229'
}
}
},
// banner and outstream video
{
Expand Down Expand Up @@ -245,6 +252,11 @@ describe('triplelift adapter', function () {
auctionId: '1d1a030790a475',
userId: {},
schain,
ortb2Imp: {
misc: {
test: 1
}
}
},
// incomplete banner and incomplete video
{
Expand Down Expand Up @@ -689,6 +701,39 @@ describe('triplelift adapter', function () {
expect(payload.imp[13].video.placement).to.equal(3);
});

it('should add tid to imp.ext if transactionId exists', function() {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.imp[0].ext.tid).to.exist.and.be.a('string');
expect(request.data.imp[0].ext.tid).to.equal('173f49a8-7549-4218-a23c-e7ba59b47229');
});

it('should not add impression ext object if ortb2Imp does not exist', function() {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.imp[2].ext).to.not.exist;
});

it('should not add impression ext object if ortb2Imp.ext does not exist', function() {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.imp[3].ext).to.not.exist;
});

it('should copy entire impression ext object', function() {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.imp[1].ext).to.haveOwnProperty('tid');
expect(request.data.imp[1].ext).to.haveOwnProperty('data');
expect(request.data.imp[1].ext.data).to.haveOwnProperty('adUnitSpecificAttribute');
expect(request.data.imp[1].ext.data).to.haveOwnProperty('pbAdSlot');
expect(request.data.imp[1].ext).to.deep.equal(
{
data: {
pbAdSlot: 'homepage-top-rect',
adUnitSpecificAttribute: 123
},
tid: '173f49a8-7549-4218-a23c-e7ba59b47229'
}
);
});

it('should add tdid to the payload if included', function () {
const id = '6bca7f6b-a98a-46c0-be05-6020f7604598';
bidRequests[0].userId.tdid = id;
Expand Down Expand Up @@ -1103,10 +1148,10 @@ describe('triplelift adapter', function () {
});
it('should send ad unit fpd if kvps are available', function() {
const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest);
expect(request.data.imp[0].fpd.context).to.haveOwnProperty('data');
expect(request.data.imp[0].fpd.context.data).to.haveOwnProperty('pbAdSlot');
expect(request.data.imp[0].fpd.context.data).to.haveOwnProperty('adUnitSpecificAttribute');
expect(request.data.imp[1].fpd).to.not.exist;
expect(request.data.imp[1].fpd.context).to.haveOwnProperty('data');
expect(request.data.imp[1].fpd.context.data).to.haveOwnProperty('pbAdSlot');
expect(request.data.imp[1].fpd.context.data).to.haveOwnProperty('adUnitSpecificAttribute');
expect(request.data.imp[2].fpd).to.not.exist;
});
it('should send 1PlusX data as fpd if localStorage is available and no other fpd is defined', function() {
sandbox.stub(storage, 'getDataFromLocalStorage').callsFake(() => '{"kid":1,"s":"ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==","t":"/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug=="}');
Expand Down

0 comments on commit 48cd245

Please sign in to comment.