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

Prebid config options #7

Merged
merged 3 commits into from
Sep 7, 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
150 changes: 103 additions & 47 deletions modules/qortexRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,34 @@ function init (config) {
return false;
} else {
initializeModuleData(config);
getGroupConfig()
.then(groupConfig => {
logMessage(['Recieved response for qortex group config', groupConfig])
if (groupConfig?.active === true && groupConfig?.prebidBidEnrichment === true) {
setGroupConfigData(groupConfig);
} else {
logWarn('Group config is not configured for qortex RTD module, module functions will be paused')
setGroupConfigData(groupConfig);
}
})
.catch((e) => {
logWarn(e);
});

initiatePageAnalysis()
.then(successMessage => {
logMessage(successMessage)
})
.catch((e) => {
logWarn(e?.message);
});
}
if (config?.params?.tagConfig) {
loadScriptTag(config)
if (!config?.params?.disableBidEnrichment) {
logMessage('Requesting Qortex group configuration')
getGroupConfig()
.then(groupConfig => {
logMessage(['Recieved response for qortex group config', groupConfig])
if (groupConfig?.active === true && groupConfig?.prebidBidEnrichment === true) {
setGroupConfigData(groupConfig);
initializeBidEnrichment();
} else {
logWarn('Group config is not configured for qortex bid enrichment')
setGroupConfigData(groupConfig);
}
})
.catch((e) => {
const errorStatus = e.message;
logWarn('Returned error status code: ' + errorStatus);
if (errorStatus == 404) {
logWarn('No Group Config found');
}
});
} else {
logWarn('Bid Enrichment Function has been disabled in module configuration')
}
if (config?.params?.tagConfig) {
loadScriptTag(config)
}
return true;
}
return true;
}

/**
Expand All @@ -54,15 +56,15 @@ function init (config) {
* @param {Function} callback Called on completion
*/
function getBidRequestData (reqBidsConfig, callback) {
if (reqBidsConfig?.adUnits?.length > 0 && qortexSessionInfo.groupConfig?.prebidBidEnrichment === true) {
if (reqBidsConfig?.adUnits?.length > 0 && shouldAllowBidEnrichment()) {
getContext()
.then(contextData => {
setContextData(contextData)
addContextToRequests(reqBidsConfig)
callback();
})
.catch((e) => {
logWarn(e?.message);
.catch(e => {
logWarn('Returned error status code: ' + e.message);
callback();
});
} else {
Expand All @@ -76,7 +78,7 @@ function getBidRequestData (reqBidsConfig, callback) {
* @param {Object} data Auction end object
*/
function onAuctionEndEvent (data, config, t) {
if (qortexSessionInfo?.groupConfig?.prebidBidEnrichment === true) {
if (shouldAllowBidEnrichment()) {
sendAnalyticsEvent('AUCTION', 'AUCTION_END', attachContextAnalytics(data))
.then(result => {
logMessage('Qortex anyalitics event sent')
Expand All @@ -96,11 +98,20 @@ export function getContext () {
return new Promise((resolve, reject) => {
const callbacks = {
success(text, data) {
const result = data.status === 200 ? JSON.parse(data.response)?.content : null;
const responseStatus = data.status;
let result;
if (responseStatus === 200) {
qortexSessionInfo.pageAnalysisData.contextRetrieved = true
result = JSON.parse(data.response)?.content;
} else if (responseStatus === 202) {
qortexSessionInfo.pageAnalysisData.analysisInProgress = true;
result = null;
}
resolve(result);
},
error(error) {
reject(new Error(error));
error(e, x) {
const responseStatus = x.status;
reject(new Error(responseStatus));
}
}
ajax(qortexSessionInfo.contextUrl, callbacks, JSON.stringify(pageUrlObject), {contentType: 'application/json'})
Expand All @@ -116,15 +127,14 @@ export function getContext () {
* @returns {Promise} Qortex group configuration
*/
export function getGroupConfig () {
logMessage('Requesting group config');
return new Promise((resolve, reject) => {
const callbacks = {
success(text, data) {
const result = data.status === 200 ? JSON.parse(data.response) : null;
resolve(result);
},
error(error) {
reject(new Error(error));
error(e, x) {
reject(new Error(x.status));
}
}
ajax(qortexSessionInfo.groupConfigUrl, callbacks)
Expand All @@ -140,13 +150,19 @@ export function initiatePageAnalysis () {
logMessage('Sending page data for context analysis');
return new Promise((resolve, reject) => {
const callbacks = {
success() {
qortexSessionInfo.pageAnalysisdata.requestSuccessful = true;
resolve('Successfully initiated Qortex page analysis');
success(text, data) {
const responseStatus = data.status;
let resultMessage;
if (responseStatus === 201) {
qortexSessionInfo.pageAnalysisData.indexRequested = true;
resultMessage = 'Successfully initiated Qortex page analysis';
} else {
resultMessage = 'No index record created at this time'
}
resolve(resultMessage);
},
error(error) {
qortexSessionInfo.pageAnalysisdata.requestSuccessful = false;
reject(new Error(error));
error(e, x) {
reject(new Error(x.status));
}
}
ajax(qortexSessionInfo.pageAnalyisUrl, callbacks, JSON.stringify(qortexSessionInfo.indexData), {contentType: 'application/json'})
Expand Down Expand Up @@ -276,20 +292,49 @@ export function loadScriptTag(config) {
loadExternalScript(src, code, undefined, undefined, attr);
}

export function initializeBidEnrichment() {
if (shouldAllowBidEnrichment()) {
getContext()
.then(contextData => {
if (qortexSessionInfo.pageAnalysisData.contextRetrieved) {
logMessage('Contextual record recieved from Qortex API')
setContextData(contextData)
} else {
logWarn('Contexual record is not yet complete at this time')
}
})
.catch(e => {
const errorStatus = e.message;
logWarn('Returned error status code: ' + errorStatus);
if (errorStatus == 404) {
initiatePageAnalysis()
.then(message => {
logMessage(message)
})
.catch(e => {
logWarn(e);
})
}
});
}
}

/**
* Helper function to set initial values when they are obtained by init
* @param {Object} config module config obtained during init
*/
export function initializeModuleData(config) {
const {apiUrl, groupId, bidders} = config.params;
const {apiUrl, groupId, bidders, disableBidEnrichment} = config.params;
const qortexUrlBase = apiUrl || DEFAULT_API_URL;
const windowUrl = window.top.location.host;
qortexSessionInfo.bidEnrichmentDisabled = disableBidEnrichment !== null ? disableBidEnrichment : false;
qortexSessionInfo.bidderArray = bidders;
qortexSessionInfo.impressionIds = new Set();
qortexSessionInfo.currentSiteContext = null;
qortexSessionInfo.pageAnalysisdata = {
requestSuccessful: null,
analysisGenerated: false,
qortexSessionInfo.pageAnalysisData = {
analysisInProgress: false,
indexRequested: false,
contextRetrieved: false,
contextAdded: {}
};
qortexSessionInfo.sessionId = generateSessionId();
Expand All @@ -304,7 +349,7 @@ export function initializeModuleData(config) {
export function saveContextAdded(reqBids, bidders = null) {
const id = reqBids.auctionId;
const contextBidders = bidders ?? Array.from(new Set(reqBids.adUnits.flatMap(adunit => adunit.bids.map(bid => bid.bidder))))
qortexSessionInfo.pageAnalysisdata.contextAdded[id] = contextBidders;
qortexSessionInfo.pageAnalysisData.contextAdded[id] = contextBidders;
}

export function setContextData(value) {
Expand Down Expand Up @@ -338,7 +383,7 @@ function generateSessionId() {
function attachContextAnalytics (data) {
let qxData = {};
let qxDataAdded = false;
if (qortexSessionInfo?.pageAnalysisdata?.contextAdded[data.auctionId]) {
if (qortexSessionInfo?.pageAnalysisData?.contextAdded[data.auctionId]) {
qxData = qortexSessionInfo.currentSiteContext;
qxDataAdded = true;
}
Expand All @@ -353,6 +398,17 @@ function shouldSendAnalytics() {
return analyticsPercentage > randomInt;
}

function shouldAllowBidEnrichment() {
if (qortexSessionInfo.bidEnrichmentDisabled) {
logWarn('Bid enrichment disabled at prebid config')
return false;
} else if (!qortexSessionInfo.groupConfig?.prebidBidEnrichment) {
logWarn('Bid enrichment disabled at group config')
return false;
}
return true
}

export const qortexSubmodule = {
name: 'qortex',
init,
Expand Down
6 changes: 5 additions & 1 deletion modules/qortexRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pbjs.setConfig({
params: {
groupId: 'ABC123', //required
bidders: ['qortex', 'adapter2'], //optional (see below)
disableBidEnrichment: false, //optional (see below)
tagConfig: { // optional, please reach out to your account manager for configuration reccommendation
videoContainer: 'string',
htmlContainer: 'string',
Expand All @@ -66,4 +67,7 @@ pbjs.setConfig({
#### `tagConfig` - optional
- This optional parameter is an object containing the config settings that could be usedto initialize the Qortex integration on your page. A preconfigured object for this step will be provided to you by the Qortex team.

- If this parameter is not present, the Qortex integration can still be configured and loaded manually on your page outside of prebid. The RTD module will continue to initialize and operate as normal.
- If this parameter is not present, the Qortex integration can still be configured and loaded manually on your page outside of prebid. The RTD module will continue to initialize and operate as normal.

#### `disableBidEnrichment` - optional
- This optional parameter allows a publisher to opt out of the RTD module from using our API to enrich bids with first party data for contextuality
Loading