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

Change Matomo script, remove visible HTML #1384

Open
bwbroersma opened this issue Apr 9, 2024 · 0 comments
Open

Change Matomo script, remove visible HTML #1384

bwbroersma opened this issue Apr 9, 2024 · 0 comments

Comments

@bwbroersma
Copy link
Collaborator

bwbroersma commented Apr 9, 2024

Currently this custom code is added in the HTML:

  <div class="hidethis" aria-hidden="true">
    <span id="matomo-url">//matomo.internet.nl/</span>
    <span id="matomo-siteid">1</span>
    <span id="matomo-subdomain-tracking">*.internet.nl</span>
  </div>

It uses the hidethis class to hide it and then uses frontend/js/matomo.js to pass this on as arguments for the Matomo javascript.

This is obviously done to comply with CSP & keep it dynamic configurable. Although another approach would be to generate the JS with the parameters. An improvement to the current code would be to use HTML 5 hidden attribute instead of CSS rule:

.hidethis {
display:none !important; /* bad but we need to make sure that something will be hidden */
}

The current variables are only in the settings.py and base template:

# Features
# # User Tracking
MATOMO_URL = getenv("MATOMO_URL", "//matomo.internet.nl/")
MATOMO_SITEID = int(getenv("MATOMO_SITEID", "1"))
# # Used for subdomain tracking eg. *.internet.nl
MATOMO_SUBDOMAIN_TRACKING = getenv("MATOMO_SUBDOMAIN_TRACKING", "")

<div class="hidethis" aria-hidden="true">
<span id="matomo-url">{{"MATOMO_URL"|get_settings_value}}</span>
<span id="matomo-siteid">{{"MATOMO_SITEID"|get_settings_value}}</span>
<span id="matomo-subdomain-tracking">{{"MATOMO_SUBDOMAIN_TRACKING"|get_settings_value}}</span>
</div>

via docker compose env of the app container:
- MATOMO_URL
- MATOMO_SITEID
- MATOMO_SUBDOMAIN_TRACKING

Currently the app (Django) container is serving the /static files, so either fix it during minimizing:

RUN python3 bin/frontend.py js

or, since the Django code doesn't uses these variables, it could be done with a .template and adding a line like this below the line mentioned above:

RUN envsubst < ...matamo.js.template > ...matamo.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant