Django Google Analytics brings the power of server side/non-js Google Analytics to your Django projects
Installation
Install django-google-analytics-app from PyPI or add to your Python path some other way.
Add google_analytics to your INSTALLED_APPS setting.
Add URL include to your project’s urls.py file:
re_path('djga/', include('google_analytics.urls')),Specify a Google Analytics tracking code, i.e.:
GOOGLE_ANALYTICS = { 'google_analytics_id': 'UA-000000-2', }where UA-000000-2 is your unique tracking code.
If you intend tracking through middleware and Celery remember to install Celery and run its worker process.
Usage
There are two ways to add tracking to your pages.
1. HTML tag
Using <img/> and sticking it in your base.html:
{% load google_analytics_tags %}
<div style="display:none">
<img src="{% google_analytics %}" width="0" height="0" />
</div>
2. Middleware + Celery
Using Django’s middleware, you can process every request and use Celery to make the request to Google Analytics:
MIDDLEWARE = [
'google_analytics.middleware.GoogleAnalyticsMiddleware',
]
You have to add google_analytics to your CELERY_IMPORTS:
CELERY_IMPORTS = ('google_analytics.tasks')
You can also specify paths that will be excluded when tracking:
GOOGLE_ANALYTICS_IGNORE_PATH = ['/health/', ]
Release files for django-google-analytics-app 6.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django-google-analytics-app-6.0.0.tar.gz | 12.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_google_analytics_app-6.0.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 26.3 kB
Release files / django-google-analytics-app-6.0.0.tar.gz
| Download URL | django-google-analytics-app-6.0.0.tar.gz |
|---|---|
| Size | 12.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88fb1a057182e0aad5a653717a44f8880c8916d6b606b2f625309fde3afb1e02
|
|
BLAKE2b-256 checksum How to use checksums |
43c3887ba3e7806cec2596bd723c42f3efc372398f5e544e9f76a5ff283d00b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.15
|
Release files / django_google_analytics_app-6.0.0-py2.py3-none-any.whl
| Download URL | django_google_analytics_app-6.0.0-py2.py3-none-any.whl |
|---|---|
| Size | 13.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
badefb910a46f09040ab24f652497a58adcae07ca1526869cd34ee8632fce729
|
|
BLAKE2b-256 checksum How to use checksums |
7fcc45f30eddd0a4e2eaacab22149858c4b6c39d3ef90bd05e0dce0f1358e6d2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.15
|