: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore: Add Web analytics achievements to the context menu (#64946)
Jordan Mryyan952816d4c7b6
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex cd0afdb12f5d..25d4f291dc37 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -325,6 +325,7 @@ export const FEATURE_FLAGS = {HEALTH_ASK_AI: 'health-ask-ai', // owner: @jordanm-posthog #team-web-analytics, gates the "Ask PostHog AI" buttons on the Health overviewHOGQL_INSIGHT_ALERTS: 'hogql-insight-alerts', // owner: @vdekrijger, gates alerts on SQL-backed (HogQL) insightsIDENTITY_MATCHING: 'identity-matching', // owner: #team-growth+ INSIGHT_ADD_TO_DASHBOARD_AAB: 'insight-add-to-dashboard-aab', // owner: @pauldambra #team-product-analytics multivariate=control,control_2,testINSIGHT_SUBSCRIBE_PROMINENT_BUTTON: 'insight-subscribe-prominent-button', // owner: @mattp #team-analytics-platform multivariate=control,testINTER_PROJECT_TRANSFERS: 'inter-project-transfers', // owner: @reecejones #team-platform-featuresJS_SNIPPET_VERSIONING: 'js-snippet-versioning', // owner: #team-client-libraries@@ -431,7 +432,6 @@ export const FEATURE_FLAGS = {PRODUCT_ANALYTICS_FUNNELS_COMPARE: 'product-analytics-funnels-compare', // owner: @thmsobrmlr #team-product-analytics, gates "Compare to previous" toggle on funnel insightsPRODUCT_ANALYTICS_HIDE_WEEKENDS: 'product-analytics-hide-weekends', // owner: @kliment-slice #team-irl-eventsPRODUCT_ANALYTICS_INSIGHT_HORIZONTAL_CONTROLS: 'insight-horizontal-controls', // owner: #team-product-analytics- INSIGHT_ADD_TO_DASHBOARD_AAB: 'insight-add-to-dashboard-aab', // owner: @pauldambra #team-product-analytics multivariate=control,control_2,testPRODUCT_ANALYTICS_PATHS_V2: 'paths-v2', // owner: @thmsobrmlr #team-product-analyticsPRODUCT_ANALYTICS_QUILL_LEGEND: 'product-analytics-quill-legend', // owner: #team-product-analytics, gates the in-chart quill legend replacing the legacy side InsightLegendPRODUCT_ANALYTICS_QUILL_SQL_CHARTS: 'product-analytics-quill-sql-charts', // owner: #team-data-tools, gates rendering DataVisualization line/area charts via @posthog/quill-charts@@ -521,7 +521,7 @@ export const FEATURE_FLAGS = {WEB_ANALYTICS_REGIONS_MAP: 'web-analytics-regions-map', // owner: @jordanm-posthog #team-web-analyticsWEB_ANALYTICS_SESSION_PROPERTY_CHARTS: 'web-analytics-session-property-charts', // owner: @lricoy #team-web-analyticsWEB_ANALYTICS_SHARE_NUDGE_V2: 'web-analytics-share-nudge-v2', // owner: @jordanm-posthog #team-web-analytics multivariate=control,control_b,banner,export- WEB_ANALYTICS_STREAK_CADENCE: 'web-analytics-streak-cadence', // owner: @jordanm-posthog #team-web-analytics multivariate=holdout,hybrid,daily-only,weekly-only+ WEB_ANALYTICS_STREAK_CADENCE: 'web-analytics-streak-cadence', // owner: @jordanm-posthog #team-web-analytics multivariate=control,hybrid,daily-only,weekly-onlyWEB_ANALYTICS_TILE_HEADER_V2: 'web-analytics-tile-header-v2', // owner: @jordanm-posthog #team-web-analytics multivariate=control,testWEB_ANALYTICS_TILE_SKELETONS: 'web-analytics-tile-skeletons', // owner: @jordanm-posthog #team-web-analyticsWEB_ANALYTICS_TILE_TOGGLES: 'web-analytics-tile-toggles', // owner: @lricoy #team-web-analyticsdiff --git a/frontend/src/scenes/web-analytics/WebAnalyticsMenu.tsx b/frontend/src/scenes/web-analytics/WebAnalyticsMenu.tsxindex 998f1dd34a76..09e935761107 100644--- a/frontend/src/scenes/web-analytics/WebAnalyticsMenu.tsx+++ b/frontend/src/scenes/web-analytics/WebAnalyticsMenu.tsx@@ -1,6 +1,6 @@import { useActions, useValues } from 'kea'-import { IconGear, IconSearch, IconTarget, IconX } from '@posthog/icons'+import { IconGear, IconSearch, IconStar, IconTarget, IconX } from '@posthog/icons'import { FEATURE_FLAGS } from 'lib/constants'import { LemonSwitch } from 'lib/lemon-ui/LemonSwitch'@@ -13,6 +13,8 @@ import { webAnalyticsLogic } from 'scenes/web-analytics/webAnalyticsLogic'import { ScenePanel, ScenePanelActionsSection, ScenePanelDivider, ScenePanelLabel } from '~/layout/scenes/SceneLayout'+import { isWebAnalyticsAchievementsEnabled } from './achievements/gating'+import { webAnalyticsAchievementsLogic } from './achievements/webAnalyticsAchievementsLogic'import { ProductTab, TILE_LABELS, TileId } from './common'const ANALYTICS_TILES = [@@ -37,8 +39,10 @@ export const WebAnalyticsMenu = (): JSX.Element => {const { enterFocusMode, exitFocusMode, openFocusModeModal, setUseWebAnalyticsPrecompute, setTileVisibility } =useActions(webAnalyticsLogic)+ const { openModal: openAchievementsModal } = useActions(webAnalyticsAchievementsLogic)const showTileToggles = featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_TILE_TOGGLES]+ const showAchievements = isWebAnalyticsAchievementsEnabled(featureFlags)const availableTiles = productTab === ProductTab.ANALYTICS ? ANALYTICS_TILES : []return (@@ -65,6 +69,12 @@ export const WebAnalyticsMenu = (): JSX.Element => {Enter focus mode</ButtonPrimitive>) : null)}+ {showAchievements && (+ <ButtonPrimitive menuItem onClick={() => openAchievementsModal()}>+ <IconStar />+ Achievements+ </ButtonPrimitive>+ )}</ScenePanelActionsSection>{featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_PRECOMPUTE_TOGGLE] && (<>diff --git a/frontend/src/scenes/web-analytics/achievements/gating.ts b/frontend/src/scenes/web-analytics/achievements/gating.tsindex 7fc3d945ae8d..6ac10f11aa5e 100644--- a/frontend/src/scenes/web-analytics/achievements/gating.ts+++ b/frontend/src/scenes/web-analytics/achievements/gating.ts@@ -4,6 +4,6 @@ import { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'export function isWebAnalyticsAchievementsEnabled(featureFlags: FeatureFlagsSet): boolean {return (!!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_ACHIEVEMENTS] &&- featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_STREAK_CADENCE] !== 'holdout'+ featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_STREAK_CADENCE] !== 'control')}diff --git a/products/web_analytics/backend/achievements/definitions.py b/products/web_analytics/backend/achievements/definitions.pyindex f56eb3d6e20b..60e949cc8ca1 100644--- a/products/web_analytics/backend/achievements/definitions.py+++ b/products/web_analytics/backend/achievements/definitions.py@@ -16,7 +16,7 @@ class TrackKey(StrEnum):TRAFFIC = "traffic"-STREAK_ARM_HOLDOUT = "holdout"+STREAK_ARM_CONTROL = "control"STREAK_ARM_HYBRID = "hybrid"STREAK_ARM_DAILY = "daily-only"STREAK_ARM_WEEKLY = "weekly-only"diff --git a/products/web_analytics/backend/achievements/tasks.py b/products/web_analytics/backend/achievements/tasks.pyindex 6e735c104e1b..1f8cc61ce2a9 100644--- a/products/web_analytics/backend/achievements/tasks.py+++ b/products/web_analytics/backend/achievements/tasks.py@@ -23,7 +23,7 @@ from products.notifications.backend.facade.api import (create_notification,)from products.web_analytics.backend.achievements.definitions import (- STREAK_ARM_HOLDOUT,+ STREAK_ARM_CONTROL,TRACKS,AchievementScope,TrackDefinition,@@ -87,7 +87,7 @@ def recompute_web_analytics_achievements(team_id: int, user_id: int | None = Nonif user_id is not None:user = User.objects.get(id=user_id)arm = streak_arm_for_user(user)- if arm == STREAK_ARM_HOLDOUT:+ if arm == STREAK_ARM_CONTROL:returnctx = EvalContext(team=team, user=user, today=today, arm=arm)for track in TRACKS.values():diff --git a/products/web_analytics/backend/test/test_achievements_tasks.py b/products/web_analytics/backend/test/test_achievements_tasks.pyindex 098f89dc95fc..af89b4d8428c 100644--- a/products/web_analytics/backend/test/test_achievements_tasks.py+++ b/products/web_analytics/backend/test/test_achievements_tasks.py@@ -128,10 +128,10 @@ class TestRecomputeTask(BaseTest):progress.refresh_from_db()self.assertEqual(progress.state["pending_celebrations"], [])- def test_holdout_user_gets_no_compute(self) -> None:+ def test_control_user_gets_no_compute(self) -> None:with (patch.object(tasks, "EVALUATORS", make_evaluators(loyal_days=lambda ctx: 50)),- patch.object(tasks, "streak_arm_for_user", return_value="holdout"),+ patch.object(tasks, "streak_arm_for_user", return_value="control"),):tasks.recompute_web_analytics_achievements(self.team.id, self.user.id)self.assertFalse(WebAnalyticsAchievementProgress.objects.for_team(self.team.id).filter(user=self.user).exists())