feat(performance): 광고 보고서 상세에서 ROAS 를 광고비 오른쪽에 표기
네이버 광고 보고서는 ROAS(구매완료 광고수익률(%))가 12열이라 일자별 보고서 창에서 광고비(총비용)와 멀리 떨어져 보였다. 상세 표에서 ROAS 열을 광고비 열 바로 오른쪽으로 옮기고, 네이버 머리글은 "ROAS(%)"로 보여 준다(말풍선에 원래 머리글). 저장된 키는 그대로라 예전 업로드에도 적용된다. 구글·메타 상세도 같은 순서. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,7 +58,8 @@
|
||||
- 칸 = "광고비(ROAS%)"(ROAS = 그 쇼핑몰 매출 ÷ 광고비). 구글·메타·네이버는 계산 안 함 — 광고 보고서 ROAS(마이그레이션 006 `roas`·`metrics`).
|
||||
- 날짜 칸 직접 입력 + 쿠팡(윙)·쿠팡(로켓)·네이버 광고 보고서 업로드.
|
||||
- 쿠팡: 1열 날짜·19열 청구금액(+부가가치세).
|
||||
- 네이버: 3열 기간·4열 총비용·12열 ROAS, 머리글 클릭 = 일자별 보고서 항목.
|
||||
- 네이버: 3열 기간·4열 총비용·12열 ROAS(구매완료 광고수익률(%)), 머리글 클릭 = 일자별 보고서 항목.
|
||||
- 일자별 보고서 창: ROAS 열은 **광고비 열 바로 오른쪽**, 네이버 "구매완료 광고수익률(%)" 머리글은 "ROAS(%)"로 표기(`ad_spend._roas_next_to_spend` → `labels`, 저장 키는 파일 머리글 그대로 — 예전 업로드도 그대로 적용).
|
||||
- 매출 대비 광고비 KPI.
|
||||
- 광고 API 연동(마이그레이션 007 `perf_ad_credentials`·`perf_ad_source_status`) — 실적 설정 **광고 API 연동** 카드, 쇼핑몰과 같은 마스터 키로 암호화(AAD `perf:ad:…`), `ad_sources/`(채널 하나 = 파일 하나) + `ad_sync.py`, 매출 자동 업데이트 회차에 함께. 결과는 `perf_ad_spend` `source='api'`(초록 숫자, API 가 안 준 날은 예전 API 값만 지움).
|
||||
- **구글 = Google Ads API**(2026-10-15) — 고객 ID·(MCC)·서비스 계정 JSON·API 버전(기본 v26). 개발자 토큰은 2026-09-09 구글 폐지 — 접근 등급은 서비스 계정의 Cloud 프로젝트, 머리글 안 보냄. 광고비 탭 [구글 광고 불러오기](보는 기간). 광고비 = 비용 × 1.1(부가세 포함)·ROAS(전환 가치 ÷ 비용, 구글 값 그대로)·항목.
|
||||
|
||||
@@ -378,7 +378,30 @@ def detail_table(rows: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
out_rows = [{"date": r["date"], "amount": int(r.get("amount") or 0),
|
||||
"roas": float(r["roas"]) if r.get("roas") is not None else None,
|
||||
"values": {k: v for k, v in (r.get("metrics") or {}).items() if not k.startswith("_")}} for r in rows]
|
||||
return {"columns": cols, "rows": out_rows, "total": total}
|
||||
cols, labels = _roas_next_to_spend(cols)
|
||||
return {"columns": cols, "labels": labels, "rows": out_rows, "total": total}
|
||||
|
||||
|
||||
# 상세 표의 광고비 열 — 네이버 "총비용"(4열), 구글 "광고비(부가세 포함)", 메타 "지출 금액(부가세 포함)"
|
||||
_SPEND_COL_MARKS = ("총비용", "광고비(", "지출 금액(부가세")
|
||||
|
||||
|
||||
def _roas_next_to_spend(cols: list[str]) -> tuple[list[str], dict[str, str]]:
|
||||
"""ROAS 열을 광고비 열 바로 오른쪽으로 옮긴다(2026-10-20 사용자 요청 — 네이버 파일은 12열이라 멀리 떨어져 있었다).
|
||||
네이버 "구매완료 광고수익률(%)" 은 머리글을 "ROAS(%)" 로 보여 준다(값·키는 파일 머리글 그대로, labels 로만).
|
||||
반환: (열 순서, {열: 화면 머리글})."""
|
||||
roas_col = next((k for k in cols if "수익률" in k or "ROAS" in k.upper()), None)
|
||||
spend_col = next((k for k in cols if any(m in k for m in _SPEND_COL_MARKS)), None)
|
||||
labels: dict[str, str] = {}
|
||||
if roas_col is None:
|
||||
return cols, labels
|
||||
if "ROAS" not in roas_col.upper():
|
||||
labels[roas_col] = "ROAS(%)"
|
||||
if spend_col is None:
|
||||
return cols, labels
|
||||
out = [k for k in cols if k != roas_col]
|
||||
out.insert(out.index(spend_col) + 1, roas_col)
|
||||
return out, labels
|
||||
|
||||
|
||||
def detail_tabs(rows: list[dict[str, Any]]) -> dict[str, Any]:
|
||||
|
||||
@@ -224,4 +224,4 @@
|
||||
} | tojson }}</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}<script src="/static/performance.js?v=20261019e" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/performance.js?v=20261020a" defer></script>{% endblock %}
|
||||
|
||||
@@ -274,4 +274,4 @@
|
||||
} | tojson }}</script>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}<script src="/static/performance.js?v=20261019e" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/performance.js?v=20261020a" defer></script>{% endblock %}
|
||||
|
||||
@@ -219,4 +219,4 @@
|
||||
</section>
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}<script src="/static/performance.js?v=20261019e" defer></script>{% endblock %}
|
||||
{% block scripts %}<script src="/static/performance.js?v=20261020a" defer></script>{% endblock %}
|
||||
|
||||
@@ -276,7 +276,9 @@ def test_naver_detail_table_totals():
|
||||
{"date": "2026-09-24", "amount": 0, "roas": Decimal("0"), "metrics": {"총비용": 0, "노출수": 0, "클릭수": 0,
|
||||
"클릭률(%)": 0.0, "구매완료 광고수익률(%)": 0}}]
|
||||
t = ads.detail_table(rows)
|
||||
assert t["columns"] == ["총비용", "노출수", "클릭수", "클릭률(%)", "구매완료 광고수익률(%)"]
|
||||
# ROAS(12열)는 광고비(총비용) 바로 오른쪽, 머리글은 "ROAS(%)"(값 키는 파일 머리글 그대로)
|
||||
assert t["columns"] == ["총비용", "구매완료 광고수익률(%)", "노출수", "클릭수", "클릭률(%)"]
|
||||
assert t["labels"] == {"구매완료 광고수익률(%)": "ROAS(%)"}
|
||||
assert t["total"]["총비용"] == 600489 and t["total"]["노출수"] == 61104 and t["total"]["클릭수"] == 902
|
||||
assert t["total"]["클릭률(%)"] == round(902 * 100 / 61104, 2) # 가중: 클릭수 ÷ 노출수
|
||||
assert t["total"]["구매완료 광고수익률(%)"] == 133.09 # 광고비 가중 평균 (198.79×299,817 + 67.58×300,672) ÷ 600,489
|
||||
|
||||
@@ -434,8 +434,12 @@
|
||||
};
|
||||
const table = function (t) {
|
||||
const tcols = t.columns || cols;
|
||||
const labels = t.labels || res.labels || {};
|
||||
return '<div class="perf-ev-wrap"><table class="perf-table perf-detail-table"><thead><tr><th class="perf-th-label">날짜</th>' +
|
||||
tcols.map(function (c) { return "<th>" + esc(c) + "</th>"; }).join("") + "</tr></thead><tbody>" +
|
||||
tcols.map(function (c) {
|
||||
// 화면 머리글(labels)이 따로 있으면 그것을, 말풍선엔 파일 원래 머리글(네이버 "구매완료 광고수익률(%)" → ROAS(%))
|
||||
return labels[c] ? '<th title="' + esc(c) + '">' + esc(labels[c]) + "</th>" : "<th>" + esc(c) + "</th>";
|
||||
}).join("") + "</tr></thead><tbody>" +
|
||||
(t.rows || []).map(function (r) {
|
||||
return '<tr><th class="perf-td-label" scope="row">' + esc(day(r.date)) + "</th>" +
|
||||
tcols.map(function (c) { return '<td class="perf-num">' + cell((r.values || {})[c]) + "</td>"; }).join("") + "</tr>";
|
||||
|
||||
Reference in New Issue
Block a user