feat(analytics): add clickhouse (#11174)
This commit is contained in:
@ -1,14 +1,11 @@
|
||||
import { useCallback } from 'react';
|
||||
import { v4 } from 'uuid';
|
||||
import { useTrackMutation } from '~/generated/graphql';
|
||||
export interface EventData {
|
||||
pathname: string;
|
||||
userAgent: string;
|
||||
timeZone: string;
|
||||
locale: string;
|
||||
href: string;
|
||||
referrer: string;
|
||||
}
|
||||
import {
|
||||
AnalyticsType,
|
||||
MutationTrackAnalyticsArgs,
|
||||
useTrackAnalyticsMutation,
|
||||
} from '~/generated/graphql';
|
||||
|
||||
export const ANALYTICS_COOKIE_NAME = 'analyticsCookie';
|
||||
export const getSessionId = (): string => {
|
||||
const cookie: { [key: string]: string } = {};
|
||||
@ -28,16 +25,22 @@ export const setSessionId = (domain?: string): void => {
|
||||
};
|
||||
|
||||
export const useEventTracker = () => {
|
||||
const [createEventMutation] = useTrackMutation();
|
||||
const [createEventMutation] = useTrackAnalyticsMutation();
|
||||
|
||||
return useCallback(
|
||||
(eventAction: string, eventPayload: EventData) => {
|
||||
(
|
||||
type: AnalyticsType,
|
||||
payload: Omit<MutationTrackAnalyticsArgs, 'type'>,
|
||||
) => {
|
||||
createEventMutation({
|
||||
variables: {
|
||||
action: eventAction,
|
||||
payload: {
|
||||
sessionId: getSessionId(),
|
||||
...eventPayload,
|
||||
type,
|
||||
...payload,
|
||||
properties: {
|
||||
...payload.properties,
|
||||
...(type === AnalyticsType['PAGEVIEW']
|
||||
? { sessionId: getSessionId() }
|
||||
: {}),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user