Skip to main content

Hi all, I have a use-case where I have to implement the analytics tracking for youtube embedded videos. I have tried using two extension one being youtube playback and other one is youtube player embed but neither is giving me the desired outcome.

 

I am thinking if the videos are inside the iframe tag which is the primary reason it is not getting loaded.

 

Does anyone has experience on handing this use-case and provide an appropriate solution.

Hi @ishanchopra , i am the developer of the YouTube Playback extension. Could you elaborate more on your problem? Also, how did you setup the video tracking with my extension which did not result in your desired results?

If possible, can you share a link to a page with the video that you're trying to track? I could then take a look at the page and video to try to understand more about how the video has been embedded in your page.


Thanks for bringing this up—tracking YouTube embedded videos can indeed be a bit tricky, especially due to the use of iframes.

You’re correct that the iframe element can limit what can be tracked directly, as it creates a separate context from the main page. To handle this, the most reliable approach is to use the YouTube IFrame Player API. It allows you to listen for events such as play, pause, and end directly from the embedded player.

A few key steps to consider:

  1. Ensure you’re embedding videos using the API and not just a raw iframe snippet.

  2. Use onStateChange listeners to track playback events.

  3. Integrate these events into your analytics platform (e.g., Adobe Analytics or Google Analytics) via custom events or data layer pushes.

If you’re using a tag management system like Adobe Launch or Google Tag Manager, you might also consider a custom HTML tag that initializes the player and captures the events.

Let me know which analytics platform you’re using—happy to point you to more tailored resources or examples.


You’re right to suspect the iframe is part of the issue—standard embedded YouTube videos don’t expose playback data to GTM by default. However, this is a well-known use case, and GTM provides a solid way to track YouTube interactions using the YouTube Video trigger.

Here’s a step-by-step approach you can try:

  1. Ensure your YouTube videos are embedded using the standard <iframe> embed code from YouTube (not a custom wrapper).

  2. In GTM, go to Triggers and create a new one:

     

    • Type: YouTube Video

    • Configure which actions to track (start, complete, pause, etc.)

    • Optionally enable checkboxes for “capture progress” or define thresholds (e.g. 25%, 50%, etc.).

  3. In GTM, create a Tag to fire when that trigger activates—e.g., a Google Analytics 4 event tag or a custom event for another platform.

  4. Publish and test using GTM’s Preview mode. If the trigger doesn’t fire, ensure the iframe doesn’t have the ?enablejsapi=1 parameter missing. You might need to update the embed URL to include it, like:

https://www.youtube.com/embed/VIDEO_ID?enablejsapi=1

If you’re embedding the videos dynamically or via a CMS, you may also need to add a slight delay or use a Custom HTML tag to enhance compatibility.


Yes, YouTube videos in iframes can be tricky, but you can track them in Google Tag Manager using the built-in YouTube Video trigger.

 

Make sure your embed includes ?enablejsapi=1 in the URL—this is required for GTM to listen to video events. Then, in GTM:

 

  1. Create a YouTube Video trigger and select which events to track (e.g. start, pause, complete).

  2. Link it to a GA4 Event Tag or custom event.

  3. Use GTM Preview to verify it’s working.


Great quesiton


Reply