> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gameball.co/llms.txt
> Use this file to discover all available pages before exploring further.

# How Do I Initialize the Customer Profile in the React Native SDK (v4)?

> Register customers and show the Gameball profile widget

# Initialize Customer (Register/Identify)

Register or update a customer whenever they log in or register in your app.

🔒

**Secure API Access:** To benefit from v4.1 secure API endpoints, pass the `sessionToken` parameter when calling methods (required in upcoming SDK v4). This enables automatic routing to v4.1 secure endpoints. [Learn more about v4.1 →](https://docs.gameball.co/api-reference/introduction-v4.1.md)

```typescript theme={null}
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, 'customer-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** `PushProvider`

Push notification provider: `PushProvider.firebase` or `PushProvider.huawei`. 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. Required in upcoming SDK v4.

> [!NOTE]
>
> 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

**CustomerAttributes Fields**

**displayName** `string`

Customer's display name.

**firstName** `string`

Customer's first name.

**lastName** `string`

Customer's last name.

**email** `string`

Customer's email address.

**mobile** `string`

Customer's mobile number.

**gender** `string`

Gender: 'M' or 'F'.

**dateOfBirth** `string`

Date of birth in `YYYY-MM-DD` format.

**joinDate** `string`

Join date in `YYYY-MM-DD` format.

**preferredLanguage** `string`

Preferred language code.

**customAttributes** `Record\<string, string\>`

Custom key-value pairs for additional customer data.

**additionalAttributes** `Record\<string, string\>`

Additional key-value pairs for metadata.

> [!WARNING]
>
> **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

* [Track Customer Events](https://docs.gameball.co/installation-guides/v4/react-native/track-events.md)
* [Show Profile Widget](https://docs.gameball.co/installation-guides/v4/react-native/show-profile.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.