mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
92 lines
3 KiB
ReStructuredText
92 lines
3 KiB
ReStructuredText
==========================
|
|
Features and customization
|
|
==========================
|
|
|
|
The django-analytical application sets up basic tracking without any
|
|
further configuration. This page describes extra features and ways in
|
|
which behavior can be customized.
|
|
|
|
|
|
.. _internal-ips:
|
|
|
|
Internal IP addresses
|
|
=====================
|
|
|
|
Visits by the website developers or internal users are usually not
|
|
interesting. The django-analytical will comment out the service
|
|
initialization code if the client IP address is detected as one from the
|
|
:data:`ANALYTICAL_INTERNAL_IPS` setting. The default value for this
|
|
setting is :data:`INTERNAL_IPS`.
|
|
|
|
Example:
|
|
|
|
.. code-block:: python
|
|
|
|
ANALYTICAL_INTERNAL_IPS = ['192.168.1.45', '192.168.1.57']
|
|
|
|
.. note::
|
|
|
|
The template tags can only access the visitor IP address if the
|
|
HTTP request is present in the template context as the
|
|
``request`` variable. For this reason, the
|
|
:data:`ANALYTICAL_INTERNAL_IPS` setting only works if you add this
|
|
variable to the context yourself when you render the template, or
|
|
you use the ``RequestContext`` and add
|
|
``'django.core.context_processors.request'`` to the list of
|
|
context processors in the ``TEMPLATE_CONTEXT_PROCESSORS``
|
|
setting.
|
|
|
|
|
|
.. _identifying-visitors:
|
|
|
|
Identifying authenticated users
|
|
===============================
|
|
|
|
Some analytics services can track individual users. If the visitor is
|
|
logged in through the standard Django authentication system and the
|
|
current user is accessible in the template context, the username can be
|
|
passed to the analytics services that support identifying users. This
|
|
feature is configured by the :data:`ANALYTICAL_AUTO_IDENTIFY` setting
|
|
and is enabled by default. To disable:
|
|
|
|
.. code-block:: python
|
|
|
|
ANALYTICAL_AUTO_IDENTIFY = False
|
|
|
|
.. note::
|
|
|
|
The template tags can only access the visitor username if the
|
|
Django user is present in the template context either as the
|
|
``user`` variable, or as an attribute on the HTTP request in the
|
|
``request`` variable. Use a
|
|
:class:`~django.template.RequestContext` to render your
|
|
templates and add
|
|
``'django.contrib.auth.context_processors.auth'`` or
|
|
``'django.core.context_processors.request'`` to the list of
|
|
context processors in the :data:`TEMPLATE_CONTEXT_PROCESSORS`
|
|
setting. (The first of these is added by default.)
|
|
Alternatively, add one of the variables to the context yourself
|
|
when you render the template.
|
|
|
|
|
|
|
|
Changing the identity
|
|
*********************
|
|
|
|
If you want to change identity of the user, that different providers are
|
|
sending, you can do it by setting the `analyitcal_identity` context variable::
|
|
|
|
context = RequestContext({'analytical_identity': user.uuid})
|
|
return some_template.render(context)
|
|
|
|
or in the template:
|
|
|
|
.. code-block:: django
|
|
|
|
{% with analytical_identity=request.user.uuid|default:None %}
|
|
{% analytical_head_top %}
|
|
{% endwith %}
|
|
|
|
If you want to change the identity only for specific provider, use the
|
|
`*_identity` context variable, where `*` is prefix specified on the provider
|
|
page.
|