[Django]-Track django admin with Google Analytics

4👍

There are a number of ways you can do it

  • Extend django.contrib.admin.templates.admin.base.html template in your project and then add Analytical code to this extended base.html template.
{% extends 'admin/base_site.html' %}
{% load static %}  
{% block extrahead %}
{{ block.super }} 
google analytics code here
{% endblock %}
  • Add Google Analytics code to custom JS and then add this JS as Media to ModelAdmin to track model admin. For this approach, you have to add this custom js to every modeladmin. This could be useful if you want to track a different model under the different Google Analytics account.

Leave a comment