A React Native client for Segment. The hassle-free way to integrate analytics into any application.
This library is based on its node counterpart, analytics-node. Despite being designed to run on react-native, it will also work in browsers (via webpack or browserify) and even in nodejs. You only need to include fetch for browsers or node-fetch for nodejs or io.js.
npm install analytics-react-native
import Analytics from analytics-react-native;
const analytics = new Analytics(YOUR_WRITE_KEY);
analytics.identify({
userId: user.id,
traits: {
name: 'John',
lastname: 'Doe',
email: 'user@domain.com',
plan: 'Enterprise',
}
);
analytics.track({
userId: user.id,
event: 'Item Purchased',
properties: {
revenue: 39.95,
shippingMethod: '2-day'
}
});
The second argument to the Analytics constructor is an optional object to configure the module.
const analytics = new Analytics(YOUR_WRITE_KEY, {
host: 'http://localhost/', // Host where reports will be send. Useful for debug.
flushAt: 20, // The number of messages to enqueue before flushing.
flushAfter: 10000 // The number of milliseconds to wait before flushing the queue automatically.
});
Documentation is available at https://segment.com/libraries/node.