HTML5 Video & Audio Tracking Code Generator

GA4's built-in video tracking only covers YouTube. Choose what to track and get a ready-to-paste Google Tag Manager tag for your own <video> and <audio> players, with the exact variables, trigger and GA4 tag to create. You can test it live on this page.

Players
Events
Milestones and names
Your GTM Custom HTML tag

Set it up in Google Tag Manager
Test it here

Runs your generated code on a test audio clip (a generated tone) and shows each data layer push. Nothing is sent to analytics.

Click "Load test player", then press play.

The code is written for this site and is free to use on your own websites.

INTERACTIVE DEMO Want to test how this tool works?
Save these results as a PDF report A clean, branded copy to share with your team or client.
Free PDF report

Where should we put your name on the report?

Your PDF downloads straight away. Your tool data never leaves your browser.

Jobair Mahmud, Web Analytics & Tracking Architect
Tool Creator

Jobair Mahmud

Founder & Tracking Architect

100% Top Rated
5.0 / 5.0

Need custom tracking beyond video?

I build advanced GTM and JavaScript tracking for players, forms, calculators and single-page apps, with clean data layer events.

Get custom tracking built →

How to use the HTML5 Media Tracking Code Generator

GA4 enhanced measurement tracks YouTube embeds only. Videos and audio you host yourself, in a <video> or <audio> element, send nothing until you add tracking. The generated tag listens to each player's own events (play, timeupdate, pause, seeked, ended) and pushes clean data layer events you can send to GA4 or any other tool.

Step by step

  1. Choose the players and events to track, and the progress milestones you care about.
  2. Click "Load test player" and press play to see the exact data layer pushes the code makes.
  3. Copy the code into a GTM Custom HTML tag and follow the setup steps for variables, trigger and GA4 tag.
  4. Publish, then check in GA4 DebugView that video_start and video_progress arrive with media_title and media_percent.

How to read your result

Events in GTM Preview and GA4 DebugView

Register media_title and media_percent as custom dimensions to see which videos people actually watch to the end.

Only some players tracked

The player is inside an iframe (Vimeo, Wistia, YouTube) or a shadow DOM. Those need their own API-based tracking.

Nothing fires

The tag fires before the player exists and "track players added later" is off, or the video is not a native <video> element.

Common mistakes

  • Expecting this to track YouTube or Vimeo embeds: those players live in iframes and need their own tracking.
  • Using the same event names as GA4's YouTube tracking without the media_provider parameter to tell them apart.
  • Too many milestones (every 5%), which inflates event counts with little extra insight.
  • Forgetting to register the parameters as custom dimensions, so they never appear in reports.

Questions

Does it work with Video.js, Plyr or Elementor video?

Yes, as long as the player uses a native <video> or <audio> element underneath, which most self-hosted players do.

Will it slow my site down?

No. It only listens to events the browser already fires, and it sends at most one push per milestone per play.

Can I send these events to Meta or other tools?

Yes. They are plain data layer events, so any GTM tag can use the same trigger and variables.

Need custom tracking beyond video?

I build advanced GTM and JavaScript tracking for players, forms, calculators and single-page apps, with clean data layer events.