Documentation

Django and Flask guide

There is no Python SDK. POST the same JSON @analyticfast/node sends: amount_minor (integer) and currency, not a major-unit amount. Use the standard library so the example adds no package. Read the visitor id from your order row. Keep the token in the environment.

import json, os, urllib.request

def record_payment(order_id: str, amount_minor: int, currency: str, visitor_id: str | None) -> dict:
    if not isinstance(amount_minor, int) or amount_minor < 0:
        raise ValueError('amount_minor must be a non-negative integer')
    payload = {'transaction_id': order_id, 'type': 'payment', 'amount_minor': amount_minor, 'currency': currency}
    site_id = os.environ.get('ANALYTICFAST_SITE_ID')
    if site_id:
        payload['site_id'] = site_id
    if visitor_id:
        payload['visitor_id'] = visitor_id
    request = urllib.request.Request(
        os.environ['ANALYTICFAST_BASE_URL'].rstrip('/') + '/api/v1/payments',
        data=json.dumps(payload).encode(),
        headers={'Authorization': 'Bearer ' + os.environ['ANALYTICFAST_TOKEN'], 'Content-Type': 'application/json'},
        method='POST')
    with urllib.request.urlopen(request, timeout=10) as response:
        return json.load(response)

Django: read a JSON body from request.body in your view, then call record_payment with the amount you stored when the order was charged (2999 for $29.99). Flask: read request.json the same way. Do not trust a decimal amount field from the client. Posting the same transaction_id again is the retry.

from django.http import JsonResponse
from django.shortcuts import get_object_or_404

# Your view. Wire it in urls.py; this is not an AnalyticFast URL.
def order_paid(request, order_id):
    order = get_object_or_404(Order, pk=order_id, user=request.user)
    record_payment(str(order.pk), order.total_minor, order.currency, order.visitor_id)
    return JsonResponse({'ok': True})
from flask import Flask, request
app = Flask(__name__)

@app.post('/orders/<order_id>/paid')
def order_paid(order_id):
    body = request.json or {}
    order = load_paid_order(order_id)  # your paid order, including total_minor
    record_payment(order.id, order.total_minor, order.currency, body.get('visitor_id'))
    return {'ok': True}

Official references, checked 2026-10-26: Django views, HttpRequest.body, Flask request.json, urllib.request.

Questions, answered.

How do I use django and flask with AnalyticFast?

Follow the Django and Flask instructions on this page using your own website’s Site ID and configuration. Verify a real event before relying on the reports.

Where can I get setup help?

Contact support@analyticfast.com with the website domain and a redacted description. Do not send API tokens, signing secrets or personal customer data.