Skip to content

Commit

Permalink
SmartyadsBidAdapter remove usprivacy (#11829)
Browse files Browse the repository at this point in the history
* SmartyadsBidAdapter remove usprivacy

* refactor

* refactor

* remove unusable code

* try to fix duplicated code

* try to fix duplicated code

* smallfixes

* smallfixes

* smallfix

* tests fix

* revert fixes

* remove language

* move getAdUrlByRegion to libs

* refactor

* undo creative functions

---------

Co-authored-by: vrishko <vasyl.rishko@smartyads.com>
  • Loading branch information
rishko00 and vrishko authored Jun 26, 2024
1 parent 0ea2add commit 1131a90
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 193 deletions.
32 changes: 32 additions & 0 deletions libraries/smartyadsUtils/getAdUrlByRegion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const adUrls = {
US_EAST: 'https://n1.smartyads.com/?c=o&m=prebid&secret_key=prebid_js',
EU: 'https://n2.smartyads.com/?c=o&m=prebid&secret_key=prebid_js',
SGP: 'https://n6.smartyads.com/?c=o&m=prebid&secret_key=prebid_js'
};

export function getAdUrlByRegion(bid) {
let adUrl;

if (bid.params.region && adUrls[bid.params.region]) {
adUrl = adUrls[bid.params.region];
} else {
try {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const region = timezone.split('/')[0];

switch (region) {
case 'Europe':
adUrl = adUrls['EU'];
break;
case 'Asia':
adUrl = adUrls['SGP'];
break;
default: adUrl = adUrls['US_EAST'];
}
} catch (err) {
adUrl = adUrls['US_EAST'];
}
}

return adUrl;
};
116 changes: 6 additions & 110 deletions modules/smartyadsBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,15 @@
import {registerBidder} from '../src/adapters/bidderFactory.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, NATIVE, VIDEO } from '../src/mediaTypes.js';
import { config } from '../src/config.js';
import { convertOrtbRequestToProprietaryNative } from '../src/native.js';
import { ajax } from '../src/ajax.js';
import { getAdUrlByRegion } from '../libraries/smartyadsUtils/getAdUrlByRegion.js';
import { interpretResponse, getUserSyncs } from '../libraries/teqblazeUtils/bidderUtils.js';

const BIDDER_CODE = 'smartyads';
const GVLID = 534;
const adUrls = {
US_EAST: 'https://n1.smartyads.com/?c=o&m=prebid&secret_key=prebid_js',
EU: 'https://n2.smartyads.com/?c=o&m=prebid&secret_key=prebid_js',
SGP: 'https://n6.smartyads.com/?c=o&m=prebid&secret_key=prebid_js'
}

const URL_SYNC = 'https://as.ck-ie.com/prebidjs?p=7c47322e527cf8bdeb7facc1bb03387a';

function isBidResponseValid(bid) {
if (!bid.requestId || !bid.cpm || !bid.creativeId ||
!bid.ttl || !bid.currency) {
return false;
}
switch (bid['mediaType']) {
case BANNER:
return Boolean(bid.width && bid.height && bid.ad);
case VIDEO:
return Boolean(bid.vastUrl) || Boolean(bid.vastXml);
case NATIVE:
return Boolean(bid.native && bid.native.title && bid.native.image && bid.native.impressionTrackers);
default:
return false;
}
}

function getAdUrlByRegion(bid) {
let adUrl;

if (bid.params.region && adUrls[bid.params.region]) {
adUrl = adUrls[bid.params.region];
} else {
try {
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
const region = timezone.split('/')[0];

switch (region) {
case 'Europe':
adUrl = adUrls['EU'];
break;
case 'Asia':
adUrl = adUrls['SGP'];
break;
default: adUrl = adUrls['US_EAST'];
}
} catch (err) {
adUrl = adUrls['US_EAST'];
}
}

return adUrl;
}

export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
Expand All @@ -78,20 +30,15 @@ export const spec = {
let request = {
'deviceWidth': winTop.screen.width,
'deviceHeight': winTop.screen.height,
'language': (navigator && navigator.language) ? navigator.language : '',
'secure': 1,
'host': location?.domain ?? '',
'page': location?.page ?? '',
'coppa': config.getConfig('coppa') === true ? 1 : 0,
'placements': placements,
'eeid': validBidRequests[0]?.userIdAsEids,
'ifa': bidderRequest?.ortb2?.device?.ifa,
};
request.language.indexOf('-') != -1 && (request.language = request.language.split('-')[0])

if (bidderRequest) {
if (bidderRequest.uspConsent) {
request.ccpa = bidderRequest.uspConsent;
}
if (bidderRequest.gdprConsent) {
request.gdpr = bidderRequest.gdprConsent
}
Expand Down Expand Up @@ -128,59 +75,8 @@ export const spec = {
}
},

interpretResponse: (serverResponse) => {
let response = [];
serverResponse = serverResponse.body;
for (let i = 0; i < serverResponse.length; i++) {
let resItem = serverResponse[i];
if (isBidResponseValid(resItem)) {
response.push(resItem);
}
}
return response;
},

getUserSyncs: (syncOptions, serverResponses = [], gdprConsent = {}, uspConsent = '', gppConsent = '') => {
let syncs = [];
let { gdprApplies, consentString = '' } = gdprConsent;

if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: `${URL_SYNC}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${consentString}&type=iframe&us_privacy=${uspConsent}&gpp=${gppConsent}`
});
} else {
syncs.push({
type: 'image',
url: `${URL_SYNC}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${consentString}&type=image&us_privacy=${uspConsent}&gpp=${gppConsent}`
});
}

return syncs
},

onBidWon: function(bid) {
if (bid.winUrl) {
ajax(bid.winUrl, () => {}, JSON.stringify(bid));
} else {
if (bid?.postData && bid?.postData[0] && bid?.postData[0].params && bid?.postData[0].params[0].host == 'prebid') {
ajax('https://et-nd43.itdsmr.com/?c=o&m=prebid&secret_key=prebid_js&winTest=1', () => {}, JSON.stringify(bid));
}
}
},

onTimeout: function(bid) {
if (bid?.postData && bid?.postData[0] && bid?.postData[0].params && bid?.postData[0].params[0].host == 'prebid') {
ajax('https://et-nd43.itdsmr.com/?c=o&m=prebid&secret_key=prebid_js&bidTimeout=1', () => {}, JSON.stringify(bid));
}
},

onBidderError: function(bid) {
if (bid?.postData && bid?.postData[0] && bid?.postData[0].params && bid?.postData[0].params[0].host == 'prebid') {
ajax('https://et-nd43.itdsmr.com/?c=o&m=prebid&secret_key=prebid_js&bidderError=1', () => {}, JSON.stringify(bid));
}
},

interpretResponse,
getUserSyncs: getUserSyncs(URL_SYNC),
};

registerBidder(spec);
89 changes: 6 additions & 83 deletions test/spec/modules/smartyadsBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,10 @@ describe('SmartyadsAdapter', function () {
it('Returns valid data if array of bids is valid', function () {
let data = serverRequest.data;
expect(data).to.be.an('object');
expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements', 'coppa', 'eeid', 'ifa');
expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'host', 'page', 'placements', 'coppa', 'eeid', 'ifa');
expect(data.deviceWidth).to.be.a('number');
expect(data.deviceHeight).to.be.a('number');
expect(data.coppa).to.be.a('number');
expect(data.language).to.be.a('string');
expect(data.secure).to.be.within(0, 1);
expect(data.host).to.be.a('string');
expect(data.page).to.be.a('string');
let placement = data['placements'][0];
Expand Down Expand Up @@ -126,8 +124,8 @@ describe('SmartyadsAdapter', function () {
expect(dataItem.width).to.equal(300);
expect(dataItem.height).to.equal(250);
expect(dataItem.ad).to.equal('Test');
expect(dataItem.meta).to.have.property('advertiserDomains')
expect(dataItem.meta.advertiserDomains).to.deep.equal(['example.com']);
expect(dataItem.meta).to.have.property('advertiserDomains');
expect(dataItem.meta.advertiserDomains).to.be.an('array');
expect(dataItem.ttl).to.equal(120);
expect(dataItem.creativeId).to.equal('2');
expect(dataItem.netRevenue).to.be.true;
Expand All @@ -152,7 +150,7 @@ describe('SmartyadsAdapter', function () {

let dataItem = videoResponses[0];
expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId',
'netRevenue', 'currency', 'dealId', 'mediaType');
'netRevenue', 'currency', 'dealId', 'mediaType', 'meta');
expect(dataItem.requestId).to.equal('23fhj33i987f');
expect(dataItem.cpm).to.equal(0.5);
expect(dataItem.vastUrl).to.equal('test.com');
Expand Down Expand Up @@ -183,7 +181,7 @@ describe('SmartyadsAdapter', function () {
expect(nativeResponses).to.be.an('array').that.is.not.empty;

let dataItem = nativeResponses[0];
expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native');
expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta');
expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image')
expect(dataItem.requestId).to.equal('23fhj33i987f');
expect(dataItem.cpm).to.equal(0.4);
Expand Down Expand Up @@ -263,7 +261,7 @@ describe('SmartyadsAdapter', function () {
});
});
describe('getUserSyncs', function () {
const syncUrl = 'https://as.ck-ie.com/prebidjs?p=7c47322e527cf8bdeb7facc1bb03387a&gdpr=0&gdpr_consent=&type=iframe&us_privacy=&gpp=';
const syncUrl = 'https://as.ck-ie.com/prebidjs?p=7c47322e527cf8bdeb7facc1bb03387a/iframe?pbjs=1&coppa=0';
const syncOptions = {
iframeEnabled: true
};
Expand All @@ -277,79 +275,4 @@ describe('SmartyadsAdapter', function () {
]);
});
});

describe('onBidWon', function () {
it('should exists', function () {
expect(spec.onBidWon).to.exist.and.to.be.a('function');
});

it('should send a valid bid won notice', function () {
const bid = {
'c': 'o',
'm': 'prebid',
'secret_key': 'prebid_js',
'winTest': '1',
'postData': [{
'bidder': 'smartyads',
'params': [
{'host': 'prebid',
'accountid': '123',
'sourceid': '12345'
}]
}]
};
spec.onBidWon(bid);
expect(server.requests.length).to.equal(1);
});
});

describe('onTimeout', function () {
it('should exists', function () {
expect(spec.onTimeout).to.exist.and.to.be.a('function');
});

it('should send a valid bid timeout notice', function () {
const bid = {
'c': 'o',
'm': 'prebid',
'secret_key': 'prebid_js',
'bidTimeout': '1',
'postData': [{
'bidder': 'smartyads',
'params': [
{'host': 'prebid',
'accountid': '123',
'sourceid': '12345'
}]
}]
};
spec.onTimeout(bid);
expect(server.requests.length).to.equal(1);
});
});

describe('onBidderError', function () {
it('should exists', function () {
expect(spec.onBidderError).to.exist.and.to.be.a('function');
});

it('should send a valid bidder error notice', function () {
const bid = {
'c': 'o',
'm': 'prebid',
'secret_key': 'prebid_js',
'bidderError': '1',
'postData': [{
'bidder': 'smartyads',
'params': [
{'host': 'prebid',
'accountid': '123',
'sourceid': '12345'
}]
}]
};
spec.onBidderError(bid);
expect(server.requests.length).to.equal(1);
});
});
});

0 comments on commit 1131a90

Please sign in to comment.