Skip to main content

Server side GA4 tracking

Project description

Install

pip install django-ga4-serverside

Settings

INSTALLED_APPS = [
        # …
        'django_ga4_serverside',
]

MIDDLEWARE = [
        # …
        'django_ga4_serverside.middleware.TrackingMiddleware',
]

GA4_ID = 'G-XXXXXXXXXX'
GA4_SECRET = 'XXXXXXXXXX-XXXXXXXXXXX'
GA4_DEBUG = False

Advanced settings

GA4_IGNORE_URL_REGEX - allows to configure ignored URLs

GA4_PROCESS_ANALYTICS - callback used to modify payload. Default implementation configures client_id from cookies. Default implementation:

def process_analytics(context):
        client_id, created = get_or_create_client_id(context.request)
        if created:
                store_user_cookie(context.response, client_id)
        store_parameters(context.request, client_id=client_id)

GA4_GENERATE_PAYLOAD - callback to generate payload

GA4_SHOULD_TRACK_CALLBACK - callback to filter tracked requests

API

Storing custom events

from django_ga4_serverside.utils import store_event

# inside view

store_event('custom_event', {'custom': 'property'})

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_ga4_serverside-0.0.2.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distribution

django_ga4_serverside-0.0.2-py3-none-any.whl (7.6 kB view hashes)

Uploaded Python 3

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