# 유저 프로필 설정

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

## 시작하기 전에

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

## 유의사항

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

## 설정하기

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

### 유저 프로필 속성

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

### 메소드 설명

```csharp
void SetUserProfiles(Dictionary<string, object> profiles)
```

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

```csharp
Dictionary<string, object> profiles = new Dictionary<string, object>
{
  {DFUserProfile.NAME, "JACK"},
  {DFUserProfile.PUSH_ADS_OPTIN, true},
  {"custom1", 34000L},//Long
  {"custom2", 42.195},//Double
  {"custom3", DateTime.Now},//Datetime
  {"custom4", new List<long>() { 20L, 30L}},
  {"custom5", new List<double>() { 1.1, 1.2 }},
  {"custom6", new List<string>() { "Hello", "World" }}
}
Dfinery.SetUserProfiles(profiles);
```

## 사용 예시

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

### 이름 설정하기

* 지원 유형
  * value : `string`

```csharp
Dfinery.SetUserProfiles(new Dictionary<string, object> {{DFUserProfile.NAME, "John"}});
```

### 성별 설정하기

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

```csharp
Dfinery.SetUserProfiles(new Dictionary<string, object> {{DFUserProfile.GENDER, DFGender.MALE}});
```

### 회원 등급 설정하기

* 지원 유형
  * value : `string`

```csharp
Dfinery.SetUserProfiles(new Dictionary<string, object> {{DFUserProfile.MEMBERSHIP, "VIP"}});
```

### 생년월일 설정하기

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

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

```csharp
Dfinery.SetUserProfiles(new Dictionary<string, object> {{DFUserProfile.BIRTH, "1999-01-01"}});
```

### 알림 수신 동의 정보 설정하기 <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 : `bool`

```csharp
Dfinery.SetUserProfiles(new Dictionary<string, object> {{DFUserProfile.PUSH_ADS_OPTIN, true}});
```

#### 알림 수신 동의 유형 <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/)에 해당하는 유저 프로필의 커스텀 유저 속성을 생성하고 키 값으로 입력하여 설정하면 됩니다.

```csharp
Dfinery.SetUserProfiles(new Dictionary<string, object> {{"CUSTOM_USER_PROFILE", true}});
```

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

날짜 및 시간 형식의 설정해야 할 경우 [Datetime](https://learn.microsoft.com/ko-kr/dotnet/api/system.datetime?view=net-8.0)을 사용하여 입력해야 합니다. 입력한 값은 TimeZone 정보를 포함하여 입력됩니다.

```csharp
DateTime registeredDate = new DateTime(1991, 8, 26)
Dfinery.SetUserProfiles(new Dictionary<string, object> {{"registered_date", registeredDate}});
```
