In Google Analytics BigQuery, the following query tries to aggregate information both at the sessions
and at the hits
level
SELECT
visitId,
trafficSource.source as source,
trafficSource.medium as medium,
device.browser as browser,
min(hits.hour) as firstHitHour,
boolean(count(hits.eventInfo.eventCategory = "SomeValue")) as hasSomeValue
FROM
[my-table.ga_sessions_20150216]
GROUP BY
visitId, source, medium, browser;
The line boolean(count(hits.eventInfo.eventCategory = "SomeValue")) as hasSomeValue
is intended to be true
if, among all the hits of a row's session, at least one hit has the hits.eventInfo.eventCategory
equal to SomeValue
.
The expected results look like:
sessionId source medium browser firstHitHour hasSomeValue
--------------------------------------------------------------------------------------
12318 google cpc firefox 12 true
13317 google organic safari 14 null
13551 bing organic firefox 14 true
13610 orange display chrome 14 true
14381 stackoverflow referral safari 15 false
14422 google organic chrome 15 true
However, the line mentioned above doesn't seem to work. Even if I put some dumb value, for instance hits.eventInfo.eventCategory = "Blablablabla"
, it will output true
for some rows anyway (whereas obviously no hit has this dumb value).
Actually, the instruction count(hits.eventInfo.eventCategory = "Blablablabla")
- without the boolean()
returns seemingly random results (have nothing in common with the actual counts).
What should this line be to trigger the correct output?