11import videojs from 'video.js' ;
2- import { sliceProperties } from 'utils/slicing' ;
3- import { normalizeEventsParam , default as ExtendedEvents } from 'extended-events' ;
2+ import { normalizeEventsParam } from 'extended-events' ;
43import { PLAYER_EVENT } from '../../utils/consts' ;
54
65const DEFAULT_EVENTS = [
@@ -38,36 +37,24 @@ class AnalyticsPlugin {
3837 this . options = videojs . obj . merge ( DEFAULT_OPTIONS , initOptions ) ;
3938 this . events = normalizeEventsParam ( this . options . events , EVENT_DEFAULTS ) ;
4039
41- const extendedEvents = sliceProperties ( this . events , PLAYER_EVENT . PERCENTS_PLAYED , PLAYER_EVENT . TIME_PLAYED , PLAYER_EVENT . PAUSE , PLAYER_EVENT . SEEK ) ;
42-
43- if ( extendedEvents . pause ) {
44- delete extendedEvents . pause ;
45- extendedEvents . pausenoseek = { } ;
46- }
47-
48- this . _extendedEvents = new ExtendedEvents ( player , { events : extendedEvents } ) ;
49-
50- this . _currentSource = null ;
5140 this . _startTracked = null ;
5241 this . _endTracked = null ;
5342
5443 this . resetState ( ) ;
5544 }
5645
5746 init ( ) {
58- const playerLoad = ( ) => {
59- this . track ( { action : 'Player Load' , label : window . location . href , nonInteraction : true } ) ;
47+ const playerLoad = ( event , data ) => {
48+ const label = data ?. url || window . location . href ;
49+ this . track ( { action : 'Player Load' , label, nonInteraction : true } ) ;
6050 } ;
6151
6252 const play = ( ) => {
6353 this . track ( { action : 'Play' } ) ;
6454 } ;
6555
6656 const start = ( ) => {
67- if ( this . _startTracked ) {
68- this . track ( { action : 'Start' } ) ;
69- this . _startTracked = true ;
70- }
57+ this . track ( { action : 'Start' } ) ;
7158 } ;
7259
7360 const pause = ( ) => {
@@ -174,34 +161,36 @@ class AnalyticsPlugin {
174161 }
175162
176163 if ( this . events . start ) {
177- this . player . on ( PLAYER_EVENT . PLAYING , start . bind ( this ) ) ;
164+ this . player . on ( PLAYER_EVENT . START , start . bind ( this ) ) ;
178165 }
179166
180167 if ( this . events . fullscreenchange ) {
181168 this . player . on ( PLAYER_EVENT . FULL_SCREEN_CHANGE , fullscreenchange . bind ( this ) ) ;
182169 }
183170
184171 if ( this . events . percentsplayed ) {
185- this . _extendedEvents . on ( PLAYER_EVENT . PERCENTS_PLAYED , percentsPlayed . bind ( this ) ) ;
172+ this . player . on ( PLAYER_EVENT . PERCENTS_PLAYED , percentsPlayed . bind ( this ) ) ;
186173 }
187174
188175 if ( this . events . timeplayed ) {
189- this . _extendedEvents . on ( PLAYER_EVENT . TIME_PLAYED , timePlayed . bind ( this ) ) ;
176+ this . player . on ( PLAYER_EVENT . TIME_PLAYED , timePlayed . bind ( this ) ) ;
190177 }
191178
192179 if ( this . events . pause ) {
193- this . _extendedEvents . on ( PLAYER_EVENT . PAUSE_NO_SEEK , pause . bind ( this ) ) ;
180+ this . player . on ( PLAYER_EVENT . PAUSE_NO_SEEK , pause . bind ( this ) ) ;
194181 }
195182
196183 if ( this . events . seek ) {
197- this . _extendedEvents . on ( PLAYER_EVENT . SEEK , seek . bind ( this ) ) ;
184+ this . player . on ( PLAYER_EVENT . SEEK , seek . bind ( this ) ) ;
198185 }
199186
200187 if ( this . events . playerload ) {
201- playerLoad ( ) ;
188+ this . player . on ( PLAYER_EVENT . PLAYER_LOAD , playerLoad . bind ( this ) ) ;
202189 }
203190
204- this . player . on ( PLAYER_EVENT . LOADED_METADATA , this . loadedmetadata . bind ( this ) ) ;
191+ if ( this . events . videoload ) {
192+ this . player . on ( PLAYER_EVENT . VIDEO_LOAD , this . videoload . bind ( this ) ) ;
193+ }
205194 }
206195
207196 track ( { action, label, value = null , nonInteraction = false } ) {
@@ -219,24 +208,10 @@ class AnalyticsPlugin {
219208 }
220209
221210 resetState ( ) {
222- this . _currentSource = '' ;
223211 this . _startTracked = false ;
224212 this . _endTracked = false ;
225213 }
226214
227- loadedmetadata ( ) {
228- const src = this . player . currentSource ( ) . src ;
229-
230- if ( src !== this . _currentSource ) {
231- this . resetState ( ) ;
232- this . _currentSource = src ;
233-
234- if ( this . events . videoload ) {
235- this . videoload ( ) ;
236- }
237- }
238- }
239-
240215}
241216
242217export default function ( opts = { } ) {
0 commit comments