Skip to main content

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 →
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.
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

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

const reviewEvent: Event = {
  customerId: 'customer-123',
  events: {
    review_submitted: {
      product_id: 'PROD-789',
      rating: 5
    }
  },
};
Events are the foundation of Gameball’s reward and engagement system. Configure how events trigger rewards and actions in your Gameball dashboard.

Error Handling

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