How to customise the default GA4 engaged session definition in BigQuery

The calculation for engaged sessions above is based on the event user_engagement. To be more specific: when the string.value for parameter key session_engaged = '1'. The definition of engaged sessions, according to the GA4 user interface, is:

The number of sessions that lasted longer than 10 seconds, or had a conversion event, or had 2 or more screen or page views.

You can set a conversion event in the UI, but the definitions of session length or the amount of page views cannot be changed if you use the event user_engagement. But what if we want to customise the definition of an engaged session?

In this tutorial I'll show you how to create your own engaged session definition, that can be applied on your historical data too.