Skip to content

Commit

Permalink
Admixer adapter update - add user syncs (prebid#6024)
Browse files Browse the repository at this point in the history
* Migrating to Prebid 1.0

* Migrating to Prebid 1.0

* Fix spec

* add gdpr and usp

* remove changes in gdpr_hello_world.html

* Update gdpr_hello_world.html

add spaces

* add user syncs

* remove comments

* tests

Co-authored-by: atkachov <atkachov91@admixer.ua>
  • Loading branch information
Galphimbl and atkachov authored Nov 25, 2020
1 parent e202cf5 commit 1137a64
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 26 deletions.
20 changes: 16 additions & 4 deletions modules/admixerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {registerBidder} from '../src/adapters/bidderFactory.js';

const BIDDER_CODE = 'admixer';
const ALIASES = ['go2net'];
const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.0.aspx';
const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.1.aspx';
export const spec = {
code: BIDDER_CODE,
aliases: ALIASES,
Expand Down Expand Up @@ -51,10 +51,9 @@ export const spec = {
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];
// loop through serverResponses {
try {
serverResponse = serverResponse.body;
serverResponse.forEach((bidResponse) => {
const {body: {ads = []} = {}} = serverResponse;
ads.forEach((bidResponse) => {
const bidResp = {
requestId: bidResponse.bidId,
cpm: bidResponse.cpm,
Expand All @@ -73,6 +72,19 @@ export const spec = {
utils.logError(e);
}
return bidResponses;
},
getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
const pixels = [];
serverResponses.forEach(({body: {cm = {}} = {}}) => {
const {pixels: img = [], iframes: frm = []} = cm;
if (syncOptions.pixelEnabled) {
img.forEach((url) => pixels.push({type: 'image', url}));
}
if (syncOptions.iframeEnabled) {
frm.forEach((url) => pixels.push({type: 'iframe', url}));
}
});
return pixels;
}
};
registerBidder(spec);
76 changes: 54 additions & 22 deletions test/spec/modules/admixerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {spec} from 'modules/admixerBidAdapter.js';
import {newBidder} from 'src/adapters/bidderFactory.js';

const BIDDER_CODE = 'admixer';
const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.0.aspx';
const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.1.aspx';
const ZONE_ID = '2eb6bd58-865c-47ce-af7f-a918108c3fd2';

describe('AdmixerAdapter', function () {
Expand Down Expand Up @@ -78,33 +78,35 @@ describe('AdmixerAdapter', function () {

describe('interpretResponse', function () {
let response = {
body: [{
'currency': 'USD',
'cpm': 6.210000,
'ad': '<div>ad</div>',
'width': 300,
'height': 600,
'creativeId': 'ccca3e5e-0c54-4761-9667-771322fbdffc',
'ttl': 360,
'netRevenue': false,
'bidId': '5e4e763b6bc60b'
}]
body: {
ads: [{
'currency': 'USD',
'cpm': 6.210000,
'ad': '<div>ad</div>',
'width': 300,
'height': 600,
'creativeId': 'ccca3e5e-0c54-4761-9667-771322fbdffc',
'ttl': 360,
'netRevenue': false,
'bidId': '5e4e763b6bc60b'
}]
}
};

it('should get correct bid response', function () {
const body = response.body;
const ads = response.body.ads;
let expectedResponse = [
{
'requestId': body[0].bidId,
'cpm': body[0].cpm,
'creativeId': body[0].creativeId,
'width': body[0].width,
'height': body[0].height,
'ad': body[0].ad,
'requestId': ads[0].bidId,
'cpm': ads[0].cpm,
'creativeId': ads[0].creativeId,
'width': ads[0].width,
'height': ads[0].height,
'ad': ads[0].ad,
'vastUrl': undefined,
'currency': body[0].currency,
'netRevenue': body[0].netRevenue,
'ttl': body[0].ttl,
'currency': ads[0].currency,
'netRevenue': ads[0].netRevenue,
'ttl': ads[0].ttl,
}
];

Expand All @@ -119,4 +121,34 @@ describe('AdmixerAdapter', function () {
expect(result.length).to.equal(0);
});
});

describe('getUserSyncs', function () {
let imgUrl = 'https://example.com/img1';
let frmUrl = 'https://example.com/frm2';
let responses = [{
body: {
cm: {
pixels: [
imgUrl
],
iframes: [
frmUrl
],
}
}
}];

it('Returns valid values', function () {
let userSyncAll = spec.getUserSyncs({pixelEnabled: true, iframeEnabled: true}, responses);
let userSyncImg = spec.getUserSyncs({pixelEnabled: true, iframeEnabled: false}, responses);
let userSyncFrm = spec.getUserSyncs({pixelEnabled: false, iframeEnabled: true}, responses);
expect(userSyncAll).to.be.an('array').with.lengthOf(2);
expect(userSyncImg).to.be.an('array').with.lengthOf(1);
expect(userSyncImg[0].url).to.be.equal(imgUrl);
expect(userSyncImg[0].type).to.be.equal('image');
expect(userSyncFrm).to.be.an('array').with.lengthOf(1);
expect(userSyncFrm[0].url).to.be.equal(frmUrl);
expect(userSyncFrm[0].type).to.be.equal('iframe');
});
});
});

0 comments on commit 1137a64

Please sign in to comment.