-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8afaa1a
commit 0737a02
Showing
1 changed file
with
38 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ import { | |
transformToServerNames, | ||
checkReservedKeywords, | ||
getReferrer, | ||
getReferringDomain | ||
getReferringDomain, | ||
} from "./utils/utils"; | ||
import { | ||
CONFIG_URL, | ||
|
@@ -45,7 +45,7 @@ import { configToIntNames } from "./config_to_integration_names.js"; | |
|
||
const queryDefaults = { | ||
trait: "ajs_trait_", | ||
prop: "ajs_prop_" | ||
prop: "ajs_prop_", | ||
}; | ||
|
||
// https://unpkg.com/[email protected]/dist/browser.js | ||
|
@@ -93,7 +93,7 @@ class Analytics { | |
this.readyCallback = () => {}; | ||
this.executeReadyCallback = undefined; | ||
this.methodToCallbackMapping = { | ||
syncPixel: "syncPixelCallback" | ||
syncPixel: "syncPixelCallback", | ||
}; | ||
this.loaded = false; | ||
this.loadIntegration = true; | ||
|
@@ -170,7 +170,6 @@ class Analytics { | |
}); | ||
} | ||
|
||
|
||
/** | ||
* Process the response from control plane and | ||
* call initialize for integrations | ||
|
@@ -200,7 +199,7 @@ class Analytics { | |
if (destination.enabled) { | ||
this.clientIntegrations.push({ | ||
name: destination.destinationDefinition.name, | ||
config: destination.config | ||
config: destination.config, | ||
}); | ||
} | ||
}, this); | ||
|
@@ -212,7 +211,7 @@ class Analytics { | |
this.loadOnlyIntegrations, | ||
this.clientIntegrations | ||
); | ||
|
||
logger.debug("this.clientIntegrations: ", this.clientIntegrations); | ||
// Load all the client integrations dynamically | ||
this.clientIntegrations.forEach((intg) => { | ||
|
@@ -276,7 +275,8 @@ class Analytics { | |
// remove from the list which don't have support yet in SDK | ||
object.clientIntegrations = object.clientIntegrations.filter((intg) => { | ||
return ( | ||
object.dynamicallyLoadedIntegrations[configToIntNames[intg.name]] != undefined | ||
object.dynamicallyLoadedIntegrations[configToIntNames[intg.name]] != | ||
undefined | ||
); | ||
}); | ||
const intgArray = object.clientIntegrations; | ||
|
@@ -356,7 +356,7 @@ class Analytics { | |
logger.debug("==registering ready callback==="); | ||
object.on("ready", object.executeReadyCallback); | ||
|
||
object.clientIntegrationObjects.forEach(intg => { | ||
object.clientIntegrationObjects.forEach((intg) => { | ||
logger.debug("===looping over each successful integration===="); | ||
if (!intg.isReady || intg.isReady()) { | ||
logger.debug("===letting know I am ready=====", intg.name); | ||
|
@@ -366,7 +366,7 @@ class Analytics { | |
|
||
if (object.toBeProcessedByIntegrationArray.length > 0) { | ||
// send the queued events to the fetched integration | ||
object.toBeProcessedByIntegrationArray.forEach(event => { | ||
object.toBeProcessedByIntegrationArray.forEach((event) => { | ||
const methodName = event[0]; | ||
event.shift(); | ||
|
||
|
@@ -380,10 +380,11 @@ class Analytics { | |
|
||
// get intersection between config plane native enabled destinations | ||
// (which were able to successfully load on the page) vs user supplied integrations | ||
const succesfulLoadedIntersectClientSuppliedIntegrations = findAllEnabledDestinations( | ||
clientSuppliedIntegrations, | ||
object.clientIntegrationObjects | ||
); | ||
const succesfulLoadedIntersectClientSuppliedIntegrations = | ||
findAllEnabledDestinations( | ||
clientSuppliedIntegrations, | ||
object.clientIntegrationObjects | ||
); | ||
|
||
// send to all integrations now from the 'toBeProcessedByIntegrationArray' replay queue | ||
for ( | ||
|
@@ -421,13 +422,13 @@ class Analytics { | |
} | ||
|
||
pause(time) { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
setTimeout(resolve, time); | ||
}); | ||
} | ||
|
||
isInitialized(instance, time = 0) { | ||
return new Promise(resolve => { | ||
return new Promise((resolve) => { | ||
if (instance.isLoaded()) { | ||
logger.debug("===integration loaded successfully====", instance.name); | ||
this.successfullyLoadedIntegration.push(instance); | ||
|
@@ -684,7 +685,7 @@ class Analytics { | |
rudderElement.message.context.traits | ||
) { | ||
this.userTraits = { | ||
...rudderElement.message.context.traits | ||
...rudderElement.message.context.traits, | ||
}; | ||
this.storage.setUserTraits(this.userTraits); | ||
} | ||
|
@@ -747,7 +748,7 @@ class Analytics { | |
// rudderElement.message.context.page = getDefaultPageProperties(); | ||
|
||
rudderElement.message.context.traits = { | ||
...this.userTraits | ||
...this.userTraits, | ||
}; | ||
|
||
logger.debug("anonymousId: ", this.anonymousId); | ||
|
@@ -762,7 +763,7 @@ class Analytics { | |
} | ||
if (this.groupTraits) { | ||
rudderElement.message.traits = { | ||
...this.groupTraits | ||
...this.groupTraits, | ||
}; | ||
} | ||
} | ||
|
@@ -783,14 +784,15 @@ class Analytics { | |
|
||
// get intersection between config plane native enabled destinations | ||
// (which were able to successfully load on the page) vs user supplied integrations | ||
const succesfulLoadedIntersectClientSuppliedIntegrations = findAllEnabledDestinations( | ||
clientSuppliedIntegrations, | ||
this.clientIntegrationObjects | ||
); | ||
const succesfulLoadedIntersectClientSuppliedIntegrations = | ||
findAllEnabledDestinations( | ||
clientSuppliedIntegrations, | ||
this.clientIntegrationObjects | ||
); | ||
|
||
// try to first send to all integrations, if list populated from BE | ||
try { | ||
succesfulLoadedIntersectClientSuppliedIntegrations.forEach(obj => { | ||
succesfulLoadedIntersectClientSuppliedIntegrations.forEach((obj) => { | ||
if (!obj.isFailed || !obj.isFailed()) { | ||
if (obj[type]) { | ||
obj[type](rudderElement); | ||
|
@@ -863,18 +865,18 @@ class Analytics { | |
const toplevelElements = [ | ||
"integrations", | ||
"anonymousId", | ||
"originalTimestamp" | ||
"originalTimestamp", | ||
]; | ||
for (const key in options) { | ||
if (toplevelElements.includes(key)) { | ||
rudderElement.message[key] = options[key]; | ||
} else if (key !== "context") { | ||
rudderElement.message.context = merge(rudderElement.message.context, { | ||
[key]: options[key] | ||
[key]: options[key], | ||
}); | ||
} else if (typeof options[key] === "object" && options[key] != null) { | ||
rudderElement.message.context = merge(rudderElement.message.context, { | ||
...options[key] | ||
...options[key], | ||
}); | ||
} else { | ||
logger.error( | ||
|
@@ -996,7 +998,7 @@ class Analytics { | |
if (!this.isValidWriteKey(writeKey) || !this.isValidServerUrl(serverUrl)) { | ||
handleError({ | ||
message: | ||
"[Analytics] load:: Unable to load due to wrong writeKey or serverUrl" | ||
"[Analytics] load:: Unable to load due to wrong writeKey or serverUrl", | ||
}); | ||
throw Error("failed to initialize"); | ||
} | ||
|
@@ -1024,7 +1026,7 @@ class Analytics { | |
if (options && options.clientSuppliedCallbacks) { | ||
// convert to rudder recognised method names | ||
const tranformedCallbackMapping = {}; | ||
Object.keys(this.methodToCallbackMapping).forEach(methodName => { | ||
Object.keys(this.methodToCallbackMapping).forEach((methodName) => { | ||
if (this.methodToCallbackMapping.hasOwnProperty(methodName)) { | ||
if ( | ||
options.clientSuppliedCallbacks[ | ||
|
@@ -1097,7 +1099,7 @@ class Analytics { | |
const res = options.getSourceConfig(); | ||
|
||
if (res instanceof Promise) { | ||
res.then(res => this.processResponse(200, res)).catch(errorHandler); | ||
res.then((res) => this.processResponse(200, res)).catch(errorHandler); | ||
} else { | ||
this.processResponse(200, res); | ||
} | ||
|
@@ -1125,7 +1127,7 @@ class Analytics { | |
} | ||
|
||
initializeCallbacks() { | ||
Object.keys(this.methodToCallbackMapping).forEach(methodName => { | ||
Object.keys(this.methodToCallbackMapping).forEach((methodName) => { | ||
if (this.methodToCallbackMapping.hasOwnProperty(methodName)) { | ||
this.on(methodName, () => {}); | ||
} | ||
|
@@ -1134,7 +1136,7 @@ class Analytics { | |
|
||
registerCallbacks(calledFromLoad) { | ||
if (!calledFromLoad) { | ||
Object.keys(this.methodToCallbackMapping).forEach(methodName => { | ||
Object.keys(this.methodToCallbackMapping).forEach((methodName) => { | ||
if (this.methodToCallbackMapping.hasOwnProperty(methodName)) { | ||
if (window.rudderanalytics) { | ||
if ( | ||
|
@@ -1163,7 +1165,7 @@ class Analytics { | |
}); | ||
} | ||
|
||
Object.keys(this.clientSuppliedCallbacks).forEach(methodName => { | ||
Object.keys(this.clientSuppliedCallbacks).forEach((methodName) => { | ||
if (this.clientSuppliedCallbacks.hasOwnProperty(methodName)) { | ||
logger.debug( | ||
"registerCallbacks", | ||
|
@@ -1189,7 +1191,7 @@ class Analytics { | |
parseQueryString(query) { | ||
function getTraitsFromQueryObject(qObj) { | ||
const traits = {}; | ||
Object.keys(qObj).forEach(key => { | ||
Object.keys(qObj).forEach((key) => { | ||
if (key.substr(0, queryDefaults.trait.length) == queryDefaults.trait) { | ||
traits[key.substr(queryDefaults.trait.length)] = qObj[key]; | ||
} | ||
|
@@ -1200,7 +1202,7 @@ class Analytics { | |
|
||
function getEventPropertiesFromQueryObject(qObj) { | ||
const props = {}; | ||
Object.keys(qObj).forEach(key => { | ||
Object.keys(qObj).forEach((key) => { | ||
if (key.substr(0, queryDefaults.prop.length) == queryDefaults.prop) { | ||
props[key.substr(queryDefaults.prop.length)] = qObj[key]; | ||
} | ||
|
@@ -1268,7 +1270,7 @@ Emitter(instance); | |
|
||
window.addEventListener( | ||
"error", | ||
e => { | ||
(e) => { | ||
handleError(e, instance); | ||
}, | ||
true | ||
|
@@ -1344,5 +1346,5 @@ export { | |
group, | ||
getUserTraits, | ||
getAnonymousId, | ||
setAnonymousId | ||
setAnonymousId, | ||
}; |