# User Profile Settings

User profiles are profile information about users managed by the DFINERY server. All of this information is optional and is not stored on the terminal.

## Before you start

Before setting up a user profile, create and link user profile properties in [the DFINERY console](https://console.dfinery.ai/login). User profile properties can be created in Additional Settings / Data Linkage / Property Management / User Profile Property List.

## Note

* If an unregistered user profile or an incorrect type of user profile property is recorded, the user profile will not be set.
* `Array of String` You can create up to 10 user profile properties of a type.
* `Array of Long`, `Array of Double` you can create up to 5 types.
* There is no limit to the number of values ​​entered, but the total size cannot exceed 8KB.

## Set up

You can set up a user profile using the `DfineryProperties.setUserProfile()` methods or `DfineryProperties.setUserProfiles()`.

### User profile properties

| Constant                   | Profile name   | Detail          |
| -------------------------- | -------------- | --------------- |
| `DFUserProfile.BIRTH`      | df\_birth      | User's birthday |
| `DFUserProfile.GENDER`     | df\_gender     | User gender     |
| `DFUserProfile.NAME`       | df\_name       | User name       |
| `DFUserProfile.MEMBERSHIP` | df\_membership | User Membership |

### Set by item

```java
void setUserProfile(String key, String value)
```

Each parameter means:

* `key` : The name of the user profile attribute to set. `String` A value of type can be entered.
* `value` : The value of the user profile to be set. `null` The following types can be entered.
  * `String`, `Boolean`, `Long`, `Double`, `java.util.Date`, `Array of String`, `Array of Long`, `Array of Double`

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

```java
DfineryProperties.setUserProfile("CUSTOM_USER_PROFILE", "VALUE");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfile("CUSTOM_USER_PROFILE", "VALUE")
```

{% endtab %}
{% endtabs %}

### Set up multiple items at once

```java
void setUserProfiles(Map<String, Object> profiles)
```

* `profiles` : User profile to set. `java.util.Map<String,Object>` ou must enter the name and value in the form. `profiles`cannot `null`be entered.

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

```java
Map<String, Object> profiles = new HashMap<>();
//PredefinedUserProfile
profiles.put(DFUserProfile.NAME, "JACK");//String
profiles.put(DFUserProfile.PUSH_OPTIN, true);//Boolean
//CustomUserProfile
profiles.put("custom1", 34000L);//Long
profiles.put("custom2", 42.195);//Double
profiles.put("custom3", new Date());//Date
profiles.put("custom4", new Long[]{20L,30L});//Array of Long
profiles.put("custom5", new Double[]{1.1,1.2});//Array of Double
profiles.put("custom6", new String[]{"Hello","World"});//Array of String
DfineryProperties.setUserProfiles(profiles);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val profiles = mapOf<String, Any>(
    //PredefinedUserProfile
    DFUserProfile.NAME to "JACK",
    DFUserProfile.PUSH_OPTIN to true,
    //CustomUserProfile
    "custom1" to 34000L,//Long
    "custom2" to 42.195,//Double
    "custom3" to Date(),//Date
    "custom4" to longArrayOf(20L, 30L),//Array of Long
    "custom5" to doubleArrayOf(1.1, 1.2),//Array of Double
    "custom6" to arrayOf<String>("Hello", "World")//Array of String
)
DfineryProperties.setUserProfiles(profiles)
```

{% endtab %}
{% endtabs %}

## Example of use

User profiles have standard key values, and `DFUserProfile`you can apply them by entering constants in the key values.

### Set a name

* Support Type
  * value : `String`

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

```java
DfineryProperties.setUserProfile(DFUserProfile.NAME, "John");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfile(DFUserProfile.NAME, "John")
```

{% endtab %}
{% endtabs %}

### Set gender

* Support Type
  * value : `DFGender.MALE`, `DFGender.FEMALE`, `DFGender.NON_BINARY`, `DFGender.OTHER`

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

```java
DfineryProperties.setUserProfile(DFUserProfile.GENDER, DFGender.MALE);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfile(DFUserProfile.GENDER, DFGender.MALE)
```

{% endtab %}
{% endtabs %}

### Set your membership level

* Support Type
  * value : `String`

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

```java
DfineryProperties.setUserProfile(DFUserProfile.MEMBERSHIP, "VIP");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfile(DFUserProfile.MEMBERSHIP, "VIP")
```

{% endtab %}
{% endtabs %}

### Set your date of birth

* Support Type
  * value : `String(yyyy-MM-dd)`

{% hint style="warning" %}
For df\_birth (date of birth), please enter the input value type as a String type of yyyy-MM-dd. Example: "1999-01-01"
{% endhint %}

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

```java
DfineryProperties.setUserProfile(DFUserProfile.BIRTH, "1999-01-01");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfile(DFUserProfile.BIRTH, "1999-01-01")
```

{% endtab %}
{% endtabs %}

### Set consent information for receiving notifications <a href="#consent" id="consent"></a>

Consent to receive notifications is part of the user profile and you can set consent values ​​for various channels.

{% hint style="danger" %}
If you do not set the consent information for receiving notifications, the value is null. When it is null and true, notifications can be sent, and when it is false, notifications cannot be sent. For more information, please refer to [the user guide.](https://docs.dfinery.ai/user-guide/action/off-site-campaign/opt-state)
{% endhint %}

{% hint style="info" %}
User profiles for consent to receive notifications are automatically registered when creating a service in DFINERY, so they can be set up without having to set them in the DFINERY console.
{% endhint %}

* Support Type
  * key : Notification consent type (DFUserProfile)
  * value : `Boolean`

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

```java
DfineryProperties.setUserProfile(DFUserProfile.PUSH_OPTIN, true);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfile(DFUserProfile.PUSH_OPTIN, true)
```

{% endtab %}
{% endtabs %}

#### Types of consent to receive notifications <a href="#consent-type" id="consent-type"></a>

{% hint style="warning" %}
Please use the value to obtain consent for sending advertising notifications between 9 PM and 8 AM, as separate consent for nighttime advertising notifications is required to send advertising notifications `PUSH_NIGHT_ADS_OPTIN`. (Information and Communications Network Act Guide for Prevention of Illegal Spam, Korea Internet & Security Agency, July 2020)
{% endhint %}

| Designation                          | Channel     | Explanation                                                         |
| ------------------------------------ | ----------- | ------------------------------------------------------------------- |
| `DFUserProfile.PUSH_OPTIN`           | Push        | Consent to receive informational notifications for push channels    |
| `DFUserProfile.PUSH_ADS_OPTIN`       | Push        | Consent to receive promotional notifications for push channels      |
| `DFUserProfile.PUSH_NIGHT_ADS_OPTIN` | Push        | Consent to nightly promotional notifications for push channels      |
| `DFUserProfile.SMS_ADS_OPTIN`        | Message     | Consent to receive promotional notifications for text channels      |
| `DFUserProfile.KAKAO_ADS_OPTIN`      | Friend Talk | Consent to advertising notifications for Kakao Friends Talk channel |

## Setting custom user properties

If you want to set a custom user attribute, you can create a custom user attribute in the corresponding user profile in [the DFINERY console](https://console.dfinery.ai/) and set it by entering it as a key value.

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

```java
DfineryProperties.setUserProfile("CUSTOM_USER_PROFILE", true);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfile("CUSTOM_USER_PROFILE", true)
```

{% endtab %}
{% endtabs %}

## Setting custom user properties in date and time format <a href="#how-to-write-date-format" id="how-to-write-date-format"></a>

If you need to set the date and time format, `java.util.Date`you must use. The value you enter will be entered including the TimeZone information.

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

```java
//If you enter 1991.08.26 using Calendar
Calendar registeredDate = Calendar.getInstance();
registeredDate.set(Calendar.YEAR, 1991);
registeredDate.set(Calendar.MONTH, Calendar.AUGUST);
registeredDate.set(Calendar.DATE, 26);
DfineryProperties.setUserProfile("registered_date", registeredDate.getTime());

//If you input 1991.08.26 using SimpleDateFormat
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date registeredDate = simpleDateFormat.parse("1991-08-26");
DfineryProperties.setUserProfile("registered_date", registeredDate);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
//If you enter 1991.08.26 using Calendar
val registeredDate = Calendar.getInstance()
registeredDate[Calendar.YEAR] = 1991
registeredDate[Calendar.MONTH] = Calendar.AUGUST
registeredDate[Calendar.DATE] = 26
DfineryProperties.setUserProfile("registered_date", registeredDate.time);

//If you input 1991.08.26 using SimpleDateFormat
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd")
val registeredDate = simpleDateFormat.parse("1991-08-26")
DfineryProperties.setUserProfile("registered_date", registeredDate)
```

{% endtab %}
{% endtabs %}
