Skip to content

Commit

Permalink
AdagioRtdProvider: add placementSource param
Browse files Browse the repository at this point in the history
  • Loading branch information
osazos committed Jun 12, 2024
1 parent 69d7906 commit 360e20d
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 6 deletions.
31 changes: 26 additions & 5 deletions modules/adagioRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const ADAGIO_BIDDER_CODE = 'adagio';
const GVLID = 617;
const SCRIPT_URL = 'https://script.4dex.io/a/latest/adagio.js';
const SESS_DURATION = 30 * 60 * 1000;
export const PLACEMENT_SOURCES = {
ORTB: 'ortb', // implicit default, not used atm.
ADUNITCODE: 'code',
GPID: 'gpid'
};
export const storage = getStorageManager({ moduleType: MODULE_TYPE_RTD, moduleName: SUBMODULE_NAME });

const { logError, logWarn } = prefixLog('AdagioRtdProvider:');
Expand Down Expand Up @@ -271,6 +276,7 @@ function onBidRequest(bidderRequest, config, _userConsent) {
* @param {*} config
*/
function onGetBidRequestData(bidReqConfig, callback, config) {
const configParams = deepAccess(config, 'params', {});
const { site: ortb2Site } = bidReqConfig.ortb2Fragments.global;
const features = _internal.getFeatures().get();
const ext = {
Expand All @@ -294,8 +300,26 @@ function onGetBidRequestData(bidReqConfig, callback, config) {
const slotPosition = getSlotPosition(adUnit);
deepSetValue(ortb2Imp, `ext.data.adg_rtd.adunit_position`, slotPosition);

// We expect `pagetype` `category` are defined in FPD `ortb2.site.ext.data` object.
// `placement` is expected in FPD `adUnits[].ortb2Imp.ext.data` object. (Please note that this `placement` is not related to the oRTB video property.)
// It is expected that the publisher set a `adUnits[].ortb2Imp.ext.data.placement` value.
// Btw, We allow fallback sources to programmatically set this value.
// The source is defined in the `config.params.placementSource` and the possible values are `code` or `gpid`.
// (Please note that this `placement` is not related to the oRTB video property.)
if (!deepAccess(ortb2Imp, 'ext.data.placement')) {
const { placementSource = '' } = configParams;

switch (placementSource.toLowerCase()) {
case PLACEMENT_SOURCES.ADUNITCODE:
deepSetValue(ortb2Imp, 'ext.data.placement', adUnit.code);
break;
case PLACEMENT_SOURCES.GPID:
deepSetValue(ortb2Imp, 'ext.data.placement', deepAccess(ortb2Imp, 'ext.gpid'));
break;
default:
logWarn('`ortb2Imp.ext.data.placement` is missing and `params.definePlacement` is not set in the config.');
}
}

// We expect that `pagetype`, `category`, `placement` are defined in FPD `ortb2.site.ext.data` and `adUnits[].ortb2Imp.ext.data` objects.
// Btw, we have to ensure compatibility with publishers that use the "legacy" adagio params at the adUnit.params level.
const adagioBid = adUnit.bids.find(bid => _internal.isAdagioBidder(bid.bidder));
if (adagioBid) {
Expand All @@ -316,9 +340,6 @@ function onGetBidRequestData(bidReqConfig, callback, config) {
if (adagioBid.params.placement) {
deepSetValue(ortb2Imp, 'ext.data.placement', adagioBid.params.placement);
mustWarnOrtb2Imp = true;
} else {
// If the placement is not defined, we fallback to the adUnit code.
deepSetValue(ortb2Imp, 'ext.data.placement', adUnit.code);
}
}

Expand Down
1 change: 1 addition & 0 deletions modules/adagioRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pbjs.setConfig({
params: {
organizationId: '1000' // Required. Provided by Adagio
site: 'my-site' // Required. Provided by Adagio
placementSource: 'ortb' // Optional. Where to find the "placement" value. Possible values: 'ortb'<default> | 'code' | 'gpid'
}
}]
}
Expand Down
63 changes: 62 additions & 1 deletion test/spec/modules/adagioRtdProvider_spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { adagioRtdSubmodule, _internal, storage } from 'modules/adagioRtdProvider.js';
import {
PLACEMENT_SOURCES,
_internal,
adagioRtdSubmodule,
storage,
} from 'modules/adagioRtdProvider.js';
import * as utils from 'src/utils.js';
import { loadExternalScript } from '../../../src/adloader.js';
import { expect } from 'chai';
Expand Down Expand Up @@ -376,6 +381,62 @@ describe('Adagio Rtd Provider', function () {
const ortb2ImpExt = bidRequest.adUnits[0].ortb2Imp.ext.data.adg_rtd;
expect(ortb2ImpExt.adunit_position).equal('');
});

describe('update the ortb2Imp.ext.data.placement if not present', function() {
const config = {
name: SUBMODULE_NAME,
params: {
organizationId: '1000',
site: 'mysite'
}
};

it('update the placement value with the adUnit.code value', function() {
const configCopy = utils.deepClone(config);
configCopy.params.placementSource = PLACEMENT_SOURCES.ADUNITCODE;

const bidRequest = utils.deepClone(bidReqConfig);

adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy);
expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp');
expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.equal('div-gpt-ad-1460505748561-0');
});

it('update the placement value with the gpid value', function() {
const configCopy = utils.deepClone(config);
configCopy.params.placementSource = PLACEMENT_SOURCES.GPID;

const bidRequest = utils.deepClone(bidReqConfig);
const gpid = '/19968336/header-bid-tag-0'
utils.deepSetValue(bidRequest.adUnits[0], 'ortb2Imp.ext.gpid', gpid)

adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy);
expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp');
expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.equal(gpid);
});

it('update the placement value the legacy adUnit[].bids adagio.params.placement value', function() {
const placement = 'placement-value';

const configCopy = utils.deepClone(config);

const bidRequest = utils.deepClone(bidReqConfig);
bidRequest.adUnits[0].bids[0].params.placement = placement;

adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy);
expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp');
expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.equal(placement);
});

it('it does not populate `ortb2Imp.ext.data.placement` if no fallback', function() {
const configCopy = utils.deepClone(config);
const bidRequest = utils.deepClone(bidReqConfig);

adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy);
expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp');
expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.not.exist;
});
});
});

describe('submodule `onBidRequestEvent`', function() {
Expand Down

0 comments on commit 360e20d

Please sign in to comment.