Django
Add Loamly to your Django site
Django is a high-level Python web framework that makes it easy to build web applications. Adding Loamly takes just a single script tag in your base template.
Add the tracking script
Add the Loamly script to your base template (usually base.html) just before the closing </head> tag:
<!-- templates/base.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{% block title %}My Site{% endblock %}</title>
<!-- Loamly tracking script -->
<script src="https://app.loamly.ai/t.js?d=yourdomain.com" defer></script>
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>Replace yourdomain.com
yourdomain.com with the domain you registered in your Loamly workspace settings.Using a custom template tag
For more control, you can create a custom Django template tag. This is useful if you want to conditionally load the script or keep analytics configuration in one place.
Method 1: django-analytical
If you use django-analytical, you can add Loamly as a generic script in your settings:
# settings.py
ANALYTICAL_INTERNAL_IPS = [] # Track all visitorsThen add the script tag to your base template inside the analytical_head_top block.
Method 2: Custom template tag
Create a reusable template tag for your project:
# myapp/templatetags/loamly_tags.py
from django import template
from django.conf import settings
from django.utils.safestring import mark_safe
register = template.Library()
@register.simple_tag
def loamly_script():
domain = getattr(settings, 'LOAMLY_DOMAIN', '')
if not domain:
return ''
return mark_safe(
f'<script src="https://app.loamly.ai/t.js?d={domain}" defer></script>'
)Add your domain to settings.py:
# settings.py
LOAMLY_DOMAIN = "yourdomain.com"Then use it in your base template:
<!-- templates/base.html -->
{% load loamly_tags %}
<!DOCTYPE html>
<html lang="en">
<head>
{% loamly_script %}
</head>
<body>
{% block content %}{% endblock %}
</body>
</html>Enable AI verification (recommended)
The client-side script tracks page views, but to unlock the full power of Loamly you need server-side setup. This enables AI bot crawl detection, RFC 9421 signature verification, bot-to-click temporal matching, and prompt-to-crawl correlation with your Intelligence data. Without it, you miss the connection between AI bots crawling your site and the humans who visit after.
See the AI Visitor Verification guide for setup instructions.
Verify installation
- Run your Django development server with
python manage.py runserver - Visit your site in a browser
- Right-click → View Page Source
- Search for "loamly" to confirm the script is in the head
- Check your Loamly dashboard — the visit should appear within 2 minutes
Troubleshooting
Not seeing visits?
- Make sure the domain in the script tag matches the domain registered in your Loamly workspace settings
- Wait at least 2 minutes — data is not instant
- Check that the script is inside the
<head>tag, not the<body>
Ad blockers
- Some browser extensions may block tracking scripts. Try loading your site in an incognito/private window with extensions disabled
Debug mode
Open your browser's developer console and run:
Loamly.debug(true)This will log all tracking events to the console so you can verify everything is working.
Need help?