---
title: Track Youtube videos as events
description: By adding a TrenDemon pixel to a video player, you will be able to track visitors who viewed the video and see what goals they subsequently completed. Use Case: Let’s say that you run a video on your
---

[Skip to content](https://support.trendemon.com/track-youtube-videos-s#main-content)

English

Show submenu for translations

[![trendemon logo](https://support.trendemon.com/hubfs/trendemon_logo-1.svg)](https://www.trendemon.com/?hsLang=en)

Open main navigation

Close main navigation

- English
  
  Show submenu for translations
- [Go to trendemon.com](https://www.trendemon.com/)

[Go to trendemon.com](https://www.trendemon.com/?hsLang=en)

 Hi! How can we help?

- There are no suggestions because the search field is empty.

1. [Success center](https://support.trendemon.com/?hsLang=en)
2. [Best Practices](https://support.trendemon.com/best-practices?hsLang=en)

# Track Youtube videos as events

By adding a TrenDemon pixel to a video player, you will be able to track visitors who viewed the video and see what goals they subsequently completed.

**Use Case:** Let’s say that you run a video on your home page and the goal you are tracking is “requesting a demo”. You can track the video on the home page and see in your TrenDemon report how many visitors who viewed the video also requested a demo after doing so.

In the following post, you will find a tutorial on how to add TrenDemon’s pixel to a YouTube video.

**Note:** In order to track a YouTube video that is played on your website, you should also use the YouTube Player API.

Here are the steps:

1\) When you embed a YouTube video as an \<iframe\> element, make sure that either the player’s src URL includes the enable jsapi parameter = 1 or the \<iframe\> element’s enablejsapi attribute is set to “true”. Example:

```
<iframe id="iframe-example" src="https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1"></iframe>
```

2\) Each YouTube video \<iframe\> element should have a specific ID.

Example:

```
<iframe id="iframe-example" src="https://www.youtube.com/embed/M7lc1UVf-VE?enablejsapi=1"></iframe>
```

3\) Load the YouTube Player API so that you can track the number of clicks on “play”. Add this code to the \<body\> of the page:

```
<script>// Inject YouTube API scriptvar tag = document.createElement('script');tag.src = "https://www.youtube.com/player_api";var firstScriptTag = document.getElementsByTagName('script')[0];firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);var player;function onYouTubePlayerAPIReady() {// create the global player from the specific iframe (#video) player = new YT.Player('IFRAME_ID', { events: { // call this function when player changes the state 'onStateChange': onPlayerStateChange } });}function onPlayerStateChange(event) { if(event.data ==1){ //fire pixel var img = new Image(1,1); img.src = 'https://prod.trendemon.com/apis/loadflame/pixel?user_id=USER_ID&conv_id=GOAL_ID'; }}</script> 
```

Note: make sure that the img.src is the pixel for the event you created.

Here is the [reference](https://developers.google.com/youtube/iframe_api_reference) to the YouTube documentation.

 

For any questions or issues, please contact our [support team.](mailto:support@trendemon.com)

- [Getting started](https://support.trendemon.com/getting-started?hsLang=en)
- [Personalization](https://support.trendemon.com/personalization?hsLang=en)
- [Integrations](https://support.trendemon.com/integrations?hsLang=en)
- [Account based orchestration](https://support.trendemon.com/account-based-orchestration?hsLang=en)
- [Privacy, Security and Compliance](https://support.trendemon.com/privacy-security-and-compliance?hsLang=en)
- [FAQ & Troubleshooting](https://support.trendemon.com/faq-troubleshooting?hsLang=en)
- [Best Practices](https://support.trendemon.com/best-practices?hsLang=en)

[![Chill listening crop-3](https://support.trendemon.com/hs-fs/hubfs/TrenDemon%20logo.png?width=132&height=24&name=TrenDemon%20logo.png "Chill listening crop-3")](http://trendemon.com?hsLang=en)

Trendemon Success Center

<https://www.linkedin.com/company/trendemon/>

Copyright © 2026, Trendemon