or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/posthog@6.7.x
tile.json

tessl/pypi-posthog

tessl install tessl/pypi-posthog@6.7.0

Integrate 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%

task.mdevals/scenario-7/

Analytics Event Tracker with Resilient Network Handling

Overview

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.

Requirements

Core Functionality

Implement an analytics event tracking system with the following features:

  1. Event Capture: Track user events with custom properties including:

    • Event name
    • User identifier
    • Event properties (key-value pairs)
    • Timestamp
  2. Network Resilience: The system must handle network failures by:

    • Automatically retrying failed requests
    • Using exponential backoff between retry attempts
    • Configuring the maximum number of retry attempts
    • Handling timeout scenarios appropriately
  3. Configuration Options: Support configurable parameters for:

    • API endpoint URL
    • API authentication key
    • Maximum number of retries
    • Request timeout duration
    • Batch size for event collection
  4. Graceful Shutdown: Ensure all pending events are sent before the application exits

Implementation Details

Create a Python module analytics_tracker.py that exports:

  • init_tracker(api_key, host, max_retries, timeout): Initialize the analytics tracker with configuration
  • track_event(event_name, user_id, properties): Track a single event
  • shutdown_tracker(): Flush pending events and clean up resources

The system should be resilient to:

  • Temporary network outages
  • Connection timeouts
  • Service unavailability
  • Rate limiting responses

Dependencies { .dependencies }

posthog { .dependency }

Provides analytics event tracking with built-in retry logic.

Test Cases

Test 1: Basic Event Tracking { .test @test }

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"}
)

Test 2: Multiple Events with Batch Processing { .test @test }

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}"}
    )

Test 3: Graceful Shutdown { .test @test }

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 events

Output Files

Create the following files:

  • analytics_tracker.py: Main implementation
  • analytics_tracker.test.py: Test file with the above test cases

Success Criteria

  • Events are successfully tracked and sent to the analytics service
  • Network failures are handled gracefully with automatic retries
  • Configuration parameters are properly applied
  • System shuts down cleanly with all events flushed