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.3.0.tar.gz (16.5 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.3.0-py3-none-any.whl (26.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for traaaction-1.3.0.tar.gz
Algorithm Hash digest
SHA256 449ca282269ad3cd914f39f9303fe259838bf980aeb8e6ccd3431d1e1bac9fe7
MD5 51a3d88ae714cbbfd146af5ae9d97d9e
BLAKE2b-256 eb93fd7ec689b1a143d445e79ef6692c7a32e901867e6cf63b17d7c39e6a09fc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: traaaction-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 26.1 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 efab9ebae3045cb2601d4c16e5515659febfb5fbb57daa752f76777bd3a2e5fe
MD5 a5299f4d9ec26b29e0eead3783bc57c3
BLAKE2b-256 6d4ac53e1d30d72e5983cedfaf334fc677b2ff4ea391aa8e6873d6f4764403f8

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