Django

Add attribu.tech to your Django project.

Add the script to your base template

Open your base template (usually templates/base.html) and add the tracking script inside the <head> tag:

<!-- templates/base.html -->
<head>
  ...
  <script
    defer
    data-website-id="YOUR_SITE_ID"
    data-domain="yourdomain.com"
    src="https://attribu.tech/js/script.js"
  ></script>
</head>
Replace YOUR_SITE_ID with your actual Website ID from your attribu.tech dashboard. Replace yourdomain.com with your site's root domain.

This works with any Django template that extends base.html. The script loads on every page automatically.

Optional: Use Django settings

If you prefer to keep configuration in your Django settings instead of hardcoding values in the template:

# settings.py
ATTRIBU_SITE_ID = "YOUR_SITE_ID"
ATTRIBU_DOMAIN = "yourdomain.com"

Create a context processor to make these values available in all templates:

# yourapp/context_processors.py
from django.conf import settings

def attribu(request):
    return {
        "attribu_site_id": settings.ATTRIBU_SITE_ID,
        "attribu_domain": settings.ATTRIBU_DOMAIN,
    }

Register it in your settings:

# settings.py
TEMPLATES = [
    {
        ...
        "OPTIONS": {
            "context_processors": [
                ...
                "yourapp.context_processors.attribu",
            ],
        },
    },
]

Then use the variables in your template:

<!-- templates/base.html -->
<script
  defer
  data-website-id="{{ attribu_site_id }}"
  data-domain="{{ attribu_domain }}"
  src="https://attribu.tech/js/script.js"
></script>

Verify installation

  1. Start your Django development server and visit your site.
  2. Open your browser's Developer Tools and check the Network tab for a request to /js/script.js.
  3. Check your attribu.tech dashboard - a pageview should appear within a few minutes.
The tracking script ignores localhost by default. Deploy to a public URL or enable localhost debugging in your dashboard to test locally.

For available script configuration options, see script options.

What's next

Copied