(function() { // Media Analytics must only report the real video players // (trailer / / interviews). Those tag their container // with data-matomo-title; every other on the page -- // hover thumbnails, header/banner loops, sliders, shorts -- is // opted out with data-matomo-ignore, which Matomo honours in its // own scan. // // This runs from so nodes are tagged as they are parsed, // before Matomo's on-load scan, and so players created after // mount are ed when they appear. if (!window.MutationObserver) { return; } var TITLE_ATTR = 'data-matomo-title'; function playerContainer(video) { var el = video; while (el && el.getAttribute) { if (el.getAttribute(TITLE_ATTR)) { return el; } el = el.parentElement; } return null; } function tag(video) { if (video.matomoTagged) { return; } video.matomoTagged = true; var container = playerContainer(video); if (!container) { video.setAttribute('data-matomo-ignore', 'true'); return; } // The players set the title on the element, which // video.js keeps as the player box while appending a separate // tech inside it. Matomo reads the title off the media // element itself, so copy it down. if (!video.getAttribute(TITLE_ATTR)) { video.setAttribute(TITLE_ATTR, container.getAttribute(TITLE_ATTR)); } // scanForMedia searches *within* the node it is given, so a bare // (a few apps render their own trailer markup) has to be // scanned via its parent. Repeat scans are safe -- Matomo skips // media it already tracks. var scanRoot = container === video ? video.parentNode : container; if (!scanRoot) { return; } window._paq = window._paq || []; window._paq.push(['MediaAnalytics::scanForMedia', scanRoot]); } function scan(node) { if (!node || node.nodeType !== 1) { return; } if (node.tagName === 'VIDEO') { tag(node); } if (!node.getElementsByTagName) { return; } var videos = node.getElementsByTagName('video'); for (var i = 0; i < videos.length; i++) { tag(videos[i]); } } new MutationObserver(function(mutations) { for (var i = 0; i < mutations.length; i++) { var added = mutations[i].addedNodes; for (var j = 0; j < added.length; j++) { scan(added[j]); } } }).observe(document.documentElement, { childList: true, subtree: true }); })();