Requires authorization
Lists custom metrics to which the user has access. Try it now or see an example.
Request
HTTP request
GET https://www.googleapis.com/analytics/v3/management/accounts/accountId/webproperties/webPropertyId/customMetrics
Parameters
Parameter name | Value | Description |
---|---|---|
Path parameters | ||
accountId |
string |
Account ID for the custom metrics to retrieve. |
webPropertyId |
string |
Web property ID for the custom metrics to retrieve. |
Optional query parameters | ||
max-results |
integer |
The maximum number of custom metrics to include in this response. |
start-index |
integer |
An index of the first entity to retrieve. Use this parameter as a pagination mechanism along with the max-results parameter. |
Authorization
This request requires authorization with at least one of the following scopes (read more about authentication and authorization).
Scope |
---|
https://www.googleapis.com/auth/analytics.readonly |
https://www.googleapis.com/auth/analytics |
Request body
Do not supply a request body with this method.
Response
If successful, this method returns a response body with the following structure:
{ "kind": "analytics#customMetrics", "username": string, "totalResults": integer, "startIndex": integer, "itemsPerPage": integer, "previousLink": string, "nextLink": string, "items": [ management.customMetrics Resource ] }
Property name | Value | Description | Notes |
---|---|---|---|
kind |
string |
Collection type. | |
username |
string |
Email ID of the authenticated user | |
totalResults |
integer |
The total number of results for the query, regardless of the number of results in the response. | |
startIndex |
integer |
The starting index of the resources, which is 1 by default or otherwise specified by the start-index query parameter. | |
itemsPerPage |
integer |
The maximum number of resources the response can contain, regardless of the actual number of resources returned. Its value ranges from 1 to 1000 with a value of 1000 by default, or otherwise specified by the max-results query parameter. | |
previousLink |
string |
Link to previous page for this custom metric collection. | |
nextLink |
string |
Link to next page for this custom metric collection. | |
items[] |
list |
Collection of custom metrics. |
Examples
Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).
Java
Uses the Java client library.
/** * Note: This code assumes you have an authorized Analytics service object. */ /** * This request lists all custom metrics for the authorized user. */ try { CustomMetrics metrics = analytics.management.customMetrics .list("12345", "UA-12345-1").execute(); } catch (GoogleJsonResponseException e) { System.err.println("There was a service error: " + e.getDetails().getCode() + " : " + e.getDetails().getMessage()); } /** * The results of the list method are stored in the metrics object. * The following code shows how to iterate through them. */ for (CustomMetric metric : metrics.getItems()) { System.out.println("Metric Kind: " + metric.getKind()); System.out.println("Metric Id: " + metric.getId()); System.out.println("Account ID: " + metric.getAccountId()); System.out.println("Property ID: " + metric.getWebPropertyId()); System.out.println("Metric Name: " + metric.getName()); System.out.println("Metric Index: " + metric.getIndex()); System.out.println("Metric Scope: " + metric.getScope()); System.out.println("Metric Active: " + metric.getActive()); System.out.println("Metric Type: " + metric.getType()); System.out.println("Metric Created: " + metric.getCreated()); System.out.println("Metric Updated: " + metric.getUpdated()); }
Python
Uses the Python client library.
# Note: This code assumes you have an authorized Analytics service object. # This request lists all custom metrics for the authorized user. try: metrics = analytics.management().customMetrics().list( accountId='123456', webPropertyId='UA-123456-1', ).execute() except TypeError, error: # Handle errors in constructing a query. print 'There was an error in constructing your query : %s' % error except HttpError, error: # Handle API errors. print ('There was an API error : %s : %s' % (error.resp.status, error.resp.reason)) # The results of the list method are stored in the metrics object. # The following code shows how to iterate through them. for metric in metrics.get('items', []): print 'Metric Kind = %s' % metric.get('kind') print 'Metric Id = %s' % metric.get('id') print 'Account ID = %s' % metric.get('accountId') print 'Property ID = %s' % metric.get('webPropertyId') print 'Metric Name = %s' % metric.get('name') print 'Metric Index = %s' % metric.get('index') print 'Metric Scope = %s' % metric.get('scope') print 'Metric Active = %s' % metric.get('active') print 'Metric Type = %s' % metric.get('type') print 'Metric Created = %s' % metric.get('created') print 'Metric Updated = %s' % metric.get('updated')
Try it!
Use the APIs Explorer below to call this method on live data and see the response. Alternatively, try the standalone Explorer.