From 8d48576fdf135492e288e1fc7cc28d14c2ef02e2 Mon Sep 17 00:00:00 2001 From: Alfredo Toselli Date: Wed, 28 Oct 2026 16:22:47 +0100 Subject: [PATCH] feat: track the interactions with the YT video --- source/_static/matomo.js | 21 +++++++++++++++++++++ source/core-concepts.md | 1 + 2 files changed, 22 insertions(+) diff --git a/source/_static/matomo.js b/source/_static/matomo.js index 8113bbb..4f00bc4 100644 --- a/source/_static/matomo.js +++ b/source/_static/matomo.js @@ -20,6 +20,20 @@ queue.push(['setConsentGiven']); } + function enableMediaEvents() { + window.Matomo.getAsyncTrackers().forEach(function (tracker) { + if (tracker.MediaAnalytics) { + tracker.MediaAnalytics.enableTrackEvents(); + } + }); + } + + function initMediaAnalytics() { + // Tag Manager can add trackers after Media Analytics has initialized. + window.Matomo.on('TrackerAdded', enableMediaEvents); + enableMediaEvents(); + } + function markCopyButtons() { document.querySelectorAll('button.copybtn:not([data-matomo-copy])').forEach(function (button) { button.setAttribute('data-matomo-copy', 'docs-code-snippet'); @@ -31,6 +45,13 @@ document.addEventListener('DOMContentLoaded', markCopyButtons); + if (window.Matomo) { + initMediaAnalytics(); + } else { + var pluginInit = window.matomoPluginAsyncInit = window.matomoPluginAsyncInit || []; + pluginInit.push(initMediaAnalytics); + } + enableTracking(); var dataLayer = window._mtm = window._mtm || []; dataLayer.push({'mtm.startTime': new Date().getTime(), event: 'mtm.Start'}); diff --git a/source/core-concepts.md b/source/core-concepts.md index cfbcd01..db6a38c 100644 --- a/source/core-concepts.md +++ b/source/core-concepts.md @@ -95,5 +95,6 @@ The {edh_url}`Climate DT ` high-resolution datasets a ```{youtube} JV5g9XWBWfI --- width: 100% +url_parameters: ?enablejsapi=1 --- ```