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(retention): differentiate events data retention by plan (#64111)

Sandy Spicer3b6a9d010c12
diff --git a/frontend/src/generated/core/api.schemas.ts b/frontend/src/generated/core/api.schemas.ts
index 80d5c31db294..96f999deb8aa 100644
--- a/frontend/src/generated/core/api.schemas.ts
+++ b/frontend/src/generated/core/api.schemas.ts
@@ -1762,6 +1762,10 @@ export interface ProjectBackwardCompatApi {
onboarding_tasks?: unknown
/** @nullable */
web_analytics_pre_aggregated_tables_enabled?: boolean | null
+ /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. */
+ readonly event_retention_months: number
+ /** Whether events data retention is currently enforced for this team (cohort/flag gated). */
+ readonly events_retention_enforced: boolean
}
export type PatchedProjectBackwardCompatApiGroupTypesItem = { [key: string]: unknown }
@@ -2610,6 +2614,10 @@ export interface PatchedProjectBackwardCompatApi {
onboarding_tasks?: unknown
/** @nullable */
web_analytics_pre_aggregated_tables_enabled?: boolean | null
+ /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. */
+ readonly event_retention_months?: number
+ /** Whether events data retention is currently enforced for this team (cohort/flag gated). */
+ readonly events_retention_enforced?: boolean
}
export interface SharePasswordApi {
diff --git a/frontend/src/lib/api.mock.ts b/frontend/src/lib/api.mock.ts
index d683d702107d..07ead6ba54e8 100644
--- a/frontend/src/lib/api.mock.ts
+++ b/frontend/src/lib/api.mock.ts
@@ -89,6 +89,8 @@ export const MOCK_DEFAULT_TEAM: TeamType = {
maskAllInputs: true,
},
session_recording_retention_period: '30d',
+ event_retention_months: 84,
+ events_retention_enforced: false,
session_replay_config: null,
capture_console_log_opt_in: true,
capture_performance_opt_in: true,
diff --git a/frontend/src/scenes/insights/InsightAsScene.tsx b/frontend/src/scenes/insights/InsightAsScene.tsx
index c6e05ebbd08e..99693042b4d6 100644
--- a/frontend/src/scenes/insights/InsightAsScene.tsx
+++ b/frontend/src/scenes/insights/InsightAsScene.tsx
@@ -15,6 +15,7 @@ import { containsHogQLQuery, isDataVisualizationNode, isInsightVizNode } from '~
import { InsightShortId, ItemMode } from '~/types'
import { teamLogic } from '../teamLogic'
+import { InsightRetentionBanner } from './dataRetention/InsightRetentionBanner'
import { insightDataLogic } from './insightDataLogic'
import { insightLogic } from './insightLogic'
import { InsightSceneHeader } from './InsightSceneHeader'
@@ -86,6 +87,8 @@ export function InsightAsScene({ insightId, attachTo }: InsightAsSceneProps): JS
<InsightSceneHeader insightLogicProps={insightProps} />
)}
+ <InsightRetentionBanner insightProps={insightProps} />
+
{isDataVisualizationNode(query) && insightLoading ? (
// Avoid painting the stale chart type during a reload (the query re-syncs in insightDataLogic).
<LemonSkeleton className="h-100 w-full" />
diff --git a/frontend/src/scenes/insights/dataRetention/InsightRetentionBanner.tsx b/frontend/src/scenes/insights/dataRetention/InsightRetentionBanner.tsx
new file mode 100644
index 000000000000..2a75e4dc4e04
--- /dev/null
+++ b/frontend/src/scenes/insights/dataRetention/InsightRetentionBanner.tsx
@@ -0,0 +1,30 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonBanner } from 'lib/lemon-ui/LemonBanner'
+import { urls } from 'scenes/urls'
+
+import { InsightLogicProps } from '~/types'
+
+import { dataRetentionBannerLogic } from './dataRetentionBannerLogic'
+import { insightRetentionBannerLogic } from './insightRetentionBannerLogic'
+
+export function InsightRetentionBanner({ insightProps }: { insightProps: InsightLogicProps }): JSX.Element | null {
+ const { shouldShowBanner } = useValues(insightRetentionBannerLogic(insightProps))
+ const { retentionPeriodLabel } = useValues(dataRetentionBannerLogic)
+ const { snooze } = useActions(dataRetentionBannerLogic)
+
+ if (!shouldShowBanner || !retentionPeriodLabel) {
+ return null
+ }
+
+ return (
+ <LemonBanner
+ type="warning"
+ onClose={snooze}
+ action={{ children: 'Upgrade to unlock past data', to: urls.organizationBilling() }}
+ >
+ This insight has the potential to go back further than your {retentionPeriodLabel} of events data retention.
+ Older events aren't included in the results.
+ </LemonBanner>
+ )
+}
diff --git a/frontend/src/scenes/insights/dataRetention/dataRetentionBannerLogic.ts b/frontend/src/scenes/insights/dataRetention/dataRetentionBannerLogic.ts
new file mode 100644
index 000000000000..734b23f11bf0
--- /dev/null
+++ b/frontend/src/scenes/insights/dataRetention/dataRetentionBannerLogic.ts
@@ -0,0 +1,80 @@
+import { actions, connect, kea, path, reducers, selectors } from 'kea'
+
+import { dayjs } from 'lib/dayjs'
+import { organizationLogic } from 'scenes/organizationLogic'
+import { teamLogic } from 'scenes/teamLogic'
+
+import { TeamType } from '~/types'
+
+import type { dataRetentionBannerLogicType } from './dataRetentionBannerLogicType'
+
+const SNOOZE_DAYS = 30
+// Don't nag accounts that can't yet have at-risk data: only warn once the account is within 90 days of its
+// retention horizon (or past it).
+const WARN_WITHIN_DAYS = 90
+
+// Humanize a retention window in months: whole years read as "N year(s)", otherwise "N month(s)".
+function retentionMonthsLabel(months: number): string {
+ if (months % 12 === 0) {
+ const years = months / 12
+ return `${years} year${years === 1 ? '' : 's'}`
+ }
+ return `${months} month${months === 1 ? '' : 's'}`
+}
+
+// Global (per-browser) snooze + plan-derived eligibility for the events data-retention warning. The per-insight
+// "does this query's range exceed retention" check lives in insightRetentionBannerLogic; this one stays a singleton
+// so the snooze is shared across every insight rather than dismissed once per insight.
+export const dataRetentionBannerLogic = kea<dataRetentionBannerLogicType>([
+ path(['scenes', 'insights', 'dataRetention', 'dataRetentionBannerLogic']),
+ connect({
+ values: [teamLogic, ['currentTeam'], organizationLogic, ['currentOrganization']],
+ }),
+ actions({
+ snooze: true,
+ }),
+ reducers({
+ snoozedUntil: [
+ null as string | null,
+ { persist: true },
+ {
+ snooze: () => dayjs().add(SNOOZE_DAYS, 'day').toISOString(),
+ },
+ ],
+ }),
+ selectors({
+ retentionEnforced: [
+ (s) => [s.currentTeam],
+ (currentTeam): boolean => !!(currentTeam as TeamType | null)?.events_retention_enforced,
+ ],
+ retentionMonths: [
+ (s) => [s.currentTeam],
+ (currentTeam): number | null => (currentTeam as TeamType | null)?.event_retention_months ?? null,
+ ],
+ retentionPeriodLabel: [
+ (s) => [s.retentionMonths],
+ (retentionMonths): string | null => (retentionMonths ? retentionMonthsLabel(retentionMonths) : null),
+ ],
+ isSnoozed: [
+ (s) => [s.snoozedUntil],
+ (snoozedUntil): boolean => !!snoozedUntil && dayjs(snoozedUntil).isAfter(dayjs()),
+ ],
+ accountAgeEligible: [
+ (s) => [s.currentOrganization, s.retentionMonths],
+ (currentOrganization, retentionMonths): boolean => {
+ if (!currentOrganization?.created_at || !retentionMonths) {
+ return false
+ }
+ // Eligible once the account is old enough to have data within 90 days of (or past) its retention
+ // horizon — i.e. created before now − retention + 90 days.
+ const horizon = dayjs().subtract(retentionMonths, 'month').add(WARN_WITHIN_DAYS, 'day')
+ return dayjs(currentOrganization.created_at).isBefore(horizon)
+ },
+ ],
+ warningEligible: [
+ (s) => [s.retentionEnforced, s.accountAgeEligible, s.isSnoozed],
+ (retentionEnforced, accountAgeEligible, isSnoozed): boolean =>
+ retentionEnforced && accountAgeEligible && !isSnoozed,
+ ],
+ }),
+])
diff --git a/frontend/src/scenes/insights/dataRetention/insightRetentionBannerLogic.ts b/frontend/src/scenes/insights/dataRetention/insightRetentionBannerLogic.ts
new file mode 100644
index 000000000000..473030b01f0c
--- /dev/null
+++ b/frontend/src/scenes/insights/dataRetention/insightRetentionBannerLogic.ts
@@ -0,0 +1,58 @@
+import { connect, kea, key, path, props, selectors } from 'kea'
+
+import { dayjs } from 'lib/dayjs'
+import { insightDataLogic } from 'scenes/insights/insightDataLogic'
+import { insightVizDataLogic } from 'scenes/insights/insightVizDataLogic'
+import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
+
+import { isDataVisualizationNode, isHogQLQuery } from '~/queries/utils'
+import { InsightLogicProps } from '~/types'
+
+import { dataRetentionBannerLogic } from './dataRetentionBannerLogic'
+import type { insightRetentionBannerLogicType } from './insightRetentionBannerLogicType'
+
+// Per-insight half of the retention warning: does this insight's range reach past the team's retention window?
+// "All time" is treated as exceeding (it resolves to the earliest event, so a team with only recent data wouldn't
+// otherwise trip it); every other range uses the resolved date range straight from the query response.
+export const insightRetentionBannerLogic = kea<insightRetentionBannerLogicType>([
+ props({} as InsightLogicProps),
+ key(keyForInsightLogicProps('new')),
+ path((key) => ['scenes', 'insights', 'dataRetention', 'insightRetentionBannerLogic', key]),
+ connect((props: InsightLogicProps) => ({
+ values: [
+ dataRetentionBannerLogic,
+ ['warningEligible', 'retentionMonths'],
+ insightDataLogic(props),
+ ['insightData', 'query'],
+ insightVizDataLogic(props),
+ ['dateRange'],
+ ],
+ })),
+ selectors({
+ rangeExceedsRetention: [
+ (s) => [s.dateRange, s.insightData, s.retentionMonths, s.query],
+ (dateRange, insightData, retentionMonths, query): boolean => {
+ if (!retentionMonths) {
+ return false
+ }
+ // SQL/HogQL insights can scan arbitrary history with no resolvable range, so warn whenever eligible.
+ if (query && (isHogQLQuery(query) || (isDataVisualizationNode(query) && isHogQLQuery(query.source)))) {
+ return true
+ }
+ // "All time" is an unbounded intent: warn even when the team's data doesn't yet reach that far back.
+ if (dateRange?.date_from === 'all') {
+ return true
+ }
+ const dateFrom = insightData?.resolved_date_range?.date_from
+ if (!dateFrom) {
+ return false
+ }
+ return dayjs(dateFrom).isBefore(dayjs().subtract(retentionMonths, 'month'))
+ },
+ ],
+ shouldShowBanner: [
+ (s) => [s.warningEligible, s.rangeExceedsRetention],
+ (warningEligible, rangeExceedsRetention): boolean => warningEligible && rangeExceedsRetention,
+ ],
+ }),
+])
diff --git a/frontend/src/scenes/team-activity/teamActivityDescriber.tsx b/frontend/src/scenes/team-activity/teamActivityDescriber.tsx
index e8bc6f8bfe12..99390c5b231e 100644
--- a/frontend/src/scenes/team-activity/teamActivityDescriber.tsx
+++ b/frontend/src/scenes/team-activity/teamActivityDescriber.tsx
@@ -754,6 +754,8 @@ const TEAM_PROPERTIES_MAPPING: Record<keyof TeamType, (change: ActivityChange) =
web_analytics_pre_aggregated_tables_version: () => null,
managed_viewsets: () => null,
workflows_config: () => null,
+ event_retention_months: () => null,
+ events_retention_enforced: () => null,
}
function nameAndLink(logItem?: ActivityLogItem): JSX.Element {
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index d2829eb51674..8d2e025f56de 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -787,6 +787,10 @@ export interface TeamType extends TeamBasicType {
| null
session_recording_masking_config: SessionRecordingMaskingConfig | undefined | null
session_recording_retention_period: SessionRecordingRetentionPeriod | null
+ /** Plan-derived events data retention window in months (synced from billing). */
+ event_retention_months: number
+ /** Whether events data retention is currently enforced for this team (cohort/flag gated). */
+ events_retention_enforced: boolean
session_replay_config: { record_canvas?: boolean } | undefined | null
survey_config?: TeamSurveyConfigType
logs_settings?: LogsSettings | null
diff --git a/posthog/api/project.py b/posthog/api/project.py
index f2a014af8f8a..b62c3f5c2676 100644
--- a/posthog/api/project.py
+++ b/posthog/api/project.py
@@ -68,6 +68,7 @@ from posthog.models.product_intent.product_intent import (
calculate_product_activation,
)
from posthog.models.project import Project
+from posthog.models.team.event_retention import should_enforce_events_retention
from posthog.models.team.extensions import get_or_create_team_extension
from posthog.models.team.setup_tasks import SetupTaskId
from posthog.models.team.team import CURRENCY_CODE_CHOICES, Team
@@ -570,6 +571,9 @@ class ProjectBackwardCompatSerializer(
product_intents = serializers.SerializerMethodField() # Compat with TeamSerializer
available_setup_task_ids = serializers.SerializerMethodField() # Compat with TeamSerializer
managed_viewsets = serializers.SerializerMethodField() # Compat with TeamSerializer
+ events_retention_enforced = serializers.SerializerMethodField(
+ help_text="Whether events data retention is currently enforced for this team (cohort/flag gated)."
+ ) # Compat with TeamSerializer
# These are @property attrs on Team, not Django model fields — declare explicitly so drf-spectacular can resolve them
default_modifiers = serializers.DictField(read_only=True) # Compat with TeamSerializer
person_on_events_querying_enabled = serializers.BooleanField(read_only=True) # Compat with TeamSerializer
@@ -695,6 +699,8 @@ class ProjectBackwardCompatSerializer(
"default_data_theme", # Compat with TeamSerializer
"onboarding_tasks", # Compat with TeamSerializer
"web_analytics_pre_aggregated_tables_enabled", # Compat with TeamSerializer
+ "event_retention_months", # Compat with TeamSerializer
+ "events_retention_enforced", # Compat with TeamSerializer
)
read_only_fields = (
"id",
@@ -718,6 +724,7 @@ class ProjectBackwardCompatSerializer(
"project_id",
"user_access_level",
"managed_viewsets",
+ "event_retention_months",
)
team_passthrough_fields = {
@@ -794,6 +801,7 @@ class ProjectBackwardCompatSerializer(
"marketing_analytics_config",
"customer_analytics_config",
"workflows_config",
+ "event_retention_months",
}
# help_text entries flow into the generated OpenAPI spec, frontend types, and MCP tool schemas.
@@ -841,6 +849,12 @@ class ProjectBackwardCompatSerializer(
"How long to retain new session recordings. One of `30d`, `90d`, `1y`, or `5y` (availability depends on plan)."
)
},
+ "event_retention_months": {
+ "help_text": (
+ "The team's events data retention window in months (plan-derived, synced from billing). When "
+ "retention enforcement is active for the team, queries do not return events older than this many months."
+ )
+ },
"data_attributes": {
"help_text": (
"Element attributes that posthog-js should capture as action identifiers (e.g. `['data-attr']`)."
@@ -895,6 +909,10 @@ class ProjectBackwardCompatSerializer(
)
return {kind: (kind in enabled_set) for kind, _ in DataWarehouseManagedViewSetKind.choices}
+ @extend_schema_field(serializers.BooleanField())
+ def get_events_retention_enforced(self, obj: Project) -> bool:
+ return should_enforce_events_retention(obj.passthrough_team.id)
+
@staticmethod
def validate_revenue_analytics_config(value):
return TeamSerializer.validate_revenue_analytics_config(value)
diff --git a/posthog/api/team.py b/posthog/api/team.py
index 5d150dac566c..64257a9ff0d7 100644
--- a/posthog/api/team.py
+++ b/posthog/api/team.py
@@ -52,6 +52,7 @@ from posthog.models.product_intent.product_intent import (
enqueue_product_activation_calc_debounced,
)
from posthog.models.project import Project
+from posthog.models.team.event_retention import should_enforce_events_retention
from posthog.models.team.extensions import get_or_create_team_extension
from posthog.models.team.setup_tasks import SetupTaskId
from posthog.models.team.team import CURRENCY_CODE_CHOICES, DEFAULT_CURRENCY
@@ -720,6 +721,16 @@ class TeamSerializer(serializers.ModelSerializer, UserPermissionsSerializerMixin
customer_analytics_config = TeamCustomerAnalyticsConfigSerializer(required=False)
workflows_config = TeamWorkflowsConfigSerializer(required=False)
base_currency = serializers.ChoiceField(choices=CURRENCY_CODE_CHOICES, default=DEFAULT_CURRENCY)
+ event_retention_months = serializers.IntegerField(
+ read_only=True,
+ help_text=(
+ "The team's events data retention window in months (plan-derived, synced from billing). When retention "
+ "enforcement is active for the team, queries do not return events older than this many months."
+ ),
+ )
+ events_retention_enforced = serializers.SerializerMethodField(
+ help_text="Whether events data retention is currently enforced for this team (cohort/flag gated)."
+ )
class Meta:
model = Team
@@ -749,6 +760,8 @@ class TeamSerializer(serializers.ModelSerializer, UserPermissionsSerializerMixin
"product_intents",
"managed_viewsets",
"available_setup_task_ids",
+ "event_retention_months",
+ "events_retention_enforced",
)
read_only_fields = (
@@ -797,6 +810,11 @@ class TeamSerializer(serializers.ModelSerializer, UserPermissionsSerializerMixin
def get_group_types(self, team: Team) -> list[dict[str, Any]]:
return cached_group_types_for_team(team)
+ @extend_schema_field(serializers.BooleanField())
+ @tracer.start_as_current_span("team_serializer.events_retention_enforced")
+ def get_events_retention_enforced(self, team: Team) -> bool:
+ return should_enforce_events_retention(team.id)
+
@tracer.start_as_current_span("team_serializer.live_events_token")
def get_live_events_token(self, team: Team) -> str | None:
request = self.context.get("request")
diff --git a/posthog/api/test/__snapshots__/test_element.ambr b/posthog/api/test/__snapshots__/test_element.ambr
index 358e7d2b2438..9ec5256363de 100644
--- a/posthog/api/test/__snapshots__/test_element.ambr
+++ b/posthog/api/test/__snapshots__/test_element.ambr
@@ -122,6 +122,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -327,6 +328,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/posthog/api/test/__snapshots__/test_preflight.ambr b/posthog/api/test/__snapshots__/test_preflight.ambr
index 9e70e737dff6..bb8582adc47a 100644
--- a/posthog/api/test/__snapshots__/test_preflight.ambr
+++ b/posthog/api/test/__snapshots__/test_preflight.ambr
@@ -122,6 +122,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
index 655a2074679d..e81b9a6490f2 100644
--- a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
+++ b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr
@@ -154,6 +154,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -281,6 +282,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -419,6 +421,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -521,6 +524,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -660,6 +664,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -822,6 +827,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -988,6 +994,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1090,6 +1097,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1299,6 +1307,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1627,6 +1636,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1826,6 +1836,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2133,6 +2144,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2294,6 +2306,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2753,6 +2766,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -3014,6 +3028,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -3546,6 +3561,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4102,6 +4118,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4240,6 +4257,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4342,6 +4360,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4481,6 +4500,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4671,6 +4691,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4773,6 +4794,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4911,6 +4933,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -5092,6 +5115,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -5264,6 +5288,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -5592,6 +5617,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -5791,6 +5817,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -6119,6 +6146,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -6523,6 +6551,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -6737,6 +6766,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -6918,6 +6948,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -7090,6 +7121,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -7378,6 +7410,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -7577,6 +7610,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -7856,6 +7890,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -7983,6 +8018,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -8121,6 +8157,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -8223,6 +8260,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -8362,6 +8400,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -8571,6 +8610,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -8673,6 +8713,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -8854,6 +8895,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -9026,6 +9068,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -9310,6 +9353,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -9509,6 +9553,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -9795,6 +9840,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -9922,6 +9968,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -10060,6 +10107,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -10162,6 +10210,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -10301,6 +10350,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -10507,6 +10557,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -10609,6 +10660,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -10790,6 +10842,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -11008,6 +11061,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -11315,6 +11369,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -11592,6 +11647,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -11791,6 +11847,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -12142,6 +12199,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -12646,6 +12704,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -12858,6 +12917,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -13318,6 +13378,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -13570,6 +13631,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -14109,6 +14171,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -14604,6 +14667,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -14805,6 +14869,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -15113,6 +15178,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -15525,6 +15591,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -15640,6 +15707,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -15839,6 +15907,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -16205,6 +16274,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -16332,6 +16402,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -16470,6 +16541,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -16572,6 +16644,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -16711,6 +16784,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -16914,6 +16988,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -17016,6 +17091,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -17155,6 +17231,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -17345,6 +17422,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -17447,6 +17525,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -17636,6 +17715,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -17808,6 +17888,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -18101,6 +18182,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -18300,6 +18382,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -18567,6 +18650,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -18669,6 +18753,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -18796,6 +18881,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -18934,6 +19020,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -19036,6 +19123,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -19175,6 +19263,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -19365,6 +19454,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -19661,6 +19751,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -19999,6 +20090,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -20211,6 +20303,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -20969,6 +21062,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -21168,6 +21262,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -21595,6 +21690,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -21955,6 +22051,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -22135,6 +22232,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -22334,6 +22432,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -22535,6 +22634,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -22843,6 +22943,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -23255,6 +23356,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -23370,6 +23472,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -23569,6 +23672,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -24157,6 +24261,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr b/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr
index 923e53130632..3bc75aae3890 100644
--- a/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr
+++ b/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr
@@ -164,6 +164,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -377,6 +378,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -557,6 +559,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -796,6 +799,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -898,6 +902,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1300,6 +1305,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1513,6 +1519,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1808,6 +1815,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/posthog/constants.py b/posthog/constants.py
index b825bdc623c5..191583ecfc0a 100644
--- a/posthog/constants.py
+++ b/posthog/constants.py
@@ -47,6 +47,7 @@ class AvailableFeature(StrEnum):
ORGANIZATION_SECURITY_SETTINGS = "organization_security_settings"
ORGANIZATION_APP_QUERY_CONCURRENCY_LIMIT = "organization_app_query_concurrency_limit"
SESSION_REPLAY_DATA_RETENTION = "session_replay_data_retention"
+ PRODUCT_ANALYTICS_DATA_RETENTION = "product_analytics_data_retention"
AUDIT_LOGS = "audit_logs"
APPROVALS = "approvals"
XAA_AUTHENTICATION = "xaa_authentication"
diff --git a/posthog/hogql/context.py b/posthog/hogql/context.py
index 8a92c44968ac..616a97b067a4 100644
--- a/posthog/hogql/context.py
+++ b/posthog/hogql/context.py
@@ -124,6 +124,14 @@ class HogQLContext:
# FieldType.get_child() can raise QueryError for restricted properties.
restricted_properties: Optional[set[tuple[str, int]]] = None
+ # Cohort-gated events data retention: when set, the ClickHouse printer floors every events-table scan to
+ # now() - toIntervalMonth(this). Computed once per query in prepare_ast_for_printing; None means not enforced.
+ events_retention_months: Optional[int] = None
+ # Backend-only switch for the events-retention floor. Defaults on; server-side paths that must act on all rows
+ # regardless of retention — notably the GDPR data-deletion mutation path — set this False. Deliberately NOT a
+ # HogQLQueryModifier, so a query can't disable enforcement.
+ apply_events_retention_floor: bool = True
+
def __post_init__(self):
if self.team:
self.team_id = self.team.id
diff --git a/posthog/hogql/printer/base.py b/posthog/hogql/printer/base.py
index ac7986713211..0daf85d4595a 100644
--- a/posthog/hogql/printer/base.py
+++ b/posthog/hogql/printer/base.py
@@ -528,6 +528,15 @@ class BasePrinter(Visitor[str]):
"""
raise NotImplementedError("BasePrinter._ensure_access_control_where_clause not overridden")
+ def _events_retention_floor(
+ self,
+ table_type: ast.TableType | ast.LazyTableType,
+ node_type: ast.TableOrSelectType | None,
+ ) -> ast.Expr | None:
+ """Floor events-table scans to the team's retention window. Overridden by the ClickHouse dialect;
+ default no-op — the HogQL and warehouse dialects don't enforce events retention."""
+ return None
+
def _print_table_ref(self, table_type: ast.TableType | ast.LazyTableType, node: ast.JoinExpr) -> str:
"""Print a table reference. Fail-fast by default: each dialect must override.
@@ -593,8 +602,12 @@ class BasePrinter(Visitor[str]):
else:
extra_where = combined_guard
- # Apply table-level predicates (e.g., date filters on PostgresTable).
+ # Apply table-level predicates (e.g., date filters on PostgresTable), plus the cohort-gated
+ # events-retention floor (timestamp > now() - retention) injected at the lowest level on the events table.
predicate_exprs = self._get_table_predicates(table_type, node.type)
+ retention_floor = self._events_retention_floor(table_type, node.type)
+ if retention_floor is not None:
+ predicate_exprs = [*predicate_exprs, retention_floor]
for pred in predicate_exprs:
if is_left_join and node.constraint is not None:
if on_clause_guard is None:
diff --git a/posthog/hogql/printer/clickhouse.py b/posthog/hogql/printer/clickhouse.py
index 8f301753164a..3f82e227a5cc 100644
--- a/posthog/hogql/printer/clickhouse.py
+++ b/posthog/hogql/printer/clickhouse.py
@@ -52,6 +52,26 @@ def team_id_guard_for_table(table_type: ast.TableOrSelectType, context: HogQLCon
)
+def retention_floor_for_table(table_type: ast.TableOrSelectType, retention_months: int) -> ast.Expr:
+ """Floor an events-table scan to ``timestamp > now() - toIntervalMonth(retention_months)``.
+
+ Sibling to ``team_id_guard_for_table``: a mandatory, context-derived guard added at the lowest level on the
+ events table, so the events-data-retention cap can't be bypassed by query-supplied date filters or modifiers.
+ Uses a calendar-month interval so the boundary lands on the exact date (no leap-year / 365-day drift).
+ """
+ field_table_type = _table_filter_type(table_type)
+ return ast.CompareOperation(
+ op=ast.CompareOperationOp.Gt,
+ left=ast.Field(chain=["timestamp"], type=ast.FieldType(name="timestamp", table_type=field_table_type)),
+ right=ast.ArithmeticOperation(
+ op=ast.ArithmeticOperationOp.Sub,
+ left=ast.Call(name="now", args=[]),
+ right=ast.Call(name="toIntervalMonth", args=[ast.Constant(value=retention_months)]),
+ ),
+ type=ast.BooleanType(),
+ )
+
+
# The $ai_* properties whose materialized columns carry bloom-filter skip indexes. We read them bare — no nullIf/ifNull
# wrapping — so the index stays usable. Canonical set; ClickHouse property resolution imports it to make the same call.
AI_BLOOM_FILTER_PROPERTIES = {"$ai_trace_id", "$ai_session_id", "$ai_is_error"}
@@ -845,6 +865,20 @@ class ClickHousePrinter(BasePrinter):
return build_access_control_guard(table_type.table, node_type, self.context)
+ def _events_retention_floor(
+ self,
+ table_type: ast.TableType | ast.LazyTableType,
+ node_type: ast.TableOrSelectType | None,
+ ) -> ast.Expr | None:
+ from posthog.hogql.database.schema.events import EventsTable
+
+ months = self.context.events_retention_months
+ if months is None or node_type is None or not isinstance(table_type, ast.TableType):
+ return None
+ if not isinstance(table_type.table, EventsTable):
+ return None
+ return retention_floor_for_table(node_type, months)
+
def _print_table_ref(self, table_type: ast.TableType | ast.LazyTableType, node: ast.JoinExpr) -> str:
sql = table_type.table.to_printed_clickhouse(self.context)
table = table_type.table
diff --git a/posthog/hogql/printer/test/test_printer.py b/posthog/hogql/printer/test/test_printer.py
index 0ddb59f3bd9f..c127cd354579 100644
--- a/posthog/hogql/printer/test/test_printer.py
+++ b/posthog/hogql/printer/test/test_printer.py
@@ -167,6 +167,40 @@ class TestPrinter(BaseTest):
)
return printed
+ @parameterized.expand([(12,), (84,)])
+ @override_settings(EVENTS_DATA_RETENTION_ENFORCED=True)
+ def test_events_retention_floor_applied(self, months: int):
+ self.team.event_retention_months = months
+ context = HogQLContext(team_id=self.team.pk, team=self.team, enable_select_queries=True)
+ sql = self._select("select count() from events", context=context)
+ assert f"toIntervalMonth({months})" in sql
+ assert "greater(events.timestamp, minus(now" in sql
+
+ @override_settings(EVENTS_DATA_RETENTION_ENFORCED=False)
+ def test_events_retention_floor_not_applied_when_disabled(self):
+ self.team.event_retention_months = 12
+ context = HogQLContext(team_id=self.team.pk, team=self.team, enable_select_queries=True)
+ sql = self._select("select count() from events", context=context)
+ assert "toIntervalMonth" not in sql
+
+ @override_settings(EVENTS_DATA_RETENTION_ENFORCED=True)
+ def test_events_retention_floor_only_on_events_table(self):
+ # The floor is keyed to the events table only — a persons query must not get an events.timestamp floor.
+ self.team.event_retention_months = 12
+ context = HogQLContext(team_id=self.team.pk, team=self.team, enable_select_queries=True)
+ sql = self._select("select count() from persons", context=context)
+ assert "greater(events.timestamp, minus(now" not in sql
+ assert "toIntervalMonth(12)" not in sql
+
+ @override_settings(EVENTS_DATA_RETENTION_ENFORCED=True)
+ def test_events_retention_floor_loads_team_when_not_in_context(self):
+ # Prod path: the context carries only team_id (see query.py), so the window is loaded from the DB by id.
+ self.team.event_retention_months = 24
+ self.team.save()
+ context = HogQLContext(team_id=self.team.pk, enable_select_queries=True)
+ sql = self._select("select count() from events", context=context)
+ assert "toIntervalMonth(24)" in sql
+
def test_to_printed_hogql(self):
expr = parse_select("select 1 + 2, 3 from events")
repsponse = to_printed_hogql(expr, self.team)
diff --git a/posthog/hogql/printer/utils.py b/posthog/hogql/printer/utils.py
index ab1502c664c2..3eb157f42d0a 100644
--- a/posthog/hogql/printer/utils.py
+++ b/posthog/hogql/printer/utils.py
@@ -49,6 +49,7 @@ from posthog.hogql.workload import WorkloadCollector
from posthog.clickhouse.workload import Workload
from posthog.models.team import Team
+from posthog.models.team.event_retention import events_retention_months_for_team
from products.access_control.backend.property_access_control import get_restricted_properties_for_team
@@ -274,6 +275,15 @@ def prepare_ast_for_printing(
)
)
+ # Cohort-gated events data retention: floor every events scan to now() - retention. Computed once here
+ # (the per-scan printer hook can't afford the team lookup + flag eval); the printer reads it off the context.
+ # Gated on the backend-only apply_events_retention_floor flag so server-side paths that must bypass the floor
+ # — e.g. the GDPR data-deletion mutation path — can opt out; the flag can't be set from a query, so the
+ # enforcement floor still can't be circumvented by a query-supplied modifier.
+ with context.timings.measure("events_retention_floor"):
+ if context.apply_events_retention_floor:
+ context.events_retention_months = events_retention_months_for_team(context.team, context.team_id)
+
# Events predicate pushdown runs on the lowered AST (between lowering and property resolution), so it matches the
# dialect-neutral PropertyAccess form. Its pre-filtering subquery projects only source columns (raw blobs and
# bare events columns); outer blob references are re-typed onto the subquery, so the resolution pass substitutes
diff --git a/posthog/hogql_queries/insights/retention/retention_query_runner.py b/posthog/hogql_queries/insights/retention/retention_query_runner.py
index 680afaf6f501..2afa8b80b92a 100644
--- a/posthog/hogql_queries/insights/retention/retention_query_runner.py
+++ b/posthog/hogql_queries/insights/retention/retention_query_runner.py
@@ -13,6 +13,7 @@ from posthog.schema import (
HogQLQueryResponse,
InCohortVia,
IntervalType,
+ ResolvedDateRangeResponse,
RetentionEntity,
RetentionQuery,
RetentionQueryResponse,
@@ -611,7 +612,16 @@ class RetentionQueryRunner(AnalyticsQueryRunner[RetentionQueryResponse]):
results = self.format_results(response)
- return RetentionQueryResponse(results=results, timings=response.timings, hogql=hogql, modifiers=self.modifiers)
+ return RetentionQueryResponse(
+ results=results,
+ timings=response.timings,
+ hogql=hogql,
+ modifiers=self.modifiers,
+ resolved_date_range=ResolvedDateRangeResponse(
+ date_from=self.query_date_range.date_from(),
+ date_to=self.query_date_range.date_to(),
+ ),
+ )
def format_results(self, response: HogQLQueryResponse) -> list[dict[str, Any]]:
"""Format raw retention HogQL response into nested interval structures.
diff --git a/posthog/hogql_queries/query_runner.py b/posthog/hogql_queries/query_runner.py
index 79bef8331e5f..a945cd867160 100644
--- a/posthog/hogql_queries/query_runner.py
+++ b/posthog/hogql_queries/query_runner.py
@@ -120,6 +120,7 @@ from posthog.hogql_queries.validation.validation import (
)
from posthog.models import Team, User
from posthog.models.team import WeekStartDay
+from posthog.models.team.event_retention import events_retention_months_for_team
from posthog.rbac.user_access_control import UserAccessControl, UserAccessControlError
from posthog.schema_helpers import to_dict
from posthog.scopes import APIScopeObject
@@ -1958,6 +1959,13 @@ class QueryRunner(ABC, Generic[Q, R, CR]):
if geoip_dict_fallback_team_in_env(self.team.pk):
payload["geoip_dict_fallback"] = True
+ # Vary the cache key by the events-retention floor: a cache hit returns before the printer applies the floor,
+ # so without this a result cached pre-enforcement (or at a longer period) would keep surfacing events past
+ # retention. Only set when enforced, so non-cohort teams' keys are unchanged.
+ retention_months = events_retention_months_for_team(self.team, self.team.pk)
+ if retention_months is not None:
+ payload["events_retention_floor_months"] = retention_months
+
return payload
def _get_property_access_restrictions(self) -> list[tuple[str, int]] | None:
diff --git a/posthog/management/commands/execute_temporal_workflow.py b/posthog/management/commands/execute_temporal_workflow.py
index e5ccc5581bbf..6f4452c6c25f 100644
--- a/posthog/management/commands/execute_temporal_workflow.py
+++ b/posthog/management/commands/execute_temporal_workflow.py
@@ -24,6 +24,7 @@ from posthog.temporal.session_replay.enforce_max_replay_retention import ENFORCE
from posthog.temporal.session_replay.rasterize_recording import RASTERIZE_RECORDING_WORKFLOWS
from posthog.temporal.session_replay.summarization_sweep import SUMMARIZATION_SWEEP_WORKFLOWS
from posthog.temporal.session_replay.surfacing_scoring_sweep import SURFACING_SCORING_SWEEP_WORKFLOWS
+from posthog.temporal.sync_events_retention import SYNC_EVENTS_RETENTION_WORKFLOWS
from posthog.temporal.tests.utils.workflow import WORKFLOWS as TEST_WORKFLOWS
from posthog.temporal.usage_report import WORKFLOWS as USAGE_REPORTS_WORKFLOWS
from posthog.temporal.weekly_digest import WORKFLOWS as WEEKLY_DIGEST_WORKFLOWS
@@ -146,6 +147,7 @@ class Command(BaseCommand):
+ TEST_WORKFLOWS
+ DELETE_RECORDINGS_WORKFLOWS
+ ENFORCE_MAX_REPLAY_RETENTION_WORKFLOWS
+ + SYNC_EVENTS_RETENTION_WORKFLOWS
+ WEEKLY_DIGEST_WORKFLOWS
+ DATA_MODELING_WORKFLOWS
+ LLM_ANALYTICS_WORKFLOWS
diff --git a/posthog/management/commands/start_temporal_worker.py b/posthog/management/commands/start_temporal_worker.py
index b3d9c7ab1589..0a4193428d8c 100644
--- a/posthog/management/commands/start_temporal_worker.py
+++ b/posthog/management/commands/start_temporal_worker.py
@@ -143,6 +143,7 @@ from posthog.temporal.session_replay.surfacing_scoring_sweep import (
SURFACING_SCORING_SWEEP_ACTIVITIES,
SURFACING_SCORING_SWEEP_WORKFLOWS,
)
+from posthog.temporal.sync_events_retention import SYNC_EVENTS_RETENTION_ACTIVITIES, SYNC_EVENTS_RETENTION_WORKFLOWS
from posthog.temporal.sync_person_distinct_ids import (
ACTIVITIES as SYNC_PERSON_DISTINCT_IDS_ACTIVITIES,
WORKFLOWS as SYNC_PERSON_DISTINCT_IDS_WORKFLOWS,
@@ -270,7 +271,8 @@ _task_queue_specs = [
+ CLEANUP_PROPDEFS_WORKFLOWS
+ BACKFILL_GROUP_TYPE_CREATED_AT_WORKFLOWS
+ INGESTION_ACCEPTANCE_TEST_WORKFLOWS
- + WAREHOUSE_SOURCES_QUEUE_PARTITION_WORKFLOWS,
+ + WAREHOUSE_SOURCES_QUEUE_PARTITION_WORKFLOWS
+ + SYNC_EVENTS_RETENTION_WORKFLOWS,
PROXY_SERVICE_ACTIVITIES
+ DELETE_PERSONS_ACTIVITIES
+ DELETE_TEAMS_ACTIVITIES
@@ -285,7 +287,8 @@ _task_queue_specs = [
+ CLEANUP_PROPDEFS_ACTIVITIES
+ BACKFILL_GROUP_TYPE_CREATED_AT_ACTIVITIES
+ INGESTION_ACCEPTANCE_TEST_ACTIVITIES
- + WAREHOUSE_SOURCES_QUEUE_PARTITION_ACTIVITIES,
+ + WAREHOUSE_SOURCES_QUEUE_PARTITION_ACTIVITIES
+ + SYNC_EVENTS_RETENTION_ACTIVITIES,
),
(
settings.HEALTH_CHECK_TASK_QUEUE,
diff --git a/posthog/management/commands/start_temporal_workflow.py b/posthog/management/commands/start_temporal_workflow.py
index 9bef44d04b76..92392b13ae0d 100644
--- a/posthog/management/commands/start_temporal_workflow.py
+++ b/posthog/management/commands/start_temporal_workflow.py
@@ -23,6 +23,7 @@ from posthog.temporal.session_replay.rasterize_recording import RASTERIZE_RECORD
from posthog.temporal.session_replay.replay_count_metrics import REPLAY_COUNT_METRICS_WORKFLOWS
from posthog.temporal.session_replay.summarization_sweep import SUMMARIZATION_SWEEP_WORKFLOWS
from posthog.temporal.session_replay.surfacing_scoring_sweep import SURFACING_SCORING_SWEEP_WORKFLOWS
+from posthog.temporal.sync_events_retention import SYNC_EVENTS_RETENTION_WORKFLOWS
from posthog.temporal.sync_person_distinct_ids import WORKFLOWS as SYNC_PERSON_DISTINCT_IDS_WORKFLOWS
from posthog.temporal.tests.utils.workflow import WORKFLOWS as TEST_WORKFLOWS
from posthog.temporal.usage_report import WORKFLOWS as USAGE_REPORTS_WORKFLOWS
@@ -148,6 +149,7 @@ class Command(BaseCommand):
+ COUNT_PLAYLIST_ITEMS_WORKFLOWS
+ DELETE_RECORDINGS_WORKFLOWS
+ ENFORCE_MAX_REPLAY_RETENTION_WORKFLOWS
+ + SYNC_EVENTS_RETENTION_WORKFLOWS
+ RASTERIZE_RECORDING_WORKFLOWS
+ REPLAY_COUNT_METRICS_WORKFLOWS
+ SUMMARIZATION_SWEEP_WORKFLOWS
diff --git a/posthog/management/migration_analysis/hot_table_acknowledged_migrations.txt b/posthog/management/migration_analysis/hot_table_acknowledged_migrations.txt
index 9d663bf94973..e492d1cb7577 100644
--- a/posthog/management/migration_analysis/hot_table_acknowledged_migrations.txt
+++ b/posthog/management/migration_analysis/hot_table_acknowledged_migrations.txt
@@ -16,3 +16,4 @@
#
# Format: one "<app_label>.<migration_name>" per line, e.g.
# posthog.1234_team_some_genuinely_core_field
+posthog.1244_team_event_retention_months
diff --git a/posthog/migrations/1244_team_event_retention_months.py b/posthog/migrations/1244_team_event_retention_months.py
new file mode 100644
index 000000000000..c3345c643d42
--- /dev/null
+++ b/posthog/migrations/1244_team_event_retention_months.py
@@ -0,0 +1,15 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("posthog", "1243_alter_team_options"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="team",
+ name="event_retention_months",
+ field=models.PositiveSmallIntegerField(db_default=84, default=84),
+ ),
+ ]
diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txt
index 0f04404cbb95..173198f725e0 100644
--- a/posthog/migrations/max_migration.txt
+++ b/posthog/migrations/max_migration.txt
@@ -1 +1 @@
-1243_alter_team_options
+1244_team_event_retention_months
diff --git a/posthog/models/data_deletion_request.py b/posthog/models/data_deletion_request.py
index 133c793ba1f5..cee42257cc9b 100644
--- a/posthog/models/data_deletion_request.py
+++ b/posthog/models/data_deletion_request.py
@@ -92,6 +92,9 @@ def compile_hogql_predicate(obj) -> tuple[str, dict]:
modifiers=modifiers,
within_non_hogql_query=True,
enable_select_queries=True,
+ # A deletion predicate must match rows regardless of retention; the events-retention floor would otherwise
+ # narrow an events sub-query here and leave events older than the window un-deleted.
+ apply_events_retention_floor=False,
)
try:
sql = translate_hogql(predicate, context, dialect="clickhouse")
diff --git a/posthog/models/team/event_retention.py b/posthog/models/team/event_retention.py
new file mode 100644
index 000000000000..73e7ab89054d
--- /dev/null
+++ b/posthog/models/team/event_retention.py
@@ -0,0 +1,91 @@
+from typing import Optional
+
+from django.conf import settings
+
+import posthoganalytics
+
+from posthog.cloud_utils import is_cloud
+from posthog.constants import AvailableFeature
+from posthog.models.organization import ProductFeature
+from posthog.models.team.team import Team
+
+# Grandfather default: existing teams keep 7 years (84 months) until billing assigns a shorter window.
+DEFAULT_EVENT_RETENTION_MONTHS = 84
+
+# Cohort feature flag — gates enforcement so the rollout can target a specific cohort.
+EVENTS_DATA_RETENTION_FLAG = "events-data-retention"
+
+# Billing entitlement key the sync job reconciles Team.event_retention_months against.
+EVENTS_DATA_RETENTION_FEATURE = AvailableFeature.PRODUCT_ANALYTICS_DATA_RETENTION
+
+
+def should_enforce_events_retention(team_id: int) -> bool:
+ """Whether events-data-retention is enforced for this team — the cohort gate.
+
+ Keyed on team_id so it stays DB-free on the HogQL hot path: the settings override wins (ops kill switch /
+ local + test toggle), otherwise a cohort flag on cloud, evaluated locally against the team's distinct id.
+ Self-hosted never enforces — those users own their data.
+ """
+ if settings.EVENTS_DATA_RETENTION_ENFORCED is not None:
+ return settings.EVENTS_DATA_RETENTION_ENFORCED
+
+ if not is_cloud():
+ return False
+
+ return bool(
+ posthoganalytics.feature_enabled(
+ EVENTS_DATA_RETENTION_FLAG,
+ str(team_id),
+ only_evaluate_locally=True,
+ send_feature_flag_events=False,
+ )
+ )
+
+
+def events_retention_months_for_team(team: Optional[Team], team_id: Optional[int]) -> Optional[int]:
+ """Months of events retention to floor a query's events scans to, or None if retention isn't enforced.
+
+ Computed once per query in prepare_ast_for_printing. The cohort gate runs first and is DB-free, so non-cohort
+ teams (the vast majority during rollout) never hit Postgres here — only an enforced team triggers the lean
+ field load.
+ """
+ if team_id is None:
+ if team is None:
+ return None
+ team_id = team.id
+
+ if not should_enforce_events_retention(team_id):
+ return None
+
+ if team is None:
+ team = Team.objects.filter(id=team_id).only("event_retention_months").first()
+ if team is None:
+ return None
+
+ return team.event_retention_months or DEFAULT_EVENT_RETENTION_MONTHS
+
+
+def parse_events_feature_to_months(retention_feature: ProductFeature | None) -> int:
+ """Map the billing events-retention entitlement to a number of months for the sync job.
+
+ Defaults to 7 years (84 months) when billing exposes no entitlement, so existing paid teams stay grandfathered
+ rather than being silently reduced. Honors billing's value exactly — no bucketing — since the field stores the
+ real duration.
+ """
+ if retention_feature is None:
+ return DEFAULT_EVENT_RETENTION_MONTHS
+
+ limit = retention_feature.get("limit")
+ unit = retention_feature.get("unit")
+ if limit is None or unit is None or limit <= 0:
+ return DEFAULT_EVENT_RETENTION_MONTHS
+
+ match unit.lower():
+ case "year" | "years":
+ return limit * 12
+ case "month" | "months":
+ return limit
+ case _:
+ # Events retention is a months/years concept; an unexpected unit (e.g. days) grandfathers rather than
+ # introducing a lossy day→month conversion.
+ return DEFAULT_EVENT_RETENTION_MONTHS
diff --git a/posthog/models/team/team.py b/posthog/models/team/team.py
index ced645334296..80ed9e81e644 100644
--- a/posthog/models/team/team.py
+++ b/posthog/models/team/team.py
@@ -415,6 +415,15 @@ class Team(UUIDTClassicModel):
"admin",
)
+ # Events data retention in months — denormalized from the billing entitlement by sync_events_retention, read on
+ # the HogQL hot path. Default 84 (7 years) grandfathers existing teams. db_default because posthog_team is also
+ # written by raw inserts in nodejs/rust and the test-schema builder.
+ event_retention_months = field_access_control(
+ models.PositiveSmallIntegerField(default=84, db_default=84),
+ "project",
+ "admin",
+ )
+
# Conversations
conversations_enabled = field_access_control(models.BooleanField(null=True, blank=True), "project", "admin")
conversations_settings = field_access_control(models.JSONField(null=True, blank=True), "project", "admin")
diff --git a/posthog/models/team/test/test_event_retention.py b/posthog/models/team/test/test_event_retention.py
new file mode 100644
index 000000000000..db04d078f9eb
--- /dev/null
+++ b/posthog/models/team/test/test_event_retention.py
@@ -0,0 +1,30 @@
+from typing import cast
+
+from parameterized import parameterized
+
+from posthog.models.organization import ProductFeature
+from posthog.models.team.event_retention import parse_events_feature_to_months
+
+
+class TestParseEventsFeatureToMonths:
+ @parameterized.expand(
+ [
+ (None, 84),
+ ({"limit": 1, "unit": "year"}, 12),
+ ({"limit": 2, "unit": "years"}, 24),
+ ({"limit": 5, "unit": "years"}, 60),
+ ({"limit": 7, "unit": "years"}, 84),
+ ({"limit": 10, "unit": "years"}, 120),
+ ({"limit": 6, "unit": "months"}, 6),
+ ({"limit": 18, "unit": "months"}, 18),
+ ({"limit": 84, "unit": "months"}, 84),
+ ({"limit": None, "unit": "years"}, 84),
+ ({"limit": 1, "unit": "decades"}, 84),
+ ({"limit": 90, "unit": "days"}, 84),
+ ({"limit": 0, "unit": "years"}, 84),
+ ({"limit": 0, "unit": "months"}, 84),
+ ({"limit": -5, "unit": "years"}, 84),
+ ]
+ )
+ def test_parse(self, feature: dict | None, expected: int) -> None:
+ assert parse_events_feature_to_months(cast(ProductFeature | None, feature)) == expected
diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr
index da66dd9d15a0..e22de0abea95 100644
--- a/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr
+++ b/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr
@@ -101,6 +101,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -417,6 +418,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -616,6 +618,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -834,6 +837,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1259,6 +1263,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1458,6 +1463,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1649,6 +1655,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1982,6 +1989,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2181,6 +2189,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr
index 32047fa64e11..a37723905758 100644
--- a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr
+++ b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr
@@ -221,6 +221,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -430,6 +431,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -629,6 +631,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1207,6 +1210,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1412,6 +1416,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1611,6 +1616,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2189,6 +2195,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2390,6 +2397,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2589,6 +2597,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -3167,6 +3176,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -3368,6 +3378,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -3567,6 +3578,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4145,6 +4157,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4350,6 +4363,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4549,6 +4563,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -5127,6 +5142,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -5332,6 +5348,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -5531,6 +5548,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -6109,6 +6127,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -6314,6 +6333,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -6513,6 +6533,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -7146,6 +7167,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -7454,6 +7476,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -7593,6 +7616,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -7792,6 +7816,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -8270,6 +8295,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -8627,6 +8653,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -8826,6 +8853,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -9346,6 +9374,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -9575,6 +9604,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -9800,6 +9830,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -9999,6 +10030,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -10528,6 +10560,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -10848,6 +10881,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -11047,6 +11081,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -11172,6 +11207,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -11650,6 +11686,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -12124,6 +12161,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -12388,6 +12426,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -12727,6 +12766,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -12926,6 +12966,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -13404,6 +13445,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -13553,6 +13595,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -13821,6 +13864,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -14020,6 +14064,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -14547,6 +14592,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -14941,6 +14987,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -15140,6 +15187,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -15708,6 +15756,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -16008,6 +16057,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -16242,6 +16292,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -16720,6 +16771,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -17095,6 +17147,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -17294,6 +17347,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/posthog/settings/__init__.py b/posthog/settings/__init__.py
index 3f30cf3cf3cb..b97c0563e1d2 100644
--- a/posthog/settings/__init__.py
+++ b/posthog/settings/__init__.py
@@ -111,6 +111,12 @@ PERSON_ON_EVENTS_OVERRIDE: bool = get_from_env("PERSON_ON_EVENTS_OVERRIDE", opti
# Only written in specific scripts - do not use outside of them.
PERSON_ON_EVENTS_V2_OVERRIDE: bool = get_from_env("PERSON_ON_EVENTS_V2_OVERRIDE", optional=True, type_cast=str_to_bool)
+# Events data retention enforcement override (ops kill switch / local + test toggle). When unset (None),
+# enforcement falls back to the per-project `events-data-retention` cohort flag. When set, forces it on/off everywhere.
+EVENTS_DATA_RETENTION_ENFORCED: bool | None = get_from_env(
+ "EVENTS_DATA_RETENTION_ENFORCED", optional=True, type_cast=str_to_bool
+)
+
# Support creating multiple organizations in a single instance. Requires a premium license.
MULTI_ORG_ENABLED: bool = get_from_env("MULTI_ORG_ENABLED", False, type_cast=str_to_bool)
diff --git a/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr b/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr
index 47d0da232208..28434cba7969 100644
--- a/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr
+++ b/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr
@@ -426,6 +426,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -613,6 +614,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1202,6 +1204,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1481,6 +1484,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/posthog/temporal/schedule.py b/posthog/temporal/schedule.py
index 86f4e0452362..e2db363f8b64 100644
--- a/posthog/temporal/schedule.py
+++ b/posthog/temporal/schedule.py
@@ -66,6 +66,7 @@ from posthog.temporal.session_replay.summarization_sweep.reconciler import (
create_summarization_sweep_reconciler_schedule,
)
from posthog.temporal.session_replay.surfacing_scoring_sweep.schedule import create_surfacing_scoring_sweep_schedule
+from posthog.temporal.sync_events_retention.types import SyncEventsRetentionInput
from posthog.temporal.usage_report.types import RunUsageReportsInputs
from posthog.temporal.warehouse_sources_queue_partition_management.schedule import (
create_warehouse_sources_queue_partition_management_schedule,
@@ -317,6 +318,44 @@ async def create_enforce_max_replay_retention_schedule(client: Client):
)
+async def create_sync_events_retention_schedule(client: Client):
+ """Create or update the schedule for the events retention sync workflow.
+
+ Runs daily at 02:22 UTC — an off-the-hour minute so it doesn't pile onto the cluster of jobs that fire at the
+ top of the hour.
+ """
+ sync_events_retention_schedule = Schedule(
+ action=ScheduleActionStartWorkflow(
+ "sync-events-retention",
+ SyncEventsRetentionInput(dry_run=False),
+ id="sync-events-retention-schedule",
+ task_queue=settings.GENERAL_PURPOSE_TASK_QUEUE,
+ retry_policy=common.RetryPolicy(
+ maximum_attempts=1,
+ ),
+ ),
+ spec=ScheduleSpec(
+ calendars=[
+ ScheduleCalendarSpec(
+ comment="Daily at 02:22 UTC",
+ hour=[ScheduleRange(start=2, end=2)],
+ minute=[ScheduleRange(start=22, end=22)],
+ )
+ ]
+ ),
+ )
+
+ if await a_schedule_exists(client, "sync-events-retention-schedule"):
+ await a_update_schedule(client, "sync-events-retention-schedule", sync_events_retention_schedule)
+ else:
+ await a_create_schedule(
+ client,
+ "sync-events-retention-schedule",
+ sync_events_retention_schedule,
+ trigger_immediately=False,
+ )
+
+
async def create_weekly_digest_schedule(client: Client):
"""Create or update the schedule for the weekly digest workflow.
@@ -656,6 +695,7 @@ schedules = [
create_count_all_playlists_schedule,
create_error_tracking_recommendations_refresh_schedule,
create_enforce_max_replay_retention_schedule,
+ create_sync_events_retention_schedule,
create_replay_count_metrics_schedule,
create_weekly_digest_schedule,
create_batch_trace_summarization_schedule,
diff --git a/posthog/temporal/sync_events_retention/__init__.py b/posthog/temporal/sync_events_retention/__init__.py
new file mode 100644
index 000000000000..cbbff91f48eb
--- /dev/null
+++ b/posthog/temporal/sync_events_retention/__init__.py
@@ -0,0 +1,5 @@
+from posthog.temporal.sync_events_retention.activities import sync_events_retention
+from posthog.temporal.sync_events_retention.workflow import SyncEventsRetentionWorkflow
+
+SYNC_EVENTS_RETENTION_WORKFLOWS = [SyncEventsRetentionWorkflow]
+SYNC_EVENTS_RETENTION_ACTIVITIES = [sync_events_retention]
diff --git a/posthog/temporal/sync_events_retention/activities.py b/posthog/temporal/sync_events_retention/activities.py
new file mode 100644
index 000000000000..054500b986bb
--- /dev/null
+++ b/posthog/temporal/sync_events_retention/activities.py
@@ -0,0 +1,59 @@
+from temporalio import activity
+
+from posthog.constants import AvailableFeature
+from posthog.models.team import Team
+from posthog.models.team.event_retention import parse_events_feature_to_months
+from posthog.sync import database_sync_to_async
+from posthog.temporal.common.heartbeat import Heartbeater
+from posthog.temporal.common.logger import get_write_only_logger
+from posthog.temporal.sync_events_retention.types import SyncEventsRetentionInput
+
+LOGGER = get_write_only_logger()
+
+
[email protected](name="sync-events-retention")
+async def sync_events_retention(input: SyncEventsRetentionInput) -> None:
+ """Reconcile every team's events retention window with its billing entitlement.
+
+ Events retention is plan-derived and not user-editable, so we set it outright — unlike replay enforcement, which
+ only caps a user-chosen value. Teams with no entitlement default to 7 years, grandfathering existing paid teams.
+ """
+ async with Heartbeater():
+ logger = LOGGER.bind()
+ teams_to_update = []
+ query_counter = 0
+
+ logger.info("Syncing events retention for all teams...")
+ async for team in Team.objects.select_related("organization").only(
+ "id", "name", "organization", "event_retention_months"
+ ):
+ organization = team.organization
+ retention_feature = await database_sync_to_async(organization.get_available_feature)(
+ AvailableFeature.PRODUCT_ANALYTICS_DATA_RETENTION
+ )
+ target_months = parse_events_feature_to_months(retention_feature)
+
+ if team.event_retention_months != target_months:
+ logger.info(
+ "Events retention period synced",
+ team_id=team.id,
+ team_name=team.name,
+ organization_id=organization.id,
+ retention_months_before=team.event_retention_months,
+ retention_months_after=target_months,
+ )
+ team.event_retention_months = target_months
+ teams_to_update.append(team)
+
+ query_counter += 1
+ if query_counter >= input.batch_size:
+ query_counter = 0
+ logger.info(f"Processed {input.batch_size} teams...")
+
+ if not input.dry_run:
+ logger.info(f"Updating {len(teams_to_update)} teams...")
+ await database_sync_to_async(Team.objects.bulk_update)(
+ teams_to_update, ["event_retention_months"], batch_size=input.batch_size
+ )
+ else:
+ logger.info(f"DRY RUN: Would have updated {len(teams_to_update)} teams...")
diff --git a/posthog/temporal/sync_events_retention/types.py b/posthog/temporal/sync_events_retention/types.py
new file mode 100644
index 000000000000..3f321ae078e0
--- /dev/null
+++ b/posthog/temporal/sync_events_retention/types.py
@@ -0,0 +1,7 @@
+from dataclasses import dataclass
+
+
+@dataclass(frozen=True)
+class SyncEventsRetentionInput:
+ dry_run: bool
+ batch_size: int = 1000
diff --git a/posthog/temporal/sync_events_retention/workflow.py b/posthog/temporal/sync_events_retention/workflow.py
new file mode 100644
index 000000000000..eabea5dfb759
--- /dev/null
+++ b/posthog/temporal/sync_events_retention/workflow.py
@@ -0,0 +1,25 @@
+from datetime import timedelta
+
+from temporalio import common, workflow
+
+from posthog.temporal.common.base import PostHogWorkflow
+from posthog.temporal.sync_events_retention.activities import sync_events_retention
+from posthog.temporal.sync_events_retention.types import SyncEventsRetentionInput
+
+
[email protected](name="sync-events-retention")
+class SyncEventsRetentionWorkflow(PostHogWorkflow):
+ inputs_cls = SyncEventsRetentionInput
+
+ @workflow.run
+ async def run(self, input: SyncEventsRetentionInput) -> None:
+ await workflow.execute_activity(
+ sync_events_retention,
+ input,
+ start_to_close_timeout=timedelta(minutes=120),
+ retry_policy=common.RetryPolicy(
+ maximum_attempts=2,
+ initial_interval=timedelta(minutes=1),
+ ),
+ heartbeat_timeout=timedelta(minutes=5),
+ )
diff --git a/posthog/temporal/tests/sync_events_retention/__init__.py b/posthog/temporal/tests/sync_events_retention/__init__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/posthog/temporal/tests/sync_events_retention/test_activities.py b/posthog/temporal/tests/sync_events_retention/test_activities.py
new file mode 100644
index 000000000000..05656f9ca3ae
--- /dev/null
+++ b/posthog/temporal/tests/sync_events_retention/test_activities.py
@@ -0,0 +1,60 @@
+import pytest
+
+from asgiref.sync import sync_to_async
+from temporalio.testing import ActivityEnvironment
+
+from posthog.models import Organization, Team
+from posthog.temporal.sync_events_retention.activities import sync_events_retention
+from posthog.temporal.sync_events_retention.types import SyncEventsRetentionInput
+
+# These run against the real DB on purpose: the activity's value is in its real queryset
+# (select_related/.only), reading a real Organization.available_product_features via
+# get_available_feature, and persisting via bulk_update. Mocking Team.objects would hide
+# exactly those — which is how a select_related/.only() FieldError shipped undetected.
+
+
+async def _team_with_features(features: list[dict], *, current_months: int) -> Team:
+ org = await sync_to_async(Organization.objects.create)(name="test-org")
+ team = await sync_to_async(Team.objects.create)(
+ organization=org, name="test-team", event_retention_months=current_months
+ )
+ # available_product_features is recomputed from licenses by a pre_save signal on create, so set it with a
+ # direct UPDATE (which bypasses save/signals) — this mirrors how billing actually populates the field.
+ await sync_to_async(Organization.objects.filter(pk=org.pk).update)(available_product_features=features)
+ return team
+
+
[email protected]_db(transaction=True)
+ "features, expected_months",
+ [
+ # Real entitlement under the key billing actually emits -> converted to months and written.
+ # Also guards the billing key: a wrong key would miss this feature and grandfather to 84 instead.
+ ([{"key": "product_analytics_data_retention", "limit": 1, "unit": "year"}], 12),
+ # A present-but-unrelated feature must be ignored -> grandfather to 7 years (84 months).
+ ([{"key": "some_other_feature", "limit": 1, "unit": "year"}], 84),
+ ],
+)
+async def test_syncs_event_retention_months_from_billing(features: list[dict], expected_months: int):
+ # Start at a sentinel that differs from every expected value, so the assertion proves a real write.
+ team = await _team_with_features(features, current_months=999)
+
+ await ActivityEnvironment().run(sync_events_retention, SyncEventsRetentionInput(dry_run=False))
+
+ await sync_to_async(team.refresh_from_db)()
+ assert team.event_retention_months == expected_months
+
+
[email protected]_db(transaction=True)
+async def test_dry_run_computes_but_does_not_persist():
+ team = await _team_with_features(
+ [{"key": "product_analytics_data_retention", "limit": 1, "unit": "year"}], current_months=84
+ )
+
+ await ActivityEnvironment().run(sync_events_retention, SyncEventsRetentionInput(dry_run=True))
+
+ await sync_to_async(team.refresh_from_db)()
+ # The target is 12, but a dry run must not write it.
+ assert team.event_retention_months == 84
diff --git a/products/actions/backend/api/test/__snapshots__/test_action.ambr b/products/actions/backend/api/test/__snapshots__/test_action.ambr
index c8fa55faa644..9ca0dbfc20b4 100644
--- a/products/actions/backend/api/test/__snapshots__/test_action.ambr
+++ b/products/actions/backend/api/test/__snapshots__/test_action.ambr
@@ -122,6 +122,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -335,6 +336,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -694,6 +696,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -832,6 +835,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1045,6 +1049,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1392,6 +1397,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/products/annotations/backend/api/test/__snapshots__/test_annotation.ambr b/products/annotations/backend/api/test/__snapshots__/test_annotation.ambr
index 5bd1ea2ab695..6195ee4b27e8 100644
--- a/products/annotations/backend/api/test/__snapshots__/test_annotation.ambr
+++ b/products/annotations/backend/api/test/__snapshots__/test_annotation.ambr
@@ -122,6 +122,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -335,6 +336,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -704,6 +706,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -842,6 +845,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1055,6 +1059,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1412,6 +1417,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr b/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr
index 980e2e5b89d6..70aa3bd0eaec 100644
--- a/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr
+++ b/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr
@@ -79,6 +79,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -542,6 +543,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -685,6 +687,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/products/feature_flags/backend/api/test/__snapshots__/test_feature_flag.ambr b/products/feature_flags/backend/api/test/__snapshots__/test_feature_flag.ambr
index 256744d35c61..05381632c443 100644
--- a/products/feature_flags/backend/api/test/__snapshots__/test_feature_flag.ambr
+++ b/products/feature_flags/backend/api/test/__snapshots__/test_feature_flag.ambr
@@ -596,6 +596,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -861,6 +862,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -963,6 +965,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1179,6 +1182,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1513,6 +1517,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr b/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr
index 7ceb83354b74..28d3e6e1eab6 100644
--- a/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr
+++ b/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr
@@ -122,6 +122,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -317,6 +318,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -616,6 +618,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -779,6 +782,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -945,6 +949,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1046,6 +1051,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1462,6 +1468,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1600,6 +1607,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1702,6 +1710,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1817,6 +1826,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1934,6 +1944,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2050,6 +2061,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2189,6 +2201,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2430,6 +2443,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2532,6 +2546,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2696,6 +2711,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2834,6 +2850,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2936,6 +2953,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -3075,6 +3093,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -3311,6 +3330,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -3413,6 +3433,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -4655,6 +4676,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr b/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr
index dbc02f7f9bc3..32232edec804 100644
--- a/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr
+++ b/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr
@@ -569,6 +569,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -707,6 +708,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -809,6 +811,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -948,6 +951,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1138,6 +1142,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1240,6 +1245,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1378,6 +1384,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1587,6 +1594,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -1922,6 +1930,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2121,6 +2130,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2329,6 +2339,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2557,6 +2568,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
@@ -2803,6 +2815,7 @@
"posthog_team"."session_recording_trigger_groups",
"posthog_team"."session_replay_config",
"posthog_team"."session_recording_retention_period",
+ "posthog_team"."event_retention_months",
"posthog_team"."conversations_enabled",
"posthog_team"."conversations_settings",
"posthog_team"."proactive_tasks_enabled",
diff --git a/products/product_analytics/backend/hogql_queries/paths/paths_query_runner.py b/products/product_analytics/backend/hogql_queries/paths/paths_query_runner.py
index 14ed190c02f8..87db2d1627ed 100644
--- a/products/product_analytics/backend/hogql_queries/paths/paths_query_runner.py
+++ b/products/product_analytics/backend/hogql_queries/paths/paths_query_runner.py
@@ -18,6 +18,7 @@ from posthog.schema import (
PathsQuery,
PathsQueryResponse,
PathType,
+ ResolvedDateRangeResponse,
)
from posthog.hogql import ast
@@ -914,7 +915,16 @@ class PathsQueryRunner(AnalyticsQueryRunner[PathsQueryResponse]):
for source, target, value, avg_conversion_time in response.results
)
- return PathsQueryResponse(results=results, timings=response.timings, hogql=hogql, modifiers=self.modifiers)
+ return PathsQueryResponse(
+ results=results,
+ timings=response.timings,
+ hogql=hogql,
+ modifiers=self.modifiers,
+ resolved_date_range=ResolvedDateRangeResponse(
+ date_from=self.query_date_range.date_from(),
+ date_to=self.query_date_range.date_to(),
+ ),
+ )
@property
def extra_event_fields_and_properties(self) -> list[str]:
diff --git a/products/product_analytics/backend/hogql_queries/stickiness/stickiness_query_runner.py b/products/product_analytics/backend/hogql_queries/stickiness/stickiness_query_runner.py
index a7edbc6f408e..82749b9dd876 100644
--- a/products/product_analytics/backend/hogql_queries/stickiness/stickiness_query_runner.py
+++ b/products/product_analytics/backend/hogql_queries/stickiness/stickiness_query_runner.py
@@ -12,6 +12,7 @@ from posthog.schema import (
DataWarehouseNode,
EventsNode,
HogQLQueryModifiers,
+ ResolvedDateRangeResponse,
StickinessComputationMode,
StickinessQuery,
StickinessQueryResponse,
@@ -383,7 +384,16 @@ class StickinessQueryRunner(AnalyticsQueryRunner[StickinessQueryResponse]):
res.append(series_object)
- return StickinessQueryResponse(results=res, timings=timings, modifiers=self.modifiers, hogql=response_hogql)
+ return StickinessQueryResponse(
+ results=res,
+ timings=timings,
+ modifiers=self.modifiers,
+ hogql=response_hogql,
+ resolved_date_range=ResolvedDateRangeResponse(
+ date_from=self.query_date_range.date_from(),
+ date_to=self.query_date_range.date_to(),
+ ),
+ )
def where_clause(self, series_with_extra: SeriesWithExtras) -> ast.Expr:
date_range = self.date_range(series_with_extra)
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index c13a6100faef..458f4ef75a85 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -39697,6 +39697,10 @@ export namespace Schemas {
onboarding_tasks?: unknown;
/** @nullable */
web_analytics_pre_aggregated_tables_enabled?: boolean | null;
+ /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. */
+ readonly event_retention_months?: number;
+ /** Whether events data retention is currently enforced for this team (cohort/flag gated). */
+ readonly events_retention_enforced?: boolean;
}
export interface PatchedProjectSecretAPIKey {
@@ -41492,6 +41496,10 @@ export namespace Schemas {
readonly product_intents?: readonly PatchedTeamProductIntentsItem[];
readonly managed_viewsets?: PatchedTeamManagedViewsets;
readonly available_setup_task_ids?: readonly AvailableSetupTaskIdsEnum[];
+ /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. */
+ readonly event_retention_months?: number;
+ /** Whether events data retention is currently enforced for this team (cohort/flag gated). */
+ readonly events_retention_enforced?: boolean;
}
/**
@@ -43205,6 +43213,10 @@ export namespace Schemas {
onboarding_tasks?: unknown;
/** @nullable */
web_analytics_pre_aggregated_tables_enabled?: boolean | null;
+ /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. */
+ readonly event_retention_months: number;
+ /** Whether events data retention is currently enforced for this team (cohort/flag gated). */
+ readonly events_retention_enforced: boolean;
}
/**
@@ -51806,6 +51818,10 @@ export namespace Schemas {
readonly product_intents: readonly TeamProductIntentsItem[];
readonly managed_viewsets: TeamManagedViewsets;
readonly available_setup_task_ids: readonly AvailableSetupTaskIdsEnum[];
+ /** The team's events data retention window in months (plan-derived, synced from billing). When retention enforcement is active for the team, queries do not return events older than this many months. */
+ readonly event_retention_months: number;
+ /** Whether events data retention is currently enforced for this team (cohort/flag gated). */
+ readonly events_retention_enforced: boolean;
}
export type TestHogRequestConditionsItem = { [key: string]: unknown };