mirror of
https://github.com/walkxcode/dashboard-icons.git
synced 2025-11-19 10:07:29 +01:00
refactor(analytics): improve PostHog integration
- Update PostHog utilities and provider configuration - Enhance analytics tracking setup
This commit is contained in:
@@ -15,7 +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',
|
person_profiles: "identified_only",
|
||||||
loaded(posthogInstance) {
|
loaded(posthogInstance) {
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
window.posthog = posthogInstance
|
window.posthog = posthogInstance
|
||||||
|
|||||||
@@ -3,17 +3,17 @@ import { pb } from "./pb"
|
|||||||
/**
|
/**
|
||||||
* Identifies a user in PostHog with their PocketBase user data
|
* Identifies a user in PostHog with their PocketBase user data
|
||||||
* Follows PostHog best practices for user identification
|
* Follows PostHog best practices for user identification
|
||||||
*
|
*
|
||||||
* @param posthog - PostHog instance
|
* @param posthog - PostHog instance
|
||||||
* @param user - PocketBase user model (optional, will use current auth if not provided)
|
* @param user - PocketBase user model (optional, will use current auth if not provided)
|
||||||
*/
|
*/
|
||||||
export function identifyUserInPostHog(posthog: any, user?: any) {
|
export function identifyUserInPostHog(posthog: any, user?: any) {
|
||||||
if (!posthog) return
|
if (!posthog) return
|
||||||
|
|
||||||
const userData = user || pb.authStore.model
|
const userData = user || pb.authStore.model
|
||||||
|
|
||||||
if (!userData) return
|
if (!userData) return
|
||||||
|
|
||||||
// Use PocketBase user ID as distinct_id (unique string)
|
// Use PocketBase user ID as distinct_id (unique string)
|
||||||
// Pass all available person properties for complete profile
|
// Pass all available person properties for complete profile
|
||||||
posthog.identify(userData.id, {
|
posthog.identify(userData.id, {
|
||||||
@@ -33,12 +33,12 @@ export function identifyUserInPostHog(posthog: any, user?: any) {
|
|||||||
/**
|
/**
|
||||||
* Resets PostHog identity (should be called on logout)
|
* Resets PostHog identity (should be called on logout)
|
||||||
* This unlinks future events from the user
|
* This unlinks future events from the user
|
||||||
*
|
*
|
||||||
* @param posthog - PostHog instance
|
* @param posthog - PostHog instance
|
||||||
*/
|
*/
|
||||||
export function resetPostHogIdentity(posthog: any) {
|
export function resetPostHogIdentity(posthog: any) {
|
||||||
if (!posthog) return
|
if (!posthog) return
|
||||||
|
|
||||||
// Reset PostHog identity to unlink future events from this user
|
// Reset PostHog identity to unlink future events from this user
|
||||||
// This is important for shared computers and follows PostHog best practices
|
// This is important for shared computers and follows PostHog best practices
|
||||||
posthog.reset()
|
posthog.reset()
|
||||||
|
|||||||
Reference in New Issue
Block a user