試用 Google Analytics 的 MCP 伺服器。從
GitHub 安裝,詳情請參閱
公告。
建立目標對象匯出作業
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google Analytics 中的目標對象可讓您根據自家業務的需求區隔使用者。您可以使用目標對象,根據共用屬性將網站或應用程式的使用者分組。
您可以使用 Data API 匯出目標對象,包括使用者的快照。
如要進一步瞭解目標對象匯出資料的預期內容,請參閱目標對象匯出資料預期內容指南。
總覽
提出下列 Data API 要求,即可建立及查詢目標對象匯出作業:
- 呼叫
audienceExports.create
方法,建立目標對象匯出作業。
- 呼叫
audienceExports.query
方法,用於擷取目標對象中的使用者。
如需更多資訊,您可以呼叫 audienceExports.get
來擷取特定目標對象匯出作業的設定中繼資料,並呼叫 audienceExports.list
來列出特定資源的所有目標對象匯出作業。
選取報表實體
所有 Data API 方法都需要在網址要求路徑中指定 Google Analytics 資源 ID,格式為 properties/GA_PROPERTY_ID
。範例如下:
POST https://analyticsdata.googleapis.com/v1beta/properties/GA_PROPERTY_ID/audienceExports
報表會根據指定 Google Analytics 資源中收集到的 Google Analytics 事件資料產生。
如果您使用的是其中一種 Data API 用戶端程式庫,就不需要變更要求網址路徑。大多數 API 用戶端都會提供 property
參數,該參數會預期 properties/GA_PROPERTY_ID
格式的字串。如需用戶端程式庫的使用範例,請參閱快速入門指南。
建立目標對象匯出作業
如要建立目標對象匯出作業,請使用要求中的 AudienceExport
物件呼叫 audienceExports.create
方法。以下是必要參數:
以下是建立目標對象匯出作業的範例要求:
HTTP 要求
POST https://analyticsdata.googleapis.com/v1beta/properties/1234567/audienceExports
{
"audience": "properties/1234567/audiences/12345",
"dimensions": [
{
"dimensionName": "deviceId"
}
]
}
audienceExports.create
方法的回應會在 name
欄位中包含目標對象匯出項目的名稱,例如 properties/1234567/audienceExports/123
。以下是回覆範例:
HTTP 回應
{
"response": {
"@type": "type.googleapis.com/google.analytics.data.v1alpha.AudienceExport",
"name": "properties/1234567/audienceExports/123",
"audience": "properties/1234567/audiences/12345",
"audienceDisplayName": "Purchasers",
"dimensions": [
{
"dimensionName": "deviceId"
}
],
"state": "CREATING",
"beginCreatingTime": "2023-06-22T23:35:28.787910949Z"
}
}
您可以使用 name
查詢目標對象匯出資料中的使用者。
查詢目標對象匯出作業的完備性狀態
audienceExports.create
呼叫後,系統可能需要幾分鐘的時間才能產生目標對象匯出作業。
您可以呼叫 audienceExports.get
方法,檢查目標對象匯出的就緒狀態。
請使用 audienceExports.create
回應中的目標對象匯出名稱,在要求中指定目標對象匯出作業。
以下是範例要求:
HTTP 要求
GET https://analyticsdata.googleapis.com/v1beta/properties/1234567/audienceExports/123
回應的 state
欄位會傳回目標對象匯出作業的準備就緒狀態。目標對象匯出作業完成後,其狀態會從 CREATING
變更為 ACTIVE
。
以下是回覆範例:
HTTP 回應
{
"name": "properties/1234567/audienceExports/123",
"audience": "properties/1234567/audiences/12345",
"audienceDisplayName": "Purchasers",
"dimensions": [
{
"dimensionName": "deviceId"
}
],
"state": "CREATING",
"beginCreatingTime": "2023-06-22T23:35:28.787910949Z"
}
您可以呼叫 audienceExports.list
方法,取得所有目標對象匯出作業的狀態。
從匯出的目標對象中擷取使用者
產生目標對象匯出作業後,請呼叫 audienceExports.query
方法,並在要求中指定目標對象匯出作業的 name
。
以下是要求範例:
HTTP 要求
POST https://analyticsdata.googleapis.com/v1beta/properties/1234567/audienceExports/123:query
如果目標對象匯出作業已就緒,這個呼叫就會傳回目標對象中的使用者清單。
以下是回覆範例:
HTTP 回應
{
"audienceExport": {
"name": "properties/1234567/audienceExports/123",
"audience": "properties/1234567/audiences/12345",
"audienceDisplayName": "Purchasers",
"dimensions": [
{
"dimensionName": "deviceId"
}
],
"state": "ACTIVE",
"beginCreatingTime": "2023-06-22T23:35:28.787910949Z"
},
"audienceRows": [
{
"dimensionValues": [
{
"value": "1000276123.1681742376"
}
]
},
{
"dimensionValues": [
{
"value": "1000374452.1668627377"
}
]
},
{
"dimensionValues": [
{
"value": "1000391956.1652750758"
}
]
},
{
"dimensionValues": [
{
"value": "1000410539.1682018694"
}
]
},
{
"dimensionValues": [
{
"value": "1000703969.1666725875"
}
]
}
],
"rowCount": 5
}
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003eGoogle Analytics Audiences allows you to segment users based on shared attributes, enabling targeted analysis and marketing efforts.\u003c/p\u003e\n"],["\u003cp\u003eYou can export audience data, including user snapshots, using the Data API, specifically the \u003ccode\u003eaudienceExports.create\u003c/code\u003e and \u003ccode\u003eaudienceExports.query\u003c/code\u003e methods.\u003c/p\u003e\n"],["\u003cp\u003eBefore querying, you should check the audience export's readiness state using the \u003ccode\u003eaudienceExports.get\u003c/code\u003e method to ensure data is available.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eaudienceExports.list\u003c/code\u003e method lets you view all your audience exports for a given property, while \u003ccode\u003eaudienceExports.query\u003c/code\u003e retrieves the actual user data.\u003c/p\u003e\n"]]],["Google Analytics audiences can be segmented and exported via the Data API. To export, first, call `audienceExports.create` with a valid audience name and dimensions. Then, use `audienceExports.get` to check the export's readiness (`CREATING` or `ACTIVE`). Once `ACTIVE`, retrieve users with `audienceExports.query` using the export's name. You can use `audienceExports.list` to view all exports and use the format `properties/GA_PROPERTY_ID` when specifying the property ID.\n"],null,["# Create an audience export\n\n[Audiences in Google Analytics](//support.google.com/analytics/answer/9267572)\nlet you segment your users in the ways that are important to your business. With\naudiences, you can group users of your site or application based on shared\nattributes.\n\nYou can export your audiences, including a snapshot of their users, using the\n[Data API](/analytics/devguides/reporting/data/v1/rest).\n\nRefer to the [Audience export data expectations](/analytics/devguides/reporting/data/v1/audience-export-expectations)\nguide for important information about the data you see in audience exports.\n\nOverview\n--------\n\nMake the following Data API requests to create and query an audience export:\n\n1. Call the [`audienceExports.create`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports/create) method to create an audience export.\n2. Call the [`audienceExports.query`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports/query) method is used to retrieve the users in the audience.\n\nFor more information, you can call\n[`audienceExports.get`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports/get) to\nretrieve configuration metadata about a specific audience export, and\n[`audienceExports.list`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports/list) to\nlist all your audience exports for a specific property.\n\nSelect a reporting entity\n-------------------------\n\nAll Data API methods require the [Google Analytics property\nidentifier](/analytics/devguides/reporting/data/v1/property-id) to be specified inside a URL request path, in the\nform of `properties/GA_PROPERTY_ID`. Here's an example: \n\n POST https://analyticsdata.googleapis.com/v1beta/properties/GA_PROPERTY_ID/audienceExports\n\nThe report is generated based on the Google Analytics event data collected in\nthe specified Google Analytics property.\n\nIf you're using one of the [Data API client libraries](/analytics/devguides/reporting/data/v1/client-libraries), you\ndon't need to change the request URL path. Most API clients provide a `property`\nparameter that expects a string in the form of `properties/GA_PROPERTY_ID`. See\n[Quick start guide](/analytics/devguides/reporting/data/v1/quickstart-client-libraries) for examples of using the\nclient libraries.\n\nCreate an audience export\n-------------------------\n\nTo create an audience export, call the [`audienceExports.create`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports/create) method using the\n[`AudienceExport`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports#AudienceExport)\nobject in your request. The following parameters are required:\n\n- A valid audience name in the [`audience`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports#AudienceExport.FIELDS.audience) field, formatted as `properties/{propertyId}/audiences/{audienceId}`. You can use the [`audiences.list`](/analytics/devguides/config/admin/v1/rest/v1alpha/properties.audiences/list) method of the Google Analytics Admin API v1 to obtain this value. The [`Audience.name`](/analytics/devguides/config/admin/v1/rest/v1alpha/properties.audiences#Audience.FIELDS.name) field of the `audiences.list` response contains the audience name.\n- A valid list of dimensions in the [`dimensions`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports#AudienceExport.FIELDS.dimensions) field. The list of dimensions supported by this method can be found in the [Audience export schema](/analytics/devguides/reporting/data/v1/audience-export-api-schema) documentation. Only the data for dimensions mentioned in this field is included in an audience export.\n\nHere's a sample request to create an audience export: \n\n### HTTP Request\n\n POST https://analyticsdata.googleapis.com/v1beta/properties/1234567/audienceExports\n {\n \"audience\": \"properties/1234567/audiences/12345\",\n \"dimensions\": [\n {\n \"dimensionName\": \"deviceId\"\n }\n ]\n }\n\nA response of the `audienceExports.create` method contains the audience export's\nname in the `name` field, for example `properties/1234567/audienceExports/123`.\nHere's a sample response: \n\n### HTTP Response\n\n {\n \"response\": {\n \"@type\": \"type.googleapis.com/google.analytics.data.v1alpha.AudienceExport\",\n \"name\": \"properties/1234567/audienceExports/123\",\n \"audience\": \"properties/1234567/audiences/12345\",\n \"audienceDisplayName\": \"Purchasers\",\n \"dimensions\": [\n {\n \"dimensionName\": \"deviceId\"\n }\n ],\n \"state\": \"CREATING\",\n \"beginCreatingTime\": \"2023-06-22T23:35:28.787910949Z\"\n }\n }\n\nYou can use the `name` to query the users from the audience export.\n\nQuery the audience export's readiness state\n-------------------------------------------\n\nIt might take several minutes to generate the audience export after the\n[`audienceExports.create`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports/create)\ncall.\n\nYou can check the readiness state of an audience export by calling the\n[`audienceExports.get`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports/get) method.\n\nUse the audience export name from an `audienceExports.create` response to\nspecify the audience export in your request.\n\nHere's a sample request: \n\n### HTTP Request\n\n GET https://analyticsdata.googleapis.com/v1beta/properties/1234567/audienceExports/123\n\nThe readiness state for an audience export is returned in the [`state`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports#AudienceExport.FIELDS.state) field\nof the response. Once the audience export generation is complete, its state\nchanges from `CREATING` to `ACTIVE`.\n\nHere's a sample response: \n\n### HTTP Response\n\n {\n \"name\": \"properties/1234567/audienceExports/123\",\n \"audience\": \"properties/1234567/audiences/12345\",\n \"audienceDisplayName\": \"Purchasers\",\n \"dimensions\": [\n {\n \"dimensionName\": \"deviceId\"\n }\n ],\n \"state\": \"CREATING\",\n \"beginCreatingTime\": \"2023-06-22T23:35:28.787910949Z\"\n }\n\nYou can obtain the state of all audience exports by calling the\n[`audienceExports.list`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports/list)\nmethod.\n\nRetrieve users from an audience export\n--------------------------------------\n\nOnce the audience export is generated, call the [`audienceExports.query`](/analytics/devguides/reporting/data/v1/rest/v1beta/properties.audienceExports/query) method, and specify the\naudience export's `name` in the request.\n\nHere's a sample request: \n\n### HTTP Request\n\n POST https://analyticsdata.googleapis.com/v1beta/properties/1234567/audienceExports/123:query\n\nIf the audience export is ready, this call returns the list of users in the\naudience.\n\nHere's a sample response: \n\n### HTTP Response\n\n {\n \"audienceExport\": {\n \"name\": \"properties/1234567/audienceExports/123\",\n \"audience\": \"properties/1234567/audiences/12345\",\n \"audienceDisplayName\": \"Purchasers\",\n \"dimensions\": [\n {\n \"dimensionName\": \"deviceId\"\n }\n ],\n \"state\": \"ACTIVE\",\n \"beginCreatingTime\": \"2023-06-22T23:35:28.787910949Z\"\n },\n \"audienceRows\": [\n {\n \"dimensionValues\": [\n {\n \"value\": \"1000276123.1681742376\"\n }\n ]\n },\n {\n \"dimensionValues\": [\n {\n \"value\": \"1000374452.1668627377\"\n }\n ]\n },\n {\n \"dimensionValues\": [\n {\n \"value\": \"1000391956.1652750758\"\n }\n ]\n },\n {\n \"dimensionValues\": [\n {\n \"value\": \"1000410539.1682018694\"\n }\n ]\n },\n {\n \"dimensionValues\": [\n {\n \"value\": \"1000703969.1666725875\"\n }\n ]\n }\n ],\n \"rowCount\": 5\n }"]]