Skip to main content

React Native SDK (Coming Soon)

The official UserBoost React Native SDK is currently under development and will be available soon.

Use REST API in the Meantime

While we work on the React Native SDK, you can integrate UserBoost using direct HTTP API calls:

Installation

npm install axios
# or
npm install fetch

Basic Setup

// userboost.js
const USERBOOST_API_KEY = "ub_live_your_api_key_here";
const USERBOOST_ENDPOINT = "https://api.userboo.st";

export const trackEvent = async (eventName, userData, properties = {}) => {
  const payload = {
    sent_at: new Date().toISOString(),
    events: [
      {
        type: "event",
        name: eventName,
        user: userData,
        timestamp: new Date().toISOString(),
        properties,
      },
    ],
  };

  try {
    const response = await fetch(`${USERBOOST_ENDPOINT}/v1/events`, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${USERBOOST_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(payload),
    });

    return await response.json();
  } catch (error) {
    console.error("UserBoost tracking error:", error);
  }
};

export const identifyUser = async (userData) => {
  const payload = {
    type: "identify",
    user: userData,
    timestamp: new Date().toISOString(),
  };

  try {
    const response = await fetch(`${USERBOOST_ENDPOINT}/v1/event`, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${USERBOOST_API_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify(payload),
    });

    return await response.json();
  } catch (error) {
    console.error("UserBoost identify error:", error);
  }
};

Usage in Components

// App.js or your component
import React, { useEffect } from "react";
import { View, Button } from "react-native";
import { trackEvent, identifyUser } from "./userboost";

export default function App() {
  const userId = "user_123";

  useEffect(() => {
    // Identify user when app loads
    identifyUser({
      id: userId,
      email: "john@example.com",
      traits: {
        name: "John Doe",
        plan: "free",
      },
    });
  }, []);

  const handleSignUp = () => {
    // Track registration event
    trackEvent(
      "user_registered",
      {
        id: userId,
        email: "john@example.com",
      },
      {
        registration_source: "mobile",
      }
    );
  };

  const handleFeatureUse = () => {
    // Track feature usage
    trackEvent(
      "feature_used",
      {
        id: userId,
      },
      {
        feature: "camera",
        screen: "home",
      }
    );
  };

  return (
    <View style={{ flex: 1, justifyContent: "center" }}>
      <Button title="Sign Up" onPress={handleSignUp} />
      <Button title="Use Feature" onPress={handleFeatureUse} />
    </View>
  );
}

TypeScript Support

// types.ts
interface EventProperties {
  [key: string]: string | number | boolean;
}

interface UserData {
  id: string;
  email?: string;
  traits?: {
    name?: string;
    plan?: string;
    created_at?: string;
    [key: string]: any;
  };
}

// userboost.ts
export const trackEvent = async (
  eventName: string,
  userData: UserData,
  properties: EventProperties = {}
): Promise<any> => {
  // Implementation same as above
};

export const identifyUser = async (userData: UserData): Promise<any> => {
  // Implementation same as above
};

Environment Configuration

// config.js
const CONFIG = {
  development: {
    apiKey: "ub_live_your_dev_key_here",
    endpoint: "https://api-test.userboo.st",
    debug: true,
  },
  production: {
    apiKey: "ub_live_your_prod_key_here",
    endpoint: "https://api.userboo.st",
    debug: false,
  },
};

export default CONFIG[__DEV__ ? "development" : "production"];

Best Practices

  1. Handle network errors gracefully - mobile connections can be unreliable
  2. Batch events when possible to save battery and data
  3. Use background tasks for non-critical tracking
  4. Respect user privacy - only track necessary events
  5. Test thoroughly on both iOS and Android

SDK Development Updates

We’re actively working on the React Native SDK with the following planned features:
  • Native iOS and Android modules for better performance
  • Automatic session tracking and app state management
  • Offline event queuing and retry logic
  • TypeScript definitions included
  • React hooks for easy integration

Stay Updated

Need Help?

For React Native integration questions, contact support@userboo.st