Skip to content

Commit

Permalink
Add user sync pixel logic in Adtelligent adapter (#3359)
Browse files Browse the repository at this point in the history
* Add user sync pixel logic in Adtelligent adapter

* Add gdpr support

* Add gdpr support

* Update tests
  • Loading branch information
GeneGenie authored and jsnellbaker committed Dec 10, 2018
1 parent 239f180 commit f424cd2
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
37 changes: 35 additions & 2 deletions modules/adtelligentBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,43 @@ export const spec = {
isBidRequestValid: function (bid) {
return bid && bid.params && bid.params.aid;
},
getUserSyncs: function (syncOptions, serverResponses) {
var syncs = [];

function addSyncs(_s) {
if (_s && _s.length) {
_s.forEach(s => {
syncs.push({
type: 'image',
url: s
})
})
}
}

if (syncOptions.pixelEnabled) {
serverResponses && serverResponses.length && serverResponses.forEach((response) => {
if (response.body) {
if (utils.isArray(response.body)) {
response.body.forEach(b => {
addSyncs(b.cookieURLs);
})
} else {
addSyncs(response.body.cookieURLs)
}
}
})
}
return syncs;
},
/**
* Make a server request from the list of BidRequests
* @param bidRequests
* @param bidderRequest
*/
buildRequests: function (bidRequests, bidderRequest) {
return {
data: bidToTag(bidRequests),
data: bidToTag(bidRequests, bidderRequest),
bidderRequest,
method: 'GET',
url: URL
Expand Down Expand Up @@ -83,11 +111,16 @@ function parseRTBResponse(serverResponse, bidderRequest) {
return bids;
}

function bidToTag(bidRequests) {
function bidToTag(bidRequests, bidderRequest) {
let tag = {
domain: utils.getTopWindowLocation().hostname
};

if (bidderRequest && bidderRequest.gdprConsent) {
tag.gdpr = 1;
tag.gdpr_consent = bidderRequest.gdprConsent.consentString;
}

for (let i = 0, length = bidRequests.length; i < length; i++) {
Object.assign(tag, prepareRTBRequestParams(i, bidRequests[i]));
}
Expand Down
37 changes: 35 additions & 2 deletions test/spec/modules/adtelligentBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const SERVER_VIDEO_RESPONSE = {
}
]
};

const SERVER_DISPLAY_RESPONSE = {
'source': {'aid': 12345, 'pubId': 54321},
'bids': [{
Expand All @@ -57,7 +58,8 @@ const SERVER_DISPLAY_RESPONSE = {
'cur': 'USD',
'width': 300,
'cpm': 0.9
}]
}],
'cookieURLs': ['link1', 'link2']
};

const videoBidderRequest = {
Expand All @@ -70,6 +72,14 @@ const displayBidderRequest = {
bids: [{bidId: '2e41f65424c87c'}]
};

const displayBidderRequestWithGdpr = {
bidderCode: 'bidderCode',
bids: [{bidId: '2e41f65424c87c'}],
gdprConsent: {
consentString: 'test'
}
};

const videoEqResponse = [{
vastUrl: 'http://rtb.adtelligent.com/vast/?adid=44F2AEB9BFC881B3',
requestId: '2e41f65424c87c',
Expand All @@ -96,9 +106,25 @@ const displayEqResponse = [{
cpm: 0.9
}];

describe('adtelligentBidAdapter', function () {
describe('adtelligentBidAdapter', function () { // todo remove only
const adapter = newBidder(spec);

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

expect(syncs.map(s => s.url)).to.deep.equal(SERVER_DISPLAY_RESPONSE.cookieURLs);
})
})

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

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

describe('inherited functions', function () {
it('exists and is a function', function () {
expect(adapter.callBids).to.exist.and.to.be.a('function');
Expand Down Expand Up @@ -212,6 +238,13 @@ describe('adtelligentBidAdapter', function () {
bidServerResponseCheck();
});

it('should set gdpr data correctly', function () {
const builtRequestData = spec.buildRequests([DISPLAY_REQUEST], displayBidderRequestWithGdpr);

expect(builtRequestData.data.gdpr).to.be.equal(1);
expect(builtRequestData.data.gdpr_consent).to.be.equal(displayBidderRequestWithGdpr.gdprConsent.consentString);
});

function bidServerResponseCheck() {
const result = spec.interpretResponse({body: serverResponse}, {bidderRequest});

Expand Down

0 comments on commit f424cd2

Please sign in to comment.