Created
March 22, 2021 18:34
-
-
Save rdundon/ad03aee7f82792cf571b1ed541ba969f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "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