mirror of
https://github.com/jazzband/django-analytical.git
synced 2026-03-16 22:20:25 +00:00
Compare commits
2 commits
b175ef35a4
...
dca164734c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dca164734c | ||
|
|
e6f12719cc |
5 changed files with 57 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
* Fix GA gtag user_id setup and add support for custom dimensions (Erick Massip)
|
||||
* Change spelling of "JavaScript" across all files in docstrings and docs
|
||||
(Peter Bittner)
|
||||
* Ask site visitors for consent when using Matomo (Julian Haluska & Ronard Luna)
|
||||
|
||||
Version 3.2.0
|
||||
-------------
|
||||
|
|
|
|||
|
|
@ -46,6 +46,30 @@ VARIABLE_CODE = (
|
|||
IDENTITY_CODE = '_paq.push(["setUserId", "%(userid)s"]);'
|
||||
DISABLE_COOKIES_CODE = "_paq.push(['disableCookies']);"
|
||||
|
||||
GIVE_CONSENT_CLASS = 'matomo_give_consent'
|
||||
REMOVE_CONSENT_CLASS = 'matomo_remove_consent'
|
||||
ASK_FOR_CONSENT_CODE = """
|
||||
_paq.push(['requireConsent']);
|
||||
|
||||
var elements = document.getElementsByClassName("{}");
|
||||
for (var i = 0; i < elements.length; i++) {{
|
||||
elements[i].addEventListener("click",
|
||||
function () {{
|
||||
_paq.push(["forgetConsentGiven"]);
|
||||
}}
|
||||
);
|
||||
}}
|
||||
|
||||
var elements = document.getElementsByClassName("{}");
|
||||
for (var i = 0; i < elements.length; i++) {{
|
||||
elements[i].addEventListener("click",
|
||||
function () {{
|
||||
_paq.push(["rememberConsentGiven"]);
|
||||
}}
|
||||
);
|
||||
}}
|
||||
""".format(REMOVE_CONSENT_CLASS, GIVE_CONSENT_CLASS)
|
||||
|
||||
DEFAULT_SCOPE = 'page'
|
||||
|
||||
MatomoVar = namedtuple('MatomoVar', ('index', 'name', 'value', 'scope'))
|
||||
|
|
@ -103,6 +127,9 @@ class MatomoNode(Node):
|
|||
if getattr(settings, 'MATOMO_DISABLE_COOKIES', False):
|
||||
commands.append(DISABLE_COOKIES_CODE)
|
||||
|
||||
if getattr(settings, 'MATOMO_ASK_FOR_CONSENT', False):
|
||||
commands.append(ASK_FOR_CONSENT_CODE)
|
||||
|
||||
userid = get_identity(context, 'matomo')
|
||||
if userid is not None:
|
||||
variables_code = chain(
|
||||
|
|
|
|||
|
|
@ -149,6 +149,28 @@ If you want to `disable cookies`_, set :data:`MATOMO_DISABLE_COOKIES` to
|
|||
|
||||
.. _`disable cookies`: https://matomo.org/faq/general/faq_157/
|
||||
|
||||
Ask for consent
|
||||
---------------
|
||||
|
||||
If you do not want to track visitors without permission, you can `ask for consent`_ first.
|
||||
To enable this, set :data:`MATOMO_ASK_FOR_CONSENT` to :const:`True`.
|
||||
By default, no consent for tracking is needed (i.e. :const:`False`).
|
||||
|
||||
To give and remove consent in your page, create DOM elements with the following classes:
|
||||
|
||||
`matomo_give_consent` - class name for element to click when visitors want to **give** consent
|
||||
`matomo_remove_consent` - class name for element to click when visitors want to **remove** consent
|
||||
|
||||
Examples::
|
||||
|
||||
# button to allow tracking
|
||||
<button class="matomo_give_consent">Track me!</button>
|
||||
|
||||
# button to remove tracking consent
|
||||
<button class="matomo_remove_consent">Don't track me anymore!</button>
|
||||
|
||||
.. _`asking for consent`: https://developer.matomo.org/guides/tracking-javascript-guide#asking-for-consent
|
||||
|
||||
Internal IP addresses
|
||||
---------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ authors = [
|
|||
{name = "Tinnet Coronam", email = "tinnet@coronam.net"},
|
||||
{name = "Uros Trebec", email = "uros@trebec.org"},
|
||||
{name = "Walter Renner", email = "walter.renner@me.com"},
|
||||
{name = "Julian Haluska", email = "mail@julianhaluska.de"},
|
||||
{name = "Ronard Luna", email = "rlunag@proton.me"},
|
||||
]
|
||||
maintainers = [
|
||||
{name = "Jazzband community", email = "jazzband-bot@users.noreply.github.com"},
|
||||
|
|
|
|||
|
|
@ -159,3 +159,8 @@ class MatomoTagTestCase(TagTestCase):
|
|||
def test_disable_cookies(self):
|
||||
r = MatomoNode().render(Context({}))
|
||||
assert "_paq.push(['disableCookies']);" in r
|
||||
|
||||
@override_settings(MATOMO_ASK_FOR_CONSENT=True)
|
||||
def test_ask_for_consent(self):
|
||||
r = MatomoNode().render(Context({}))
|
||||
self.assertTrue("_paq.push(['requireConsent']);" in r, r)
|
||||
|
|
|
|||
Loading…
Reference in a new issue