Tracking in embedded videos | XM Community
Skip to main content

I have two embedded youtube videos and I want to track the number of times someone presses play without using youtube api. Anyone have a code for this? 

Use plyr.io


Hi @jyanson 

// Add this script to your Qualtrics survey
document.addEventListener('DOMContentLoaded', function () {
 // Assuming you have elements with class 'video-play-btn' for each video
 var playButtons = document.querySelectorAll('.video-play-btn');

 playButtons.forEach(function (button) {
   button.addEventListener('click', function () {
     // Increment a counter or send a tracking event to your analytics system
     // Example: Send data to Google Analytics
     // ga('send', 'event', 'Video', 'Play', 'Video Title');

     // Example: Increment a counter
     // You need to handle storage (localStorage, cookies, etc.) for persistent counting
     // var playCount = localStorage.getItem('videoPlayCount') || 0;
     // localStorage.setItem('videoPlayCount', ++playCount);
   });
 });
});


Leave a Reply