1
0
mirror of https://github.com/upscayl/upscayl.git synced 2025-02-15 02:12:34 +01:00
upscayl/renderer/components/posthog-provider-wrapper.tsx
2024-12-16 16:18:57 +05:30

50 lines
1.5 KiB
TypeScript

import { enableContributionAtom } from "@/atoms/user-settings-atom";
import { useAtomValue } from "jotai";
import posthog from "posthog-js";
import { PostHogProvider } from "posthog-js/react";
import { useEffect } from "react";
const PostHogProviderWrapper = ({
children,
}: {
children: React.ReactNode;
}) => {
const enableContribution = useAtomValue(enableContributionAtom);
useEffect(() => {
posthog.init("phc_QMcmlmComdofjfaRPzoN4KV9ziV2KgOwAOVyu4J3dIc", {
api_host: "https://us.i.posthog.com",
person_profiles: "identified_only",
autocapture: false,
capture_pageview: false,
capture_pageleave: false,
disable_session_recording: true,
loaded: async (posthog) => {
if (process.env.NODE_ENV === "development") posthog.debug();
const systemInfo = await window.electron.getSystemInfo();
const appVersion = await window.electron.getAppVersion();
// Set super properties that will be included with all events
posthog.register({
...systemInfo,
appVersion,
$ip: "0.0.0.0",
$geoip_disable: true,
});
// Capture initial session start
posthog.capture("app_launched", {
...systemInfo,
appVersion,
$ip: "0.0.0.0",
$geoip_disable: true,
});
},
});
}, []);
if (!enableContribution) return <>{children}</>;
return <PostHogProvider client={posthog}>{children}</PostHogProvider>;
};
export default PostHogProviderWrapper;