fix: ventas KPI = Online Clientify (89) y atribución por fuente real

Excluye Málaga del cohort; enriquece source desde lead/Clientify para que el cruce ads vs CRM deje de volcar todo en sin-atribuir.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
4Ventures
2026-09-28 12:19:57 +02:00
parent 48fb31d247
commit 062c43325d
6 changed files with 206 additions and 27 deletions

View File

@@ -281,6 +281,25 @@ def main() -> int:
pipe_id = ""
if "/pipelines/" in pipe_url:
pipe_id = pipe_url.rstrip("/").split("/")[-1]
raw_src = (
d.get("deal_source")
or d.get("contact_source")
or ""
)
if isinstance(raw_src, str):
raw_src = raw_src.strip()[:80]
else:
raw_src = ""
tags = d.get("tags") or []
tag_blob = " ".join(str(t) for t in tags).lower() if isinstance(tags, list) else ""
name = (d.get("name") or "")[:200]
if not raw_src:
if any(x in tag_blob for x in ("facebook", "instagram", "meta", " fb ")):
raw_src = "meta"
elif "google" in tag_blob:
raw_src = "google"
elif "woocommerce" in tag_blob or name.lower().startswith("order "):
raw_src = "ecommerce"
row = {
"id": str(uuid.uuid5(uuid.NAMESPACE_URL, f"clientify-deal:{tid}:{did}")),
"tenant_id": tid,
@@ -292,6 +311,8 @@ def main() -> int:
"lost_at": closed if stage == "lost" else None,
"pipeline_id": pipe_id or None,
"pipeline_name": (d.get("pipeline_desc") or None),
"source": raw_src.lower() if raw_src else None,
"name": name or None,
}
rows.append(row)