Skip to content

Commit

Permalink
TargetVideo Bid Adapter : user sync and response changes (#12461)
Browse files Browse the repository at this point in the history
* TargetVideo bid adapter

* TargetVideo bid adapter

* TargetVideo bid adapter

* TargetVideo Bid Adapter: Add GDPR/USP support

* TargetVideo Bid Adapter: Add GDPR/USP support tests

* TargetVideo Bid Adapter: Updating margin rule

* Add Brid bid adapter

* Brid adapter requested changes

* BridBidAdapter: switching to plcmt

* Brid Bid Adapter: getUserSyncs method and interpretResponse updates

* Adding missing semicolon

* TargetVideo Bid Adapter : user sync and response changes

* TargetVideo Bid Adapter : removing duplicate code
  • Loading branch information
grajzer authored Nov 24, 2024
1 parent e3e9ce0 commit b3577cc
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 39 deletions.
37 changes: 36 additions & 1 deletion libraries/targetVideoUtils/bidderUtils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {SYNC_URL} from './constants.js';
import {VIDEO} from '../../src/mediaTypes.js';
import {getRefererInfo} from '../../src/refererDetection.js';
import {createTrackPixelHtml, deepAccess, getBidRequest} from '../../src/utils.js';
import {createTrackPixelHtml, deepAccess, getBidRequest, formatQS} from '../../src/utils.js';

export function getSizes(request) {
let sizes = request.sizes;
Expand Down Expand Up @@ -167,6 +168,40 @@ export function getAd(bid) {
return {ad, adUrl, vastXml, vastUrl};
}

export function getSyncResponse(syncOptions, gdprConsent, uspConsent, gppConsent, endpoint) {
const params = {
endpoint
};

// Attaching GDPR Consent Params in UserSync url
if (gdprConsent) {
params.gdpr = (gdprConsent.gdprApplies ? 1 : 0);
params.gdpr_consent = encodeURIComponent(gdprConsent.consentString || '');
}

// CCPA
if (uspConsent && typeof uspConsent === 'string') {
params.us_privacy = encodeURIComponent(uspConsent);
}

// GPP Consent
if (gppConsent?.gppString && gppConsent?.applicableSections?.length) {
params.gpp = encodeURIComponent(gppConsent.gppString);
params.gpp_sid = encodeURIComponent(gppConsent?.applicableSections?.join(','));
}

const queryParams = Object.keys(params).length > 0 ? formatQS(params) : '';
let response = [];
if (syncOptions.iframeEnabled) {
response = [{
type: 'iframe',
url: SYNC_URL + 'load-cookie.html?' + queryParams
}];
}

return response;
}

export function getSiteObj() {
const refInfo = (getRefererInfo && getRefererInfo()) || {};

Expand Down
2 changes: 1 addition & 1 deletion libraries/targetVideoUtils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const VIDEO_ENDPOINT_URL = 'https://pbs.prebrid.tv/openrtb2/auction';
const SYNC_URL = 'https://bppb.link/static/';
const VIDEO_PARAMS = [
'api', 'linearity', 'maxduration', 'mimes', 'minduration',
'plcmt', 'playbackmethod', 'protocols', 'startdelay'
'plcmt', 'playbackmethod', 'protocols', 'startdelay', 'placement'
];

export {
Expand Down
38 changes: 4 additions & 34 deletions modules/bridBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {_each, deepAccess, formatQS, getDefinedParams, parseGPTSingleSizeArrayToRtbSize} from '../src/utils.js';
import {_each, deepAccess, getDefinedParams, parseGPTSingleSizeArrayToRtbSize} from '../src/utils.js';
import {VIDEO} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getAd, getSiteObj} from '../libraries/targetVideoUtils/bidderUtils.js'
import {GVLID, SOURCE, SYNC_URL, TIME_TO_LIVE, VIDEO_ENDPOINT_URL, VIDEO_PARAMS} from '../libraries/targetVideoUtils/constants.js';
import {getAd, getSiteObj, getSyncResponse} from '../libraries/targetVideoUtils/bidderUtils.js'
import {GVLID, SOURCE, TIME_TO_LIVE, VIDEO_ENDPOINT_URL, VIDEO_PARAMS} from '../libraries/targetVideoUtils/constants.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest
Expand Down Expand Up @@ -178,37 +178,7 @@ export const spec = {
* Return an array containing an object with the sync type and the constructed URL.
*/
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) => {
const params = {
endpoint: 'brid'
};

// Attaching GDPR Consent Params in UserSync url
if (gdprConsent) {
params.gdpr = (gdprConsent.gdprApplies ? 1 : 0);
params.gdpr_consent = encodeURIComponent(gdprConsent.consentString || '');
}

// CCPA
if (uspConsent && typeof uspConsent === 'string') {
params.us_privacy = encodeURIComponent(uspConsent);
}

// GPP Consent
if (gppConsent?.gppString && gppConsent?.applicableSections?.length) {
params.gpp = encodeURIComponent(gppConsent.gppString);
params.gpp_sid = encodeURIComponent(gppConsent?.applicableSections?.join(','));
}

const queryParams = Object.keys(params).length > 0 ? formatQS(params) : '';
let response = [];
if (syncOptions.iframeEnabled) {
response = [{
type: 'iframe',
url: SYNC_URL + 'load-cookie.html?' + queryParams
}];
}

return response;
return getSyncResponse(syncOptions, gdprConsent, uspConsent, gppConsent, 'brid');
}

}
Expand Down
18 changes: 15 additions & 3 deletions modules/targetVideoBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {_each, getDefinedParams, parseGPTSingleSizeArrayToRtbSize} from '../src/utils.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {registerBidder} from '../src/adapters/bidderFactory.js';
import {formatRequest, getRtbBid, getSiteObj, videoBid, bannerBid, createVideoTag} from '../libraries/targetVideoUtils/bidderUtils.js';
import {formatRequest, getRtbBid, getSiteObj, getSyncResponse, videoBid, bannerBid, createVideoTag} from '../libraries/targetVideoUtils/bidderUtils.js';
import {SOURCE, GVLID, BIDDER_CODE, VIDEO_PARAMS, BANNER_ENDPOINT_URL, VIDEO_ENDPOINT_URL, MARGIN, TIME_TO_LIVE} from '../libraries/targetVideoUtils/constants.js';

/**
Expand Down Expand Up @@ -167,14 +167,26 @@ export const spec = {
_each(resp.bid, (bid) => {
const requestId = bidRequest.bidId;
const params = bidRequest.params;

bids.push(videoBid(bid, requestId, currency, params, TIME_TO_LIVE));
const vBid = videoBid(bid, requestId, currency, params, TIME_TO_LIVE);
if (bids.length == 0 || bids[0].cpm < vBid.cpm) {
bids[0] = vBid;
}
});
});
}

return bids;
},

/**
* Determine the user sync type (either 'iframe' or 'image') based on syncOptions.
* Construct the sync URL by appending required query parameters such as gdpr, ccpa, and coppa consents.
* Return an array containing an object with the sync type and the constructed URL.
*/
getUserSyncs: (syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent) => {
return getSyncResponse(syncOptions, gdprConsent, uspConsent, gppConsent, 'targetvideo');
}

}

registerBidder(spec);
20 changes: 20 additions & 0 deletions test/spec/modules/targetVideoBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { spec } from '../../../modules/targetVideoBidAdapter.js'
import { SYNC_URL } from '../../../libraries/targetVideoUtils/constants.js';

describe('TargetVideo Bid Adapter', function() {
const bidder = 'targetVideo';
Expand Down Expand Up @@ -237,4 +238,23 @@ describe('TargetVideo Bid Adapter', function() {
expect(payload.regs.ext.us_privacy).to.equal(uspConsentString);
expect(payload.regs.ext.gdpr).to.equal(1);
});

it('Test userSync have only one object and it should have a property type=iframe', function () {
let userSync = spec.getUserSyncs({ iframeEnabled: true });
expect(userSync).to.be.an('array');
expect(userSync.length).to.be.equal(1);
expect(userSync[0]).to.have.property('type');
expect(userSync[0].type).to.be.equal('iframe');
});

it('Test userSync valid sync url for iframe', function () {
let [userSync] = spec.getUserSyncs({ iframeEnabled: true }, {}, {consentString: 'anyString'});
expect(userSync.url).to.contain(SYNC_URL + 'load-cookie.html?endpoint=targetvideo&gdpr=0&gdpr_consent=anyString');
expect(userSync.type).to.be.equal('iframe');
});

it('Test userSyncs iframeEnabled=false', function () {
let userSyncs = spec.getUserSyncs({iframeEnabled: false});
expect(userSyncs).to.have.lengthOf(0);
});
});

0 comments on commit b3577cc

Please sign in to comment.