Skip to content

Instantly share code, notes, and snippets.

@Kugelschieber
Last active December 2, 2023 17:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kugelschieber/09c911e0637da8b6cbd54cee1969dc64 to your computer and use it in GitHub Desktop.
Save Kugelschieber/09c911e0637da8b6cbd54cee1969dc64 to your computer and use it in GitHub Desktop.
Pirsch Vimeo Video Tracking Demo
<!DOCTYPE html>
<html>
<head>
<title>Vimeo Pirsch Demo</title>
<!-- Add the Pirsch extended script to support page views and events. -->
<script defer src="https://api.pirsch.io/pirsch-extended.js"
id="pirschextendedjs"
data-code="YOUR_PIRSCH_CODE"></script>
<!-- Add the Vimeo player.js script -->
<script src="https://player.vimeo.com/api/player.js"></script>
</head>
<body>
<div id="player"></div>
<script>
// Initialize the player and set up an event handler for state changes.
let player;
let progress = 0;
document.addEventListener("DOMContentLoaded", () => {
var iframe = document.querySelector('#player');
player = new Vimeo.Player(iframe, {
id: 76979871, // Replace with your Vimeo video ID.
width: 640
});
// Event listener for the play progress
player.on('timeupdate', function(data) {
progress = Math.round(data.percent * 100);
console.log(progress); // debugging
});
});
// Send the progress when the page is navigated away from or the tab/window is closed.
window.addEventListener("beforeunload", () => {
pirsch("Vimeo Video Playback", {
meta: {
progress
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment