Application collectors
React Native Video Media Player
For the React Native Collector
The React Native Video Media Player Extension is a configuration option for the React Native Collector by Datazoom that makes the following additional data points automatically collectable in real time.
Integration Instructions
Node.js and npm / yarn installed. React Native Project Packages needed (example) Datazoom Collector: https://www.npmjs.com/package/@datazoom/collector_react_native_video, or https://www.npmjs.com/package/@datazoom/collector_react_native_video_mt_om (to integrate with MediaTailor) React Native Video Player: https://www.npmjs.com/package/react-native-video This project is structured and configured to work with NPM (Node Package Manager), and it is mandatory to use NPM for installing the Datazoom Collector SDK and other dependencies. Direct inclusion of the Collector SDK or other dependencies is not supported and may lead to compatibility issues or unexpected behavior. Run the command to create a new React Native project: Replace Navigate to your project directory: Inside your project directory, run the following commands to install the required packages. React Native Video player: Datazoom collector SDK: Poly-fills required for Datazoom/MediaTailor SDKs After installing the packages, you need to integrate the Player into your React Native application by: Import Use the Example: App.tsx First add the poly-fills required for Datazoom/MediaTailor SDKs by creating a new file Import and configure the Datazoom Collector for React Native Video Player per the documentation of Replace The Optionally (for MediaTailor use cases), set up the When a React Native Video element is rendered, create a Datazoom context object to observe the playback activities and manage the gathered information: The pre-existence of As shown in the line Optionally (to start a MediaTailor streaming session), add a Example: App.tsx React Native Video Player NPM: https://www.npmjs.com/package/react-native-video React Native Video Player Doc: https://docs.thewidlarzgroup.com/react-native-video/docs/v6/intro Datazoom Collector: https://www.npmjs.com/package/@datazoom/collector_react_native_video and https://www.npmjs.com/package/@datazoom/collector_react_native_video_mt_omPrerequisites
Important Notice: Datazoom NPM Collector SDK Required
Implementation
Step 1: Setup React Native Project
npx @react-native-community/cli@latest init your-project-name
your-project-name with your desired project name.cd your-project-name
Step 2: Install the Required Packages
npm install --save react-native-video
# Without MediaTailor SDK
npm install --save @datazoom/collector_react_native_video
# With MediaTailor SDK
npm install --save @datazoom/collector_react_native_video_mt_om
npm install --save react-native-url-polyfill
npm install --save @xmldom/xmldom
Step 3: Add the Player
Video component from react-native-video.Video component, providing necessary props such as source, ref, etc.import React, { useEffect, useState, useRef } from 'react';
import { SafeAreaView, View, StyleSheet } from 'react-native';
import Video from 'react-native-video';
export default function App() {
const [currentVideoUrl, setCurrentVideoUrl] = useState<string>(null);
const videoRef = useRef(null);
useEffect(() => {
setCurrentVideoUrl('your_video_stream_url');
}, []);
// The 'videoRef.current' methods can be used to interact with the player programmatically
return (
<SafeAreaView style={styles.container}>
<View style={[ styles.videoContainer ]}>
<Video
ref={videoRef}
source={{ uri: currentVideoUrl }}
style={StyleSheet.absoluteFill}
controls
resizeMode="contain"
/>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#111',
},
videoContainer: {
width: '100%',
height: 220,
backgroundColor: '#000',
}
});
Step 4: Add Datazoom SDK integration
polyfill.js with the following content (to be imported in the next step):import 'react-native-url-polyfill/auto';
import { DOMParser } from '@xmldom/xmldom';
globalThis.DOMParser = DOMParser;
@datazoom/collector_react_native_video:// Add polyfills required by the Datazoom/MediaTailor SDK
import './polyfill.js';
// Add Datazoom SDK
import datazoom from '@datazoom/collector_react_native_video'
// or from '@datazoom/collector_react_native_video_mt_om' for MediaTailor use cases.
datazoom.init({
configuration_id: dzConfigId,
log: "debug"
});
dzConfigId with your configuration id.log: "debug" option can be omitted if console debug logging isn’t needed.mediatailor root object and enable MediaTailor debug logging if needed:// Get the 'mediatailor' root object from Datazoom SDK
const mediatailor = datazoom.mediatailor;
// Enable MediaTailor debug logs
mediatailor.setLogLevel(mediatailor.LogLevel.DEBUG);
export default function App() {
...
const dzContextRef = useRef(null);
...
if (dzContextRef.current == null) {
// Create a Datazoom context object
dzContextRef.current = datazoom.createContext();
}
...
return (
<SafeAreaView style={styles.container}>
<View style={[ styles.videoContainer ]}>
<Video
ref={videoRef}
source={{ uri: currentVideoUrl }}
style={StyleSheet.absoluteFill}
controls
resizeMode="contain"
{...dzContextRef.current.eventListeners()}
/>
</View>
</SafeAreaView>
);
}
dzContextRef.current is checked before creating a new context object. This is to prevent redundancies and confusions when React renders the same element twice when operating in its strict-mode during development phase.{...dzContextRef.current.eventListeners()} above, the Datazoom context object provides a list of event listeners through its eventListeners() method. These listeners should be specified as props in the declaration of the react-native-video Video element.useEffect hook with the following code to start a session right after the application root element is rendered:export default function App() {
...
const mtSessionRef = useRef(null);
const mtSessionRequestedRef = useRef(false);
...
useEffect(() => {
if (mtSessionRequestedRef.current === false) {
// Initialize a MT session
const sessionConfig = {
sessionInitUrl: 'your_mediatailor_session_init_url'
};
mediatailor.createSession(sessionConfig).then(
session => {
// Update the playback URL of the video player element
setCurrentVideoUrl(session.getPlaybackUrl());
// Attach the MediaTailor session to the Datazoon context object
dzContextRef.current.attachMediaTailorSession(session);
// Keep track of the MediaTailor session object for its other uses
mtSessionRef.current = session;
},
error => {
console.warn("MT session initialization failed", error);
}
);
mtSessionRequestedRef.current = true;
}
}, []);
}
import React, { useEffect, useState, useRef } from 'react';
import { SafeAreaView, View, StyleSheet } from 'react-native';
import Video from 'react-native-video';
// Add polyfills required by the Datazoom/MediaTailor SDK
import './polyfill.js';
// Add Datazoom SDK
import datazoom from '@datazoom/collector_react_native_video_mt_om'
datazoom.init({
configuration_id: dzConfigId,
log: "debug"
});
// Get the 'mediatailor' root object from Datazoom SDK
const mediatailor = datazoom.mediatailor;
// Enable MediaTailor debug logs
mediatailor.setLogLevel(mediatailor.LogLevel.DEBUG);
export default function App() {
const [currentVideoUrl, setCurrentVideoUrl] = useState<string>(null);
const videoRef = useRef(null);
const dzContextRef = useRef(null);
const mtSessionRef = useRef(null);
const mtSessionRequestedRef = useRef(false);
if (dzContextRef.current == null) {
// Create a Datazoom context object
dzContextRef.current = datazoom.createContext();
}
useEffect(() => {
if (mtSessionRequestedRef.current === false) {
// Initialize a MT session
const sessionConfig = {
sessionInitUrl: 'your_mediatailor_session_init_url'
};
mediatailor.createSession(sessionConfig).then(
session => {
// Update the playback URL of the video player element
setCurrentVideoUrl(session.getPlaybackUrl());
// Attach the MediaTailor session to the Datazoon context object
dzContextRef.current.attachMediaTailorSession(session);
// Keep track of the MediaTailor session object for its other uses
mtSessionRef.current = session;
},
error => {
console.warn("MT session initialization failed", error);
}
);
mtSessionRequestedRef.current = true;
}
}, []);
// The 'videoRef.current' methods can be used to interact with the player programmatically
return (
<SafeAreaView style={styles.container}>
<View style={[ styles.videoContainer ]}>
<Video
ref={videoRef}
source={{ uri: currentVideoUrl }}
style={StyleSheet.absoluteFill}
controls
resizeMode="contain"
{...dzContextRef.current.eventListeners()}
/>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#111',
},
videoContainer: {
width: '100%',
height: 220,
backgroundColor: '#000',
}
});
References:
Ad Frameworks Extensions
If your React Native application has a media player with an ad framework, Datazoom’s React Native Collector with a React Native Video Media Player can be extended with the following ad framework extensions.
Supported Data Points
Events
Discrete occurrences driven by user interactions or system actions
Metadata
Attributes
Player
Video
User
Fluxdata
Metrics measuring changing parameters over time
-
Content Session Start Timestamp
-
Number of Content Plays
-
Number of Content Requests
-
Number of Errors
-
Number of Errors - Content
-
Pause Duration
-
Pause Duration - Content
-
Playback Duration
-
Playback Duration - Content
-
Playback Rate
-
Player State
-
Playhead Position
-
Playhead Position - Program Date Time
-
Stall Count
-
Stall Count - Content
-
Stall Duration
-
Stall Duration - Content
-
Time Since Content Request
-
Time Since Content Started
-
Time Since Last Heartbeat
-
Time Since Last Pause
-
Time Since Last Stall Start
-
Time Since Last Stall Start - Content
- Volume