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

Add User Syncs and Partner #3

Merged
Show file tree
Hide file tree
Changes from all commits
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
96 changes: 90 additions & 6 deletions modules/adpartnerBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const spec = {
code: BIDDER_CODE,

isBidRequestValid: function (bidRequest) {
return !!parseInt(bidRequest.params.unitId);
return !!parseInt(bidRequest.params.unitId) || !!parseInt(bidRequest.params.partnerId);
},

buildRequests: function (validBidRequests, bidderRequest) {
Expand All @@ -25,24 +25,42 @@ export const spec = {
let bidRequests = [];
let beaconParams = {
tag: [],
partner: [],
sizes: [],
referer: ''
};

validBidRequests.forEach(function(validBidRequest) {
bidRequests.push({
unitId: parseInt(validBidRequest.params.unitId),
let bidRequestObject = {
adUnitCode: validBidRequest.adUnitCode,
sizes: validBidRequest.sizes,
bidId: validBidRequest.bidId,
referer: referer
});
};

if (parseInt(validBidRequest.params.unitId)) {
bidRequestObject.unitId = parseInt(validBidRequest.params.unitId);
beaconParams.tag.push(validBidRequest.params.unitId);
}

if (parseInt(validBidRequest.params.partnerId)) {
bidRequestObject.unitId = 0;
bidRequestObject.partnerId = parseInt(validBidRequest.params.partnerId);
beaconParams.partner.push(validBidRequest.params.partnerId);
}

bidRequests.push(bidRequestObject);

beaconParams.tag.push(validBidRequest.params.unitId);
beaconParams.sizes.push(spec.joinSizesToString(validBidRequest.sizes));
beaconParams.referer = encodeURIComponent(referer);
});

if (beaconParams.partner.length > 0) {
beaconParams.partner = beaconParams.partner.join(',');
} else {
delete beaconParams.partner;
}

beaconParams.tag = beaconParams.tag.join(',');
beaconParams.sizes = beaconParams.sizes.join(',');

Expand Down Expand Up @@ -125,7 +143,73 @@ export const spec = {

postRequest(endpoint, data) {
ajax(endpoint, null, data, {method: 'POST'});
}
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
const syncs = [];

if (!syncOptions.iframeEnabled && !syncOptions.pixelEnabled) {
return syncs;
}

let appendGdprParams = function (url, gdprParams) {
if (gdprParams === null) {
return url;
}

return url + (url.indexOf('?') >= 0 ? '&' : '?') + gdprParams;
};

let gdprParams = null;
if (gdprConsent) {
if (typeof gdprConsent.gdprApplies === 'boolean') {
gdprParams = `gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`;
} else {
gdprParams = `gdpr_consent=${gdprConsent.consentString}`;
}
}

serverResponses.forEach(resp => {
if (resp.body) {
Object.keys(resp.body).map(function(key, index) {
let respObject = resp.body[key];
if (respObject['syncs'] !== undefined &&
Array.isArray(respObject.syncs) &&
respObject.syncs.length > 0) {
if (syncOptions.iframeEnabled) {
respObject.syncs.filter(function (syncIframeObject) {
if (syncIframeObject['type'] !== undefined &&
syncIframeObject['link'] !== undefined &&
syncIframeObject.type === 'iframe') { return true; }
return false;
}).forEach(function (syncIframeObject) {
syncs.push({
type: 'iframe',
url: appendGdprParams(syncIframeObject.link, gdprParams)
});
});
}
if (syncOptions.pixelEnabled) {
respObject.syncs.filter(function (syncImageObject) {
if (syncImageObject['type'] !== undefined &&
syncImageObject['link'] !== undefined &&
syncImageObject.type === 'image') { return true; }
return false;
}).forEach(function (syncImageObject) {
syncs.push({
type: 'image',
url: appendGdprParams(syncImageObject.link, gdprParams)
});
});
}
}
});
}
});

return syncs;
},

}

registerBidder(spec);
12 changes: 12 additions & 0 deletions modules/adpartnerBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ About us : https://adpartner.pro
}
}
]
},
{
code: 'div-adpartner-example-2',
sizes: [[300, 250]],
bids: [
{
bidder: "adpartner",
params: {
partnerId: 6698
}
}
]
}
];
```
100 changes: 97 additions & 3 deletions test/spec/modules/adpartnerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('AdpartnerAdapter', function () {
});

describe('buildRequests', function () {
let validEndpoint = ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&sizes=300x250|300x600,728x90&referer=https%3A%2F%2Ftest.domain';
let validEndpoint = ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&partner=777&sizes=300x250|300x600,728x90,300x250&referer=https%3A%2F%2Ftest.domain';

let validRequest = [
{
Expand All @@ -72,6 +72,15 @@ describe('AdpartnerAdapter', function () {
'adUnitCode': 'adunit-code-2',
'sizes': [[728, 90]],
'bidId': '22aidtbx5eabd9'
},
{
'bidder': BIDDER_CODE,
'params': {
'partnerId': 777
},
'adUnitCode': 'partner-code-3',
'sizes': [[300, 250]],
'bidId': '5d4531d5a6c013'
}
];

Expand Down Expand Up @@ -100,6 +109,9 @@ describe('AdpartnerAdapter', function () {
expect(payload[1].unitId).to.equal(456);
expect(payload[1].sizes).to.deep.equal([[728, 90]]);
expect(payload[1].bidId).to.equal('22aidtbx5eabd9');
expect(payload[2].partnerId).to.equal(777);
expect(payload[2].sizes).to.deep.equal([[300, 250]]);
expect(payload[2].bidId).to.equal('5d4531d5a6c013');
});
});

Expand All @@ -113,8 +125,10 @@ describe('AdpartnerAdapter', function () {
describe('interpretResponse', function () {
const bidRequest = {
'method': 'POST',
'url': ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&code=adunit-code-1,adunit-code-2&bid=30b31c1838de1e,22aidtbx5eabd9&sizes=300x250|300x600,728x90&referer=https%3A%2F%2Ftest.domain',
'data': '[{"unitId": 13144370,"adUnitCode": "div-gpt-ad-1460505748561-0","sizes": [[300, 250], [300, 600]],"bidId": "2bdcb0b203c17d","referer": "https://test.domain/index.html"},{"unitId": 13144370,"adUnitCode":"div-gpt-ad-1460505748561-1","sizes": [[768, 90]],"bidId": "3dc6b8084f91a8","referer": "https://test.domain/index.html"}]'
'url': ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&partner=777code=adunit-code-1,adunit-code-2,partner-code-3&bid=30b31c1838de1e,22aidtbx5eabd9,5d4531d5a6c013&sizes=300x250|300x600,728x90,300x250&referer=https%3A%2F%2Ftest.domain',
'data': '[{"unitId": 13144370,"adUnitCode": "div-gpt-ad-1460505748561-0","sizes": [[300, 250], [300, 600]],"bidId": "2bdcb0b203c17d","referer": "https://test.domain/index.html"},' +
'{"unitId": 13144370,"adUnitCode":"div-gpt-ad-1460505748561-1","sizes": [[768, 90]],"bidId": "3dc6b8084f91a8","referer": "https://test.domain/index.html"},' +
'{"unitId": 0,"partnerId": 777,"adUnitCode":"div-gpt-ad-1460505748561-2","sizes": [[300, 250]],"bidId": "5d4531d5a6c013","referer": "https://test.domain/index.html"}]'
};

const bidResponse = {
Expand Down Expand Up @@ -239,4 +253,84 @@ describe('AdpartnerAdapter', function () {
expect(ajaxStub.firstCall.args[1]).to.deep.equal(JSON.stringify(bid.winNotification[0].data));
});
});

describe('getUserSyncs', function () {
const bidResponse = [{
body: {
'div-gpt-ad-1460505748561-0':
{
'ad': '<div>ad</div>',
'width': 300,
'height': 250,
'creativeId': '8:123456',
'adomain': [
'test.domain'
],
'syncs': [
{'type': 'image', 'link': 'https://test.domain/tracker_1.gif'},
{'type': 'image', 'link': 'https://test.domain/tracker_2.gif'},
{'type': 'image', 'link': 'https://test.domain/tracker_3.gif'}
],
'winNotification': [
{
'method': 'POST',
'path': '/hb/bid_won?test=1',
'data': {
'ad': [
{'dsp': 8, 'id': 800008, 'cost': 1.0e-5, 'nurl': 'https://test.domain/'}
],
'unit_id': 1234,
'site_id': 123
}
}
],
'cpm': 0.01,
'currency': 'USD',
'netRevenue': true
}
},
headers: {}
}];

it('should return nothing when sync is disabled', function () {
const syncOptions = {
'iframeEnabled': false,
'pixelEnabled': false
};

let syncs = spec.getUserSyncs(syncOptions);
expect(syncs).to.deep.equal([]);
});

it('should register image sync when only image is enabled where gdprConsent is undefined', function () {
const syncOptions = {
'iframeEnabled': false,
'pixelEnabled': true
};

const gdprConsent = undefined;
let syncs = spec.getUserSyncs(syncOptions, bidResponse, gdprConsent);
expect(syncs.length).to.equal(3);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://test.domain/tracker_1.gif');
});

it('should register image sync when only image is enabled where gdprConsent is defined', function () {
const syncOptions = {
'iframeEnabled': false,
'pixelEnabled': true
};
const gdprConsent = {
consentString: 'someString',
vendorData: {},
gdprApplies: true,
apiVersion: 2
};

let syncs = spec.getUserSyncs(syncOptions, bidResponse, gdprConsent);
expect(syncs.length).to.equal(3);
expect(syncs[0].type).to.equal('image');
expect(syncs[0].url).to.equal('https://test.domain/tracker_1.gif?gdpr=1&gdpr_consent=someString');
});
});
});