Skip to content

Commit 6562cef

Browse files
committed
hotfix: 트랙 강제 수정
1 parent 8e29eb5 commit 6562cef

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/utils/trackUtil.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,25 @@ type VisitDataType = {
88
unloadDate?: string;
99
};
1010

11-
type MessageType = '01' | '02' | '03' | '04' | '99';
12-
13-
export const trackUserEvent = (event_type: MessageType) => {
14-
const { pathname: path } = window.location;
15-
instance('/event', { body: { path, event_type }, method: 'POST' });
11+
export const MessageEnum = {
12+
LOGIN: '11',
13+
NAVIGATE: '12',
14+
LOGOUT: '13',
15+
SECTION_INTERACT_MAIN: '21',
16+
SORT_INTERACT_MAIN: '22',
17+
REFRESH_INTERACT_MAIN: '23',
18+
SORT_INTERACT_BOARD: '31',
19+
UNKNOWON: '99',
20+
} as const;
21+
const EVENT_LOG = process.env.NEXT_PUBLIC_EVENT_LOG;
22+
if (EVENT_LOG === undefined) {
23+
throw new Error('EVENT_LOG가 ENV에서 설정되지 않았습니다.');
24+
}
25+
26+
export const trackUserEvent = (event_type: keyof typeof MessageEnum) => {
27+
if (EVENT_LOG === 'true') {
28+
instance('/event', { body: { eventType: event_type }, method: 'POST' });
29+
}
1630
};
1731

1832
export const TrackVisitEvent = () => {
@@ -22,22 +36,19 @@ export const TrackVisitEvent = () => {
2236
});
2337

2438
const setUnloadData = () => {
25-
data.current = {
26-
...data.current,
27-
unloadDate: new Date().toISOString(),
28-
};
39+
data.current = { ...data.current, unloadDate: new Date().toISOString() };
2940
instance('/stay', { body: data.current, method: 'POST', keepalive: true });
3041
};
3142

3243
useEffect(() => {
3344
// 페이지 로드 시 시간 기록
3445
data.current.loadDate = new Date().toISOString();
35-
if (process.env.NODE_ENV === 'production') {
46+
if (process.env.NODE_ENV === 'production' && EVENT_LOG === 'true') {
3647
window.addEventListener('unload', setUnloadData);
3748
}
3849

3950
return () => {
40-
if (process.env.NODE_ENV === 'production') {
51+
if (process.env.NODE_ENV === 'production' && EVENT_LOG === 'true') {
4152
window.removeEventListener('unload', setUnloadData);
4253
}
4354
};

0 commit comments

Comments
 (0)