Skip to content

Commit

Permalink
Akamai RTD Module: Fixed randomly failing test cases and updated the …
Browse files Browse the repository at this point in the history
…variable names (prebid#8487)

* Fixed the randomly failing test cases and updated the variable names

* Improving code quality
  • Loading branch information
visrivastava authored and renebaudisch committed Jun 28, 2022
1 parent fd160a4 commit 56aacaa
Show file tree
Hide file tree
Showing 4 changed files with 148 additions and 94 deletions.
4 changes: 2 additions & 2 deletions integrationExamples/gpt/akamaidap_segments_example.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
domain: "prebid.org",
identityType: "dap-signature:1.3.0",
segtax: 504,
dapFpUrl: 'https://dap-dist.akamaized.net/dapfingerprinting.js',
dapFpTimeout: 1500
dapEntropyUrl: 'https://dap-dist.akamaized.net/dapentropy.js',
dapEntropyTimeout: 1500
}
}
]
Expand Down
62 changes: 31 additions & 31 deletions modules/akamaiDapRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export function addRealTimeData(rtd) {
export function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) {
let entropyDict = JSON.parse(storage.getDataFromLocalStorage(DAP_CLIENT_ENTROPY));
let loadScriptPromise = new Promise((resolve, reject) => {
if (rtdConfig && rtdConfig.params && rtdConfig.params.dapFpTimeout && Number.isInteger(rtdConfig.params.dapFpTimeout)) {
setTimeout(reject, rtdConfig.params.dapFpTimeout, Error('DapFP script could not be loaded'));
if (rtdConfig && rtdConfig.params && rtdConfig.params.dapEntropyTimeout && Number.isInteger(rtdConfig.params.dapEntropyTimeout)) {
setTimeout(reject, rtdConfig.params.dapEntropyTimeout, Error('DapEntropy script could not be loaded'));
}
if (entropyDict && entropyDict.expires_at > Math.round(Date.now() / 1000.0)) {
logMessage('Using cached entropy');
Expand All @@ -79,10 +79,10 @@ export function getRealTimeData(bidConfig, onDone, rtdConfig, userConsent) {
if (typeof window.dapCalculateEntropy === 'function') {
window.dapCalculateEntropy(resolve, reject);
} else {
if (rtdConfig && rtdConfig.params && dapUtils.isValidHttpsUrl(rtdConfig.params.dapFpUrl)) {
loadExternalScript(rtdConfig.params.dapFpUrl, MODULE_CODE, () => { dapUtils.dapGetEntropy(resolve, reject) });
if (rtdConfig && rtdConfig.params && dapUtils.isValidHttpsUrl(rtdConfig.params.dapEntropyUrl)) {
loadExternalScript(rtdConfig.params.dapEntropyUrl, MODULE_CODE, () => { dapUtils.dapGetEntropy(resolve, reject) });
} else {
reject(Error('Please check if dapFpUrl is specified and is valid under config.params'));
reject(Error('Please check if dapEntropyUrl is specified and is valid under config.params'));
}
}
}
Expand Down Expand Up @@ -124,32 +124,7 @@ export function generateRealTimeData(bidConfig, onDone, rtdConfig, userConsent)
}
}
// Calling setTimeout to release the main thread so that the bid request could be sent.
setTimeout(callDapAPIs, 0, bidConfig, onDone, rtdConfig, userConsent);
}

function callDapAPIs(bidConfig, onDone, rtdConfig, userConsent) {
if (rtdConfig && isPlainObject(rtdConfig.params)) {
let config = {
api_hostname: rtdConfig.params.apiHostname,
api_version: rtdConfig.params.apiVersion,
domain: rtdConfig.params.domain,
segtax: rtdConfig.params.segtax,
identity: {type: rtdConfig.params.identityType}
};
let refreshMembership = true;
let token = dapUtils.dapGetTokenFromLocalStorage();
logMessage('token is: ', token);
if (token !== null) { // If token is not null then check the membership in storage and add the RTD object
if (config.segtax == 504) { // Follow the encrypted membership path
dapUtils.dapRefreshEncryptedMembership(config, token, onDone) // Get the encrypted membership from server
refreshMembership = false;
} else {
dapUtils.dapRefreshMembership(config, token, onDone) // Get the membership from server
refreshMembership = false;
}
}
dapUtils.dapRefreshToken(config, refreshMembership, onDone) // Refresh Token and membership in all the cases
}
setTimeout(dapUtils.callDapAPIs, 0, bidConfig, onDone, rtdConfig, userConsent);
}

/**
Expand All @@ -174,6 +149,31 @@ export const akamaiDapRtdSubmodule = {

submodule(MODULE_NAME, akamaiDapRtdSubmodule);
export const dapUtils = {

callDapAPIs: function(bidConfig, onDone, rtdConfig, userConsent) {
if (rtdConfig && isPlainObject(rtdConfig.params)) {
let config = {
api_hostname: rtdConfig.params.apiHostname,
api_version: rtdConfig.params.apiVersion,
domain: rtdConfig.params.domain,
segtax: rtdConfig.params.segtax,
identity: {type: rtdConfig.params.identityType}
};
let refreshMembership = true;
let token = dapUtils.dapGetTokenFromLocalStorage();
logMessage('token is: ', token);
if (token !== null) { // If token is not null then check the membership in storage and add the RTD object
if (config.segtax == 504) { // Follow the encrypted membership path
dapUtils.dapRefreshEncryptedMembership(config, token, onDone) // Get the encrypted membership from server
refreshMembership = false;
} else {
dapUtils.dapRefreshMembership(config, token, onDone) // Get the membership from server
refreshMembership = false;
}
}
dapUtils.dapRefreshToken(config, refreshMembership, onDone) // Refresh Token and membership in all the cases
}
},
dapGetEntropy: function(resolve, reject) {
if (typeof window.dapCalculateEntropy === 'function') {
window.dapCalculateEntropy(resolve, reject);
Expand Down
4 changes: 2 additions & 2 deletions modules/akamaiDapRtdProvider.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
domain: 'your-domain.com',
identityType: 'email' | 'mobile' | ... | 'dap-signature:1.3.0',
segtax: 504,
dapFpUrl: 'https://dap-dist.akamaized.net/dapfingerprinting.js',
dapFpTimeout: 1500 // Maximum time for dapFP to run
dapEntropyUrl: 'https://dap-dist.akamaized.net/dapentropy.js',
dapEntropyTimeout: 1500 // Maximum time for dapentropy to run
}
}
]
Expand Down
Loading

0 comments on commit 56aacaa

Please sign in to comment.