Django Integration
Follow these steps to integrate Affonso tracking into your Django application using template inheritance and Django's settings system for clean configuration.
Method 1: Base Template (Recommended)
Add the tracking script to your base template at templates/base.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{% block title %}Your Site{% endblock %}</title>
<script
async
defer
src="https://affonso.io/js/pixel.min.js"
data-affonso="YOUR_PUBLIC_PROGRAM_ID"
data-cookie_duration="30"
></script>
</head>
<body>
{% block content %} {% endblock %}
</body>
</html>
Method 2: Dynamic Configuration
For more flexibility, use Django settings:
Add to settings.py
:
# settings.py
AFFONSO_PROGRAM_ID = 'your_program_id_here'
AFFONSO_COOKIE_DURATION = 30
Update your base template:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{% block title %}Your Site{% endblock %}</title>
<script
async
defer
src="https://affonso.io/js/pixel.min.js"
data-affonso="{{ settings.AFFONSO_PROGRAM_ID }}"
data-cookie_duration="{{ settings.AFFONSO_COOKIE_DURATION }}"
></script>
</head>
<body>
{% block content %} {% endblock %}
</body>
</html>
Next Steps
Once installed, you can access affiliate referral data and pass it to your payment provider. Learn how to integrate with your payment provider →
Testing
- Start your Django server:
python manage.py runserver
- Visit
localhost:8000?atp=test
- Check browser DevTools → Application → Cookies →
affonso_referral
- Deploy and verify tracking in your Affonso dashboard
Note: Make sure your ALLOWED_HOSTS
includes your domain when deployed.