> For the complete documentation index, see [llms.txt](https://docs.dfinery.ai/developer-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dfinery.ai/developer-guide/platform/android/user-profile.md).

# 유저 프로필 설정

유저 프로필은 DFINERY 서버에서 관리하고 있는 유저에 대한 프로필 정보입니다. 해당 정보들은 모두 선택사항이며 단말기에 저장되지 않습니다.

## 시작하기 전에

유저 프로필을 설정하기 전에 [DFINERY 콘솔](https://console.dfinery.ai/)에 유저 프로필 속성을 생성 후 연동해 주세요. 유저 프로필 속성은 부가 설정 / 데이터 연동 / 속성 관리 / 유저 프로필 속성 목록에서 생성할 수 있습니다.

## 유의사항

* 등록되지 않은 유저 프로필, 잘못된 타입의 유저 프로필 속성이 기록될 경우, 유저 프로필은 설정되지 않습니다.
* `Array of String` 타입의 유저 프로필 속성은 최대 10개까지 생성할 수 있습니다.
* `Array of Long`, `Array of Double` 타입은 최대 5개까지 생성할 수 있습니다.
* value의 입력 개수 제한은 없으나 전체 크기는 8KB를 초과할 수 없습니다.

## 설정하기

`DfineryProperties.setUserProfiles()` 사용하여 유저 프로필을 설정할 수 있습니다.

### 유저 프로필 속성

| 상수                         | 프로필명           | 내용      |
| -------------------------- | -------------- | ------- |
| `DFUserProfile.BIRTH`      | df\_birth      | 유저 생일   |
| `DFUserProfile.GENDER`     | df\_gender     | 유저 성별   |
| `DFUserProfile.NAME`       | df\_name       | 유저 이름   |
| `DFUserProfile.MEMBERSHIP` | df\_membership | 유저의 멤버쉽 |

### 메소드 설명

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

* `profiles` : 설정할 유저 프로필. `java.util.Map<String,Object>` 형태로 이름과 값을 입력해야 합니다. `profiles`는 `null`이 입력 될 수 없습니다.

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

```java
Map<String, Object> profiles = new HashMap<>();
//PredefinedUserProfile
profiles.put(DFUserProfile.NAME, "JACK");//String
profiles.put(DFUserProfile.PUSH_ADS_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_ADS_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 %}

## 사용 예시

유저 프로필에는 표준 키 값 들이 있으며, 키 값에 `DFUserProfile`에 있는 상수를 입력하면 적용됩니다.

### 이름 설정하기

* 지원 유형
  * value : `String`

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

```java
Map<String, Object> profiles = new HashMap<>();
profiles.put(DFUserProfile.NAME, "John");
DfineryProperties.setUserProfiles(profiles);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfiles(mapOf(DFUserProfile.NAME to "John"))
```

{% endtab %}
{% endtabs %}

### 성별 설정하기

* 지원 유형
  * value : `DFGender.MALE`, `DFGender.FEMALE`, `DFGender.NON_BINARY`, `DFGender.OTHER`

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

```java
Map<String, Object> profiles = new HashMap<>();
profiles.put(DFUserProfile.GENDER, DFGender.MALE);
DfineryProperties.setUserProfiles(profiles);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfiles(mapOf(DFUserProfile.GENDER to DFGender.MALE))
```

{% endtab %}
{% endtabs %}

### 회원 등급 설정하기

* 지원 유형
  * value : `String`

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

```java
Map<String, Object> profiles = new HashMap<>();
profiles.put(DFUserProfile.MEMBERSHIP, "VIP");
DfineryProperties.setUserProfiles(profiles);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfiles(mapOf(DFUserProfile.MEMBERSHIP to "VIP")))
```

{% endtab %}
{% endtabs %}

### 생년월일 설정하기

* 지원 유형
  * value : `String(yyyy-MM-dd)`

{% hint style="warning" %}
df\_birth(생년월일)의 경우 입력 값 타입을 yyyy-MM-dd의 String 타입으로 입력해 주세요. 예시: "1999-01-01"
{% endhint %}

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

```java
Map<String, Object> profiles = new HashMap<>();
profiles.put(DFUserProfile.BIRTH, "1999-01-01");
DfineryProperties.setUserProfiles(profiles);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfiles(mapOf(DFUserProfile.BIRTH to "1999-01-01")))
```

{% endtab %}
{% endtabs %}

### 알림 수신 동의 정보 설정하기 <a href="#consent" id="consent"></a>

알림 수신 동의 정보는 유저 프로필에 속해있으며 다양한 채널에 대한 수신 동의 정보 값을 설정할 수 있습니다.

{% hint style="danger" %}
알림 수신 동의 정보를 설정해주지 않는 경우 해당 값은 null이며, null과 true일 때 발송이 가능하고, false 일 때 발송되지 않습니다. 자세한 사항은 [이용 가이드](https://docs.dfinery.ai/user-guide/action/off-site-campaign/opt-state) 참고해주시기 바랍니다.
{% endhint %}

{% hint style="info" %}
알림 수신 동의 정보에 대한 유저 프로필은 예외적으로 DFINERY에서 서비스 생성 시 이미 자동으로 등록되어 있어 DFINERY 콘솔에서 설정하지 않아도 설정이 가능합니다.
{% endhint %}

* 지원 유형
  * key : 알림 수신 동의 유형(DFUserProfile)
  * value : `Boolean`

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

```java
Map<String, Object> profiles = new HashMap<>();
profiles.put(DFUserProfile.PUSH_ADS_OPTIN, true);
DfineryProperties.setUserProfiles(profiles);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfiles(mapOf(DFUserProfile.PUSH_ADS_OPTIN to true)))
```

{% endtab %}
{% endtabs %}

#### 알림 수신 동의 유형 <a href="#consent-type" id="consent-type"></a>

{% hint style="warning" %}
오후 9시 부터 오전 8시 사이에는 별도의 야간 광고성 알림 동의를 받아야 광고성 알림을 전송할 수 있으므로 해당 시간에 메시지를 발송하고 싶으실 경우 `PUSH_NIGHT_ADS_OPTIN` 값을 사용하여 동의를 받아 주시기 바랍니다. (불법 스팸 방지를 위한 정보통신망법 안내서, 한국인터넷진흥원, 2020.07)
{% endhint %}

| 명칭                                   | 채널           | 설명                                |
| ------------------------------------ | ------------ | --------------------------------- |
| `DFUserProfile.PUSH_ADS_OPTIN`       | 푸시           | 푸시 채널에 대한 광고성 알림 동의               |
| `DFUserProfile.PUSH_NIGHT_ADS_OPTIN` | 푸시           | 푸시 채널에 대한 야간 광고성 알림 동의            |
| `DFUserProfile.SMS_ADS_OPTIN`        | 문자           | 문자 채널에 대한 광고성 알림 동의               |
| `DFUserProfile.KAKAO_ADS_OPTIN`      | 친구톡, 브랜드 메시지 | 카카오 친구톡과 브랜드 메시지 채널에 대한 광고성 알림 동의 |

## 커스텀 유저 속성 설정하기

커스텀 유저 속성을 설정하고 싶을 경우 [DFINERY 콘솔](https://console.dfinery.ai/)에 해당하는 유저 프로필의 커스텀 유저 속성을 생성하고 키 값으로 입력하여 설정하면 됩니다.

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

```java
Map<String, Object> profiles = new HashMap<>();
profiles.put("CUSTOM_USER_PROFILE", true);
DfineryProperties.setUserProfiles(profiles);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
DfineryProperties.setUserProfiles(mapOf("CUSTOM_USER_PROFILE" to true)))
```

{% endtab %}
{% endtabs %}

## 날짜 및 시간 형식의 커스텀 유저 속성 설정하기 <a href="#how-to-write-date-format" id="how-to-write-date-format"></a>

날짜 및 시간 형식의 설정해야 할 경우 `java.util.Date`을 사용하여 입력해야 합니다. 입력한 값은 TimeZone 정보를 포함하여 입력됩니다.

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

```java
//1991.08.26를 Calendar를 사용해 입력했을 경우
Calendar registeredDate = Calendar.getInstance();
registeredDate.set(Calendar.YEAR, 1991);
registeredDate.set(Calendar.MONTH, Calendar.AUGUST);
registeredDate.set(Calendar.DATE, 26);
Map<String, Object> profiles = new HashMap<>();
profiles.put("registered_date", registeredDate.getTime());
DfineryProperties.setUserProfiles(profiles);

//1991.08.26을 SimpleDateFormat을 사용해 입력했을 경우
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date registeredDate = simpleDateFormat.parse("1991-08-26");
Map<String, Object> profiles = new HashMap<>();
profiles.put("registered_date", registeredDate);
DfineryProperties.setUserProfiles(profiles);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
//1991.08.26를 Calendar를 사용해 입력했을 경우
val registeredDate = Calendar.getInstance()
registeredDate[Calendar.YEAR] = 1991
registeredDate[Calendar.MONTH] = Calendar.AUGUST
registeredDate[Calendar.DATE] = 26
DfineryProperties.setUserProfiles(mapOf("registered_date" to registeredDate.time))

//1991.08.26을 SimpleDateFormat을 사용해 입력했을 경우
val simpleDateFormat = SimpleDateFormat("yyyy-MM-dd")
val registeredDate = simpleDateFormat.parse("1991-08-26")
DfineryProperties.setUserProfiles(mapOf("registered_date" to registeredDate))
```

{% endtab %}
{% endtabs %}
