Skip to content

Commit

Permalink
Limelight Digital Bid Adapter: Add user sync (prebid#7560)
Browse files Browse the repository at this point in the history
* Limelight Digital Bid Adapter: Add user sync

* improve tests

* Improve unique size checking

* fix adunit sizes

* remove unused variable
  • Loading branch information
imedvedko authored and Chris Pabst committed Jan 10, 2022
1 parent be3a18b commit a3e26ee
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 3 deletions.
24 changes: 22 additions & 2 deletions modules/limelightDigitalBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logMessage, groupBy, uniques } from '../src/utils.js';
import { logMessage, groupBy, uniques, flatten, deepAccess } from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import {ajax} from '../src/ajax.js';
Expand Down Expand Up @@ -92,6 +92,26 @@ export const spec = {
}
return bidResponses;
},

getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent) => {
const syncs = serverResponses.map(response => response.body).reduce(flatten, [])
.map(response => deepAccess(response, 'ext.sync')).filter(Boolean);
const iframeSyncUrls = !syncOptions.iframeEnabled ? [] : syncs.map(sync => sync.iframe).filter(Boolean)
.filter(uniques).map(url => {
return {
type: 'iframe',
url: url
}
});
const pixelSyncUrls = !syncOptions.pixelEnabled ? [] : syncs.map(sync => sync.pixel).filter(Boolean)
.filter(uniques).map(url => {
return {
type: 'image',
url: url
}
});
return [iframeSyncUrls, pixelSyncUrls].reduce(flatten, []);
}
};

registerBidder(spec);
Expand Down Expand Up @@ -125,7 +145,7 @@ function buildPlacement(bidRequest) {
break;
}
}
sizes = (sizes || []).concat(bidRequest.sizes || []).filter(uniques);
sizes = (sizes || []).concat(bidRequest.sizes || []);
return {
host: bidRequest.params.host,
adUnit: {
Expand Down
156 changes: 155 additions & 1 deletion test/spec/modules/limelightDigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,160 @@ describe('limelightDigitalAdapter', function () {
expect(spec.interpretResponse(bidResponses)).to.deep.equal([ resObject ]);
});
});
describe('getUserSyncs', function () {
const serverResponses = [
{
body: [
{
ext: {
sync: {
iframe: 'iframeUrl',
}
}
},
{
ext: {
sync: {
pixel: 'pixelUrl'
}
}
},
{},
{
ext: {}
},
{
ext: {
sync: {}
}
},
{
ext: {
sync: {
iframe: 'iframeUrl2',
pixel: 'pixelUrl3'
}
}
}
]
},
{
body: [
{
ext: {
sync: {
iframe: 'iframeUrl2',
pixel: 'pixelUrl2'
}
}
},
{
ext: {
sync: {
iframe: 'iframeUrl3',
pixel: 'pixelUrl3'
}
}
}
]
}
];
it('should return empty array if server responses do not contain sync urls', function () {
const syncOptions = {
iframeEnabled: true,
pixelEnabled: true
};
const serverResponsesWithoutSyncUrls = serverResponses.map(serverResponse => {
const serverResponseWithoutSyncUrls = Object.assign({}, serverResponse);
serverResponseWithoutSyncUrls.body = serverResponse.body.map(serverResponseBody => {
const serverResponseBodyWithoutSyncUrls = Object.assign({}, serverResponseBody);
delete serverResponseBodyWithoutSyncUrls.ext;
return serverResponseBodyWithoutSyncUrls;
});
return serverResponseWithoutSyncUrls;
});
expect(spec.getUserSyncs(syncOptions, serverResponsesWithoutSyncUrls)).to.be.an('array').that.is.empty;
});
it('should return empty array if all sync types are disabled', function () {
const syncOptions = {
iframeEnabled: false,
pixelEnabled: false
};
expect(spec.getUserSyncs(syncOptions, serverResponses)).to.be.an('array').that.is.empty;
});
it('should return iframe sync urls if iframe sync is enabled', function () {
const syncOptions = {
iframeEnabled: true,
pixelEnabled: false
};
expect(spec.getUserSyncs(syncOptions, serverResponses)).to.deep.equal([
{
type: 'iframe',
url: 'iframeUrl'
},
{
type: 'iframe',
url: 'iframeUrl2'
},
{
type: 'iframe',
url: 'iframeUrl3'
}
]);
});
it('should return image sync urls if pixel sync is enabled', function () {
const syncOptions = {
iframeEnabled: false,
pixelEnabled: true
};
expect(spec.getUserSyncs(syncOptions, serverResponses)).to.deep.equal([
{
type: 'image',
url: 'pixelUrl'
},
{
type: 'image',
url: 'pixelUrl3'
},
{
type: 'image',
url: 'pixelUrl2'
}
]);
});
it('should return all sync urls if all sync types are enabled', function () {
const syncOptions = {
iframeEnabled: true,
pixelEnabled: true
}
expect(spec.getUserSyncs(syncOptions, serverResponses)).to.deep.equal([
{
type: 'iframe',
url: 'iframeUrl'
},
{
type: 'iframe',
url: 'iframeUrl2'
},
{
type: 'iframe',
url: 'iframeUrl3'
},
{
type: 'image',
url: 'pixelUrl'
},
{
type: 'image',
url: 'pixelUrl3'
},
{
type: 'image',
url: 'pixelUrl2'
}
]);
});
});
});

function validateAdUnit(adUnit, bid) {
Expand All @@ -323,5 +477,5 @@ function validateAdUnit(adUnit, bid) {
width: size[0],
height: size[1]
}
}))
}));
}

0 comments on commit a3e26ee

Please sign in to comment.