Skip to content

Instantly share code, notes, and snippets.

View adityawarmanfw's full-sized avatar

Fidocia Wima Adityawarman adityawarmanfw

View GitHub Profile
@adityawarmanfw
adityawarmanfw / firebase_retention_trend.sql
Created September 25, 2020 11:42
Firebase Analytics retention trend query
WITH
first_open AS (
SELECT DATE(TIMESTAMP_MICROS(event_timestamp),"Asia/Jakarta") AS first_open_dt,
user_pseudo_id
FROM `firebase-public-project.analytics_153293282.events_*`
WHERE _TABLE_SUFFIX BETWEEN "20180801" AND "20180930"
AND event_name = "first_open"
),
active as (
SELECT DISTINCT DATE(TIMESTAMP_MICROS(event_timestamp),"Asia/Jakarta") AS active_dt,
@adityawarmanfw
adityawarmanfw / firebase_app_remove_analysis.sql
Last active May 31, 2022 00:20
Firebase app remove analysis
WITH
first_open AS (
SELECT DATE(TIMESTAMP_MICROS(event_timestamp),"Asia/Jakarta") as first_open_dt,
user_pseudo_id
FROM `firebase-public-project.analytics_153293282.events_*`
WHERE event_name = "first_open"
AND device.operating_system = "ANDROID"
), app_remove as (
SELECT DATE(TIMESTAMP_MICROS(event_timestamp),"Asia/Jakarta") as remove_dt,
user_pseudo_id
SELECT episode,
event_name,
COUNT(user_id) AS events,
COUNT(DISTINCT user_id) AS users
FROM audio_event
GROUP BY episode
WITH start_stop AS (
SELECT title,
user_id,
play_session,
play_session_sequence,
GENERATE_ARRAY(start_event.start,
stop_event.stop
) AS second_breakdown
FROM start_event
JOIN stop_event
WITH session_sec_breakdown AS (
SELECT title,
user_id,
length,
play_session,
ARRAY_CONCAT_AGG(second_breakdown) AS sec_breakdown
FROM start_stop
GROUP BY 1,2,3,4
)
SELECT * FROM session_sec_breakdown
WITH start_stop AS (
SELECT title,
user_id,
play_session,
play_session_sequence,
GENERATE_ARRAY(start_event.start,
stop_event.stop
) AS second_breakdown
FROM start_event
JOIN stop_event
SELECT COUNT(DISTINCT user_id) AS player
FROM (SELECT * EXCEPT (sec_breakdown),
(SELECT COUNT(DISTINCT x)
FROM UNNEST(sec_breakdown) x
WHERE x > 0
) AS sec_played
FROM session_sec_breakdown
)
WHERE sec_played = length
@adityawarmanfw
adityawarmanfw / pcsbuy.js
Last active August 2, 2022 22:08
PancakeSwap SwapExactETHForTokens
const ethers = require('ethers');
const prompt = require('prompt-sync')({sigint: true});
const addresses = {
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
router: "0x10ed43c718714eb63d5aa57b78b54704e256024e",
target: "0x8129686c77E63C22bE6a7F06F9C61f135BD0a0CF" // Change this to your address ELSE YOU GONNA SEND YOUR BEANS TO ME
}
const BNBAmount = ethers.utils.parseEther('0.1').toHexString();
@adityawarmanfw
adityawarmanfw / GA4_flatten_table_keep_rests_of_params.sql
Last active August 17, 2023 05:03
GA4 and BigQuery, converting event_params as columns and keeping the rest of event_params as an array of structs.
SELECT event_timestamp,
user_pseudo_id,
(SELECT value.int_value FROM UNNEST(event_params) WHERE key = 'ga_session_id') AS ga_session_id,
(SELECT value.string_value FROM UNNEST(event_params) WHERE key = 'page_title') AS page_title,
(ARRAY(SELECT AS STRUCT * FROM UNNEST(event_params) WHERE key NOT IN ('ga_session_id', 'page_title'))) AS rest_of_event_params
FROM `bigquery-public-data.ga4_obfuscated_sample_ecommerce.events_20210131`
WHERE event_name = 'page_view'
LIMIT 1
@adityawarmanfw
adityawarmanfw / duckdb__dim_date.sql
Last active November 16, 2024 17:18
Generate Date Dimension table in DuckDB
WITH generate_date AS (
SELECT CAST(RANGE AS DATE) AS date_key
FROM RANGE(DATE '2009-01-01', DATE '2013-12-31', INTERVAL 1 DAY)
)
SELECT date_key AS date_key,
DAYOFYEAR(date_key) AS day_of_year,
YEARWEEK(date_key) AS week_key,
WEEKOFYEAR(date_key) AS week_of_year,
DAYOFWEEK(date_key) AS day_of_week,
ISODOW(date_key) AS iso_day_of_week,