Afonso_DiazNew / Active users + Retention Rate
    Updated 2025-03-06
    with

    main as (
    select
    tx_hash,
    block_timestamp,
    from_address as user,
    tx_fee
    from
    ink.core.fact_transactions
    where
    tx_succeeded
    ),

    weekly_users as (
    select
    date_trunc('week', block_timestamp) as week,
    user,
    min(block_timestamp) over (partition by user) as first_seen
    from main
    ),

    weekly_metrics as (
    select
    week,
    count(distinct user) as active_users,
    count(distinct case when date_trunc('week', first_seen) = week then user end) as new_users,
    count(distinct case when date_trunc('week', first_seen) < week then user end) as returning_users
    from weekly_users
    group by week
    ),

    retention as (
    select
    w1.week as current_week,
    w2.week as previous_week,
    QueryRunArchived: QueryRun has been archived