: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
refactor(growth): separate nav ad broadcasts from product pushes (#91161)
Rafael Audibert6656bac80e7b
diff --git a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelAdvertisement.tsx b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelAdvertisement.tsxindex 3908cc2908c4..b4ca9f6da35e 100644--- a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelAdvertisement.tsx+++ b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelAdvertisement.tsx@@ -1,13 +1,14 @@import { useValues } from 'kea'+import { FEATURE_FLAGS } from 'lib/constants'import { getFeatureFlagPayload } from 'lib/logic/featureFlagLogic'import { preflightLogic } from 'lib/logic/preflightLogic'import { userLogic } from 'scenes/userLogic'import { panelLayoutLogic } from '~/layout/panel-layout/panelLayoutLogic'-import { CampaignPayload, isCampaignPayload } from './navPanelAdShared'-import { NavPanelCampaignAd } from './NavPanelCampaignAd'+import { BroadcastPayload, isBroadcastPayload } from './navPanelAdShared'+import { NavPanelBroadcastAd } from './NavPanelBroadcastAd'import { NavPanelProductPushAd } from './NavPanelProductPushAd'import { navPanelProductPushLogic } from './navPanelProductPushLogic'@@ -17,15 +18,16 @@ export function NavPanelAdvertisement(): JSX.Element | null {const { isCloudOrDev } = useValues(preflightLogic)const { user } = useValues(userLogic)- const campaignFlagPayload = getFeatureFlagPayload('nav-panel-campaign') as CampaignPayload | undefined+ const broadcastPayload = getFeatureFlagPayload(FEATURE_FLAGS.NAV_PANEL_BROADCAST) as BroadcastPayload | undefinedif (isLayoutNavCollapsed) {return null}- // Campaign flag payload takes priority over product recommendations, but campaigns promote cloud features so are not shown on hobby- if (isCloudOrDev && isCampaignPayload(campaignFlagPayload)) {- return <NavPanelCampaignAd campaign={campaignFlagPayload} />+ // A hand-authored broadcast outranks the scheduler, so a deliberate message is never preempted+ // by an automated push. Both cards promote cloud features, so neither is shown on hobby.+ if (isCloudOrDev && isBroadcastPayload(broadcastPayload)) {+ return <NavPanelBroadcastAd broadcast={broadcastPayload} />}// The org-wide product push campaign, driven by the growth backend. Respects thediff --git a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelAdvertisementLogic.ts b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelAdvertisementLogic.tsindex 9fa1024791c8..e4a72af96ff5 100644--- a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelAdvertisementLogic.ts+++ b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelAdvertisementLogic.ts@@ -1,7 +1,8 @@import { MakeLogicType, actions, kea, key, path, props, reducers } from 'kea'export type NavPanelAdvertisementLogicProps = {- campaign: string+ /** Identifies the card whose dismissal this instance holds, e.g. `broadcast-<slug>`. */+ dismissKey: string}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -30,7 +31,7 @@ export type navPanelAdvertisementLogicType = MakeLogicType<export const navPanelAdvertisementLogic = kea<navPanelAdvertisementLogicType>([path(['lib', 'components', 'NavPanelAdvertisementLogic']),props({} as NavPanelAdvertisementLogicProps),- key(({ campaign }) => campaign),+ key(({ dismissKey }) => dismissKey),actions(() => ({hideAdvertisement: () => true,showAdvertisement: () => false,diff --git a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelBroadcastAd.tsx b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelBroadcastAd.tsxnew file mode 100644index 000000000000..c85e36498eaa--- /dev/null+++ b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelBroadcastAd.tsx@@ -0,0 +1,44 @@+import { BindLogic, useValues } from 'kea'+import posthog from 'posthog-js'+import { useEffect } from 'react'++import { BroadcastPayload, AdvertisementCard, NAV_PANEL_CARD_TYPE } from './navPanelAdShared'+import { navPanelAdvertisementLogic } from './NavPanelAdvertisementLogic'++export function NavPanelBroadcastAd({ broadcast }: { broadcast: BroadcastPayload }): JSX.Element | null {+ const logicProps = { dismissKey: `broadcast-${broadcast.broadcast}` }+ const logic = navPanelAdvertisementLogic(logicProps)+ const { hidden } = useValues(logic)++ useEffect(() => {+ if (!hidden) {+ posthog.capture('nav panel broadcast shown', {+ broadcast: broadcast.broadcast,+ card_type: NAV_PANEL_CARD_TYPE.BROADCAST,+ product_key: broadcast.productKey,+ })+ }+ }, [broadcast.broadcast, broadcast.productKey, hidden])++ if (hidden) {+ return null+ }++ return (+ <BindLogic logic={navPanelAdvertisementLogic} props={logicProps}>+ <AdvertisementCard+ emoji={broadcast.emoji}+ emojiLabel={broadcast.emojiLabel}+ title={broadcast.title}+ text={broadcast.text}+ onClose={() => {+ posthog.capture('nav panel broadcast dismissed', {+ broadcast: broadcast.broadcast,+ card_type: NAV_PANEL_CARD_TYPE.BROADCAST,+ product_key: broadcast.productKey,+ })+ }}+ />+ </BindLogic>+ )+}diff --git a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelCampaignAd.tsx b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelCampaignAd.tsxdeleted file mode 100644index 5a8570e4bfc0..000000000000--- a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelCampaignAd.tsx+++ /dev/null@@ -1,38 +0,0 @@-import { BindLogic, useValues } from 'kea'-import posthog from 'posthog-js'-import { useEffect } from 'react'--import { CampaignPayload, AdvertisementCard } from './navPanelAdShared'-import { navPanelAdvertisementLogic } from './NavPanelAdvertisementLogic'--export function NavPanelCampaignAd({ campaign }: { campaign: CampaignPayload }): JSX.Element | null {- const logicProps = { campaign: `campaign-${campaign.campaign}` }- const logic = navPanelAdvertisementLogic(logicProps)- const { hidden } = useValues(logic)-- useEffect(() => {- if (!hidden) {- posthog.capture('nav panel campaign shown', { campaign: campaign.campaign })- }- }, [campaign.campaign, hidden])-- if (hidden) {- return null- }-- return (- <BindLogic logic={navPanelAdvertisementLogic} props={logicProps}>- <AdvertisementCard- emoji={campaign.emoji}- emojiLabel={campaign.emojiLabel}- title={campaign.title}- text={campaign.text}- onClose={() => {- posthog.capture('nav panel campaign dismissed', {- campaign: campaign.campaign,- })- }}- />- </BindLogic>- )-}diff --git a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelProductPushAd.stories.tsx b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelProductPushAd.stories.tsxindex f9b772aa0a4f..21df55422c90 100644--- a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelProductPushAd.stories.tsx+++ b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelProductPushAd.stories.tsx@@ -14,21 +14,21 @@ export default metatype Story = StoryObj<typeof meta>/**- * A card for a product push campaign. The campaign is the product key, the title is the product name, and the display is the product display.+ * One product push card, labelled with the product key it renders for.*/const PushCard = ({- campaign,+ productKey,title,display,}: {- campaign: string+ productKey: stringtitle: stringdisplay: ProductPushDisplay}): JSX.Element => (// The push card renders inside the (narrow) sidebar, so mirror that width here.<div className="w-[232px]">- <div className="mb-1 font-mono text-xs text-muted">{campaign}</div>- <BindLogic logic={navPanelAdvertisementLogic} props={{ campaign: `story-${campaign}` }}>+ <div className="mb-1 font-mono text-xs text-muted">{productKey}</div>+ <BindLogic logic={navPanelAdvertisementLogic} props={{ dismissKey: `story-${productKey}` }}><AdvertisementCard title={title} text={display.tagline} hero={display} /></BindLogic></div>@@ -51,7 +51,7 @@ export const AllProducts: Story = {([productKey, display]) => (<PushCardkey={productKey}- campaign={productKey}+ productKey={productKey}title={humanizeProductKey(productKey)}display={display}/>@@ -65,6 +65,6 @@ export const AllProducts: Story = {// What a product key with no bespoke entry falls back to (e.g. a TAM-scheduled push of an unlisted product).export const DefaultFallback: Story = {render: (): JSX.Element => (- <PushCard campaign="default_fallback" title="Any other product" display={DEFAULT_PRODUCT_PUSH_DISPLAY} />+ <PushCard productKey="default_fallback" title="Any other product" display={DEFAULT_PRODUCT_PUSH_DISPLAY} />),}diff --git a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelProductPushAd.tsx b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelProductPushAd.tsxindex 29f17aace123..230e87534e1a 100644--- a/frontend/src/lib/components/NavPanelAdvertisement/NavPanelProductPushAd.tsx+++ b/frontend/src/lib/components/NavPanelAdvertisement/NavPanelProductPushAd.tsx@@ -20,7 +20,7 @@ export function NavPanelProductPushAd({ campaign }: { campaign: ProductPushCampareturn (<div className="w-full"><Link to={productInfo.href} className="text-primary" onClick={() => reportAdClicked()}>- <BindLogic logic={navPanelAdvertisementLogic} props={{ campaign: `product-push-${campaign.id}` }}>+ <BindLogic logic={navPanelAdvertisementLogic} props={{ dismissKey: `product-push-${campaign.id}` }}><AdvertisementCardtitle={productInfo.displayLabel ?? productInfo.path}text={campaign.reason_text || display.tagline}diff --git a/frontend/src/lib/components/NavPanelAdvertisement/navPanelAdShared.test.ts b/frontend/src/lib/components/NavPanelAdvertisement/navPanelAdShared.test.tsnew file mode 100644index 000000000000..72619de3bebe--- /dev/null+++ b/frontend/src/lib/components/NavPanelAdvertisement/navPanelAdShared.test.ts@@ -0,0 +1,26 @@+import { BroadcastPayload, isBroadcastPayload } from './navPanelAdShared'++const VALID_PAYLOAD: BroadcastPayload = {+ broadcast: 'managed-warehouse-beta',+ text: 'Query everything in one place.',+ emoji: '🏠',+ emojiLabel: 'house emoji',+ title: 'Managed warehouse beta',+}++describe('navPanelAdShared', () => {+ describe('isBroadcastPayload', () => {+ // Broadcast payloads are hand-authored in the feature flag, so the guard has to keep+ // accepting a payload that names no product.+ it.each([+ ['without productKey', VALID_PAYLOAD, true],+ ['with a productKey', { ...VALID_PAYLOAD, productKey: 'session_replay' }, true],+ ['with an explicitly undefined productKey', { ...VALID_PAYLOAD, productKey: undefined }, true],+ ['with a non-string productKey', { ...VALID_PAYLOAD, productKey: 42 }, false],+ ['missing a required field', { ...VALID_PAYLOAD, title: undefined }, false],+ ['not an object', 'managed-warehouse-beta', false],+ ])('accepts or rejects a payload %s', (_description, value, expected) => {+ expect(isBroadcastPayload(value)).toBe(expected)+ })+ })+})diff --git a/frontend/src/lib/components/NavPanelAdvertisement/navPanelAdShared.tsx b/frontend/src/lib/components/NavPanelAdvertisement/navPanelAdShared.tsxindex b872950582fc..f9d943c6732a 100644--- a/frontend/src/lib/components/NavPanelAdvertisement/navPanelAdShared.tsx+++ b/frontend/src/lib/components/NavPanelAdvertisement/navPanelAdShared.tsx@@ -7,23 +7,45 @@ import { LemonButton } from 'lib/lemon-ui/LemonButton'import { navPanelAdvertisementLogic } from './NavPanelAdvertisementLogic'-export interface CampaignPayload {- campaign: string+/**+ * Which card filled the ad slot, sent as `card_type` on every ad-slot event.+ *+ * A broadcast is hand-authored in a feature flag and targeted by whoever wrote it. A product push+ * is chosen by the growth scheduler from an organization's `ProductPushCampaign` queue. Two cards+ * shared one event name once before, which made their impressions indistinguishable, so every+ * ad-slot event states its card outright.+ */+// pinned: analytics property values — renaming breaks dashboards+export const NAV_PANEL_CARD_TYPE = {+ BROADCAST: 'broadcast',+ PRODUCT_PUSH: 'product_push',+} as const++export interface BroadcastPayload {+ /** Slug identifying this broadcast, e.g. 'managed-warehouse-beta'. Keys dismissal state. */+ broadcast: stringtext: stringemoji: stringemojiLabel: stringtitle: string+ /**+ * ProductKey the broadcast advertises, e.g. 'session_replay'. Optional, because a broadcast+ * need not be about a product at all (a legal notice, say). Set it whenever the broadcast does+ * promote one, so its impressions can be compared against the product push for that product.+ */+ productKey?: string}-export function isCampaignPayload(value: unknown): value is CampaignPayload {+export function isBroadcastPayload(value: unknown): value is BroadcastPayload {return (typeof value === 'object' &&value !== null &&- typeof (value as CampaignPayload).campaign === 'string' &&- typeof (value as CampaignPayload).text === 'string' &&- typeof (value as CampaignPayload).emoji === 'string' &&- typeof (value as CampaignPayload).emojiLabel === 'string' &&- typeof (value as CampaignPayload).title === 'string'+ typeof (value as BroadcastPayload).broadcast === 'string' &&+ typeof (value as BroadcastPayload).text === 'string' &&+ typeof (value as BroadcastPayload).emoji === 'string' &&+ typeof (value as BroadcastPayload).emojiLabel === 'string' &&+ typeof (value as BroadcastPayload).title === 'string' &&+ ['undefined', 'string'].includes(typeof (value as BroadcastPayload).productKey))}diff --git a/frontend/src/lib/components/NavPanelAdvertisement/navPanelProductPushAdLogic.ts b/frontend/src/lib/components/NavPanelAdvertisement/navPanelProductPushAdLogic.tsindex 7bba0f2b2923..d96867d76caa 100644--- a/frontend/src/lib/components/NavPanelAdvertisement/navPanelProductPushAdLogic.ts+++ b/frontend/src/lib/components/NavPanelAdvertisement/navPanelProductPushAdLogic.ts@@ -10,7 +10,7 @@ import { FileSystemImport, ProductIntentContext, ProductKey } from '~/queries/scimport type { ProductPushCampaignApi } from 'products/growth/frontend/generated/api.schemas'import type { FeatureFlagsSet } from '../../logic/featureFlagLogic'-import type { ProductPushDisplay } from './navPanelAdShared'+import { NAV_PANEL_CARD_TYPE, type ProductPushDisplay } from './navPanelAdShared'import { navPanelAdvertisementLogic } from './NavPanelAdvertisementLogic'import { getProductPushDisplay } from './navPanelProductPushDisplay'@@ -71,7 +71,7 @@ export const navPanelProductPushAdLogic = kea<navPanelProductPushAdLogicType>([values: [featureFlagLogic,['featureFlags'],- navPanelAdvertisementLogic({ campaign: dismissKey(props.campaign) }),+ navPanelAdvertisementLogic({ dismissKey: dismissKey(props.campaign) }),['hidden'],],})),@@ -104,33 +104,31 @@ export const navPanelProductPushAdLogic = kea<navPanelProductPushAdLogicType>([!hidden && !!productInfo && !flagGated,],}),- listeners(({ props }) => ({- reportAdShown: () => {- posthog.capture('nav panel product push shown', {- campaign_id: props.campaign.id,- product_key: props.campaign.product_key,- })- },- reportAdClicked: () => {- posthog.capture('nav panel product push clicked', {- campaign_id: props.campaign.id,- product_key: props.campaign.product_key,- })- if (Object.values(ProductKey).includes(props.campaign.product_key as ProductKey)) {- addProductIntent({- product_type: props.campaign.product_key as ProductKey,- intent_context: ProductIntentContext.NAV_PANEL_ADVERTISEMENT_CLICKED,- metadata: { campaign_id: props.campaign.id },- })- }- },- reportAdDismissed: () => {- posthog.capture('nav panel product push dismissed', {- campaign_id: props.campaign.id,- product_key: props.campaign.product_key,- })- },- })),+ listeners(({ props }) => {+ const eventProperties = {+ campaign_id: props.campaign.id,+ product_key: props.campaign.product_key,+ card_type: NAV_PANEL_CARD_TYPE.PRODUCT_PUSH,+ }+ return {+ reportAdShown: () => {+ posthog.capture('nav panel product push shown', eventProperties)+ },+ reportAdClicked: () => {+ posthog.capture('nav panel product push clicked', eventProperties)+ if (Object.values(ProductKey).includes(props.campaign.product_key as ProductKey)) {+ addProductIntent({+ product_type: props.campaign.product_key as ProductKey,+ intent_context: ProductIntentContext.NAV_PANEL_ADVERTISEMENT_CLICKED,+ metadata: { campaign_id: props.campaign.id },+ })+ }+ },+ reportAdDismissed: () => {+ posthog.capture('nav panel product push dismissed', eventProperties)+ },+ }+ }),afterMount(({ actions, values }) => {if (values.shouldRender) {actions.reportAdShown()diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex 9c40d6c292f3..d8d51064b145 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -167,7 +167,7 @@ export const FEATURE_FLAGS = {BILLING_FORECASTING_ISSUES: 'billing-forecasting-issues', // owner: #team-billing, see `Billing.tsx`, used to raise a warning when billing is having problemsCOMING_SOON_WAITLIST_SURVEYS: 'coming-soon-waitlist-surveys', // owner: #team-growth, see `FeaturePreviews.tsx`, swaps concept-stage one-click for an email waitlist surveyHOG: 'hog', // owner: #team-data-tools, see `DebugScene.tsx` and also insights- NAV_PANEL_CAMPAIGN: 'nav-panel-campaign', // owner: #team-growth, sidebar promotional campaign, payload-driven. See NavPanelAdvertisement.tsx+ NAV_PANEL_BROADCAST: 'nav-panel-broadcast', // owner: #team-growth, hand-authored sidebar broadcast, payload-driven. See NavPanelAdvertisement.tsxQUERY_TIMINGS: 'query-timings', // owner: #team-analytics-platform, usage: see `dataTableLogic.ts`REDIRECT_SIGNUPS_TO_INSTANCE: 'redirect-signups-to-instance', // owner: @raquelmsmith, see `signupLogic.ts`SESSION_RESET_ON_LOAD: 'session-reset-on-load', // owner: @benjackwhite, usage: see `loadPosthogJS.tsx`