Skip to content

Commit

Permalink
Merge branch 'master' of github.com:parthshah51999/Prebid.js
Browse files Browse the repository at this point in the history
  • Loading branch information
parthshah51999 committed Apr 25, 2024
2 parents e22ae9c + 7c53743 commit 000816d
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 20 deletions.
5 changes: 5 additions & 0 deletions modules/adnuntiusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ export const spec = {
queryParamsAndValues.push('gdpr=' + flag);
}

const searchParams = new URLSearchParams(window.location.search);
if (searchParams.has('script-override')) {
queryParamsAndValues.push('so=' + searchParams.get('script-override'));
}

storageTool.refreshStorage(bidderRequest);

const urlRelatedMetaData = storageTool.getUrlRelatedData();
Expand Down
2 changes: 1 addition & 1 deletion modules/gumgumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ function buildRequests(validBidRequests, bidderRequest) {
}
const dsa = deepAccess(bidderRequest, 'ortb2.regs.ext.dsa');
if (dsa) {
data.dsa = dsa
data.dsa = JSON.stringify(dsa)
}
if (coppa) {
data.coppa = coppa;
Expand Down
24 changes: 20 additions & 4 deletions modules/optidigitalBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,24 @@ export const spec = {
}
}

if (bidderRequest?.gppConsent?.gppString) {
payload.gpp = {
consent: bidderRequest.gppConsent.gppString,
sid: bidderRequest.gppConsent.applicableSections
}
} else if (bidderRequest?.ortb2?.regs?.gpp) {
payload.gpp = {
consent: bidderRequest.ortb2.regs.gpp,
sid: bidderRequest.ortb2.regs.gpp_sid
}
}

if (window.location.href.indexOf('optidigitalTestMode=true') !== -1) {
payload.testMode = true;
}

if (bidderRequest && bidderRequest.uspConsent) {
payload.uspConsent = bidderRequest.uspConsent;
payload.us_privacy = bidderRequest.uspConsent;
}

if (_getEids(validBidRequests[0])) {
Expand Down Expand Up @@ -153,16 +165,20 @@ export const spec = {
* @param {ServerResponse[]} serverResponses List of server's responses.
* @return {UserSync[]} The user syncs which should be dropped.
*/
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) {
getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) {
let syncurl = '';
if (!isSynced) {
// Attaching GDPR Consent Params in UserSync url
if (gdprConsent) {
syncurl += '&gdpr=' + (gdprConsent.gdprApplies ? 1 : 0);
syncurl += '&gdpr_consent=' + encodeURIComponent(gdprConsent.consentString || '');
}
if (uspConsent && uspConsent.consentString) {
syncurl += `&ccpa_consent=${uspConsent.consentString}`;
if (uspConsent) {
syncurl += '&us_privacy=' + encodeURIComponent(uspConsent);
}
if (gppConsent?.gppString && gppConsent?.applicableSections?.length) {
syncurl += '&gpp=' + encodeURIComponent(gppConsent.gppString);
syncurl += '&gpp_sid=' + encodeURIComponent(gppConsent?.applicableSections?.join(','));
}

if (syncOptions.iframeEnabled) {
Expand Down
79 changes: 70 additions & 9 deletions modules/relaidoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import {
isArray,
isNumber,
parseSizesInput,
getBidIdParameter
getBidIdParameter,
isGptPubadsDefined
} from '../src/utils.js';
import { registerBidder } from '../src/adapters/bidderFactory.js';
import { BANNER, VIDEO } from '../src/mediaTypes.js';
import { Renderer } from '../src/Renderer.js';
import { getStorageManager } from '../src/storageManager.js';
import sha1 from 'crypto-js/sha1';
import { isSlotMatchingAdUnitCode } from '../libraries/gptUtils/gptUtils.js';

const BIDDER_CODE = 'relaido';
const BIDDER_DOMAIN = 'api.relaido.jp';
const ADAPTER_VERSION = '1.1.0';
const ADAPTER_VERSION = '1.2.0';
const DEFAULT_TTL = 300;
const UUID_KEY = 'relaido_uuid';

Expand Down Expand Up @@ -47,6 +49,7 @@ function buildRequests(validBidRequests, bidderRequest) {
let bidDomain = null;
let bidder = null;
let count = null;
let isOgUrlOption = false;

for (let i = 0; i < validBidRequests.length; i++) {
const bidRequest = validBidRequests[i];
Expand Down Expand Up @@ -92,6 +95,10 @@ function buildRequests(validBidRequests, bidderRequest) {
count = bidRequest.bidRequestsCount;
}

if (getBidIdParameter('ogUrl', bidRequest.params)) {
isOgUrlOption = true;
}

bids.push({
bid_id: bidRequest.bidId,
placement_id: getBidIdParameter('placementId', bidRequest.params),
Expand All @@ -105,10 +112,13 @@ function buildRequests(validBidRequests, bidderRequest) {
height: height,
banner_sizes: getBannerSizes(bidRequest),
media_type: mediaType,
userIdAsEids: bidRequest.userIdAsEids || {},
userIdAsEids: bidRequest.userIdAsEids || [],
pagekvt: getTargeting(bidRequest),
});
}

const canonicalUrl = getCanonicalUrl(bidderRequest.refererInfo?.canonicalUrl, isOgUrlOption);

const data = JSON.stringify({
version: ADAPTER_VERSION,
bids: bids,
Expand All @@ -118,8 +128,8 @@ function buildRequests(validBidRequests, bidderRequest) {
uuid: getUuid(),
pv: '$prebid.version$',
imuid: imuid,
canonical_url: bidderRequest.refererInfo?.canonicalUrl || null,
canonical_url_hash: getCanonicalUrlHash(bidderRequest.refererInfo),
canonical_url: canonicalUrl,
canonical_url_hash: getCanonicalUrlHash(canonicalUrl),
ref: bidderRequest.refererInfo.page
});

Expand Down Expand Up @@ -294,12 +304,25 @@ function getUuid() {
return newId;
}

function getCanonicalUrlHash(refererInfo) {
const canonicalUrl = refererInfo.canonicalUrl || null;
function getOgUrl() {
try {
const ogURLElement = window.top.document.querySelector('meta[property="og:url"]');
return ogURLElement ? ogURLElement.content : null;
} catch (e) {
const ogURLElement = document.querySelector('meta[property="og:url"]');
return ogURLElement ? ogURLElement.content : null;
}
}

function getCanonicalUrl(canonicalUrl, isOgUrlOption) {
if (!canonicalUrl) {
return null;
return (isOgUrlOption) ? getOgUrl() : null;
}
return sha1(canonicalUrl).toString();
return canonicalUrl;
}

function getCanonicalUrlHash(canonicalUrl) {
return (canonicalUrl) ? sha1(canonicalUrl).toString() : null;
}

function hasBannerMediaType(bid) {
Expand Down Expand Up @@ -349,6 +372,44 @@ function getBannerSizes(bidRequest) {
return parseSizesInput(sizes).join(',');
}

function getTargeting(bidRequest) {
const targetings = {};
const pubads = getPubads();
if (pubads) {
const keys = pubads.getTargetingKeys();
for (const key of keys) {
const values = pubads.getTargeting(key);
targetings[key] = values;
}
}
const adUnitSlot = getAdUnit(bidRequest.adUnitCode);
if (adUnitSlot) {
const keys = adUnitSlot.getTargetingKeys();
for (const key of keys) {
const values = adUnitSlot.getTargeting(key);
targetings[key] = values;
}
}
return targetings;
}

function getPubads() {
return (isGptPubadsDefined()) ? window.googletag.pubads() : null;
}

function getAdUnit(adUnitCode) {
if (isGptPubadsDefined()) {
const adSlots = window.googletag.pubads().getSlots();
const isMatchingAdSlot = isSlotMatchingAdUnitCode(adUnitCode);
for (let i = 0; i < adSlots.length; i++) {
if (isMatchingAdSlot(adSlots[i])) {
return adSlots[i];
}
}
}
return null;
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
Expand Down
19 changes: 18 additions & 1 deletion test/spec/modules/adnuntiusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ describe('adnuntiusBidAdapter', function() {
const meta = [{key: 'valueless'}, {value: 'keyless'}, {key: 'voidAuIds'}, {key: 'voidAuIds', value: [{auId: '11118b6bc', exp: misc.getUnixTimestamp()}, {exp: misc.getUnixTimestamp(1)}]}, {key: 'valid-withnetwork', value: 'also-valid-network', network: 'the-network', exp: misc.getUnixTimestamp(1)}, {key: 'valid', value: 'also-valid', exp: misc.getUnixTimestamp(1)}, {key: 'expired', value: 'fwefew', exp: misc.getUnixTimestamp()}, {key: 'usi', value: 'should be skipped because timestamp', exp: misc.getUnixTimestamp(), network: 'adnuntius'}, {key: 'usi', value: usi, exp: misc.getUnixTimestamp(100), network: 'adnuntius'}, {key: 'usi', value: 'should be skipped because timestamp', exp: misc.getUnixTimestamp()}]
let storage;

// need this to make the restore work correctly -- something to do with stubbing static prototype methods
let stub1 = {}, stub2 = {};

before(() => {
getGlobal().bidderSettings = {
adnuntius: {
Expand All @@ -34,6 +37,13 @@ describe('adnuntiusBidAdapter', function() {

afterEach(function() {
config.resetConfig();

if (stub1.restore) {
stub1.restore();
}
if (stub2.restore) {
stub2.restore();
}
});

const tzo = new Date().getTimezoneOffset();
Expand Down Expand Up @@ -457,13 +467,20 @@ describe('adnuntiusBidAdapter', function() {

describe('buildRequests', function() {
it('Test requests', function() {
stub1 = sinon.stub(URLSearchParams.prototype, 'has').callsFake(() => {
return true;
});
stub2 = sinon.stub(URLSearchParams.prototype, 'get').callsFake(() => {
return 'overridden-value';
});

const request = spec.buildRequests(bidderRequests, {});
expect(request.length).to.equal(1);
expect(request[0]).to.have.property('bid');
const bid = request[0].bid[0]
expect(bid).to.have.property('bidId');
expect(request[0]).to.have.property('url');
expect(request[0].url).to.equal(ENDPOINT_URL);
expect(request[0].url).to.equal(ENDPOINT_URL.replace('format=prebid', 'format=prebid&so=overridden-value'));
expect(request[0]).to.have.property('data');
expect(request[0].data).to.equal('{"adUnits":[{"auId":"000000000008b6bc","targetId":"123","maxDeals":1,"dimensions":[[640,480],[600,400]]},{"auId":"0000000000000551","targetId":"adn-0000000000000551","dimensions":[[1640,1480],[1600,1400]]}]}');
});
Expand Down
2 changes: 1 addition & 1 deletion test/spec/modules/gumgumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ describe('gumgumAdapter', function () {
// Call the buildRequests function to generate the bid request
const [bidRequest] = spec.buildRequests(bidRequests, fakeBidRequest);
// Assert that the DSA information in the bid request matches the provided ORTB2 data
expect(bidRequest.data.dsa).to.deep.equal(fakeBidRequest.ortb2.regs.ext.dsa);
expect(bidRequest.data.dsa).to.deep.equal(JSON.stringify(fakeBidRequest.ortb2.regs.ext.dsa));
});
it('should not set coppa parameter if coppa config is set to false', function () {
config.setConfig({
Expand Down
38 changes: 34 additions & 4 deletions test/spec/modules/optidigitalBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,32 @@ describe('optidigitalAdapterTests', function () {
bidderRequest.uspConsent = '1YYY';
const request = spec.buildRequests(validBidRequests, bidderRequest);
const payload = JSON.parse(request.data);
expect(payload.uspConsent).to.exist;
expect(payload.us_privacy).to.exist;
});

it('should send gppConsent to given endpoint where there is gppConsent', function() {
let consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==';
bidderRequest.gppConsent = {
'gppString': consentString,
'applicableSections': [7]
};
const request = spec.buildRequests(validBidRequests, bidderRequest);
const payload = JSON.parse(request.data);
expect(payload.gpp).to.exist;
});

it('should send gppConsent to given endpoint when there is gpp in ortb2', function() {
let consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==';
bidderRequest.gppConsent = undefined;
bidderRequest.ortb2 = {
regs: {
gpp: consentString,
gpp_sid: [7]
}
}
const request = spec.buildRequests(validBidRequests, bidderRequest);
const payload = JSON.parse(request.data);
expect(payload.gpp).to.exist;
});

it('should use appropriate mediaTypes banner sizes', function() {
Expand Down Expand Up @@ -546,9 +571,14 @@ describe('optidigitalAdapterTests', function () {
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=`
}]);
});
it('should return appropriate URL with GDPR equals to 1, GDPR consent and CCPA consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, {consentString: 'fooUsp'})).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo&ccpa_consent=fooUsp`
it('should return appropriate URL with GDPR equals to 1, GDPR consent and US Privacy consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, 'fooUsp')).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo&us_privacy=fooUsp`
}]);
});
it('should return appropriate URL with GDPR equals to 1, GDPR consent, US Privacy consent and GPP consent', function() {
expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, 'fooUsp', {gppString: 'fooGpp', applicableSections: [7]})).to.deep.equal([{
type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo&us_privacy=fooUsp&gpp=fooGpp&gpp_sid=7`
}]);
});
});
Expand Down
Loading

0 comments on commit 000816d

Please sign in to comment.