Tracking Vimeo videos to LMFX using GTM is easy. All you have to do is follow the instructions on the Guru card related to Vimeo Video tracking. But what about pop-up videos? This is an issue that most Analysts face whenever they have to track Vimeo pop-up videos. I’ve tried many ways to edit the existing JS listener but have had no luck. I even tried using TeamAI to update it, but it still doesn’t work.
There are several potential reasons why the existing js listener might not work with pop-up Vimeo videos:
Same-Origin Policy: If the pop-up video is hosted on a different domain or subdomain, the browser’s same-origin policy might prevent the script from communicating with the iframe.
Dynamic Content Loading: If the pop-up content (including the Vimeo iframe) is loaded dynamically after the initial page load, your script might not be attaching event listeners to the newly added iframes.
Iframe ID and API Parameters: The script checks and updates the iframe src attribute to include necessary API parameters (api=1 and player_id). If these parameters are not correctly set or if the iframe is reloaded without these parameters, it might not work as expected.
Error Handling: The error handling in your script catches errors but does not log them in a way that you can easily debug. This makes it hard to identify what exactly is going wrong.
Luckily, after sometime of researching, I found a resource (a website) that talks about the exact issue I have (some sort of a forum) and they introduce new ways of tracking Vimeo pop up videos using the new and improved js script below
<script src="https://player.vimeo.com/api/player.js"></script><script>(function() {var videoProgress = [10, 25, 50, 75];function handlePlayer(player) {var triggeredSteps = {};var video_title = '';var video_url = '';var isStarted = false;var upperRange = 2;player.getVideoTitle().then(function(title) {video_title = title;});player.getVideoUrl().then(function(url) {video_url = url;});player.on('play', function(data) {if (!isStarted) {if(data.duration < 30) {upperRange = 6;}window.dataLayer = window.dataLayer || [];dataLayer.push({event: 'video',video_action: 'start',video_current_time: 0,video_duration: data.duration,video_percent: 0,video_provider: 'Vimeo',video_title: video_title,video_url: video_url})isStarted = true;}});player.on('ended', function(data) {window.dataLayer = window.dataLayer || [];dataLayer.push({event: 'video',video_action: 'complete',video_current_time: data.seconds,video_duration: data.duration,video_percent: 100,video_provider: 'Vimeo',video_title: video_title,video_url: video_url});});player.on('timeupdate', function(data) {var actualPercent = data.percent * 100;videoProgress.forEach(function(targetPercent) {if (!triggeredSteps[targetPercent] &&actualPercent >= targetPercent &&actualPercent <= targetPercent + upperRange) {window.dataLayer = window.dataLayer || [];dataLayer.push({event: 'video',video_action: 'progress',video_current_time: data.seconds,video_duration: data.duration,video_percent: targetPercent,video_provider: 'Vimeo',video_title: video_title,video_url: video_url});triggeredSteps[targetPercent] = true;}});});}function findVimeoPlayer(node) {if (node.tagName === 'IFRAME' && node.src.includes('player.vimeo.com/video')) {var player = new Vimeo.Player(node);handlePlayer(player);} else {var iframes = node.querySelectorAll('iframe');iframes.forEach(function(iframe) {if (iframe.src.includes('player.vimeo.com/video')) {var player = new Vimeo.Player(iframe);handlePlayer(player);}});}}var observer = new MutationObserver(function(mutationsList) {mutationsList.forEach(function(mutation) {if (mutation.type === 'childList') {mutation.addedNodes.forEach(function(node) {findVimeoPlayer(node);});}});});observer.observe(document.body, { childList: true, subtree: true });var existingPlayers = document.querySelectorAll('iframe[src^="https://player.vimeo.com/video"]');existingPlayers.forEach(function(playerNode) {handlePlayer(new Vimeo.Player(playerNode));});})();</script> ***By leveraging the Vimeo Player API library, using a MutationObserver for dynamic content, and simplifying event handling, this script effectively tracks interactions with both existing and newly added Vimeo pop-up videos.
Updated Guru card which includes the js script that capture/listens to Vimeo pop-up videos: https://app.getguru.com/card/cXz7bKbi/Tracking-NonYouTube-Video-Events-in-LeadManagerFX