# Initialize Referd User Profile

Showing the Referd widget on your mobile application is slightly different than showing it on the website. You have two options; first, if you want to design your customer interface, you will use our set of REST APIs.\
\
The other option as this section elaborates, is through using our android SDK.

Using the SDK, you can open the **Referd** user profile from a button in your app, programmatically when someone does something, or from a persistent button that sits over your app’s UI.

When you trigger the **Referd** user profile, your player is presented with a home screen. This is configurable inside **Referd** to change how it looks and what’s presented.

From there, your user can check his progress across different **Referd** programs as per your configurations.

<figure><img src="https://983627972-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1bAQ4IvAKNqrQlsRN5b4%2Fuploads%2FXcTIA8yqOOlts6FbUE1R%2Fimage%20(4).png?alt=media&#x26;token=7c6e6b59-8448-440d-8256-aed4dcd40e15" alt=""><figcaption></figcaption></figure>

## Showing Referd Profile

To show the Referd player profile that contains the user details, user challenges, and the leaderboard use **showProfile()** SDK method.

<table data-header-hidden><thead><tr><th width="214">Parameter</th><th width="110">Type</th><th width="115">Required</th><th>Description</th></tr></thead><tbody><tr><td>Parameter</td><td>Type</td><td>Required</td><td>Description</td></tr><tr><td><code>Activity</code></td><td><strong>Activity</strong></td><td><strong>Yes</strong></td><td>Current activity instance holding the GameballApp which will be used in showing the User's profile.</td></tr><tr><td><code>PlayerUniqueId</code></td><td><strong>String</strong></td><td><strong>Yes</strong></td><td><p>Unique identifier for the user in your database.</p><p>Could be database ID, random string, email or anything that uniquely identifies the user.</p></td></tr><tr><td><code>openDetail</code></td><td><strong>String</strong></td><td><strong>No</strong></td><td>Specify if you want the widget to open on a specific view. Possible values are <code>details_referral</code></td></tr><tr><td><code>hideNavigation</code></td><td><strong>Boolean</strong></td><td><strong>No</strong></td><td>Set to true to stop widget navigation otherwise leave as null.</td></tr></tbody></table>

{% tabs %}
{% tab title="Java" %}

```java
gameballApp.showProfile(this, "{{playerUniqueId}}", "{{openDetail}}", "{{hideNavigation}}");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
gameballApp.showProfile(this, "{{playerUniqueId}}", "{{openDetail}}", "{{hideNavigation}}")
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Use showProfile as a parameter to collect the activity or the fragment you are going to show the profile in. Just create a button and call this method in the onClick() method of this button.
{% endhint %}

**Change Profile Widget language**

***`changeLanguage(String language)`***

Use `changeLaguage` SDK method to change the widget language.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

**Example:** `"en"`, `"fr"`.

## Register/Update User&#x20;

You should register your users with **Referd**. This can be done using **`registerPlayer`**&#x6D;ethod which can be used to create or update the player details at **Referd**. Ideally, it is called when your login or register network call is successful.

<table data-header-hidden><thead><tr><th width="220">Parameter</th><th width="110">Type</th><th width="115">Required</th><th>Description</th></tr></thead><tbody><tr><td>Parameter</td><td>Type</td><td>Required</td><td>Description</td></tr><tr><td><code>PlayerUniqueId</code></td><td><strong>string</strong></td><td><strong>Yes</strong></td><td><p>Unique identifier for the user in your database.</p><p>Could be database ID, random string, email or anything that uniquely identifies the user.</p></td></tr><tr><td><code>PlayerAttributes</code></td><td><strong>object</strong></td><td><strong>No</strong></td><td>PlayerAttributes is a builder class with set of properties that you want to set for the user.</td></tr><tr><td><code>Activity</code></td><td><strong>Activity</strong></td><td><strong>Yes</strong></td><td>Current activity instance holding the GameballApp which will be used in detecting the referal code from the dynamic link.</td></tr><tr><td><code>Intent</code></td><td><strong>Intent</strong></td><td><strong>Yes</strong></td><td>An intent instance that will be used in combination with the Activity to detect the referal code from the dynamic link.</td></tr><tr><td><code>CallBack</code></td><td><strong>function</strong></td><td><strong>No</strong></td><td>Callback is used for providing the developer with the response status and payload.</td></tr></tbody></table>

{% hint style="success" %}
Everytime the **SDK** is initialized with a new p**layerUniqueId** , the user profile is created or updated at **Referd** side. You may consider enriching your Referd's user profile with attributes that are not avialable to the UI by using server side [Create\Update User API](https://developer.tryreferd.com/api-reference/api-reference/player#post-create-player)
{% endhint %}

{% 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 player, 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 %}

**`PlayerAttributes`Object**

PlayerAttributes is a builder class that helps in creation of the PlayerAttributes with the common attributes mentioned below, all of these attributes are **optional** to use.

<table><thead><tr><th width="207">Method</th><th>Parameter Name</th><th>Type</th></tr></thead><tbody><tr><td>withDisplayName</td><td>displayName</td><td>string</td></tr><tr><td>withFirstName</td><td>firstName</td><td>string</td></tr><tr><td>withLastName</td><td>lastName</td><td>string</td></tr><tr><td>withEmail</td><td>email</td><td>string</td></tr><tr><td>withGender</td><td>gender</td><td>string</td></tr><tr><td>withMobileNumber</td><td>mobileNumber</td><td>string</td></tr><tr><td>withDateOfBirth</td><td>dateOfBirth</td><td>string</td></tr><tr><td>withJoinDate</td><td>joinDate</td><td>string</td></tr><tr><td>withCustomAttribute</td><td>(key, value)</td><td>(string, string)</td></tr></tbody></table>

#### An example to create *PlayerAttributes* object

{% tabs %}
{% tab title="Java" %}

```java
PlayerAttributes playerAttributes = new PlayerAttributes.Builder()
        .withDisplayName("John Doe")
        .withFirstName("John")
        .withLastName("Doe")
        .withMobileNumber("0123456789")
        .withCustomAttribute("{key}", "{Value}")
        .build();
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val playerAttributes = PlayerAttributes.Builder()
    .withDisplayName("John Doe")
    .withFirstName("John")
    .withLastName("Doe")
    .withMobileNumber("0123456789")
    .withCustomAttribute("{key}", "{Value}")
    .build()
```

{% endtab %}
{% endtabs %}

The previous example will return an object of PlayerAttributes with DisplayName “Jack”

### Register the User

Using the previously created GameballApp instance or by creating a new one, call the ***RegisterPlayer()*** method as shown below

{% tabs %}
{% tab title="Java" %}

```java
gameballApp.registerPlayer(
    "{{uniquePlayerId}}", 
    playerAttributes, 
    this, 
    this.getIntent(), 
    new Callback<PlayerRegisterResponse>() {
        @Override
        public void onSuccess(PlayerRegisterResponse playerRegisterResponse) {
            // TODO Handle on success result.
        }
    
        @Override
        public void onError(Throwable e) {
            // TODO Handle on failure result.
        }
});
```

{% endtab %}
{% endtabs %}
