Collect data from client on during watching video.
npm install --save @filmgardi/videojs-collect-data
To include videojs-collect-data on your website or web application, use any of the following methods.
This is the simplest case. Get the script in whatever way you prefer and include the plugin after you include video.js, so that the videojs
global is available.
<script src="//path/to/video.min.js"></script>
<script src="//path/to/videojs-collect-data.min.js"></script>
<script>
var player = videojs('my-video');
const collectDataOption = {
intervalTime: 1000, // `intervalTime` get integer value. "base on miliseconds"
requiredParameter: [
{ name: 'require1', value: 'require1_Value' },
{ name: 'require2', value: 1 },
{ name: 'require3', value: true },
{ name: 'require4', value: new Date().getTime() },
{ name: 'require5', value: 12 },
],
action: { // The main action in each interval call this function.
name: 'Temp1', // The name of action.
method: 'POST', // GET,POST,PUT,DELETE
url: 'https://example.com/api/v1/temp',// The destination url
body: { // The body have to main parameter :
// params : the defination of your request body set here.
// config : the config is optional variable for create your body.
params: {
p1: 'p1_value', // static value
p2: 'p2_value', // static value
nestetParam: {
p3: 'FG-VIDEO_HALF_TIME', // FG-VIDEO_HALF_TIME : get half video duration
p4: 'FG-VIDEO_CURRENT_TIME', // FG-VIDEO_CURRENT_TIME : get videojs current time
p5: 'FG-DEVICE_RESOLUTION' // FG-DEVICE_RESOLUTION : get client monitor resolution
p6: 'FG-METHOD(${fuid} + "_" + ${fmid})', // FG-METHOD(arguments) : calculate arguments
p7: 'FG-VIDEO_MIN_TO_NOW', // FG-VIDEO_MIN_TO_NOW : get videojs difference between live time and play time
// you can use static value and `params` inside parameters in your arguments.
// ex.
// 1: FG-METHOD(${p1} + ${p2})
// 2: FG-METHOD(${require1} + ${require2})
// 3: FG-METHOD(${require2} * ${require5}) use same type value for ( * and / and - ) operation.
},
...
},
config: {
targetParam: 'nestetParam' // with this config `requiredParameter` object add to `targetParam` object if you did't set `targetParam` the object add to root of `params`.
ignore:{
requiredParameter: false, // with this option control append `requiredParameter`to your body
clientInfo: false // with this option control append `clientInfo`to your body
//clientInfo contain os: "Linux", osVersion: "x86_64", market: "WEB", marketVersion: "0.0.1"
}
}
}
},
altAction: [
{
name: 'Temp2',
method: 'POST',
url: 'https://example.com/api/v1/temp2',
body: {
params: {
p1: 'FG-VIDEO_HALF_TIME',
p2: 'FG-VIDEO_CURRENT_TIME',
p3: 'FG-DEVICE_RESOLUTION',
p4: 'FG-VIDEO_MIN_TO_NOW',
}
}
},
{
name: 'Temp3',
method: 'POST',
url: 'https://example.com/api/v1/temp3/',
headers: {
Authorization: 'Authorization hash',
...
},
body: {
params: {
p1: 'FG-VIDEO_HALF_TIME',
p2: 'FG-VIDEO_CURRENT_TIME',
p3: 'FG-VIDEO_MIN_TO_NOW',
}
}
}
]
};
player.collectData(collectDataOption);
</script>
When using with Browserify, install videojs-collect-data via npm and require
the plugin as you would any other module.
var videojs = require('video.js');
// The actual plugin function is exported by this module, but it is also
// attached to the `Player.prototype`; so, there is no need to assign it
// to a variable.
require('@filmgardi/videojs-collect-data');
var player = videojs('my-video');
player.collectData();
When using with RequireJS (or another AMD library), get the script in whatever way you prefer and require
the plugin as you normally would:
require(['video.js', '@filmgardi/videojs-collect-data'], function(videojs) {
var player = videojs('my-video');
player.collectData();
});
MIT. Copyright (c) m-saffari <[email protected]>