Some checks failed
CI / Frontend Lint & Type Check (push) Has been cancelled
CI / Frontend Build (push) Has been cancelled
CI / Backend Lint (push) Has been cancelled
CI / Backend Tests (push) Has been cancelled
CI / Docker Build (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
Deploy / Build & Push Images (push) Has been cancelled
Deploy / Deploy to Server (push) Has been cancelled
Deploy / Notify (push) Has been cancelled
57 lines
2.3 KiB
Python
57 lines
2.3 KiB
Python
"""
|
|
Telemetry events (4A).
|
|
|
|
Store canonical product events for funnel KPIs:
|
|
- Deal funnel: listing_view → inquiry_created → message_sent → listing_marked_sold
|
|
- Yield funnel: yield_connected → yield_click → yield_conversion → payout_paid
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
from sqlalchemy import Boolean, DateTime, ForeignKey, Index, Integer, String, Text
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.database import Base
|
|
|
|
|
|
class TelemetryEvent(Base):
|
|
__tablename__ = "telemetry_events"
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, index=True)
|
|
|
|
# Who
|
|
user_id: Mapped[Optional[int]] = mapped_column(ForeignKey("users.id"), nullable=True, index=True)
|
|
|
|
# What
|
|
event_name: Mapped[str] = mapped_column(String(60), nullable=False, index=True)
|
|
|
|
# Entity links (optional)
|
|
listing_id: Mapped[Optional[int]] = mapped_column(Integer, nullable=True, index=True)
|
|
inquiry_id: Mapped[Optional[int]] = mapped_column(Integer, nullable=True, index=True)
|
|
yield_domain_id: Mapped[Optional[int]] = mapped_column(Integer, nullable=True, index=True)
|
|
click_id: Mapped[Optional[str]] = mapped_column(String(64), nullable=True, index=True)
|
|
domain: Mapped[Optional[str]] = mapped_column(String(255), nullable=True, index=True)
|
|
|
|
# Context
|
|
source: Mapped[Optional[str]] = mapped_column(String(30), nullable=True) # "public" | "terminal" | "webhook" | "scheduler" | "admin"
|
|
ip_hash: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
|
user_agent: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
|
|
referrer: Mapped[Optional[str]] = mapped_column(String(500), nullable=True)
|
|
metadata_json: Mapped[Optional[str]] = mapped_column(Text, nullable=True) # JSON string
|
|
|
|
# Flags
|
|
is_authenticated: Mapped[Optional[bool]] = mapped_column(Boolean, nullable=True)
|
|
|
|
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
|
|
|
|
__table_args__ = (
|
|
Index("ix_telemetry_event_name_created", "event_name", "created_at"),
|
|
Index("ix_telemetry_user_created", "user_id", "created_at"),
|
|
Index("ix_telemetry_listing_created", "listing_id", "created_at"),
|
|
Index("ix_telemetry_yield_created", "yield_domain_id", "created_at"),
|
|
)
|
|
|