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.

feat(mobile): show country flags in session replays (#129666)

Chris Volzer3eb1c09d564a
diff --git a/products/mobile/docs/VIEWS.md b/products/mobile/docs/VIEWS.md
index 23fd6612a87f..7dd9298b2af3 100644
--- a/products/mobile/docs/VIEWS.md
+++ b/products/mobile/docs/VIEWS.md
@@ -291,6 +291,11 @@ The tab makes no backend change. [`VIEWS_BACKEND_FOLLOWUPS.md`](VIEWS_BACKEND_FO
- Insights viewed on the web in Recent, and phone views in the web's "Recently viewed".
- Compare on dashboards: `DASHBOARD_COMPARE_SUPPORTED` stays false until US and EU run a build that accepts `compareFilter` in a dashboard override (the deploy check at the end of that file).
+## Session replays
+
+Session rows show a country flag beside the person when their profile has a valid `$geoip_country_code`.
+Profiles without a country show the person alone.
+
## Sessions and Errors release controls
The `mobile-session-replay` and `mobile-error-tracking` feature flags control Sessions and Errors independently.
diff --git a/products/mobile/src/features/replay/SessionListRow.tsx b/products/mobile/src/features/replay/SessionListRow.tsx
index 91cb411badea..06e8da237467 100644
--- a/products/mobile/src/features/replay/SessionListRow.tsx
+++ b/products/mobile/src/features/replay/SessionListRow.tsx
@@ -26,7 +26,7 @@ export function SessionListRow({ row, now, onOpen }: SessionListRowProps): React
<Pressable44
onPress={() => onOpen(row)}
accessibilityRole="button"
- accessibilityLabel={`${title}. ${meta}`}
+ accessibilityLabel={`${title}. ${row.countryCode ? `Country ${row.countryCode}. ` : ''}${meta}`}
pressedBackground={colors.sunken}
style={styles.row}
testID={`session-row-${row.sessionId}`}
diff --git a/products/mobile/src/features/replay/replayModel.ts b/products/mobile/src/features/replay/replayModel.ts
index f9f376536874..67479f8b6d55 100644
--- a/products/mobile/src/features/replay/replayModel.ts
+++ b/products/mobile/src/features/replay/replayModel.ts
@@ -1,6 +1,7 @@
export interface RecordingView {
sessionId: string
personLabel: string
+ countryCode: string | null
startedAt: string | null
endedAt: string | null
durationSeconds: number
@@ -77,6 +78,7 @@ export interface SessionListRow {
sessionId: string
title: string | null
personLabel: string
+ countryCode: string | null
startedAt: string | null
durationSeconds: number | null
keyMomentMs: number | null
diff --git a/products/mobile/src/features/replay/sessionAdapters.test.ts b/products/mobile/src/features/replay/sessionAdapters.test.ts
index 67cbe6684521..11293d67ca57 100644
--- a/products/mobile/src/features/replay/sessionAdapters.test.ts
+++ b/products/mobile/src/features/replay/sessionAdapters.test.ts
@@ -3,6 +3,7 @@ import type { ObservationApi, WatchFeedItemApi } from '@/api/replayVision'
import { parseSeekSeconds, shareSeconds } from './replayLinks'
import {
+ countryFlag,
fallbackTitle,
formatDuration,
formatOffset,
@@ -77,6 +78,19 @@ describe('session adapters', () => {
expect(personLabel(person, distinctId)).toBe(expected)
})
+ test.each([
+ ['us', '🇺🇸'],
+ ['GB', '🇬🇧'],
+ [' de ', '🇩🇪'],
+ ['USA', null],
+ ['ZZ', null],
+ ['', null],
+ [null, null],
+ ])('only renders usable country codes from profiles: %s', (code, expected) => {
+ const recording = recordingView({ id: 's-1', person: { properties: { $geoip_country_code: code } } })
+ expect(countryFlag(recording.countryCode)).toBe(expected)
+ })
+
test('formats offsets and durations', () => {
expect(formatOffset(134_000)).toBe('2:14')
expect(formatOffset(3_734_000)).toBe('1:02:14')
@@ -202,7 +216,11 @@ describe('session adapters', () => {
test('the list puts the feed first, once per session, then the recordings it left out', () => {
const recordings: RecordingApi[] = [
- { id: 's-2', recording_duration: 60, person: { properties: { email: '[email protected]' } } },
+ {
+ id: 's-2',
+ recording_duration: 60,
+ person: { properties: { email: '[email protected]', $geoip_country_code: 'gb' } },
+ },
{ id: 's-1', recording_duration: 252 },
]
const feed: WatchFeedItemApi[] = [
@@ -213,9 +231,9 @@ describe('session adapters', () => {
{ observation: observation({ id: 'obs-4', session_id: 's-1' }), reason: { kind: 'recent' } },
]
const rows = sessionListRows(feed, recordings)
- expect(rows.map((item) => [item.sessionId, item.title, item.durationSeconds])).toEqual([
- ['s-1', 'Share fails', 252],
- ['s-2', null, 60],
+ expect(rows.map((item) => [item.sessionId, item.title, item.durationSeconds, item.countryCode])).toEqual([
+ ['s-1', 'Share fails', 252, null],
+ ['s-2', null, 60, 'GB'],
])
})
diff --git a/products/mobile/src/features/replay/sessionAdapters.ts b/products/mobile/src/features/replay/sessionAdapters.ts
index 1efe05108577..b51de705cc36 100644
--- a/products/mobile/src/features/replay/sessionAdapters.ts
+++ b/products/mobile/src/features/replay/sessionAdapters.ts
@@ -60,6 +60,15 @@ export function personLabel(
return label
}
+export function countryCode(person: RecordingPersonApi | null | undefined): string | null {
+ const code = text(asRecord(person?.properties)?.$geoip_country_code)?.toUpperCase()
+ return code && /^[A-Z]{2}$/.test(code) && code !== 'XX' && code !== 'ZZ' ? code : null
+}
+
+export function countryFlag(code: string | null): string | null {
+ return code ? String.fromCodePoint(...[...code].map((letter) => 0x1f1e6 + letter.charCodeAt(0) - 65)) : null
+}
+
export function urlPath(url: string | null | undefined): string | null {
const value = text(url)
if (!value) {
@@ -76,6 +85,7 @@ export function recordingView(api: RecordingApi): RecordingView {
return {
sessionId: api.id,
personLabel: personLabel(api.person, api.distinct_id),
+ countryCode: countryCode(api.person),
startedAt: text(api.start_time),
endedAt: text(api.end_time),
durationSeconds: Math.max(0, Math.round(count(api.recording_duration))),
@@ -452,6 +462,7 @@ export function sessionListRows(
(text(observation.summary_line) ? truncate(observation.summary_line ?? '', 100) : null),
personLabel:
view?.personLabel ?? personLabel(null, observation.distinct_id, observation.recording_subject_email),
+ countryCode: view?.countryCode ?? null,
startedAt: view?.startedAt ?? null,
durationSeconds: view?.durationSeconds ?? null,
keyMomentMs: typeof output.key_moment_ms === 'number' ? output.key_moment_ms : null,
@@ -479,6 +490,7 @@ export function sessionListRows(
sessionId: view.sessionId,
title: null,
personLabel: view.personLabel,
+ countryCode: view.countryCode,
startedAt: view.startedAt,
durationSeconds: view.durationSeconds,
keyMomentMs: null,
@@ -494,7 +506,7 @@ export function sessionListRows(
export function sessionRowMeta(row: SessionListRow, now: Date): string[] {
return [
- row.personLabel,
+ [countryFlag(row.countryCode), row.personLabel].filter(Boolean).join(' '),
row.durationSeconds !== null ? formatShortDuration(row.durationSeconds) : null,
row.keyMomentMs !== null ? `key moment ${formatOffset(row.keyMomentMs)}` : null,
row.title === null && row.startPath ? row.startPath : null,