Background
⌘K

Django Integration

Learn how to integrate Affonso affiliate tracking into your Django application.

Silvestro
Written by Silvestro
Updated more than a month ago

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.

  1. Open or create your base template at templates/base.html
  2. Add the tracking script in the <head> section
  3. 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

  1. Start your Django server: python manage.py runserver
  2. Visit localhost:8000?atp=test
  3. Check browser DevTools → ApplicationCookiesaffonso_referral
  4. 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 →

Was this article helpful?

If you still need help, our support team is here for you.

Contact Support
bg

Ready to Scale Your SaaS?

Affonso is the easiest way to launch your own affiliate program. We take care of the technical stuff, so you can focus on growing your business.