Skip to content

Commit

Permalink
code refactor and update dist files
Browse files Browse the repository at this point in the history
  • Loading branch information
prabrishac committed Jan 28, 2021
1 parent 259b2b1 commit da7d7fa
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 476 deletions.
20 changes: 9 additions & 11 deletions analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,25 +1080,22 @@ class Analytics {
}
}

function pushQueryStringDataToAnalyticsArray(argumentsArray, obj) {
if (!argumentsArray) {
argumentsArray = [];
}
function pushQueryStringDataToAnalyticsArray(obj) {
if (obj.anonymousId) {
if (obj.userId) {
argumentsArray.unshift(
instance.toBeProcessedArray.push(
["setAnonymousId", obj.anonymousId],
["identify", obj.userId, obj.traits]
);
} else {
argumentsArray.unshift(["setAnonymousId", obj.anonymousId]);
instance.toBeProcessedArray.push(["setAnonymousId", obj.anonymousId]);
}
} else if (obj.userId) {
argumentsArray.unshift(["identify", obj.userId, obj.traits]);
instance.toBeProcessedArray.push(["identify", obj.userId, obj.traits]);
}

if (obj.event) {
argumentsArray.push(["track", obj.event, obj.properties]);
instance.toBeProcessedArray.push(["track", obj.event, obj.properties]);
}
}

Expand Down Expand Up @@ -1161,13 +1158,14 @@ if (
// once loaded, parse querystring of the page url to send events
const parsedQueryObject = instance.parseQueryString(window.location.search);

pushQueryStringDataToAnalyticsArray(argumentsArray, parsedQueryObject);
pushQueryStringDataToAnalyticsArray(parsedQueryObject);

if (eventsPushedAlready && argumentsArray && argumentsArray.length > 0) {
if (argumentsArray && argumentsArray.length > 0) {
for (let i = 0; i < argumentsArray.length; i++) {
instance.toBeProcessedArray.push(argumentsArray[i]);
}

}
if(eventsPushedAlready){
processDataInAnalyticsArray(instance);
}
// }
Expand Down
Loading

0 comments on commit da7d7fa

Please sign in to comment.