1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00
budibase/packages/backend-core/src/events/processors/PosthogProcessor.ts

29 lines
737 B
TypeScript
Raw Normal View History

2022-05-05 19:32:14 +12:00
import PostHog from "posthog-node"
import { Event } from "@budibase/types"
import { EventProcessor } from "./types"
import { getTenantId } from "../../context"
2022-05-05 19:32:14 +12:00
export default class PosthogProcessor implements EventProcessor {
2022-05-05 19:32:14 +12:00
posthog: PostHog
constructor(token: string | undefined) {
if (!token) {
throw new Error("Posthog token is not defined")
}
this.posthog = new PostHog(token)
}
processEvent(event: Event, properties: any): void {
const userId = getTenantId() // TODO
this.posthog.capture({ distinctId: userId, event, properties })
2022-05-05 19:32:14 +12:00
}
identify(distinctId: string, properties: any) {
this.posthog.identify({ distinctId, properties })
2022-05-05 19:32:14 +12:00
}
shutdown() {
this.posthog.shutdown()
}
}