DataCapture 정책의 <Collect> 요소를 사용하여 수집할 데이터를 지정합니다.
데이터 수집기 REST 리소스 만들기
DataCapture 정책을 사용하려면 먼저 데이터 수집기 REST 리소스를 만들어야 합니다. 이렇게 하려면 다음과 같이 API 요청을 보냅니다.
curl -H "Authorization: Bearer $(gcloud auth print-access-token)" -X POST -H "content-type:application/json" \
-d '
{
"name": "dc_my_custom_data",
"description": "Collects data for analysis.",
"type": "STRING",
}' \
"https://apigee.googleapis.com/v1/organizations/$PROJECT_ID/datacollectors"
그러면 dc_my_custom_data라는 리소스가 생성되며 이 리소스를 DataCapture 정책에서 사용할 수 있습니다.
수집할 데이터 지정
DataCapture 정책의 <Collect> 요소를 사용하여 수집할 데이터를 지정할 수 있습니다. DataCapure 참조 페이지의 예시 섹션에 표시된 것처럼 다양한 방법이 있습니다. 한 가지 방법은 API 요청 및 응답에 전달된 데이터를 저장하는 흐름 변수를 지정하는 것입니다. 예를 들어 고객이 흐름 변수 message.formparam.param_name.values를 사용하여 웹페이지 양식에 입력하는 데이터를 수집할 수 있습니다. 여기서 param_name은 양식의 매개변수 이름입니다. 양식에 payment_amount라는 매개변수가 있다고 가정해 보겠습니다. 해당 흐름 변수는 message.formparam.payment_amount.values입니다.
이 설정을 사용하면 양식의 payment_amount 필드에 입력되는 데이터가 DataCapture에서 수집되어 dc_my_custom_data라는 변수에 저장됩니다.
DataCapture로 수집된 데이터에서 커스텀 보고서 만들기
DataCapture 정책으로 데이터 수집을 설정한 후에는 커스텀 보고서 추가에 설명된 절차에 따라 데이터를 사용하여 커스텀 보고서를 만들 수 있습니다.
이렇게 하려면 절차의 4단계에 표시된 대로 보고서의 측정항목을 선택할 때 DataCapture용으로 만든 데이터 수집기 REST 리소스와 이름이 동일한 변수를 선택합니다. 예를 들어 아래와 같이 dc_my_custom_data입니다.
커스텀 보고서에서 측정기준과 동일한 변수를 사용할 수도 있습니다. 측정기준은 변수의 값을 기준으로 데이터를 그룹화하므로 일반적으로 제한된 수의 값만 취하는 문자열을 변수로 사용하는 것이 좋습니다.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-08-19(UTC)"],[[["\u003cp\u003eThis documentation page pertains to both Apigee and Apigee hybrid platforms, detailing how to collect custom API data beyond the standard analytics.\u003c/p\u003e\n"],["\u003cp\u003eUtilizing the DataCapture policy allows for the collection of custom data, and it requires first creating a Data Collector REST resource that should have a name beginning with the prefix \u003ccode\u003edc_\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe DataCapture policy's \u003ccode\u003e<Collect>\u003c/code\u003e element specifies the data to be gathered, such as data within form parameters utilizing a corresponding flow variable reference.\u003c/p\u003e\n"],["\u003cp\u003eData collected using the DataCapture policy can be used for custom reporting by choosing the relevant Data Collector variable when selecting a metric for the custom report.\u003c/p\u003e\n"]]],[],null,["# Collecting custom data with the DataCapture policy\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\nIn addition to the [usual API data collected by Apigee](/apigee/docs/api-platform/analytics/analytics-services-overview#what-kind-of-data-is-collected-and-analyzed), you can also collect custom data\nusing the\n[DataCapture](/apigee/docs/api-platform/reference/policies/data-capture-policy)\npolicy. There are two main steps required, as described in the following sections:\n\n1. [Create a Data Collector REST resource](#create-a-data-collector-rest-resource).\n2. [Specify the data you want to collect](#specify-the-data-to-collect) using the DataCapture policy's `\u003cCollect\u003e` element.\n\n| **Note** :If you have an Apigee organization with Pay-as-you-go billing, you must enable the Apigee API Analytics add-on to use this policy. For more information, see [Manage the Apigee API Analytics add-on](/apigee/docs/api-platform/reference/manage-analytics-add-on).\n|\n| If you are unsure whether you are using a Subscription or Pay-as-you-go Apigee\n| organization, contact your Apigee organization administrator.\n\nCreate a Data Collector REST resource\n-------------------------------------\n\nTo use the `DataCapture` policy, you must first create a\n[Data Collector](/apigee/docs/reference/apis/apigee/rest#rest-resource:-v1.organizations.datacollectors) REST resource. To do so, send an API request like the following: \n\n```\ncurl -H \"Authorization: Bearer $(gcloud auth print-access-token)\" -X POST -H \"content-type:application/json\" \\\n -d '\n{\n \"name\": \"dc_my_custom_data\",\n \"description\": \"Collects data for analysis.\",\n \"type\": \"STRING\",\n}' \\\n \"https://apigee.googleapis.com/v1/organizations/$PROJECT_ID/datacollectors\"\n```\n\nThis creates a resource named `dc_my_custom_data`, which you can use with\nthe `DataCapture` policy.\n| **Notes:**\n|\n| - The name of the Data Collector resource must begin with the prefix `dc_`.\n| - If you use a Data Collector in multiple policies, the captured data will be overwritten by the last policy that executes.\n| **Warning:** Do *not* create two data collectors whose names differ only by case, such as `dc_my_data` and `dc_My_Data`, as then exporting data will result in a \"duplicate column names\" error.\n\nSpecify the data to collect\n---------------------------\n\nYou can specify the data to collect using the DataCapture policy's\n[`\u003cCollect\u003e`](/apigee/docs/api-platform/reference/policies/data-capture-policy#collect) element. There are various ways to do this, as shown in the\n[Examples](/apigee/docs/api-platform/reference/policies/data-capture-policy#examples)\nsection in the DataCapure reference page. One way is to specify a\n[flow variable](/apigee/docs/api-platform/reference/variables-reference),\nwhich stores data passed in API requests and responses. For example, you could collect data\nthat customers enter in a web page form using the flow\nvariable `message.formparam.`\u003cvar translate=\"no\"\u003eparam_name\u003c/var\u003e`.values`,\nwhere \u003cvar translate=\"no\"\u003eparam_name\u003c/var\u003e is the name of a parameter in the form. Suppose the form\nhas a parameter named `payment_amount`. The corresponding flow variable would be\n`message.formparam.payment_amount.values`.\n\nThe following code specifies this variable by the `ref` attribute\nof the `\u003cCollect\u003e` element. \n\n```scdoc\n\u003cDataCapture name=\"capturepayment\"\u003e\n \u003cCapture\u003e\n \u003cDataCollector\u003edc_my_custom_data\u003c/DataCollector\u003e\n \u003cCollect ref=\"message.form_param.payment_amount.values\" \u003e\n \u003c/Capture\u003e\n\u003c/DataCapture\u003e\n```\n\nWith this setting, the data entered in the form's `payment_amount` field will be\ncollected by DataCapture and stored in a variable named `dc_my_custom_data`.\n\nCreating a custom report from data collected with DataCapture\n-------------------------------------------------------------\n\nOnce you have set up data collection with the DataCapture policy, you can\nuse the data to create a custom report by the procedure described in\n[Adding a custom report](/apigee/docs/api-platform/analytics/create-custom-reports#add).\nTo do so, when you select a metric for\nthe report, as shown in [step 4 of the procedure](/apigee/docs/api-platform/analytics/create-custom-reports#step4), choose the variable that has the same name as the Data Collector\nREST resource you created for DataCapture---for example, `dc_my_custom_data`.\n\nYou can also use the same variable as a dimension in a custom report. Since dimensions\ngroup data by the values of the variable, it is\nusually preferable for the variable to be a string that only takes on a limited number of\nvalues."]]