Skip to content

Instantly share code, notes, and snippets.

@Sanaldev
Created December 5, 2013 09:13
Show Gist options
  • Save Sanaldev/7802376 to your computer and use it in GitHub Desktop.
Save Sanaldev/7802376 to your computer and use it in GitHub Desktop.
VideoMarkups
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
var videoDuration;
var firstQuartileFlag = true;
var mutedFlag = false;
var videoad;
var updateProgressBar = function() {
progress = (100.0 * parseFloat(videoad.prop("played").end(0)) / videoDuration).toFixed(2);
if (firstQuartileFlag && progress >= 25.0 && progress < 50.0) {
trackEvent("firstQuartile");
firstQuartileFlag = false;
sendTracker();
}
};
function trackProgress() {
videoad = $('#videoad');
videoDuration = parseFloat(videoad.prop('duration'));
setInterval(updateProgressBar, 100);
}
function trackEvent(event) {
console.log(event);
}
function sendTracker() {
var xhr = new XMLHttpRequest();
xhr.open('GET', '<?php echo $tracking_url;?>', true);
xhr.onreadystatechange = function(e) {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText);
}
};
xhr.send();
}
</script>
</head>
<body>
<a href="<?php echo htmlspecialchars($clickthrough); ?>">
<video id="videoad" controls autoplay onplay="trackEvent('start'); trackProgress();" onshow="trackEvent('show');" onpause="trackEvent('pause');" onseeked="trackEvent('seeked');" onloadedmetadata="trackEvent('createView');" onended="trackEvent('complete');" >
<?php
echo "<source src=\"$videourl\" width=\"$width\" height=\"$height\" type=\"$type\">";
?>
</video>
</a>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment