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

Add Matomo as an option for analytics_tool. #38221

Merged
merged 2 commits into from
Mar 19, 2024
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
9 changes: 8 additions & 1 deletion airflow/config_templates/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1775,7 +1775,7 @@ webserver:
analytics_tool:
description: |
Send anonymous user activity to your analytics tool
choose from google_analytics, segment, or metarouter
choose from google_analytics, segment, metarouter, or matomo
version_added: ~
type: string
example: ~
Expand All @@ -1787,6 +1787,13 @@ webserver:
type: string
example: ~
default: ~
analytics_url:
description: |
Your instances url, only applicable to Matomo.
version_added: 2.9.0
type: string
example: https://your.matomo.instance.com/
default: ~
show_recent_stats_for_completed_runs:
description: |
'Recent Tasks' stats will show for old DagRuns if set
Expand Down
2 changes: 1 addition & 1 deletion airflow/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def inversed_deprecated_sections(self):
("logging", "fab_logging_level"): _available_logging_levels,
# celery_logging_level can be empty, which uses logging_level as fallback
("logging", "celery_logging_level"): [*_available_logging_levels, ""],
("webserver", "analytical_tool"): ["google_analytics", "metarouter", "segment", ""],
("webserver", "analytical_tool"): ["google_analytics", "metarouter", "segment", "matomo", ""],
}

upgraded_values: dict[tuple[str, str], str]
Expand Down
1 change: 1 addition & 0 deletions airflow/www/extensions/init_jinja_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def prepare_jinja_globals():
{
"analytics_tool": conf.get("webserver", "ANALYTICS_TOOL"),
"analytics_id": conf.get("webserver", "ANALYTICS_ID"),
"analytics_url": conf.get("webserver", "ANALYTICS_URL"),
}
)

Expand Down
34 changes: 34 additions & 0 deletions airflow/www/templates/analytics/matomo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{#
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
#}

<!-- Matomo -->
<script>
var _paq = window._paq = window._paq || [];
/* tracker methods like "setCustomDimension" should be called before "trackPageView" */
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u="{{ analytics_url }}";
_paq.push(['setTrackerUrl', u+'matomo.php']);
_paq.push(['setSiteId', '{{ analytics_id }}']);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
g.async=true; g.src=u+'matomo.js'; s.parentNode.insertBefore(g,s);
})();
</script>
<!-- End Matomo Code -->
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ You can configure Airflow to route anonymous data to
`Google Analytics <https://analytics.google.com/>`_,
`Segment <https://segment.com/>`_, or `Metarouter <https://www.metarouter.io/>`_.

Edit ``airflow.cfg`` and set the ``webserver`` block to have an ``analytics_tool`` and ``analytics_id``:
Edit ``airflow.cfg`` and set the ``webserver`` block to have an ``analytics_tool`` and ``analytics_id`` and ``analytics_url`` if you're using ``matomo``:

.. code-block:: ini

[webserver]
# Send anonymous user activity to Google Analytics, Segment, or Metarouter
analytics_tool = google_analytics # valid options: google_analytics, segment, metarouter
analytics_tool = google_analytics # valid options: google_analytics, segment, metarouter, matomo
analytics_id = XXXXXXXXXXX
analytics_url = https://your-matomo-instance.example.com # only required for Matomo

.. note:: You can see view injected tracker html within Airflow's source code at
``airflow/www/templates/airflow/main.html``. The related global
Expand Down
2 changes: 2 additions & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,8 @@ MarketingTeam
MarkupSafe
Masternode
masterType
Matomo
matomo
Maxime
mb
md
Expand Down
Loading