Created
October 30, 2013 15:56
-
-
Save pablolobos/7235107 to your computer and use it in GitHub Desktop.
js_youtube_video_tracking
This file contains 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
<script type="text/javascript"> | |
var tag = document.createElement('script'); | |
tag.src = "http://www.youtube.com/player_api"; | |
var firstScriptTag = document.getElementsByTagName('script')[0]; | |
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); | |
var player1; | |
function onYouTubePlayerAPIReady() { | |
player1 = new YT.Player('player1', { | |
height: '315', | |
width: '560', | |
videoId: '-rh4xSsqq4Y', | |
playerVars: {rel: 0, showinfo: 0, controls: 1, autohide: 1}, | |
events: { | |
'onReady': onPlayerReady, | |
'onStateChange': onPlayerStateChange | |
} | |
}); | |
} | |
function onPlayerReady(event) { | |
/// event.target.playVideo(); | |
} | |
function onPlayerStateChange(event) { | |
if (event.data == YT.PlayerState.PLAYING) { | |
_gaq.push(['_trackEvent', 'Video Como invertir Landing Inversion', 'Play', | |
player1.getVideoUrl()]); | |
} | |
if (event.data == YT.PlayerState.PAUSED) { | |
_gaq.push(['_trackEvent', 'Video Como invertir Landing Inversion', 'Paused', | |
player1.getVideoUrl()]); | |
} | |
if (event.data == YT.PlayerState.ENDED) { | |
_gaq.push(['_trackEvent', 'Video Como invertir Landing Inversion', 'Watch to End', | |
player1.getVideoUrl()]); | |
} | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment