Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ask for consent - Matomo (Piwik) #142

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
8 changes: 8 additions & 0 deletions analytical/templatetags/piwik.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
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\']);'
bittner marked this conversation as resolved.
Show resolved Hide resolved
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'

Expand Down Expand Up @@ -96,6 +99,11 @@ def render(self, context):
if getattr(settings, 'PIWIK_DISABLE_COOKIES', False):
commands.append(DISABLE_COOKIES_CODE)

if getattr(settings, 'PIWIK_ASK_FOR_CONSENT', False):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still says, PIWIK in the constant name. Shouldn't it say MATOMO?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this code shouldn't go here at all. As mentioned by my other comments.

commands.append(ASK_FOR_CONSENT_CODE)
commands.append(FORGET_CONSENT_CODE)
commands.append(REMEMBER_CONSENT_CODE)
jcassee marked this conversation as resolved.
Show resolved Hide resolved

userid = get_identity(context, 'piwik')
if userid is not None:
variables_code = chain(variables_code, (
Expand Down
5 changes: 5 additions & 0 deletions analytical/tests/test_tag_piwik.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,8 @@ def test_disable_usertrack(self):
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)
bittner marked this conversation as resolved.
Show resolved Hide resolved
15 changes: 14 additions & 1 deletion docs/services/piwik.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
bittner marked this conversation as resolved.
Show resolved Hide resolved
: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.
bittner marked this conversation as resolved.
Show resolved Hide resolved

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
bittner marked this conversation as resolved.
Show resolved Hide resolved

.. _`asking for consent`: https://developer.matomo.org/guides/tracking-javascript-guide#asking-for-consent

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we remove the documentation for Piwiki all together, maybe just showing a hint on the new location and the reason for it? I don't think it makes sense to continue to maintain, let alone extend, it.

Internal IP addresses
---------------------

Expand Down