Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track how long a user has watched a video

I teach an online course, and I need to make sure my students actually watch a certain video. Now, I understand that everything can be defeated, but what I'm looking is the 80/20 rule were I can make a few tweaks to start on the journey of accountability for my students.

Q1: Is there a way via JavaScript to fire an event if the current window loses focus?

Q2: Is there a way to fire an event when the video finishes playing?

Q3: Is there a way to make sure the video was played all the way through instead of the student clicking on the end of the timeline?

I feel compelled to say (again), please don't answer this questions with something like "you're wasting your time, the students will defeat anything that you do".

like image 445
Phillip Senn Avatar asked Oct 05 '12 19:10

Phillip Senn


1 Answers

What is the player you are using. If you are using open source video players like JWPlayer or Flow Player. You can track events. I personally prefer flow player and you can use google analytics to track the duration and any other task you want on the page.

as you have an authentication mechanism on the page you can get the username of the student (or an identifier). Push events to google analytic with this as a label and you can track each and everything the student do including the links he clicked, duration what played, when he played ...

  • you can setup google analytic http://www.google.lk/analytics/ its Free :)
  • Event tracking guide https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide
  • Flow player events http://flash.flowplayer.org/documentation/events/player.html

example setup

        <script type="text/javascript">

      var _gaq = _gaq || [];
      _gaq.push(['_setAccount', '#########']);
      _gaq.push(['_trackPageview']);
      (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

      })();

    </script>

To track

_gaq.push(['_trackEvent', 'Videos', 'Play', 'Gone With the Wind']);

this is part of the live code i took from http://vsp.ideawide.com/ in which I track some of those events.

var events = {
    clip : {
        onStart: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Play", defaults.source]);
        },


        onPause: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Pause", defaults.source, parseInt(this.getTime())]);
        },

        onResume: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Resume", defaults.source, parseInt(this.getTime())]);
        },

        onSeek: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Seek", defaults.source ]);
        },

        onStop: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Stop", defaults.source, parseInt(this.getTime())]);
        },
         onFinish: function(clip) {
            _gaq.push(['_trackEvent',"Videos", "Finish", defaults.source]);
        }
    },
    onFullscreen: function() {
        _gaq.push(['_trackEvent',"Videos", "Full Screen", defaults.source]);
    },
    onError: function(errorCode , errorMessage) {
        _gaq.push(['_trackEvent',"Videos", "Error", defaults.source, errorCode ]);
    }
}

As a final note with analytic properly setup with a proper player you can improve your 80/20 to 99/1.

like image 158
udnisap Avatar answered Nov 15 '22 16:11

udnisap