BIGQUERY — Count events

Andy Guliev
2 min readMar 13, 2021

How to quickly and most importantly simply count the number of events and, if necessary, the conversion between them in Bigquery?
And as a result, get such a wonderful table, with the sum of each of the events!

extremely simple piece of code, onion structure:

-- ( 3 ) Third piece of codeSELECT 
*,
end_quickplay/start_quickplay AS CR_to_end_quickPlay
FROM (
-- ( 2 ) Second piece of codeSELECT
SUM(start_quickplay) AS start_quickplay,
SUM(end_quickplay) AS end_quickplay
FROM(
-- ( 1 ) First piece of codeSELECT
user_pseudo_id,
event_name,
IF(event_name='level_start_quickplay', 1, 0) AS start_quickplay,
IF(event_name='level_end_quickplay', 1, 0) AS end_quickplay
FROM `firebase-public-project.analytics_153293282.events_20181003`
WHERE event_name='level_start_quickplay' OR
event_name='level_end_quickplay'
GROUP BY user_pseudo_id,
event_name
)
)

( 1 ) First piece of code

The first part of the code, here, depending on what event happened, put a “tick” in the appropriate column. For example, if the level_start_quickplay event has occurred, put ‘1’ in the column with the name below is the result obtained as a result of the work of this part of the code.

SELECT
user_pseudo_id,
event_name,
IF(event_name='level_start_quickplay', 1, 0) AS start_quickplay,
IF(event_name='level_end_quickplay', 1, 0) AS end_quickplay
FROM `firebase-public-project.analytics_153293282.events_20181003`
WHERE event_name='level_start_quickplay' OR
event_name='level_end_quickplay'
GROUP BY user_pseudo_id,
event_name

( 2 ) Second piece of code

This part of the code calculates the sum of each of the events

( 3 ) Third piece of code

And finally, the final part of the code, which wraps all the previous parts, is used to calculate the conversion. In this case, we are talking about the conversion from the beginning of the Quickplay (event — start_quickplay ) to the end (event — end_quickplay).

In our case, 85% of those who started finished the game.

An example is given on the basis of a public dataset:
firebase-public-project.analytics_153293282.events_*

--

--

Andy Guliev

DEEPWAVE AI LAB | Analyst - in a fun way of finding patterns