Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gdpr_consent/dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions gdpr_consent/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ function onRender(event: Event): void {
}
)
}
if (data.args['matomo']) {
klaroConfig.services.push(
{
name: 'matomo',
purposes: ['analytics'],
onAccept: callback,
onDecline: callback,
}
)
}

// Create a new script element
var script = document.createElement('script')
Expand Down
21 changes: 21 additions & 0 deletions hooks/hook-analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ def piwik_pro_body(piwik_tag):
"""


def matomo_head(matomo_url, matomo_tag):
return f"""
<!-- Matomo Tag Manager -->
<script>
var _mtm = window._mtm = window._mtm || [];
_mtm.push({{'mtm.startTime': (new Date().getTime()), 'event': 'mtm.Start'}});
(function() {{
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src='{matomo_url}/container_{matomo_tag}.js'; s.parentNode.insertBefore(g,s);
}})();
</script>
<!-- End Matomo Tag Manager -->
"""


if __name__ == '__main__':

# Load configuration
Expand All @@ -79,6 +94,12 @@ def piwik_pro_body(piwik_tag):
piwik_tag = settings['analytics']['piwik-pro']['tag']
index = patch_body(index, piwik_pro_body(piwik_tag))

# Configure matomo tag manager
if settings['analytics']['matomo']['enabled']:
matomo_url = settings['analytics']['matomo']['url']
matomo_tag = settings['analytics']['matomo']['tag']
index = patch_head(index, matomo_head(matomo_url, matomo_tag))

# Save index.html
with open(index_path, 'w') as f:
f.write(index)
7 changes: 6 additions & 1 deletion settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
"tag": ""
},
"piwik-pro": {
"enabled": false,
"tag": ""
},
"matomo": {
"enabled": true,
"tag": "57690c44-d635-43b0-ab43-f8bd3064ca06"
"url": "https://cdn.matomo.cloud/openms.matomo.cloud",
"tag": "yDGK8bfY"
}
},
"online_deployment": false,
Expand Down
5 changes: 3 additions & 2 deletions src/common/captcha_.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,13 @@ def captcha_control():
# Check if consent for tracking was given
ga = st.session_state.settings['analytics']['google-analytics']['enabled']
pp = st.session_state.settings['analytics']['piwik-pro']['enabled']
if (ga or pp) and (st.session_state.tracking_consent is None):
mt = st.session_state.settings['analytics']['matomo']['enabled']
if (ga or pp or mt) and (st.session_state.tracking_consent is None):
consent_component = st_components.declare_component("gdpr_consent", path=Path("gdpr_consent"))
with st.spinner():
# Ask for consent
st.session_state.tracking_consent = consent_component(
google_analytics=ga, piwik_pro=pp
google_analytics=ga, piwik_pro=pp, matomo=mt
)
if st.session_state.tracking_consent is None:
# No response by user yet
Expand Down
17 changes: 17 additions & 0 deletions src/common/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,23 @@ def page_setup(page: str = "") -> dict[str, Any]:
width=1,
height=1,
)
if (st.session_state.settings["analytics"]["matomo"]["enabled"]) and (
st.session_state.tracking_consent["matomo"] == True
):
Comment on lines +408 to +410
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Replace == True equality comparison with a truthiness check (Ruff E712).

Ruff flags this as E712. The same pattern exists for the pre-existing GA and Piwik Pro blocks (lines 368, 386), but should be fixed here in the new code.

🔧 Proposed fix
-        if (st.session_state.settings["analytics"]["matomo"]["enabled"]) and (
-            st.session_state.tracking_consent["matomo"] == True
-        ):
+        if (st.session_state.settings["analytics"]["matomo"]["enabled"]) and (
+            st.session_state.tracking_consent["matomo"]
+        ):
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (st.session_state.settings["analytics"]["matomo"]["enabled"]) and (
st.session_state.tracking_consent["matomo"] == True
):
if (st.session_state.settings["analytics"]["matomo"]["enabled"]) and (
st.session_state.tracking_consent["matomo"]
):
🧰 Tools
🪛 Ruff (0.15.1)

[error] 409-409: Avoid equality comparisons to True; use st.session_state.tracking_consent["matomo"]: for truth checks

Replace with st.session_state.tracking_consent["matomo"]

(E712)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/common/common.py` around lines 408 - 410, The conditional uses an
explicit equality check "st.session_state.tracking_consent['matomo'] == True"
which triggers Ruff E712; change it to a truthiness check so the condition reads
as a boolean expression (e.g., use the existing left-hand check with just
st.session_state.tracking_consent['matomo']), and apply the same change pattern
to the similar GA and Piwik Pro checks; edit the conditional containing
st.session_state.settings["analytics"]["matomo"]["enabled"] and
st.session_state.tracking_consent["matomo"] to remove the "== True" comparison
and rely on truthiness instead.

html(
"""
<!DOCTYPE html>
<html lang="en">
<head></head>
<body><script>
window.parent._mtm = window.parent._mtm || [];
window.parent._mtm.push(['MTMSetConsentGiven']);
</script></body>
</html>
""",
width=1,
height=1,
)

# Determine the workspace for the current session
if ("workspace" not in st.session_state) or (
Expand Down
Loading