Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 25 additions & 34 deletions modules/liveIntentRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,42 @@
* This module adds the LiveIntent provider to the Real Time Data module (rtdModule).
*/
import { submodule } from '../src/hook.js';
import { deepAccess, deepSetValue } from '../src/utils.js';

/**
* @typedef {import('../modules/rtdModule/index.js').RtdSubmodule} RtdSubmodule
* @typedef {import('../modules/rtdModule/index.js').SubmoduleConfig} SubmoduleConfig
* @typedef {import('../modules/rtdModule/index.js').UserConsentData} UserConsentData
*/
import { deepAccess, mergeDeep } from '../src/utils.js';
import { getGlobal } from '../src/prebidGlobal.js';

const SUBMODULE_NAME = 'liveintent';
const GVLID = 148;
const LI_DOMAIN = 'liveintent.com';

/**
* Init
* @param {Object} config Module configuration
* @param {UserConsentData} userConsent User consent
* @returns true
*/
const init = (config, userConsent) => {
return true;
};
const init = () => true;

/**
* onBidRequest is called for each bidder during an auction and contains the bids for that bidder.
*
* @param {Object} bidRequest
* @param {SubmoduleConfig} config
* @param {UserConsentData} userConsent
*/
function getLiveIntentSegments() {
const userIds = typeof getGlobal().getUserIds === 'function'
? getGlobal().getUserIds()
: {};
return deepAccess(userIds, 'lipb.segments', []);
}

function onBidRequest(bidRequest, config, userConsent) {
bidRequest.bids.forEach(bid => {
const providedSegmentsFromUserId = deepAccess(bid, 'userId.lipb.segments', []);
if (providedSegmentsFromUserId.length > 0) {
const providedSegments = { name: 'liveintent.com', segment: providedSegmentsFromUserId.map(id => ({ id })) };
const existingData = deepAccess(bid, 'ortb2.user.data', []);
deepSetValue(bid, 'ortb2.user.data', existingData.concat(providedSegments));
}
});
function getBidRequestData(reqBidsConfigObj, callback) {
const segments = getLiveIntentSegments();
if (segments.length > 0) {
mergeDeep(reqBidsConfigObj.ortb2Fragments.global, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the User ID bidder allowlist when adding segments

When a publisher configures LiveIntent with bidders: ['allowedBidder'] in userSync.userIds, getUserIds() still exposes its segments through initializedSubmodules.combined (modules/userId/index.ts:609-610). Writing those segments into ortb2Fragments.global then includes them in every bidder's request, including bidders excluded by the publisher's allowlist. Normal User ID enrichment preserves this restriction using bidder-specific fragments. Preserve the same bidder scope when adding user.data, rather than turning restricted LiveIntent data into globally shared FPD.

AGENTS.md reference: AGENTS.md:L119-L119

Useful? React with 👍 / 👎.

user: {
data: [{
name: LI_DOMAIN,
segment: segments.map(id => ({ id }))
}]
}
});
}
callback();
}

export const liveIntentRtdSubmodule = {
name: SUBMODULE_NAME,
gvlid: GVLID,
init: init,
onBidRequestEvent: onBidRequest
init,
getBidRequestData
};

submodule('realTimeData', liveIntentRtdSubmodule);
6 changes: 4 additions & 2 deletions modules/liveIntentRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Maintainer: product@liveIntent.com

# Description

This module extracts segments from `bidRequest.userId.lipb.segments` enriched by the userID module and
injects them in `ortb2.user.data` array entry.
This module reads LiveIntent segments from the User ID module via
`pbjs.getUserIds().lipb.segments` and injects them into `ortb2.user.data`
as a `{ name: 'liveintent.com', segment: [...] }` entry during
`getBidRequestData`.

Please visit [LiveIntent](https://www.liveIntent.com/) for more information.

Expand Down
194 changes: 110 additions & 84 deletions test/spec/modules/liveIntentRtdProvider_spec.js
Original file line number Diff line number Diff line change
@@ -1,116 +1,142 @@
import { liveIntentRtdSubmodule } from 'modules/liveIntentRtdProvider.js';
import * as utils from 'src/utils.js';
import * as prebidGlobal from 'src/prebidGlobal.js';
import { expect } from 'chai';

describe('LiveIntent Rtd Provider', function () {
const SUBMODULE_NAME = 'liveintent';
const SEGMENTS = ['asa_1231', 'lalo_4311', 'liurl_99123'];
const EXPECTED_USER_DATA = [{
name: 'liveintent.com',
segment: SEGMENTS.map(id => ({ id }))
}];

describe('submodule `init`', function () {
const config = {
name: SUBMODULE_NAME,
let sandbox;
let getUserIdsStub;

function makeReqBidsConfig(globalOrtb2 = {}) {
return {
ortb2Fragments: {
global: globalOrtb2,
bidder: {}
}
};
it('init returns true when the subModuleName is defined', function () {
const value = liveIntentRtdSubmodule.init(config);
expect(value).to.equal(true);
}

function stubUserIds(userIds) {
getUserIdsStub = sandbox.stub().returns(userIds);
sandbox.stub(prebidGlobal, 'getGlobal').returns({
getUserIds: getUserIdsStub
});
}

beforeEach(function () {
sandbox = sinon.createSandbox();
});

describe('submodule `onBidRequestEvent`', function () {
const bidRequestExample = {
bidderCode: 'appnexus',
auctionId: '8dbd7cb1-7f6d-4f84-946c-d0df4837234a',
bidderRequestId: '2a038c6820142b',
bids: [
{
bidder: 'appnexus',
userId: {
lipb: {
segments: [
'asa_1231',
'lalo_4311',
'liurl_99123'
]
}
}
}
]
};
afterEach(function () {
sandbox.restore();
});

describe('submodule `init`', function () {
it('returns true', function () {
expect(liveIntentRtdSubmodule.init({ name: SUBMODULE_NAME })).to.equal(true);
});
});

describe('submodule `getBidRequestData`', function () {
it('exists', function () {
expect(liveIntentRtdSubmodule.onBidRequestEvent).to.be.a('function');
expect(liveIntentRtdSubmodule.getBidRequestData).to.be.a('function');
});

it('calls callback and leaves ortb2 unchanged when getUserIds is missing', function () {
sandbox.stub(prebidGlobal, 'getGlobal').returns({});
const reqBidsConfigObj = makeReqBidsConfig();
const callback = sandbox.spy();

liveIntentRtdSubmodule.getBidRequestData(reqBidsConfigObj, callback);

expect(callback.calledOnce).to.equal(true);
expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({});
});

it('undefined segments field does not change the ortb2', function() {
const bidRequest = {
bidderCode: 'appnexus',
auctionId: '8dbd7cb1-7f6d-4f84-946c-d0df4837234a',
bidderRequestId: '2a038c6820142b',
bids: [
{
bidder: 'appnexus',
ortb2: {}
}
]
it('calls callback and leaves ortb2 unchanged when segments are missing', function () {
stubUserIds({ lipb: { lipbid: 'abc' } });

const existing = {
name: 'example.com',
segment: [{ id: 'a_1231' }, { id: 'b_4311' }]
};

liveIntentRtdSubmodule.onBidRequestEvent(bidRequest);
const ortb2 = bidRequest.bids[0].ortb2;
expect(ortb2).to.deep.equal({});
const reqBidsConfigObj = makeReqBidsConfig({
source: {},
user: { data: [existing] }
});
const callback = sandbox.spy();

liveIntentRtdSubmodule.getBidRequestData(reqBidsConfigObj, callback);

expect(callback.calledOnce).to.equal(true);
expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({
source: {},
user: { data: [existing] }
});
});

it('extracts segments and move them to the bidRequest.ortb2.user.data when the ortb2 is undefined', function() {
const bidRequest = utils.deepClone(bidRequestExample);
it('calls callback and leaves ortb2 unchanged when segments are empty', function () {
stubUserIds({ lipb: { segments: [] } });
const reqBidsConfigObj = makeReqBidsConfig();
const callback = sandbox.spy();

liveIntentRtdSubmodule.getBidRequestData(reqBidsConfigObj, callback);

liveIntentRtdSubmodule.onBidRequestEvent(bidRequest);
const ortb2 = bidRequest.bids[0].ortb2;
const expectedOrtb2 = { user: { data: [{ name: 'liveintent.com', segment: [{ id: 'asa_1231' }, { id: 'lalo_4311' }, { id: 'liurl_99123' }] }] } };
expect(ortb2).to.deep.equal(expectedOrtb2);
expect(callback.calledOnce).to.equal(true);
expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({});
});

it('extracts segments and move them to the bidRequest.ortb2.user.data when user is undefined', function() {
bidRequestExample.bids[0].ortb2 = { source: {} };
const bidRequest = utils.deepClone(bidRequestExample);
it('writes liveintent.com user.data from getUserIds().lipb.segments', function () {
stubUserIds({ lipb: { lipbid: 'abc', segments: SEGMENTS } });
const reqBidsConfigObj = makeReqBidsConfig();
const callback = sandbox.spy();

liveIntentRtdSubmodule.getBidRequestData(reqBidsConfigObj, callback);

liveIntentRtdSubmodule.onBidRequestEvent(bidRequest);
const ortb2 = bidRequest.bids[0].ortb2;
const expectedOrtb2 = { source: {}, user: { data: [{ name: 'liveintent.com', segment: [{ id: 'asa_1231' }, { id: 'lalo_4311' }, { id: 'liurl_99123' }] }] } };
expect(ortb2).to.deep.equal(expectedOrtb2);
expect(callback.calledOnce).to.equal(true);
expect(getUserIdsStub.calledOnce).to.equal(true);
expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({
user: { data: EXPECTED_USER_DATA }
});
});

it('extracts segments and move them to the bidRequest.ortb2.user.data when data is undefined', function() {
bidRequestExample.bids[0].ortb2 = {
source: {},
user: {}
};
const bidRequest = utils.deepClone(bidRequestExample);
it('still writes segments when lipbid is absent', function () {
stubUserIds({ lipb: { segments: SEGMENTS } });
const reqBidsConfigObj = makeReqBidsConfig();
const callback = sandbox.spy();

liveIntentRtdSubmodule.onBidRequestEvent(bidRequest);
const ortb2 = bidRequest.bids[0].ortb2;
const expectedOrtb2 = { source: {}, user: { data: [{ name: 'liveintent.com', segment: [{ id: 'asa_1231' }, { id: 'lalo_4311' }, { id: 'liurl_99123' }] }] } };
expect(ortb2).to.deep.equal(expectedOrtb2);
liveIntentRtdSubmodule.getBidRequestData(reqBidsConfigObj, callback);

expect(callback.calledOnce).to.equal(true);
expect(reqBidsConfigObj.ortb2Fragments.global.user.data).to.deep.equal(EXPECTED_USER_DATA);
});

it('extracts segments and move them to the bidRequest.ortb2.user.data with the existing data', function() {
bidRequestExample.bids[0].ortb2 = {
source: {},
user: {
data: [
{
name: 'example.com',
segment: [
{ id: 'a_1231' },
{ id: 'b_4311' }
]
}
]
}
it('appends to existing global user.data', function () {
stubUserIds({ lipb: { segments: SEGMENTS } });
const existing = {
name: 'example.com',
segment: [{ id: 'a_1231' }, { id: 'b_4311' }]
};
const bidRequest = utils.deepClone(bidRequestExample);
const reqBidsConfigObj = makeReqBidsConfig({
source: {},
user: { data: [existing] }
});
const callback = sandbox.spy();

liveIntentRtdSubmodule.getBidRequestData(reqBidsConfigObj, callback);

liveIntentRtdSubmodule.onBidRequestEvent(bidRequest);
const ortb2 = bidRequest.bids[0].ortb2;
const expectedOrtb2 = { source: {}, user: { data: [{ name: 'example.com', segment: [{ id: 'a_1231' }, { id: 'b_4311' }] }, { name: 'liveintent.com', segment: [{ id: 'asa_1231' }, { id: 'lalo_4311' }, { id: 'liurl_99123' }] }] } };
expect(ortb2).to.deep.equal(expectedOrtb2);
expect(callback.calledOnce).to.equal(true);
expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({
source: {},
user: { data: [existing, ...EXPECTED_USER_DATA] }
});
});
});
});
Loading