React HLS Player is very popular player to play HLS streams on reactive websites.
Step 1: Create Gumlet Configuration JSON
All the data is associated to a property ID which you need to get from our dashboard. Pass it in the config JSON as property_id. This is the only required field.
There is an option to pass extra data such as the user specific data and video meta data which can be viewed in the dashboard as data breakdowns. A full list of variables is available here.
import './App.css';
import ReactHlsPlayer from '@gumlet/react-hls-player';
// Step 1: Create the Gumlet Configuration JSON
const gumletConfig = {
property_id: '<PROPERTY_ID_GOES_HERE>', // required: please replace with correct property id.
};
Step 2: Initialise the player
Initialise the player with the player options you want to configure it with. Pass the video URL to be played.
You need to add a reference to the player component, this will be used by Gumlet SDK to hook on.
import './App.css';
import ReactHlsPlayer from '@gumlet/react-hls-player';
// Step 1: Create the Gumlet Configuration JSON
const gumletConfig = {
property_id: '<PROPERTY_ID_GOES_HERE>', // required: please replace with correct property id.
};
// Step 2: Initialise player
function App() {
return (
<div className="App">
<ReactHlsPlayer
src="https://video.gumlet.io/5f462c1561cf8a766464ffc4/635789f017629894d4d125a4/main.m3u8"
autoPlay={false}
controls={true}
width="100%"
height="auto"
getHLSRef={(hlsJSObject) => {console.log(hlsJSObject);}}
/>
</div>
);
}
export default App;
Step 3: Gumlet Insights SDK Installation
The easiest way to integrate Gumlet insights SDK with react hls player is to load and append a script in the document body via a function
import './App.css';
import React, { useRef, useEffect, useState } from "react";
import ReactHlsPlayer from '@gumlet/react-hls-player';
// Step 1: Create the Gumlet Configuration JSON
const gumletConfig = {
property_id: '<PROPERTY_ID_GOES_HERE>', // required: please replace with correct property id.
};
// Step 2: Initialise player
function App() {
const playerRef = useRef(null);
const [gumletLoaded, setGumletLoaded] = useState(false);
// Step 3: Load Gumlet SDK
function _loadGumletScript() {
return new Promise(function (resolve, reject) {
if (document.querySelector("script#gumlet-insights-sdk-script")) {
resolve();
} else {
const script = document.createElement("script");
script.src = "https://cdn.gumlytics.com/insights/1.1.2/gumlet-insights.min.js";
script.id = "gumlet-insights-sdk-script";
script.async = true;
script.onload = () => resolve();
document.body.appendChild(script);
}
});
}
useEffect(() => {
_loadGumletScript().then(() => {
setGumletLoaded(true);
});
}, []);
// Until the gumlet script is loaded on the page i.e. the state variable is set, show a loader to
// the user
if(!gumletLoaded){
return (
<div>
<p>Loading...</p>
</div>
)
}
// end Step 3
return (
<div className="App">
<ReactHlsPlayer
src="https://video.gumlet.io/5f462c1561cf8a766464ffc4/635789f017629894d4d125a4/main.m3u8"
autoPlay={false}
controls={true}
width="100%"
height="auto"
playerRef={playerRef}
getHLSRef={(hlsJSObject) => {console.log(hlsJSObject);}}
/>
</div>
);
}
export default App;
Step 4: Initialise Gumlet Insights SDK
Initialise the Gumlet Insights SDK with the config JSON to start receiving data on your dashboard. Pass the player object which you created in the previous step to Gumlet Insights object.
import './App.css';
import React, { useRef, useEffect, useState } from "react";
import ReactHlsPlayer from '@gumlet/react-hls-player';
// Step 1: Create the Gumlet Configuration JSON
const gumletConfig = {
property_id: '<PROPERTY_ID_GOES_HERE>', // required: please replace with correct property id.
};
function App() {
const playerRef = useRef(null);
const [gumletLoaded, setGumletLoaded] = useState(false);
// Step 3: Load Gumlet SDK
function _loadGumletScript() {
return new Promise(async function (resolve, reject) {
if (document.querySelector("script#gumlet-insights-sdk")) {
resolve();
} else {
const script = document.createElement("script");
script.src = "https://cdn.gumlytics.com/insights/1.1.2/gumlet-insights.min.js";
script.id = "gumlet-insights-sdk";
script.async = false;
document.body.appendChild(script);
script.onload = () => resolve();
}
});
}
useEffect(() => {
_loadGumletScript().then(() => {
setGumletLoaded(true);
});
}, []);
// Until the gumlet script is loaded on the page i.e. the state variable is set, show a loader to
// the user
if(!gumletLoaded){
return (
<div>
<p>Loading...</p>
</div>
)
}
// Step 4: Initialize Gumlet SDK
function _attachHLSObjectToGumletSDK(hlsObject) {
let gumlet = window.gumlet.insights(gumletConfig);
gumlet.registerHLSJSPlayer(hlsObject);
}
return (
<div className="App">
<ReactHlsPlayer
src="https://video.gumlet.io/5f462c1561cf8a766464ffc4/635789f017629894d4d125a4/main.m3u8"
autoPlay={false}
controls={true}
width="100%"
height="auto"
playerRef={playerRef}
getHLSRef={(hlsJSObject) => {_attachHLSObjectToGumletSDK(hlsJSObject);}}
/>
</div>
);
}
export default App;
Done!
Once you integrate with these steps, you should start seeing data on your customised dashboard.
Working code for the above mentioned steps can be found in this repository.
How to?
Add custom data
You can send first party user data to our dashboard via the SDK. While building the configuration to initialise the SDK object you can pass these parameters.
const gumletConfig = {
property_id : 'PROPERTY_ID_GOES_HERE', // required: please replace with correct property id.
userId : '123',
userName : 'Océane Bourgeois',
userEMail : '[email protected]',
userPhone : '(840)-295-4133',
userProfileImage : 'https://assets.gumlet.io/assets/gumlet-logo-white-font.png?w=240&format=auto',
userAddressLine1 : '8774, Rue de la Mairie',
userAddressLine2 : '',
userCity : 'Reims',
userState : 'Landes',
userCountry : 'France',
userZipcode : '83894',
customContentType : 'episode',
customVideoDurationMillis : 2600000, // 43 minutes 20 seconds
customEncodingVariant : 'test1',
customVideoLanguage : 'English',
customVideoId : 'HIMYMSeason1Episode1',
customVideoSeries : 'HIMYMSeason1',
customVideoProducer : 'Ece Tekelioglu',
customVideoTitle : 'Pilot',
customVideoVariantName : '',
customVideoVariant : '',
customPlayerIntegrationVersion : 'v1.1',
customPlayerName : 'Trailer',
customPageType : 'Homepage',
customData1 : '',
customData2 : '',
customData3 : '',
customData4 : '',
customData5 : '',
customData6 : '',
customData7 : '',
customData8 : '',
customData9 : '',
customData10 : ''
};
Change the essential user details being sent to the Gumlet Dashboard.
If the user decides to login after the Gumlet SDK was attached to the player then you can use the following function to update the data being sent to the Gumlet backend.
Use the updateCustomUserData() function available in the SDK.
gumlet.updateCustomUserData({
userId : '123',
userName : 'Christelle Robert',
userEMail : '[email protected]',
});
Change the video title that is being played in the player.
If your app supports multiple videos in the same player after it is initialised then you need to tell our SDK to track the new video details after the player finishes playing a video and is about to start the new video.
Use the updateCustomVideoData() function available in the SDK
gumlet.updateCustomVideoData({
customVideoTitle : 'Episode2'
})
API Documentation
insights(config)
The Initialise method takes in a config JSON and returns a Gumlet Insights object which is then attached with a player. Only the property id to which data is to be sent is a mandatory parameter, but there is an option to pass custom data as well, the whole list of parameters is available here
gumlet = window.gumlet.insights(gumletConfig);
registerHLSJSPlayer(playerObject)
The registerHLSJSPlayer method takes in a hls.js player object as an argument. After the SDK has been installed and initialised on the page it needs a player object to listen events from. The register event accepts player object and attaches the Gumlet Insight object with the player.
If there are multiple players on a page please initialise the same number of Gumlet SDK objects and pass the different player objects to it.
Gumlet insights SDK won't start sending data to the dashboard unless the player is registered with it.
gumlet.registerHLSJSPlayer(HLS_PLAYER_OBJECT);
updateCustomUserData(data)
Gumlet Insights SDK allows you to pass user data which is stored in the projects main database to allow analysis at user level complete list of user parameters is available here
There is an option to update this data via a function call while the SDK is already initialised with some user data.
gumlet.updateCustomUserData({
userId : '123',
userName : 'Christelle Robert',
userEMail : '[email protected]',
userPhone : '(078)-380-95-96',
userProfileImage : 'https://assets.gumlet.io/assets/gumlet-logo-white-font.png?w=240&format=auto',
userAddressLine1 : '8774, Rue de la Mairie',
userAddressLine2 : '',
userCity : 'Reims',
userState : 'Landes',
userCountry : 'France',
userZipcode : '83894',
});
updateCustomVideoData(data)
Gumlet Insights SDK allows you to pass custom data related to a video to easily identify and drill down metrics for a particular video on the dashboard. A complete list of parameters is available here
gumlet.updateCustomVideoData({
customContentType : 'episode',
customVideoDurationMillis : 2405000, // 40 minutes 5 seconds
customEncodingVariant : 'test1',
customVideoLanguage : 'English',
customVideoId : 'HIMYMSeason1Episode2',
customVideoSeries : 'HIMYMSeason1',
customVideoProducer : 'Ece Tekelioglu',
customVideoTitle : 'Episode2',
customVideoVariantName : '',
customVideoVariant : '',
})
updateCustomData(data)
Each SDK allows ten additional data points which can be used to a particular use case for an application. The values in these parameters can be anything which needs to be tracked. Each parameter is optional ad accepts alphanumeric values. The whole lit of parameters is available here
gumlet.updateCustomData({
customData1 : '',
customData2 : '',
customData3 : '',
customData4 : '',
customData5 : '',
customData6 : '',
customData7 : '',
customData8 : '',
customData9 : '',
customData10 : ''
});