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(web-analytics): simplify cookieless setting to a single toggle (#51311)

Lucas Ricoyf4f9dc1b1f45
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 783a994aabce..00de38e1d552 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -7399,9 +7399,9 @@ snapshots:
scenes-app-settings-environment--settings-environment-surveys--light:
hash: v1.k794b7964.82a6d0673ae37171eb0f50012e837e8417d965f747a21d0a728425dd53209fc1.YyKQuLivmwjiIilN3bvDszBRrnZ207pshWSu8nSp_j4
scenes-app-settings-environment--settings-environment-web-analytics--dark:
- hash: v1.k794b7964.f4407b8de1789098f3f6d1ab4358406efd1194c82b87fb23f0570d539e371f43.y1WuTs0OiZ9IzEgeHR-hkuWtYTx7w3ZCooRd1-26dvg
+ hash: v1.k794b7964.345c0a0e72de6e02a76677bf0e67b9eb7d91d07a30f3c94b8a5f4d98676ca8ce.zpjJqvTV7a_PYYxjl99FcHYQp4IakvV7bTwfRaB5NH4
scenes-app-settings-environment--settings-environment-web-analytics--light:
- hash: v1.k794b7964.9b9f3376d395bc3b0df04869ad6be28c2f5543b29803c60f445a6db2a25a4722.F5JdDB3NROJMin8xXl-UWTOhPB953NwsEXotpXh953E
+ hash: v1.k794b7964.c45e1d9def388dcbc3e178352fe89c60802c8d439f9c5ab6a0f7d5b655a982f3.7Yaa0aoTJCoQ2JQl05KVW_sxK7pRgyd-XrQHy4ZS0a0
scenes-app-settings-organization--settings-organization-authentication--dark:
hash: v1.k794b7964.6ddb506ed211a3f8de0d302d47d070cb16ff121a93b22e78cf47d71582084971.rD1vE9nirvysLXvvRet6q3N2Jn8yqEeY6kj49SMtz3c
scenes-app-settings-organization--settings-organization-authentication--light:
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 04bf2ce9bf23..bf3014eab977 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -205,7 +205,6 @@ export const FEATURE_FLAGS = {
BATCH_EXPORTS_POSTHOG_HTTP: 'posthog-http-batch-exports', // owner: #team-batch-exports
BILLING_SKIP_FORECASTING: 'billing-skip-forecasting', // owner: @zach
BOX_PLOT_INSIGHT: 'box-plot-insight', // owner: @pauldambra #team-product-analytics
- COOKIELESS_SERVER_HASH_MODE_SETTING: 'cookieless-server-hash-mode-setting', // owner: #team-web-analytics
EXPERIMENT_INTERVAL_TIMESERIES: 'experiments-interval-timeseries', // owner: @jurajmajerik #team-experiments
GATEWAY_PERSONAL_API_KEY: 'gateway-personal-api-key', // owner: #team-platform-features
HEATMAPS_COHORT_FILTER: 'heatmaps-cohort-filter', // owner: #team-web-analytics
diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsx
index 266f4dfd66fc..ee90f4306435 100644
--- a/frontend/src/scenes/settings/SettingsMap.tsx
+++ b/frontend/src/scenes/settings/SettingsMap.tsx
@@ -1296,9 +1296,9 @@ export const SETTINGS_MAP: SettingSection[] = [
},
{
id: 'cookieless-server-hash-mode',
- title: 'Cookieless server hash mode',
+ title: 'Cookieless tracking',
description:
- 'Enable cookieless tracking using a privacy-preserving hash to count unique users without cookies. You must enable this here before enabling cookieless in posthog-js.',
+ 'Count unique users with a privacy-preserving hash instead of cookies. Enable this here, then enable cookieless mode in posthog-js.',
docsUrl: 'https://posthog.com/tutorials/cookieless-tracking',
component: <CookielessServerHashModeSetting />,
keywords: ['cookie', 'privacy', 'gdpr', 'tracking', 'consent'],
diff --git a/frontend/src/scenes/settings/environment/CookielessServerHashMode.tsx b/frontend/src/scenes/settings/environment/CookielessServerHashMode.tsx
index 2b160ab243eb..2068aba75b43 100644
--- a/frontend/src/scenes/settings/environment/CookielessServerHashMode.tsx
+++ b/frontend/src/scenes/settings/environment/CookielessServerHashMode.tsx
@@ -1,45 +1,15 @@
import { useActions, useValues } from 'kea'
import { useState } from 'react'
-import { LemonBanner } from '@posthog/lemon-ui'
+import { LemonBanner, LemonSwitch } from '@posthog/lemon-ui'
import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'
import { TeamMembershipLevel } from 'lib/constants'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
-import { LemonRadio, LemonRadioOption } from 'lib/lemon-ui/LemonRadio'
import { teamLogic } from 'scenes/teamLogic'
import { CookielessServerHashMode } from '~/types'
-const options: LemonRadioOption<CookielessServerHashMode>[] = [
- {
- value: CookielessServerHashMode.Stateful,
- label: (
- <>
- <div>Enabled</div>
- </>
- ),
- },
- {
- value: CookielessServerHashMode.Stateless,
- label: (
- <>
- <div>Stateless</div>
- </>
- ),
- },
- {
- value: CookielessServerHashMode.Disabled,
- label: (
- <>
- <div>Disabled</div>
- </>
- ),
- },
-]
-
-const optionsToShowByDefault = [CookielessServerHashMode.Stateful, CookielessServerHashMode.Disabled]
-
export function CookielessServerHashModeSetting(): JSX.Element {
const { updateCurrentTeam } = useActions(teamLogic)
const { currentTeam } = useValues(teamLogic)
@@ -48,30 +18,38 @@ export function CookielessServerHashModeSetting(): JSX.Element {
minimumAccessLevel: TeamMembershipLevel.Admin,
})
- const savedSetting = currentTeam?.cookieless_server_hash_mode ?? CookielessServerHashMode.Disabled
- const [setting, setSetting] = useState<CookielessServerHashMode>(savedSetting)
-
- const handleChange = (newSetting: CookielessServerHashMode): void => {
- updateCurrentTeam({ cookieless_server_hash_mode: newSetting })
+ const savedEnabled =
+ (currentTeam?.cookieless_server_hash_mode ?? CookielessServerHashMode.Disabled) !==
+ CookielessServerHashMode.Disabled
+ const [enabled, setEnabled] = useState<boolean>(savedEnabled)
+
+ const handleSave = (): void => {
+ updateCurrentTeam({
+ cookieless_server_hash_mode: enabled
+ ? CookielessServerHashMode.Stateful
+ : CookielessServerHashMode.Disabled,
+ })
}
- const optionsToShow = options
- .filter((option) => optionsToShowByDefault.includes(option.value) || option.value === setting)
- .map((option) => ({ ...option, disabledReason: restrictedReason ?? undefined }))
-
return (
<>
<LemonBanner type="info" className="mb-4">
- When Cookieless server hash mode is enabled, IP-based transformations like GeoIP enrichment and bot
- detection will not enrich events. The IP is hashed into the distinct ID and stripped before
- transformations run.
+ When cookieless tracking is enabled, the IP address is hashed into the distinct ID and stripped before
+ transformations run, so IP-based transformations like GeoIP enrichment and bot detection will not enrich
+ those events.
</LemonBanner>
- <LemonRadio value={setting} onChange={setSetting} options={optionsToShow} />
+ <LemonSwitch
+ label="Enable cookieless tracking"
+ checked={enabled}
+ onChange={setEnabled}
+ disabledReason={restrictedReason}
+ data-attr="cookieless-tracking-toggle"
+ />
<div className="mt-4">
<LemonButton
type="primary"
- onClick={() => handleChange(setting)}
- disabledReason={setting === savedSetting ? 'No changes to save' : restrictedReason}
+ onClick={handleSave}
+ disabledReason={enabled === savedEnabled ? 'No changes to save' : restrictedReason}
>
Save
</LemonButton>
diff --git a/nodejs/src/ingestion/common/cookieless/cookieless-manager.test.ts b/nodejs/src/ingestion/common/cookieless/cookieless-manager.test.ts
index 6c2a3bd8e316..0b518eb74048 100644
--- a/nodejs/src/ingestion/common/cookieless/cookieless-manager.test.ts
+++ b/nodejs/src/ingestion/common/cookieless/cookieless-manager.test.ts
@@ -209,6 +209,12 @@ describe('CookielessManager', () => {
jest.clearAllTimers()
})
+ const clearRedis = async () => {
+ const client = await infra.redisPool.acquire()
+ await client.flushall()
+ await infra.redisPool.release(client)
+ }
+
const setModeForTeam = async (mode: CookielessServerHashMode) => {
await infra.postgres.query(
PostgresUse.COMMON_WRITE,
@@ -219,17 +225,11 @@ describe('CookielessManager', () => {
team = (await getTeam(infra.postgres, teamId))!
}
- const clearRedis = async () => {
- const client = await infra.redisPool.acquire()
- await client.flushall()
- await infra.redisPool.release(client)
- }
-
beforeEach(async () => {
await clearRedis()
infra.cookielessManager.deleteAllLocalSalts()
teamId = await createTeam(infra.postgres, organizationId)
- team = (await getTeam(infra.postgres, teamId))!
+ await setModeForTeam(CookielessServerHashMode.Stateful)
event = deepFreeze({
event: 'test event',
distinct_id: COOKIELESS_SENTINEL_VALUE,
@@ -360,14 +360,7 @@ describe('CookielessManager', () => {
}
}
- // tests that are shared between both modes
- describe.each([
- ['stateless', CookielessServerHashMode.Stateless],
- ['stateful', CookielessServerHashMode.Stateful],
- ])('common (%s)', (_, mode) => {
- beforeEach(async () => {
- await setModeForTeam(mode)
- })
+ describe('common behavior', () => {
it('should give an event a distinct id and session id ', async () => {
const actual = await processEvent(event)
@@ -461,90 +454,7 @@ describe('CookielessManager', () => {
})
})
- describe('stateless', () => {
- beforeEach(async () => {
- await setModeForTeam(CookielessServerHashMode.Stateless)
- })
-
- it('should provide the same session ID for events within the same day, later than the session timeout', async () => {
- // this is actually a limitation of this mode, but we have the same test (with a different outcome) for stateful mode
-
- const actual1 = await processEvent(event)
- const actual2 = await processEvent(eventMuchLater)
-
- if (!actual1?.properties || !actual2?.properties) {
- throw new Error('no event or properties')
- }
- expect(actual2.distinct_id).toEqual(actual1.distinct_id)
- expect(actual1.properties.$session_id).toBeDefined()
- expect(actual2.properties.$session_id).toEqual(actual1.properties.$session_id)
- })
-
- it('should drop identify events', async () => {
- // this is also a limitation of this mode
- const actual1 = await processEvent(identifyEvent)
- expect(actual1).toBeUndefined()
- })
-
- it('should work even if redis is cleared (as it can use the local cache)', async () => {
- const actual1 = await processEvent(event)
- await clearRedis()
- const actual2 = await processEvent(eventABitLater)
-
- if (!actual1?.properties || !actual2?.properties) {
- throw new Error('no event or properties')
- }
- expect(actual2.distinct_id).toEqual(actual1.distinct_id)
- expect(actual1.properties.$session_id).toBeDefined()
- expect(actual2.properties.$session_id).toEqual(actual1.properties.$session_id)
- })
-
- it('should preserve headers through cookieless processing', async () => {
- const testHeaders = createTestEventHeaders({
- token: 'test-token',
- distinct_id: 'test-distinct-id',
- timestamp: '1234567890',
- })
-
- const result = await processEventWithHeaders(event, testHeaders)
-
- expect(result.headers).toEqual(testHeaders)
- expect(result.event).toBeDefined()
- })
-
- it('should preserve headers for non-cookieless events', async () => {
- const testHeaders = createTestEventHeaders({
- token: 'test-token',
- distinct_id: 'test-distinct-id',
- timestamp: '1234567890',
- })
-
- const result = await processEventWithHeaders(nonCookielessEvent, testHeaders)
-
- expect(result.headers).toEqual(testHeaders)
- expect(result.event).toBe(nonCookielessEvent)
- })
-
- it('should not return dropped events but should not throw', async () => {
- const testHeaders = createTestEventHeaders({
- token: 'test-token',
- distinct_id: 'test-distinct-id',
- timestamp: '1234567890',
- })
-
- // Test with alias event which should be dropped
- const result = await processEventWithHeaders(aliasEvent, testHeaders)
-
- // Dropped events are not returned in the response array
- expect(result.event).toBeUndefined()
- expect(result.headers).toEqual(createTestEventHeaders())
- })
- })
-
- describe('stateful', () => {
- beforeEach(async () => {
- await setModeForTeam(CookielessServerHashMode.Stateful)
- })
+ describe('stateful behavior', () => {
it('should provide a different session ID after session timeout', async () => {
const actual1 = await processEvent(event)
const actual2 = await processEvent(eventMuchLater)
@@ -756,12 +666,34 @@ describe('CookielessManager', () => {
expect(anonResult.value.event.distinct_id).toEqual(baselineDistinctId)
}
})
- })
- describe('timestamp out of range', () => {
- beforeEach(async () => {
- await setModeForTeam(CookielessServerHashMode.Stateful)
+
+ it('should preserve headers through cookieless processing', async () => {
+ const testHeaders = createTestEventHeaders({
+ token: 'test-token',
+ distinct_id: 'test-distinct-id',
+ timestamp: '1234567890',
+ })
+
+ const result = await processEventWithHeaders(event, testHeaders)
+
+ expect(result.headers).toEqual(testHeaders)
+ expect(result.event).toBeDefined()
})
+ it('should preserve headers for non-cookieless events', async () => {
+ const testHeaders = createTestEventHeaders({
+ token: 'test-token',
+ distinct_id: 'test-distinct-id',
+ timestamp: '1234567890',
+ })
+
+ const result = await processEventWithHeaders(nonCookielessEvent, testHeaders)
+
+ expect(result.headers).toEqual(testHeaders)
+ expect(result.event).toBe(nonCookielessEvent)
+ })
+ })
+ describe('timestamp out of range', () => {
it('should drop only the event with out-of-range timestamp, not other events in batch', async () => {
// Create an event with a timestamp that's too old (more than 72h + timezone buffer in the past)
const oldTimestamp = new Date('2025-01-05T11:00:00Z') // 5 days before "now" (2025-01-10)
@@ -869,7 +801,7 @@ describe('CookielessManager', () => {
beforeEach(async () => {
await setModeForTeam(CookielessServerHashMode.Disabled)
})
- it('should drop all events', async () => {
+ it('should drop all cookieless events', async () => {
const actual1 = await processEvent(event)
expect(actual1).toBeUndefined()
})
@@ -890,25 +822,21 @@ describe('CookielessManager', () => {
expect(result.event).toBeUndefined()
expect(result.headers).toEqual(createTestEventHeaders())
})
- it('should preserve headers when passing through non-cookieless events', async () => {
- const testHeaders = createTestEventHeaders({
- token: 'test-token',
- distinct_id: 'test-distinct-id',
- timestamp: '1234567890',
- })
-
- const result = await processEventWithHeaders(nonCookielessEvent, testHeaders)
-
- expect(result.headers).toEqual(testHeaders)
- expect(result.event).toBe(nonCookielessEvent)
- })
})
-
- describe('ingestion warnings', () => {
+ describe('legacy stateless value', () => {
beforeEach(async () => {
- await setModeForTeam(CookielessServerHashMode.Stateful)
+ await setModeForTeam(CookielessServerHashMode.Stateless)
})
+ it('should process events as stateful, including $identify', async () => {
+ const actual = await processEvent(event)
+ expect(actual?.distinct_id).toMatch(/^cookieless_/)
+ // stateless mode used to drop $identify events; sunset means stateful handling
+ const identified = await processEvent(identifyEvent)
+ expect(identified).toBeDefined()
+ })
+ })
+ describe('ingestion warnings', () => {
it('should emit warning when timestamp is missing', async () => {
const eventWithoutTimestamp = deepFreeze({
...event,
diff --git a/nodejs/src/ingestion/common/cookieless/cookieless-manager.ts b/nodejs/src/ingestion/common/cookieless/cookieless-manager.ts
index 81055cd1dbcb..08c27d198f42 100644
--- a/nodejs/src/ingestion/common/cookieless/cookieless-manager.ts
+++ b/nodejs/src/ingestion/common/cookieless/cookieless-manager.ts
@@ -84,7 +84,6 @@ type SaltResult = { success: true; salt: Buffer } | { success: false; reason: 'd
interface CookielessConfig {
disabled: boolean
- forceStatelessMode: boolean
deleteExpiredLocalSaltsIntervalMs: number
identifiesTtlSeconds: number
sessionTtlSeconds: number
@@ -98,7 +97,6 @@ interface CookielessConfig {
export type CookielessManagerConfig = Pick<
IngestionConsumerConfig,
| 'COOKIELESS_DISABLED'
- | 'COOKIELESS_FORCE_STATELESS_MODE'
| 'COOKIELESS_DELETE_EXPIRED_LOCAL_SALTS_INTERVAL_MS'
| 'COOKIELESS_SESSION_TTL_SECONDS'
| 'COOKIELESS_SALT_TTL_SECONDS'
@@ -126,7 +124,6 @@ export class CookielessManager {
constructor(config: CookielessManagerConfig, redis: GenericPool<Redis.Redis>) {
this.config = {
disabled: config.COOKIELESS_DISABLED,
- forceStatelessMode: config.COOKIELESS_FORCE_STATELESS_MODE,
deleteExpiredLocalSaltsIntervalMs: config.COOKIELESS_DELETE_EXPIRED_LOCAL_SALTS_INTERVAL_MS,
sessionTtlSeconds: config.COOKIELESS_SESSION_TTL_SECONDS,
saltTtlSeconds: config.COOKIELESS_SALT_TTL_SECONDS,
@@ -351,14 +348,6 @@ export class CookielessManager {
results[i] = drop('cookieless_unsupported_event')
continue
}
- if (
- event.event === '$identify' &&
- team.cookieless_server_hash_mode === CookielessServerHashMode.Stateless
- ) {
- // $identify events are not supported in stateless cookieless mode, drop them
- results[i] = drop('cookieless_stateless_no_identify')
- continue
- }
if (
team.cookieless_server_hash_mode == null ||
@@ -368,6 +357,7 @@ export class CookielessManager {
results[i] = drop('cookieless_team_disabled')
continue
}
+
const timestamp = event.timestamp ?? event.sent_at ?? event.now
if (!timestamp) {
@@ -486,8 +476,8 @@ export class CookielessManager {
return results
}
- // Do a second pass to see what `identifiesRedisKey`s we need to load from redis for stateful events.
- // Fully process stateless events.
+ // Do a second pass to see what `identifiesRedisKey`s we need to load from redis.
+ // All events are processed as stateful.
const identifiesKeys = new Set<string>()
for (const eventWithProcessing of eventsWithStatus) {
const { team, firstPass } = eventWithProcessing
@@ -495,28 +485,9 @@ export class CookielessManager {
continue
}
- if (team.cookieless_server_hash_mode === CookielessServerHashMode.Stateful) {
- const identifiesRedisKey = getRedisIdentifiesKey(firstPass.baseHash, team.id)
- identifiesKeys.add(identifiesRedisKey)
- firstPass.secondPass = { identifiesRedisKey }
- } else {
- const { baseHash, timestampMs, eventTimeZone } = firstPass
- const distinctId = hashToDistinctId(baseHash)
- const deviceId = baseHashToDeviceId(baseHash)
- const sessionId = createStatelessSessionId(timestampMs, eventTimeZone, team.timezone, baseHash)
- const newProperties: Properties = {
- ...eventWithProcessing.event.properties,
- $distinct_id: distinctId,
- $device_id: deviceId,
- $session_id: sessionId,
- }
- eventWithProcessing.event = stripPIIProperties({
- ...eventWithProcessing.event,
- distinct_id: distinctId,
- properties: newProperties,
- })
- // the event is fully processed, no need to add create secondPass object
- }
+ const identifiesRedisKey = getRedisIdentifiesKey(firstPass.baseHash, team.id)
+ identifiesKeys.add(identifiesRedisKey)
+ firstPass.secondPass = { identifiesRedisKey }
}
// Fetch the identifies from redis and populate our in-memory cache
diff --git a/nodejs/src/ingestion/config.ts b/nodejs/src/ingestion/config.ts
index 7ab0f1b63177..7948384295a5 100644
--- a/nodejs/src/ingestion/config.ts
+++ b/nodejs/src/ingestion/config.ts
@@ -250,7 +250,6 @@ export type IngestionConsumerConfig = {
// Cookieless server hash mode config
COOKIELESS_DISABLED: boolean
- COOKIELESS_FORCE_STATELESS_MODE: boolean
COOKIELESS_DELETE_EXPIRED_LOCAL_SALTS_INTERVAL_MS: number
COOKIELESS_SESSION_TTL_SECONDS: number
COOKIELESS_SALT_TTL_SECONDS: number
@@ -391,7 +390,6 @@ export function getDefaultIngestionConsumerConfig(): IngestionConsumerConfig {
// Cookieless server hash mode config
COOKIELESS_DISABLED: false,
- COOKIELESS_FORCE_STATELESS_MODE: false,
COOKIELESS_DELETE_EXPIRED_LOCAL_SALTS_INTERVAL_MS: 60 * 60 * 1000,
COOKIELESS_SESSION_TTL_SECONDS: 60 * 60 * (72 + 24),
COOKIELESS_SALT_TTL_SECONDS: 60 * 60 * (72 + 24),
diff --git a/nodejs/src/ingestion/ingestion-consumer.test.ts b/nodejs/src/ingestion/ingestion-consumer.test.ts
index 9b09e0ce93db..2f5cec41f298 100644
--- a/nodejs/src/ingestion/ingestion-consumer.test.ts
+++ b/nodejs/src/ingestion/ingestion-consumer.test.ts
@@ -224,12 +224,6 @@ describe('IngestionConsumer', () => {
})
it('should process a cookieless event', async () => {
- await infra.postgres.query(
- PostgresUse.COMMON_WRITE,
- `UPDATE posthog_team SET cookieless_server_hash_mode = $1 WHERE id = $2`,
- [CookielessServerHashMode.Stateful, team.id],
- 'set cookieless to stateful'
- )
await ingester.handleKafkaBatch(createKafkaMessages([createCookielessEvent()]))
expect(forSnapshot(mockProducerObserver.getProducedKafkaMessages())).toMatchSnapshot()
diff --git a/posthog/api/test/test_team_project_differential.py b/posthog/api/test/test_team_project_differential.py
index f53d30f788ea..1b823ab0291d 100644
--- a/posthog/api/test/test_team_project_differential.py
+++ b/posthog/api/test/test_team_project_differential.py
@@ -184,7 +184,7 @@ FIELD_VALUES: dict[str, Any] = {
"primary_dashboard": "__PER_TWIN_DASHBOARD__", # special-cased: a dashboard belonging to each twin
"live_events_columns": ["event"],
"recording_domains": ["https://example.com"],
- "cookieless_server_hash_mode": 1,
+ "cookieless_server_hash_mode": 2,
"human_friendly_comparison_periods": True,
"inject_web_apps": True,
"extra_settings": {"foo": "bar"},
diff --git a/posthog/models/team/team.py b/posthog/models/team/team.py
index e19f2d790fc3..74b98d680b8c 100644
--- a/posthog/models/team/team.py
+++ b/posthog/models/team/team.py
@@ -601,6 +601,8 @@ class Team(UUIDTClassicModel):
human_friendly_comparison_periods = field_access_control(
models.BooleanField(default=False, null=True, blank=True), "project", "admin"
)
+ # Enable/disable toggle for cookieless ingestion. STATELESS (1) is sunset: any non-disabled
+ # value is processed as stateful.
cookieless_server_hash_mode = field_access_control(
models.SmallIntegerField(
default=CookielessServerHashMode.DISABLED,
diff --git a/products/ingestion/skills/resolving-ingestion-warnings/references/fixing-cookieless-warnings.md b/products/ingestion/skills/resolving-ingestion-warnings/references/fixing-cookieless-warnings.md
index 71c986979cb8..5565d8ca2b83 100644
--- a/products/ingestion/skills/resolving-ingestion-warnings/references/fixing-cookieless-warnings.md
+++ b/products/ingestion/skills/resolving-ingestion-warnings/references/fixing-cookieless-warnings.md
@@ -29,7 +29,7 @@ Which ingredient is missing points at which layer is broken:
- **`$ip` missing** → the capture path saw no client IP — a proxy/CDN in front of PostHog not passing the client address through, or middleware explicitly deleting `$ip` before the identity is computed.
- **timestamp missing** → server-side batching that strips timestamps.
- **timestamp out of range** → a historical import routed through cookieless (can't work, see below), badly skewed client clocks, or offline queues flushing much later.
-3. If cookieless events produce **no warnings and no events at all**, check the project setting first: cookieless server hash mode must be enabled on the team — with it disabled, sentinel events are dropped without a warning.
+3. If cookieless events produce **no warnings and no events at all**, check the project setting first: cookieless tracking must be enabled on the team (Settings → Web analytics → Cookieless tracking, stored as `cookieless_server_hash_mode`) — with it disabled, sentinel events are dropped without a warning.
## Fix
diff --git a/rust/common/cookieless/src/manager.rs b/rust/common/cookieless/src/manager.rs
index e9ea3a6399af..3f1cd961292e 100644
--- a/rust/common/cookieless/src/manager.rs
+++ b/rust/common/cookieless/src/manager.rs
@@ -49,8 +49,6 @@ pub enum CookielessManagerError {
pub struct CookielessConfig {
/// Whether cookieless mode is disabled
pub disabled: bool,
- /// Whether to force stateless mode
- pub force_stateless_mode: bool,
/// TTL for identifies (in seconds)
pub identifies_ttl_seconds: u64,
/// TTL for salts (in seconds)
@@ -61,7 +59,6 @@ impl Default for CookielessConfig {
fn default() -> Self {
Self {
disabled: false,
- force_stateless_mode: false,
identifies_ttl_seconds: IDENTIFIES_TTL_SECONDS,
salt_ttl_seconds: SALT_TTL_SECONDS,
}
@@ -113,27 +110,19 @@ pub struct EventData<'a> {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum CookielessServerHashMode {
Disabled = 0,
- Stateless = 1,
Stateful = 2,
}
impl From<i16> for CookielessServerHashMode {
fn from(value: i16) -> Self {
match value {
- 0 => Self::Disabled,
- 1 => Self::Stateless,
- 2 => Self::Stateful,
- _ => Self::Disabled, // Default to disabled for unknown values
+ // 1 was stateless mode, now sunset: any enabled value is processed as stateful
+ 1 | 2 => Self::Stateful,
+ _ => Self::Disabled,
}
}
}
-impl From<CookielessServerHashMode> for i16 {
- fn from(mode: CookielessServerHashMode) -> Self {
- mode as i16
- }
-}
-
/// Team information required for cookieless distinct ID computation
#[derive(Debug, Clone)]
pub struct TeamData {
@@ -183,7 +172,7 @@ impl CookielessManager {
event_data: EventData<'_>,
team_data: TeamData,
) -> Result<String, CookielessManagerError> {
- // If cookieless mode is disabled or team's hash mode is Disabled, return the original distinct id
+ // If cookieless mode is globally disabled or the team hasn't enabled it, return the original distinct id
if self.config.disabled
|| team_data.cookieless_server_hash_mode == CookielessServerHashMode::Disabled
{
@@ -224,11 +213,6 @@ impl CookielessManager {
// Compute the base hash
let base_hash = self.do_hash_for_day(hash_params.clone()).await?;
- // If we're in stateless mode, use the base hash directly
- if self.config.force_stateless_mode {
- return Ok(Self::hash_to_distinct_id(&base_hash));
- }
-
// Get the number of identify events for this hash
let n = self
.get_identify_count(&base_hash, team_data.team_id)
@@ -292,11 +276,6 @@ impl CookielessManager {
hash: &[u8],
team_id: TeamId,
) -> Result<u64, CookielessManagerError> {
- // If we're in stateless mode, always return 0
- if self.config.force_stateless_mode {
- return Ok(0);
- }
-
// Get the Redis key for the identify count
let redis_key = get_redis_identifies_key(hash, team_id);
@@ -571,7 +550,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await
@@ -597,7 +576,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await
@@ -650,7 +629,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await
@@ -661,7 +640,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await
@@ -703,7 +682,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await
@@ -729,7 +708,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await
@@ -739,6 +718,37 @@ mod tests {
assert_eq!(result, "non_sentinel_id");
}
+ #[tokio::test]
+ async fn test_compute_cookieless_distinct_id_team_disabled() {
+ let redis_client = Arc::new(MockRedisClient::new());
+ let manager = CookielessManager::new(CookielessConfig::default(), redis_client);
+
+ let event_data = EventData {
+ ip: "127.0.0.1",
+ timestamp_ms: Utc::now().timestamp_millis() as u64,
+ host: "example.com",
+ user_agent: "Mozilla/5.0",
+ event_time_zone: None,
+ hash_extra: None,
+ distinct_id: COOKIELESS_SENTINEL_VALUE,
+ };
+
+ let result = manager
+ .compute_cookieless_distinct_id(
+ event_data,
+ TeamData {
+ team_id: 1,
+ timezone: "UTC".to_string(),
+ cookieless_server_hash_mode: CookielessServerHashMode::Disabled,
+ },
+ )
+ .await
+ .unwrap();
+
+ // A team that hasn't enabled cookieless keeps the sentinel untouched
+ assert_eq!(result, COOKIELESS_SENTINEL_VALUE);
+ }
+
#[tokio::test]
async fn test_compute_cookieless_distinct_id_missing_fields() {
// Create a mock Redis client
@@ -764,7 +774,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await;
@@ -789,7 +799,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await;
@@ -814,7 +824,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await;
@@ -866,24 +876,6 @@ mod tests {
assert_eq!(count, 0);
}
- #[tokio::test]
- async fn test_get_identify_count_stateless_mode() {
- // Create a mock Redis client
- let redis_client = Arc::new(MockRedisClient::new());
-
- // Create a CookielessManager with force_stateless_mode=true
- let config = CookielessConfig {
- force_stateless_mode: true,
- ..CookielessConfig::default()
- };
- let manager = CookielessManager::new(config, redis_client);
-
- // Get the identify count
- let hash = vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16];
- let count = manager.get_identify_count(&hash, 1).await.unwrap();
- assert_eq!(count, 0);
- }
-
#[tokio::test]
async fn test_compute_cookieless_distinct_id_with_identifies() {
// Create a mock Redis client
@@ -964,51 +956,6 @@ mod tests {
assert_eq!(result, expected_distinct_id);
}
- #[tokio::test]
- async fn test_compute_cookieless_distinct_id_stateless_mode() {
- // Create a mock Redis client
- let mut mock_redis = MockRedisClient::new();
- let salt_base64 = "AAAAAAAAAAAAAAAAAAAAAA=="; // 16 bytes of zeros
- let today = Utc::now().format("%Y-%m-%d").to_string();
- let redis_key = format!("cookieless_salt:{today}");
- mock_redis = mock_redis.get_ret(&redis_key, Ok(salt_base64.to_string()));
- let redis_client = Arc::new(mock_redis);
-
- // Create a CookielessManager with force_stateless_mode=true
- let config = CookielessConfig {
- force_stateless_mode: true,
- ..CookielessConfig::default()
- };
- let manager = CookielessManager::new(config, redis_client);
-
- // Create an event
- let event_data = EventData {
- ip: "127.0.0.1",
- timestamp_ms: Utc::now().timestamp_millis() as u64,
- host: "example.com",
- user_agent: "Mozilla/5.0",
- event_time_zone: None,
- hash_extra: None,
- distinct_id: COOKIELESS_SENTINEL_VALUE,
- };
-
- // Process the event
- let result = manager
- .compute_cookieless_distinct_id(
- event_data,
- TeamData {
- team_id: 1,
- timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
- },
- )
- .await
- .unwrap();
-
- // Check that we got a distinct ID
- assert!(result.starts_with(COOKIELESS_DISTINCT_ID_PREFIX));
- }
-
#[test]
fn test_key_generation_functions() {
// Read the test cases from the JSON file
@@ -1076,7 +1023,7 @@ mod tests {
TeamData {
team_id: 1,
timezone: "UTC".to_string(),
- cookieless_server_hash_mode: CookielessServerHashMode::Stateless,
+ cookieless_server_hash_mode: CookielessServerHashMode::Stateful,
},
)
.await
diff --git a/rust/feature-flags/src/config.rs b/rust/feature-flags/src/config.rs
index 0e1bdc4aa774..c96c071faab5 100644
--- a/rust/feature-flags/src/config.rs
+++ b/rust/feature-flags/src/config.rs
@@ -646,9 +646,6 @@ pub struct Config {
#[envconfig(from = "COOKIELESS_DISABLED", default = "false")]
pub cookieless_disabled: bool,
- #[envconfig(from = "COOKIELESS_FORCE_STATELESS", default = "false")]
- pub cookieless_force_stateless: bool,
-
#[envconfig(from = "COOKIELESS_IDENTIFIES_TTL_SECONDS", default = "345600")]
pub cookieless_identifies_ttl_seconds: u64,
@@ -1105,7 +1102,6 @@ impl Config {
group_type_cache_ttl_seconds: 300,
group_type_cache_max_entries: 50_000,
cookieless_disabled: false,
- cookieless_force_stateless: false,
cookieless_identifies_ttl_seconds: 345600,
cookieless_salt_ttl_seconds: 345600,
cookieless_redis_host: "localhost".to_string(),
@@ -1224,7 +1220,6 @@ impl Config {
pub fn get_cookieless_config(&self) -> CookielessConfig {
CookielessConfig {
disabled: self.cookieless_disabled,
- force_stateless_mode: self.cookieless_force_stateless,
identifies_ttl_seconds: self.cookieless_identifies_ttl_seconds,
salt_ttl_seconds: self.cookieless_salt_ttl_seconds,
}