mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-10-27 13:39:03 +08:00
feat: integrate PostHog authentication handler
- Add PostHogAuthHandler component to PostHogProvider - Integrate usePostHogAuth hook for automatic user identification - Add person_profiles: 'identified_only' configuration - Enable automatic user identification on app load and auth changes
This commit is contained in:
@@ -4,6 +4,7 @@ import { usePathname, useSearchParams } from "next/navigation"
|
|||||||
import posthog from "posthog-js"
|
import posthog from "posthog-js"
|
||||||
import { PostHogProvider as PHProvider, usePostHog } from "posthog-js/react"
|
import { PostHogProvider as PHProvider, usePostHog } from "posthog-js/react"
|
||||||
import { Suspense, useEffect } from "react"
|
import { Suspense, useEffect } from "react"
|
||||||
|
import { usePostHogAuth } from "@/hooks/use-posthog-auth"
|
||||||
|
|
||||||
export function PostHogProvider({ children }: { children: React.ReactNode }) {
|
export function PostHogProvider({ children }: { children: React.ReactNode }) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -14,6 +15,7 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
|
|||||||
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || "https://eu.i.posthog.com",
|
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || "https://eu.i.posthog.com",
|
||||||
capture_pageview: false, // We capture pageviews manually
|
capture_pageview: false, // We capture pageviews manually
|
||||||
capture_pageleave: true, // Enable pageleave capture
|
capture_pageleave: true, // Enable pageleave capture
|
||||||
|
person_profiles: 'identified_only',
|
||||||
loaded(posthogInstance) {
|
loaded(posthogInstance) {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
window.posthog = posthogInstance
|
window.posthog = posthogInstance
|
||||||
@@ -23,12 +25,18 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<PHProvider client={posthog}>
|
<PHProvider client={posthog}>
|
||||||
|
<PostHogAuthHandler />
|
||||||
<SuspendedPostHogPageView />
|
<SuspendedPostHogPageView />
|
||||||
{children}
|
{children}
|
||||||
</PHProvider>
|
</PHProvider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function PostHogAuthHandler() {
|
||||||
|
usePostHogAuth()
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
function PostHogPageView() {
|
function PostHogPageView() {
|
||||||
const pathname = usePathname()
|
const pathname = usePathname()
|
||||||
const searchParams = useSearchParams()
|
const searchParams = useSearchParams()
|
||||||
|
|||||||
Reference in New Issue
Block a user