From a587ed7dcd2f688b474855e6b0f9a68bd2fa92a0 Mon Sep 17 00:00:00 2001 From: Moumita Mandal Date: Wed, 15 Dec 2021 18:34:49 +0530 Subject: [PATCH 1/3] writekey added in source config API --- analytics.js | 3 ++- utils/utils.js | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/analytics.js b/analytics.js index 2b14bdec50..a420c9c7c6 100644 --- a/analytics.js +++ b/analytics.js @@ -27,6 +27,7 @@ import { getReferrer, getReferringDomain, removeTrailingSlashes, + getConfigUrlWithWritekey, } from "./utils/utils"; import { CONFIG_URL, @@ -963,7 +964,7 @@ class Analytics { return; } - let configUrl = CONFIG_URL; + let configUrl = getConfigUrlWithWritekey(writeKey); if (options && options.configUrl) { configUrl = getUserProvidedConfigUrl(options.configUrl); } diff --git a/utils/utils.js b/utils/utils.js index 4e7f7202f7..bbfd469f67 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -630,6 +630,14 @@ const getDataFromSource = (src, dest, properties) => { return data; }; +const getConfigUrlWithWritekey = (writeKey) => { + if (writeKey) { + return `https://api.rudderlabs.com/sourceConfig/?p=process.module_type${writeKey}&v=process.package_version`; + } else { + return CONFIG_URL; + } +}; + export { replacer, generateUUID, @@ -656,4 +664,5 @@ export { isDefinedAndNotNull, getDataFromSource, removeTrailingSlashes, + getConfigUrlWithWritekey, }; From 45cd86cafa807f60b5c28a96fb591ec0ff356844 Mon Sep 17 00:00:00 2001 From: Moumita Mandal Date: Wed, 15 Dec 2021 19:23:56 +0530 Subject: [PATCH 2/3] getConfigUrlWithWritekey updated --- utils/utils.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/utils/utils.js b/utils/utils.js index bbfd469f67..191d7277d6 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -631,11 +631,9 @@ const getDataFromSource = (src, dest, properties) => { }; const getConfigUrlWithWritekey = (writeKey) => { - if (writeKey) { - return `https://api.rudderlabs.com/sourceConfig/?p=process.module_type${writeKey}&v=process.package_version`; - } else { - return CONFIG_URL; - } + return CONFIG_URL.concat(CONFIG_URL.includes("?") ? "&" : "?").concat( + writeKey ? `writeKey=${writeKey}` : "" + ); }; export { From dbc187901b3e467f043b4942a579a86eff72be43 Mon Sep 17 00:00:00 2001 From: saikumarrs Date: Sun, 26 Dec 2021 16:12:32 +0530 Subject: [PATCH 3/3] Minor code refactoring and user config url bug resolved --- analytics.js | 7 +++---- utils/utils.js | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/analytics.js b/analytics.js index a420c9c7c6..185102342e 100644 --- a/analytics.js +++ b/analytics.js @@ -27,10 +27,9 @@ import { getReferrer, getReferringDomain, removeTrailingSlashes, - getConfigUrlWithWritekey, + getConfigUrl, } from "./utils/utils"; import { - CONFIG_URL, MAX_WAIT_FOR_INTEGRATION_LOAD, INTEGRATION_LOAD_CHECK_INTERVAL, DEST_SDK_BASE_URL, @@ -964,9 +963,9 @@ class Analytics { return; } - let configUrl = getConfigUrlWithWritekey(writeKey); + let configUrl = getConfigUrl(writeKey); if (options && options.configUrl) { - configUrl = getUserProvidedConfigUrl(options.configUrl); + configUrl = getUserProvidedConfigUrl(options.configUrl, configUrl); } try { diff --git a/utils/utils.js b/utils/utils.js index 191d7277d6..e4d3dcd4ec 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -406,13 +406,13 @@ function type(val) { return typeof val; } -function getUserProvidedConfigUrl(configUrl) { +function getUserProvidedConfigUrl(configUrl, defConfigUrl) { let url = configUrl; if (url.indexOf("sourceConfig") === -1) { url = `${removeTrailingSlashes(url)}/sourceConfig/`; } url = url.slice(-1) === "/" ? url : `${url}/`; - const defQueryParams = CONFIG_URL.split("?")[1]; + const defQueryParams = defConfigUrl.split("?")[1]; const urlSplitItems = url.split("?"); if (urlSplitItems.length > 1 && urlSplitItems[1] !== defQueryParams) { url = `${urlSplitItems[0]}?${defQueryParams}`; @@ -630,7 +630,7 @@ const getDataFromSource = (src, dest, properties) => { return data; }; -const getConfigUrlWithWritekey = (writeKey) => { +const getConfigUrl = (writeKey) => { return CONFIG_URL.concat(CONFIG_URL.includes("?") ? "&" : "?").concat( writeKey ? `writeKey=${writeKey}` : "" ); @@ -662,5 +662,5 @@ export { isDefinedAndNotNull, getDataFromSource, removeTrailingSlashes, - getConfigUrlWithWritekey, + getConfigUrl, };