-
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
cc1f5bc
commit 66132f8
Showing
1 changed file
with
34 additions
and
35 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 |
---|---|---|
|
@@ -29,7 +29,7 @@ import { | |
import { | ||
CONFIG_URL, | ||
MAX_WAIT_FOR_INTEGRATION_LOAD, | ||
INTEGRATION_LOAD_CHECK_INTERVAL, | ||
INTEGRATION_LOAD_CHECK_INTERVAL | ||
} from "./utils/constants"; | ||
import { integrations } from "./integrations"; | ||
import RudderElementBuilder from "./utils/RudderElementBuilder"; | ||
|
@@ -42,7 +42,7 @@ import parseLinker from "./utils/linker"; | |
|
||
const queryDefaults = { | ||
trait: "ajs_trait_", | ||
prop: "ajs_prop_", | ||
prop: "ajs_prop_" | ||
}; | ||
|
||
// https://unpkg.com/[email protected]/dist/browser.js | ||
|
@@ -90,7 +90,7 @@ class Analytics { | |
this.readyCallback = () => {}; | ||
this.executeReadyCallback = undefined; | ||
this.methodToCallbackMapping = { | ||
syncPixel: "syncPixelCallback", | ||
syncPixel: "syncPixelCallback" | ||
}; | ||
this.loaded = false; | ||
} | ||
|
@@ -152,7 +152,7 @@ class Analytics { | |
if (destination.enabled) { | ||
this.clientIntegrations.push({ | ||
name: destination.destinationDefinition.name, | ||
config: destination.config, | ||
config: destination.config | ||
}); | ||
} | ||
}, this); | ||
|
@@ -165,7 +165,7 @@ class Analytics { | |
); | ||
|
||
// remove from the list which don't have support yet in SDK | ||
this.clientIntegrations = this.clientIntegrations.filter((intg) => { | ||
this.clientIntegrations = this.clientIntegrations.filter(intg => { | ||
return integrations[intg.name] != undefined; | ||
}); | ||
|
||
|
@@ -204,8 +204,7 @@ class Analytics { | |
this.toBeProcessedByIntegrationArray = []; | ||
return; | ||
} | ||
|
||
intgArray.forEach((intg) => { | ||
intgArray.forEach(intg => { | ||
try { | ||
logger.debug( | ||
"[Analytics] init :: trying to initialize integration name:: ", | ||
|
@@ -233,7 +232,8 @@ class Analytics { | |
if ( | ||
object.successfullyLoadedIntegration.length + | ||
object.failedToBeLoadedIntegration.length === | ||
object.clientIntegrations.length && !object.areEventsReplayed | ||
object.clientIntegrations.length && | ||
!object.areEventsReplayed | ||
) { | ||
logger.debug( | ||
"===replay events called====", | ||
|
@@ -257,7 +257,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); | ||
|
@@ -267,7 +267,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(); | ||
|
||
|
@@ -316,19 +316,19 @@ class Analytics { | |
} | ||
}); | ||
object.toBeProcessedByIntegrationArray = []; | ||
object.areEventsReplayed = true; | ||
} | ||
object.areEventsReplayed = true; | ||
} | ||
} | ||
|
||
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); | ||
|
@@ -585,7 +585,7 @@ class Analytics { | |
rudderElement.message.context.traits | ||
) { | ||
this.userTraits = { | ||
...rudderElement.message.context.traits, | ||
...rudderElement.message.context.traits | ||
}; | ||
this.storage.setUserTraits(this.userTraits); | ||
} | ||
|
@@ -648,7 +648,7 @@ class Analytics { | |
// rudderElement.message.context.page = getDefaultPageProperties(); | ||
|
||
rudderElement.message.context.traits = { | ||
...this.userTraits, | ||
...this.userTraits | ||
}; | ||
|
||
logger.debug("anonymousId: ", this.anonymousId); | ||
|
@@ -663,7 +663,7 @@ class Analytics { | |
} | ||
if (this.groupTraits) { | ||
rudderElement.message.traits = { | ||
...this.groupTraits, | ||
...this.groupTraits | ||
}; | ||
} | ||
} | ||
|
@@ -691,7 +691,7 @@ class Analytics { | |
|
||
// 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); | ||
|
@@ -764,18 +764,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( | ||
|
@@ -886,7 +886,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"); | ||
} | ||
|
@@ -911,7 +911,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[ | ||
|
@@ -985,7 +985,7 @@ class Analytics { | |
} | ||
|
||
initializeCallbacks() { | ||
Object.keys(this.methodToCallbackMapping).forEach((methodName) => { | ||
Object.keys(this.methodToCallbackMapping).forEach(methodName => { | ||
if (this.methodToCallbackMapping.hasOwnProperty(methodName)) { | ||
this.on(methodName, () => {}); | ||
} | ||
|
@@ -994,7 +994,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 ( | ||
|
@@ -1023,7 +1023,7 @@ class Analytics { | |
}); | ||
} | ||
|
||
Object.keys(this.clientSuppliedCallbacks).forEach((methodName) => { | ||
Object.keys(this.clientSuppliedCallbacks).forEach(methodName => { | ||
if (this.clientSuppliedCallbacks.hasOwnProperty(methodName)) { | ||
logger.debug( | ||
"registerCallbacks", | ||
|
@@ -1049,7 +1049,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]; | ||
} | ||
|
@@ -1060,7 +1060,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]; | ||
} | ||
|
@@ -1090,7 +1090,7 @@ class Analytics { | |
} | ||
|
||
function pushQueryStringDataToAnalyticsArray(argumentsArray, obj) { | ||
if(!argumentsArray){ | ||
if (!argumentsArray) { | ||
argumentsArray = []; | ||
} | ||
if (obj.anonymousId) { | ||
|
@@ -1111,16 +1111,16 @@ function pushQueryStringDataToAnalyticsArray(argumentsArray, obj) { | |
} | ||
} | ||
|
||
function processDataInAnalyticsArray(analytics){ | ||
if(instance.loaded){ | ||
function processDataInAnalyticsArray(analytics) { | ||
if (instance.loaded) { | ||
for (let i = 0; i < analytics.toBeProcessedArray.length; i++) { | ||
const event = [...analytics.toBeProcessedArray[i]]; | ||
const method = event[0]; | ||
event.shift(); | ||
logger.debug("=====from analytics array, calling method:: ", method); | ||
analytics[method](...event); | ||
} | ||
|
||
instance.toBeProcessedArray = []; | ||
} | ||
} | ||
|
@@ -1131,7 +1131,7 @@ Emitter(instance); | |
|
||
window.addEventListener( | ||
"error", | ||
(e) => { | ||
e => { | ||
handleError(e, instance); | ||
}, | ||
true | ||
|
@@ -1173,12 +1173,11 @@ const parsedQueryObject = instance.parseQueryString(window.location.search); | |
pushQueryStringDataToAnalyticsArray(argumentsArray, parsedQueryObject); | ||
|
||
if (eventsPushedAlready && argumentsArray && argumentsArray.length > 0) { | ||
for (let i = 0; i < argumentsArray.length; i++) { | ||
for (let i = 0; i < argumentsArray.length; i++) { | ||
instance.toBeProcessedArray.push(argumentsArray[i]); | ||
} | ||
|
||
processDataInAnalyticsArray(instance); | ||
|
||
} | ||
// } | ||
|
||
|
@@ -1205,5 +1204,5 @@ export { | |
alias, | ||
group, | ||
getAnonymousId, | ||
setAnonymousId, | ||
setAnonymousId | ||
}; |