Created
February 22, 2014 04:34
-
-
Save ttrefren/9148828 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function onYouTubePlayerReady(playerId) { | |
ytplayer = document.getElementById("myytplayer"); | |
ytplayer.addEventListener("onStateChange", "onytplayerStateChange"); | |
} | |
function onytplayerStateChange(newState) { | |
ytplayer = document.getElementById("myytplayer"); | |
var props = {}; | |
props['duration'] = ytplayer.getDuration(); | |
props['elapsed'] = ytplayer.getCurrentTime(); | |
props['percent complete'] = ytplayer.getCurrentTime() / ytplayer.getDuration(); | |
props['quality level'] = ytplayer.getPlaybackQuality(); | |
props['video name'] = "Arab Revolutions"; | |
if(newState==-1){ | |
mixpanel.track("Video Loaded",props); | |
console.log("Video Loaded"); | |
} | |
else if(newState==0){ | |
mixpanel.track("Video Ended",props); | |
console.log("Video Ended"); | |
} | |
else if(newState==1){ | |
mixpanel.track("Video Playing",props); | |
console.log("Video Playing"); | |
} | |
else if(newState==2){ | |
mixpanel.track("Video Paused",props); | |
console.log("Video Paused"); | |
} | |
else{ | |
mixpanel.track("Video Event "+newState,props); | |
console.log("Video Event "+newState); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment