matomo: detect bad tracking for hotjar and xiti (#45488)
This commit is contained in:
parent
fd1c99f073
commit
9aa26aca45
|
@ -71,15 +71,15 @@
|
|||
</p>
|
||||
{% else %}
|
||||
{% if tracking_js != '' %}
|
||||
{% if cnil_ack_level == 'success' %}
|
||||
{% if cnil_ack_level == 'excellent' %}
|
||||
<div class="successnotice">
|
||||
{% trans "Excellent respect of user rights." %}
|
||||
</div>
|
||||
{% elif cnil_ack_level == 'warning' %}
|
||||
{% elif cnil_ack_level == 'good' %}
|
||||
<div class="warningnotice">
|
||||
{% trans "Good respect of user rights." %}
|
||||
</div>
|
||||
{% elif cnil_ack_level == 'error' %}
|
||||
{% elif cnil_ack_level == 'bad' %}
|
||||
<div class="errornotice">
|
||||
{% trans "No respect of user rights." %}
|
||||
</div>
|
||||
|
|
|
@ -75,7 +75,7 @@ def put_tracking_js(tracking_js):
|
|||
variable1 = get_variable('cnil_compliant_visits_tracking_js')
|
||||
variable2 = get_variable('visits_tracking_js')
|
||||
if tracking_js != '':
|
||||
if compute_cnil_acknowledgment_level(tracking_js) != 'error':
|
||||
if compute_cnil_acknowledgment_level(tracking_js) != 'bad':
|
||||
variable1.value = tracking_js
|
||||
variable1.save()
|
||||
variable2.delete()
|
||||
|
@ -312,14 +312,21 @@ def upgrade_javascript_tag(matomo, id_site):
|
|||
enhanced_tag = '\n'.join(lines)
|
||||
return enhanced_tag
|
||||
|
||||
|
||||
def compute_cnil_acknowledgment_level(tracking_js):
|
||||
if tracking_js.find('google') != -1:
|
||||
# google reference found into javascript
|
||||
return 'error'
|
||||
if tracking_js.find('getOriginalVisitorCookieTimeout') == -1:
|
||||
# can't find cookie's life time extension prevention
|
||||
return 'warning'
|
||||
return 'success'
|
||||
bad_tracker_words = [
|
||||
'google',
|
||||
'hotjar',
|
||||
'ATInternet.Tracker.Tag',
|
||||
]
|
||||
for word in bad_tracker_words:
|
||||
if word in tracking_js:
|
||||
return 'bad'
|
||||
if 'paq.push' in tracking_js and 'getOriginalVisitorCookieTimeout' in tracking_js:
|
||||
# piwik/matomo and life time extension prevention
|
||||
return 'excellent'
|
||||
return 'good'
|
||||
|
||||
|
||||
def auto_configure_matomo(matomo):
|
||||
"""main function"""
|
||||
|
|
|
@ -714,15 +714,15 @@ def test_compute_cnil_acknowledgment_level():
|
|||
warning_content = force_text(JAVASCRIPT_TAG)
|
||||
|
||||
# can't find cookie's life time extension prevention
|
||||
assert compute_cnil_acknowledgment_level(warning_content) == 'warning'
|
||||
assert compute_cnil_acknowledgment_level(warning_content) == 'good'
|
||||
|
||||
# ok
|
||||
success_content = warning_content + '\n...getOriginalVisitorCookieTimeout...'
|
||||
assert compute_cnil_acknowledgment_level(success_content) == 'success'
|
||||
success_content = warning_content + '\npaq.push(...) ...getOriginalVisitorCookieTimeout...'
|
||||
assert compute_cnil_acknowledgment_level(success_content) == 'excellent'
|
||||
|
||||
# google reference found into javascript
|
||||
error_content = success_content + '\n...google...'
|
||||
assert compute_cnil_acknowledgment_level(error_content) == 'error'
|
||||
assert compute_cnil_acknowledgment_level(error_content) == 'bad'
|
||||
|
||||
def test_get_tracking_js():
|
||||
"""read previous tracking JS from hobo variables"""
|
||||
|
@ -781,7 +781,7 @@ def test_upgrade_javascript_tag(mocked_post):
|
|||
assert javascript_tag.find('<script') == -1
|
||||
assert javascript_tag.find('script>') == -1
|
||||
assert javascript_tag == ENHANCED_JAVASCRIPT_TAG
|
||||
assert compute_cnil_acknowledgment_level(javascript_tag) == 'success'
|
||||
assert compute_cnil_acknowledgment_level(javascript_tag) == 'excellent'
|
||||
|
||||
@mock.patch('requests.post')
|
||||
def test_auto_configure_matomo(mocked_post):
|
||||
|
|
Loading…
Reference in New Issue