Send Customer Events
Use events to record customer actions (purchases, visits, interactions) and trigger Gameball automations and rewards.
Basic Usage
import Gameball
do {
let event = try Event(
events: [
"purchase": [
"amount": 120.50,
"currency": "USD",
"order_id": "order-123",
"items": 3,
"channel": "ios_app"
]
],
customerId: "customer-123"
)
GameballApp.getInstance().sendEvent(event) { success, errorMessage in
if success {
print("Event sent")
} else if let errorMessage = errorMessage {
print("Gameball event error: \(errorMessage)")
}
}
} catch {
print("Validation error: \(error.localizedDescription)")
}
Event Parameters
Permanent identifier for the customer.
events
[String: [String: Any]]
required
Dictionary of event names and metadata payloads.
Customer email (optional).
Customer mobile number (optional).
Optional session token override for this request.
Best Practices
Keep names consistent
Standardize event names and keys (e.g., snake_case).
Send after init
Call sendEvent only after the SDK and customer are initialized.
Include identifiers
Add order IDs, amounts, and channels to improve targeting.
Handle errors
Surface validation and API errors for quick debugging.