HTML5 Media plugin: allow CSS selectors#1447
Merged
Jethro Nederhof (jethron) merged 4 commits intorelease/4.6.6from Aug 20, 2025
Merged
HTML5 Media plugin: allow CSS selectors#1447Jethro Nederhof (jethron) merged 4 commits intorelease/4.6.6from
Jethro Nederhof (jethron) merged 4 commits intorelease/4.6.6from
Conversation
Mostly useful for GTM templates where actual DOM elements can not be directly passed to the plugin call because of the sandbox. Issue: BCPF-1956
Didn't seem to get updated with v4 API changes for Media Plugin compatibility.
Matus Tomlein (matus-tomlein)
approved these changes
Aug 19, 2025
ce052f1
into
release/4.6.6
5 of 6 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some users have reported that when using the GTM Tag Template with the HTML5 Media Tracking plugin, they are not able to pass their media elements directly to the plugin to enable tracking. The GTM Tag Template runs in a sandbox where DOM elements are replaced with
nullvalues when passed as arguments to functions created in the sandbox (i.e. thesnowplow()command queue). If the element has an ID (or is a child of an element with an ID), you can work around this issue by passing the ID as a string; the plugin itself is not sandboxxed, so if it selects the element itself it finds the element successfully and proceeds as expected.Unfortunately, if your element has no ID or ancestor with an ID, you can not use this workaround with the current implementation.
This extends the plugin to try using the passed ID string as a CSS selector to find an element (using
document.querySelector()) if the passed string fails to succeed as an exact ID match. This allows the plugin to work on pages that don't use IDs often in their layout by using more complex CSS selectors.This introduces an odd edge case where it may now match elements that previously did not match in cases where IDs happen to also be valid CSS selectors.
For example, if you had an element on one page like
<video id="video" />and on another page just had<video />, selecting viaid: 'video':I'm hoping this is rare enough to not be a big deal.
I have also updated the README to reflect this information, and the API changes from v4.0.0 which it seems it was not updated for. I have also made the
media_elementcurrentSrcvalue fallback to thesrcattribute if it has no value, as this has been reported as a source for invalid events. This should make the events valid but the state is still observable from thenetworkStatefield which should beNETWORK_NO_SOURCEwhen this is the case.