FUNNELCOUNT

This section contains reference documentation for the FUNNELCOUNT function.

Funnel analytics aggregation function.

Returns array of distinct correlated counts for each funnel step.

Signature

FUNNEL_COUNT (

STEPS ( predicate1, predicate2 ... ),

CORRELATED_BY ( correlation_column ),

SETTINGS ( setting1, setting2 ... ) )

Usage Examples

Many datasets are time series in nature, tracking events of an entity over time. An example of such a dataset could be a user analytics activity log from a commerce web application.

Example

Funnel

We want to analyse the following checkout funnel:

  • /cart/add

  • /checkout/start

  • /checkout/confirmation

Counts

We want to answer the following questions about the above funnel:

  • How many users entered the top of the funnel?

  • How many of these users proceeded to the second step?

  • How many users reached the bottom of the funnel after completing all steps?

Query

select 
  FUNNEL_COUNT(
    STEPS(
      url = '/cart/add', 
      url = '/checkout/start', 
      url = '/checkout/confirmation'),
    CORRELATED_BY(user_id)
  ) AS counts
from user_log 

Notes

Notice that although U1 user added to cart twice, it still counted as one conversion in the first step, as we report on unique counts rather than total events. Also notice that although U2 events were logged out of order, we still counted the user as converted.

Equivalence

The above query is equivalent to the below presto SQL query:

select 
   ARRAY[
     count_if(steps[1]),
     count_if(steps[1] and steps[2]),
     count_if(steps[1] and steps[2] and steps[3])
   ] as counts
 from (
   select 
     ARRAY[
       bool_or(url = '/cart/add'),
       bool_or(url = '/checkout/start'),
       bool_or(url = '/checkout/confirmation')
     ] as steps
   from user_log
   group by user_id
 )

Settings

For a large dataset we could use for example a theta_sketch strategy, or furthermore, partition the data by user_id and leverage a partitioned strategy. It is also important to filter in the where clause so to aggregate only necessary rows.

select 
  FUNNEL_COUNT(
    STEPS(
      url = '/cart/add', 
      url = '/checkout/start', 
      url = '/checkout/confirmation'),
    CORRELATED_BY(user_id),
    SETTINGS('theta_sketch', 'nominalEntries=4096')
  ) AS counts
from user_log 
where url in ('/cart/add', '/checkout/start', '/checkout/confirmation')

Another Example

We now want to learn how many users checkout after a text search; as opposed to other entry points such as browsing a product category listing. We want to then analyse the following funnel:

  • /product/search

  • /cart/add

  • /checkout/start

  • /checkout/confirmation

Query

select 
  FUNNEL_COUNT(
    STEPS(
      url = '/product/search',
      url = '/cart/add', 
      url = '/checkout/start', 
      url = '/checkout/confirmation'),
    CORRELATED_BY(user_id)
  ) AS counts
from user_log 

Notes

Notice that U1 is not counted in this funnel, as the user did not perform any product search. Both U2 and U3 entered the top of the funnel and performed the second step, but only U2 converted to the bottom of the funnel.