/django-segment

Primary LanguagePythonMIT LicenseMIT

django-segment

This a project to setup segment with django.

How to install

Use pip:

pip install django-segment

Or use a requirement file.

Settings

You must configure few things like the segment write key. You can configure four variable in your settings file, the SEGMENT_WRITE_KEY, SEGMENT_DEBUG, SEGMENT_SEND and SEGMENT_ON_ERROR, SEGMENT_WRITE_KEY is required others is optional. For example:

DEBUG = True
SEGMENT_WRITE_KEY = 'my_write_key'
SEGMENT_DEBUG = DEBUG

Template

First add the context processors in your settings:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'segment.context_processors.segment'
            ],
        },
    },
]

Then you can include the segment template in your base template:

{% include "_segment.html" %}

Enjoy folks.