-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Posthog is an analytics tool that will allow us to run A/B tests in product in a simple manner. The advantage vs LaunchDarkly is that they provide features for experimenting, setting goals, create funnels, etc. Thanks to their UI, we can define experiments and monitor which variant is the winner. Posthog will do all the maths for us. More info: https://posthog.com/product/experimentation-suite This addition needs to be approved by @timroes after a security audit has been performed. This PR sets all the code needed in case the audit is succesful
- Loading branch information
1 parent
7ab162a
commit 5cf55ae
Showing
7 changed files
with
111 additions
and
10 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
38 changes: 38 additions & 0 deletions
38
airbyte-webapp/src/hooks/services/PostHogExperiment/PostHogExperimentService.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,38 @@ | ||
import posthog, { PostHog } from "posthog-js"; | ||
import { useContext, useEffect } from "react"; | ||
import React from "react"; | ||
|
||
import { useConfig } from "config"; | ||
|
||
interface Context { | ||
posthog: PostHog; | ||
featureFlagsVariants?: Record<string, boolean | string>; | ||
} | ||
const postHogServiceContext = React.createContext<Context | null>(null); | ||
const PostHogServiceProvider = postHogServiceContext.Provider; | ||
|
||
export const PostHogProvider = ({ children }: { children: React.ReactNode }) => { | ||
const { postHog: posthogKey } = useConfig(); | ||
|
||
useEffect(() => { | ||
if (posthogKey) { | ||
posthog.init(posthogKey, { api_host: "https://app.posthog.com" }); | ||
} | ||
}, []); | ||
|
||
if (posthogKey) { | ||
return <PostHogServiceProvider value={{ posthog }}>{children}</PostHogServiceProvider>; | ||
} | ||
|
||
return <>{children}</>; | ||
}; | ||
|
||
export const usePostHog = () => { | ||
const posthogContext = useContext(postHogServiceContext); | ||
|
||
if (!posthogContext) { | ||
throw new Error("posthogContext must be used within a PostHogProvider."); | ||
} | ||
|
||
return posthogContext; | ||
}; |
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