Jetrack

Jetrack

Installation Guides

Django Installation

Install Jetrack in your Django application

Jetrack works great with Django. Add the tracking script to your base template to track all pages across your site.

Installation

Add the tracking script to your base Django template, which other templates extend.

Step 1: Locate Your Base Template

In most Django projects, the base template is at:

  • templates/base.html
  • Or your_app/templates/base.html

Step 2: Add the Script

Open your base template and add the tracking script in the <head> section:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}{{ site_name }}{% endblock %}</title>
    
    <!-- Jetrack -->
    <script
        async
        defer
        data-website-id="your-unique-id"
        src="https://analytics.brandjet.ai/script.js">
    </script>
    
    {% block extra_head %}{% endblock %}
</head>
<body>
    {% block content %}{% endblock %}
</body>
</html>

Using Environment Variables

For better security and multi-environment support:

Step 1: Add to .env or settings.py

Using python-decouple or similar:

# .env
BRANDJET_WEBSITE_ID=your-unique-id

Or directly in settings.py:

# settings.py
BRANDJET_WEBSITE_ID = 'your-unique-id'

Step 2: Update Your 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 %}My Site{% endblock %}</title>
    
    {% if BRANDJET_WEBSITE_ID %}
        <!-- Jetrack -->
        <script
            async
            defer
            data-website-id="{{ BRANDJET_WEBSITE_ID }}"
            src="https://analytics.brandjet.ai/script.js">
        </script>
    {% endif %}
</head>
<body>
    {% block content %}{% endblock %}
</body>
</html>

Step 3: Add Context Processor

Create your_app/context_processors.py:

from django.conf import settings

def brandjet(request):
    return {
        'BRANDJET_WEBSITE_ID': getattr(settings, 'BRANDJET_WEBSITE_ID', None)
    }

Add to settings.py:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        ' OPTIONS': {
            'context_processors': [
                # ... existing processors
                'your_app.context_processors.brandjet',
            ],
        },
    },
]

Production Only

To load the script only in production:

{% if not DEBUG %}
    <!-- Jetrack -->
    <script
        async
        defer
        data-website-id="{{ BRANDJET_WEBSITE_ID }}"
        src="https://analytics.brandjet.ai/script.js">
    </script>
{% endif %}

Django REST Framework + SPA

If you're using Django as an API backend with a JavaScript frontend (React, Vue, etc.), add the tracking script to your SPA's index.html instead.

Template Block for Custom Head Content

Create a flexible template structure:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}My Site{% endblock %}</title>
    
    <!-- Analytics -->
    {% block analytics %}
        <script
            async
            defer
            data-website-id="{{ BRANDJET_WEBSITE_ID }}"
            src="https://analytics.brandjet.ai/script.js">
        </script>
    {% endblock %}
    
    {% block extra_head %}{% endblock %}
</head>
<body>
    {% block content %}{% endblock %}
</body>
</html>

Testing

  1. Add the tracking script to your base template
  2. Run your Django development server: python manage.py runserver
  3. Visit http://localhost:8000
  4. Enable localhost debugging in BrandJet settings
  5. Check your dashboard for visitor data

Troubleshooting

Script Not Appearing

  • Check that your pages extend the base template
  • Verify the template path is correct
  • Clear Django's template cache if using caching

Not Tracking

  • Verify your website ID is correct
  • Check browser console for errors
  • View page source to confirm script is present
  • Ensure ad blockers are disabled when testing

Context Variable Not Available

  • Verify the context processor is added to settings
  • Restart your Django development server
  • Check that BRANDJET_WEBSITE_ID is set in settings

Django Channels / WebSockets

For Django Channels applications, the tracking script works normally for HTTP pages. WebSocket connections are not tracked by default.

Next Steps

On this page