# 이벤트

이 문서는 DFINERY SDK를 사용하여 유저의 동작을 분석하기 위해 수행해야 할 작업에 대해 설명합니다. 이를 사용하기 위해서는 [SDK 연동](https://docs.dfinery.ai/developer-guide/platform/unity/integration)이 선행되어야 합니다.

## 시작하기 전에

이벤트를 연동하기 전에 [DFINERY 콘솔](https://console.dfinery.ai/)에서 이벤트 등록을 하세요. 이벤트 등록은 콘솔의 부가 설정 > 데이터 연동 > 이벤트 관리 > 이벤트 목록 페이지로 이동한 뒤 이벤트 생성 버튼을 눌러 표준 및 커스텀 이벤트를 생성할 수 있습니다.

## 유의사항

* 등록되지 않은 이벤트 또는 이벤트 속성이 입력될 경우 이벤트가 기록되지 않습니다.
* 입력한 이벤트 속성의 타입과 이벤트 속성 타입이 맞지 않을 경우 이벤트가 기록되지 않습니다.
* 이벤트에 필수로 입력되어야 하는 이벤트 속성이 누락될 경우 이벤트가 기록되지 않습니다.
* [상품](#item_property)은 한 이벤트에 최대 100개까지 입력 가능합니다.

## 이벤트 기록

`logEvent` 메소드를 사용하여 유저의 이벤트를 기록합니다. [표준 이벤트](#predefinded_event)는 상수를 제공합니다.

```csharp
void LogEvent(string eventName)
void LogEvent(string eventName, Dictionary<string, object> properties)
```

각각의 매개변수는 다음을 의미합니다.

* `eventName` : 이벤트 이름
* `properties` : 이벤트 속성

### 이벤트 기록 예시

```csharp
// 속성이 없을 경우
Dfinery.LogEvent(DFEvent.SIGN_UP);

// 속성이 있을 경우
JSONObject properties = new JSONObject();
properties.put(DFEventProperty.SHARING_CHANNEL, "Kakao");
Dfinery.LogEvent(DFEvent.SIGN_UP, properties);

```

## 표준 이벤트 및 속성

표준 이벤트와 표준 이벤트 속성, 상품 속성은 아래와 같습니다.

### 표준 이벤트 <a href="#predefinded_event" id="predefinded_event"></a>

표준 이벤트 이름은 다음과 같이 사전 정의된 정적 상수로 제공됩니다.

| 상수                             | 이벤트명                       | 표기명      |
| ------------------------------ | -------------------------- | -------- |
| `DFEvent.LOGIN`                | df\_login                  | 로그인      |
| `DFEvent.LOGOUT`               | df\_logout                 | 로그아웃     |
| `DFEvent.SIGN_UP`              | df\_sign\_up               | 회원가입     |
| `DFEvent.PURCHASE`             | df\_purchase               | 구매       |
| `DFEvent.VIEW_HOME`            | df\_view\_home             | 홈 화면 조회  |
| `DFEvent.VIEW_PRODUCT_DETAILS` | df\_view\_product\_details | 상품 상세보기  |
| `DFEvent.ADD_TO_CART`          | df\_add\_to\_cart          | 장바구니 담기  |
| `DFEvent.ADD_TO_WISHLIST`      | df\_add\_to\_wishlist      | 관심상품 추가  |
| `DFEvent.REFUND`               | df\_refund                 | 주문취소하기   |
| `DFEvent.VIEW_SEARCH_RESULT`   | df\_view\_search\_result   | 상품 검색하기  |
| `DFEvent.SHARE_PRODUCT`        | df\_share\_product         | 상품 공유하기  |
| `DFEvent.VIEW_LIST`            | df\_view\_list             | 상품 목록 조회 |
| `DFEvent.VIEW_CART`            | df\_view\_cart             | 장바구니 조회  |
| `DFEvent.ADD_PAYMENT_INFO`     | df\_add\_payment\_info     | 구매 정보 입력 |
| `DFEvent.REMOVE_CART`          | df\_remove\_cart           | 장바구니 삭제  |

### 표준 이벤트 속성

표준 이벤트의 속성 명의 경우 다음과 같이 이벤트 속성 명이 사전 정의된 정적 상수로 제공됩니다.

| 상수                                      | 이벤트 속성명                     | 표기명       |
| --------------------------------------- | --------------------------- | --------- |
| `DFEventProperty.ITEMS`                 | df\_items                   | 상품        |
| `DFEventProperty.TOTAL_REFUND_AMOUNT`   | df\_total\_refund\_amount   | 환불(취소) 총액 |
| `DFEventProperty.ORDER_ID`              | df\_order\_id               | 주문 번호(ID) |
| `DFEventProperty.DELIVERY_CHARGE`       | df\_delivery\_charge        | 배송료       |
| `DFEventProperty.PAYMENT_METHOD`        | df\_payment\_method         | 결제 방법     |
| `DFEventProperty.TOTAL_PURCHASE_AMOUNT` | df\_total\_purchase\_amount | 주문 총액     |
| `DFEventProperty.SHARING_CHANNEL`       | df\_sharing\_channel        | 상품공유 채널   |
| `DFEventProperty.SIGN_CHANNEL`          | df\_sign\_channel           | 상품 할인가    |
| `DFEventProperty.KEYWORD`               | df\_keyword                 | 검색 키워드    |

### 상품 속성 <a href="#item_property" id="item_property"></a>

DFEventProperty.ITEMS 내에 배열로 적재되는 상품에 대한 표준 이벤트 속성에 대한 정보입니다. ITEM\_ID, ITEM\_NAME, ITEM\_PRICE, ITEM\_QUANTITY, ITEM\_DISCOUNT는 필수 값으로 반드시 포함해야 합니다.

| 상수                               | 이벤트 속성명        | 타입     | 설명        | 필수 |
| -------------------------------- | -------------- | ------ | --------- | -- |
| `DFEventProperty.ITEM_ID`        | df\_item\_id   | string | 상품 번호(ID) | ✅  |
| `DFEventProperty.ITEM_NAME`      | df\_item\_name | string | 상품 명      | ✅  |
| `DFEventProperty.ITEM_PRICE`     | df\_price      | Number | 상품 단가     | ✅  |
| `DFEventProperty.ITEM_QUANTITY`  | df\_quantity   | Number | 상품 수량     | ✅  |
| `DFEventProperty.ITEM_DISCOUNT`  | df\_discount   | Number | 상품 할인가    | ✅  |
| `DFEventProperty.ITEM_CATEGORY1` | df\_category1  | string | 상품 카테고리1  |    |
| `DFEventProperty.ITEM_CATEGORY2` | df\_category2  | string | 상품 카테고리2  |    |
| `DFEventProperty.ITEM_CATEGORY3` | df\_category3  | string | 상품 카테고리3  |    |
| `DFEventProperty.ITEM_CATEGORY4` | df\_category4  | string | 상품 카테고리4  |    |
| `DFEventProperty.ITEM_CATEGORY5` | df\_category5  | string | 상품 카테고리5  |    |

## 표준 이벤트 사용 예시

### 로그인

유저가 서비스에 회원으로 가입하는 동작을 나타내는 이벤트입니다.

{% hint style="success" %}
로그인을 한 [유저 식별 정보를 설정](https://docs.dfinery.ai/developer-guide/platform/unity/identity)하면 통합 아이디에 정보가 반영되어 유저를 더 명확하게 식별할 수 있게 됩니다.
{% endhint %}

```csharp
Dfinery.LogEvent(DFEvent.LOGIN);
```

### 로그아웃

유저가 앱에서 로그아웃하는 동작을 나타내는 이벤트입니다.

```csharp
Dfinery.LogEvent(DFEvent.LOGOUT);
```

### 회원가입

유저가 회원으로 가입하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.SIGN_CHANNEL, "Kakao"}
};
Dfinery.LogEvent(DFEvent.SIGN_UP, properties);
```

#### 표준 이벤트 속성

| 이름                             | 타입     | 설명      | 필수 |
| ------------------------------ | ------ | ------- | -- |
| `DFEventProperty.SIGN_CHANNEL` | string | 회원가입 채널 | ✅  |

### 구매

유저가 상품이나 서비스를 구매하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items},
    {DFEventProperty.ORDER_ID, "상품번호"},
    {DFEventProperty.PAYMENT_METHOD, "BankTransfer"},
    {DFEventProperty.TOTAL_PURCHASE_AMOUNT, 25500.0},
    {DFEventProperty.DELIVERY_CHARGE, 3000.0},
    {DFEventProperty.DISCOUNT, 0},
};
Dfinery.LogEvent(DFEvent.PURCHASE, properties);
```

#### 표준 이벤트 속성

| 이름                                      | 타입                                 | 설명                   | 필수 |
| --------------------------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS`                 | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |
| `DFEventProperty.ORDER_ID`              | string                             | 주문 번호(ID)            | ✅  |
| `DFEventProperty.PAYMENT_METHOD`        | string                             | 결제 방법                | ✅  |
| `DFEventProperty.TOTAL_PURCHASE_AMOUNT` | double                             | 주문 총액                | ✅  |
| `DFEventProperty.DELIVERY_CHARGE`       | double                             | 배송료                  | ✅  |
| `DFEventProperty.DISCOUNT`              | double                             | 상품할인가                | ✅  |

### 홈 화면 조회

유저가 앱의 홈 화면을 조회하는 동작을 나타내는 이벤트입니다.

```csharp
Dfinery.LogEvent(DFEvent.VIEW_HOME);
```

### 상품 상세 보기

유저가 특정 상품의 상세 정보를 조회하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items}
};
Dfinery.LogEvent(DFEvent.VIEW_PRODUCT_DETAILS, properties);
```

#### 표준 이벤트 속성

| 이름                      | 타입                                 | 설명                   | 필수 |
| ----------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS` | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |

### 장바구니 담기

유저가 상품을 장바구니에 담는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items}
};
Dfinery.LogEvent(DFEvent.ADD_TO_CART, properties);
```

#### 표준 이벤트 속성

| 이름                      | 타입                                 | 설명                   | 필수 |
| ----------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS` | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |

### 관심 상품 추가

유저가 상품을 관심 목록에 추가하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items}
};
Dfinery.LogEvent(DFEvent.ADD_TO_WISHLIST, properties);
```

#### 표준 이벤트 속성

| 이름                      | 타입                                 | 설명                   | 필수 |
| ----------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS` | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |

### 주문 취소하기

유저가 구매한 주문을 취소하고 환불하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items},
    {DFEventProperty.TOTAL_REFUND_AMOUNT, 22500.0}
};
Dfinery.LogEvent(DFEvent.REFUND, properties);
```

#### 표준 이벤트 속성

| 이름                                    | 타입                                 | 설명                   | 필수 |
| ------------------------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS`               | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |
| `DFEventProperty.TOTAL_REFUND_AMOUNT` | double                             | 환불(취소) 총액            | ✅  |

### 상품 검색하기

유저가 상품을 검색하여 결과를 확인하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items},
    {DFEventProperty.KEYWORD, "삼겹살"}
};
Dfinery.LogEvent(DFEvent.REFUND, properties);
```

#### 표준 이벤트 속성

| 이름                        | 타입                                 | 설명                   | 필수 |
| ------------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS`   | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |
| `DFEventProperty.KEYWORD` | string                             | 검색 키워드               | ✅  |

### 상품 공유하기

유저가 상품을 공유하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items},
    {DFEventProperty.SHARING_CHANNEL, "Facebook"}
};
Dfinery.LogEvent(DFEvent.SHARE_PRODUCT, properties);
```

#### 표준 이벤트 속성

| 이름                                | 타입                                 | 설명                   | 필수 |
| --------------------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS`           | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |
| `DFEventProperty.SHARING_CHANNEL` | string                             | 상품 공유 채널             | ✅  |

### 상품 목록 조회

유저가 상품 목록을 조회하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items}
};
Dfinery.LogEvent(DFEvent.VIEW_LIST, properties);
```

#### 표준 이벤트 속성

| 이름                      | 타입                                 | 설명                   | 필수 |
| ----------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS` | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |

### 장바구니 조회

유저가 장바구니를 조회하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items}
};
Dfinery.LogEvent(DFEvent.VIEW_CART, properties);
```

#### 표준 이벤트 속성

| 이름                      | 타입                                 | 설명                   | 필수 |
| ----------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS` | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |

### 구매 정보 입력

유저가 구매 정보를 입력하는 동작을 나타내는 이벤트입니다.

```csharp
Dfinery.LogEvent(DFEvent.ADD_PAYMENT_INFO);
```

### 장바구니 삭제

유저가 장바구니에 담긴 상품을 제거하는 동작을 나타내는 이벤트입니다.

```csharp
Dictionary<string, object> item = new Dictionary<string, object>
{
    {DFEventProperty.ITEM_ID, "상품번호"},
    {DFEventProperty.ITEM_NAME, "상품이름"},
    {DFEventProperty.ITEM_CATEGORY1, "식품"},
    {DFEventProperty.ITEM_CATEGORY2, "과자"},
    {DFEventProperty.ITEM_PRICE, 5000.0},
    {DFEventProperty.ITEM_DISCOUNT, 500.0},
    {DFEventProperty.ITEM_QUANTITY, 5L}
};
List<Dictionary<string, object>> items = new List<Dictionary<string, object>> { item };
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {DFEventProperty.ITEMS, items}
};
Dfinery.LogEvent(DFEvent.REMOVE_CART, properties);
```

#### 표준 이벤트 속성

| 이름                      | 타입                                 | 설명                   | 필수 |
| ----------------------- | ---------------------------------- | -------------------- | -- |
| `DFEventProperty.ITEMS` | List\<Dictionary\<string, object>> | [상품](#item_property) | ✅  |

## 커스텀 이벤트

사용자가 직접 임의의 이벤트 명칭과 속성을 입력하여 반영하는 이벤트입니다. 표준 이벤트에도 디파이너리 콘솔에서 커스텀 속성을 추가하여 사용할 수 있습니다.

**속성이 없을 경우**

```csharp
Dfinery.LogEvent("CUSTOM_EVENT_NAME", null);
```

**속성이 있을 경우**

```csharp
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {"CUSTOM_PROPERTY_KEY", "CUSTOM_PROPERTY_VALUE"}//사용자 정의 속성 값(Optional)
};
Dfinery.LogEvent("CUSTOM_EVENT_NAME", properties);
```

## 날짜 및 시간 형식 속성 입력하기

날짜 및 시간 형식은 `yyyy-MM-dd'T'HH:mm:ss.SSS'Z'` 포맷의 문자열 형태로 입력해야합니다.

```csharp
Dictionary<string, object> properties = new Dictionary<string, object>
{
    {"CUSTOM_PROPERTY_KEY", DateTime.Now}//사용자 정의 속성 값(Optional)
};
Dfinery.LogEvent(DFEvent.SIGN_UP, properties);
```
