videojs-event-tracking icon indicating copy to clipboard operation
videojs-event-tracking copied to clipboard

Performance metrics not active when enabled via player.on

Open jollyrogue opened this issue 2 years ago • 2 comments

I'm trying to the performance tracker to fire off via player.on().

Adding a "performance" function to the eventTracking config works.

player.eventTracking({
    performance: function(data) {
      console.log('tracking:performance', data);
    }
});

Adding it via player.on() does not work. This is my preferred method, but it doesn't fire off.

player.on('tracking:performance', (e, data) => console.log(e.type, data))

I'm working with the index.html in the Github repo. I followed the instructions in the Readme to clone the repo, install the dependencies, and open the index.html.

Browser: Firefox Developer Edition 103.0b9 (64-bit) VideoJS: 7.18.1

jollyrogue avatar Jul 19 '22 23:07 jollyrogue

Same here

denys-medynskyi avatar Aug 31 '22 07:08 denys-medynskyi

Looks like the README is a bit outdated (it's said to be experimental - I will update this now). This event trigger is removed due to accuracy and is only really available with passing the function through the configuration. The culprit is the unload event for the browser. Without it being a synchronous function, you will loose the ability to track when the user refreshes the browser / backs out / closes the window.

If you do want this and are OK with the inaccuracy, here is a quick code change; https://github.com/spodlecki/videojs-event-tracking/pull/32

I'm open to any Pull Requests. I've updated the readme & examples as well in master

spodlecki avatar Aug 31 '22 13:08 spodlecki