diff --git a/packages/common/components/src/api/connection-log.ts b/packages/common/components/src/api/connection-log.ts new file mode 100644 index 000000000..b421b7cb3 --- /dev/null +++ b/packages/common/components/src/api/connection-log.ts @@ -0,0 +1,34 @@ +import { ENDPOINT } from "../config"; +import { getApiClient } from "./client"; + +export interface ConnectionLog { + cntnSn: number; + cntnDt: string; + cntnId: string; + cntnIp: string; + cntnRgn: string; + wbsrKnd: string; + menuCd: number; + siteId: string; + urlPath: string; +} + +export interface ConnectionLogPayload { + cntnId?: string; + cntnIp?: string; + cntnRgn?: string; + wbsrKnd?: string; + menuCd?: number | null; + siteId?: string; + urlPath: string; +} + +const client = getApiClient(); + +export const saveConnectionLog = async (payload: ConnectionLogPayload) => { + const response = await client.post( + `${ENDPOINT.CMS_SERVICE.CONNECTION_LOG}`, + payload, + ); + return response.data; +}; diff --git a/packages/common/components/src/api/index.ts b/packages/common/components/src/api/index.ts index 10d68732c..d569765c2 100644 --- a/packages/common/components/src/api/index.ts +++ b/packages/common/components/src/api/index.ts @@ -1,4 +1,5 @@ export * from "./client"; +export * from "./connection-log"; export * from "./menu"; export * from "./popup"; export * from "./site"; diff --git a/packages/common/components/src/config/api.ts b/packages/common/components/src/config/api.ts index 6772182fb..a12ff5887 100644 --- a/packages/common/components/src/config/api.ts +++ b/packages/common/components/src/config/api.ts @@ -6,6 +6,7 @@ export const ENDPOINT = { SITES: "/cms-service/api/v1/sites", POPUPS: "/cms-service/api/v1/popups", IPS: "/cms-service/api/v1/site-ips", + CONNECTION_LOG: "/cms-service/api/v1/cntnlog", }, USER_SERVICE: { USERS: "/user-service/api/v1/users", diff --git a/packages/common/components/src/ui/lnb/index.tsx b/packages/common/components/src/ui/lnb/index.tsx index dee4356f6..8e3c2aebf 100644 --- a/packages/common/components/src/ui/lnb/index.tsx +++ b/packages/common/components/src/ui/lnb/index.tsx @@ -3,6 +3,7 @@ import { useState, useEffect, useRef } from "react"; import { useQuery } from "@tanstack/react-query"; import { ChevronRight } from "lucide-react"; +import { useDetectDevice } from "@frontend-opensource/use-react-hooks"; import { getConfig } from "@common/config"; import { getParentIds } from "./lib"; import { @@ -24,9 +25,10 @@ import { import { ENDPOINT } from "../../config"; import { cn, getCookie, setCookie } from "../../lib"; import { - getAnonymouseMenuList, getMenuList, getPreviewTreeMenuList, + getAnonymouseMenuList, + saveConnectionLog, type MenuItem, } from "../../api"; @@ -55,6 +57,7 @@ export function LNB({ const [defaultOpenMenuIds, setDefaultOpenMenuIds] = useState([]); const [currentMenuCode, setCurrentMenuCode] = useState(null); const prevPathRef = useRef(currentPath); + const { browser } = useDetectDevice(); const siteId = propSiteId ?? appSiteId; @@ -125,6 +128,16 @@ export function LNB({ } if (matchedMenuCode) setCurrentMenuCode(matchedMenuCode); + + // 접속 로그 저장 + saveConnectionLog({ + cntnId: userId, + cntnRgn: navigator.language, + wbsrKnd: browser, + menuCd: matchedMenuCode, + siteId, + urlPath: currentPath, + }); }, [menuList, currentPath]); function MenuItem({