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

feat: add matomo tracking site #526

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions atlas/atlasRoutes.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ def index():
else:
lastDiscoveries = []

if current_app.config["MATOMO_URL"] != "":
matomo_script = current_app.config["MATOMO_SCRIPT"]
else:
matomo_script = ""

connection.close()
session.close()

Expand All @@ -213,6 +218,7 @@ def index():
mostViewTaxon=mostViewTaxon,
customStatMedias=customStatMedias,
lastDiscoveries=lastDiscoveries,
matomo_script=matomo_script,
)


Expand Down
5 changes: 5 additions & 0 deletions atlas/configuration/config.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ LANGUAGES = {
# Code de suivi des statistiques Google Analytics (si AFFICHAGE_FOOTER = True)
ID_GOOGLE_ANALYTICS = "UA-xxxxxxx-xx"

# Suivi de statistiques avec MATOMO si MATOMO_URL != ""
MATOMO_URL = "" # URL lié à votre MATOMO
MATOMO_SITE_ID = 1 # id du site suivi qui correspond ici à celui du GeoNature Atlas (votre site doit être renseigné dans MATOMO)
#### LIEN AIDE MATOMO : https://developer.matomo.org/guides/tracking-javascript-guide

# Utiliser et afficher le glossaire (static/custom/glossaire.json.sample)
GLOSSAIRE = False

Expand Down
18 changes: 18 additions & 0 deletions atlas/configuration/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@
},
}

# LATEST VERSION OF MATOMO
MATOMO_SCRIPT_TO_INCLUDE = """
var _paq = _paq || [];
var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="//url_matomo/";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', site_id]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.type='text/javascript'; g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
"""


class SecretSchemaConf(Schema):
class Meta:
Expand Down Expand Up @@ -208,6 +223,9 @@ class Meta:
# (no need to restart the atlas service when updating templates)
# Defaults to False to have the best performance in production
TEMPLATES_AUTO_RELOAD = fields.Boolean(load_default=False)
MATOMO_SCRIPT = fields.String(load_default=MATOMO_SCRIPT_TO_INCLUDE)
MATOMO_URL = fields.String(load_default="")
MATOMO_SITE_ID = fields.Integer(load_default=0)

@validates_schema
def validate_url_taxhub(self, data, **kwargs):
Expand Down
13 changes: 13 additions & 0 deletions atlas/templates/core/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
{% endblock %}
<link rel="stylesheet" href="{{ url_for('static', filename='custom/custom.css') }}"/>
{% block metaTags %}{% endblock %}

{% if configuration.MATOMO_URL and configuration.MATOMO_SITE_ID is defined %}
{% set site_id = configuration.MATOMO_SITE_ID | int(default=-1) %}
{% set url_matomo = configuration.MATOMO_URL %}
<!-- Matomo -->
<script type="text/javascript">
var url_matomo = "{{ url_matomo }}";
var site_id = {{ site_id | int }};
{{ matomo_script | safe }}
</script>
<!-- End Matomo Code -->
{% endif %}

</head>

<body>
Expand Down
Loading