Im trying to use the google analytics api to automate some reporting I have to do but Im having trouble using multiple dimensions and metrics at one time. I basically want to get pageviews and the total number of events that occur on that page for ONLY ONE event category
Basically I want to get a df that looks something like this
page pageviews specific_events
xx.com 2330 193
xx2.com 1980 204
I can get the correct data when I don't apply the event category filter but as soon as I apply it, I no longer get the page metrics
sooo what im getting looks like the following:
page pageviews specific_events
xx.com 0 193
xx2.com 0 204
Im using the following request
'reportRequests': [
{
'viewId': VIEW_ID,
'dateRanges': [{'startDate': '90daysAgo', 'endDate': 'today'}],
'metrics': [{'expression': 'ga:pageviews'}, {'expression': 'ga:totalEvents'}],
'dimensions': [{'name': 'ga:pagePathlevel1'}, {'name': 'ga:eventCategory'}],
"orderBys": [
{
"orderType": "VALUE",
"sortOrder": "DESCENDING",
"fieldName": "ga:totalEvents"
}
],
"dimensionFilterClauses": [
{
"filters": [
{
"dimensionName": "ga:eventCategory",
"operator": "EXACT",
"not": "true",
"expressions": ["specific_events"]
}
]
}
],
"pageSize": 10
}
]
}
I guess, I could send two requests the API, and the merge on the pagepath dimension but it would be better if I can just do it with one request.
Am I doing something wrong or is this not possible?
Events by definition are not page views. This means that an Event dimension (i.e. category) can't have page view metrics (i.e. pageviews), because that information does not relate to the specific event.
So you have to do two reports, and merge them on pagePath dimension.