-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
fix: provide worspaceId to AnalyticsInitializer #7642
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2dc5e66
fix: provide worspaceId to AnalyticsInitializer
isalikov 9a3e4bf
fix: customerIdProvider
isalikov b8698df
fix: AppServicesProvider.tsx
isalikov f649b9e
feat: update AppServicesProvider
isalikov c20999c
Merge branch 'master' of github.com:airbytehq/airbyte into 7596/Rewor…
isalikov 610d072
feat: added default context to AnalyticsServiceProvider
isalikov 1158da9
fix: WithAnalyticsContext
isalikov 9e28fd8
fix: added customerId
isalikov 8bc0cdf
fix: customerId useEffect deps
isalikov f3172fd
Merge branch 'master' into 7596/Rework-Webapp-segment-tracking
jamakase a80a8c3
Refactor Analytics for more independent approach
jamakase a2ff169
Speed up initial load for cloud webapp
jamakase 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
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
19 changes: 19 additions & 0 deletions
19
airbyte-webapp/src/hooks/services/Analytics/TrackPageAnalytics.tsx
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,19 @@ | ||
import React, { useEffect } from "react"; | ||
|
||
import useRouter from "hooks/useRouter"; | ||
|
||
import { useAnalyticsService } from "./useAnalyticsService"; | ||
import { getPageName } from "./pageNameUtils"; | ||
|
||
export const TrackPageAnalytics: React.FC = () => { | ||
const { pathname } = useRouter(); | ||
const analyticsService = useAnalyticsService(); | ||
useEffect(() => { | ||
const pageName = getPageName(pathname); | ||
if (pageName) { | ||
analyticsService.page(pageName); | ||
} | ||
}, [analyticsService, pathname]); | ||
|
||
return null; | ||
}; |
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,2 @@ | ||
export * from "./TrackPageAnalytics"; | ||
export * from "./useAnalyticsService"; |
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
101 changes: 101 additions & 0 deletions
101
airbyte-webapp/src/hooks/services/Analytics/useAnalyticsService.tsx
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,101 @@ | ||
import React, { useContext, useEffect, useMemo } from "react"; | ||
import { useMap } from "react-use"; | ||
|
||
import { AnalyticsService } from "core/analytics/AnalyticsService"; | ||
|
||
type AnalyticsContext = Record<string, unknown>; | ||
|
||
export type AnalyticsServiceProviderValue = { | ||
analyticsContext: AnalyticsContext; | ||
setContext: (ctx: AnalyticsContext) => void; | ||
addContextProps: (props: AnalyticsContext) => void; | ||
removeContextProps: (props: string[]) => void; | ||
service: AnalyticsService; | ||
}; | ||
|
||
const analyticsServiceContext = React.createContext<AnalyticsServiceProviderValue | null>( | ||
null | ||
); | ||
|
||
function AnalyticsServiceProvider({ | ||
children, | ||
version, | ||
initialContext = {}, | ||
}: { | ||
children: React.ReactNode; | ||
version?: string; | ||
initialContext?: AnalyticsContext; | ||
}) { | ||
const [analyticsContext, { set, setAll, remove }] = useMap(initialContext); | ||
|
||
const analyticsService: AnalyticsService = useMemo( | ||
() => new AnalyticsService(analyticsContext, version), | ||
[version, analyticsContext] | ||
); | ||
|
||
const handleAddContextProps = (props: AnalyticsContext) => { | ||
Object.entries(props).forEach((value) => set(...value)); | ||
}; | ||
|
||
const handleRemoveContextProps = (props: string[]) => props.forEach(remove); | ||
|
||
return ( | ||
<analyticsServiceContext.Provider | ||
value={{ | ||
analyticsContext, | ||
setContext: setAll, | ||
addContextProps: handleAddContextProps, | ||
removeContextProps: handleRemoveContextProps, | ||
service: analyticsService, | ||
}} | ||
> | ||
{children} | ||
</analyticsServiceContext.Provider> | ||
); | ||
} | ||
|
||
export const useAnalyticsService = (): AnalyticsService => { | ||
const analyticsService = useAnalytics(); | ||
|
||
return analyticsService.service; | ||
}; | ||
|
||
export const useAnalytics = (): AnalyticsServiceProviderValue => { | ||
const analyticsContext = useContext(analyticsServiceContext); | ||
|
||
if (!analyticsContext) { | ||
throw new Error( | ||
"analyticsContext must be used within a AnalyticsServiceProvider." | ||
); | ||
} | ||
|
||
return analyticsContext; | ||
}; | ||
|
||
export const useAnalyticsIdentifyUser = (userId?: string): void => { | ||
const analyticsService = useAnalyticsService(); | ||
|
||
useEffect(() => { | ||
if (userId) { | ||
analyticsService.identify(userId); | ||
} | ||
}, [userId]); | ||
}; | ||
|
||
export const useAnalyticsRegisterValues = ( | ||
props?: AnalyticsContext | null | ||
): void => { | ||
const { addContextProps, removeContextProps } = useAnalytics(); | ||
|
||
useEffect(() => { | ||
if (props) { | ||
addContextProps(props); | ||
|
||
return () => removeContextProps(Object.keys(props)); | ||
} | ||
|
||
return; | ||
}, [props]); | ||
}; | ||
|
||
export default React.memo(AnalyticsServiceProvider); |
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 |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import NotificationService from "./NotificationService"; | ||
import NotificationService, { | ||
useNotificationService, | ||
} from "./NotificationService"; | ||
|
||
export default NotificationService; | ||
export { NotificationService }; | ||
export { NotificationService, useNotificationService }; |
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
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
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.
I think something like
additionalContext
suits better.