Skip to content

Instantly share code, notes, and snippets.

@rdundon
Created March 22, 2021 18:34
Show Gist options
  • Select an option

  • Save rdundon/94b2c97647f6d02eca5d5646c04c7ed0 to your computer and use it in GitHub Desktop.

Select an option

Save rdundon/94b2c97647f6d02eca5d5646c04c7ed0 to your computer and use it in GitHub Desktop.

Revisions

  1. rdundon created this gist Mar 22, 2021.
    18 changes: 18 additions & 0 deletions simple_video_progress.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    // "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;
    }
    }