mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
Asking for consent implementation + documentation
This commit is contained in:
parent
456ab03a7d
commit
e50b247a87
3 changed files with 27 additions and 1 deletions
|
|
@ -42,6 +42,9 @@ 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\']);'
|
||||
ASK_FOR_CONSENT_CODE = '_paq.push([\'requireConsent\']);'
|
||||
FORGET_CONSENT_CODE = 'document.getElementById("piwik_deny_consent").addEventListener("click", () => { _paq.push(["forgetConsentGiven"]); });'
|
||||
REMEMBER_CONSENT_CODE = 'document.getElementById("piwik_give_consent").addEventListener("click", () => { _paq.push(["setConsentGiven"]); _paq.push(["rememberConsentGiven"]); });'
|
||||
|
||||
DEFAULT_SCOPE = 'page'
|
||||
|
||||
|
|
@ -96,6 +99,11 @@ class PiwikNode(Node):
|
|||
if getattr(settings, 'PIWIK_DISABLE_COOKIES', False):
|
||||
commands.append(DISABLE_COOKIES_CODE)
|
||||
|
||||
if getattr(settings, 'PIWIK_ASK_FOR_CONSENT', False):
|
||||
commands.append(ASK_FOR_CONSENT_CODE)
|
||||
commands.append(FORGET_CONSENT_CODE)
|
||||
commands.append(REMEMBER_CONSENT_CODE)
|
||||
|
||||
userid = get_identity(context, 'piwik')
|
||||
if userid is not None:
|
||||
variables_code = chain(variables_code, (
|
||||
|
|
|
|||
|
|
@ -150,3 +150,8 @@ class PiwikTagTestCase(TagTestCase):
|
|||
def test_disable_cookies(self):
|
||||
r = PiwikNode().render(Context({}))
|
||||
self.assertTrue("_paq.push(['disableCookies']);" in r, r)
|
||||
|
||||
@override_settings(PIWIK_ASK_FOR_CONSENT=True)
|
||||
def test_disable_cookies(self):
|
||||
r = PiwikNode().render(Context({}))
|
||||
self.assertTrue("_paq.push([\'requireConsent\']);" in r, r)
|
||||
|
|
|
|||
|
|
@ -145,11 +145,24 @@ set the context variable ``analytical_identity`` (for global configuration) or
|
|||
Disabling cookies
|
||||
-----------------
|
||||
|
||||
If you want to `disable cookies`_, set :data:`PIWIKI_DISABLE_COOKIES` to
|
||||
If you want to `disable cookies`_, set :data:`PIWIK_DISABLE_COOKIES` to
|
||||
:const:`True`. This is disabled by default.
|
||||
|
||||
.. _`disable cookies`: https://matomo.org/faq/general/faq_157/
|
||||
|
||||
Ask for consent
|
||||
-----------------
|
||||
|
||||
If you want to ask for consent set :data:`PIWIK_ASK_FOR_CONSENT` to
|
||||
:const:`True`. This is disabled by default.
|
||||
|
||||
To ask the visitor for consent just create DOM elements with the following id's:
|
||||
|
||||
`piwik_deny_consent` - id for DOM element to click, if the user denies consent
|
||||
`piwik_give_consent` - id for DOM element to click, if the user gives consent
|
||||
|
||||
.. _`asking for consent`: https://developer.matomo.org/guides/tracking-javascript-guide#asking-for-consent
|
||||
|
||||
Internal IP addresses
|
||||
---------------------
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue