In today’s data-driven world, understanding how visitors interact with your website is essential. Google Analytics (GA) provides deep insights into traffic, behavior, and conversions. If you’re running a Django-based CMS, integrating Google Analytics directly into your system will allow site staff to view analytics without leaving the CMS dashboard.
In this guide, we’ll cover how to:
Set up Google Analytics for your Django site
Add the GA tracking code to your templates
Use the Google Analytics Reporting API to pull analytics data
Build a Django admin/staff dashboard to view site analytics
1. Prerequisites
Before we dive in, make sure you have:
A working Django project (CMS or custom-built)
Google Analytics 4 (GA4) property created for your site
Python 3.8+
A service account with API credentials from Google Cloud
2. Adding Google Analytics Tracking to Django Templates
The simplest way to start collecting data is by embedding the inside your Django base template.
