Commit 8723cb52 authored by Christophe Benz's avatar Christophe Benz

Call Matomo by a client-side call

parent 659dddec
Pipeline #1109 passed with stage
in 4 minutes and 52 seconds
......@@ -15,7 +15,6 @@ API_VALIDATE_ENDPOINT=http://127.0.0.1:5600/validate
# Homepage sections and blocks config file path
# HOMEPAGE_CONFIG_FILE=homepage_config.json
# If used, do "pip install validata-ui[matomo]"
# MATOMO_AUTH_TOKEN=""
# Uncomment to enable [Matomo](https://matomo.org/) analytics
# MATOMO_BASE_URL=""
# MATOMO_SITE_ID=""
## 0.2.2
## 0.2.7
Non-breaking changes:
Technical changes:
- Don't fail if error loading catalog
- Replace Flask-Matomo by a client-side JavaScript function
- Remove configuration variable `MATOMO_AUTH_TOKEN`
## 0.2.1
## 0.2.6
Non-breaking changes:
Technical changes:
- display version number in footer
- Fix PDF report generation
## 0.2.4
......@@ -17,6 +18,18 @@ New features for users:
- Render Markdown links table header, in the table that shows validation errors
- Ease clicking on links in popups, in the table that shows validation errors
## 0.2.2
Non-breaking changes:
- Don't fail if error loading catalog
## 0.2.1
Non-breaking changes:
- display version number in footer
## 0.2.0
New features for users:
......
......@@ -3,7 +3,6 @@ cachecontrol==0.12.5
commonmark==0.8.1
ezodf==0.3.2
Flask==1.0.2
Flask-Matomo==1.2.0
lxml==4.2.5
opendataschema==0.5.2
python-dotenv==0.10.1
......
......@@ -13,7 +13,7 @@ with readme_filepath.open('rt', encoding='utf-8') as fd:
setup(
name='validata_ui',
version='0.2.6',
version='0.2.7',
description='Validata Web UI',
long_description=LONG_DESCRIPTION,
......@@ -69,7 +69,4 @@ setup(
'validata_core >= 0.3.5, < 0.4',
],
extras_require={
'matomo': ["Flask-Matomo"],
},
)
......@@ -77,12 +77,6 @@ if config.HOMEPAGE_CONFIG:
app = flask.Flask(__name__)
app.secret_key = config.SECRET_KEY
matomo = None
if config.MATOMO_AUTH_TOKEN and config.MATOMO_BASE_URL and config.MATOMO_SITE_ID:
from flask_matomo import Matomo
matomo = Matomo(app, matomo_url=config.MATOMO_BASE_URL,
id_site=config.MATOMO_SITE_ID, token_auth=config.MATOMO_AUTH_TOKEN)
# Jinja2 url_quote_plus custom filter
# https://stackoverflow.com/questions/12288454/how-to-import-custom-jinja2-filters-from-another-file-and-using-flask
blueprint = flask.Blueprint('filters', __name__)
......@@ -102,5 +96,10 @@ def inject_version():
return {"validata_ui_version": pkg_resources.get_distribution("validata-ui").version}
@app.context_processor
def inject_config():
return {"config": config}
# Keep this import after app initialisation (to avoid cyclic imports)
from . import views # noqa isort:skip
......@@ -12,6 +12,11 @@ log = logging.getLogger(__name__)
load_dotenv()
def without_trailing_slash(url):
return url[:-1] if url.endswith('/') else url
LOG_LEVEL = os.environ.get("LOG_LEVEL", "INFO")
numeric_log_level = getattr(logging, LOG_LEVEL.upper(), None)
if not isinstance(numeric_log_level, int):
......@@ -29,8 +34,8 @@ if API_VALIDATE_ENDPOINT is None:
raise ValueError("API_VALIDATE_ENDPOINT environment variable required")
SHIELDS_IO_BASE_URL = os.environ.get("SHIELDS_IO_BASE_URL") or None
if SHIELDS_IO_BASE_URL and not SHIELDS_IO_BASE_URL.endswith('/'):
SHIELDS_IO_BASE_URL += '/'
if SHIELDS_IO_BASE_URL:
SHIELDS_IO_BASE_URL = without_trailing_slash(SHIELDS_IO_BASE_URL)
HOMEPAGE_CONFIG_FILE = os.environ.get("HOMEPAGE_CONFIG_FILE") or None
HOMEPAGE_CONFIG = None
......@@ -39,8 +44,9 @@ if HOMEPAGE_CONFIG_FILE:
with HOMEPAGE_CONFIG_FILE.open() as fd:
HOMEPAGE_CONFIG = json.load(fd)
MATOMO_AUTH_TOKEN = os.getenv("MATOMO_AUTH_TOKEN") or None
MATOMO_BASE_URL = os.getenv("MATOMO_BASE_URL") or None
if MATOMO_BASE_URL:
MATOMO_BASE_URL = without_trailing_slash(MATOMO_BASE_URL)
MATOMO_SITE_ID = os.getenv("MATOMO_SITE_ID") or None
if MATOMO_SITE_ID:
MATOMO_SITE_ID = int(MATOMO_SITE_ID)
......@@ -95,6 +95,22 @@
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
{% block page_scripts %}{% endblock %}
{% if config.MATOMO_BASE_URL and config.MATOMO_SITE_ID %}
<script type="text/javascript">
var _paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="{{ config.MATOMO_BASE_URL }}/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', 'config.MATOMO_SITE_ID']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
{% endif %}
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment