예외 측정
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
예외 이벤트를 전송하여 웹페이지에서 발생하는 비정상 종료나 오류의 수와 유형을 측정할 수 있습니다. 이 페이지에서는 gtag.js를 사용하여 Google 애널리틱스로 예외를 전송하는 방법을 설명합니다.
구현
오류가 발생하면 Google 애널리틱스로 예외 이벤트를 전송합니다.
gtag('event', 'exception', {<exception_parameters>});
여기서 <exception_parameters>
는 하나 이상의 매개변수-값 쌍입니다. 각 쌍을 쉼표로 구분하세요. 예를 들어 다음 명령어는 심각하지 않은 오류를 전송합니다.
예외가 인정됩니다.
gtag('event', 'exception', {
'description': 'error_description',
'fatal': false // set to true if the error is fatal
});
예외 매개변수
다음 표에는 예외 매개변수가 나와 있습니다.
매개변수 이름 |
데이터 유형 |
필수 |
설명 |
description |
문자열 |
아니요 |
오류에 대한 설명입니다. |
fatal |
불리언 |
아니요 |
오류가 심각한 경우 true 입니다. |
예
다음 함수가 지정된 경우:
function divide(x, y) {
if (y === 0) {
throw "Division by zero";
}
return x/y;
}
제수 y가 0이면 다음 코드는 Google 애널리틱스로 예외 이벤트를 전송합니다.
var x = document.getElementById('x').value;
var y = document.getElementById('y').value;
try {
var r = divide(x, y);
} catch(err) {
gtag('event', 'exception', {
'description': err,
'fatal': false
});
}
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-09-13(UTC)
[null,null,["최종 업데이트: 2024-09-13(UTC)"],[[["\u003cp\u003eGoogle Analytics can track website errors and crashes using exception events sent via gtag.js.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003egtag('event', 'exception', {<exception_parameters>})\u003c/code\u003e is the core function to send exception data, including an optional description and fatality status.\u003c/p\u003e\n"],["\u003cp\u003eAn example demonstrates how to capture and send exceptions occurring within a JavaScript \u003ccode\u003etry...catch\u003c/code\u003e block.\u003c/p\u003e\n"]]],["Exception events, used to track web page crashes and errors, are sent to Google Analytics via the `gtag('event', 'exception', {\u003cexception_parameters\u003e});` command. `\u003cexception_parameters\u003e` include 'description' (error details) and 'fatal' (boolean indicating if the error is fatal). When an error is detected, a `gtag` event can be sent. An example uses a `try...catch` block to intercept division-by-zero errors and trigger the `gtag` event.\n"],null,["# Measure exceptions\n\nYou can send exception events to measure the number and type of crashes or\nerrors that occur on a web page. This page describes how to use gtag.js to send\nexceptions to Google Analytics.\n\nImplementation\n--------------\n\nWhen an error occurs, send an exception event to Google Analytics: \n\n gtag('event', 'exception', {\u003cexception_parameters\u003e});\n\nwhere `\u003cexception_parameters\u003e` is one or more parameter-value pairs. Separate\neach pair by a comma. For example, this command sends a nonfatal error\nexception. \n\n gtag('event', 'exception', {\n 'description': 'error_description',\n 'fatal': false // set to true if the error is fatal\n });\n\nException parameters\n--------------------\n\nThe following table lists the exception parameters:\n\n| Parameter name | Data type | Required | Description |\n|----------------|-----------|----------|--------------------------------|\n| `description` | string | No | A description of the error. |\n| `fatal` | boolean | No | `true` if the error was fatal. |\n\nExample\n-------\n\nGiven the following function: \n\n function divide(x, y) {\n if (y === 0) {\n throw \"Division by zero\";\n }\n return x/y;\n }\n\nthe following code will send an exception event to Google Analytics if the\ndivisor y is zero: \n\n var x = document.getElementById('x').value;\n var y = document.getElementById('y').value;\n\n try {\n var r = divide(x, y);\n } catch(err) {\n gtag('event', 'exception', {\n 'description': err,\n 'fatal': false\n });\n }"]]