muxinc / elements

Custom elements for working with media in the browser that Just Work™
https://elements-demo-nextjs.vercel.app
MIT License
235 stars 45 forks source link

🦟 Bug: Pass custom events to data integration #950

Open endymion1818 opened 1 month ago

endymion1818 commented 1 month ago

EDIT: Sorry this seems to be a bug, my colleague found this line of code that looks like it should update analytics when updated attributes are passed to the element

Is there an existing issue for this?

Which Mux Elements/Packages does this apply to? Select all that apply

mux-video

Description

Currently, we are able to pass data to Mux analytics via attributes on the element, for example:

<mux-video
    env-key="some-env-key"
    metadata-video-title="My Video"
>
</mux-video>

This tracks fine in Mux Data dashboard.

However if we later wanted to update the video title (use case is a change to the playing video, or some other metadata associated with relevant user behaviour), I don't think it's possible to update the metadata.

I've tried updating the attribute like this:

const video = parent.shadowRoot.querySelector('mux-video');
video.setAttribute('metadata-video-title', 'New Title')

❌ This doesn't work, the data sent to Mux Data still maintains the old title.

Even though it looks like there is a MutationObserver for those elements:

https://github.com/muxinc/elements/blob/1e6972805459a0bb3a18b5b5a6d0bbf32c900b17/packages/mux-player/src/video-api.ts#L178

Expected Behavior

I would like a custom event I can hook into so that I can update the metadata, something like:

const video = parentElement.shadowRoot.querySelector('mux-video');

video.dispatchEvent(
  new CustomEvent('metadata', 'New Title')
)

Or for updating the attributes to be observed by the internal mux-data integration so that updating the attributes also updates the mux data.

As an aside, I tried to write a custom integration using the HTML <video> element but it doesn't support your extended video element, instead it specifically looks for a <video> element.

endymion1818 commented 1 month ago

Just to emphasise this is a blocker for us. We have a mux data integration for JWPlayer in prod and we need to be able to maintain the same feature set that is provided with that integration.

I really don't want to stick with JWPlayer 😭