Add estimate for number of devices to accounts_backend.users_services_daily_v1 (#5131)

This commit is contained in:
akkomar 2024-02-28 19:29:09 +01:00 коммит произвёл GitHub
Родитель 638f44c4ff
Коммит 6c185d0a88
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 20 добавлений и 0 удалений

Просмотреть файл

@ -15,6 +15,10 @@ CREATE TEMP FUNCTION udf_contains_tier1_country(x ANY TYPE) AS ( --
)
);
CREATE TEMP FUNCTION count_distinct(arr ANY TYPE) AS (
(SELECT COUNT(DISTINCT x) FROM UNNEST(arr) AS x)
);
WITH fxa_events AS (
SELECT
submission_timestamp,
@ -34,6 +38,7 @@ WITH fxa_events AS (
metrics.string.utm_source AS utm_source,
metrics.string.utm_campaign AS utm_campaign,
metrics.string.utm_content AS utm_content,
metadata.user_agent,
FROM
`accounts_backend.accounts_events`
WHERE
@ -56,6 +61,16 @@ windowed AS (
udf.mode_last(ARRAY_AGG(country) OVER w1) AS country,
udf_contains_tier1_country(ARRAY_AGG(country) OVER w1) AS seen_in_tier1_country,
LOGICAL_OR(event_name = 'reg_complete') OVER w1 AS registered,
-- we cannot count distinct here because the window is ordered by submission_timestamp
ARRAY_AGG(
CONCAT(
COALESCE(user_agent.browser, ''),
'_',
COALESCE(user_agent.os, ''),
'_',
COALESCE(user_agent.version, '')
)
) OVER w1 AS user_agent_devices,
FROM
fxa_events
WHERE
@ -89,5 +104,6 @@ SELECT
windowed.country,
windowed.seen_in_tier1_country,
windowed.registered,
count_distinct(windowed.user_agent_devices) AS user_agent_device_count,
FROM
windowed

Просмотреть файл

@ -17,3 +17,7 @@ fields:
- name: registered
type: BOOLEAN
mode: NULLABLE
- name: user_agent_device_count
type: INTEGER
mode: NULLABLE
description: Number of devices associated with the user, per service, per day. Estimated from the number of unique user agent strings.