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

Suffix added to identify individual integration scripts #377

Merged
merged 5 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
35 changes: 20 additions & 15 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
INTEGRATION_LOAD_CHECK_INTERVAL,
DEST_SDK_BASE_URL,
CDN_INT_DIR,
INTG_SUFFIX,
} from "./utils/constants";
import RudderElementBuilder from "./utils/RudderElementBuilder";
import Storage from "./utils/storage";
Expand Down Expand Up @@ -116,8 +117,9 @@ class Analytics {
if (
this.clientIntegrations.every(
(intg) =>
this.dynamicallyLoadedIntegrations[configToIntNames[intg.name]] !=
undefined
this.dynamicallyLoadedIntegrations[
`${configToIntNames[intg.name]}${INTG_SUFFIX}`
] != undefined
)
) {
// logger.debug(
Expand Down Expand Up @@ -177,38 +179,40 @@ class Analytics {
// Load all the client integrations dynamically
this.clientIntegrations.forEach((intg) => {
const modName = configToIntNames[intg.name];
const scriptName = `${modName}${INTG_SUFFIX}`;
if (process.browser) {
const modURL = `${this.destSDKBaseURL}/${modName}.min.js`;
if (!window.hasOwnProperty(modName)) {
ScriptLoader(modName, modURL);
if (!window.hasOwnProperty(scriptName)) {
ScriptLoader(scriptName, modURL);
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
}

const self = this;
const interval = setInterval(function () {
if (window.hasOwnProperty(modName)) {
const intMod = window[modName];
if (window.hasOwnProperty(scriptName)) {
const intMod = window[scriptName];
clearInterval(interval);

// logger.debug(modName, " dynamically loaded integration SDK")
// logger.debug(scriptName, " dynamically loaded integration SDK")

let intgInstance;
try {
// logger.debug(
// modName,
// scriptName,
// " [Analytics] processResponse :: trying to initialize integration ::"
// );
intgInstance = new intMod[modName](intg.config, self);
intgInstance = new intMod[scriptName](intg.config, self);
intgInstance.init();

// logger.debug(modName, " initializing destination")
// logger.debug(scriptName, " initializing destination")

self.isInitialized(intgInstance).then(() => {
// logger.debug(modName, " module init sequence complete")
self.dynamicallyLoadedIntegrations[modName] = intMod[modName];
// logger.debug(scriptName, " module init sequence complete")
self.dynamicallyLoadedIntegrations[scriptName] =
intMod[scriptName];
});
} catch (e) {
logger.error(
modName,
scriptName,
" [Analytics] initialize integration (integration.init()) failed",
e
);
Expand All @@ -230,8 +234,9 @@ class Analytics {
// remove from the list which don't have support yet in SDK
self.clientIntegrations = self.clientIntegrations.filter((intg) => {
return (
self.dynamicallyLoadedIntegrations[configToIntNames[intg.name]] !=
undefined
self.dynamicallyLoadedIntegrations[
`${configToIntNames[intg.name]}${INTG_SUFFIX}`
] != undefined
);
});

Expand Down
2 changes: 1 addition & 1 deletion rollup.intgConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ if (process.env.NPM === "true") {
outputFiles.push({
file: distFileName,
format: "iife",
name: `${process.env.INTG_NAME}`,
name: `${process.env.INTG_NAME}_RS`,
saikumarrs marked this conversation as resolved.
Show resolved Hide resolved
sourcemap:
process.env.PROD_DEBUG_INLINE === "true"
? "inline"
Expand Down
3 changes: 2 additions & 1 deletion utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const DEST_SDK_BASE_URL = `https://cdn.rudderlabs.com/v1.1/${CDN_INT_DIR}`;

const MAX_WAIT_FOR_INTEGRATION_LOAD = 10000;
const INTEGRATION_LOAD_CHECK_INTERVAL = 1000;

const INTG_SUFFIX = "_RS";
export {
ReservedPropertyKeywords,
ECommerceParamNames,
Expand All @@ -82,6 +82,7 @@ export {
DEST_SDK_BASE_URL,
MAX_WAIT_FOR_INTEGRATION_LOAD,
INTEGRATION_LOAD_CHECK_INTERVAL,
INTG_SUFFIX,
};
/* module.exports = {
MessageType: MessageType,
Expand Down