Tracking in embedded videos | XM Community
Skip to main content
Question

Tracking in embedded videos

  • January 19, 2024
  • 2 replies
  • 84 views

Forum|alt.badge.img+1

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? 

2 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • 2050 replies
  • January 19, 2024

Use plyr.io


Umang Upadhyay
QPN Level 4 ●●●●
Forum|alt.badge.img+25
  • QPN Level 4 ●●●●
  • 122 replies
  • February 5, 2024

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);
   });
 });
});