Skip to content

Commit

Permalink
Adding score file check on auction init. (prebid#7172)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallari authored and agrandes-tappx committed Sep 29, 2021
1 parent 0c0a230 commit 6cdad34
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
38 changes: 35 additions & 3 deletions modules/optimeraRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export let device = 'default';
*/
export let optimeraTargeting = {};

/**
* Flag to indicateo if a new score file should be fetched.
* @type {string}
*/
export let fetchScoreFile = true;

/**
* Make the request for the Score File.
*/
Expand Down Expand Up @@ -108,6 +114,17 @@ export function returnTargetingData(adUnits, config) {
return targeting;
}

/**
* Fetch a new score file when an auction starts.
* Only fetch the new file if a new score file is needed.
*/
export function onAuctionInit(auctionDetails, config, userConsent) {
setScoresURL();
if (fetchScoreFile) {
scoreFileRequest();
}
}

/**
* Initialize the Module.
*/
Expand All @@ -134,14 +151,25 @@ export function init(moduleConfig) {

/**
* Set the score file url.
* This fully-formed URL for the data endpoint request to fetch
*
* This fully-formed URL is for the data endpoint request to fetch
* the targeting values. This is not a js library, rather JSON
* which has the targeting values for the page.
*
* The score file url is based on the web page url. If the new score file URL
* has been updated, set the fetchScoreFile flag to true to is can be fetched.
*
*/
export function setScoresURL() {
const optimeraHost = window.location.host;
const optimeraPathName = window.location.pathname;
scoresURL = `${scoresBaseURL}${clientID}/${optimeraHost}${optimeraPathName}.js`;
let newScoresURL = `${scoresBaseURL}${clientID}/${optimeraHost}${optimeraPathName}.js`;
if (scoresURL !== newScoresURL) {
scoresURL = newScoresURL;
fetchScoreFile = true;
} else {
fetchScoreFile = false;
}
}

/**
Expand Down Expand Up @@ -169,10 +197,14 @@ export const optimeraSubmodule = {
* @type {string}
*/
name: 'optimeraRTD',
/**
* get data when an auction starts
* @function
*/
onAuctionInitEvent: onAuctionInit,
/**
* get data and send back to realTimeData module
* @function
* @param {string[]} adUnitsCodes
*/
getTargetingData: returnTargetingData,
init,
Expand Down
5 changes: 5 additions & 0 deletions test/spec/modules/optimeraRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ describe('Optimera RTD error logging', () => {
optimeraRTD.init(conf.dataProviders[0]);
expect(utils.logError.called).to.equal(true);
});

it('if adUnits is not an array should log an error', () => {
optimeraRTD.returnTargetingData('test');
expect(utils.logError.called).to.equal(true);
});
});

0 comments on commit 6cdad34

Please sign in to comment.