-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #409 from gitroomhq/feat/posthog
Add posthog analytics
- Loading branch information
Showing
5 changed files
with
73 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,19 @@ | ||
import { usePlausible } from 'next-plausible'; | ||
import { useCallback } from 'react'; | ||
import { useVariables } from '@gitroom/react/helpers/variable.context'; | ||
import { usePostHog } from 'posthog-js/react'; | ||
|
||
export const useFireEvents = () => { | ||
const { billingEnabled } = useVariables(); | ||
const plausible = usePlausible(); | ||
const posthog = usePostHog(); | ||
|
||
return useCallback((name: string, props?: any) => { | ||
if (!billingEnabled) { | ||
return; | ||
} | ||
|
||
posthog.capture(name, props); | ||
plausible(name, { props }); | ||
}, []); | ||
}; |
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,28 @@ | ||
'use client'; | ||
|
||
import posthog from 'posthog-js'; | ||
import { PostHogProvider } from 'posthog-js/react'; | ||
import { FC, ReactNode, useEffect } from 'react'; | ||
|
||
export const PHProvider: FC<{ | ||
children: ReactNode; | ||
key?: string; | ||
host?: string; | ||
}> = ({ children, key, host }) => { | ||
useEffect(() => { | ||
if (!key || !host) { | ||
return; | ||
} | ||
|
||
posthog.init(key, { | ||
api_host: host, | ||
person_profiles: 'identified_only', | ||
capture_pageview: false, // Disable automatic pageview capture, as we capture manually | ||
}); | ||
}, []); | ||
|
||
if (!key || !host) { | ||
return <>{children}</>; | ||
} | ||
return <PostHogProvider client={posthog}>{children}</PostHogProvider>; | ||
}; |
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