class VideoTracker { constructor(videoElement) { this.reportedPlay = false; this.reported25Perc = false; this.reported50Perc = false; this.reported75Perc = false; this.reported100Perc = false; this.reportedEnd = false this.videoElement = videoElement this.videoElement.addEventListener('play', this.OnPlay.bind(this)) this.videoElement.addEventListener('timeupdate', this.onTimeUpdate.bind(this)) } OnPlay() { if (!this.reportedPlay) { console.log('report play video event') ga('send', 'event', 'Video', 'play', `PAGE: #{window.location.pathname}` ); this.reportedPlay = true } } onTimeUpdate () { if (this.videoElement.currentTime > 0.25 * this.videoElement.duration && !this.reported25Perc) { console.log('report video 25% played') ga('send', 'event', 'Video', '25%', `PAGE: #{window.location.pathname}` ); this.reported25Perc = true } if (this.videoElement.currentTime > 0.50 * this.videoElement.duration && !this.reported50Perc) { console.log('report video 50% played') ga('send', 'event', 'Video', '50%', `PAGE: #{window.location.pathname}` ); this.reported50Perc = true } if (this.videoElement.currentTime > 0.75 * this.videoElement.duration && !this.reported75Perc) { console.log('report video 75% played') ga('send', 'event', 'Video', '75%', `PAGE: #{window.location.pathname}` ); this.reported75Perc = true } if (this.videoElement.currentTime > 0.9999 * this.videoElement.duration && !this.reported100Perc) { console.log('report video 100% played') ga('send', 'event', 'Video', '100%', `PAGE: #{window.location.pathname}` ); this.reported100Perc = true } } } document.addEventListener('DOMContentLoaded', function(){ const videoContainers = document.querySelectorAll("[data-player-name='Playable']") console.log('found video containers:', videoContainers) videoContainers.forEach(function(container){ const videoElement = container.querySelector('video') if (!videoElement) { return } new VideoTracker(videoElement) }) })

info@zeptive.com

617-528-0258

  • zeptive facebook
  • zeptive twitter
  • zeptive linkedin

145 S. Bedford St.

Burlington, MA 01803

© 2021 by Zeptive. Happily Designed by LetsDesignYourSite.com