mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
Add PIWIK_DISABLE_COOKIES.
This option disables cookies -- it's off by default.
This commit is contained in:
parent
ac66302ddc
commit
7b3c107758
3 changed files with 21 additions and 1 deletions
|
|
@ -8,6 +8,7 @@ from collections import namedtuple
|
|||
from itertools import chain
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.template import Library, Node, TemplateSyntaxError
|
||||
|
||||
from analytical.utils import (is_internal_ip, disable_html,
|
||||
|
|
@ -24,6 +25,7 @@ TRACKING_CODE = """
|
|||
<script type="text/javascript">
|
||||
var _paq = _paq || [];
|
||||
%(variables)s
|
||||
%(commands)s
|
||||
_paq.push(['trackPageView']);
|
||||
_paq.push(['enableLinkTracking']);
|
||||
(function() {
|
||||
|
|
@ -39,6 +41,7 @@ TRACKING_CODE = """
|
|||
|
||||
VARIABLE_CODE = '_paq.push(["setCustomVariable", %(index)s, "%(name)s", "%(value)s", "%(scope)s"]);' # noqa
|
||||
IDENTITY_CODE = '_paq.push(["setUserId", "%(userid)s"]);'
|
||||
DISABLE_COOKIES_CODE = '_paq.push([\'disableCookies\']);'
|
||||
|
||||
DEFAULT_SCOPE = 'page'
|
||||
|
||||
|
|
@ -89,6 +92,10 @@ class PiwikNode(Node):
|
|||
variables_code = (VARIABLE_CODE % PiwikVar(*var)._asdict()
|
||||
for var in complete_variables)
|
||||
|
||||
commands = []
|
||||
if getattr(settings, 'PIWIK_DISABLE_COOKIES', False):
|
||||
commands.append(DISABLE_COOKIES_CODE)
|
||||
|
||||
userid = get_identity(context, 'piwik')
|
||||
if userid is not None:
|
||||
variables_code = chain(variables_code, (
|
||||
|
|
@ -98,7 +105,8 @@ class PiwikNode(Node):
|
|||
html = TRACKING_CODE % {
|
||||
'url': self.domain_path,
|
||||
'siteid': self.site_id,
|
||||
'variables': '\n '.join(variables_code)
|
||||
'variables': '\n '.join(variables_code),
|
||||
'commands' : '\n '.join(commands)
|
||||
}
|
||||
if is_internal_ip(context, 'PIWIK'):
|
||||
html = disable_html(html, 'Piwik')
|
||||
|
|
|
|||
|
|
@ -145,3 +145,8 @@ class PiwikTagTestCase(TagTestCase):
|
|||
msg = 'Incorrect Piwik user tracking rendering.\nFound:\n%s\nIn:\n%s'
|
||||
var_code = '_paq.push(["setUserId", "BDFL"]);'
|
||||
self.assertNotIn(var_code, r, msg % (var_code, r))
|
||||
|
||||
@override_settings(PIWIK_DISABLE_COOKIES=True)
|
||||
def test_disable_coolies(self):
|
||||
r = PiwikNode().render(Context({}))
|
||||
self.assertTrue("_paq.push(['disableCookies']);" in r, r)
|
||||
|
|
|
|||
|
|
@ -142,6 +142,13 @@ set the context variable ``analytical_identity`` (for global configuration) or
|
|||
|
||||
.. _`track individual users`: http://developer.piwik.org/guides/tracking-javascript-guide#user-id
|
||||
|
||||
Disabling cookies
|
||||
-----------------
|
||||
|
||||
If you want to `disable cookies`_, set :data:`PIWIKI_DISABLE_COOKIES` to
|
||||
:const:`True`. This is disabled by default.
|
||||
|
||||
.. _`disable cookies`: https://matomo.org/faq/general/faq_157/
|
||||
|
||||
Internal IP addresses
|
||||
---------------------
|
||||
|
|
|
|||
Loading…
Reference in a new issue