feat: update posthog configuration

This commit is contained in:
Ho Duc Hieu 2023-12-29 20:41:25 +07:00
parent 19f583c079
commit 234aa68cb9

View File

@ -1,15 +1,37 @@
import posthog, { Properties } from 'posthog-js' import posthog, { Properties } from 'posthog-js'
// Initialize PostHog
posthog.init(ANALYTICS_ID, { posthog.init(ANALYTICS_ID, {
api_host: ANALYTICS_HOST, api_host: ANALYTICS_HOST,
autocapture: false, autocapture: false,
capture_pageview: false,
capture_pageleave: false,
rageclick: false,
}) })
// Export the PostHog instance
export const instance = posthog export const instance = posthog
// eslint-disable-next-line @typescript-eslint/no-explicit-any // Enum for Analytics Events
export const trackEvent = (name: string, properties?: Properties) => { export enum AnalyticsEvent {
posthog.capture(name, properties) Ping = 'Ping',
} }
export enum AnalyticsEvent {} // Function to determine the operating system
function getOperatingSystem(): string {
if (isMac) return 'MacOS'
if (isWindows) return 'Windows'
if (isLinux) return 'Linux'
return 'Unknown'
}
// Function to capture app version and operating system
function captureAppVersionAndOS() {
const properties: Properties = {
JanVersion: VERSION,
userOperatingSystem: getOperatingSystem(),
}
posthog.capture(AnalyticsEvent.Ping, properties)
}
// Example usage
captureAppVersionAndOS()