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

Rayn RTD Module: update orbt object with personas #11841

Merged
merged 1 commit into from
Jun 20, 2024
Merged
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
1 change: 1 addition & 0 deletions integrationExamples/gpt/raynRtdProvider_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"3": ["264", "267", "261"],
"4": ["438"]
},
"103015": ['agdv23', 'avscg3'],
"903555595": {
"7": {
"2": ["51", "246"]
Expand Down
39 changes: 36 additions & 3 deletions modules/raynRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { deepAccess, deepSetValue, logError, logMessage, mergeDeep } from '../sr
const MODULE_NAME = 'realTimeData';
const SUBMODULE_NAME = 'rayn';
const RAYN_TCF_ID = 1220;
const RAYN_PERSONA_TAXONOMY_ID = 103015;
const LOG_PREFIX = 'RaynJS: ';
export const SEGMENTS_RESOLVER = 'rayn.io';
export const RAYN_LOCAL_STORAGE_KEY = 'rayn-segtax';
Expand Down Expand Up @@ -77,6 +78,32 @@ export function generateOrtbDataObject(segtax, segment, maxTier) {
};
}

/**
* Create and return ORTB2 object with segtax and personaIds
* @param {number} segtax
* @param {Array} personaIds
* @return {Array}
*/
export function generatePersonaOrtbDataObject(segtax, personaIds) {
const segmentIds = [];

try {
segmentIds.push(...personaIds.map((id) => {
return { id };
}))
} catch (error) {
logError(LOG_PREFIX, error);
}

return {
name: SEGMENTS_RESOLVER,
ext: {
segtax,
},
segment: segmentIds,
};
}

/**
* Generates checksum
* @param {string} url
Expand Down Expand Up @@ -127,8 +154,14 @@ export function setSegmentsAsBidderOrtb2(bidConfig, bidders, integrationConfig,
deepSetValue(raynOrtb2, 'site.content.data', raynContentData);
}

const raynUserData = [];
if (integrationConfig.iabAudienceCategories.v1_1.enabled && segments[4]) {
const raynUserData = [generateOrtbDataObject(4, segments[4], integrationConfig.iabAudienceCategories.v1_1.tier)];
raynUserData.push(generateOrtbDataObject(4, segments[4], integrationConfig.iabAudienceCategories.v1_1.tier));
}
if (segments[RAYN_PERSONA_TAXONOMY_ID]) {
raynUserData.push(generatePersonaOrtbDataObject(RAYN_PERSONA_TAXONOMY_ID, segments[RAYN_PERSONA_TAXONOMY_ID]));
}
if (raynUserData.length > 0) {
deepSetValue(raynOrtb2, 'user.data', raynUserData);
}

Expand Down Expand Up @@ -163,8 +196,8 @@ function alterBidRequests(reqBidsConfigObj, callback, config, userConsent) {
segments[checksum] || (segments[4] &&
integrationConfig.iabAudienceCategories.v1_1.enabled &&
!integrationConfig.iabContentCategories.v2_2.enabled &&
!integrationConfig.iabContentCategories.v3_0.enabled
)
!integrationConfig.iabContentCategories.v3_0.enabled) ||
segments[RAYN_PERSONA_TAXONOMY_ID]
)) {
logMessage(LOG_PREFIX, `Segtax data from localStorage: ${JSON.stringify(segments)}`);
setSegmentsAsBidderOrtb2(reqBidsConfigObj, bidders, integrationConfig, segments, checksum);
Expand Down
25 changes: 25 additions & 0 deletions test/spec/modules/raynRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ describe('rayn RTD Submodule', function () {
2: ['71', '313'],
4: ['33', '145', '712']
};
TEST_SEGMENTS['103015'] = ['agdv23', 'avscg3'];

const bidderOrtb2 = {};
const bidders = RTD_CONFIG.dataProviders[0].params.bidders;
Expand All @@ -174,6 +175,9 @@ describe('rayn RTD Submodule', function () {
TEST_SEGMENTS['4']['3'].forEach((id) => {
expect(ortb2.user.data[0].segment.find(segment => segment.id === id)).to.exist;
});
TEST_SEGMENTS['103015'].forEach((id) => {
expect(ortb2.user.data[1].segment.find(segment => segment.id === id)).to.exist;
});
});
});
});
Expand Down Expand Up @@ -229,6 +233,27 @@ describe('rayn RTD Submodule', function () {
logMessageSpy.restore();
});

it('should update reqBidsConfigObj and execute callback using persona segment from localStorage', function () {
const callbackSpy = sinon.spy();
const logMessageSpy = sinon.spy(utils, 'logMessage');
const testSegments = {
103015: ['agdv23', 'avscg3']
};

getDataFromLocalStorageStub
.withArgs(raynRTD.RAYN_LOCAL_STORAGE_KEY)
.returns(JSON.stringify(testSegments));

const reqBidsConfigObj = { ortb2Fragments: { bidder: {} } };

raynRTD.raynSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, RTD_CONFIG.dataProviders[0]);

expect(callbackSpy.calledOnce).to.be.true;
expect(logMessageSpy.lastCall.lastArg).to.equal(`Segtax data from localStorage: ${JSON.stringify(testSegments)}`);

logMessageSpy.restore();
});

it('should update reqBidsConfigObj and execute callback using segments from raynJS', function () {
const callbackSpy = sinon.spy();
const logMessageSpy = sinon.spy(utils, 'logMessage');
Expand Down