[feat] solution/backend,frontend,postgres-init: 서비스 사이트 공개 화면 방문 수집 — 전체 방문 통계에 합산하고 사이트 표에 한 줄로, 기능 문서 추가
This commit is contained in:
1 parent
2fc50de161
commit
99a344f65c
21 files changed
+378
-21
No files matched your search
@@ -443,6 +443,8 @@ export * from "./visitDeviceRow";
|
||||
export * from "./visitPathRow";
|
||||
export * from "./visitReferrerRow";
|
||||
export * from "./visitSiteRow";
|
||||
export * from "./visitSiteRowPlaceId";
|
||||
export * from "./visitSiteRowSiteId";
|
||||
export * from "./visitStatsParams";
|
||||
export * from "./visitSummary";
|
||||
export * from "./visitSummaryLastAt";
|
||||
|
||||
@@ -4,11 +4,14 @@
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
import type { VisitSiteRowSiteId } from "./visitSiteRowSiteId";
|
||||
import type { VisitSiteRowPlaceId } from "./visitSiteRowPlaceId";
|
||||
|
||||
export interface VisitSiteRow {
|
||||
site_id: string;
|
||||
place_id: string;
|
||||
site_id?: VisitSiteRowSiteId;
|
||||
place_id?: VisitSiteRowPlaceId;
|
||||
name: string;
|
||||
views: number;
|
||||
visitors: number;
|
||||
service?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type VisitSiteRowPlaceId = string | null;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Generated by orval v7.21.0 🍺
|
||||
* Do not edit manually.
|
||||
* Web4Ai API
|
||||
* OpenAPI spec version: 0.1.0
|
||||
*/
|
||||
|
||||
export type VisitSiteRowSiteId = string | null;
|
||||
@@ -19,7 +19,7 @@ export function OverallVisitStats() {
|
||||
return (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h2 className="text-sm font-semibold">방문 (전체 사이트)</h2>
|
||||
<h2 className="text-sm font-semibold">방문 (발행 사이트 + 서비스 사이트)</h2>
|
||||
<RangeTabs value={days} onChange={setDays} />
|
||||
</div>
|
||||
{isLoading && (
|
||||
|
||||
@@ -37,13 +37,21 @@ export function VisitStatsPanel({data, scope}: {data: ResVisitStats; scope: 'ove
|
||||
</Section>
|
||||
|
||||
{scope === 'overall' ? (
|
||||
<Section title="방문이 많은 사이트">
|
||||
<Section title="방문이 많은 사이트 (서비스 사이트 포함)">
|
||||
<Table
|
||||
head={['사이트', '페이지뷰', '방문자']}
|
||||
rows={(data.sites ?? []).map((s) => [
|
||||
<Link key="n" to={`/ops/sites/${s.place_id}/stats`} className="font-medium hover:underline">
|
||||
{s.name}
|
||||
</Link>,
|
||||
// 서비스 사이트 줄은 사업장이 없어 사이트별 통계로 갈 곳이 없다 — 이름만 보인다.
|
||||
s.service ? (
|
||||
<span key="n" className="font-medium">
|
||||
{s.name}
|
||||
<span className="ml-1.5 text-xs font-normal text-muted-foreground">공개 화면</span>
|
||||
</span>
|
||||
) : (
|
||||
<Link key="n" to={`/ops/sites/${s.place_id}/stats`} className="font-medium hover:underline">
|
||||
{s.name}
|
||||
</Link>
|
||||
),
|
||||
s.views,
|
||||
s.visitors,
|
||||
])}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import {useEffect, useRef} from 'react';
|
||||
import {useLocation} from 'react-router';
|
||||
|
||||
/**
|
||||
* 서비스 사이트 공개 화면 방문 비콘 — 발행 사이트 비콘(solution/site/src/lib/visit-beacon.ts)과 같은 방식이다.
|
||||
* 쿠키·식별자를 남기지 않고, 방문자 구분은 서버가 IP·UA·월로 해시해 한다.
|
||||
*/
|
||||
|
||||
const ENDPOINT = '/v1/track/view';
|
||||
/** 운영자가 자기 방문을 빼고 싶을 때 콘솔에서 `localStorage.setItem('web4ai.stats.disabled', '1')` — 발행 사이트와 같은 키. */
|
||||
const OPT_OUT_KEY = 'web4ai.stats.disabled';
|
||||
|
||||
/** 세는 공개 화면 — 백엔드 `services/visit_service.py` SERVICE_PATHS 와 같게 둔다. 작업 화면(빌더·내 사이트·운영)은 뺀다. */
|
||||
const SERVICE_PATHS = new Set(['/', '/pricing', '/showcase', '/login', '/signup']);
|
||||
|
||||
function servicePath(pathname: string): string | null {
|
||||
const path = pathname.replace(/\/+$/, '') || '/';
|
||||
return SERVICE_PATHS.has(path) ? path : null;
|
||||
}
|
||||
|
||||
function isOptedOut(): boolean {
|
||||
try {
|
||||
return window.localStorage.getItem(OPT_OUT_KEY) === '1';
|
||||
} catch {
|
||||
// 저장소 접근이 막힌 브라우저 — 그냥 센다. 통계 때문에 화면이 깨지면 안 된다.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function send(payload: {path: string; referrer: string; utm_source: string}): void {
|
||||
const body = JSON.stringify(payload);
|
||||
// text/plain — sendBeacon 이 프리플라이트 없이 보낼 수 있는 형식이다.
|
||||
const blob = new Blob([body], {type: 'text/plain;charset=UTF-8'});
|
||||
if (navigator.sendBeacon?.(ENDPOINT, blob)) return;
|
||||
// 전송 실패는 방문자에게 보일 일이 아니다 — 결과를 버린다.
|
||||
void fetch(ENDPOINT, {method: 'POST', body, keepalive: true, headers: {'Content-Type': 'text/plain'}}).catch(
|
||||
() => undefined,
|
||||
);
|
||||
}
|
||||
|
||||
/** 공개 화면에 들어올 때마다 한 번. 앱 안에서 옮겨 온 화면은 리퍼러를 우리 주소로 보낸다 — 첫 유입처를 화면마다 되풀이하지 않는다. */
|
||||
export function useServiceVisitBeacon(): void {
|
||||
const {pathname} = useLocation();
|
||||
const first = useRef(true);
|
||||
useEffect(() => {
|
||||
const isFirst = first.current;
|
||||
first.current = false;
|
||||
const path = servicePath(pathname);
|
||||
if (!path || isOptedOut()) return;
|
||||
send({
|
||||
path,
|
||||
referrer: isFirst ? document.referrer : `${window.location.origin}/`,
|
||||
utm_source: new URLSearchParams(window.location.search).get('utm_source') ?? '',
|
||||
});
|
||||
}, [pathname]);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import {isRouteErrorResponse, Links, Meta, Outlet, Scripts, ScrollRestoration} from 'react-router';
|
||||
import type {LinksFunction, MetaFunction} from 'react-router';
|
||||
import {Providers} from '@/app/provider';
|
||||
import {useServiceVisitBeacon} from '@/lib/visitBeacon';
|
||||
import './index.css';
|
||||
|
||||
/** 문서 껍데기. */
|
||||
@@ -53,6 +54,7 @@ export function Layout({children}: {children: React.ReactNode}) {
|
||||
}
|
||||
|
||||
export default function Root() {
|
||||
useServiceVisitBeacon();
|
||||
return (
|
||||
<Providers>
|
||||
<Outlet />
|
||||
|
||||
Reference in new issue
Block a user