Skip to main content

Library to track user interactions in Dash applications

Project description

Dash Tracker

Dash Tracker is a lightweight tracking library for Dash applications. It logs user interactions, page views, and navigation events, with support for sending data to a tracking endpoint or printing to console for development purposes.

Features

  • Tracks full-page loads and internal navigation events
  • Built-in analytics capabilities for querying user activity and page views
  • Captures user information from Flask sessions (ID, email, full name)
  • Supports ignoring specific routes and callbacks
  • Sends tracking data via HTTP requests or logs to the console
  • Seamless integration with Dash and Flask
  • Support for custom user providers and repositories

Installation

pip install dash-user-tracker

Basic Usage

The basic usage supports sending tracking data to a custom endpoint.

from dash import Dash
from dash_user_tracker import Tracker

app = Dash(__name__)
tracker = Tracker(app, tracker_endpoint="https://your-tracker-endpoint.com")

Development Mode

tracker = Tracker(app)  # Will print events to console

Custom Configuration

You can use the HttpTrackerRepository class to send tracking data to a custom endpoint.

from dash import Dash
from dash_user_tracker import Tracker, HttpTrackerRepository

app = Dash(__name__)
repository = HttpTrackerRepository("https://your-tracker-endpoint.com", "api-key")
tracker = Tracker(
    app,
    ignore_route = ignore_route,
    ignore_callback = ignore_callback,
    user_provider = user_provider,
    repository = repository
)

Ignoring Routes and Callbacks

The library allows you to customize the ignore_route and ignore_callback functions to exclude specific routes and callbacks from tracking.

def ignore_route(route):
    return route in ["/health", "/metrics"]

def ignore_callback(callback):
    return callback in ["callback1", "callback2"]

User Information

You can also customize the user provider to extract user information from the Flask session.

def user_provider():
    return {
        "id": session.get("user_id"),
        "email": session.get("user_email"),
        "full_name": session.get("user_full_name")
    }

Custom Repository

Alternatively, you can create your own custom repository by extending the TrackerRepository class. To do this, look at the HttpTrackerRepository class for reference.

Analytics

The library includes a built-in analytics module for querying user activity and page views.

Use it directly from the tracker instance, or, use the TrackerAnalytics class directly.

tracker_analytics = tracker.analytics
# Or
from dash_user_tracker import TrackerAnalytics

tracker_analytics = TrackerAnalytics(
    repository = repository
)
# Get Page Views
page_views = await tracker_analytics.get_page_views()

# Get user activity
activity = await tracker_analytics.get_user_activity("user123")

# Get page activity
page_stats = await tracker_analytics.get_page_activity("/dashboard")

# Get user counts
total_users = await tracker_analytics.get_user_count()

# Get user counts by path
page_users = await tracker_analytics.get_user_count_by_path("/home")

Event Data Format

The information sent to the tracking endpoint is in the following format:

{
    "event": "page_view",
    "data": {
        "app_name": "My Dash App",
        "ip": "127.0.0.1",
        "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36",
        "base_url": "http://127.0.0.1:8050/",
        "url": "http://127.0.0.1:8050/",
        "url_root": "http://127.0.0.1:8050/",
        "referrer": null,
        "path": "/",
        "full_path": "/?",
        "method": "GET",
        "user_id": "anonymous",
        "email": "anonymous",
        "full_name": "anonymous"
    },
    "timestamp": "2025-01-30T20:29:28.543062+00:00"
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dash_user_tracker-1.2.0.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dash_user_tracker-1.2.0-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file dash_user_tracker-1.2.0.tar.gz.

File metadata

  • Download URL: dash_user_tracker-1.2.0.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.4 Darwin/24.3.0

File hashes

Hashes for dash_user_tracker-1.2.0.tar.gz
Algorithm Hash digest
SHA256 e039e59eb5f9787a7718af08f6599df4649b07668b7bbeb449bd48d3a0741c70
MD5 452adf29ee98b0c31013f5802d273330
BLAKE2b-256 9bb3fe73a7b5ea39f94c982cdec65b3b021e1bc0b96a8663bbd908cd97c0619c

See more details on using hashes here.

File details

Details for the file dash_user_tracker-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: dash_user_tracker-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.11.4 Darwin/24.3.0

File hashes

Hashes for dash_user_tracker-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0e59cc98546960a44ac7bd6a7b0c1d5b9fe2ad62fde7386aa56ed2e96726647b
MD5 3f1b61b4d0c4be198310d7c22f21e7f5
BLAKE2b-256 58f9ee52488a02a70c0ab42fa8e1fee7cc9ed885609215143ec9fbbf91cf1b50

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page