Fire-and-forget analytics event to Tinybird. All errors are swallowed and logged — analytics never breaks the app.
(
event_name: str,
org_id: int,
user_id: int = 0,
session_id: str = "",
properties: dict | None = None,
source: str = "api",
ip: str = "",
)
| 35 | |
| 36 | |
| 37 | async def track( |
| 38 | event_name: str, |
| 39 | org_id: int, |
| 40 | user_id: int = 0, |
| 41 | session_id: str = "", |
| 42 | properties: dict | None = None, |
| 43 | source: str = "api", |
| 44 | ip: str = "", |
| 45 | ) -> None: |
| 46 | """ |
| 47 | Fire-and-forget analytics event to Tinybird. |
| 48 | All errors are swallowed and logged — analytics never breaks the app. |
| 49 | """ |
| 50 | config = get_learnhouse_config() |
| 51 | if config.tinybird_config is None: |
| 52 | return |
| 53 | |
| 54 | task = asyncio.create_task( |
| 55 | _send_event( |
| 56 | event_name=event_name, |
| 57 | org_id=org_id, |
| 58 | user_id=user_id, |
| 59 | session_id=session_id, |
| 60 | properties=properties or {}, |
| 61 | source=source, |
| 62 | ip=ip, |
| 63 | ) |
| 64 | ) |
| 65 | _background_tasks.add(task) |
| 66 | task.add_done_callback(_background_tasks.discard) |
| 67 | |
| 68 | |
| 69 | async def _send_event( |