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
-
In GTM, go to Variables > Configure
-
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
-
Go to Triggers > New
-
Choose YouTube Video as the trigger type
-
Configure the following:
-
Capture: Start (add Pause or Complete as needed)
-
Check: Add JavaScript API support to all YouTube videos
-
Fire on: All Videos
-
-
Name the trigger:
TRG - YouTube Video Start -
Save the trigger
Step 4: Create the Custom HTML Tag for HubSpot
-
Go to Tags > New
-
Select Custom HTML as the tag type
-
Name the tag:
TAG - HubSpot Video Tracking -
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>
-
Assign the trigger
TRG - YouTube Video Start -
Save and publish the tag
Step 5: Test the Implementation
-
Enable Preview Mode in GTM
-
Open your website in a new tab
-
Play a YouTube video
-
In the GTM debug panel:
-
Confirm the
gtm.videoevent appears -
Verify the tag is firing correctly
-
-
Open the browser console to check the logs
-
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
-
Publish your GTM container to the live environment
-
Re-test on the production site
-
Monitor event activity in HubSpot
-
Create automated workflows, lead scoring, or reports based on video interactions