# Getting Started

The Referd Android and iOS package, enables you to use the show Referd user profile in your app, track app user events, integrate referrals and display Referd's in-app push notifications.

## Installation <a href="#installation" id="installation"></a>

Follow the below steps to start installing react native SDK package to your app

* Install package using npm

```typescript
npm install --save react-native-gameball
```

* Install prerequisite packages using npm

```bash
npm install react-native-modal react-native-push-notification-popup
```

{% hint style="info" %}
react-native-modal and react-native-push-notification-popup packages are required to use gameball package.
{% endhint %}

{% hint style="info" %}
Fetch API is used for network communications, conversion of response to json is needed in order to read the response\
res => res.json()
{% endhint %}

## Initialization

In order to use Referd SDK, apply the below step to the **main JS file (index or app)**.

**Import Referd Widget**

```typescript
import {GameballWidget} from ‘react-native-gameball’;
```

**Initialize Referd Widget**

```typescript
GameballWidget.init(gameball_apiKey, lang, shop, platform, deepLinks )
```

| Parameter         | Type       | Required | Description                                                                                                                                                                                                                                                                                                                                                      |
| ----------------- | ---------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gameball_apiKey` | string     | Required | Client API key                                                                                                                                                                                                                                                                                                                                                   |
| `lang`            | **string** | Optional | <p>Your platform language preference to view <strong>Referd</strong> Widget with.</p><p><strong>Note:</strong> The language provided should be as per configured languages in your account. If not provided the Referd profile widget will be shown with your account default language</p><p><strong>Example:</strong> <code>"en"</code>, <code>"fr"</code>.</p> |

## Register User

Register user method is used to create or update users at Referd. It is called when your login network call is successful.

First, import Referd SDK as follows:

```typescript
import {GameballSDK} from 'react-native-gameball';
```

then

```typescript
GameballSDK.registerPlayer({
      "playerUniqueId": playerId,
      "playerTypeId": playerTypeId,
      "deviceToken": playerDeviceToken,
      "playerAttributes": {
        "displayName": "Alex",
        "email": "example@example.com",
        "gender": "m",
        "mobileNumber": "01099999999",
        "dateOfBirth": "2019-08-18T10:11:34.478Z",
        "joinDate": "2019-08-18T10:11:34.478Z" 
       }
}).then(res => res.json()).then(jsonResponse => {...}) // on success
```

Once the **APIKey** and **playerUniqueId** have been registered, Referd views can be made visible to the user.

<table data-header-hidden><thead><tr><th width="225">Param</th><th width="127">Required</th><th>Description</th><th>Type</th></tr></thead><tbody><tr><td>Param</td><td>Required</td><td>Description</td><td>Type</td></tr><tr><td><code>playerUniqueId</code></td><td>Required</td><td>PlayerUniqueId is a unique ID for you user, for example UUID or username. The PlayerUniqueId is to be provided by the client and must be unique for each user.</td><td>String</td></tr><tr><td><code>playerTypeId</code></td><td>Optional</td><td>Each User type has an ID</td><td>Integer</td></tr><tr><td><code>playerAttributes</code></td><td>Optional</td><td>PlayerAttributes is a builder class which you will use to add or update your player info to Referd. </td><td>Object</td></tr><tr><td><code>deviceToken</code></td><td>Optional</td><td>Mobile device token used for push notifications<br><strong>Note:</strong> Should be sent along with <code>osType</code></td><td>String</td></tr></tbody></table>

{% hint style="warning" %}
**Choose an Unchangeable Player Unique ID**

Referd user profile gets created using the **`playerUniqueId`**. It is highly recommended to have the unique ID as an identifier that would NEVER be changed. If this unique ID changes for a given user, you risk losing all original data for that user on Referd. Accordingly, it is NOT recommended to use email address or mobile number as the unique ID as both can be changed by the user at anytime.
{% endhint %}
