Django

Add DataSaaS analytics to your Django application. You can add the script directly to your base template or use a settings-driven approach.

Method 1: Base Template

Add the tracking script to your templates/base.html inside the <head> section:

<!-- templates/base.html -->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>{% block title %}My Site{% endblock %}</title>

    {% block head %}
    <!-- DataSaaS Analytics -->
    <script
      defer
      data-website-id="ds_YOUR_WEBSITE_ID"
      data-domain="yourdomain.com"
      src="https://datasaas.co/js/script.min.js"
    ></script>
    {% endblock %}
  </head>
  <body>
    {% block content %}{% endblock %}
  </body>
</html>

Method 2: Django Settings

Store your Website ID in settings.py and reference it in your template with a context processor.

First, add the setting to settings.py:

# settings.py
DATASAAS_WEBSITE_ID = "ds_YOUR_WEBSITE_ID"

Method 2 (continued): Template

Then use the setting in your base template:

<!-- templates/base.html -->
<script
  defer
  data-website-id="{{ settings.DATASAAS_WEBSITE_ID }}"
  data-domain="yourdomain.com"
  src="https://datasaas.co/js/script.min.js"
></script>

Verify

Visit your website, then open the DataSaaS dashboard. You should see your visit appear within a few seconds.