Skip to main content

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

customerId
string
required
Unique identifier for the customer. This should never change for a given customer.
email
string
Customer’s email address.
mobile
string
Customer’s mobile number with country code.
deviceToken
string
Push notification token (required if pushProvider is set).
pushProvider
'Firebase' | 'Huawei'
Push notification provider (required if deviceToken is set).
customerAttributes
CustomerAttributes
Additional customer attributes.
referralCode
string
Referral code if customer was referred by another customer.
isGuest
boolean
Guest user flag (defaults to false).
sessionToken
string
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

Choose an Unchangeable Customer IDThe 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.

Show Customer Profile Widget

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)
});
customerId
string
required
The customer’s unique identifier.
showCloseButton
boolean
Show close button in widget.
openDetail
string
Widget section to open: ‘profile’, ‘achievements’, ‘rewards’.
hideNavigation
boolean
Hide widget navigation.
closeButtonColor
string
Close button color in hex format (e.g., ‘#FF0000’).
widgetUrlPrefix
string
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