YouTube video tracking

Here you can see an embedded YouTube video. Play it, pause or seek within the video track to see what Google Tag Manager event names and variables are being shown for specific user interactions.

Why would you use this way of YouTube tracking if Google Tag Manager has its own YouTube trigger?

Because this implementation has been standardized to use the same event names and variables for other players like Vimeo or Soundcloud. If you are using multiple player vendors on your site, this could give you fewer triggers and tags in your container.

You should see the following events and variables:

  • gtm4wp.mediaApiReady – when the page loaded and YouTube API is ready to track user interactions in the player
    • mediaType variable will be set to youtube
  • gtm4wp.mediaPlayerReady – one specific player is ready to be used. You will see several event variables attached:
    • mediaType will be set to youtube
    • mediaData.id will be set to the unique ID of the video on YouTube
    • mediaData.author will be the name of the YouTube channel
    • mediaData.title will be set to the title of the YouTube video
    • mediaData.url will include the YouTube URL of the video
    • mediaData.duraction will be set to the length of the video in seconds
  • gtm4wp.mediaPlayerStateChange will fire each time the player started playing, or if it is paused, stopped or it is buffering. Next to the variables above, you will see some additional variables:
    • mediaPlayerState: unstarted, play, ended, pause, buffering or cued
    • mediaCurrentTime: the time index where the player is currently playing the video
  • gtm4wp.mediaPlayerEvent – an event happening in the player during or before playback. Next to the variables above, you will see the following variables:
    • mediaPlayerEvent: quality-change, ratechange, error, api-change
    • mediaPlayerEventParam: if there is any additional data attached to the event name in mediaPlayerEvent, you will see it here
  • gtm4wp.mediaPlaybackPercentage – while the video plays, this event will fire each time the user watched 10% more seconds of the video. in addition to the variables above, you will have this as well:
    • mediaPercentage: the percentage the video was already played