Last active
September 27, 2017 06:17
-
-
Save sahanh/5be63695a03e77354032522a68270ec8 to your computer and use it in GitHub Desktop.
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 options = { | |
facebookPixelId: '45454545454', | |
customEvent: false, | |
injectionProgress: 50 | |
}; | |
$(document).ready(function(){ var timer; var player; var injected = false; $('iframe').each(function(){ var ele = $(this); if (ele.attr('id').indexOf('fitvid') < 0) { return; } var video = ele; var id = video.attr('id'); var src = video.attr('src') + '&enablejsapi=1'; video.attr('src', src); video.load(function(){ player = new YT.Player(id, { events: { 'onStateChange': onPlayerStateChange } }); }); function onPlayerStateChange(event) { if (event.data == YT.PlayerState.PLAYING) { var playerTotalTime = player.getDuration(); timer = setInterval(function() { var playerCurrentTime = player.getCurrentTime(); var playProgress = Math.ceil((playerCurrentTime / playerTotalTime) * 100); if (playProgress > options.injectionProgress && !injected) { if (!injected) { var eventData; if (options.customEvent !== false) { eventData = options.customEvent + '&cd[progress]='+ playProgress; } else { eventData = 'PageView'; } var pixeltag = document.createElement('img'); pixeltag.src = 'https://www.facebook.com/tr?id='+options.facebookPixelId+'&ev=' + eventData + '&noscript=1'; pixeltag.height = 1; pixeltag.width = 1; document.body.appendChild(pixeltag); injected = true; } } }, 1000); } else { clearTimeout(timer); } } }); }); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment