Giter Site home page Giter Site logo

styleshare / bigquery-firebase-funnel-builder Goto Github PK

View Code? Open in Web Editor NEW
19.0 28.0 8.0 2 KB

A Python script that builds a funnel for Google BigQuery with Firebase Analytics.

License: MIT License

Python 100.00%
python bigquery firebase funnel sql query data-processing

bigquery-firebase-funnel-builder's Introduction

BigQuery Firebase Funnel Builder

A Python script that builds a funnel for Google BigQuery with Firebase Analytics.

example-funnel

Usage

$ python funnel.py
USAGE:
    python funnel.py table_name event_name_0 event_name_1 ...

EXAMPLE:
    python funnel.py com_myapp_IOS.app_events_* sign_up add_to_cart purchase

Here is an example query generated by the script:

#standardSQL

-- Generated by BigQuery Firebase Funnel Builder
-- https://github.com/StyleShare/bigquery-firebase-funnel-builder

WITH
data AS (
  SELECT
    user_dim.first_open_timestamp_micros AS session,
    event.timestamp_micros AS timestamp,
    (CASE event.name WHEN "sign_up" THEN event.timestamp_micros END) AS step_0_timestamp,
    (CASE event.name WHEN "add_to_cart" THEN event.timestamp_micros END) AS step_1_timestamp,
    (CASE event.name WHEN "purchase" THEN event.timestamp_micros END) AS step_2_timestamp
  FROM
    `com_myapp_IOS.app_events_*`,
    UNNEST(event_dim) as event,
    UNNEST(event.params) as params
),

funnel AS (
  SELECT
    session,
    timestamp,
    LAST_VALUE(step_0_timestamp IGNORE NULLS) OVER(PARTITION BY session ORDER BY timestamp) AS step_0_funnel,
    LAST_VALUE(step_1_timestamp IGNORE NULLS) OVER(PARTITION BY session ORDER BY timestamp) AS step_1_funnel,
    LAST_VALUE(step_2_timestamp IGNORE NULLS) OVER(PARTITION BY session ORDER BY timestamp) AS step_2_funnel
  FROM data
)

SELECT
  "1_sign_up" AS step,
  COUNT(
    DISTINCT CASE
    WHEN step_0_funnel IS NOT NULL
    THEN step_0_funnel END
  ) AS count
  FROM funnel
UNION ALL SELECT
  "2_add_to_cart" AS step,
  COUNT(
    DISTINCT CASE
    WHEN step_0_funnel IS NOT NULL
      AND step_1_funnel IS NOT NULL AND step_0_funnel < step_1_funnel
    THEN step_0_funnel END
  ) AS count
  FROM funnel
UNION ALL SELECT
  "3_purchase" AS step,
  COUNT(
    DISTINCT CASE
    WHEN step_0_funnel IS NOT NULL
      AND step_1_funnel IS NOT NULL AND step_0_funnel < step_1_funnel
      AND step_2_funnel IS NOT NULL AND step_1_funnel < step_2_funnel
    THEN step_0_funnel END
  ) AS count
  FROM funnel
ORDER BY step
;

LICENSE

BigQuery Firebase Funnel Builder is written by Suyeol Jeon and available under MIT license. See the LICENSE file for more info.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.