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

Undertone add parameters to request #4995

Merged
merged 21 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d8779ee
* Update undertone adapter - change parameters - placementId paramete…
omerko May 30, 2018
6785395
* Update undertone adapter - change parameters - placementId paramete…
omerko May 30, 2018
c5611e3
fix lint issue in undertone adapter spec
omerko May 30, 2018
eea398e
Merge branch 'master' of https://github.com/prebid/Prebid.js
omerko Jul 15, 2018
ddcce01
added user sync function to undertone adapter
omerko Sep 13, 2018
2d5bd83
* Update undertone adapter - change parameters - placementId paramete…
omerko May 30, 2018
a33df49
added user sync function to undertone adapter
omerko Sep 13, 2018
467a238
added user sync function to undertone adapter
omerko Sep 16, 2018
4f3342c
Merge remote-tracking branch 'origin/master'
omerko Sep 16, 2018
95228a2
revert package-lock.json
omerko Oct 11, 2018
852cd6d
Merge branch 'master' of https://github.com/prebid/Prebid.js
AnnaPerion Mar 8, 2020
74cc4bd
send element coordinates and viewport
AnnaPerion Mar 15, 2020
00d2e42
Update undertoneBidAdapter.js
AnnaPerion Mar 17, 2020
e9dac72
add null in case of no data
AnnaPerion Mar 17, 2020
252383b
update according to fixes
AnnaPerion Mar 17, 2020
55fad56
added user sync function to undertone adapter
omerko Sep 13, 2018
33bf123
Merge branch 'master' of https://github.com/PerionNet/Prebid.js
AnnaPerion Mar 25, 2020
2a00e62
Merge remote-tracking branch 'origin/master' into UN-22446_Element-Pl…
AnnaPerion Mar 25, 2020
beba2be
Update undertoneBidAdapter.js
AnnaPerion Mar 25, 2020
624ac44
Merge remote-tracking branch 'origin/master' into UN-22446_Element-Pl…
AnnaPerion Mar 25, 2020
a7a709b
remove unneded changes after rebase
AnnaPerion Mar 25, 2020
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
27 changes: 26 additions & 1 deletion modules/undertoneBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ function getGdprQueryParams(gdprConsent) {
return `gdpr=${gdpr}&gdprstr=${gdprstr}`;
}

function getBannerCoords(id) {
let element = document.getElementById(id);
let left = -1;
let top = -1;
if (element) {
left = element.offsetLeft;
top = element.offsetTop;

let parent = element.offsetParent;
if (parent) {
left += parent.offsetLeft;
top += parent.offsetTop;
}

return [left, top];
} else {
return null;
}
}

export const spec = {
code: BIDDER_CODE,
isBidRequestValid: function(bid) {
Expand All @@ -60,11 +80,15 @@ export const spec = {
}
},
buildRequests: function(validBidRequests, bidderRequest) {
const vw = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
const vh = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
const pageSizeArray = vw == 0 || vh == 0 ? null : [vw, vh];
const payload = {
'x-ut-hb-params': [],
'commons': {
'adapterVersion': '$prebid.version$',
'uids': validBidRequests[0].userId
'uids': validBidRequests[0].userId,
'pageSize': pageSizeArray
}
};
const referer = bidderRequest.refererInfo.referer;
Expand All @@ -87,6 +111,7 @@ export const spec = {
validBidRequests.map(bidReq => {
const bid = {
bidRequestId: bidReq.bidId,
coordinates: getBannerCoords(bidReq.adUnitCode),
hbadaptor: 'prebid',
url: pageUrl,
domain: domain,
Expand Down
73 changes: 64 additions & 9 deletions test/spec/modules/undertoneBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const invalidBidReq = {
};

const bidReq = [{
adUnitCode: 'div-gpt-ad-1460505748561-0',
bidder: BIDDER_CODE,
params: {
placementId: '10433394',
Expand All @@ -35,6 +36,7 @@ const bidReq = [{
auctionId: '9ad1fa8d-2297-4660-a018-b39945054746'
},
{
adUnitCode: 'div-gpt-ad-1460505748561-0',
bidder: BIDDER_CODE,
params: {
publisherId: 12345
Expand All @@ -54,6 +56,7 @@ const bidReqUserIds = [{
bidId: '263be71e91dd9d',
auctionId: '9ad1fa8d-2297-4660-a018-b39945054746',
userId: {
idl_env: '1111',
tdid: '123456',
digitrustid: {data: {id: 'DTID', keyv: 4, privacy: {optout: false}, producer: 'ABC', version: 2}}
}
Expand Down Expand Up @@ -145,16 +148,43 @@ const bidResArray = [
}
];

describe('Undertone Adapter', function () {
describe('request', function () {
it('should validate bid request', function () {
let element;
let sandbox;

let elementParent = {
offsetLeft: 100,
offsetTop: 100,
offsetHeight: 100,
getAttribute: function() {}
};

describe('Undertone Adapter', () => {
describe('request', () => {
it('should validate bid request', () => {
expect(spec.isBidRequestValid(validBidReq)).to.equal(true);
});
it('should not validate incorrect bid request', function () {
it('should not validate incorrect bid request', () => {
expect(spec.isBidRequestValid(invalidBidReq)).to.equal(undefined);
});
});
describe('build request', function () {
beforeEach(function() {
element = {
id: 'div-gpt-ad-1460505748561-0',
offsetLeft: 100,
offsetTop: 100,
offsetWidth: 300,
offsetHeight: 250
};

sandbox = sinon.sandbox.create();
sandbox.stub(document, 'getElementById').withArgs('div-gpt-ad-1460505748561-0').returns(element);
});

afterEach(function() {
sandbox.restore();
});

it('should send request to correct url via POST not in GDPR or CCPA', function () {
const request = spec.buildRequests(bidReq, bidderReq);
const domainStart = bidderReq.refererInfo.referer.indexOf('//');
Expand Down Expand Up @@ -202,6 +232,7 @@ describe('Undertone Adapter', function () {
expect(bid1.sizes.length).to.equal(2);
expect(bid1.placementId).to.equal('10433394');
expect(bid1.publisherId).to.equal(12345);
expect(bid1.coordinates).to.be.an('array');
expect(bid1.params).to.be.an('object');
const bid2 = JSON.parse(request.data)['x-ut-hb-params'][1];
expect(bid2.bidRequestId).to.equal('453cf42d72bb3c');
Expand All @@ -216,17 +247,41 @@ describe('Undertone Adapter', function () {
expect(bidCommons).to.be.an('object');
expect(bidCommons.uids).to.be.an('object');
expect(bidCommons.uids.tdid).to.equal('123456');
expect(bidCommons.uids.idl_env).to.equal('1111');
expect(bidCommons.uids.digitrustid.data.id).to.equal('DTID');
});
it('should send page sizes sizes correctly', function () {
const request = spec.buildRequests(bidReqUserIds, bidderReq);
const bidCommons = JSON.parse(request.data)['commons'];
expect(bidCommons).to.be.an('object');
expect(bidCommons.pageSize).to.be.an('array');
expect(bidCommons.pageSize[0]).to.equal(window.innerWidth);
expect(bidCommons.pageSize[1]).to.equal(window.innerHeight);
});
it('should send banner coordinates', function() {
const request = spec.buildRequests(bidReq, bidderReq);
const bid1 = JSON.parse(request.data)['x-ut-hb-params'][0];
expect(bid1.coordinates).to.be.an('array');
expect(bid1.coordinates[0]).to.equal(100);
expect(bid1.coordinates[1]).to.equal(100);
});
it('should send banner coordinates plus parent', function() {
element.offsetParent = elementParent;
const request = spec.buildRequests(bidReq, bidderReq);
const bid1 = JSON.parse(request.data)['x-ut-hb-params'][0];
expect(bid1.coordinates).to.be.an('array');
expect(bid1.coordinates[0]).to.equal(200);
expect(bid1.coordinates[1]).to.equal(200);
});
});

describe('interpretResponse', function () {
it('should build bid array', function () {
describe('interpretResponse', () => {
it('should build bid array', () => {
let result = spec.interpretResponse({body: bidResponse});
expect(result.length).to.equal(1);
});

it('should have all relevant fields', function () {
it('should have all relevant fields', () => {
const result = spec.interpretResponse({body: bidResponse});
const bid = result[0];

Expand All @@ -240,12 +295,12 @@ describe('Undertone Adapter', function () {
expect(bid.ttl).to.equal(360);
});

it('should return empty array when response is incorrect', function () {
it('should return empty array when response is incorrect', () => {
expect(spec.interpretResponse({body: {}}).length).to.equal(0);
expect(spec.interpretResponse({body: []}).length).to.equal(0);
});

it('should only use valid bid responses', function () {
it('should only use valid bid responses', () => {
expect(spec.interpretResponse({ body: bidResArray }).length).to.equal(1);
});
});
Expand Down