Skip to main content

Python SDK for Traaaction affiliate tracking and management

Project description

traaaction

Python SDK for Traaaction — affiliate tracking for Python web apps.

Install

pip install traaaction

Quick start

from traaaction import Traaaction

trac = Traaaction()  # reads TRAAACTION_API_KEY env var
# or: trac = Traaaction(api_key="pk_live_xxx")

Track a lead (signup)

Call this immediately after creating a user in your database:

trac.track.lead(
    click_id=click_id,          # from cookie or URL param
    event_name="sign_up",
    customer_id=str(user.id),   # your app's user ID
    customer_email=user.email,
    customer_name=user.get_full_name(),
)

Stripe checkout metadata

Pass this to stripe.checkout.Session.create():

metadata = trac.stripe_metadata(request, str(user.id))
session = stripe.checkout.Session.create(
    line_items=[...],
    mode="subscription",
    metadata=metadata,
    success_url="...",
)

Django integration

1. Install with Django extras

pip install "traaaction[django]"

2. Add middleware

# settings.py
MIDDLEWARE = [
    ...
    "traaaction.django.TraacMiddleware",
    "django.contrib.sessions.middleware.SessionMiddleware",
    ...
]

# Optional: share cookie across subdomains
TRAC_COOKIE_DOMAIN = ".yourdomain.com"

3. Track events in views

# views.py
from traaaction import Traaaction
from traaaction.django import get_click_id

trac = Traaaction()

def signup_view(request):
    # ... create user ...

    click_id = get_click_id(request)  # reads middleware session or cookies
    trac.track.lead(
        click_id=click_id,
        event_name="sign_up",
        customer_id=str(user.id),
        customer_email=user.email,
    )
    return redirect("/dashboard")

def checkout_view(request):
    metadata = trac.stripe_metadata(request, str(user.id))
    session = stripe.checkout.Session.create(
        line_items=[...],
        mode="subscription",
        metadata=metadata,
        success_url=request.build_absolute_uri("/dashboard"),
    )
    return redirect(session.url)

Environment variables

Variable Description
TRAAACTION_API_KEY Your Traaaction publishable key (pk_live_...)
TRAC_API_KEY Legacy alias (backwards compatible)

How it works

  1. A seller shares their Traaaction affiliate link (e.g. traaaction.com/s/mission/abc123)
  2. A customer clicks → lands on your site with ?trac_click_id=clk_xxx
  3. TraacMiddleware captures and persists the click ID (session + cookie)
  4. On signup: track.lead() links the customer to the seller
  5. On purchase: Stripe webhook (configured in Traaaction dashboard) automatically creates the commission

Links

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

traaaction-1.1.0.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

traaaction-1.1.0-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: traaaction-1.1.0.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for traaaction-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0450d776002067781905af9bd2de223c733ff532e3369d0584f7c413c7a221f8
MD5 40de0eda525dcd4b61726d6c4bded699
BLAKE2b-256 c0c272523d48157d770ec9d37bff72fa033ea690cdf44f77dd900b82432f3722

See more details on using hashes here.

File details

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

File metadata

  • Download URL: traaaction-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 25.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for traaaction-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa4fa2acfa79870a5063fb497569ad0a9dd29e2a5c4753e57d6a2ca2f96df76d
MD5 7fbb9f7dc507adba4a69e19f2754b9fa
BLAKE2b-256 d2f02d86433329cc5b9498512473edce183f7ef45e4d09d81e5e571163faa6e3

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