Last active
September 13, 2017 17:50
-
-
Save jramsahai/cd9aade063fdc4b3c056 to your computer and use it in GitHub Desktop.
Using Google Analytics Event tracking and the Vidyard player API, we can push player events into Google Analytics to allow us to capture some useful viewership data along side the standard web traffic reporting.
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
<html> | |
<head> | |
<!-- Vidyard player API script --> | |
<script src="//play.vidyard.com/v0/api.js"></script> | |
<!-- Google Analytics tracking code --> | |
<script> | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','//www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'UA-XXXXXXXX-X', 'auto'); | |
ga('send', 'pageview'); | |
</script> | |
</head> | |
<body> | |
<!-- Vidyard video embed code --> | |
<script type="text/javascript" id="vidyard_embed_code_CvMSiespEMc5lia2k2fHeg" src="//play.vidyard.com/CvMSiespEMc5lia2k2fHeg.js?v=3.1&type=inline"></script> | |
<!-- Player API tracking into Google Analytics --> | |
<script type="text/javascript"> | |
var video = new Vidyard.player("CvMSiespEMc5lia2k2fHeg"); | |
video.on("ready", function() { _gaq.push(['_trackEvent', 'Videos', 'Ready', 'Homepage Video']); }); | |
video.on("play", function() { _gaq.push(['_trackEvent', 'Videos', 'Play', 'Homepage Video']); }); | |
video.on("pause", function() { _gaq.push(['_trackEvent', 'Videos', 'Pause', 'Homepage Video']); }); | |
video.on("playerComplete", function() { _gaq.push(['_trackEvent', 'Videos', 'End', 'Homepage Video']); }); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment