This repository has been archived by the owner on Apr 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathyoutube.ga.min.js
7 lines (7 loc) · 2.65 KB
/
youtube.ga.min.js
1
2
3
4
5
6
7
/*!
* youtube.ga.js | v0.3
* Copyright (c) 2012 - 2013 Sander Heilbron (http://sanderheilbron.nl)
* Edits by Ali Karbassi (http://karbassi.com)
* MIT licensed
*/
function onYouTubePlayerAPIReady(){var e={height:configYouTubePlayer.height,width:configYouTubePlayer.width,videoId:configYouTubePlayer.videoID,playerVars:{},events:{onReady:onPlayerReady,onStateChange:onPlayerStateChange,onPlaybackQualityChange:onPlayerPlaybackQualityChange}};for(var t in configYouTubePlayer.playerVars){if(!configYouTubePlayer.playerVars.hasOwnProperty(t)){continue}e.playerVars[t]=configYouTubePlayer.playerVars[t]}YT_GA.player=new YT.Player("ytplayer",e)}function onPlayerReady(e){setInterval(onPlayerProgressChange,500);YT_GA.progress25=false;YT_GA.progress50=false;YT_GA.progress75=false;YT_GA.url=YT_GA.player.getVideoUrl();YT_GA.videoPlayed=false;YT_GA.videoCompleted=false}function onPlayerProgressChange(){if(!configYouTubePlayer.trackProgress||typeof _gaq==="undefined"){return}YT_GA.timePercentComplete=Math.round(YT_GA.player.getCurrentTime()/YT_GA.player.getDuration()*100);var e;if(YT_GA.timePercentComplete>24&&!YT_GA.progress25){e="25%";YT_GA.progress25=true}if(YT_GA.timePercentComplete>49&&!YT_GA.progress50){e="50%";YT_GA.progress50=true}if(YT_GA.timePercentComplete>74&&!YT_GA.progress75){e="75%";YT_GA.progress75=true}if(e){_gaq.push(["_trackEvent","YouTube","Played video: "+e,YT_GA.url,undefined,true])}}function onPlayerPlaybackQualityChange(e){if(!configYouTubePlayer.trackPlaybackQuality||typeof _gaq==="undefined"){return}var t;switch(e.data){case"hd1080":t="1080p HD";break;case"hd720":t="720p HD";break;case"large":t="480p";break;case"medium":t="360p";break;case"small":t="240p";break}if(t){_gaq.push(["_trackEvent","YouTube","Video quality: "+t,YT_GA.url,undefined,true])}}function onPlayerStateChange(e){if(typeof _gaq==="undefined"){return}YT_GA.timePercentComplete=Math.round(YT_GA.player.getCurrentTime()/YT_GA.player.getDuration()*100);if(e.data===YT.PlayerState.PLAYING&&!YT_GA.videoPlayed){_gaq.push(["_trackEvent","YouTube","Started video",YT_GA.url,undefined,true]);YT_GA.videoPaused=false;YT_GA.videoPlayed=true}else if(e.data===YT.PlayerState.PAUSED&&YT_GA.timePercentComplete<92&&!YT_GA.videoPaused){_gaq.push(["_trackEvent","YouTube","Paused video",YT_GA.url,undefined,true]);YT_GA.videoPaused=true}else if(e.data===YT.PlayerState.ENDED&&!YT_GA.videoCompleted){_gaq.push(["_trackEvent","YouTube","Completed video",YT_GA.url,undefined,true]);YT_GA.videoCompleted=true}}var tag=document.createElement("script");tag.src="//youtube.com/iframe_api";var firstScriptTag=document.getElementsByTagName("script")[0];firstScriptTag.parentNode.insertBefore(tag,firstScriptTag);var YT_GA=YT_GA||{}