0.0.4 • Published 9 months ago

@circuit-ai/react-native-sdk v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Circuit React Native SDK

A React Native SDK for Circuit - User session and interaction tracking.

Installation

npm install @circuit-ai/react-native-sdk
# or
yarn add @circuit-ai/react-native-sdk

Usage

  1. Wrap your app with the CircuitProvider:
import { CircuitProvider } from "@circuit-ai/react-native-sdk";

const App = () => {
  return (
    <CircuitProvider config={{ apiKey: "your-api-key" }}>
      {/* Your app components */}
    </CircuitProvider>
  );
};
  1. Use the Circuit hook in your components:
import { useCircuit } from '@circuit-ai/react-native-sdk';

const MyComponent = () => {
  const circuit = useCircuit();

  useEffect(() => {
    // Start a new session
    circuit.startSession();

    // Track events
    circuit.trackEvent('page_view', { page: 'home' });

    return () => {
      // End the session when component unmounts
      circuit.endSession();
    };
  }, []);

  return (
    // Your component JSX
  );
};

Configuration

The CircuitProvider accepts a configuration object with the following options:

interface CircuitConfig {
  apiKey: string; // Your Circuit API key (required)
  apiUrl?: string; // Custom API URL (optional)
  debug?: boolean; // Enable debug logging (optional)
}

API Reference

useCircuit Hook

The useCircuit hook provides access to the following methods:

  • initialize(config: CircuitConfig): Initialize the Circuit SDK
  • startSession(): Start a new tracking session
  • endSession(): End the current tracking session
  • trackEvent(eventType: string, eventData?: any): Track a custom event
  • isInitialized: Boolean indicating if the SDK is initialized

Development

  1. Install dependencies:
npm install
  1. Build the package:
npm run build

License

MIT