Insight Agent for Browsers
Integration Guide
The ni-agent.js file contains a minified build of the agent exported as a Universal Module Definition (UMD). The module is exported to the global variable n, and you can call all the methods described in the api on this object.
Load the agent
JS
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>NI Agent Integration</title>
</head>
<body>
<!-- ... -->
<script src="path/to/ni-agent.js" />
</body>
</html>
Initialize the agent
JS
ni.initialize({
operatorId: 'abcdefabcdef',
deviceId: '123456789',
// additional options are available, please refer to the API documentation
});
Start reporting
JS
// The user requested to play something...
ni.play();
// ... it is live content: the user is watching the news on "channel one"
ni.setLiveContent({
channelId: 'CHANNEL1',
channelName: 'Channel One',
eventId: 'NEWS_EVENING',
eventName: 'The News',
duration: 942,
});
// (later) Initial buffering is complete and playback started
ni.playing();
// On player progress events, update the position
ni.setPosition(1);
ni.setPosition(2);
ni.setPosition(3);
// (eventually) Network is too slow, the player needs to freeze playback in order to do additional buffering
ni.buffering();
// (eventually) Everything is back to normal
ni.playing();
// User pauses playback
ni.pause();
// User resumes playback
ni.playing();
// User stop playback of this content
ni.stop();
// At this point it is needed to call play() and set*Content() again when another content is viewed
Please refer to the API for the full documentation on all available methods
Terminating the agent
This terminates the reporting session in a clean manner. It should be called just before the page is unloaded.
JS
ni.terminate();
To continue reporting after calling the terminate() method, you must re-initialize the player first; for example
ni.initialize(...)
.