Skip to main content

Django Google Analytics app allowing for server side/non-js tracking.

Project description

Django Google Analytics brings the power of server side/non-js Google Analytics to your Django projects

Installation

  1. Install django-google-analytics-app from PyPI or add to your Python path some other way.

  2. Add google_analytics to your INSTALLED_APPS setting.

  3. Add URL include to your project’s urls.py file:

    re_path('djga/', include('google_analytics.urls')),
  4. 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.

  5. 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/', ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-google-analytics-app-6.0.0.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

django_google_analytics_app-6.0.0-py2.py3-none-any.whl (13.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-google-analytics-app-6.0.0.tar.gz.

File metadata

File hashes

Hashes for django-google-analytics-app-6.0.0.tar.gz
Algorithm Hash digest
SHA256 88fb1a057182e0aad5a653717a44f8880c8916d6b606b2f625309fde3afb1e02
MD5 fa0380c66d5a91cfe17ddecb50bd677c
BLAKE2b-256 43c3887ba3e7806cec2596bd723c42f3efc372398f5e544e9f76a5ff283d00b3

See more details on using hashes here.

File details

Details for the file django_google_analytics_app-6.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_google_analytics_app-6.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 badefb910a46f09040ab24f652497a58adcae07ca1526869cd34ee8632fce729
MD5 96beeebec2e24fa70e57ee0b5de560fa
BLAKE2b-256 7fcc45f30eddd0a4e2eaacab22149858c4b6c39d3ef90bd05e0dce0f1358e6d2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page