> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gameball.co/llms.txt
> Use this file to discover all available pages before exploring further.

# How Do I Track Customer Events with the React Native SDK (v4)?

> Send events to power actions, campaigns and rewards

# Track Customer Events

Send events to Gameball when users perform important actions within your app.

🔒

**Secure API Access:** To benefit from v4.1 secure API endpoints, pass the `sessionToken` parameter when sending events (required in upcoming SDK v4). This enables automatic routing to v4.1 secure endpoints. [Learn more about v4.1 →](https://docs.gameball.co/api-reference/introduction-v4.1.md)

```typescript theme={null}
import { GameballApp, Event } from 'react-native-gameball';

const event: Event = {
  customerId: 'customer-123',
  email: 'john@example.com',
  mobile: '+1234567890',
  events: {
    purchase: {
      order_id: 'ORD-12345',
      amount: 149.99,
      currency: 'USD',
      category: 'electronics',
      channel: 'mobile_app',
    },
  },
};

// Using async/await
try {
  const success = await GameballApp.getInstance().sendEvent(event);
  console.log('Event sent successfully:', success);
} catch (error) {
  console.error('Error sending event:', error);
}

// With session token override
try {
  const success = await GameballApp.getInstance().sendEvent(event, undefined, 'customer-token');
  console.log('Event sent with custom token');
} catch (error) {
  console.error('Error:', error);
}

// Using callbacks
GameballApp.getInstance().sendEvent(event, {
  onSuccess: (success) => console.log('Event sent:', success),
  onError: (error) => console.error('Error:', error.message)
});
```

## Event Structure

**customerId** `string` *required*

The unique identifier of the customer performing the event.

**events** `Record\<string, Record\<string, any\>\>` *required*

Event data where keys are event names and values are nested properties/metadata.

**email** `string`

Customer's email address.

**mobile** `string`

Customer's mobile number.

**sessionToken** `string`

Optional session token to override the global token for this specific request. Required in upcoming SDK v4.

> [!NOTE]
>
> In React Native SDK, passing a sessionToken parameter updates the global session token. Pass `undefined` to clear the global token, or omit it to use the current global token.

### Validation Rules

**Event requires:**

* `customerId` cannot be empty or whitespace
* `events` object must contain at least one event
* Event names should be meaningful and descriptive
* Event metadata values can be string, number, boolean, or nested objects

## Best Practices

**1. Use Clear Event Names**

Make event names human-readable and consistent (e.g., `purchase_completed`, `review_submitted`).

**2. Send After Action Completion**

Send events when an action is fully completed (e.g., after payment confirmation).

**3. Include Relevant Metadata**

Add metadata that will be useful for segmentation and campaign targeting.

**4. Keep Keys Consistent**

Use consistent metadata keys across similar events.

## Common Event Examples

### Purchase Event

```typescript theme={null}
const purchaseEvent: Event = {
  customerId: 'customer-123',
  events: {
    purchase_completed: {
      order_id: 'ORD-12345',
      amount: 149.99,
      currency: 'USD',
      category: 'electronics'
    }
  },
};

await GameballApp.getInstance().sendEvent(purchaseEvent);
```

### Review Event

```typescript theme={null}
const reviewEvent: Event = {
  customerId: 'customer-123',
  events: {
    review_submitted: {
      product_id: 'PROD-789',
      rating: 5
    }
  },
};
```

> [!NOTE]
>
> Events are the foundation of Gameball's reward and engagement system. Configure how events trigger rewards and actions in your Gameball dashboard.

## Error Handling

```typescript theme={null}
try {
  await GameballApp.getInstance().sendEvent(event);
} catch (error) {
  if (error.message.includes('HTTP 401')) {
    // Handle authentication error
  } else if (error.message.includes('HTTP 500')) {
    // Handle server error
  } else {
    // Handle general error
  }
}
```

## Next Steps

* [Show Profile Widget](https://docs.gameball.co/installation-guides/v4/react-native/show-profile.md)
* [Go-Live Checklist](https://docs.gameball.co/installation-guides/v4/react-native/go-live-checklist.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.