Initialize Customer (Register/Identify)
Register or update a customer whenever they log in or register in your app.
import { GameballApp , InitializeCustomerRequest , CustomerAttributes } from 'gameball-react-native' ;
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: {
loyaltyTier: 'gold' ,
city: 'New York' ,
},
additionalAttributes: {
segment: 'premium' ,
},
};
const request : InitializeCustomerRequest = {
customerId: 'customer-123' ,
email: 'john@example.com' ,
mobile: '+1234567890' ,
customerAttributes: attributes ,
referralCode: 'REF123' , // Optional
isGuest: false , // Optional
};
// 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.
Display the Gameball customer profile widget:
import { GameballApp , ShowProfileRequest } from 'gameball-react-native' ;
const profileRequest : ShowProfileRequest = {
customerId: 'customer-123' ,
showCloseButton: true , // Optional
openDetail: 'rewards' , // Optional
hideNavigation: false , // Optional
closeButtonColor: '#FF6B6B' , // Optional
};
// Using async/await
try {
await GameballApp . getInstance (). showProfile ( profileRequest );
} catch ( error ) {
console . error ( 'Error showing profile:' , error );
}
// Using callbacks
GameballApp . getInstance (). showProfile ( profileRequest , {
onSuccess : () => console . log ( 'Profile shown' ),
onError : ( error ) => console . error ( 'Error:' , error . message )
});
The customer’s unique identifier.
Show close button in widget.
Widget section to open: ‘profile’, ‘achievements’, ‘rewards’.
Close button color in hex format (e.g., ‘#FF0000’).
Custom widget URL prefix.
Validation Rules
ShowProfileRequest requires:
customerId cannot be empty or whitespace
Call initializeCustomer when the user logs in or registers to ensure their profile is up-to-date before showing the widget.
Next Steps