Initialize Customer (Register/Identify)
Register or update a customer whenever they log in or register in your app.
import { GameballApp , InitializeCustomerRequest , CustomerAttributes } from 'react-native-gameball' ;
const attributes : CustomerAttributes = {
displayName: 'John Doe' ,
firstName: 'John' ,
lastName: 'Doe' ,
email: 'john@example.com' ,
mobile: '+1234567890' ,
gender: 'M' ,
dateOfBirth: '1990-01-15' ,
joinDate: '2024-01-01' ,
preferredLanguage: 'en' ,
customAttributes: {
favoriteCategory: 'electronics' ,
preferredChannel: 'email' ,
},
additionalAttributes: {
country: 'USA' ,
city: 'New York' ,
},
};
const request : InitializeCustomerRequest = {
customerId: 'customer-123' ,
email: 'john@example.com' ,
mobile: '+1234567890' ,
customerAttributes: attributes ,
referralCode: 'REF123' , // Optional
isGuest: false , // Optional (omit for guest mode)
};
// Using async/await
try {
const response = await GameballApp . getInstance (). initializeCustomer ( request );
console . log ( 'Customer initialized:' , response . gameballId );
} catch ( error ) {
console . error ( 'Error:' , error . message );
}
// With session token override
try {
const response = await GameballApp . getInstance (). initializeCustomer ( request , undefined , 'custom-token' );
console . log ( 'Customer initialized with custom token' );
} catch ( error ) {
console . error ( 'Error:' , error . message );
}
// Using callbacks (backward compatibility)
GameballApp . getInstance (). initializeCustomer ( request , {
onSuccess : ( response ) => {
console . log ( 'Success:' , response . gameballId );
},
onError : ( error ) => {
console . error ( 'Error:' , error . message );
}
});
Request Parameters
Unique identifier for the customer. This should never change for a given customer.
Customer’s email address.
Customer’s mobile number with country code.
Push notification token (required if pushProvider is set).
Push notification provider (required if deviceToken is set).
Additional customer attributes.
Referral code if customer was referred by another customer.
Guest user flag (defaults to false).
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
InitializeCustomerRequest requires:
customerId cannot be empty or whitespace
If deviceToken is provided, pushProvider must also be specified
If pushProvider is specified, deviceToken must also be provided
CustomerAttributes
Show CustomerAttributes Fields
Customer’s email address.
Customer’s mobile number.
Date of birth in YYYY-MM-DD format.
Join date in YYYY-MM-DD format.
Custom key-value pairs for additional customer data.
Additional key-value pairs for metadata.
Choose an Unchangeable Customer ID The customerId should be a permanent identifier that will NEVER change. Avoid using email or phone number as the customer ID since these can be updated by users.
Next Steps