[[["わかりやすい","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."]]