Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

chore(replay): add mobile capture mode to clickhouse metadata (#96387)

Manoel Aranda Netof05197c97cdf
diff --git a/posthog/clickhouse/hcl/golden/dev/data.hcl b/posthog/clickhouse/hcl/golden/dev/data.hcl
index 0df9f65834fb..b82a31b8987f 100644
--- a/posthog/clickhouse/hcl/golden/dev/data.hcl
+++ b/posthog/clickhouse/hcl/golden/dev/data.hcl
@@ -4211,6 +4211,9 @@ database "posthog" {
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -6733,6 +6736,9 @@ database "posthog" {
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
replica_name = "{replica}"
@@ -8650,6 +8656,9 @@ database "posthog" {
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "SimpleAggregateFunction(max, DateTime)"
}
diff --git a/posthog/clickhouse/hcl/golden/local-multi/data.hcl b/posthog/clickhouse/hcl/golden/local-multi/data.hcl
index 65029a659c6e..9fd4d10be524 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/data.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/data.hcl
@@ -4655,6 +4655,9 @@ database "posthog" {
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -7810,6 +7813,9 @@ database "posthog" {
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
replica_name = "{replica}"
@@ -9965,6 +9971,9 @@ database "posthog" {
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "SimpleAggregateFunction(max, DateTime)"
}
diff --git a/posthog/clickhouse/hcl/golden/local-multi/ingestion_small.hcl b/posthog/clickhouse/hcl/golden/local-multi/ingestion_small.hcl
index 746335657b6a..938f2ea07930 100644
--- a/posthog/clickhouse/hcl/golden/local-multi/ingestion_small.hcl
+++ b/posthog/clickhouse/hcl/golden/local-multi/ingestion_small.hcl
@@ -590,6 +590,9 @@ database "posthog" {
column "snapshot_library" {
type = "Nullable(String)"
}
+ column "snapshot_mode" {
+ type = "LowCardinality(Nullable(String))"
+ }
column "retention_period_days" {
type = "Nullable(Int64)"
}
@@ -1761,6 +1764,9 @@ database "posthog" {
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "SimpleAggregateFunction(max, DateTime)"
}
@@ -2656,7 +2662,8 @@ SELECT
groupUniqArrayArray(ai_tags_fixed) AS ai_tags_fixed,
groupUniqArrayArray(ai_tags_freeform) AS ai_tags_freeform,
max(ai_highlighted) AS ai_highlighted,
- max(surfacing_score) AS surfacing_score
+ max(surfacing_score) AS surfacing_score,
+ argMinState(snapshot_mode, first_timestamp) AS snapshot_mode
FROM posthog.kafka_session_replay_events
GROUP BY
session_id, team_id
@@ -2728,6 +2735,9 @@ SQL
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "Nullable(DateTime)"
}
diff --git a/posthog/clickhouse/hcl/golden/local-single/all.hcl b/posthog/clickhouse/hcl/golden/local-single/all.hcl
index 6ad379d3cae1..e004ca25b16d 100644
--- a/posthog/clickhouse/hcl/golden/local-single/all.hcl
+++ b/posthog/clickhouse/hcl/golden/local-single/all.hcl
@@ -4272,6 +4272,9 @@ database "posthog" {
column "snapshot_library" {
type = "Nullable(String)"
}
+ column "snapshot_mode" {
+ type = "LowCardinality(Nullable(String))"
+ }
column "retention_period_days" {
type = "Nullable(Int64)"
}
@@ -9383,6 +9386,9 @@ SQL
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -13518,6 +13524,9 @@ SQL
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
replica_name = "{replica}"
@@ -18084,6 +18093,9 @@ SQL
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "SimpleAggregateFunction(max, DateTime)"
}
@@ -23051,7 +23063,8 @@ SELECT
groupUniqArrayArray(ai_tags_fixed) AS ai_tags_fixed,
groupUniqArrayArray(ai_tags_freeform) AS ai_tags_freeform,
max(ai_highlighted) AS ai_highlighted,
- max(surfacing_score) AS surfacing_score
+ max(surfacing_score) AS surfacing_score,
+ argMinState(snapshot_mode, first_timestamp) AS snapshot_mode
FROM posthog.kafka_session_replay_events
GROUP BY
session_id, team_id
@@ -23123,6 +23136,9 @@ SQL
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "Nullable(DateTime)"
}
diff --git a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
index c5c9eccde3c9..4063530ea5f5 100644
--- a/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-eu/data.hcl
@@ -4684,6 +4684,9 @@ database "posthog" {
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -6541,6 +6544,9 @@ database "posthog" {
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
replica_name = "{replica}"
@@ -8713,6 +8719,9 @@ database "posthog" {
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "SimpleAggregateFunction(max, DateTime)"
}
diff --git a/posthog/clickhouse/hcl/golden/prod-us/data.hcl b/posthog/clickhouse/hcl/golden/prod-us/data.hcl
index 3d061bed3f98..985bb570175e 100644
--- a/posthog/clickhouse/hcl/golden/prod-us/data.hcl
+++ b/posthog/clickhouse/hcl/golden/prod-us/data.hcl
@@ -4479,6 +4479,9 @@ database "posthog" {
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -6303,6 +6306,9 @@ database "posthog" {
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/reshard/{shard}/posthog.session_replay_events"
replica_name = "{replica}"
@@ -8535,6 +8541,9 @@ database "posthog" {
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "SimpleAggregateFunction(max, DateTime)"
}
diff --git a/posthog/clickhouse/hcl/roles/coshared/session_replay_write/tables.hcl b/posthog/clickhouse/hcl/roles/coshared/session_replay_write/tables.hcl
index d802e33d97d4..6beab50571ab 100644
--- a/posthog/clickhouse/hcl/roles/coshared/session_replay_write/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/coshared/session_replay_write/tables.hcl
@@ -66,6 +66,9 @@ database "posthog" {
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "SimpleAggregateFunction(max, DateTime)"
}
diff --git a/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl b/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl
index e17f74db1452..a5bfa1587dfb 100644
--- a/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl
+++ b/posthog/clickhouse/hcl/roles/data/common/shared_declarations.hcl
@@ -1169,6 +1169,9 @@ SQL
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "distributed" {
cluster_name = "posthog"
remote_database = "posthog"
@@ -1498,6 +1501,9 @@ SQL
column "retention_period_days" {
type = "SimpleAggregateFunction(max, Nullable(Int64))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
engine "replicated_aggregating_merge_tree" {
zoo_path = "/clickhouse/tables/{shard}/posthog.session_replay_events"
replica_name = "{replica}"
diff --git a/posthog/clickhouse/hcl/roles/ingestion_small/local/tables.hcl b/posthog/clickhouse/hcl/roles/ingestion_small/local/tables.hcl
index 2a183cc342ba..08841fb98955 100644
--- a/posthog/clickhouse/hcl/roles/ingestion_small/local/tables.hcl
+++ b/posthog/clickhouse/hcl/roles/ingestion_small/local/tables.hcl
@@ -548,6 +548,9 @@ database "posthog" {
column "snapshot_library" {
type = "Nullable(String)"
}
+ column "snapshot_mode" {
+ type = "LowCardinality(Nullable(String))"
+ }
column "retention_period_days" {
type = "Nullable(Int64)"
}
@@ -1971,7 +1974,8 @@ SELECT
groupUniqArrayArray(ai_tags_fixed) AS ai_tags_fixed,
groupUniqArrayArray(ai_tags_freeform) AS ai_tags_freeform,
max(ai_highlighted) AS ai_highlighted,
- max(surfacing_score) AS surfacing_score
+ max(surfacing_score) AS surfacing_score,
+ argMinState(snapshot_mode, first_timestamp) AS snapshot_mode
FROM posthog.kafka_session_replay_events
GROUP BY
session_id, team_id
@@ -2043,6 +2047,9 @@ SQL
column "snapshot_library" {
type = "AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC'))"
}
+ column "snapshot_mode" {
+ type = "AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))"
+ }
column "_timestamp" {
type = "Nullable(DateTime)"
}
diff --git a/posthog/clickhouse/hcl/sql/dev/data.sql b/posthog/clickhouse/hcl/sql/dev/data.sql
index 74d538d79768..53fd40c75e84 100644
--- a/posthog/clickhouse/hcl/sql/dev/data.sql
+++ b/posthog/clickhouse/hcl/sql/dev/data.sql
@@ -1456,7 +1456,8 @@ CREATE TABLE posthog.sharded_session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
CREATE TABLE posthog.sharded_sessions (
session_id String,
@@ -2054,6 +2055,7 @@ CREATE TABLE posthog.writable_session_replay_events (
event_count SimpleAggregateFunction(sum, Int64),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0
@@ -2821,7 +2823,8 @@ CREATE TABLE posthog.session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
CREATE TABLE posthog.sessions (
session_id String,
diff --git a/posthog/clickhouse/hcl/sql/local-multi/data.sql b/posthog/clickhouse/hcl/sql/local-multi/data.sql
index b5a284eac772..80ebb1236b43 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/data.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/data.sql
@@ -1665,7 +1665,8 @@ CREATE TABLE posthog.sharded_session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512;
CREATE TABLE posthog.sharded_sessions (
session_id String,
@@ -2330,6 +2331,7 @@ CREATE TABLE posthog.writable_session_replay_events (
event_count SimpleAggregateFunction(sum, Int64),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
@@ -3452,7 +3454,8 @@ CREATE TABLE posthog.session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
CREATE TABLE posthog.sessions (
session_id String,
diff --git a/posthog/clickhouse/hcl/sql/local-multi/ingestion_small.sql b/posthog/clickhouse/hcl/sql/local-multi/ingestion_small.sql
index abd189b57f39..6d0867249b63 100644
--- a/posthog/clickhouse/hcl/sql/local-multi/ingestion_small.sql
+++ b/posthog/clickhouse/hcl/sql/local-multi/ingestion_small.sql
@@ -178,6 +178,7 @@ CREATE TABLE posthog.kafka_session_replay_events (
message_count Int64,
snapshot_source LowCardinality(Nullable(String)),
snapshot_library Nullable(String),
+ snapshot_mode LowCardinality(Nullable(String)),
retention_period_days Nullable(Int64),
is_deleted UInt8,
ai_tags_fixed Array(String),
@@ -529,6 +530,7 @@ CREATE TABLE posthog.writable_session_replay_events (
event_count SimpleAggregateFunction(sum, Int64),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
@@ -748,7 +750,7 @@ CREATE MATERIALIZED VIEW posthog.posthog_document_embeddings_kafka_to_buffer_mv
_offset,
_partition
FROM posthog.kafka_posthog_document_embeddings;
-CREATE MATERIALIZED VIEW posthog.session_replay_events_mv TO posthog.writable_session_replay_events (session_id String, team_id Int64, distinct_id String, min_first_timestamp DateTime64(6, 'UTC'), max_last_timestamp DateTime64(6, 'UTC'), block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))), block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))), block_urls SimpleAggregateFunction(groupArrayArray, Array(String)), first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')), all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)), click_count Int64, keypress_count Int64, mouse_activity_count Int64, active_milliseconds Int64, console_log_count Int64, console_warn_count Int64, console_error_count Int64, size Int64, message_count Int64, event_count Int64, snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')), snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')), _timestamp Nullable(DateTime), retention_period_days SimpleAggregateFunction(max, Nullable(Int64)), is_deleted SimpleAggregateFunction(max, UInt8), ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)), ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)), ai_highlighted SimpleAggregateFunction(max, UInt8), surfacing_score SimpleAggregateFunction(max, Nullable(Float32))) AS SELECT
+CREATE MATERIALIZED VIEW posthog.session_replay_events_mv TO posthog.writable_session_replay_events (session_id String, team_id Int64, distinct_id String, min_first_timestamp DateTime64(6, 'UTC'), max_last_timestamp DateTime64(6, 'UTC'), block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))), block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))), block_urls SimpleAggregateFunction(groupArrayArray, Array(String)), first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')), all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)), click_count Int64, keypress_count Int64, mouse_activity_count Int64, active_milliseconds Int64, console_log_count Int64, console_warn_count Int64, console_error_count Int64, size Int64, message_count Int64, event_count Int64, snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')), snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')), snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')), _timestamp Nullable(DateTime), retention_period_days SimpleAggregateFunction(max, Nullable(Int64)), is_deleted SimpleAggregateFunction(max, UInt8), ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)), ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)), ai_highlighted SimpleAggregateFunction(max, UInt8), surfacing_score SimpleAggregateFunction(max, Nullable(Float32))) AS SELECT
session_id,
team_id,
any(distinct_id) AS distinct_id,
@@ -777,7 +779,8 @@ CREATE MATERIALIZED VIEW posthog.session_replay_events_mv TO posthog.writable_se
groupUniqArrayArray(ai_tags_fixed) AS ai_tags_fixed,
groupUniqArrayArray(ai_tags_freeform) AS ai_tags_freeform,
max(ai_highlighted) AS ai_highlighted,
- max(surfacing_score) AS surfacing_score
+ max(surfacing_score) AS surfacing_score,
+ argMinState(snapshot_mode, first_timestamp) AS snapshot_mode
FROM posthog.kafka_session_replay_events
GROUP BY
session_id, team_id;
diff --git a/posthog/clickhouse/hcl/sql/local-single/all.sql b/posthog/clickhouse/hcl/sql/local-single/all.sql
index 4764f39509bf..9e1c2dab1832 100644
--- a/posthog/clickhouse/hcl/sql/local-single/all.sql
+++ b/posthog/clickhouse/hcl/sql/local-single/all.sql
@@ -797,6 +797,7 @@ CREATE TABLE posthog.kafka_session_replay_events (
message_count Int64,
snapshot_source LowCardinality(Nullable(String)),
snapshot_library Nullable(String),
+ snapshot_mode LowCardinality(Nullable(String)),
retention_period_days Nullable(Int64),
is_deleted UInt8,
ai_tags_fixed Array(String),
@@ -2781,7 +2782,8 @@ CREATE TABLE posthog.sharded_session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512;
CREATE TABLE posthog.sharded_session_replay_features (
session_id String,
@@ -4125,6 +4127,7 @@ CREATE TABLE posthog.writable_session_replay_events (
event_count SimpleAggregateFunction(sum, Int64),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
is_deleted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
@@ -5478,7 +5481,7 @@ WHERE
bitAnd(bitShiftRight(toUInt128(accurateCastOrNull(`$session_id`, 'UUID')), 76), 15) = 7
GROUP BY
team_id, toStartOfHour(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(session_id_v7, 80)), 1000))), cityHash64(session_id_v7), session_id_v7;
-CREATE MATERIALIZED VIEW posthog.session_replay_events_mv TO posthog.writable_session_replay_events (session_id String, team_id Int64, distinct_id String, min_first_timestamp DateTime64(6, 'UTC'), max_last_timestamp DateTime64(6, 'UTC'), block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))), block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))), block_urls SimpleAggregateFunction(groupArrayArray, Array(String)), first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')), all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)), click_count Int64, keypress_count Int64, mouse_activity_count Int64, active_milliseconds Int64, console_log_count Int64, console_warn_count Int64, console_error_count Int64, size Int64, message_count Int64, event_count Int64, snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')), snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')), _timestamp Nullable(DateTime), retention_period_days SimpleAggregateFunction(max, Nullable(Int64)), is_deleted SimpleAggregateFunction(max, UInt8), ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)), ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)), ai_highlighted SimpleAggregateFunction(max, UInt8), surfacing_score SimpleAggregateFunction(max, Nullable(Float32))) AS SELECT
+CREATE MATERIALIZED VIEW posthog.session_replay_events_mv TO posthog.writable_session_replay_events (session_id String, team_id Int64, distinct_id String, min_first_timestamp DateTime64(6, 'UTC'), max_last_timestamp DateTime64(6, 'UTC'), block_first_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))), block_last_timestamps SimpleAggregateFunction(groupArrayArray, Array(DateTime64(6, 'UTC'))), block_urls SimpleAggregateFunction(groupArrayArray, Array(String)), first_url AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')), all_urls SimpleAggregateFunction(groupUniqArrayArray, Array(String)), click_count Int64, keypress_count Int64, mouse_activity_count Int64, active_milliseconds Int64, console_log_count Int64, console_warn_count Int64, console_error_count Int64, size Int64, message_count Int64, event_count Int64, snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')), snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')), snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')), _timestamp Nullable(DateTime), retention_period_days SimpleAggregateFunction(max, Nullable(Int64)), is_deleted SimpleAggregateFunction(max, UInt8), ai_tags_fixed SimpleAggregateFunction(groupUniqArrayArray, Array(String)), ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)), ai_highlighted SimpleAggregateFunction(max, UInt8), surfacing_score SimpleAggregateFunction(max, Nullable(Float32))) AS SELECT
session_id,
team_id,
any(distinct_id) AS distinct_id,
@@ -5507,7 +5510,8 @@ CREATE MATERIALIZED VIEW posthog.session_replay_events_mv TO posthog.writable_se
groupUniqArrayArray(ai_tags_fixed) AS ai_tags_fixed,
groupUniqArrayArray(ai_tags_freeform) AS ai_tags_freeform,
max(ai_highlighted) AS ai_highlighted,
- max(surfacing_score) AS surfacing_score
+ max(surfacing_score) AS surfacing_score,
+ argMinState(snapshot_mode, first_timestamp) AS snapshot_mode
FROM posthog.kafka_session_replay_events
GROUP BY
session_id, team_id;
@@ -6985,7 +6989,8 @@ CREATE TABLE posthog.session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
CREATE TABLE posthog.session_replay_features (
session_id String,
diff --git a/posthog/clickhouse/hcl/sql/prod-eu/data.sql b/posthog/clickhouse/hcl/sql/prod-eu/data.sql
index f626d4b4af09..86bc493725fc 100644
--- a/posthog/clickhouse/hcl/sql/prod-eu/data.sql
+++ b/posthog/clickhouse/hcl/sql/prod-eu/data.sql
@@ -1624,7 +1624,8 @@ CREATE TABLE posthog.sharded_session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512, ttl_only_drop_parts = 1;
CREATE TABLE posthog.swap_person_distinct_id (
distinct_id String,
@@ -2298,6 +2299,7 @@ CREATE TABLE posthog.writable_session_replay_events (
event_count SimpleAggregateFunction(sum, Int64),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
@@ -3091,7 +3093,8 @@ CREATE TABLE posthog.session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
CREATE VIEW posthog.custom_metrics AS SELECT * REPLACE(toFloat64(value) AS value)
FROM posthog.custom_metrics_test
diff --git a/posthog/clickhouse/hcl/sql/prod-us/data.sql b/posthog/clickhouse/hcl/sql/prod-us/data.sql
index d90a464d69fd..aeb8f175b5dc 100644
--- a/posthog/clickhouse/hcl/sql/prod-us/data.sql
+++ b/posthog/clickhouse/hcl/sql/prod-us/data.sql
@@ -1456,7 +1456,8 @@ CREATE TABLE posthog.sharded_session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = ReplicatedAggregatingMergeTree('/clickhouse/tables/reshard/{shard}/posthog.session_replay_events', '{replica}') ORDER BY (toDate(min_first_timestamp), team_id, session_id) PARTITION BY toYYYYMM(min_first_timestamp) SETTINGS index_granularity = 512;
CREATE TABLE posthog.swap_person_distinct_id (
distinct_id String,
@@ -2101,6 +2102,7 @@ CREATE TABLE posthog.writable_session_replay_events (
event_count SimpleAggregateFunction(sum, Int64),
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
) ENGINE = Distributed('posthog_writable', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
@@ -2928,7 +2930,8 @@ CREATE TABLE posthog.session_replay_events (
ai_tags_freeform SimpleAggregateFunction(groupUniqArrayArray, Array(String)),
ai_highlighted SimpleAggregateFunction(max, UInt8) DEFAULT 0,
surfacing_score SimpleAggregateFunction(max, Nullable(Float32)),
- retention_period_days SimpleAggregateFunction(max, Nullable(Int64))
+ retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
) ENGINE = Distributed('posthog', 'posthog', 'sharded_session_replay_events', sipHash64(distinct_id));
CREATE TABLE posthog.writable_raw_sessions_v3 (
team_id Int64,
diff --git a/posthog/clickhouse/migrations/0315_add_snapshot_mode_to_session_replay_events.py b/posthog/clickhouse/migrations/0315_add_snapshot_mode_to_session_replay_events.py
new file mode 100644
index 000000000000..e39870864f53
--- /dev/null
+++ b/posthog/clickhouse/migrations/0315_add_snapshot_mode_to_session_replay_events.py
@@ -0,0 +1,64 @@
+from posthog.clickhouse.client.connection import NodeRole
+from posthog.clickhouse.client.migration_tools import run_sql_with_exceptions
+from posthog.run_mode import run_mode
+from posthog.session_recordings.sql.session_replay_event_migrations_sql import (
+ DROP_KAFKA_SESSION_REPLAY_EVENTS_TABLE_SQL,
+ DROP_SESSION_REPLAY_EVENTS_TABLE_MV_SQL,
+)
+from posthog.session_recordings.sql.session_replay_event_sql import (
+ DROP_KAFKA_SESSION_REPLAY_EVENTS_WS_TABLE_SQL,
+ DROP_SESSION_REPLAY_EVENTS_WS_MV_SQL,
+ KAFKA_SESSION_REPLAY_EVENTS_TABLE_SQL,
+ KAFKA_SESSION_REPLAY_EVENTS_WS_TABLE_SQL,
+ SESSION_REPLAY_EVENTS_TABLE_MV_SQL,
+ SESSION_REPLAY_EVENTS_WS_MV_SQL,
+)
+
+ADD_SNAPSHOT_MODE = """
+ALTER TABLE {table_name}
+ADD COLUMN IF NOT EXISTS snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
+"""
+
+operations = [
+ run_sql_with_exceptions(
+ DROP_SESSION_REPLAY_EVENTS_TABLE_MV_SQL(on_cluster=False), node_roles=[NodeRole.INGESTION_SMALL]
+ ),
+ run_sql_with_exceptions(
+ DROP_KAFKA_SESSION_REPLAY_EVENTS_TABLE_SQL(on_cluster=False), node_roles=[NodeRole.INGESTION_SMALL]
+ ),
+ run_sql_with_exceptions(DROP_SESSION_REPLAY_EVENTS_WS_MV_SQL, node_roles=[NodeRole.INGESTION_SMALL]),
+ run_sql_with_exceptions(DROP_KAFKA_SESSION_REPLAY_EVENTS_WS_TABLE_SQL, node_roles=[NodeRole.INGESTION_SMALL]),
+ run_sql_with_exceptions(
+ ADD_SNAPSHOT_MODE.format(table_name="sharded_session_replay_events"),
+ node_roles=[NodeRole.DATA],
+ sharded=True,
+ is_alter_on_replicated_table=True,
+ ),
+ run_sql_with_exceptions(
+ ADD_SNAPSHOT_MODE.format(table_name="session_replay_events"),
+ node_roles=[NodeRole.DATA],
+ sharded=False,
+ is_alter_on_replicated_table=False,
+ ),
+ run_sql_with_exceptions(
+ ADD_SNAPSHOT_MODE.format(table_name="writable_session_replay_events"),
+ node_roles=[NodeRole.INGESTION_SMALL],
+ sharded=False,
+ is_alter_on_replicated_table=False,
+ ),
+ *(
+ [
+ run_sql_with_exceptions(KAFKA_SESSION_REPLAY_EVENTS_WS_TABLE_SQL(), node_roles=[NodeRole.INGESTION_SMALL]),
+ run_sql_with_exceptions(SESSION_REPLAY_EVENTS_WS_MV_SQL(), node_roles=[NodeRole.INGESTION_SMALL]),
+ ]
+ if run_mode().is_deployed_cloud
+ else [
+ run_sql_with_exceptions(
+ KAFKA_SESSION_REPLAY_EVENTS_TABLE_SQL(on_cluster=False), node_roles=[NodeRole.INGESTION_SMALL]
+ ),
+ run_sql_with_exceptions(
+ SESSION_REPLAY_EVENTS_TABLE_MV_SQL(on_cluster=False), node_roles=[NodeRole.INGESTION_SMALL]
+ ),
+ ]
+ ),
+]
diff --git a/posthog/clickhouse/migrations/max_migration.txt b/posthog/clickhouse/migrations/max_migration.txt
index d82a360f9d33..ee68f2c2ca4f 100644
--- a/posthog/clickhouse/migrations/max_migration.txt
+++ b/posthog/clickhouse/migrations/max_migration.txt
@@ -1 +1 @@
-0314_metrics2_chain
+0315_add_snapshot_mode_to_session_replay_events
diff --git a/posthog/clickhouse/test/__snapshots__/test_schema.ambr b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
index 9be4af3c5f77..1f02e75ec651 100644
--- a/posthog/clickhouse/test/__snapshots__/test_schema.ambr
+++ b/posthog/clickhouse/test/__snapshots__/test_schema.ambr
@@ -760,6 +760,7 @@
message_count Int64,
snapshot_source LowCardinality(Nullable(String)),
snapshot_library Nullable(String),
+ snapshot_mode LowCardinality(Nullable(String)),
retention_period_days Nullable(Int64),
is_deleted UInt8,
ai_tags_fixed Array(String),
@@ -3064,6 +3065,7 @@
message_count Int64,
snapshot_source LowCardinality(Nullable(String)),
snapshot_library Nullable(String),
+ snapshot_mode LowCardinality(Nullable(String)),
retention_period_days Nullable(Int64),
is_deleted UInt8,
ai_tags_fixed Array(String),
@@ -6388,6 +6390,7 @@
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
-- knowing something is mobile isn't enough, we need to know if e.g. RN or flutter
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
-- retention period for this session, in days. Useful to show TTL for the recording
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
@@ -6432,6 +6435,7 @@
,`ai_tags_freeform` SimpleAggregateFunction(groupUniqArrayArray, Array(String))
,`ai_highlighted` SimpleAggregateFunction(max, UInt8)
,`surfacing_score` SimpleAggregateFunction(max, Nullable(Float32))
+ ,`snapshot_mode` AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))
)
AS SELECT
session_id,
@@ -6473,6 +6477,7 @@
,groupUniqArrayArray(ai_tags_freeform) as ai_tags_freeform
,max(ai_highlighted) as ai_highlighted
,max(surfacing_score) as surfacing_score
+ ,argMinState(snapshot_mode, first_timestamp) as snapshot_mode
FROM posthog_test.kafka_session_replay_events
group by session_id, team_id
@@ -8236,6 +8241,7 @@
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
-- knowing something is mobile isn't enough, we need to know if e.g. RN or flutter
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
-- retention period for this session, in days. Useful to show TTL for the recording
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
@@ -10344,6 +10350,7 @@
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
-- knowing something is mobile isn't enough, we need to know if e.g. RN or flutter
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
-- retention period for this session, in days. Useful to show TTL for the recording
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
@@ -13485,6 +13492,7 @@
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
-- knowing something is mobile isn't enough, we need to know if e.g. RN or flutter
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
-- retention period for this session, in days. Useful to show TTL for the recording
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
@@ -14382,6 +14390,7 @@
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
-- knowing something is mobile isn't enough, we need to know if e.g. RN or flutter
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
-- retention period for this session, in days. Useful to show TTL for the recording
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
diff --git a/posthog/session_recordings/queries/test/session_replay_sql.py b/posthog/session_recordings/queries/test/session_replay_sql.py
index 2d0f45e81fd9..07e20f8a3232 100644
--- a/posthog/session_recordings/queries/test/session_replay_sql.py
+++ b/posthog/session_recordings/queries/test/session_replay_sql.py
@@ -31,6 +31,7 @@ INSERT INTO sharded_session_replay_events (
console_error_count,
snapshot_source,
snapshot_library,
+ snapshot_mode,
size,
block_urls,
block_first_timestamps,
@@ -57,6 +58,7 @@ SELECT
%(console_error_count)s,
argMinState(cast(%(snapshot_source)s, 'LowCardinality(Nullable(String))'), toDateTime64(%(first_timestamp)s, 6, 'UTC')),
argMinState(cast(%(snapshot_library)s, 'LowCardinality(Nullable(String))'), toDateTime64(%(first_timestamp)s, 6, 'UTC')),
+ argMinState(cast(NULL, 'LowCardinality(Nullable(String))'), toDateTime64(%(first_timestamp)s, 6, 'UTC')),
%(size)s,
%(block_urls)s,
%(block_first_timestamps)s,
diff --git a/posthog/session_recordings/sql/session_replay_event_sql.py b/posthog/session_recordings/sql/session_replay_event_sql.py
index 333e8b4fb7d4..4070d3e80f63 100644
--- a/posthog/session_recordings/sql/session_replay_event_sql.py
+++ b/posthog/session_recordings/sql/session_replay_event_sql.py
@@ -42,6 +42,7 @@ CREATE TABLE IF NOT EXISTS {table_name} {on_cluster_clause}
message_count Int64,
snapshot_source LowCardinality(Nullable(String)),
snapshot_library Nullable(String),
+ snapshot_mode LowCardinality(Nullable(String)),
retention_period_days Nullable(Int64),
is_deleted UInt8,
ai_tags_fixed Array(String),
@@ -95,6 +96,7 @@ CREATE TABLE IF NOT EXISTS {table_name} {on_cluster_clause}
snapshot_source AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
-- knowing something is mobile isn't enough, we need to know if e.g. RN or flutter
snapshot_library AggregateFunction(argMin, Nullable(String), DateTime64(6, 'UTC')),
+ snapshot_mode AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC')),
_timestamp SimpleAggregateFunction(max, DateTime),
-- retention period for this session, in days. Useful to show TTL for the recording
retention_period_days SimpleAggregateFunction(max, Nullable(Int64)),
@@ -182,6 +184,7 @@ def SESSION_REPLAY_EVENTS_TABLE_MV_SQL(on_cluster=True, exclude_columns=None):
{",`ai_tags_freeform` SimpleAggregateFunction(groupUniqArrayArray, Array(String))" if "ai_tags_freeform" not in exclude_columns else ""}
{",`ai_highlighted` SimpleAggregateFunction(max, UInt8)" if "ai_highlighted" not in exclude_columns else ""}
{",`surfacing_score` SimpleAggregateFunction(max, Nullable(Float32))" if "surfacing_score" not in exclude_columns else ""}
+{",`snapshot_mode` AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))" if "snapshot_mode" not in exclude_columns else ""}
)"""
return f"""
@@ -227,6 +230,7 @@ max(_timestamp) as _timestamp
{",groupUniqArrayArray(ai_tags_freeform) as ai_tags_freeform" if "ai_tags_freeform" not in exclude_columns else ""}
{",max(ai_highlighted) as ai_highlighted" if "ai_highlighted" not in exclude_columns else ""}
{",max(surfacing_score) as surfacing_score" if "surfacing_score" not in exclude_columns else ""}
+{",argMinState(snapshot_mode, first_timestamp) as snapshot_mode" if "snapshot_mode" not in exclude_columns else ""}
FROM {database}.kafka_session_replay_events
group by session_id, team_id
"""
@@ -329,6 +333,7 @@ def SESSION_REPLAY_EVENTS_WS_MV_SQL(on_cluster=False, exclude_columns=None):
{",`ai_tags_freeform` SimpleAggregateFunction(groupUniqArrayArray, Array(String))" if "ai_tags_freeform" not in exclude_columns else ""}
{",`ai_highlighted` SimpleAggregateFunction(max, UInt8)" if "ai_highlighted" not in exclude_columns else ""}
{",`surfacing_score` SimpleAggregateFunction(max, Nullable(Float32))" if "surfacing_score" not in exclude_columns else ""}
+{",`snapshot_mode` AggregateFunction(argMin, LowCardinality(Nullable(String)), DateTime64(6, 'UTC'))" if "snapshot_mode" not in exclude_columns else ""}
)"""
return f"""
@@ -364,6 +369,7 @@ max(_timestamp) as _timestamp
{",groupUniqArrayArray(ai_tags_freeform) as ai_tags_freeform" if "ai_tags_freeform" not in exclude_columns else ""}
{",max(ai_highlighted) as ai_highlighted" if "ai_highlighted" not in exclude_columns else ""}
{",max(surfacing_score) as surfacing_score" if "surfacing_score" not in exclude_columns else ""}
+{",argMinState(snapshot_mode, first_timestamp) as snapshot_mode" if "snapshot_mode" not in exclude_columns else ""}
FROM {database}.{KAFKA_SESSION_REPLAY_EVENTS_WS_TABLE}
group by session_id, team_id
"""
diff --git a/posthog/temporal/tests/session_replay/surfacing_scoring_sweep/ch_insert_helpers.py b/posthog/temporal/tests/session_replay/surfacing_scoring_sweep/ch_insert_helpers.py
index 2c72f64b6c13..d1601a7122c5 100644
--- a/posthog/temporal/tests/session_replay/surfacing_scoring_sweep/ch_insert_helpers.py
+++ b/posthog/temporal/tests/session_replay/surfacing_scoring_sweep/ch_insert_helpers.py
@@ -21,6 +21,7 @@ INSERT INTO sharded_session_replay_events (
first_url,
snapshot_source,
snapshot_library,
+ snapshot_mode,
event_count,
surfacing_score
)
@@ -33,6 +34,7 @@ SELECT
argMinState(cast(NULL, 'Nullable(String)'), now64(6) - INTERVAL 1 HOUR),
argMinState(cast(NULL, 'LowCardinality(Nullable(String))'), now64(6) - INTERVAL 1 HOUR),
argMinState(cast(NULL, 'Nullable(String)'), now64(6) - INTERVAL 1 HOUR),
+ argMinState(cast(NULL, 'LowCardinality(Nullable(String))'), now64(6) - INTERVAL 1 HOUR),
%(event_count)s,
%(surfacing_score)s
"""
@@ -47,6 +49,7 @@ INSERT INTO sharded_session_replay_events (
first_url,
snapshot_source,
snapshot_library,
+ snapshot_mode,
event_count,
surfacing_score
)
@@ -59,6 +62,7 @@ SELECT
argMinState(cast(NULL, 'Nullable(String)'), toDateTime64(%(start)s, 6, 'UTC')),
argMinState(cast(NULL, 'LowCardinality(Nullable(String))'), toDateTime64(%(start)s, 6, 'UTC')),
argMinState(cast(NULL, 'Nullable(String)'), toDateTime64(%(start)s, 6, 'UTC')),
+ argMinState(cast(NULL, 'LowCardinality(Nullable(String))'), toDateTime64(%(start)s, 6, 'UTC')),
%(event_count)s,
%(surfacing_score)s
"""