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
1npx @react-native-community/cli@latest init your-project-nameyour-project-name with your desired project name.1cd your-project-nameStep 2: Install the Required Packages
1npm install --save react-native-video1# Without MediaTailor SDK2npm install --save @datazoom/collector_react_native_video34# With MediaTailor SDK5npm install --save @datazoom/collector_react_native_video_mt_om1npm install --save react-native-url-polyfill2npm install --save @xmldom/xmldomStep 3: Add the Player
Video component from react-native-video.Video component, providing necessary props such as source, ref, etc.1import React, { useEffect, useState, useRef } from 'react';2import { SafeAreaView, View, StyleSheet } from 'react-native';3import Video from 'react-native-video';45export default function App() {6 const [currentVideoUrl, setCurrentVideoUrl] = useState<string>(null);7 const videoRef = useRef(null);89 useEffect(() => {10 setCurrentVideoUrl('your_video_stream_url');11 }, []);1213 // The 'videoRef.current' methods can be used to interact with the player programmatically1415 return (16 <SafeAreaView style={styles.container}>17 <View style={[ styles.videoContainer ]}>18 <Video19 ref={videoRef}20 source={{ uri: currentVideoUrl }}21 style={StyleSheet.absoluteFill}22 controls23 resizeMode="contain"24 />25 </View>26 </SafeAreaView>27 );28}2930const styles = StyleSheet.create({31 container: {32 flex: 1,33 backgroundColor: '#111',34 },35 videoContainer: {36 width: '100%',37 height: 220,38 backgroundColor: '#000',39 }40});Step 4: Add Datazoom SDK integration
polyfill.js with the following content (to be imported in the next step):1import 'react-native-url-polyfill/auto';2import { DOMParser } from '@xmldom/xmldom';34globalThis.DOMParser = DOMParser;@datazoom/collector_react_native_video:1// Add polyfills required by the Datazoom/MediaTailor SDK2import './polyfill.js';34// Add Datazoom SDK5import datazoom from '@datazoom/collector_react_native_video'6// or from '@datazoom/collector_react_native_video_mt_om' for MediaTailor use cases.78datazoom.init({9 configuration_id: dzConfigId,10 log: "debug"11});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:1// Get the 'mediatailor' root object from Datazoom SDK2const mediatailor = datazoom.mediatailor;34// Enable MediaTailor debug logs5mediatailor.setLogLevel(mediatailor.LogLevel.DEBUG);1export default function App() {2 ...3 const dzContextRef = useRef(null);4 ...5 if (dzContextRef.current == null) {6 // Create a Datazoom context object7 dzContextRef.current = datazoom.createContext();8 }9 ...10 return (11 <SafeAreaView style={styles.container}>12 <View style={[ styles.videoContainer ]}>13 <Video14 ref={videoRef}15 source={{ uri: currentVideoUrl }}16 style={StyleSheet.absoluteFill}17 controls18 resizeMode="contain"19 {...dzContextRef.current.eventListeners()}20 />21 </View>22 </SafeAreaView>23 );24}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:1export default function App() {2 ...3 const mtSessionRef = useRef(null);4 const mtSessionRequestedRef = useRef(false);5 ...6 useEffect(() => {7 if (mtSessionRequestedRef.current === false) {8 // Initialize a MT session9 const sessionConfig = {10 sessionInitUrl: 'your_mediatailor_session_init_url'11 };12 mediatailor.createSession(sessionConfig).then(13 session => {14 // Update the playback URL of the video player element15 setCurrentVideoUrl(session.getPlaybackUrl());16 // Attach the MediaTailor session to the Datazoon context object17 dzContextRef.current.attachMediaTailorSession(session);18 // Keep track of the MediaTailor session object for its other uses19 mtSessionRef.current = session;20 },21 error => {22 console.warn("MT session initialization failed", error);23 }24 );25 mtSessionRequestedRef.current = true;26 }27 }, []);28}1import React, { useEffect, useState, useRef } from 'react';2import { SafeAreaView, View, StyleSheet } from 'react-native';3import Video from 'react-native-video';45// Add polyfills required by the Datazoom/MediaTailor SDK6import './polyfill.js';78// Add Datazoom SDK9import datazoom from '@datazoom/collector_react_native_video_mt_om'1011datazoom.init({12 configuration_id: dzConfigId,13 log: "debug"14});1516// Get the 'mediatailor' root object from Datazoom SDK17const mediatailor = datazoom.mediatailor;1819// Enable MediaTailor debug logs20mediatailor.setLogLevel(mediatailor.LogLevel.DEBUG);2122export default function App() {23 const [currentVideoUrl, setCurrentVideoUrl] = useState<string>(null);24 const videoRef = useRef(null);25 const dzContextRef = useRef(null);26 const mtSessionRef = useRef(null);27 const mtSessionRequestedRef = useRef(false);2829 if (dzContextRef.current == null) {30 // Create a Datazoom context object31 dzContextRef.current = datazoom.createContext();32 }3334 useEffect(() => {35 if (mtSessionRequestedRef.current === false) {36 // Initialize a MT session37 const sessionConfig = {38 sessionInitUrl: 'your_mediatailor_session_init_url'39 };40 mediatailor.createSession(sessionConfig).then(41 session => {42 // Update the playback URL of the video player element43 setCurrentVideoUrl(session.getPlaybackUrl());44 // Attach the MediaTailor session to the Datazoon context object45 dzContextRef.current.attachMediaTailorSession(session);46 // Keep track of the MediaTailor session object for its other uses47 mtSessionRef.current = session;48 },49 error => {50 console.warn("MT session initialization failed", error);51 }52 );53 mtSessionRequestedRef.current = true;54 }55 }, []);5657 // The 'videoRef.current' methods can be used to interact with the player programmatically5859 return (60 <SafeAreaView style={styles.container}>61 <View style={[ styles.videoContainer ]}>62 <Video63 ref={videoRef}64 source={{ uri: currentVideoUrl }}65 style={StyleSheet.absoluteFill}66 controls67 resizeMode="contain"68 {...dzContextRef.current.eventListeners()}69 />70 </View>71 </SafeAreaView>72 );73}7475const styles = StyleSheet.create({76 container: {77 flex: 1,78 backgroundColor: '#111',79 },80 videoContainer: {81 width: '100%',82 height: 220,83 backgroundColor: '#000',84 }85});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
Player
Attributes
Video
User
Fluxdata
Metrics measuring changing parameters over time
-
Content Error Count (App Session)
-
Content Media Request Count (App Session)
-
Content Media Request Recency (Content Session)
-
Content Pause Duration (Content Session)
-
Content Playback Duration (Content Session)
-
Content Playback Start Count (App Session)
-
Content Playback Start Recency (Content Session)
-
Content Session Start Timestamp
-
Content Stall Count (Content Session)
-
Content Stall Duration (Content Session)
-
Content Stall Start Recency (Content Session)
-
Error Count (App Session)
-
Heartbeat Recency (Content Session)
-
Pause Duration (Content Session)
-
Pause Recency (Content Session)
-
Playback Duration (Content Session)
-
Playback Rate
-
Player State
-
Playhead Position
-
Playhead Position - Program Date Time
-
Stall Count (Content Session)
-
Stall Duration (Content Session)
-
Stall Start Recency (Content Session)
- Volume