✨(frontend) add capture method support to PostHogAnalytics wrapper
Implement capture method in PostHogAnalytics wrapper to support direct event tracking through PostHog SDK. Enables more granular analytics event handling within the application's analytics abstraction layer.
This commit is contained in:
@@ -9,7 +9,15 @@ type AnalyticEventUser = {
|
||||
email: string;
|
||||
};
|
||||
|
||||
export type AnalyticEvent = AnalyticEventClick | AnalyticEventUser;
|
||||
export type AnalyticEventGeneric = {
|
||||
eventName: string;
|
||||
[key: string]: string | number;
|
||||
};
|
||||
|
||||
export type AnalyticEvent =
|
||||
| AnalyticEventClick
|
||||
| AnalyticEventUser
|
||||
| AnalyticEventGeneric;
|
||||
|
||||
export abstract class AbstractAnalytic {
|
||||
public constructor() {
|
||||
|
||||
@@ -3,7 +3,7 @@ import posthog from 'posthog-js';
|
||||
import { PostHogProvider as PHProvider } from 'posthog-js/react';
|
||||
import { JSX, PropsWithChildren, ReactNode, useEffect } from 'react';
|
||||
|
||||
import { AbstractAnalytic, AnalyticEvent } from '@/libs/';
|
||||
import { AbstractAnalytic, AnalyticEvent, AnalyticEventGeneric } from '@/libs/';
|
||||
|
||||
export class PostHogAnalytic extends AbstractAnalytic {
|
||||
private conf?: PostHogConf = undefined;
|
||||
@@ -19,8 +19,14 @@ export class PostHogAnalytic extends AbstractAnalytic {
|
||||
}
|
||||
|
||||
public trackEvent(evt: AnalyticEvent): void {
|
||||
if (evt.eventName === 'user') {
|
||||
posthog.identify(evt.id, { email: evt.email });
|
||||
switch (evt.eventName) {
|
||||
case 'user':
|
||||
posthog.identify(evt.id as string, { email: evt.email });
|
||||
break;
|
||||
default:
|
||||
const { eventName, ...properties } = evt as AnalyticEventGeneric;
|
||||
posthog.capture(eventName, properties);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user