Files
cal.diy/packages/features/ee/event-tracking/lib/posthog/provider.tsx
T
9048d053ac feat: posthog version upgrade and added trackings (#24401)
* posthog version upgrade and calai banner tracking

* disable posthog for EU

* bunch more posthog tracking

* Revert yarn.lock changes

* add posthog package yarn changes

* fix: add missing posthog import and fix lint warning in MemberInvitationModal

Co-Authored-By: [email protected] <[email protected]>

* fix: type check

* cubic fixes

* refactor

* remove ui playground

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2025-11-28 12:43:37 +00:00

41 lines
1.2 KiB
TypeScript

"use client";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import { useEffect, useRef } from "react";
import { useGeo } from "@calcom/web/app/GeoContext";
function Provider({ children }: { children: React.ReactNode }) {
const initializeOnce = useRef(false);
const { country } = useGeo();
useEffect(() => {
if (!process.env.NEXT_PUBLIC_POSTHOG_KEY || initializeOnce.current) return;
initializeOnce.current = true;
const isUS = country === "US";
posthog.init(process.env.NEXT_PUBLIC_POSTHOG_KEY, {
api_host: process.env.NEXT_PUBLIC_POSTHOG_HOST || "https://eu.i.posthog.com",
persistence: isUS ? "localStorage+cookie" : "memory",
autocapture: false,
person_profiles: "never",
request_batching: true,
capture_pageview: false,
capture_pageleave: false,
cookieless_mode: isUS ? undefined : "always",
disable_session_recording: true,
advanced_disable_flags: true,
loaded: (posthog) => {
if (process.env.NODE_ENV === "development") posthog.debug();
},
});
}, [country]);
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
}
export default Provider;