-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
chore: Analytics util refactor #38089
Merged
Merged
Changes from 29 commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
fe09402
chore: Make segment singleton
hetunandu 8d28d95
fix: type error
hetunandu c193689
Merge branch 'release' into chore/analytics-util-refactor
hetunandu 3795506
chore: correct split for logEvent
hetunandu e9090d2
Merge branch 'release' into chore/analytics-util-refactor
hetunandu d62d1c1
chore: correct split for identifyUser
hetunandu c7b34a6
fix type error
hetunandu 8f6216d
chore: remove zipy
hetunandu 0dc6a20
chore: Other changes to separate concerns
hetunandu a5fe8de
Merge branch 'release' into chore/analytics-util-refactor
hetunandu 9a59649
fix: user source getter
hetunandu 11034ef
Merge branch 'release' into chore/analytics-util-refactor
hetunandu 0ef89c7
fix: TrackedUser error handling
hetunandu 7009e5d
chore: Mask all mixpanel recordings
hetunandu be6a625
chore: Mixpanel should not record admin settings
hetunandu 713cf05
chore: Improve segment anonymousId get
hetunandu 74a1ddd
chore: AnalyticsUtil.tsx improvements
hetunandu a383ef3
remove other ee concerns from ce
hetunandu e3f8768
chore: null checks
hetunandu 61986b2
Revert "chore: AnalyticsUtil.tsx improvements"
hetunandu 08a0d40
chore: Fix Smartlook init
hetunandu 864a829
Merge branch 'release' into chore/analytics-util-refactor
hetunandu caca6fd
chore: convert class into object
hetunandu 6cd44a9
chore: export getEventExtraProperties
hetunandu cbbcc1a
verify theory
hetunandu 0bf6f87
chore: add cypress logging
hetunandu 1c1da03
chore: add back editor line
hetunandu 2549d3c
Revert "chore: add cypress logging"
hetunandu a9c3d68
chore: segment init change
hetunandu 949076c
chore: Try toasts
hetunandu 250121f
avoid waiting for segment init
hetunandu de8acdd
Merge branch 'release' into chore/analytics-util-refactor
hetunandu 0730a4e
chore: Better splitting
hetunandu fb643f5
chore: check if its the state issue
hetunandu 719dd1e
Merge branch 'release' into chore/analytics-util-refactor
hetunandu 071b86b
fix: Type error from latest changes
hetunandu 414657d
Merge branch 'release' into chore/analytics-util-refactor
hetunandu 34a639a
fix: chore test another change
hetunandu a79138a
chore: Updte tracked user usage
hetunandu 25ac6ce
chore: Revert wait added in pull #19122
hetunandu aebbbd4
chore: Avoid adding more dependencies
hetunandu 87d3493
Merge branch 'release' into chore/analytics-util-refactor
hetunandu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
3 changes: 2 additions & 1 deletion
3
app/client/src/api/interceptors/request/addAnonymousUserIdHeader.ts
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
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
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
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 |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import { ANONYMOUS_USERNAME, type User } from "constants/userConstants"; | ||
import { getAppsmithConfigs } from "ee/configs"; | ||
import { sha256 } from "js-sha256"; | ||
|
||
interface TrackedUserProperties { | ||
userId: string; | ||
source: string; | ||
email?: string; | ||
name?: string; | ||
emailVerified?: boolean; | ||
} | ||
|
||
/** | ||
* Function to get the application id from the URL | ||
* @param location current location object based on URL | ||
* @returns application id | ||
*/ | ||
export function getApplicationId(location: Location) { | ||
const pathSplit = location.pathname.split("/"); | ||
const applicationsIndex = pathSplit.findIndex( | ||
(path) => path === "applications", | ||
); | ||
|
||
if (applicationsIndex === -1 || applicationsIndex + 1 >= pathSplit.length) { | ||
return undefined; | ||
} | ||
|
||
return pathSplit[applicationsIndex + 1]; | ||
} | ||
|
||
class TrackedUser { | ||
private static instance: TrackedUser; | ||
private readonly user: User; | ||
private readonly userId: string; | ||
public readonly selfHosted: boolean; | ||
|
||
protected constructor(user: User) { | ||
this.user = user; | ||
const { cloudHosting, segment } = getAppsmithConfigs(); | ||
|
||
this.selfHosted = !(segment.apiKey || cloudHosting); | ||
|
||
if (this.selfHosted) { | ||
this.userId = sha256(user.username); | ||
} else { | ||
this.userId = user.username; | ||
} | ||
} | ||
|
||
static init(user: User) { | ||
if (!TrackedUser.instance) { | ||
TrackedUser.instance = new TrackedUser(user); | ||
} | ||
} | ||
|
||
static getInstance(): TrackedUser { | ||
if (!TrackedUser.instance) { | ||
throw new Error("TrackedUser is not initialized. Call init() first."); | ||
} | ||
|
||
return TrackedUser.instance; | ||
} | ||
|
||
protected getUserSource(): string { | ||
return this.selfHosted ? "ce" : "cloud"; | ||
} | ||
|
||
public getUser(): TrackedUserProperties { | ||
if (this.selfHosted) { | ||
return this.getAnonymousUserDetails(); | ||
} else { | ||
return this.getAllUserDetails(); | ||
} | ||
} | ||
|
||
public getEventUserProperties() { | ||
const { email, userId } = this.getUser(); | ||
|
||
if (this.userId === ANONYMOUS_USERNAME) { | ||
return undefined; | ||
} | ||
|
||
const appId = getApplicationId(window.location); | ||
|
||
return { | ||
userId, | ||
email, | ||
appId: this.selfHosted ? undefined : appId, | ||
}; | ||
} | ||
|
||
private getAllUserDetails() { | ||
const { email, emailVerified, name } = this.user; | ||
const source = this.getUserSource(); | ||
ankitakinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return { | ||
userId: this.userId, | ||
source, | ||
email, | ||
name, | ||
emailVerified, | ||
}; | ||
} | ||
|
||
private getAnonymousUserDetails() { | ||
const source = this.getUserSource(); | ||
ankitakinger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return { | ||
userId: this.userId, | ||
source, | ||
}; | ||
} | ||
} | ||
|
||
export default TrackedUser; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically not a user property. But because till now we have been sending this data as part of the userData object, I am not separating them to avoid breaking any charts