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.1.0.tar.gz (10.3 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.1.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dash_user_tracker-1.1.0.tar.gz
Algorithm Hash digest
SHA256 26e01f13826219819247ce9328ff113cff19a656111363c6df92b0a0b9ec2176
MD5 1859a3a7dc49724cc9160d44375e8253
BLAKE2b-256 d0caf96855fb7fc1a1dc3ef05a37a40979201d7dfea6e4d0ab2cccad637f502f

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dash_user_tracker-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 404a67e716e7f5b5d9ad10b09d0333d439fffb3598614efa14777b6bfc2573b4
MD5 e81d65fd2498b796088cf375d93a4bd1
BLAKE2b-256 eadcc692fd940cb853d4bf7874da9c1515e0888f1111fcba5a4238e3c19811d2

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