Skip to content

Instantly share code, notes, and snippets.

@ttrefren
Created February 22, 2014 04:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ttrefren/9148828 to your computer and use it in GitHub Desktop.
Save ttrefren/9148828 to your computer and use it in GitHub Desktop.
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