From 6cb50e04e05a3826637054a04245acf24343b030 Mon Sep 17 00:00:00 2001 From: Scott Jehl Date: Tue, 23 Jul 2024 11:07:29 -0400 Subject: [PATCH] Add two custom metrics for video using source elements with media queries (#137) * Add two custom metrics for video using source elements with media queries The first metric returns the number of video elements that have a source element using media. The second is an array of all video source media attribute values in play. * Update dist/media.js --------- Co-authored-by: Rick Viscomi Co-authored-by: Max Ostapenko <1611259+max-ostapenko@users.noreply.github.com> --- dist/media.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dist/media.js b/dist/media.js index 62e9ea1b..b880ce0c 100644 --- a/dist/media.js +++ b/dist/media.js @@ -123,6 +123,12 @@ return JSON.stringify({ 'video_display_style' : Array.from(document.querySelectorAll('video')).map(video => { return getComputedStyle(video, null).getPropertyValue('display'); }), + //Returns the number of video elements that contain a source element that uses a media attribute + 'video_using_source_media_count': document.querySelectorAll('video:has(source[media])').length, + //Returns the media attribute values in use on video source elements + 'video_source_media_values': Array.from(document.querySelectorAll('video source[media]')).map(source => { + return source.getAttribute('media'); + }), //returns an array of the number of source files per video tag. 'video_source_format_count': Array.from(document.querySelectorAll('video')).map(video => video.querySelectorAll('source').length), //Returns all of the video types for each source file