Django's template inheritance system makes it easy to add tracking scripts globally across your entire application using a base template that all pages extend.
Add tracking script to your Django app
Django's recommended approach is to add the tracking script to your base template, which serves as the foundation for all other templates in your application.
- Open or create your base template at
templates/base.html
- Add the tracking script in the
<head>
section - Ensure all your page templates extend this base template:
<!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="YOUR_COOKIE_DURATION"
></script>
</head>
<body>
{% block content %} {% endblock %}
</body>
</html>
Find your Program ID →
Alternative: Store your Program ID in settings.py
and reference it in your template using {{ settings.AFFONSO_PROGRAM_ID }}
.
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.
Next Steps
Once installed, you can access affiliate referral data and pass it to your payment provider. Connect your payment provider →