# Crash 설정

## 1. 상세 설정

### 수집 서버 설정

{% hint style="warning" %}
설치형으로 진행 된 고객사에서는 반드시 이 부분 설정이 필요합니다.
{% endhint %}

IMQA Crash 프레임워크가 수집하는 데이터를 보내는 수집 서버를 별도로 설정하실 수 있습니다. 기본적으로는 SaaS 서비스를 이용하는 고객은 별도 설정이 필요하지 않습니다. <br>

**Objective-C 설정 방법**

{% code title="AppDelegate.m" %}

```swift
NSString* imqaUrl = @"https://custom-url";
IMQACrashConfiguration* crashConfig = [[IMQACrashConfiguration alloc] initWithApiKey:PROJECT_KEY];

IMQACrashEndpointConfiguration* endpoint = [[IMQACrashEndpointConfiguration alloc] init];
endpoint.notify = [imqaUrl stringByAppendingString:@"/cocoa/crash/send"];
endpoint.sessions = [imqaUrl stringByAppendingString:@"/cocoa/session"];
crashConfig.endpoints = endpoint;


```

{% endcode %}

**Swift 설정 방법**

{% code title="AppDelegate.swift" %}

```swift
let imqaUrl = "https://custom-url"
let crashConfig = IMQACrashConfiguration("<PROJECT_KEY>")
crashConfig.endpoints = IMQACrashEndpointConfiguration(
                                 notify: imqaUrl + "/cocoa/crash/send",
                                 sessions: imqaUrl + "/cocoa/session")
```

{% endcode %}

### Custom User ID 등록

크래시 데이터 수집 시 특정 사용자를 식별하기 위한 ID 정보를 설정할 수 있습니다. 사용자 ID 정보를 설정한 후, Crash 에러 목록 에서 사용자 ID 정보로 에러를 조회할 수 있습니다.

{% hint style="warning" %}
**Custom User ID 등록시,** 사용자 식별을 위해 사용자 로그인 후의 화면, 홈 화면 또는 스플래시 화면에 추가해 주세요.
{% endhint %}

{% hint style="info" %}
SDK 옵션 상, MethodName은 사용자ID, 사용자 이름, 사용자 이메일로 작성되었으나 사용 예시이며, 실제 개인을 특정할 수 있는 직접 식별 정보 (특정 이름, 주민등록번호, 이메일 주소, 기타 유사 데이터) 보다는 **2차 가공한 임의의 식별 정보**를 사용하시기를 권고 드립니다.\
\
예를 들어, 2차 가공한 식별자 (예: 2013133, A39233 등), 등급 정보 (예: VIP, Gold, Member), 유입 경로 (예: Google, N, K) 등으로 사용자의 유형 분류에 따른 분석이 가능합니다.
{% endhint %}

<table><thead><tr><th width="282.4795378120725">Option Name</th><th>Description</th></tr></thead><tbody><tr><td>id</td><td>사용자 ID-1 (Primary)</td></tr><tr><td>name</td><td>사용자 ID-2</td></tr><tr><td>email</td><td>사용자 ID-3</td></tr></tbody></table>

* **Swift 설정 방법 (MPM/Crash 설정)**

```javascript
// Crash 설정
let crashConfig = IMQACrashConfiguration(PROJECT_KEY!)
crashConfig.setUser(userId, withEmail: userEmail, andName: userName)

// MPM 설정
IMQAMpm.sharedInstance.saveUserProfile(id: userId, name: userName, email: userEmail)
```

SDK에서 사전 정의한 사용자의 ID 정보가 수집되었을 경우, MPM 행동분석 및 Crash 사용자별 에러 목록에서 사용자 ID 정보로 데이터 조회가 가능합니다.

<figure><img src="https://3726060384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzFyCopc6yAp3UcEYW6la%2Fuploads%2F57zLvSuW0ysPZzBkJM5q%2FScreenshot%202024-08-30%20at%209.11.11%E2%80%AFAM.png?alt=media&#x26;token=8cb255cd-5a5d-4e34-98d6-836cc485f709" alt=""><figcaption></figcaption></figure>

## 2. 커스텀 에러 보내기

IMQA Crash는 원하는 Custom Error를 직접 보내실 수 있습니다. 각종 네트워크 에러나 수집하고 싶은 Error는 NSError를 통해 IMQA 서버에 직접 보내 트레킹 하실 수 있습니다.

### **Objective-C 설정 방법**

{% code title="AppDelegate.m" %}

```
#import <IMQACrashAgent/IMQACrash.h>

NSError* custom_error = [NSError errorWithDomain:@"custom_error" code:404 userInfo:NULL];
[IMQACrash notifyError:custom_error];
```

{% endcode %}

### **Swift 설정 방법**

{% code title="AppDelegate.swift" %}

```swift
let custom_error = NSError(domain: "custom error", code: 404, userInfo: nil)
IMQACrash.notifyError(custom_error)
```

{% endcode %}

## 3. Custom Web Crash 발생

IMQA Webview Agent 에서는 웹뷰에서 발생하는 에러나 비즈니스 로직에서 발생하는 다양한 문제를 사용자 정의 에러로 수집할 수 있습니다.

{% hint style="warning" %}
Webview Crash 수집을 위해서는 ImqaBridgeCrash 를 추가해 주어야 합니다. \
‘[iOS > MPM 설정 > MPM Webview Guide (WKWebView) > iOS Agent 설정](https://docs.imqa.io/imqa-guide/installation/ios/mpm#ios-agent)'을 참고하세요.
{% endhint %}

{% code title="사용자 정의 에러 수집할 js 파일" %}

```javascript
throw new IMQACustomError("사용자가 지정한 에러 메시지");

try {
	...
} catch (e) {
	throw new IMQACustomError(e)
}
```

{% endcode %}

커스텀 웹 에러 발생시, 아래와 같이 IMQA Crash, WCrash 에러 검색에서 에러 유형 ‘WCustom’으로 구분하여 검색하실 수 있습니다.

<figure><img src="https://3726060384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzFyCopc6yAp3UcEYW6la%2Fuploads%2F9D4U3yPAf9EV47Gj7ejL%2F10.123.100.5_3081_crash_4_error_total(1920)%20(1).png?alt=media&#x26;token=e8b01c14-b7d6-4ba4-a92f-b89e432b71ce" alt=""><figcaption></figcaption></figure>

{% hint style="danger" %}
현재 WCustom 유형 에러 목록 확인은 ‘에러 검색’ 페이지를 통해서만 가능합니다.
{% endhint %}

## 4. 특정 웹 크래시 수집 제한 옵션 <a href="#filtererror" id="filtererror"></a>

IMQA Webview Agent 에서는 웹뷰에서 발생하는 에러 중 수집하고 싶지 않은 에러를 설정할 수 있습니다.

{% hint style="warning" %}
Webview Crash 수집을 위해서는 ImqaBridgeCrash 를 추가해 주어야 합니다. \
‘[iOS > MPM 설정 > MPM Webview Guide (WKWebView) > iOS Agent 설정](https://docs.imqa.io/imqa-guide/installation/ios/mpm#ios-agent)'을 참고하세요.
{% endhint %}

<table><thead><tr><th width="137" align="center">Option Name</th><th width="125" align="center">Type</th><th width="132" align="center">Default Value</th><th>Description</th></tr></thead><tbody><tr><td align="center">filterError</td><td align="center">string[] | null</td><td align="center">null</td><td>예) [”$”, “type”]<br>- Agent가 수집한 에러(Web Crash)중 배열속 문자열이 포함된 에러라면 수집하지 않습니다.<br>- 대소문자는 구분하지 않습니다. <br>- [”type”]으로 옵션값을 설정하시면 “TypeError …”과 같은 에러도 수집되지 않습니다.</td></tr></tbody></table>

필수 설정과 특정 웹 크래시 수집 제한 옵션을 적용한 스크립트는 아래와 같습니다.

{% code title="webview-agent.js 연결 할 html <head>" overflow="wrap" %}

```html
// IMQA webview-agent.js 연결
<script src="https://cdn.imqa.io/agent/webview-agent.js"></script>

// IMQA webview-agent 스크립트 필수 값
<script>
    ((w, c, _wv, _w, _wk, _mh, _b) => {
        w[c] = w[c] || {};
    function imqaConf(key, value){w[c][key]=value};

    // 특정 웹 크래시 수집 제한 옵션
    imqaConf("filterError", ["$", "type"]); // "$" 또는 "type"이 에러명에 포함된 에러는 수집하지 않음         
                                                    
       w[_wv](w); // 웹뷰 에이전트 실행함수
    })(window, 'imqaClientConfig', 'IMQAWebviewMain', 'IMQAWebMain', 'webkit', 'messageHandlers', 'ImqaBridge')
</script>


```

{% endcode %}

위와 같이 Agent 웹 크래시 수집 제한 설정시, IMQA Crash, WCrash에서 **에러명**에 "$" 또는 "type"이 포함된 웹 크래시는 수집되지 않습니다.

<figure><img src="https://3726060384-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FzFyCopc6yAp3UcEYW6la%2Fuploads%2FLhS7rd4IOVZOUWCoF9Fq%2FScreenshot%202024-08-06%20at%203.43.43%E2%80%AFPM.png?alt=media&#x26;token=7fa1d5d7-8e49-41ba-8801-f1413c633660" alt=""><figcaption><p>"type"이 포함된 에러명 예시</p></figcaption></figure>

## 5. dSYM 설정

iOS의 Symbolication(기호화) 적용이 된 앱의 경우, dSYM 설정을 통해 클래스 명과 함수 명을 확인할 수 있습니다.&#x20;

<figure><img src="https://lh5.googleusercontent.com/rkImE72Kx6O3Pz7OF9scghMIPhh0wpxb-gVsm1py8Dten1WDU0p3fGEh8njQJyU9XiwmPGHUrFL_zwdJhAulu3mcuvu5POXOP-FPy8l_ArPigb_x-8grKBP7tjvf09Zr2xiQ5gNBdLRztqG_RztCzpg" alt=""><figcaption></figcaption></figure>

❶ **매핑 파일 업로드**\
1\. \[파일 선택]을 클릭하여 ‘dSYM’ 패키지 안의 바이너리 파일을 선택합니다.

{% hint style="info" %}
‘\*.dSYM’ 파일 \[패키지 내용 보기] → ‘Contents > Resources > DWARF > (바이너리 파일)’ 경로 예시\
![](https://lh6.googleusercontent.com/EzVtMu5r0oL7cdBmYQJ5uoZzlKbkPQTTYWVLZkLNRK4w7uZma9OvcD68W2J1vVZDMgJS1YF7vo1QgO31hKGZM4BZsBKHukQve16xO1qnyaIh5pYrd75dgzoch8zzpc0oFjiUoY7gLiQ7IBUntBTCY3Q)
{% endhint %}

2\. 적용할 앱 버전을 입력하고 \[등록]을 클릭합니다. \
3\. 데이터의 클래스 명과 함수 명을 IMQA에서 확인할 수 있습니다.

❷ **등록된 매핑 파일**\
등록된 매핑 파일과 적용된 앱 버전, 업로드 시간을 확인할 수 있습니다.

❸ **매핑 파일 관리**\
\[삭제] 아이콘을 클릭하면 해당 매핑 파일을 삭제합니다.

{% hint style="warning" %}
최신 앱 버전이 릴리즈 된 경우, 해당 버전에서 발생한 크래시 정보를 보기 위해서는 동일한 앱 버전의 매핑 파일을 추가 등록해 주세요.
{% endhint %}

<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.imqa.io/imqa-guide/installation/ios/crash-sdk-setting.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
