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"
}
Metadata
Release files for dash-user-tracker 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dash_user_tracker-1.2.0.tar.gz | 10.9 kB | Without provenance | Details for dash_user_tracker-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dash_user_tracker-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for dash_user_tracker-1.2.0-py3-none-any.whl |
Total release size: 23.9 kB
Release files / dash_user_tracker-1.2.0.tar.gz
| Download URL | dash_user_tracker-1.2.0.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e039e59eb5f9787a7718af08f6599df4649b07668b7bbeb449bd48d3a0741c70
|
|
BLAKE2b-256 checksum How to use checksums |
9bb3fe73a7b5ea39f94c982cdec65b3b021e1bc0b96a8663bbd908cd97c0619c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.11.4 Darwin/24.3.0
|
Release files / dash_user_tracker-1.2.0-py3-none-any.whl
| Download URL | dash_user_tracker-1.2.0-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e59cc98546960a44ac7bd6a7b0c1d5b9fe2ad62fde7386aa56ed2e96726647b
|
|
BLAKE2b-256 checksum How to use checksums |
58f9ee52488a02a70c0ab42fa8e1fee7cc9ed885609215143ec9fbbf91cf1b50
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.11.4 Darwin/24.3.0
|
Security for dash-user-tracker 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.