spodlecki / videojs-event-tracking

Track events with VideoJS and keep an eye on performance metrics
MIT License
71 stars 16 forks source link

Performance metrics not active when enabled via player.on #31

Closed jollyrogue closed 6 months ago

jollyrogue commented 2 years ago

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

denys-medynskyi commented 2 years ago

Same here

spodlecki commented 2 years ago

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