Retrieving event data from A/B tests in Firebase, using BigQuery

Tue, 27 November 2018

experiment_cohorts.sql
  SELECT
    "My a/b test name" AS experimentName,
    CASE userProperty.value.string_value
      -- These are the same order as entered/viewed in Firebase
      WHEN "0" THEN "Control group"
      WHEN "1" THEN "Test Group 1"
      WHEN "2" THEN "Test Group 2"
    END AS experimentVariant,
    event_name as eventName,
    COUNT(*) AS numberEvents,
    COUNT(DISTINCT user_pseudo_id) AS numberUsers
  FROM
    `analytics_XXXXXXXXX.events_*`,
      UNNEST(user_properties) AS userProperty
  WHERE
    _TABLE_SUFFIX >= '20180101'
    AND userProperty.key = "firebase_exp_1"
    AND event_name IN ("first_open", "session_start")
  GROUP BY
    experimentVariant, eventName