feat(performance): 네이버 광고 보고서 업로드(ROAS·보고서 항목) + 머리글 클릭 일자별 상세

- 네이버 업로드: 3열 기간·4열 총비용(광고비)·12열 구매완료 광고수익률(ROAS), 나머지 항목은 metrics(JSONB)
- 네이버·구글·메타 칸 ROAS = 보고서 값(여러 날은 광고비 가중 평균), 쇼핑몰 매출로 계산하지 않음
- 네이버 머리글 클릭 → 지금 기간 일자별 보고서 표 + 합계(GET /api/ad-spend/naver/details)
- performance_db 마이그레이션 006: perf_ad_spend.roas·metrics

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-14 17:23:11 +09:00
parent 240d61c903
commit e9fb1c3407
15 changed files with 525 additions and 46 deletions
+26 -3
View File
@@ -23,6 +23,11 @@ async function env(file) {
const isForm = o && o.body && typeof o.body !== "string";
const body = o && o.body && !isForm ? JSON.parse(o.body) : null;
e.calls.push({ method: method, url: url, body: body, form: isForm ? o.body : null });
if (/^\/performance\/api\/ad-spend\/naver\/details/.test(url)) {
return { ok: true, status: 200, json: async function () {
return { columns: ["총비용", "노출수", "클릭률(%)", "구매완료 광고수익률(%)"], total: { "총비용": 300000, "노출수": 30043, "클릭률(%)": 1.53, "구매완료 광고수익률(%)": 250.5 },
rows: [{ date: "2026-10-03", amount: 300000, roas: 250.5, values: { "총비용": 300000, "노출수": 30043, "클릭률(%)": 1.53, "구매완료 광고수익률(%)": 250.5 } }] }; } };
}
if (/^\/performance\/api\/ad-spend\/upload/.test(url)) {
return { ok: true, status: 200, json: async function () {
return { ok: true, saved: 12, name: "쿠팡(로켓)", total: 2636494, from: "2026-10-01", to: "2026-10-12" }; } };
@@ -143,7 +148,7 @@ function gross(td) { return td.querySelector(".v-gross").textContent.trim(); }
{
const e = await env("perf_ads.html");
check("[광고비] 광고비 탭이 고른 탭", e.d.querySelector(".perf-tab-ads").classList.contains("is-active"));
const heads = Array.from(e.d.querySelectorAll(".perf-main thead th")).map(function (th) { return th.textContent.replace("✎", "").trim(); });
const heads = Array.from(e.d.querySelectorAll(".perf-main thead th")).map(function (th) { return th.textContent.replace("✎", "").replace("table_view", "").trim(); });
check("[광고비] 열 = 구글·메타·네이버·쿠팡(윙)·쿠팡(로켓)·오늘의집·G마켓·카카오·GS샵·11번가·롯데ON·토스·애터미아자몰",
heads.join(",") === "날짜,구글,메타,네이버,쿠팡(윙),쿠팡(로켓),오늘의집,G마켓,카카오,GS샵,11번가,롯데ON,토스,애터미아자몰,일 합계", heads);
const wing = cell(e, "coupang_wing", "2026-10-05");
@@ -154,7 +159,7 @@ function gross(td) { return td.querySelector(".v-gross").textContent.trim(); }
!up.classList.contains("is-manual") && man.classList.contains("is-manual") && gross(up) === "220,000");
check("[광고비] 앞으로의 날은 입력 칸 아님", !cell(e, "google", "2026-10-08") && !!cell(e, "google", "2026-10-07"));
const kpi = Array.from(e.d.querySelectorAll(".perf-kpi-value")).map(function (n) { return n.textContent.trim(); });
check("[광고비] KPI — 이번달 광고비 299,000 · 매출 대비 비율", kpi[0] === "₩299,000" && /%$/.test(kpi[1]), kpi);
check("[광고비] KPI — 이번달 광고비 599,000(네이버 300,000 포함) · 매출 대비 비율", kpi[0] === "₩599,000" && /%$/.test(kpi[1]), kpi);
wing.click();
const wi = wing.querySelector(".perf-manual-input");
wi.value = "30000";
@@ -182,7 +187,8 @@ function gross(td) { return td.querySelector(".v-gross").textContent.trim(); }
e.d.getElementById("perf-ad-upload").click();
const modal = e.d.querySelector(".perf-modal");
const opts = Array.from(modal.querySelectorAll(".perf-ad-channel option")).map(function (o) { return o.value; });
check("[업로드] 채널 선택 = 양식이 정해진 쿠팡(윙)·쿠팡(로켓)", opts.join(",") === "coupang_wing,coupang_rocket", opts);
check("[업로드] 채널 선택 = 양식이 정해진 네이버·쿠팡(윙)·쿠팡(로켓)", opts.join(",") === "naver,coupang_wing,coupang_rocket", opts);
check("[업로드] 네이버 안내 = 3열 기간·4열 총비용·12열 ROAS", /3열 기간.*4열 총비용.*12열/.test(modal.querySelector(".perf-ad-help").textContent));
modal.querySelector(".perf-ad-channel").value = "coupang_rocket";
modal.querySelector(".perf-ad-channel").dispatchEvent(new e.w.Event("change"));
check("[업로드] 양식 안내(19열 청구금액)", /19열/.test(modal.querySelector(".perf-ad-help").textContent));
@@ -195,6 +201,23 @@ function gross(td) { return td.querySelector(".v-gross").textContent.trim(); }
check("[업로드] POST /api/ad-spend/upload?channel=coupang_rocket (파일)", post && post.url === "/performance/api/ad-spend/upload?channel=coupang_rocket" && !!post.form, e.calls);
check("[업로드] 결과 안내(12일 반영)", /12일 반영/.test(modal.querySelector(".perf-upload-result").textContent));
}
// ── 네이버 — 보고서 ROAS 표시 · 머리글 → 일자별 보고서 항목 ──
{
const e = await env("perf_ads.html");
const nv = cell(e, "naver", "2026-10-03");
check("[네이버] 칸 = 광고비(보고서 ROAS 반올림)", nv.textContent.trim() === "300,000(251%)", nv.textContent);
const hb = e.d.querySelector('.perf-main thead [data-detail-channel="naver"]');
check("[네이버] 머리글 = 상세 보기 버튼(다른 채널은 아님)", !!hb && e.d.querySelectorAll(".perf-main thead [data-detail-channel]").length === 1);
hb.click(); await settle();
const call = e.calls.find(function (c) { return /\/details/.test(c.url); });
check("[네이버] 지금 기간으로 상세 요청", call && call.url === "/performance/api/ad-spend/naver/details?from=2026-10-01&to=2026-10-31", e.calls);
const modal = e.d.querySelector(".perf-modal");
const ths = Array.from(modal.querySelectorAll("thead th")).map(function (t) { return t.textContent; });
const row = Array.from(modal.querySelectorAll("tbody tr")[0].children).map(function (t) { return t.textContent; });
check("[네이버] 상세 표 = 날짜 + 보고서 항목(파일 순서), 날짜 mm/dd(요일)", ths.join(",") === "날짜,총비용,노출수,클릭률(%),구매완료 광고수익률(%)" &&
row.join(",") === "10/03(토),300,000,30,043,1.53,250.50", [ths, row]);
check("[네이버] 맨 아래 합계 줄", /합계/.test(modal.querySelector("tfoot").textContent) && /30,043/.test(modal.querySelector("tfoot").textContent));
}
// ── 설정: 수동 입력 토글 ──
{
const e = await env("perf_settings.html");