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

SmartyadsBidAdapter: remove usprivacy #11829

Merged
2 changes: 1 addition & 1 deletion libraries/creative-renderer-display/renderer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion libraries/creative-renderer-native/renderer.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

89 changes: 28 additions & 61 deletions modules/smartyadsBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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';

const BIDDER_CODE = 'smartyads';
const GVLID = 534;
Expand All @@ -15,17 +14,21 @@ const adUrls = {
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']) {
if (!bid) return false;

const { requestId, cpm, creativeId, ttl, currency } = bid;

const isValid = [requestId, cpm, creativeId, ttl, currency].every(item => !!item);
if (!isValid) return false;

switch (bid.mediaType) {
case BANNER:
return Boolean(bid.width && bid.height && bid.ad);
return !!(bid.ad && bid.width && bid.height);
case VIDEO:
return Boolean(bid.vastUrl) || Boolean(bid.vastXml);
return !!(bid.vastUrl || bid.vastXml);
case NATIVE:
return Boolean(bid.native && bid.native.title && bid.native.image && bid.native.impressionTrackers);
const native = bid.native;
return !!(native && native.image && native.impressionTrackers);
default:
return false;
}
Expand Down Expand Up @@ -76,22 +79,18 @@ export const spec = {
location = bidderRequest?.refererInfo ?? null;
let placements = [];
let request = {
'placements': placements,
'deviceWidth': winTop.screen.width,
'deviceHeight': winTop.screen.height,
'host': location?.domain || '',
'page': location?.page || '',
'language': (navigator && navigator.language) ? navigator.language : '',
'secure': 1,
'host': location?.domain ?? '',
'page': location?.page ?? '',
'coppa': config.getConfig('coppa') === true ? 1 : 0,
Copy link
Collaborator

@patmmccann patmmccann Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will not be accepting tricks to fool the duplication check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patmmccann OK, but how can I fix that? I saw the report and duplication check marks, for example, the isBidResponseValid function is used in lots of adapters and looks almost the same.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out this work in progress from an adapter structured very similar to yours

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@patmmccann I'm sorry, but I still don't get it. The previous version of the isBidResponseValid function was flagged as duplicate code by your tool, but it doesn't need any updates, right? And the same function with same code is used in other adapters

Copy link
Collaborator

@patmmccann patmmccann Jun 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You and other modules have duplicate code, we need you to move common functions into libraries before making further updates to your adapter

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#8527 has an example on how to move common functions into a library

'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 +127,27 @@ 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;
interpretResponse: (response) => {
let result = [];
const respData = response.body;

respData.forEach(resp => {
if (isBidResponseValid(resp)) result.push(resp);
});

return result;
},

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}`
});
}
const type = syncOptions.iframeEnabled ? 'iframe' : 'image';
const url = `${URL_SYNC}&gdpr=${gdprApplies ? 1 : 0}&gdpr_consent=${consentString}&type=${type}&us_privacy=&gpp=${gppConsent}`;

syncs.push({ type, url });
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));
}
},

};

registerBidder(spec);
79 changes: 1 addition & 78 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', 'language', '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 @@ -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);
});
});
});