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(insights): always hide auto-generated feature flag insights (#102125)

Sam Pennington1a2a9a2abf32
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index e6c535935df4..0c32d269268c 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -9857,21 +9857,21 @@ snapshots:
scenes-app-replay-vision-test-account-filter-settings-dialog--default--light:
hash: v1.k794b7964.8276936411550e5ab99aa3d216a442c6328a55434a4bcf273cbef46a39d940b4.asrT7Nd6P9HVchxOoJPfMOOttbQVP6XFXptRAtnXC3k
scenes-app-saved-insights--empty-state--dark:
- hash: v1.k794b7964.43545664c9133c8afd354be6a6ed8f808c35b381101325d9605114632fcdc0c9.l8w9uEOEmrH6Xl1kNd9ueRtg_51cJUSjWLdjWDM0Fko
+ hash: v1.k794b7964.ff0f2df92187cffc330d9fc2cf2f72e93088e8857ebd24b56669d4f31b1d573e.sDfYAinczOzsIykVtv17_GSU9n5d88H5GILgilzNzfg
scenes-app-saved-insights--empty-state--light:
- hash: v1.k794b7964.51af80cf2b3eecf0b3b5265d0436d838e0005c3eaaf6c3d6864fe39b95395c99.X5NeESdMpZsVx89cw3gJIhyFSwfiWqeJc8iiTdBlif8
+ hash: v1.k794b7964.06d078c331d25616e66f8a7fe17d2da64a4463dd5fef58488b48fed6dbe16c83.E7qIcHI8imJfuYrOeYjAG_Xc7u86HKN5iJ8JGjyZL14
scenes-app-saved-insights--error-state--dark:
- hash: v1.k794b7964.e36c42a3d00537e266ce0f36ed697e8725d21d659bf6f0474effac61ec9e9ab7.NK9LPesw67E4MoiSNayIfQK-Pq9AGmFBAGMMZfTDq3M
+ hash: v1.k794b7964.97eca32497e04c403e975e4114a7a144c20ac2d32ab89f98aa247136ab2d0457.l3Iw0G-o40K5hWnI2rEHDZfJTzV282b0lm5fQvP14a0
scenes-app-saved-insights--error-state--light:
- hash: v1.k794b7964.be46188af42c8c13e3f85dc5bdddedfe6d03860b4dc60d7fe50271f63791540e.WW0hRR8a1JnTW_-QEgfYc7kcJXrCVI4fKKAGYgn0lxo
+ hash: v1.k794b7964.6236e2139e033c4547aa3667b37627916d0d3b2d99cb346e98f2e18ccdd8ad14.huJk5GngTJ7oP9eYDf5S9kUO6OafLC9tKCYuxN-rbfE
scenes-app-saved-insights--list-view--dark:
- hash: v1.k794b7964.1a5aa80f818d3ef28c13fcfa5f31e1fb63d06e0f1e41784b6106c46baea27a4e.qmZSyrTsDuLr2Y8FF97SwzbzcqSneHIan3-gsQ9EXhk
+ hash: v1.k794b7964.f20f4295f774b1892a3a9f52f2f4ebbeff75798bbc343b9874e1f6a95d410a4b.U6DhbwV1uNDFfQpUKmQ4F3kpvez3A0iemwOpgsZHo-g
scenes-app-saved-insights--list-view--light:
- hash: v1.k794b7964.887dafc11415b09046668e451f5810d88371554319d3003ea16c3753d047ed04.31KTuyVQ4v4QbXG9Z8tTLEEmNMQK4pQS_vPnOowbJ24
+ hash: v1.k794b7964.069a9cc60f8d3b0bedfff67bf6f77d5e724d76237789496a296d74a304effbdf.1Cmm0yQPdz1n_UzfwHBCClBBRzubLBwirpm0sfdPAPU
scenes-app-saved-insights--search-results--dark:
- hash: v1.k794b7964.e9ffaf5a9af0f5e766cba20128491f842dce8849c041b3d3f4e6432e94306998.dHNQ6L9tFR-OVJ-o_zgDyElo7v8pXfSoXl8ZEBl20eE
+ hash: v1.k794b7964.7442501d5b602a95efa6bce64f1698b35d2f5da271d4babff23036e271877f23.OvYSpQS8fSSwMJi5V3Qc4QPqtT5Swfd1_7aqSFToRww
scenes-app-saved-insights--search-results--light:
- hash: v1.k794b7964.a7e1c5334e9e3c3ea3c616dbf31ab9d8e0cc428db4376f10152b022959500d5e.CNZ66Ebm_c7BNBYLPPBwS9iiz2O3P-mkE46XuBkGKos
+ hash: v1.k794b7964.d0814b477b35a38c48d6b91e582f6fb003d8fbc0fdb98228d78b278217c0bdc2.TG-NSX1eaZP7N0ch1KniCgIPVar96Pu92WjwNwhxvfk
scenes-app-saved-insights-new-insight-menu--overlay--dark:
hash: v1.k794b7964.5a65f3fe94b288f66e436ecd8677bc2d1b3fe08ca885f03eae64bc8847b783ee.YfBWEDQwkl46pC03TjLQBVNXq96nOm91Lc0KcpIXegc
scenes-app-saved-insights-new-insight-menu--overlay--light:
diff --git a/frontend/src/scenes/saved-insights/SavedInsights.tsx b/frontend/src/scenes/saved-insights/SavedInsights.tsx
index 834c5e31b223..e72a9244ba42 100644
--- a/frontend/src/scenes/saved-insights/SavedInsights.tsx
+++ b/frontend/src/scenes/saved-insights/SavedInsights.tsx
@@ -375,9 +375,7 @@ export function SavedInsights(): JSX.Element {
filters={filters}
setFilters={setSavedInsightsFilters}
quickFilters={
- tab === SavedInsightsTabs.Yours
- ? ['insightType', 'tags', 'favorites', 'featureFlags']
- : undefined
+ tab === SavedInsightsTabs.Yours ? ['insightType', 'tags', 'favorites'] : undefined
}
/>
<LemonTable
diff --git a/frontend/src/scenes/saved-insights/SavedInsightsFilters.tsx b/frontend/src/scenes/saved-insights/SavedInsightsFilters.tsx
index 897359f88d2c..30fea013ddae 100644
--- a/frontend/src/scenes/saved-insights/SavedInsightsFilters.tsx
+++ b/frontend/src/scenes/saved-insights/SavedInsightsFilters.tsx
@@ -1,21 +1,19 @@
import posthog from 'posthog-js'
-import { IconFlag, IconHeart, IconHeartFilled } from '@posthog/icons'
+import { IconHeart, IconHeartFilled } from '@posthog/icons'
import { MemberSelectMultiplePopover } from 'lib/components/MemberSelectMultiplePopover'
import { LemonButton } from 'lib/lemon-ui/LemonButton'
import { LemonInput } from 'lib/lemon-ui/LemonInput/LemonInput'
import { LemonSelect } from 'lib/lemon-ui/LemonSelect'
-import { LemonSwitch } from 'lib/lemon-ui/LemonSwitch'
-import { Tooltip } from 'lib/lemon-ui/Tooltip'
import { cn } from 'lib/utils/css-classes'
import { INSIGHT_TYPE_OPTIONS } from 'scenes/saved-insights/SavedInsights'
import { SavedInsightFilters } from 'scenes/saved-insights/savedInsightsLogic'
import { SavedInsightsTagSelect } from './SavedInsightsTagSelect'
-export type QuickFilterKind = 'insightType' | 'tags' | 'createdBy' | 'favorites' | 'featureFlags'
-const ALL_QUICK_FILTERS: QuickFilterKind[] = ['insightType', 'tags', 'createdBy', 'favorites', 'featureFlags']
+export type QuickFilterKind = 'insightType' | 'tags' | 'createdBy' | 'favorites'
+const ALL_QUICK_FILTERS: QuickFilterKind[] = ['insightType', 'tags', 'createdBy', 'favorites']
export function SavedInsightsFilters({
filters,
@@ -29,7 +27,7 @@ export function SavedInsightsFilters({
/** When true, inactive filters appear borderless. */
borderless?: boolean
}): JSX.Element {
- const { search, hideFeatureFlagInsights, favorited, tags, insightType, createdBy } = filters
+ const { search, favorited, tags, insightType, createdBy } = filters
const quickFilterSet = new Set(quickFilters)
const hasInsightTypeSelection = !!insightType && insightType !== 'All types'
@@ -101,48 +99,8 @@ export function SavedInsightsFilters({
Favorites
</LemonButton>
)}
- {quickFilterSet.has('featureFlags') && (
- <FeatureFlagInsightsToggle
- hideFeatureFlagInsights={hideFeatureFlagInsights ?? undefined}
- onToggle={(checked) => setFilters({ hideFeatureFlagInsights: checked })}
- />
- )}
</div>
)}
</div>
)
}
-
-const FeatureFlagInsightsToggle = ({
- hideFeatureFlagInsights,
- onToggle,
-}: {
- hideFeatureFlagInsights?: boolean
- onToggle: (checked: boolean) => void
-}): JSX.Element => {
- return (
- <Tooltip
- title={
- <div>
- <p>
- PostHog automatically creates insights by default for feature flags to help you understand their
- performance.
- </p>
- <p className="mb-0">
- Use this toggle to hide these auto-generated insights from your insights list.
- </p>
- </div>
- }
- placement="top"
- >
- <LemonButton
- icon={<IconFlag />}
- onClick={() => onToggle(!hideFeatureFlagInsights)}
- type="tertiary"
- size="small"
- >
- Hide feature flag insights: <LemonSwitch checked={hideFeatureFlagInsights || false} className="ml-1" />
- </LemonButton>
- </Tooltip>
- )
-}
diff --git a/frontend/src/scenes/saved-insights/savedInsightsLogic.test.ts b/frontend/src/scenes/saved-insights/savedInsightsLogic.test.ts
index 6adbce3e4cb3..a9efd0262059 100644
--- a/frontend/src/scenes/saved-insights/savedInsightsLogic.test.ts
+++ b/frontend/src/scenes/saved-insights/savedInsightsLogic.test.ts
@@ -91,6 +91,10 @@ describe('savedInsightsLogic', () => {
await expectLogic(logic).toDispatchActions(['setSavedInsightsFilters', 'loadInsights', 'loadInsightsSuccess'])
})
+ it('always asks the API to exclude auto-generated feature flag insights', () => {
+ expect(logic.values.paramsFromFilters).toMatchObject({ hide_feature_flag_insights: true })
+ })
+
it('can filter the insights', async () => {
// makes a search query
logic.actions.setSavedInsightsFilters({ search: 'hello' })
@@ -419,7 +423,6 @@ describe('savedInsightsLogic', () => {
['created by', { createdBy: [1] }],
['favorites', { favorited: true }],
['a date range', { dateFrom: '-7d' }],
- ['the feature flag insights toggle', { hideFeatureFlagInsights: true }],
['a dashboard', { dashboardId: 5 }],
])('counts %s as a narrowing filter', (_label, overrides) => {
expect(hasNarrowingFilters(cleanFilters(overrides))).toBe(true)
diff --git a/frontend/src/scenes/saved-insights/savedInsightsLogic.ts b/frontend/src/scenes/saved-insights/savedInsightsLogic.ts
index 2f3defdcdebe..ef262c8bfe44 100644
--- a/frontend/src/scenes/saved-insights/savedInsightsLogic.ts
+++ b/frontend/src/scenes/saved-insights/savedInsightsLogic.ts
@@ -66,7 +66,6 @@ export interface SavedInsightFilters {
page: number
dashboardId: number | undefined | null
events: string[] | undefined | null
- hideFeatureFlagInsights: boolean | undefined | null
favorited: boolean | undefined | null
}
@@ -88,7 +87,6 @@ export function cleanFilters(values: Partial<SavedInsightFilters>): SavedInsight
page: parseInt(String(values.page)) || 1,
dashboardId: values.dashboardId,
events: values.events,
- hideFeatureFlagInsights: values.hideFeatureFlagInsights || false,
favorited: values.favorited || false,
}
}
@@ -100,6 +98,8 @@ function insightsListParams(filters: SavedInsightFilters): Record<string, any> {
limit: INSIGHTS_PER_PAGE,
offset: Math.max(0, (filters.page - 1) * INSIGHTS_PER_PAGE),
saved: true,
+ // PostHog no longer generates these, and the flag Usage tab still shows the same charts
+ hide_feature_flag_insights: true,
...(filters.favorited && { favorited: true }),
...(filters.search && { search: filters.search }),
...(filters.insightType?.toLowerCase() !== 'all types' && {
@@ -129,12 +129,11 @@ function insightsListParams(filters: SavedInsightFilters): Record<string, any> {
...(!!filters.dashboardId && {
dashboards: [filters.dashboardId],
}),
- ...(filters.hideFeatureFlagInsights && { hide_feature_flag_insights: true }),
}
}
/** Params that scope, page, or sort the list rather than filter it. */
-const NON_NARROWING_PARAM_KEYS = ['order', 'limit', 'offset', 'saved', 'user']
+const NON_NARROWING_PARAM_KEYS = ['order', 'limit', 'offset', 'saved', 'user', 'hide_feature_flag_insights']
/**
* Whether any filter that narrows the insights list is active, i.e. the API request would carry a
diff --git a/posthog/helpers/dashboard_templates.py b/posthog/helpers/dashboard_templates.py
index 043280383b93..f4073b80ee7a 100644
--- a/posthog/helpers/dashboard_templates.py
+++ b/posthog/helpers/dashboard_templates.py
@@ -718,8 +718,36 @@ FEATURE_FLAG_UNIQUE_CALLS_INSIGHT_NAME_SUFFIX = " per variant"
FEATURE_FLAG_UNIQUE_USERS_INSIGHT_NAME = (
f"{FEATURE_FLAG_UNIQUE_CALLS_INSIGHT_NAME_PREFIX}users{FEATURE_FLAG_UNIQUE_CALLS_INSIGHT_NAME_SUFFIX}"
)
+# The generated descriptions interpolate the flag key, so only their ends are fixed.
+FEATURE_FLAG_CALLS_DESCRIPTION_PREFIX = "Shows the number of"
+FEATURE_FLAG_CALLS_DESCRIPTION_FRAGMENT = "calls made on feature flag"
FEATURE_FLAG_ENRICHED_VIEW_INSIGHT_NAME = f"{ENRICHED_DASHBOARD_INSIGHT_IDENTIFIER} Total Volume"
FEATURE_FLAG_ENRICHED_INTERACTION_INSIGHT_NAME = "Feature Interaction Total Volume"
+FEATURE_FLAG_ENRICHED_INSIGHT_DESCRIPTION = (
+ "Shows the total number of times this feature was viewed and interacted with"
+)
+
+
+def feature_flag_generated_insight_q() -> Q:
+ """Match the insights this module generated for a feature flag usage dashboard.
+
+ A name on its own is not provenance, because a person can type any of these, so each name is
+ paired with the description the template writes beside it. That makes this narrower than
+ `delete_feature_flag_usage_insights._classifier_q`, which matches a name or a description so a
+ cleanup sweep still reaches rows an older template version wrote.
+ """
+ return Q(
+ Q(name=FEATURE_FLAG_TOTAL_VOLUME_INSIGHT_NAME)
+ | Q(
+ name__startswith=FEATURE_FLAG_UNIQUE_CALLS_INSIGHT_NAME_PREFIX,
+ name__endswith=FEATURE_FLAG_UNIQUE_CALLS_INSIGHT_NAME_SUFFIX,
+ ),
+ description__startswith=FEATURE_FLAG_CALLS_DESCRIPTION_PREFIX,
+ description__contains=FEATURE_FLAG_CALLS_DESCRIPTION_FRAGMENT,
+ ) | Q(
+ name__in=[FEATURE_FLAG_ENRICHED_VIEW_INSIGHT_NAME, FEATURE_FLAG_ENRICHED_INTERACTION_INSIGHT_NAME],
+ description=FEATURE_FLAG_ENRICHED_INSIGHT_DESCRIPTION,
+ )
def _get_aggregation_entity_labels(feature_flag) -> tuple[str | None, str | None]:
@@ -1217,7 +1245,7 @@ def add_enriched_insights_to_feature_flag_dashboard(feature_flag, dashboard: Das
_create_tile_for_insight(
dashboard,
name=FEATURE_FLAG_ENRICHED_VIEW_INSIGHT_NAME,
- description="Shows the total number of times this feature was viewed and interacted with",
+ description=FEATURE_FLAG_ENRICHED_INSIGHT_DESCRIPTION,
query={
"kind": "InsightVizNode",
"source": {
@@ -1265,7 +1293,7 @@ def add_enriched_insights_to_feature_flag_dashboard(feature_flag, dashboard: Das
_create_tile_for_insight(
dashboard,
name=FEATURE_FLAG_ENRICHED_INTERACTION_INSIGHT_NAME,
- description="Shows the total number of times this feature was viewed and interacted with",
+ description=FEATURE_FLAG_ENRICHED_INSIGHT_DESCRIPTION,
query={
"kind": "InsightVizNode",
"source": {
diff --git a/products/feature_flags/backend/management/commands/delete_feature_flag_usage_insights.py b/products/feature_flags/backend/management/commands/delete_feature_flag_usage_insights.py
index 98a8c35cf0e0..79149d7a6473 100644
--- a/products/feature_flags/backend/management/commands/delete_feature_flag_usage_insights.py
+++ b/products/feature_flags/backend/management/commands/delete_feature_flag_usage_insights.py
@@ -11,6 +11,8 @@ from django.db.models import F, Q, QuerySet
from django.utils.timezone import now
from posthog.helpers.dashboard_templates import (
+ FEATURE_FLAG_CALLS_DESCRIPTION_FRAGMENT,
+ FEATURE_FLAG_CALLS_DESCRIPTION_PREFIX,
FEATURE_FLAG_ENRICHED_INTERACTION_INSIGHT_NAME,
FEATURE_FLAG_ENRICHED_VIEW_INSIGHT_NAME,
FEATURE_FLAG_TOTAL_VOLUME_INSIGHT_NAME,
@@ -56,7 +58,10 @@ def _classifier_q() -> Q:
)
| Q(name=FEATURE_FLAG_ENRICHED_VIEW_INSIGHT_NAME)
| Q(name=FEATURE_FLAG_ENRICHED_INTERACTION_INSIGHT_NAME)
- | Q(description__startswith="Shows the number of", description__contains="calls made on feature flag")
+ | Q(
+ description__startswith=FEATURE_FLAG_CALLS_DESCRIPTION_PREFIX,
+ description__contains=FEATURE_FLAG_CALLS_DESCRIPTION_FRAGMENT,
+ )
| Q(description__startswith="Shows the total number of times this feature was viewed")
)
diff --git a/products/product_analytics/backend/presentation/insight.py b/products/product_analytics/backend/presentation/insight.py
index 9b88a0db818e..7370ec5c7486 100644
--- a/products/product_analytics/backend/presentation/insight.py
+++ b/products/product_analytics/backend/presentation/insight.py
@@ -2052,15 +2052,9 @@ class InsightViewSet(
queryset = queryset.filter(Q(favorited=True))
elif key == "hide_feature_flag_insights":
if str_to_bool(request.GET["hide_feature_flag_insights"]):
- # Exclude insights with the specific feature flag names
- from posthog.helpers.dashboard_templates import (
- FEATURE_FLAG_TOTAL_VOLUME_INSIGHT_NAME,
- FEATURE_FLAG_UNIQUE_USERS_INSIGHT_NAME,
- )
+ from posthog.helpers.dashboard_templates import feature_flag_generated_insight_q
- queryset = queryset.exclude(
- name__in=[FEATURE_FLAG_TOTAL_VOLUME_INSIGHT_NAME, FEATURE_FLAG_UNIQUE_USERS_INSIGHT_NAME]
- )
+ queryset = queryset.exclude(feature_flag_generated_insight_q())
elif key == "date_from":
queryset = queryset.filter(
last_modified_at__gt=relative_date_parse(request.GET["date_from"], self.team.timezone_info)
diff --git a/products/product_analytics/backend/tests/api/test_insight.py b/products/product_analytics/backend/tests/api/test_insight.py
index 08c5f29512b7..5a97503286a9 100644
--- a/products/product_analytics/backend/tests/api/test_insight.py
+++ b/products/product_analytics/backend/tests/api/test_insight.py
@@ -454,6 +454,9 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
def test_hide_feature_flag_insights_filter(self) -> None:
from posthog.helpers.dashboard_templates import (
+ FEATURE_FLAG_ENRICHED_INSIGHT_DESCRIPTION,
+ FEATURE_FLAG_ENRICHED_INTERACTION_INSIGHT_NAME,
+ FEATURE_FLAG_ENRICHED_VIEW_INSIGHT_NAME,
FEATURE_FLAG_TOTAL_VOLUME_INSIGHT_NAME,
FEATURE_FLAG_UNIQUE_USERS_INSIGHT_NAME,
)
@@ -462,43 +465,50 @@ class TestInsight(ClickhouseTestMixin, APIBaseTest, QueryMatchingTest):
"events": [{"id": "$pageview"}],
"properties": [{"key": "$browser", "value": "Mac OS X"}],
}
+ generated = [
+ (
+ FEATURE_FLAG_TOTAL_VOLUME_INSIGHT_NAME,
+ "Shows the number of total calls made on feature flag with key: my-flag",
+ ),
+ (
+ FEATURE_FLAG_UNIQUE_USERS_INSIGHT_NAME,
+ "Shows the number of unique user calls made on feature flag per variant with key: my-flag",
+ ),
+ # A group-aggregated flag names its entity instead of "users"
+ (
+ "Feature Flag calls made by unique organizations per variant",
+ "Shows the number of unique organization calls made on feature flag per variant with key: my-flag",
+ ),
+ (FEATURE_FLAG_ENRICHED_VIEW_INSIGHT_NAME, FEATURE_FLAG_ENRICHED_INSIGHT_DESCRIPTION),
+ (FEATURE_FLAG_ENRICHED_INTERACTION_INSIGHT_NAME, FEATURE_FLAG_ENRICHED_INSIGHT_DESCRIPTION),
+ ]
+ # A generated name a person can reuse, which the description tells apart
+ kept = [
+ ("Regular Insight", ""),
+ (FEATURE_FLAG_TOTAL_VOLUME_INSIGHT_NAME, "My own copy of this chart"),
+ (FEATURE_FLAG_ENRICHED_VIEW_INSIGHT_NAME, "My own copy of this chart"),
+ ]
- # Create feature flag insights
- Insight.objects.create(
- name=FEATURE_FLAG_TOTAL_VOLUME_INSIGHT_NAME,
- filters=Filter(data=filter_dict).to_dict(),
- saved=True,
- team=self.team,
- created_by=self.user,
- )
-
- Insight.objects.create(
- name=FEATURE_FLAG_UNIQUE_USERS_INSIGHT_NAME,
- filters=Filter(data=filter_dict).to_dict(),
- saved=True,
- team=self.team,
- created_by=self.user,
- )
-
- # Create a regular insight
- Insight.objects.create(
- name="Regular Insight",
- filters=Filter(data=filter_dict).to_dict(),
- saved=True,
- team=self.team,
- created_by=self.user,
- )
+ for name, description in generated + kept:
+ Insight.objects.create(
+ name=name,
+ description=description,
+ filters=Filter(data=filter_dict).to_dict(),
+ saved=True,
+ team=self.team,
+ created_by=self.user,
+ )
- # Without filter, should return all 3 insights
response = self.client.get(f"/api/projects/{self.team.id}/insights/?saved=true")
self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(len(response.json()["results"]), 3)
+ self.assertEqual(len(response.json()["results"]), len(generated) + len(kept))
- # With filter, should exclude feature flag insights
response = self.client.get(f"/api/projects/{self.team.id}/insights/?saved=true&hide_feature_flag_insights=true")
self.assertEqual(response.status_code, status.HTTP_200_OK)
- self.assertEqual(len(response.json()["results"]), 1)
- self.assertEqual(response.json()["results"][0]["name"], "Regular Insight")
+ self.assertEqual(
+ sorted((result["name"], result["description"]) for result in response.json()["results"]),
+ sorted(kept),
+ )
def test_get_insight_in_dashboard_context(self) -> None:
dashboard_id, _ = self.dashboard_api.create_dashboard(