tessl install tessl/pypi-posthog@6.7.0Integrate PostHog into any python application.
Agent Success
Agent success rate when using this tile
89%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.03x
Baseline
Agent success rate without this tile
86%
Build a robust analytics event tracker that can reliably send events to an analytics service even when facing network instabilities. The system should handle network failures gracefully through automatic retries with exponential backoff.
Implement an analytics event tracking system with the following features:
Event Capture: Track user events with custom properties including:
Network Resilience: The system must handle network failures by:
Configuration Options: Support configurable parameters for:
Graceful Shutdown: Ensure all pending events are sent before the application exits
Create a Python module analytics_tracker.py that exports:
init_tracker(api_key, host, max_retries, timeout): Initialize the analytics tracker with configurationtrack_event(event_name, user_id, properties): Track a single eventshutdown_tracker(): Flush pending events and clean up resourcesThe system should be resilient to:
Provides analytics event tracking with built-in retry logic.
Setup: Initialize the tracker with valid credentials
Action: Track a simple event with user ID and properties
Expected: Event is successfully captured and queued for sending
init_tracker(
api_key="test_key_123",
host="https://app.posthog.com",
max_retries=3,
timeout=10
)
track_event(
event_name="button_clicked",
user_id="user_001",
properties={"button_name": "submit", "page": "checkout"}
)Setup: Initialize tracker with batching enabled
Action: Track multiple events in succession
Expected: Events are batched and sent efficiently
init_tracker(
api_key="test_key_123",
host="https://app.posthog.com",
max_retries=3,
timeout=10
)
for i in range(5):
track_event(
event_name="page_view",
user_id=f"user_{i:03d}",
properties={"page": f"/product/{i}"}
)Setup: Initialize tracker and track events
Action: Call shutdown to flush pending events
Expected: All events are sent before shutdown completes
init_tracker(
api_key="test_key_123",
host="https://app.posthog.com",
max_retries=3,
timeout=10
)
track_event(
event_name="session_end",
user_id="user_001",
properties={"duration_seconds": 120}
)
shutdown_tracker() # Should flush all pending eventsCreate the following files:
analytics_tracker.py: Main implementationanalytics_tracker.test.py: Test file with the above test cases