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

update AJA adapter: support user sync by iframe #3382

Merged
merged 2 commits into from
Dec 18, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add handling iframe user sync
  • Loading branch information
naoto0822 committed Dec 17, 2018
commit d98105cb8b5ea37995e81b400c81ec7a8fb9a781
30 changes: 21 additions & 9 deletions modules/ajaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -93,16 +93,28 @@ export const spec = {

getUserSyncs: function(syncOptions, serverResponses) {
const syncs = [];
if (syncOptions.pixelEnabled && serverResponses.length) {
const bidderResponseBody = serverResponses[0].body;
if (bidderResponseBody.syncs) {
bidderResponseBody.syncs.forEach(sync => {
syncs.push({
type: 'image',
url: sync
});
if (!serverResponses.length) {
return syncs;
}

const bidderResponseBody = serverResponses[0].body;

if (syncOptions.pixelEnabled && bidderResponseBody.syncs) {
bidderResponseBody.syncs.forEach(sync => {
syncs.push({
type: 'image',
url: sync
});
}
});
}

if (syncOptions.iframeEnabled && bidderResponseBody.sync_htmls) {
bidderResponseBody.sync_htmls.forEach(sync => {
syncs.push({
type: 'iframe',
url: sync
});
});
}

return syncs;
43 changes: 35 additions & 8 deletions test/spec/modules/ajaBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -148,7 +148,10 @@ describe('AjaAdapter', function () {
'is_ad_return': true,
'ad': { /* ad body */ },
'syncs': [
'https://example.test/1'
'https://example.test/pixel/1'
],
'sync_htmls': [
'https://example.test/iframe/1'
]
}
};
@@ -158,29 +161,53 @@ describe('AjaAdapter', function () {
'is_ad_return': true,
'ad': { /* ad body */ },
'syncs': [
'https://example.test/2'
'https://example.test/pixel/2'
]
}
};

it('should use a sync url from first response', function () {
const syncs = spec.getUserSyncs({ pixelEnabled: true }, [bidResponse1, bidResponse2]);
it('should use a sync url from first response (pixel and iframe)', function () {
const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [bidResponse1, bidResponse2]);
expect(syncs).to.deep.equal([
{
type: 'image',
url: 'https://example.test/1'
url: 'https://example.test/pixel/1'
},
{
type: 'iframe',
url: 'https://example.test/iframe/1'
}
]);
});

it('handle empty response (e.g. timeout)', function () {
const syncs = spec.getUserSyncs({ pixelEnabled: true }, []);
const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, []);
expect(syncs).to.deep.equal([]);
});

it('returns empty syncs when not enabled', function () {
const syncs = spec.getUserSyncs({ pixelEnabled: false }, [bidResponse1]);
it('returns empty syncs when not pixel enabled and not iframe enabled', function () {
const syncs = spec.getUserSyncs({ pixelEnabled: false, iframeEnabled: false }, [bidResponse1]);
expect(syncs).to.deep.equal([]);
});

it('returns pixel syncs when pixel enabled and not iframe enabled', function() {
const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: false }, [bidResponse1]);
expect(syncs).to.deep.equal([
{
type: 'image',
url: 'https://example.test/pixel/1'
}
]);
});

it('returns iframe syncs when not pixel enabled and iframe enabled', function() {
const syncs = spec.getUserSyncs({ pixelEnabled: false, iframeEnabled: true }, [bidResponse1]);
expect(syncs).to.deep.equal([
{
type: 'iframe',
url: 'https://example.test/iframe/1'
}
]);
});
});
});