YouTube Video Tracking in HubSpot using Google Tag Manager

Overview

This guide explains how to track YouTube video interactions (such as plays, pauses, and completions) on your website using Google Tag Manager (GTM), and send that data to HubSpot as Custom Behavioral Events.

It is designed for marketing and operations teams that want to analyze video engagement and trigger automated workflows based on user behavior.


Prerequisites

Before you begin, ensure the following are in place:

  • HubSpot Enterprise subscription
    (Marketing Hub or Operations Hub Enterprise is required for Custom Behavioral Events)

  • Google Tag Manager access with publish permissions

  • YouTube videos embedded on your website

  • HubSpot tracking code is installed on your site

    • If your site is hosted on HubSpot, the tracking code is automatically included

    • If external, you must add the HubSpot tracking code manually


Step 1: Prepare the YouTube Embed Code

The YouTube iframe must include the enablejsapi=1 parameter for GTM to detect video events.

Correct Format:

<iframe src="https://www.youtube.com/embed/VIDEO_ID?si=YOUR_PARAMS"></iframe> <!-- Missing enablejsapi=1 -->

Note: If you copied the embed code directly from YouTube, you will need to manually add &enablejsapi=1 to the video URL.


Step 2: Enable Built-In GTM Variables

  1. In GTM, go to Variables > Configure

  2. Under “Videos”, enable the following:

    • Video Current Time

    • Video Duration

    • Video Percent

    • Video Provider

    • Video Status

    • Video Title

    • Video URL


Step 3: Create a YouTube Video Trigger

  1. Go to Triggers > New

  2. Choose YouTube Video as the trigger type

  3. Configure the following:

    • Capture: Start (add Pause or Complete as needed)

    • Check: Add JavaScript API support to all YouTube videos

    • Fire on: All Videos

  4. Name the trigger: TRG - YouTube Video Start

  5. Save the trigger


 

Step 4: Create the Custom HTML Tag for HubSpot

  1. Go to Tags > New

  2. Select Custom HTML as the tag type

  3. Name the tag: TAG - HubSpot Video Tracking

  4. Paste the following code:

 
<script> console.log('=== TRIGGER FIRED ==='); var lastEvent = window.dataLayer[window.dataLayer.length - 1]; if (typeof _hsq !== 'undefined' && lastEvent.event === 'gtm.video') { if (lastEvent['gtm.videoStatus'] === 'start') { _hsq.push([ 'trackCustomBehavioralEvent', { name: "pe49646889_video_youtube_view", properties: { video_action: lastEvent['gtm.videoStatus'], video_title: lastEvent['gtm.videoTitle'], video_url: lastEvent['gtm.videoUrl'], video_duration: lastEvent['gtm.videoDuration'], video_percent: lastEvent['gtm.videoPercent'], video_current_time: lastEvent['gtm.videoCurrentTime'], video_provider: lastEvent['gtm.videoProvider'], element_id: lastEvent['gtm.elementId'], page_url: window.location.href, page_title: document.title, timestamp: Date.now() } } ]); console.log('Event sent to HubSpot'); } } </script>
  1. Assign the trigger TRG - YouTube Video Start

  2. Save and publish the tag


 

Step 5: Test the Implementation

  1. Enable Preview Mode in GTM

  2. Open your website in a new tab

  3. Play a YouTube video

  4. In the GTM debug panel:

    • Confirm the gtm.video event appears

    • Verify the tag is firing correctly

  5. Open the browser console to check the logs

  6. Log into HubSpot and check the Custom Behavioral Events > Event Stream


 

Checklist

  • The YouTube iframe includes enablejsapi=1

  • All GTM video variables are enabled

  • JavaScript API support is checked in the trigger

  • The HubSpot tracking code (_hsq) is loaded before the video interaction

  • Console confirms successful event transmission


 

Step 6: Publish and Monitor

  1. Publish your GTM container to the live environment

  2. Re-test on the production site

  3. Monitor event activity in HubSpot

  4. Create automated workflows, lead scoring, or reports based on video interactions

 

Share the Post:

Related Posts

Join Our Newsletter

Scroll to Top