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

Optimera RTD Module : adding apiVersion param and v1 endpoint #10476

Merged
merged 1 commit into from
Sep 13, 2023
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
26 changes: 24 additions & 2 deletions modules/optimeraRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* @property {string} clientID
* @property {string} optimeraKeyName
* @property {string} device
* @property {string} apiVersion
*/

import { logInfo, logError } from '../src/utils.js';
Expand All @@ -38,7 +39,10 @@ export let optimeraKeyName = 'hb_deal_optimera';
* the targeting values.
* @type {string}
*/
export const scoresBaseURL = 'https://dyv1bugovvq1g.cloudfront.net/';
export const scoresBaseURL = {
v0: 'https://dyv1bugovvq1g.cloudfront.net/',
v1: 'https://v1.oapi26b.com/',
};

/**
* Optimera Score File URL.
Expand All @@ -58,6 +62,12 @@ export let clientID;
*/
export let device = 'default';

/**
* Optional apiVersion parameter.
* @type {string}
*/
export let apiVersion = 'v0';

/**
* Targeting object for all ad positions.
* @type {string}
Expand Down Expand Up @@ -127,6 +137,7 @@ export function onAuctionInit(auctionDetails, config, userConsent) {

/**
* Initialize the Module.
* moduleConfig.params.apiVersion can be either v0 or v1.
*/
export function init(moduleConfig) {
_moduleParams = moduleConfig.params;
Expand All @@ -138,6 +149,9 @@ export function init(moduleConfig) {
if (_moduleParams.device) {
device = _moduleParams.device;
}
if (_moduleParams.apiVersion) {
apiVersion = (_moduleParams.apiVersion.includes('v1', 'v0')) ? _moduleParams.apiVersion : 'v0';
}
setScoresURL();
scoreFileRequest();
return true;
Expand All @@ -162,7 +176,15 @@ export function init(moduleConfig) {
export function setScoresURL() {
const optimeraHost = window.location.host;
const optimeraPathName = window.location.pathname;
const newScoresURL = `${scoresBaseURL}${clientID}/${optimeraHost}${optimeraPathName}.js`;
const baseUrl = scoresBaseURL[apiVersion] ? scoresBaseURL[apiVersion] : scoresBaseURL.v0;
let newScoresURL;

if (apiVersion === 'v1') {
newScoresURL = `${baseUrl}api/products/scores?c=${clientID}&h=${optimeraHost}&p=${optimeraPathName}&s=${device}`;
} else {
newScoresURL = `${baseUrl}${clientID}/${optimeraHost}${optimeraPathName}.js`;
}

if (scoresURL !== newScoresURL) {
scoresURL = newScoresURL;
fetchScoreFile = true;
Expand Down
6 changes: 4 additions & 2 deletions modules/optimeraRtdProvider.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Overview
```
Module Name: Optimera Real Time Date Module
Module Name: Optimera Real Time Data Module
Module Type: RTD Module
Maintainer: [email protected]
```
Expand All @@ -26,7 +26,8 @@ Configuration example for using RTD module with `optimera` provider
params: {
clientID: '9999',
optimeraKeyName: 'optimera',
device: 'de'
device: 'de',
apiVersion: 'v0',
}
}
]
Expand All @@ -42,3 +43,4 @@ Contact Optimera to get assistance with the params.
| clientID | string | required | Optimera Client ID |
| optimeraKeyName | string | optional | GAM key name for Optimera. If migrating from the Optimera bidder adapter this will default to hb_deal_optimera and can be ommitted from the configuration. |
| device | string | optional | Device type code for mobile, tablet, or desktop. Either mo, tb, de |
| apiVersion | string | optional | Optimera API Versions. Either v0, or v1. ** Note: v1 wll need to be enabled specifically for your account, otherwise use v0.
71 changes: 69 additions & 2 deletions test/spec/modules/optimeraRtdProvider_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,80 @@ describe('Optimera RTD sub module', () => {
});
});

describe('Optimera RTD score file url is properly set', () => {
it('Proerly set the score file url', () => {
describe('Optimera RTD score file URL is properly set for v0', () => {
it('should properly set the score file URL', () => {
const conf = {
dataProviders: [{
name: 'optimeraRTD',
params: {
clientID: '9999',
optimeraKeyName: 'optimera',
device: 'de',
apiVersion: 'v0',
}
}]
};
optimeraRTD.init(conf.dataProviders[0]);
optimeraRTD.setScores();
expect(optimeraRTD.apiVersion).to.equal('v0');
expect(optimeraRTD.scoresURL).to.equal('https://dyv1bugovvq1g.cloudfront.net/9999/localhost:9876/context.html.js');
});

it('should properly set the score file URL without apiVersion set', () => {
const conf = {
dataProviders: [{
name: 'optimeraRTD',
params: {
clientID: '9999',
optimeraKeyName: 'optimera',
device: 'de',
}
}]
};
optimeraRTD.init(conf.dataProviders[0]);
optimeraRTD.setScores();
expect(optimeraRTD.apiVersion).to.equal('v0');
expect(optimeraRTD.scoresURL).to.equal('https://dyv1bugovvq1g.cloudfront.net/9999/localhost:9876/context.html.js');
});

it('should properly set the score file URL with an api version other than v0 or v1', () => {
const conf = {
dataProviders: [{
name: 'optimeraRTD',
params: {
clientID: '9999',
optimeraKeyName: 'optimera',
device: 'de',
apiVersion: 'v15',
}
}]
};
optimeraRTD.init(conf.dataProviders[0]);
optimeraRTD.setScores();
expect(optimeraRTD.scoresURL).to.equal('https://dyv1bugovvq1g.cloudfront.net/9999/localhost:9876/context.html.js');
});
});

describe('Optimera RTD score file URL is properly set for v1', () => {
it('should properly set the score file URL', () => {
const conf = {
dataProviders: [{
name: 'optimeraRTD',
params: {
clientID: '9999',
optimeraKeyName: 'optimera',
device: 'de',
apiVersion: 'v1',
}
}]
};
optimeraRTD.init(conf.dataProviders[0]);
optimeraRTD.setScores();
expect(optimeraRTD.apiVersion).to.equal('v1');
expect(optimeraRTD.scoresURL).to.equal('https://v1.oapi26b.com/api/products/scores?c=9999&h=localhost:9876&p=/context.html&s=de');
});
});

describe('Optimera RTD score file properly sets targeting values', () => {
const scores = {
'div-0': ['A1', 'A2'],
Expand Down