trackEvent updating video play duration


#1

Hello
I need to track a progress of movie watching

On movie clicking I call:
_paq.push([‘trackEvent’, ‘Video’, ‘Play-0%’, someTitle]);

This works good.

After half of video is passed I need to track it as well. So I’m sending:
_paq.push([‘trackEvent’, ‘Video’, ‘Play-50%’, someTitle]);

In admin panel I see:
action Play-0% - 1
action Play-50% - 1

Is it possible to delete first event? Should be only
action Play-50% - 1


(Matthieu Aubry) #2

We now have a Media Analytics plugin that tracks Videos & Audio!

More information is available here: http://www.media-analytics.net/ The plugin gives useful insights into media / video / audio analytics and adds many new reports, widgets and segments to Piwik.

Works with HTML5 video & audio, Vimeo and YouTube out of the box. Support for other players can be added easily and is documented in the developer docs. We are also happy to add support for more players upon request, please ping us. After installation the plugin will in most cases directly start tracking data see the setup guide

For a full list of features check out https://plugins.piwik.org/MediaAnalytics . Docs are available at FAQ, User Guide, Developer docs


#3

Here is some code (inspired by Track when user listens to a sound file from Lukas) that might help you:

document.addEventListener("DOMContentLoaded", function(event) {
  var videos = document.getElementsByTagName("video");
  for (var index = 0; index < videos.length; ++index) {
    var video = videos[index];
    video.addEventListener("playing", function() {
      _paq.push(['trackEvent', 'video', 'play', this.id]);
    }, true);
    video.addEventListener("pause", function() {
      if(this.currentTime < this.duration){
        _paq.push(['trackEvent', 'video', 'pause', this.id, this.currentTime]);
      }
    }, true);
    video.addEventListener("ended", function() {
      _paq.push(['trackEvent', 'video', 'completed', this.id, this.currentTime]);
    }, true);
    video.addEventListener("seeking", function() {
      _paq.push(['trackEvent', 'video', 'seek', this.id, this.currentTime]);
    }, true);
    video.addEventListener("error", function() {
      _paq.push(['trackEvent', 'video', 'error', this.id]);
    }, true);
  }
});

This should add events to your piwik analytics for video play, error, pause, seeking, and completion – with the length played as the event value for the latter three.


#4

Hey, this sounds like an interesting implementation. Where to I place it? in the tracking Code of the WordPress Plugin?


#5

I’m not familiar with the wordpress plugin you’re referring to but you should be able to place that javascript anywhere after your HTML5 video tags, or place it in an onload.

It could also potentially be placed in a deferred javascript file, though I have found deferred javascript loading to be unreliable at best.

If your videos are being added to the DOM asynchronously you will have to run the code using a callback.


#6

thanks, I will give it a try