Skip to content

wp-media/py-mixpanel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python integration for Mixpanel

This repository provides a comprehensive layer on top of the official Python library from Mixpanel which adds:

  • Support for anonymizing email addresses and including them in tracked events
  • Django middleware & view support (including support for HTMX)
  • Unit tested & providing type hints

Usage

You can install the package, and then start tracking straight away:

from py_mixpanel import Tracking

tracker = Tracking(mixpanel_token="s3cret")

tracker.track("user@email.com", "Login", {"browser": "Chrome"})

Django

If you use Django, you may also:

  • Use the DjangoMixpanelMiddleware class to automatically track requests
  • Use the DjangoMixpanelMixin to add a user-friendly mixpanel_track() method to any class-based view

These integrations are configured through your own settings.py:

MIXPANEL_OPTIONS = {

    # Your Mixpanel token
    TOKEN: str,

    # Potentially override the API host
    API_HOST: str,

    # Enable or disable actual tracking
    ENABLE_TRACKING: bool,  # default: True

    # Track certain properties for every user using the middleware
    # (uses the session)
    USER_TRACKING: bool,  # default: False

    # Keep track of HTMX headers in fired events
    TRACK_HTMX: bool,  # default: True

    # Name the event that will be sent on every page view
    PAGE_VIEW_EVENT_NAME: str,  # default: "Page Viewed"

    # Provide a static default payload for all events
    PAGE_VIEW_EVENT_PAYLOAD: dict,  # default: {}

}

Development

It is recommended to use uv to develop locally.

Testing (pytest)

Run the tests:

$ uv run pytest

Type checking (mypy)

Run the type checker:

uv run mypy .

Formatting and linting (ruff)

Run the formatter:

uv tool run ruff format

Run the linter:

uv tool run ruff check --fix

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages