Skip to content

Commit

Permalink
Contxtful RTD Module: added defer param (prebid#12499)
Browse files Browse the repository at this point in the history
* feat: defer param

* fix: added typecheck
  • Loading branch information
sebastienrufiange authored Nov 26, 2024
1 parent 8f0bb73 commit b319bcc
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions modules/contxtfulRtdProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import { MODULE_TYPE_RTD } from '../src/activities/modules.js';
const MODULE_NAME = 'contxtful';
const MODULE = `${MODULE_NAME}RtdProvider`;

const CONTXTFUL_RECEPTIVITY_DOMAIN = 'api.receptivity.io';
const CONTXTFUL_HOSTNAME_DEFAULT = 'api.receptivity.io';
const CONTXTFUL_DEFER_DEFAULT = 0;

const storageManager = getStorageManager({
moduleType: MODULE_TYPE_RTD,
Expand Down Expand Up @@ -128,9 +129,10 @@ export function extractParameters(config) {
throw Error(`${MODULE}: params.customer should be a non-empty string`);
}

const hostname = config?.params?.hostname || CONTXTFUL_RECEPTIVITY_DOMAIN;
const hostname = config?.params?.hostname || CONTXTFUL_HOSTNAME_DEFAULT;
const defer = config?.params?.defer || CONTXTFUL_DEFER_DEFAULT;

return { version, customer, hostname };
return { version, customer, hostname, defer };
}

/**
Expand All @@ -139,15 +141,22 @@ export function extractParameters(config) {
* @param { String } config
*/
function initCustomer(config) {
const { version, customer, hostname } = extractParameters(config);
const { version, customer, hostname, defer } = extractParameters(config);
const CONNECTOR_URL = buildUrl({
protocol: 'https',
host: hostname,
pathname: `/${version}/prebid/${customer}/connector/rxConnector.js`,
});

addConnectorEventListener(customer, config);
loadExternalScript(CONNECTOR_URL, MODULE_TYPE_RTD, MODULE_NAME);

const loadScript = () => loadExternalScript(CONNECTOR_URL, MODULE_TYPE_RTD, MODULE_NAME);
// Optionally defer the loading of the script
if (Number.isFinite(defer) && defer > 0) {
setTimeout(loadScript, defer);
} else {
loadScript();
}
}

/**
Expand Down

0 comments on commit b319bcc

Please sign in to comment.