Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adtelligent support both userSync types #3444

Merged
merged 11 commits into from
Jan 31, 2019
26 changes: 18 additions & 8 deletions modules/adtelligentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,36 @@ export const spec = {
getUserSyncs: function (syncOptions, serverResponses) {
var syncs = [];

function addSyncs(_s) {
if (_s && _s.length) {
_s.forEach(s => {
function addSyncs(bid) {
const uris = bid.cookieURLs;
const types = bid.cookieURLSTypes || [];

if (uris && uris.length) {
uris.forEach((uri, i) => {
let type = types[i] || 'image';

if ((!syncOptions.pixelEnabled && type == 'image') ||
(!syncOptions.iframeEnabled && type == 'iframe')) {
return;
}

syncs.push({
type: 'image',
url: s
type: type,
url: uri
})
})
}
}

if (syncOptions.pixelEnabled) {
if (syncOptions.pixelEnabled || syncOptions.iframeEnabled) {
serverResponses && serverResponses.length && serverResponses.forEach((response) => {
if (response.body) {
if (utils.isArray(response.body)) {
response.body.forEach(b => {
addSyncs(b.cookieURLs);
addSyncs(b);
})
} else {
addSyncs(response.body.cookieURLs)
addSyncs(response.body)
}
}
})
Expand Down
45 changes: 41 additions & 4 deletions test/spec/modules/adtelligentBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ const SERVER_DISPLAY_RESPONSE = {
}],
'cookieURLs': ['link1', 'link2']
};
const SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS = {
'source': {'aid': 12345, 'pubId': 54321},
'bids': [{
'ad': '<!-- Creative -->',
'requestId': '2e41f65424c87c',
'creative_id': 342516,
'cmpId': 342516,
'height': 250,
'cur': 'USD',
'width': 300,
'cpm': 0.9
}],
'cookieURLs': ['link1', 'link2'],
'cookieURLSTypes': ['image', 'iframe']
};

const videoBidderRequest = {
bidderCode: 'bidderCode',
Expand Down Expand Up @@ -109,17 +124,39 @@ const displayEqResponse = [{
describe('adtelligentBidAdapter', function () { // todo remove only
const adapter = newBidder(spec);

describe('user syncs', function () {
describe('user syncs as image', function () {
it('should be returned if pixel enabled', function () {
const syncs = spec.getUserSyncs({pixelEnabled: true}, [{body: SERVER_DISPLAY_RESPONSE}]);
const syncs = spec.getUserSyncs({pixelEnabled: true}, [{body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS}]);

expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[0]]);
expect(syncs.map(s => s.type)).to.deep.equal(['image']);
})
})

describe('user syncs as iframe', function () {
it('should be returned if iframe enabled', function () {
const syncs = spec.getUserSyncs({iframeEnabled: true}, [{body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS}]);

expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[1]]);
expect(syncs.map(s => s.type)).to.deep.equal(['iframe']);
})
})

describe('user syncs with both types', function () {
it('should be returned if pixel and iframe enabled', function () {
const syncs = spec.getUserSyncs({
iframeEnabled: true,
pixelEnabled: true
}, [{body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS}]);

expect(syncs.map(s => s.url)).to.deep.equal(SERVER_DISPLAY_RESPONSE.cookieURLs);
expect(syncs.map(s => s.url)).to.deep.equal(SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So again - the original idea behind usersync was that iframes would be used if they were allowed by the pub and that image syncs were a fallback. We wouldn't expect both types of syncs if both are allowed. Just iframe. Trying to minimize the number of syncs here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. Did not get your point.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if two syncs are required, and everything is allowed, then 2 syncs are called as expected. Our lineItems may require triggering multiple syncs for single bid, and their types do not matter.

expect(syncs.map(s => s.type)).to.deep.equal(SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLSTypes);
})
})

describe('user syncs', function () {
it('should not be returned if pixel not set', function () {
const syncs = spec.getUserSyncs({}, [{body: SERVER_DISPLAY_RESPONSE}]);
const syncs = spec.getUserSyncs({}, [{body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS}]);

expect(syncs).to.be.empty;
})
Expand Down