I'm trying to export a Google Anlaytics custom dimension on hit level and some events from BigQuery. So far, the custom dimension export isn't working.
I'm using LegacySQL on that. Cause this is part of a bigger Query, I don't want to switch to StandardSQL at this point.
SELECT
clientId,
totals.timeOnSite,
hits.page.pagePath,
MAX(IF(customDimensions.index=1, customDimensions.value, NULL)) WITHIN
customDimensions AS cd1,
trafficSource.source,
SUM(COUNT(CASE WHEN (hits.eventInfo.eventCategory = 'Download' AND hits.type
= 'EVENT' AND hits.eventInfo.eventAction = 'pdf') THEN
hits.eventInfo.eventAction END)) AS Downloads,
SUM(COUNT(CASE WHEN (hits.eventInfo.eventLabel = 'search-header' OR
hits.eventInfo.eventLabel = 'search-mainpage') AND hits.type = 'EVENT' THEN
hits.eventInfo.eventLabel END)) AS Search,
FROM TABLE_DATE_RANGE([xxxxxx.ga_sessions_],
TIMESTAMP('2018-11-25'), TIMESTAMP('2018-11-25')) WHERE hits.page.pagePath LIKE '%xyz%'
GROUP BY 1,2,3,4,5
LIMIT 100;
The Query fails and shows me "Error: Invalid mixture of scoped and unscoped aggregation functions" Any thoughts on how to solve this? Kind regards!