Last active
July 11, 2019 04:03
-
-
Save thomaspuppe/7de84f378c76ac532fcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function( vjs ) { | |
var videojsEventBroadcastPlugin = function( options ) { | |
var player = this, | |
postEventToWindow = function( eventString ) { | |
var messageData = { | |
'name': 'zonTriggeredEventTracking', | |
'sender': 'videojs', | |
'event': eventString | |
}; | |
window.parent.postMessage( JSON.stringify( messageData ), '*' ); | |
window.console.log( messageData ); | |
}; | |
// the play event is triggered on several occasions: | |
// - two(!) times on start (with currentTime undefined and currentTime 0) | |
// - on resume (after pause). | |
// - on jumping to another position in the video | |
// That's why we ose one() for registering the event. (Another solution | |
// would be to check for that one event which has currentTime===0.) | |
player.one( 'play', function( e ) { | |
postEventToWindow( 'playerStarted' ); | |
}); | |
// contentplayback is triggered when the real video content begins. | |
// It does not matter if an ad was played before or not. | |
// But: it is triggered again at the end of a video. Hence, "one()". | |
player.one( 'contentplayback', function( e ) { | |
postEventToWindow( 'contentStarted' ); | |
}); | |
// one() just to be sure (see above) | |
player.one( 'ended', function( e ) { | |
postEventToWindow( 'contentCompleted' ); | |
}); | |
// Testing Ad events | |
player.on( 'ads-request', function( e ) { | |
postEventToWindow( 'adRequested' ); | |
}); | |
player.on( 'ads-load', function( e ) { | |
postEventToWindow( 'adDataLoaded' ); | |
}); | |
player.on( 'ads-ad-started', function( e ) { | |
postEventToWindow( 'adStarted' ); | |
}); | |
player.on( 'ads-ad-ended', function( e ) { | |
postEventToWindow( 'adEnded' ); | |
}); | |
/* | |
Events: http://docs.brightcove.com/en/video-cloud/brightcove-player/reference/api/vjs.Player.html#eventsSection | |
Interessante Properties: | |
- this.techName (Html5 - vermutlich vs Flash) | |
- this.options.autoplay | |
*/ | |
player.on( 'durationchange', function( e ) { window.console.log( 'videoJS: durationchange' ); }); | |
player.on( 'ended', function( e ) { window.console.log( 'videoJS: ended' ); }); | |
player.on( 'error', function( e ) { window.console.log( 'videoJS: error' ); }); | |
player.on( 'firstplay', function( e ) { window.console.log( 'videoJS: firstplay' ); }); | |
player.on( 'loadedalldata', function( e ) { window.console.log( 'videoJS: loadedalldata' ); }); | |
player.on( 'loadeddata', function( e ) { window.console.log( 'videoJS: loadeddata' ); }); | |
player.on( 'loadedmetadata', function( e ) { window.console.log( 'videoJS: loadedmetadata' ); }); | |
player.on( 'loadstart', function( e ) { window.console.log( 'videoJS: loadstart' ); }); | |
player.on( 'pause', function( e ) { window.console.log( 'videoJS: pause' ); }); | |
player.on( 'play', function( e ) { window.console.log( 'videoJS: play (adState: ' + player.ads.state + ')' ); }); | |
player.on( 'seeked', function( e ) { window.console.log( 'videoJS: seeked' ); }); | |
player.on( 'seeking', function( e ) { window.console.log( 'videoJS: seeking' ); }); | |
player.on( 'waiting', function( e ) { window.console.log( 'videoJS: waiting' ); }); | |
player.on( 'contentplayback', function( e ) { window.console.log( 'videoJS: contentplayback' ); }); | |
player.on( 'ended', function( e ) { window.console.log( 'videoJS: ended' ); }); | |
player.on( 'ima3error', function( e ) { window.console.log( 'videoJS/IMA3: ima3error' ); }); | |
player.on( 'ima3-ad-error', function( e ) { window.console.log( 'videoJS/IMA3: ima3-ad-error' ); }); | |
player.on( 'ima3-ready', function( e ) { window.console.log( 'videoJS/IMA3: ima3-ready' ); }); | |
player.on( 'ads-request', function( e ) { window.console.log( 'videoJS/Ads: ads-request' ); }); | |
player.on( 'ads-load', function( e ) { window.console.log( 'videoJS/Ads: ads-load' ); }); | |
player.on( 'ads-ad-started', function( e ) { window.console.log( 'videoJS/Ads: ads-ad-started' ); }); | |
player.on( 'ads-ad-ended', function( e ) { window.console.log( 'videoJS/Ads: ads-ad-ended' ); }); | |
player.on( 'ads-first-quartile', function( e ) { window.console.log( 'videoJS/Ads: ads-first-quartile' ); }); | |
}; | |
vjs.plugin( 'videojsEventBroadcast', videojsEventBroadcastPlugin ); | |
}( window.videojs )); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment