kidar2
kidar2

Reputation: 133

How to get a list of available metrics and dimensions for use with the Google analytics API

There are several metrics and dimensions - let it be a list.

For example:

Year dimension and New Session measure.

How to get a list of available metrics and dimensions for this list via Google Analytics API java SDK V3 so that the error does not fall

"Selected dimensions and metrics cannot be queried together"?

Upvotes: 2

Views: 5358

Answers (2)

kidar2
kidar2

Reputation: 133

Sulution: take json from here https://ga-dev-tools.appspot.com/ga_cubes.json - this is a list of cubes. For each cube it contains the set of dimensions and metrics that it consists of.

The algorithm is as follows: We run through the List (for example Year dimension and New Session measure), and look if at least one of these cubes has all the dimensions and metrics from the list, then such metrics and dimensions are compatible, otherwise not.

So it works in https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/

However, it is worth considering that some metrics work together only when there is an additional dimension. For example: ga:14dayUsers, ga:newUsers works only with days dimension.

Upvotes: 0

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117301

Dimensions and metrics list

How to get a list of available metrics and dimensions for this list via Google Analytics API .

The first thing you need to understand is that the Google Analytics Core reporting API and the Google Analytics reporting APIs. Only return the data from within Google analytics. Neither has the power to return to you a list of dimensions and metrics.

To get a list of Dimensions and metrics that can be used in these APIs you should look at the Meta data api . It returns a list of all the dimensions and metrics that can be used with the Google Analytics APIs to query Google analytics data.

Example

GET https://www.googleapis.com/analytics/v3/metadata/ga/columns

Invalid dimension and metric reference.

"Selected dimensions and metrics cannot be queried together"?

Message means that some metrics and dimensions just cant be queried together because there isnt the proper data relation between them. There is no api that will tell you which dimensions and metrics can be queried together.

You have two options:

  1. You can use the Dimensions & Metrics Explorer to check which dimensions and metrics can be used together they will be grayed out if they cant be used together.
  2. You can just make a request as you have and check for an error.

Upvotes: 5

Related Questions