Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT] 유저 이탈 시 백엔드에 로그 보내기 #26

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Logger.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SetLocalStorage } from './SetLocalStorage';
import { SetLocalStorage, SetLocalStorageClear } from './SetLocalStorage';
import { LogPayloadParams, ServiceNameType } from './types/LogType';
import CryptoJS from 'crypto-js';

Expand Down Expand Up @@ -89,3 +89,12 @@ export const Logger = ({ userId, serviceName, name, message, path, tags }: LogPa
},
};
};
window.addEventListener('beforeunload', async (event) => {
nijuy marked this conversation as resolved.
Show resolved Hide resolved
// 명세에 따라 preventDefault는 호출해야하며, 기본 동작을 방지합니다.
event.preventDefault();
console.log('이탈감지');
const logList: any[] = JSON.parse(localStorage.getItem('yls-web') as string) || [];
console.log(logList);
// const res = await postLog();
SetLocalStorageClear();
});
2 changes: 1 addition & 1 deletion src/SetLocalStorage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { postLog } from './apis/postLog';
import { LogType } from './types/LogType';

const SetLocalStorageClear = () => {
export const SetLocalStorageClear = () => {
const list: any[] = [];
localStorage.setItem('yls-web', JSON.stringify(list));
};
Expand Down