Skip to content

Conversion between each funnel step

The task

The shopping app has a four step funnel, in this order:

  1. view_item
  2. add_to_cart
  3. begin_checkout
  4. purchase

A user is counted at a step when they have fired that step's event at least once and have also fired the events of every earlier step. The order of the events in time does not matter for this question, and the sessions do not have to match.

Return one row per step (four rows):

  • step_number: 1 to 4
  • step: the event name
  • users: how many users are counted at that step
  • pct_of_previous: users as a percentage of the users at the step before, rounded to 1 decimal place. For step 1 use 100.0. NULL when the step before has no users.
  • pct_of_first: users as a percentage of the users at step 1, rounded to 1 decimal place. NULL when step 1 has no users.

Sort by step_number.

Expected output

step_numberstepuserspct_of_previouspct_of_first
  • Sorted by step_number ascending.
  • Numbers rounded to 1 decimal place.
  • Checked on the sample and on 3 hidden datasets. How grading works

Tables Mobile shopping app · click a name to insert it

users360 rows in the sample

One row per user. Key: user_id.

intUnique id.
timestampSign-up time (UTC).
textTwo-letter country code.
textios, android or web.
textorganic, paid, referral or partner. NULL when unknown.
events7,616 rows in the sample

One row per tracked event. Key: event_id.

bigintUnique id.
intWho fired it.
textapp_open, search, view_item, add_to_cart, begin_checkout, purchase or share.
timestampWhen (UTC).
textSession the event belongs to. NULL for a few events sent from the background.
numeric(10,2)Order value for purchase events, NULL otherwise.
experiment_assignments349 rows in the sample

Which variant each user saw in each experiment. Key: user_id, experiment.

intThe user.
textnew_onboarding or one_tap_checkout.
textcontrol or treatment.
timestampWhen the user was assigned (UTC).

Related questions

Loading the editor and PostgreSQL