-
Transforming a Flat BigQuery Table into a Nested GA4 Structure
I managed to nest event category values, but I hit a snag when attempting to create key-value pairs for event action and event label. It’s like trying to match the array structure in GA4 raw sessions, but I just can’t quite get there.
You can see how far I’ve got: https://prnt.sc/3FhZgd7IOmVV
Ultimately, I’m aiming to make the event action label look like this: https://prnt.sc/pT5AOhL7q9S8Here’s an example: I’ve created a flat table, but how do I give it the shape I’m after?
with test as ( select 123 cid, "sports" ec, "load" ea, "module" el union all select 123,"marquee","load","home" union all select 125,"bet_add","sports","football" union all select 126, "bet_place","games","tennis" ) select cid, array_agg(struct(ec,ea,el)) as events from test group by 1
Take another look: I’ve built another flat table just like the last one. But how do I reshape it into the format I want?
with test as ( select 123 cid, "sports" ec, "load" ea, "module" el union all select 123,"marquee","load","home" union all select 125,"bet_add","sports","football" union all select 126, "bet_place","games","tennis" ) select cid, array_agg(struct(ec,ea,el)) as events from test group by 1
Log in to reply.