Track Customer Events
Send events to Gameball when users perform important actions within your app.
import { GameballApp, Event } from 'gameball-react-native';
const event: Event = {
customerId: 'customer-123',
email: 'john@example.com',
mobile: '+1234567890',
events: {
purchase: {
product_id: '12345',
amount: 99.99,
currency: 'USD',
category: 'electronics'
},
page_view: {
page: 'product_detail',
product_id: '12345'
}
},
};
// 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, 'custom-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
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.
Customer’s email address.
Customer’s mobile number.
Optional session token to override the global token for this specific request.
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
Use Clear Event Names
Make event names human-readable and consistent (e.g., purchase_completed, review_submitted).
Send After Action Completion
Send events when an action is fully completed (e.g., after payment confirmation).
Include Relevant Metadata
Add metadata that will be useful for segmentation and campaign targeting.
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
}
},
};
Multiple Events
You can send multiple events in a single call:
const multipleEvents: Event = {
customerId: 'customer-123',
events: {
add_to_cart: {
product_id: 'PROD-456',
quantity: 2
},
wishlist_add: {
product_id: 'PROD-789'
}
},
};
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