I'm querying the Google Analytics API, and got a question about combining different dimension and metric scopes. Is it possible to combine a user-level dimension like "Device Category" with a hit-level metric, i.e. "Unique Pageviews"?
I know I can't combine hit-level dimensions like "Page" with session-level metrics like "Sessions". But I can't seem to find any documentation of other combinations.
My gut tells me it should be possible as user-level dimensions are stored in a cookie and then be associated with each hit. But I'd really like to get a second opinion on this.
You can identify valid combinations of dimensions and metrics with Dimensions & Metrics Explorer tool:
https://ga-dev-tools.appspot.com/dimensions-metrics-explorer/
Since not all dimensions and metrics can be queried together, with this tool you can select a dimension or metric checkbox to see all the other values that can be combined in the same query.
[EDIT]
If your request is which dimensions and metrics may be misleading when combining, the answer is... depends on the result you want to obtain and on knowing how to recognize the data. If you want to know which pages are most viewed when a user lands in a specific landing page, you can do this by querying landing pages dimension and page dimension. You will have repeated the landing page many times in the reports (many times how many pages have been viewed from sessions originating in that landing) but this does not mean that it is wrong. Sure depending on what you combine you can get a misleading result, but Google Analytics cannot know if it is misleading for you or if you wanted to do it.
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"?
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:
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.
You can just make a request as you have and check for an error.
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.
I have added some custom dimensions via dataLayer (GTM). Now I'm creating reports in data studio and want to see unique purchases, revenue and conversion rate of these custom dimensions. I'm using ecommerce to track purchases. When I add one of my custom dimension as dimension and unique purchases as metric to create report, it gives me nothing. What should I do to have the report I want?
Have a look at this.
You're most likely pairing dimensions and metrics of incompatible scopes together. The scope of of the custom dimension always needs to be "wider" than the scope of the custom metric.
Can i create custom dimension or metric with google analytics Management API? (Or other API...)
On January 23, 2015 the Google Analytics team released a change allowing for the creating of custom dimensions and metrics via the Management API.
Custom dimensions and metrics in the Management API allow you to create, get, list, update and patch custom dimensions and metrics for a Google Analytics property.
It is split up into two sections of the api Custom dimensions and custom metrics.
Not sure what language you where using so I cant help you with any sample code. I suggest you check the documentation.
Nope. Full reference for the Management API is here.
It doesn't include custom dimensions. Would be nice though, I agree.
The Provisioning API lets you create accounts, but that is in closed beta to AdWords partners at the moment. But however an account is created, the Management API is the one that lets you edit features such as filters at the moment, so would be where custom dimensions/metric control should also sit when available.
The collection APIs then let you send data to your custom metrics and dimensions once you have created them in the admin section of your web property.
Custom Dimensions and Metrics can be created in php for sure https://github.com/google/google-api-php-client
$dimension = new Google_Service_Analytics_CustomDimension();
$dimension->setName('[name]');
$dimension->setScope('[scope]');
$dimension->setActive(TRUE);
$client->management_customDimensions->insert('[webPropertyId]', '[analytics-account]', $dimension);
"$client->management_customMetrics" can be used in a similar way for metrics.
Gathering Data
In order to send data Google provides collection APIs and SDKs.
Configuring Accounts
Google Analytics provides programmatic access and management to configuration data through the Management API and account creation capabilities through the Provisioning API.
Reading Data
Google Analytics provides a simple and powerful APIs to retrieve report data from Google Analytics.
To answer the OP: you create custom dimensions and metrics via the collection API.
Dimensions: Describe data
A dimension is a descriptive attribute or characteristic of an object that can be given different values. For example, a geographic location could have dimensions called Latitude, Longitude, or City Name. Values for the City Name dimension could be San Francisco, Berlin, or Singapore.
Browser, Exit Page, Screens, and Session Duration are all examples of dimensions that appear by default in Google Analytics. Dimensions appear all of your reports, though you might see different ones depending on the specific report. Use them to help organize, segment, and analyze your data. In some reports, you can add and remove dimensions to see different aspects of your data.
Metrics: Measure data
Metrics are individual elements of a dimension that can be measured as a sum or a ratio. For example, the dimension City can be associated with a metric like Population, which would have a sum value of all the residents of the specific city.
Screenviews, Page per Session, and Average Session Duration are examples of metrics in Google Analytics.
Dimensions vs Metrics: What’s the difference?
Definitions: Goals, Metrics, KPIs, Dimensions, Targets
Does anyone know if the Google Analytics API exposes the compatibility data for selecting a set of dimensions and measures? For example, if I select the "ga:adGroup" dimension, then I can't select any of the Goal Completion dimensions. This compatibility seems to be based upon the data cubes that are defined in Google.
Is this list of what dimensions and measures are compatible with each other programmatically available from the Google API?