Skip to content

Instantly share code, notes, and snippets.

@rdundon
Created March 22, 2021 18:34
Show Gist options
  • Save rdundon/ad03aee7f82792cf571b1ed541ba969f to your computer and use it in GitHub Desktop.
Save rdundon/ad03aee7f82792cf571b1ed541ba969f to your computer and use it in GitHub Desktop.
// "videoTag" is <video> element pulled from the DOM
var videoPercentageRate = this.duration / 100;
var videoCompletionRateIntervals = [25,50,75,100];
videoTag.play = function() {
var percentageCompleted = (videoTag.currentTime / videoTag.duration) * 100
console.log(percentageCompleted);
if (percentageCompleted >= videoCompletionRateIntervals[0]) {
console.log(videoCompletionRateIntervals[0], '% of video completed');
// GA Event
videoCompletionRateIntervals.splice(0,1);
}
if (videoCompletionRateIntervals.length == 0) {
videoTag.play = null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment