问题
Pulling data from google analytics using google-api npm.
When I tried query for a particular date 2020-05-01 using Query Explorer , total user is 204.
When adding medium ga:medium
the total count is 205.
I'm querying with
source,medium,pagePath,channelGrouping,deviceCategory,and date as dimensions.
So the total users count is near to 300. I'm saving the data from response of this query.
I need to to show the total user for a day. How can I handle this?
Query is below
const res = await analyticsreporting.reports.batchGet({
requestBody: {
reportRequests: [
{
viewId: defaultProfileId,
dateRanges: dateRanges,
includeEmptyRows: false,
'pageSize': 10000,
metrics: [
{
expression: 'ga:users',
},
{
expression: 'ga:sessions',
},
{
expression: 'ga:bounces',
},
{
expression: 'ga:avgSessionDuration',
},
{
expression: 'ga:pageviews',
},
{
expression: 'ga:newUsers',
},
{
expression: 'ga:sessionDuration',
},
{
expression: 'ga:pageviewsPerSession',
},
{
expression: 'ga:bounceRate',
},
{
expression: 'ga:goalCompletionsAll',
},
],
dimensions: [
{
name: 'ga:source'
},
{
name: 'ga:medium'
},
{
name: 'ga:pagePath'
},
{
name: 'ga:channelGrouping'
},
{
name: 'ga:deviceCategory'
},
{
name: 'ga:date'
}
]
},
],
},
});
回答1:
Google analytics is a multidimensional database.
A multidimensional database is created from multiple relational databases. While relational databases allow users to access data in the form of queries, the multidimensional databases allow users to ask analytical questions related to business or market trends.
The multidimensional databases uses MOLAP (multidimensional online analytical processing) to access its data. They allow the users to quickly get answers to their requests by generating and analyzing the data rather quickly.
The data in multidimensional databases is stored in a data cube format. This means that data can be seen and understood from many dimensions and perspectives.
The way this works is that it analyzes on the dimensions that you are requesting. and gives you a response. You cant analyze on two unrelated things and expect the same results. The only way you would get the result back would be if they have the exact same dimensions.
You can compare apples and get a total count of apples but what if there one of the apples is not labels apple what if its labels granny smith well thats not going to be included because it doesn't have the label apple.
Issues come in Google analytics when data is missing if your data doesn't have a dimension called medium for a record and its null then that is not going to be included in your request because the data doesn't exist.
Again this isnt a relational database you cant treat it as such.
来源:https://stackoverflow.com/questions/62019714/why-google-analytics-query-response-total-user-count-varying-with-dimensions