Skip to content

Commit

Permalink
Merge pull request #14 from firecatapult/qxd-5006-remove-content-anal…
Browse files Browse the repository at this point in the history
…ysis

remove content analysis
  • Loading branch information
rrochwick authored Oct 22, 2024
2 parents efac0cb + ccb5bd7 commit c1264f7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 93 deletions.
71 changes: 7 additions & 64 deletions modules/qortexRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,10 @@ export function getContext () {
const callbacks = {
success(text, data) {
const responseStatus = data.status;
let result;
let result = null;
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);
},
Expand Down Expand Up @@ -142,34 +139,6 @@ export function getGroupConfig () {
})
}

/**
* Initiates page analysis from Qortex
* @returns {Promise}
*/
export function initiatePageAnalysis () {
qortexSessionInfo.indexData = generateIndexData();
logMessage('Sending page data for context analysis');
return new Promise((resolve, reject) => {
const callbacks = {
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(e, x) {
reject(new Error(x.status));
}
}
ajax(qortexSessionInfo.pageAnalyisUrl, callbacks, JSON.stringify(qortexSessionInfo.indexData), {contentType: 'application/json'})
})
}

/**
* Sends analytics events to Qortex
* @returns {Promise}
Expand Down Expand Up @@ -231,6 +200,7 @@ export function generateAnalyticsHostUrl(qortexUrlBase) {
/**
* Updates bidder configs with the response from Qortex context services
* @param {Object} reqBidsConfig Bid request configuration object
* @param {string[]} bidders Bidders specified in module's configuration
*/
export function addContextToRequests (reqBidsConfig) {
if (qortexSessionInfo.currentSiteContext === null) {
Expand Down Expand Up @@ -303,22 +273,12 @@ export function initializeBidEnrichment() {
logWarn('Contexual record is not yet complete at this time')
}
})
.catch(e => {
.catch((e) => {
const errorStatus = e.message;
logWarn('Returned error status code: ' + errorStatus);
if (errorStatus == 404) {
initiatePageAnalysis()
.then(message => {
logMessage(message)
})
.catch(e => {
logWarn(e);
})
}
});
logWarn('Returned error status code: ' + errorStatus)
})
}
}

/**
* Helper function to set initial values when they are obtained by init
* @param {Object} config module config obtained during init
Expand All @@ -332,16 +292,13 @@ export function initializeModuleData(config) {
qortexSessionInfo.impressionIds = new Set();
qortexSessionInfo.currentSiteContext = null;
qortexSessionInfo.pageAnalysisData = {
analysisInProgress: false,
indexRequested: false,
contextRetrieved: false,
contextAdded: {}
};
qortexSessionInfo.sessionId = generateSessionId();
qortexSessionInfo.groupId = groupId;
qortexSessionInfo.groupConfigUrl = `${qortexUrlBase}/api/v1/prebid/group/configs/${groupId}/${windowUrl}`
qortexSessionInfo.contextUrl = `${qortexUrlBase}/api/v1/prebid/${groupId}/page/lookup`
qortexSessionInfo.pageAnalyisUrl = `${qortexUrlBase}/api/v1/prebid/${groupId}/page/index`;
qortexSessionInfo.groupConfigUrl = `${qortexUrlBase}/api/v1/prebid/group/configs/${groupId}/${windowUrl}`;
qortexSessionInfo.contextUrl = `${qortexUrlBase}/api/v1/prebid/${groupId}/page/lookup`;
qortexSessionInfo.analyticsUrl = generateAnalyticsHostUrl(qortexUrlBase);
return qortexSessionInfo;
}
Expand All @@ -360,20 +317,6 @@ export function setGroupConfigData(value) {
qortexSessionInfo.groupConfig = value
}

/**
* Creates page index data for Qortex analysis
* @returns {Object} page index object
*/
function generateIndexData () {
return {
pageUrl: document.location.href,
title: document.title,
text: Array.from(document.body.querySelectorAll('h1,h2,h3,h4,h5,h6,p')).reduce((acc, elm) => acc.concat(elm.textContent.trim()), []).join(' ').replaceAll(/\r?\n\s{2,}/gi, ' ').substr(0, 5000),
meta: Array.from(document.getElementsByTagName('meta')).reduce((acc, curr) => { const attr = curr.attributes; if (attr.length > 1) { acc[curr.attributes[0].value] = curr.attributes[1].value } return acc }, {}),
videos: Array.from(document.getElementsByTagName('video')).reduce((acc, curr) => { const src = curr?.src; if (src != '') { acc.push(src) } return acc }, [])
}
}

function generateSessionId() {
const randomInt = window.crypto.getRandomValues(new Uint32Array(1));
const currentDateTime = Math.floor(Date.now() / 1000);
Expand Down
4 changes: 2 additions & 2 deletions modules/qortexRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Maintainer: mannese@qortex.ai

The Qortex RTD module appends contextual segments to the bidding object based on the content of a page using the Qortex API.

If the `Qortex Group Id` and module parameters provided during configuration is active and enabled for bid enrichment, the Qortex context API will analyze the bidder page and will return a [Content object](https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-API-Specification-Version-2-5-FINAL.pdf#page=26). The module will then merge that object into the appropriate bidders' `ortb2.site.content`, which can be used by prebid adapters that use `site.content` data.
If the `Qortex Group Id` and module parameters provided during configuration is active, the Qortex context API will attempt to generate and return a [Content object](https://www.iab.com/wp-content/uploads/2016/03/OpenRTB-API-Specification-Version-2-5-FINAL.pdf#page=26) using indexed data from provided page content. The module will then merge that object into the appropriate bidders' `ortb2.site.content`, which can be used by prebid adapters that use `site.content` data.


## Build
Expand Down Expand Up @@ -70,4 +70,4 @@ pbjs.setConfig({
- 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.

#### `enableBidEnrichment` - optional
- This optional parameter allows a publisher to opt-in to the features of the RTD module that use our API to enrich bids with first party data for contextuality. Enabling this feature will allow this module to collect and send the contextual components of the page (meta, video, header, and paragraph tags) to our AI contextuality server for indexing and analysis. Please use caution when adding this module to pages that may contain personal user data or proprietary information.
- This optional parameter allows a publisher to opt-in to the features of the RTD module that use our API to enrich bids with first party data for contextuality. Enabling this feature will allow this module to interact with the Qortex AI contextuality server for indexing and analysis. Please use caution when adding this module to pages that may contain personal user data or proprietary information.
28 changes: 1 addition & 27 deletions test/spec/modules/qortexRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,33 +548,7 @@ describe('qortexRtdProvider', () => {
}, 250)
})

it('logs page analysis response information if initiated', (done) => {
initializeBidEnrichment();
server.requests[0].respond(404, responseHeaders, JSON.stringify({}));
setTimeout(() => {
server.requests[1].respond(201, responseHeaders, JSON.stringify({}));
setTimeout(() => {
expect(logMessageSpy.calledWith('Sending page data for context analysis')).to.be.true;
expect(logMessageSpy.calledWith('Successfully initiated Qortex page analysis')).to.be.true;
done();
}, 400)
}, 250)
})

it('logs page analysis response information if applicable', (done) => {
initializeBidEnrichment();
server.requests[0].respond(404, responseHeaders, JSON.stringify({}));
setTimeout(() => {
server.requests[1].respond(201, responseHeaders, JSON.stringify({}));
setTimeout(() => {
expect(logMessageSpy.calledWith('Sending page data for context analysis')).to.be.true;
expect(logMessageSpy.calledWith('Successfully initiated Qortex page analysis')).to.be.true;
done();
}, 400)
}, 250)
})

it('logs page analysis response if no record is made', (done) => {
it('logs warning if no record has been made', (done) => {
initializeBidEnrichment();
server.requests[0].respond(202, responseHeaders, JSON.stringify({}));
setTimeout(() => {
Expand Down

0 comments on commit c1264f7

Please sign in to comment.