HTML5 Video Lightbox & Google Analytics (GA4)

I am currently setting up HTML5 Video Tracking in GTM and GA4. I am working to modify the script on the linked page to also react to videos loaded in through the “Link to: Video Lightbox” feature inside Bricks Builder.

I have two questions:

  1. Is a querySelectorAll(‘a[data-pswp-video-url]’) a reliable way to check whether lightbox videos are present?
  2. Is there any event I can listen to to track new videos being opened inside PhotoSwipe lightboxes?

The issue with the method outlined in the article I linked to is that it only works for <video> tags present on the page on load. PSWP and Bricks Builder load in the videos on demand, so I need to account for that.

Any pointers appreciated.

Thanks

Anyone have an idea?

I’d suggest using Google Tag Manager and set a click trigger on the video. Then you can have that fire to Google Analytics to track it.

That would work, except I am not only tracking if a video was watched, but also for how long, if it’s been paused and other metrics. Currently, I do that by attaching an event listener to the video element, which I would have to do ad-hoc for the video elements that get spawned in. I will see if I can maybe attach a listener after the click, event, however. Thanks for your input! Good idea.