{"id":2113,"date":"2026-05-06T13:12:43","date_gmt":"2026-05-06T13:12:43","guid":{"rendered":"https:\/\/www.tarleton.edu\/weboperations\/?page_id=2113"},"modified":"2026-05-06T14:00:57","modified_gmt":"2026-05-06T14:00:57","slug":"embedded-video-tracking","status":"publish","type":"page","link":"https:\/\/www.tarleton.edu\/weboperations\/embedded-video-tracking\/","title":{"rendered":"Embedded Video Tracking"},"content":{"rendered":"\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"The Internet Was Weeks Away From Disaster and No One Knew\" width=\"800\" height=\"450\" src=\"https:\/\/www.youtube.com\/embed\/aoag03mSuXQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<script>\n(function () {\n  'use strict';\n\n  const LOG_PREFIX = '[YouTube Matomo Prep]';\n  let counter = 0;\n\n  function log(message, data) {\n    if (typeof data !== 'undefined') {\n      console.log(LOG_PREFIX, message, data);\n    } else {\n      console.log(LOG_PREFIX, message);\n    }\n  }\n\n  function isYouTubeIframe(iframe) {\n    const src = iframe.getAttribute('src') || '';\n\n    return (\n      src.includes('youtube.com\/embed\/') ||\n      src.includes('youtube-nocookie.com\/embed\/')\n    );\n  }\n\n  function prepareIframe(iframe) {\n    const rawSrc = iframe.getAttribute('src');\n\n    if (!rawSrc) {\n      return false;\n    }\n\n    let url;\n\n    try {\n      url = new URL(rawSrc, window.location.href);\n    } catch (error) {\n      console.warn(LOG_PREFIX, 'Could not parse iframe src.', rawSrc, error);\n      return false;\n    }\n\n    let changed = false;\n\n    if (url.searchParams.get('enablejsapi') !== '1') {\n      url.searchParams.set('enablejsapi', '1');\n      changed = true;\n    }\n\n    if (!url.searchParams.has('origin')) {\n      url.searchParams.set('origin', window.location.origin);\n      changed = true;\n    }\n\n    if (!iframe.id) {\n      counter += 1;\n      iframe.id = 'matomo-youtube-iframe-' + counter;\n      changed = true;\n    }\n\n    if (changed) {\n      iframe.setAttribute('src', url.toString());\n      log('Prepared YouTube iframe for API tracking.', {\n        iframe: iframe,\n        src: url.toString()\n      });\n    } else {\n      log('YouTube iframe already looked prepared.', {\n        iframe: iframe,\n        src: rawSrc\n      });\n    }\n\n    return changed;\n  }\n\n  function prepareYouTubeIframes() {\n    const iframes = Array.from(document.querySelectorAll('iframe')).filter(isYouTubeIframe);\n\n    log('Found YouTube iframes.', {\n      count: iframes.length,\n      iframes: iframes\n    });\n\n    iframes.forEach(prepareIframe);\n  }\n\n  function askMatomoToRescan() {\n    if (window.Matomo && window.Matomo.MediaAnalytics) {\n      log('Matomo MediaAnalytics found. Asking Matomo to scan for media.');\n\n      if (typeof window.Matomo.MediaAnalytics.enableMediaAnalytics === 'function') {\n        window.Matomo.MediaAnalytics.enableMediaAnalytics();\n      }\n\n      if (typeof window.Matomo.MediaAnalytics.scanForMedia === 'function') {\n        window.Matomo.MediaAnalytics.scanForMedia();\n      }\n\n      return;\n    }\n\n    if (window._paq && Array.isArray(window._paq)) {\n      log('Matomo object not found yet. Queueing MediaAnalytics scan through _paq.');\n\n      window._paq.push(['MediaAnalytics::enableMediaAnalytics']);\n      window._paq.push(['MediaAnalytics::scanForMedia']);\n\n      return;\n    }\n\n    console.warn(LOG_PREFIX, 'Matomo MediaAnalytics was not found on window.');\n  }\n\n  function run() {\n    prepareYouTubeIframes();\n\n    \/*\n     * Give the iframe a moment to reload if we changed its src,\n     * then ask Matomo to rescan.\n     *\/\n    window.setTimeout(askMatomoToRescan, 1000);\n  }\n\n  if (document.readyState === 'loading') {\n    document.addEventListener('DOMContentLoaded', run);\n  } else {\n    run();\n  }\n})();\n<\/script>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":62,"featured_media":580,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"template-fullwidth.php","meta":{"_acf_changed":false,"inline_featured_image":false,"advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","footnotes":""},"class_list":["post-2113","page","type-page","status-publish","has-post-thumbnail","hentry"],"acf":[],"coauthors":[],"author_meta":{"author_link":"https:\/\/www.tarleton.edu\/weboperations\/author\/kyle-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-2-3\/","display_name":"kyle"},"relative_dates":{"created":"Posted 2 days ago","modified":"Updated 2 days ago"},"absolute_dates":{"created":"Posted on May 6, 2026","modified":"Updated on May 6, 2026"},"absolute_dates_time":{"created":"Posted on May 6, 2026 1:12 pm","modified":"Updated on May 6, 2026 2:00 pm"},"featured_img_caption":"","featured_img":false,"series_order":"","_links":{"self":[{"href":"https:\/\/www.tarleton.edu\/weboperations\/wp-json\/wp\/v2\/pages\/2113","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tarleton.edu\/weboperations\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.tarleton.edu\/weboperations\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.tarleton.edu\/weboperations\/wp-json\/wp\/v2\/users\/62"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tarleton.edu\/weboperations\/wp-json\/wp\/v2\/comments?post=2113"}],"version-history":[{"count":3,"href":"https:\/\/www.tarleton.edu\/weboperations\/wp-json\/wp\/v2\/pages\/2113\/revisions"}],"predecessor-version":[{"id":2117,"href":"https:\/\/www.tarleton.edu\/weboperations\/wp-json\/wp\/v2\/pages\/2113\/revisions\/2117"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tarleton.edu\/weboperations\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/www.tarleton.edu\/weboperations\/wp-json\/wp\/v2\/media?parent=2113"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}