Tracking YouTube videos

Follow

Summary:

CANDDi can track Youtube videos so that you can record everyone who has started, paused, completed watching a video

This requires custom javascript to be added on to each page with a video on it

 

Reference-

https://developers.google.com/youtube/js_api_reference 

The demo here is good too-

https://developers.google.com/youtube/youtube_player_demo

 

How to track Youtube:

* This assumes you have jQuery on your site

 

1. "Get the dom element" which contains the YouTube video

 If the video code looks like this 

<iframe id="ytplayer" type="text/html" src="//www.youtube.com/embed/M7lc1UVf-VE" frameborder="0" allowfullscreen>

 

2. Add an event listener for the onstatechange event and trigger events to CANDDi

$( document ).ready(function() {
 $("#ytplayer").addEventListener(
  "onStateChange",
  function(newState) {
   if(window.canddi) {
    window.canddi.sendEvent(
     'video/[VideoName]/'+newState,
     {},
     false,
     "Video"
    );
});

});

NOTE: Replace [VideoName] with a unique identifier for this video, Replace start with the action you wish to track (start / stop / pause etc...)

Have more questions? Submit a request

Comments