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

Teads-adapter: Read placementId from response and add sync informations #3963

Merged
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
28 changes: 24 additions & 4 deletions modules/teadsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const spec = {
const payload = {
referrer: getReferrerInfo(bidderRequest),
data: bids,
deviceWidth: screen.width
deviceWidth: screen.width,
hb_version: '$prebid.version$'
};

let gdpr = bidderRequest.gdprConsent;
Expand Down Expand Up @@ -84,19 +85,38 @@ export const spec = {
ttl: bid.ttl,
ad: bid.ad,
requestId: bid.bidId,
creativeId: bid.creativeId
creativeId: bid.creativeId,
placementId: bid.placementId
};
bidResponses.push(bidResponse);
});
}
return bidResponses;
},

getUserSyncs: function(syncOptions, responses, gdprApplies) {
getUserSyncs: function(syncOptions, responses, gdprConsent) {
let queryParams = {
hb_provider: 'prebid',
hb_version: '$prebid.version$'
};

if (gdprConsent) {
let gdprIab = {
status: findGdprStatus(gdprConsent.gdprApplies, gdprConsent.vendorData),
consent: gdprConsent.consentString
};

queryParams.gdprIab = JSON.stringify(gdprIab)
}

if (utils.deepAccess(responses[0], 'body.responses.0.placementId')) {
queryParams.placementId = responses[0].body.responses[0].placementId
};

if (syncOptions.iframeEnabled) {
return [{
type: 'iframe',
url: '//sync.teads.tv/iframe'
url: '//sync.teads.tv/iframe?' + utils.parseQueryStringParameters(queryParams)
}];
}
}
Expand Down
87 changes: 78 additions & 9 deletions test/spec/modules/teadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import {newBidder} from 'src/adapters/bidderFactory';
const ENDPOINT = '//a.teads.tv/hb/bid-request';
const AD_SCRIPT = '<script type="text/javascript" class="teads" async="true" src="http://a.teads.tv/hb/getAdSettings"></script>"';

describe('teadsBidAdapter', function() {
describe('teadsBidAdapter', () => {
const adapter = newBidder(spec);

describe('inherited functions', function() {
it('exists and is a function', function() {
describe('inherited functions', () => {
it('exists and is a function', () => {
expect(adapter.callBids).to.exist.and.to.be.a('function');
});
});
Expand Down Expand Up @@ -286,16 +286,17 @@ describe('teadsBidAdapter', function() {
'currency': 'USD',
'height': 250,
'netRevenue': true,
'requestId': '3ede2a3fa0db94',
'bidId': '3ede2a3fa0db94',
'ttl': 360,
'width': 300,
'creativeId': 'er2ee'
'creativeId': 'er2ee',
'placementId': 34
}]
}
};

it('should get correct bid response', function() {
let expectedResponse = [{
let expectedResponse = {
'cpm': 0.5,
'width': 300,
'height': 250,
Expand All @@ -304,11 +305,12 @@ describe('teadsBidAdapter', function() {
'ttl': 360,
'ad': AD_SCRIPT,
'requestId': '3ede2a3fa0db94',
'creativeId': 'er2ee'
}];
'creativeId': 'er2ee',
'placementId': 34
};

let result = spec.interpretResponse(bids);
expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0]));
expect(result[0]).to.deep.equal(expectedResponse);
});

it('handles nobid responses', function() {
Expand All @@ -322,4 +324,71 @@ describe('teadsBidAdapter', function() {
expect(result.length).to.equal(0);
});
});

it('should call userSync with good params', function() {
let bids = [{
'body': {
'responses': [{
'ad': '<script>',
'cpm': 0.5,
'currency': 'USD',
'height': 250,
'netRevenue': true,
'bidId': '3ede2a3fa0db94',
'ttl': 360,
'width': 300,
'creativeId': 'er2ee',
'placementId': 34
}]
}
}];
let syncOptions = { 'iframeEnabled': true };
let consentString = 'JRJ8FCP29RPZDeBNsERRDCSAAZ+A==';
let gdprConsent = {
'consentString': consentString,
'gdprApplies': true,
'vendorData': {
'hasGlobalConsent': false
}
};
let hb_version = '$prebid.version$'
let finalUrl = `//sync.teads.tv/iframe?hb_provider=prebid&hb_version=${hb_version}&gdprIab={"status":12,"consent":"${consentString}"}&placementId=34&`;
const userSync = spec.getUserSyncs(syncOptions, bids, gdprConsent);

expect(userSync[0].type).to.equal('iframe');
expect(decodeURIComponent(userSync[0].url)).to.equal(finalUrl);
});

it('should call userSync without placementId param', function() {
let bids = [{
'body': {
'responses': [{
'ad': '<script>',
'cpm': 0.5,
'currency': 'USD',
'height': 250,
'netRevenue': true,
'bidId': '3ede2a3fa0db94',
'ttl': 360,
'width': 300,
'creativeId': 'er2ee'
}]
}
}];
let syncOptions = { 'iframeEnabled': true };
let consentString = 'JRJ8FCP29RPZDeBNsERRDCSAAZ+A==';
let gdprConsent = {
'consentString': consentString,
'gdprApplies': true,
'vendorData': {
'hasGlobalConsent': false
}
};
let hb_version = '$prebid.version$'
let finalUrl = `//sync.teads.tv/iframe?hb_provider=prebid&hb_version=${hb_version}&gdprIab={"status":12,"consent":"${consentString}"}&`;
const userSync = spec.getUserSyncs(syncOptions, bids, gdprConsent);

expect(userSync[0].type).to.equal('iframe');
expect(decodeURIComponent(userSync[0].url)).to.equal(finalUrl);
});
});