Skip to content

Commit

Permalink
OptimeraRTD Module: Expose non-ad related data to the page. (#7849) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallari committed Dec 14, 2021
1 parent f542ff9 commit a9fbb83
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 8 additions & 1 deletion modules/optimeraRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ export function setScoresURL() {
}

/**
* Set the scores for the divice if given.
* Set the scores for the device if given.
* Add any any insights to the winddow.optimeraInsights object.
*
* @param {*} result
* @returns {string} JSON string of Optimera Scores.
*/
Expand All @@ -184,6 +186,11 @@ export function setScores(result) {
if (device !== 'default' && scores.device[device]) {
scores = scores.device[device];
}
logInfo(scores);
if (scores.insights) {
window.optimeraInsights = window.optimeraInsights || {};
window.optimeraInsights.data = scores.insights;
}
} catch (e) {
logError('Optimera score file could not be parsed.');
}
Expand Down
15 changes: 14 additions & 1 deletion test/spec/modules/optimeraRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,30 @@ describe('Optimera RTD score file properly sets targeting values', () => {
'de': {
'div-0': ['A5', 'A6'],
'div-1': ['A7', 'A8'],
'insights': {
'ilv': ['div-0'],
'miv': ['div-4'],
}
},
'mo': {
'div-0': ['A9', 'B0'],
'div-1': ['B1', 'B2'],
'insights': {
'ilv': ['div-1'],
'miv': ['div-2'],
}
}
},
'insights': {
'ilv': ['div-5'],
'miv': ['div-6'],
}
};
it('Properly set the score file url', () => {
it('Properly set the score file url and scores', () => {
optimeraRTD.setScores(JSON.stringify(scores));
expect(optimeraRTD.optimeraTargeting['div-0']).to.include.ordered.members(['A5', 'A6']);
expect(optimeraRTD.optimeraTargeting['div-1']).to.include.ordered.members(['A7', 'A8']);
expect(window.optimeraInsights.data['ilv']).to.include.ordered.members(['div-0']);
});
});

Expand Down

0 comments on commit a9fbb83

Please sign in to comment.