/analytics-react-native

The hassle-free way to integrate analytics into any React Native application. https://segment.com/libraries/node

Primary LanguageJavaScriptMIT LicenseMIT

Build Status Code Climate codecov.io

dependencies

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.

Installation

npm install analytics-react-native

Usage

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'
  }
});

Configuration

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

Documentation is available at https://segment.com/libraries/node.