React Native SDK
The Datafly Signal React Native SDK wraps the native iOS and Android SDKs via native modules, giving you full native performance with a familiar JavaScript/TypeScript API.
Requirements
- React Native 0.71+
- iOS 15+ / Android API 21+
Installation
npm install @datafly/react-nativeiOS
cd ios && pod installAndroid
No additional setup required — the native module auto-links.
Initialisation
Initialise the SDK in your app entry point:
import { DataflySignal } from '@datafly/react-native';
DataflySignal.initialize({
pipelineKey: 'dk_live_abc123',
endpoint: 'https://data.example.com',
});Usage
import { DataflySignal } from '@datafly/react-native';
// Track a screen view
DataflySignal.screen('Home');
// Track a custom event
DataflySignal.track('add_to_cart', {
item_id: 'SKU-001',
item_name: 'Running Shoes',
price: 79.99,
currency: 'GBP',
});
// Identify a user
DataflySignal.identify('user-123', {
email: '[email protected]',
name: 'Jane Doe',
});
// Associate with a company
DataflySignal.group('company-456', { name: 'Acme Corp' });
// Handle deep link
DataflySignal.handleDeepLink('https://example.com?utm_source=google&gclid=abc123');
// Set consent
DataflySignal.setConsent({ analytics: true, marketing: false });
// Force flush
DataflySignal.flush();
// Logout
DataflySignal.reset();
// Get anonymous ID
const anonId = await DataflySignal.getAnonymousId();React Navigation integration
Track screen views automatically with React Navigation:
import { NavigationContainer } from '@react-navigation/native';
import { DataflySignal } from '@datafly/react-native';
function App() {
const routeNameRef = useRef<string>();
return (
<NavigationContainer
onStateChange={() => {
const currentRoute = navigationRef.getCurrentRoute();
if (currentRoute && currentRoute.name !== routeNameRef.current) {
DataflySignal.screen(currentRoute.name);
routeNameRef.current = currentRoute.name;
}
}}
>
{/* screens */}
</NavigationContainer>
);
}Deep link handling
import { Linking } from 'react-native';
Linking.addEventListener('url', ({ url }) => {
DataflySignal.handleDeepLink(url);
});
// Check for initial URL on app launch
const initialUrl = await Linking.getInitialURL();
if (initialUrl) {
DataflySignal.handleDeepLink(initialUrl);
}TypeScript
The package ships with full TypeScript declarations:
import type { DataflyConfig } from '@datafly/react-native';
const config: DataflyConfig = {
pipelineKey: 'dk_live_abc123',
endpoint: 'https://data.example.com',
debug: true,
};The React Native SDK is a thin bridge over the native iOS and Android SDKs. All event processing, offline queuing, batching, and retry logic runs natively — no JavaScript bridge overhead for the critical data path.
Configuration
See Configuration for all available options. The React Native SDK supports the same configuration as the native SDKs.