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(aeo): rename to ai visibility, move bots in, edit prompts in the ui (#130310)

Lucas Ricoyfcbd7cb215e2
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 73a89b23a7d7..f2169e348ce5 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -8283,37 +8283,41 @@ snapshots:
products-web-analytics-content-autopilot-validation-summary--ready-to-download--light:
hash: v1.k794b7964.f639222c8527f580b0a7d50335747380610569aefbac7407470e6ad296ba8853.zIXXIN4nBZV1mazHQrhFcswCdHx7awK23LO95NJ5uoc
products-web-analytics-content-autopilot-workspace--active-run--dark:
- hash: v1.k794b7964.8c2ed1294b11ca61e7ec5617cac82665c0a4d7332cd0d054154e0218c3c34b1d.O3WCYleeseYtm_Fw86iV9ySVBS3WXsL84Ym0-VEdNk0
+ hash: v1.k794b7964.5908ddc7807141c6b0fb0130e1cf42c2e87a9c5106e10a9d8d7d8683ce72c3f4.FTGIqUqA8c1KyZUi5xhKB_75seFhsUZC23qP18ap2x8
products-web-analytics-content-autopilot-workspace--active-run--light:
- hash: v1.k794b7964.6b7630980026305ba3812794c20848450305c77045037416b68b3e5c96b0266d.MFNbC3he9BPdOvnZM-eZMgu76EszZI10o9aBBGvKzfQ
+ hash: v1.k794b7964.c5b5aedc77d81c20930304ea761d761d69ace1ca7492760dedb035ce1bf95044.MhhpbXTXq1lj2t9uCzgYfVGkq7o6dhab4BriRmM01ro
products-web-analytics-content-autopilot-workspace--drafts-tab--dark:
hash: v1.k794b7964.637309bee3b445b811c08125b51c97c7405e998cef81982ab462a725251d9023.YjxtQHICh7pmzgtnLGi3ijA5kT3YtDuVR0fqCebxsRs
products-web-analytics-content-autopilot-workspace--drafts-tab--light:
hash: v1.k794b7964.68ef987ab841b7e5c388e882cbac22abafa8b029dd6ca7a6ed6f414e942259ac.FRDpQmpmPl51OBC3tAVrA1u3TWepGDCtKf9u5OEbERw
products-web-analytics-content-autopilot-workspace--failed-run--dark:
- hash: v1.k794b7964.c48edafc8558bc87f734cf385d527caaec50e6a9821a417c27ca244bcc4d88fe.pj4tRZDDFnab-PcNz0bNz65-kKNsIsIKSjL9M1Be4uE
+ hash: v1.k794b7964.2f8bf6f335e80e9d2622b7528f66ef1bcffb82a7eba1ac088709d5bb4001c72f.k-ri9ikV9pv-8Jn6Kgg6TTZdkm3QJH40CYEeeO7V8E8
products-web-analytics-content-autopilot-workspace--failed-run--light:
- hash: v1.k794b7964.7761dbde30e29ff2df4e8f2b769f47d07e1bc4bef49f8f02496e02cd92c8bf7b.nVtN7AZtGaCMqtG3f4GZtKVxN5zATkeu-9jPNIodxnI
+ hash: v1.k794b7964.6aaac8bb06bdf973bf3692f0af685e46a4e5ec0c9390c0e636f99c0f0886381d.GfVHUxSC1EXT-0EEbSfaFTcu87AtZ3Y9cFEOX7SsUW4
products-web-analytics-content-autopilot-workspace--multiple-sites--dark:
- hash: v1.k794b7964.b59bcd4873161e4d1a649a7acf03a84e86f1e4bd063a0418833288e4b4995422.1P0EVXKwtUq4LrVS9jlKO_tbPn6kLp8nmpiAyVZ8GG0
+ hash: v1.k794b7964.be62419c57e5aa130dd44ed0678d81f114db14656a6d97ce2fde6f8497a17c89.3xd9zz_B_JIMuhKbf84MVX3B7IqLZEX5AHJTeD_-xGI
products-web-analytics-content-autopilot-workspace--multiple-sites--light:
- hash: v1.k794b7964.21a7db13b993390e317a731761f511032ca5a9bc9cce892a25e7e971dc4132c9.n4GVrNk_EbdIHKcdoedPUNp__WazceU2Bz3hX_cdKLo
+ hash: v1.k794b7964.6bd356cad74c9da5e5c443b0bcf3397907a635f1f84e2ddf26fbcc76b7f41fb3.wGhp5gUQ9bXd7OGobLDw27kj4X3vn3EJAOt8qT9cKaQ
products-web-analytics-content-autopilot-workspace--onboarding--dark:
- hash: v1.k794b7964.08bf9aece2a7e9651f0969618c95caef4b09a9ee202bc5362c705253e1fd2fb4.RreWWxQzJ1MGNJjBiE-TAYy-zLAaHhtIdwDEDcdTS6M
+ hash: v1.k794b7964.6e349de380f8e8ba533cbef78b905795dd181758f4eed0cde1afa5b1caba2a21.XhBb13p6fdAgnPtvmePj1gcLNdKOGFuMpOFXzQxIslQ
products-web-analytics-content-autopilot-workspace--onboarding--light:
- hash: v1.k794b7964.c8a74b09a875fc32f80049b21eeffe1020b067c73fcfb879e5941dfa148d1ff9.yO5nGkekmtOiwH-z82KWOuIO6pq6mzFlOiboATKIkmw
+ hash: v1.k794b7964.43db8fae97d0c1d904bbc77258a41cbf9ce99992a214721db5869aca949828bd.2dCjwtWR3d2g3FGZx9hQhvz4NCBI2AmaSEAUEJHAj-I
+ products-web-analytics-content-autopilot-workspace--prompts-tab--dark:
+ hash: v1.k794b7964.909e5f4181aa2889553d2ea8cce00b04a8c17c49319d2e9efd9bc2351cdd0990.cw9K4gnJp37GgFGnYzcm3vqcVCjgm-i6s_gCG8_sbRQ
+ products-web-analytics-content-autopilot-workspace--prompts-tab--light:
+ hash: v1.k794b7964.2452cd81a3dca6efde3a7b75a11bfe8ac27e8f082f477191d7286b7c79c2b6e9.5uu6tAr2c2x0mnee3lXuNF6k5EC08hoRcydQDPHZje8
products-web-analytics-content-autopilot-workspace--proposal-preview--dark:
- hash: v1.k794b7964.3d45a7c7f322493920db20435d2182baa25f86af1a77e1cd1db94bcb1598015f.f-lDV9cFdR_QyAhO0XPEnKCvVu8p5unPUAEIznrI83k
+ hash: v1.k794b7964.3c03dc669ecd9ed2784e3cfd07da89fe99930de0dbead14eb969c3c0bfd7f7e4.4Lo8dPZZhSvHN4znzANzryiq8f-jEw18Vs6hUFgzMak
products-web-analytics-content-autopilot-workspace--proposal-preview--light:
- hash: v1.k794b7964.b8cfc1f9d3571584dcec5d27f3f544f04e2401472bd0cabccf5d76fdf4bf3472.QDh7oB5_GxqDPEuzCx7rYUiPN-dhfleeGZq_EtWk4mo
+ hash: v1.k794b7964.eb185ee8ac91098757278b83662d24959af64d7b53749f14aa98786425217582.dnOuwMmUr4yh5wdJTsFkYGKjFeGk_TIejP76kMc4Sow
products-web-analytics-content-autopilot-workspace--proposal-review--dark:
- hash: v1.k794b7964.3561e1adb9a9a5a26b95cdef970d0f76760cf1137786ca9b17940f80eef7e949.kseVCD0bpaF4XXkL6cPG9bnDkNS8pwDRSg9YC7n2FvU
+ hash: v1.k794b7964.3197db8384fed4967f493ba1ef05d021b87f3d75619ce095b78f32c2364a3806.83qwMlAvWkwjJgHgcEM4zwlhjPuyClQbo8YNPfhfFV4
products-web-analytics-content-autopilot-workspace--proposal-review--light:
- hash: v1.k794b7964.2938125cbd36f0d51e7a4e7b950075b59aa92b0f97e43e63306203b8de2191d0.NCk1bEMPM1vhBXP28nupt9KUqiS0quEHSS_g9r2tVP0
+ hash: v1.k794b7964.69504b080159049916f1a6e1728bee61b7f6cf62d5fb89a24d7ee2c2e1d8a6e9.QlHqBG1vaeRQa5YLz0a8fK1utTy_NGUtCWOyhej0flg
products-web-analytics-content-autopilot-workspace--ready-for-review--dark:
- hash: v1.k794b7964.9d67b5b685b1d4ced1845a09df5b3a89e17f4ae80f91971456cd174467e6aa9c.GQiQePjuNPhJQ8jjasQfa4zEZYuh0a2LAdnnJKTZsnw
+ hash: v1.k794b7964.4b79b307f132212f6607a1345ee71937dbd8ba4834eaf78e0c48281ecc2b820d.5zKWH-jRsTj0eNTd88UBcbfEmSh_R6LplXdHt-oMbsw
products-web-analytics-content-autopilot-workspace--ready-for-review--light:
- hash: v1.k794b7964.92a6d99472801cbf2964b844296986c59ab8e714169137d9c8840a779e519e9f.R7JiT8G2yDulVi35X7PA0UEk5hkE9cfJdf1P_f7RnqI
+ hash: v1.k794b7964.c9f7dc3bf24aaa4be647c0ba1005a030634d2677f48e4586834a30d04d93714c.JIWRlp-5KHvCbgfxARrE4e1DVuz_CH1wXP0nqDavqmw
products-web-analytics-content-autopilot-workspace--site-settings--dark:
hash: v1.k794b7964.ef6a9704812bc76a12ca6b481ecef3e6b7b3d39e1d209acb6942cb02307ea0a3.dWi69rA8aBffIyTlnxQEkEsu0r1orX8DYTR62VXkTbg
products-web-analytics-content-autopilot-workspace--site-settings--light:
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 0bf11a9952cc..a175740eabf8 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -583,8 +583,8 @@ export const FEATURE_FLAGS = {
WAREHOUSE_SUGGESTIONS: 'warehouse-suggestions', // owner: #team-data-modeling
WEB_ANALYTICS_ACHIEVEMENTS: 'web-analytics-achievements', // owner: @jordanm-posthog #team-web-analytics
WEB_ANALYTICS_AGENT_ANALYTICS: 'web-analytics-agent-analytics', // owner: @jordanm-posthog #team-web-analytics
- WEB_ANALYTICS_BOT_ANALYSIS: 'web-analytics-bot-analysis', // owner: @lricoy #team-web-analytics
- WEB_ANALYTICS_CONTENT_AUTOPILOT: 'web-analytics-content-autopilot', // owner: @jordanm-posthog #team-web-analytics
+ WEB_ANALYTICS_BOT_ANALYSIS: 'web-analytics-bot-analysis', // owner: @lricoy #team-web-analytics, gates the bot tiles on the Live tab; the Bots tab uses WEB_ANALYTICS_CONTENT_AUTOPILOT
+ WEB_ANALYTICS_CONTENT_AUTOPILOT: 'web-analytics-content-autopilot', // owner: @jordanm-posthog #team-web-analytics, gates the AI visibility page (prompts, bots, content autopilot)
WEB_ANALYTICS_CONVERSION_GOAL_PREAGG: 'web-analytics-conversion-goal-preagg', // owner: @lricoy #team-web-analytics
WEB_ANALYTICS_DRAG_TO_ZOOM: 'web-analytics-drag-to-zoom', // owner: @jordanm-posthog #team-web-analytics
WEB_ANALYTICS_EMPTY_ONBOARDING: 'web-analytics-empty-onboarding', // owner: @jordanm-posthog #team-web-analytics
diff --git a/frontend/src/products.tsx b/frontend/src/products.tsx
index 7cabb6787c4f..5270cab0dbc0 100644
--- a/frontend/src/products.tsx
+++ b/frontend/src/products.tsx
@@ -3459,7 +3459,16 @@ export const getTreeItemsProducts = (): FileSystemImport[] => [
{ name: 'Page reports', href: urls.webAnalyticsPageReports() },
{ name: 'Live', href: urls.webAnalyticsLive() },
{ name: 'Installation health', href: urls.webAnalyticsHealth() },
- { name: 'Bots', href: urls.webAnalyticsBotAnalytics(), flag: FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS },
+ {
+ name: 'AI visibility',
+ href: urls.webAnalyticsContentAutopilot(),
+ flag: FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT,
+ },
+ {
+ name: 'Bots',
+ href: urls.webAnalyticsBotAnalytics(),
+ flag: FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT,
+ },
{
name: 'Search & AI',
href: urls.webAnalyticsPagePerformance(),
diff --git a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.test.ts b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.test.ts
index 6d6340c109b5..dba087ba9638 100644
--- a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.test.ts
+++ b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.test.ts
@@ -9,6 +9,7 @@ import api from 'lib/api'
import { ApiError } from 'lib/api-error'
import { FEATURE_FLAGS } from 'lib/constants'
import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
+import { ProductTab } from 'scenes/web-analytics/common'
import { webAnalyticsLogic } from 'scenes/web-analytics/webAnalyticsLogic'
import { HogQLQuery, TrendsQuery } from '~/queries/schema/schema-general'
@@ -289,6 +290,27 @@ describe('liveWebAnalyticsMetricsLogic', () => {
await expectLogic(logic).toDispatchActions(['scheduleReload', 'loadInitialData'])
})
+ it.each([
+ [
+ 'the Bots tab with only the AI visibility flag',
+ ProductTab.BOT_ANALYTICS,
+ FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT,
+ true,
+ ],
+ [
+ 'the Live tab with only the AI visibility flag',
+ ProductTab.LIVE,
+ FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT,
+ false,
+ ],
+ ['the Live tab with the old bot flag', ProductTab.LIVE, FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS, true],
+ ])('loads bot data on %s', (_name, productTab, flag, expected) => {
+ featureFlagLogic.actions.setFeatureFlags([flag], { [flag]: true })
+ webAnalyticsLogic.actions.setProductTab(productTab)
+
+ expect(logic.values.shouldLoadBots).toBe(expected)
+ })
+
it('does not run the expensive bot query while bot analysis is disabled', async () => {
await expectLogic(logic).toDispatchActions(['setInitialData'])
diff --git a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx
index f34d8edc17c9..5037dd3ea98f 100644
--- a/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx
+++ b/frontend/src/scenes/web-analytics/LiveMetricsDashboard/liveWebAnalyticsMetricsLogic.tsx
@@ -19,7 +19,7 @@ import { isAbortedRequest } from 'lib/utils/requests'
import { hashCodeForString } from 'lib/utils/strings'
import { deduplicateEvents } from 'scenes/activity/live/deduplicateEvents'
import { teamLogic } from 'scenes/teamLogic'
-import { ProductTab, WEB_ANALYTICS_DEFAULT_QUERY_TAGS } from 'scenes/web-analytics/common'
+import { ProductTab, WEB_ANALYTICS_DEFAULT_QUERY_TAGS, isContentAutopilotEnabled } from 'scenes/web-analytics/common'
import { isLiveStreamFilter, webAnalyticsFilterLogic } from 'scenes/web-analytics/webAnalyticsFilterLogic'
import { webAnalyticsLogic } from 'scenes/web-analytics/webAnalyticsLogic'
@@ -275,7 +275,7 @@ export interface liveWebAnalyticsMetricsLogicMeta {
hasActiveFilters: (liveFilters: WebAnalyticsPropertyFilter[], shouldFilterTestAccounts: boolean) => boolean
hasBotQueryError: (botQueryStatus: BotQueryStatus) => boolean
isBotLoading: (botQueryStatus: BotQueryStatus) => boolean
- shouldLoadBots: (featureFlags: FeatureFlagsSet) => boolean
+ shouldLoadBots: (featureFlags: FeatureFlagsSet, productTab: ProductTab) => boolean
}
}
@@ -670,8 +670,12 @@ export const liveWebAnalyticsMetricsLogic = kea<liveWebAnalyticsMetricsLogicType
(botQueryStatus: BotQueryStatus): boolean => botQueryStatus === 'loading',
],
shouldLoadBots: [
- (s) => [s.featureFlags],
- (featureFlags: FeatureFlagsSet): boolean => !!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS],
+ (s) => [s.featureFlags, s.productTab],
+ (featureFlags: FeatureFlagsSet, productTab: ProductTab): boolean =>
+ // The Bots tab inside AI visibility has its own flag; the Live tab's bot tiles keep the old one.
+ productTab === ProductTab.BOT_ANALYTICS
+ ? isContentAutopilotEnabled(featureFlags)
+ : !!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS],
],
}),
listeners(({ actions, values, cache }) => ({
diff --git a/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx b/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx
index ae65ff08f125..fe30d13c0ccd 100644
--- a/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx
+++ b/frontend/src/scenes/web-analytics/WebAnalyticsDashboard.tsx
@@ -666,13 +666,12 @@ const Filters = ({ tabs }: { tabs: JSX.Element }): JSX.Element | null => {
case ProductTab.HEALTH:
case ProductTab.LIVE:
return null
- case ProductTab.BOT_ANALYTICS:
- return <BotAnalyticsFilters tabs={tabs} />
case ProductTab.PAGE_PERFORMANCE:
return <PagePerformanceFilters tabs={tabs} />
case ProductTab.AGENTS:
return <AgentAnalyticsFilters tabs={tabs} />
case ProductTab.CONTENT_AUTOPILOT:
+ case ProductTab.BOT_ANALYTICS:
return null
default:
return <WebAnalyticsFilters tabs={tabs} />
@@ -700,10 +699,6 @@ const MainContent = (): JSX.Element => {
)
}
- if (productTab === ProductTab.BOT_ANALYTICS) {
- return <BotAnalyticsTiles />
- }
-
if (productTab === ProductTab.PAGE_PERFORMANCE) {
return <PagePerformance />
}
@@ -712,13 +707,34 @@ const MainContent = (): JSX.Element => {
return <AgentAnalytics />
}
- if (productTab === ProductTab.CONTENT_AUTOPILOT) {
- return <ContentAutopilot />
+ if (productTab === ProductTab.CONTENT_AUTOPILOT || productTab === ProductTab.BOT_ANALYTICS) {
+ return <AiVisibility />
}
return <Tiles />
}
+const AiVisibility = (): JSX.Element => {
+ const { productTab } = useValues(webAnalyticsLogic)
+ const { setProductTab } = useActions(webAnalyticsLogic)
+
+ return (
+ <ContentAutopilot
+ bots={{
+ active: productTab === ProductTab.BOT_ANALYTICS,
+ open: () => setProductTab(ProductTab.BOT_ANALYTICS),
+ close: () => setProductTab(ProductTab.CONTENT_AUTOPILOT),
+ content: (
+ <div className="flex flex-col gap-2">
+ <BotAnalyticsFilters tabs={<></>} />
+ <BotAnalyticsTiles />
+ </div>
+ ),
+ }}
+ />
+ )
+}
+
const BotAnalyticsTiles = (): JSX.Element => {
// Drives bot tab off its own logic so bot filters don't pollute the regular Analytics tab.
useMountedLogic(botAnalyticsLogic)
@@ -772,29 +788,6 @@ const liveTab = (): { key: ProductTab; label: string | JSX.Element; link: string
]
}
-const botAnalyticsTab = (
- featureFlags: FeatureFlagsSet
-): { key: ProductTab; label: string | JSX.Element; link: string }[] => {
- if (!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]) {
- return []
- }
-
- return [
- {
- key: ProductTab.BOT_ANALYTICS,
- label: (
- <div className="flex items-center gap-1">
- Bots
- <LemonTag type="completion" className="uppercase">
- Alpha
- </LemonTag>
- </div>
- ),
- link: urls.webAnalyticsBotAnalytics(),
- },
- ]
-}
-
const pagePerformanceTab = (
featureFlags: FeatureFlagsSet
): { key: ProductTab; label: string | JSX.Element; link: string }[] => {
@@ -851,7 +844,7 @@ const contentAutopilotTab = (
key: ProductTab.CONTENT_AUTOPILOT,
label: (
<div className="flex items-center gap-1">
- Content autopilot
+ AI visibility
<LemonTag type="completion" className="uppercase">
Alpha
</LemonTag>
@@ -970,7 +963,8 @@ const WebAnalyticsTabs = (): JSX.Element => {
return (
<LemonTabs<ProductTab>
- activeKey={productTab}
+ // Bots lives inside AI visibility, so its route keeps that tab active.
+ activeKey={productTab === ProductTab.BOT_ANALYTICS ? ProductTab.CONTENT_AUTOPILOT : productTab}
onChange={setProductTab}
tabs={[
{ key: ProductTab.ANALYTICS, label: 'Web analytics', link: '/web' },
@@ -985,7 +979,6 @@ const WebAnalyticsTabs = (): JSX.Element => {
link: '/web/page-reports',
},
...liveTab(),
- ...botAnalyticsTab(featureFlags),
...pagePerformanceTab(featureFlags),
...agentAnalyticsTab(featureFlags),
...contentAutopilotTab(featureFlags),
diff --git a/frontend/src/scenes/web-analytics/common.ts b/frontend/src/scenes/web-analytics/common.ts
index 81907b1d79a2..19f34d0853de 100644
--- a/frontend/src/scenes/web-analytics/common.ts
+++ b/frontend/src/scenes/web-analytics/common.ts
@@ -126,8 +126,8 @@ export enum ProductTab {
CONTENT_AUTOPILOT = 'content-autopilot',
}
+// One flag gates the whole AI visibility page: prompt tracking, bots and content autopilot.
export const isContentAutopilotEnabled = (featureFlags: FeatureFlagsSet): boolean =>
- !!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE] &&
!!featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT]
export type DeviceType = 'Desktop' | 'Mobile'
diff --git a/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts b/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts
index 4b899f7b83be..6e746f3fcb03 100644
--- a/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts
+++ b/frontend/src/scenes/web-analytics/webAnalyticsLogic.test.ts
@@ -549,28 +549,28 @@ describe('webAnalyticsLogic URL restoration', () => {
expect(pushSpy).toHaveBeenCalledTimes(1)
})
- it('redirects off the bots tab when the bot-analysis flag is disabled', async () => {
- router.actions.push('/web/bots')
- await expectLogic(logic).toFinishAllListeners()
-
- // The pathname is project-prefixed in tests (e.g. /project/997/web); assert we left the bots route.
- expect(router.values.location.pathname.endsWith('/web')).toBe(true)
- })
-
- it('redirects off content autopilot when either alpha flag is disabled', async () => {
- featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE], {
- [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE]: true,
- })
+ it.each(['/web/bots', '/web/content-autopilot'])(
+ 'redirects off %s when the AI visibility flag is disabled',
+ async (path) => {
+ featureFlagLogic.actions.setFeatureFlags(
+ [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE, FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS],
+ {
+ [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE]: true,
+ [FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]: true,
+ }
+ )
- router.actions.push('/web/content-autopilot')
- await expectLogic(logic).toFinishAllListeners()
+ router.actions.push(path)
+ await expectLogic(logic).toFinishAllListeners()
- expect(router.values.location.pathname.endsWith('/web')).toBe(true)
- })
+ // The pathname is project-prefixed in tests (e.g. /project/997/web); assert we left the route.
+ expect(router.values.location.pathname.endsWith('/web')).toBe(true)
+ }
+ )
it('defaults the bots tab to the last day when the URL carries no date', async () => {
- featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS], {
- [FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]: true,
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT], {
+ [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT]: true,
})
router.actions.push('/web/bots')
@@ -595,13 +595,9 @@ describe('webAnalyticsLogic URL restoration', () => {
})
it('opens content autopilot without carrying dashboard filters', async () => {
- featureFlagLogic.actions.setFeatureFlags(
- [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE, FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
- {
- [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE]: true,
- [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT]: true,
- }
- )
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT], {
+ [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT]: true,
+ })
logic.actions.setWebAnalyticsFilters([
{
type: PropertyFilterType.Session,
@@ -666,8 +662,8 @@ describe('webAnalyticsLogic URL restoration', () => {
})
it("scrubs another tab's filters param when switching to the bots tab", async () => {
- featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS], {
- [FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]: true,
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT], {
+ [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT]: true,
})
logic.actions.setWebAnalyticsFilters([FILTER_A])
await expectLogic(logic).toFinishAllListeners()
@@ -682,8 +678,8 @@ describe('webAnalyticsLogic URL restoration', () => {
})
it('adopts a deep-linked filters param when the bots tab mounts', async () => {
- featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS], {
- [FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]: true,
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT], {
+ [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT]: true,
})
router.actions.push('/web/bots', { filters: [FILTER_A] })
await expectLogic(logic).toFinishAllListeners()
@@ -700,8 +696,8 @@ describe('webAnalyticsLogic URL restoration', () => {
})
it('writes persisted bot filters into the URL when the bots tab mounts', async () => {
- featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS], {
- [FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]: true,
+ featureFlagLogic.actions.setFeatureFlags([FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT], {
+ [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT]: true,
})
router.actions.push('/web/bots')
await expectLogic(logic).toFinishAllListeners()
diff --git a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
index 339d7e01a74f..c89de81f1a1c 100644
--- a/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
+++ b/frontend/src/scenes/web-analytics/webAnalyticsLogic.tsx
@@ -3511,15 +3511,6 @@ export const webAnalyticsLogic: LogicWrapper<webAnalyticsLogicType> = kea<webAna
return
}
- // Redirect away from bot analytics tab if the feature flag is disabled
- if (
- productTab === ProductTab.BOT_ANALYTICS &&
- !values.featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS]
- ) {
- router.actions.replace(urls.webAnalytics())
- return
- }
-
if (
productTab === ProductTab.PAGE_PERFORMANCE &&
!values.featureFlags[FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE]
@@ -3533,7 +3524,10 @@ export const webAnalyticsLogic: LogicWrapper<webAnalyticsLogicType> = kea<webAna
return
}
- if (productTab === ProductTab.CONTENT_AUTOPILOT && !isContentAutopilotEnabled(values.featureFlags)) {
+ if (
+ [ProductTab.CONTENT_AUTOPILOT, ProductTab.BOT_ANALYTICS].includes(productTab) &&
+ !isContentAutopilotEnabled(values.featureFlags)
+ ) {
router.actions.replace(urls.webAnalytics())
return
}
diff --git a/products/aeo/README.md b/products/aeo/README.md
index dda206cd833e..b6ddb2c61e49 100644
--- a/products/aeo/README.md
+++ b/products/aeo/README.md
@@ -39,6 +39,11 @@ python manage.py run_aeo_citation_checks --team-id <id> --limit 3 --dry-run
python manage.py run_aeo_citation_checks --team-id <id>
```
+### Add and edit in the app
+
+The AI visibility page in Web analytics (`/web/content-autopilot`) has an Overview tab for the prompt-set summary and a Prompts tab to add prompts (one per line, with an optional topic), edit a prompt's text or topic, turn prompts on or off, and archive them.
+Its Opportunities and Drafts tabs are content autopilot, which drafts pages for prompts where the engines did not cite the site.
+
### Import over the API
`/api/projects/<id>/aeo_prompts/` lists the prompt set (filter with `?topic=` and `?active=true|false`; archived prompts are left out unless `?include_archived=true`; each prompt carries `latest_checks`, its newest check per engine, and its `current_version` and `version_count`), lists topics with `GET topics/`, sums up the whole set with `GET overview/?days=30` (prompts tracked, checks, citation and mention rates against the window before, the same per engine and per topic, and the domains the engines cite most), returns one prompt's check history with `GET <prompt_id>/checks/` (newest first, filter with `?engine=` and `?version=`) and its per-engine totals and 30-day daily counts with `GET <prompt_id>/stats/`, lists its versions with `GET <prompt_id>/versions/` (newest first), edits a prompt with `PATCH <prompt_id>/`, archives one with `DELETE <prompt_id>/`, and imports prompts with `POST bulk_import/`. It is gated by the `aeo-citation-tracking` flag and accepts personal API keys with `web_analytics:write`:
@@ -50,7 +55,7 @@ curl -X POST "$HOST/api/projects/<id>/aeo_prompts/bulk_import/" \
```
- A request takes up to 2,000 prompts. Send larger sets in batches of a few hundred.
-- A re-import matches prompts by the normalized text of their current version. It updates the topic and the evidence, and keeps each prompt's on/off state. A new text creates a prompt with version 1.
+- A re-import matches prompts by the normalized text of their current version. It updates the topic, merges the new evidence into the stored evidence (an omitted `external_visibility` keeps its value), and keeps each prompt's on/off state. A new text creates a prompt with version 1.
- A re-import of an archived prompt's text leaves it archived and counts it as `skipped`.
- The same operations are PostHog MCP tools (`products/aeo/mcp/tools.yaml`), gated by the same flag: `aeo-prompts-list`, `aeo-prompts-get`, `aeo-prompts-update`, `aeo-prompts-archive`, `aeo-prompts-versions-list`, `aeo-prompts-import`, `aeo-prompts-topics-list`, `aeo-prompts-checks-list`, `aeo-prompts-stats-get` and `aeo-prompts-overview-get`.
- `external_visibility` (0-100) is the share of answers that mention the brand, as reported by the tool the set came from. It is kept in the prompt's evidence to benchmark against our own rates.
diff --git a/products/aeo/backend/facade/api.py b/products/aeo/backend/facade/api.py
index 41d497174dbb..3dac55a46155 100644
--- a/products/aeo/backend/facade/api.py
+++ b/products/aeo/backend/facade/api.py
@@ -17,7 +17,7 @@ from zoneinfo import ZoneInfo
from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import IntegrityError, connection, transaction
-from django.db.models import Aggregate, Count, Max, Min, Q, QuerySet
+from django.db.models import Aggregate, Count, Exists, Max, Min, OuterRef, Q, QuerySet
from django.db.models.functions import TruncDate
from django.utils import timezone
@@ -72,6 +72,9 @@ def list_citation_gaps(team_id: int, *, since: dt.datetime) -> list[CitationGap]
return gaps.list_citation_gaps(team_id, since=since)
+NEEDS_IMPROVEMENT_DAYS = 30
+
+
def list_prompts(
team_id: int,
*,
@@ -80,6 +83,7 @@ def list_prompts(
topic: str | None = None,
active: bool | None = None,
include_archived: bool = False,
+ needs_improvement: bool = False,
) -> tuple[list[Prompt], int]:
"""One page of the team's prompt set and the total count, paged in SQL.
A topic of "" selects the prompts that have no topic."""
@@ -90,6 +94,15 @@ def list_prompts(
prompts = prompts.filter(topic=topic)
if active is not None:
prompts = prompts.filter(active=active)
+ if needs_improvement:
+ # Only the current wording counts, as in citation gaps: checks before version 2 carry no version.
+ answered = AEOCitationCheck.objects.for_team(team_id).filter(
+ Q(prompt_version=OuterRef("current_version")) | Q(prompt_version__isnull=True, prompt__current_version=1),
+ prompt_id=OuterRef("pk"),
+ check_failed=False,
+ created_at__gte=timezone.now() - dt.timedelta(days=NEEDS_IMPROVEMENT_DAYS),
+ )
+ prompts = prompts.filter(Exists(answered), ~Exists(answered.filter(cited=True)))
page = list(prompts.order_by("topic", "-rank", "created_at", "id")[offset : offset + limit])
return _to_prompts(team_id, page), prompts.count()
diff --git a/products/aeo/backend/presentation/views.py b/products/aeo/backend/presentation/views.py
index 5e2087cc7af9..ec41d2a6fd40 100644
--- a/products/aeo/backend/presentation/views.py
+++ b/products/aeo/backend/presentation/views.py
@@ -18,6 +18,7 @@ from posthog.permissions import posthog_feature_flag_enabled
from products.aeo.backend.facade.api import (
MAX_CONSENSUS_DOMAINS,
MAX_OVERVIEW_DOMAINS,
+ MAX_PROMPT_LENGTH,
MAX_STATS_WORDS,
archive_prompt,
get_prompt,
@@ -143,6 +144,14 @@ class AEOPromptListQuerySerializer(serializers.Serializer):
default=False,
help_text="Also list archived prompts. Archived prompts are left out by default.",
)
+ needs_improvement = serializers.BooleanField(
+ required=False,
+ default=False,
+ help_text=(
+ "Only list prompts that the engines answered in the last 30 days without citing a target domain. "
+ "Prompts with no answered check in that window are left out."
+ ),
+ )
class AEOPromptTopicSerializer(DataclassSerializer):
@@ -449,7 +458,8 @@ class AEOPromptUpdateRequestSerializer(serializers.Serializer):
prompt = serializers.CharField(
required=False,
default=None,
- max_length=MAX_IMPORTED_PROMPT_CHARS,
+ # The engines' limit, so the generated client limit matches what update_prompt accepts.
+ max_length=MAX_PROMPT_LENGTH,
help_text=(
"New text for the prompt. A change adds the next version and makes it current; the prompt keeps its id "
"and its check history, and each check records the version that ran. A change of case or whitespace "
@@ -585,7 +595,7 @@ class AEOPromptViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
query_serializer=AEOPromptListQuerySerializer,
operation_id="aeo_prompts_list",
summary="List AEO prompts",
- description="Lists the project's AEO prompt set, ordered by topic and then rank, one page at a time. Filter by topic or by on/off state. Archived prompts are left out unless include_archived is true. Each prompt carries its latest check per answer engine.",
+ description="Lists the project's AEO prompt set, ordered by topic and then rank, one page at a time. Filter by topic, by on/off state, or to the prompts that need improvement. Archived prompts are left out unless include_archived is true. Each prompt carries its latest check per answer engine.",
responses={200: AEOPromptSerializer(many=True)},
tags=["web_analytics"],
)
@@ -598,6 +608,7 @@ class AEOPromptViewSet(TeamAndOrgViewSetMixin, viewsets.GenericViewSet):
topic=request.validated_query_data.get("topic"),
active=request.validated_query_data.get("active"),
include_archived=request.validated_query_data["include_archived"],
+ needs_improvement=request.validated_query_data["needs_improvement"],
)
paginator.set_count(count)
page = self.paginate_queryset(prompts)
diff --git a/products/aeo/backend/seeding.py b/products/aeo/backend/seeding.py
index 42a70ded3163..e343156906ae 100644
--- a/products/aeo/backend/seeding.py
+++ b/products/aeo/backend/seeding.py
@@ -105,12 +105,23 @@ def upsert_prompts(team: Team, candidates: list[PromptCandidate]) -> dict[str, i
updated_at=now,
)
with team_scope(team_id), transaction.atomic():
- existing = dict(AEOPrompt.objects.filter(prompt_hash__in=rows.keys()).values_list("prompt_hash", "archived_at"))
+ # Locked in hash order, so a concurrent import cannot overwrite evidence this one merged.
+ existing = {
+ key: (archived_at, evidence)
+ for key, archived_at, evidence in AEOPrompt.objects.filter(prompt_hash__in=rows.keys())
+ .select_for_update()
+ .order_by("prompt_hash")
+ .values_list("prompt_hash", "archived_at", "evidence")
+ }
# An archived prompt stays archived, so re-importing its text neither revives nor duplicates it.
- archived = {key for key, archived_at in existing.items() if archived_at is not None}
+ archived = {key for key, (archived_at, _) in existing.items() if archived_at is not None}
skipped += sum(1 for key in candidate_keys if key in archived)
for key in archived:
del rows[key]
+ # A re-import that leaves out a field, such as external_visibility, keeps the value already stored.
+ for key, (_, evidence) in existing.items():
+ if key in rows:
+ rows[key].evidence = (evidence or {}) | rows[key].evidence
# `active` is left out of the update, so a re-import keeps prompts someone turned off. So is `prompt`:
# it copies the current version's text, which only a version change may rewrite.
# Sorted so concurrent imports lock conflicting rows in the same order and cannot deadlock.
diff --git a/products/aeo/backend/test/test_api.py b/products/aeo/backend/test/test_api.py
index e2f185d1068f..03ec074b0c03 100644
--- a/products/aeo/backend/test/test_api.py
+++ b/products/aeo/backend/test/test_api.py
@@ -115,6 +115,13 @@ class TestAEOPromptAPI(APIBaseTest):
assert response.json() == {"created": 0, "updated": 2, "skipped": 1}
assert AEOPrompt.objects.for_team(self.team.id).get(id=replay_id).active is False
+ self.client.post(
+ f"{self.url}bulk_import/",
+ {"prompts": [{"prompt": "Best session replay tool?", "topic": "Session replay"}]},
+ format="json",
+ )
+ assert self.client.get(f"{self.url}{replay_id}/").json()["external_visibility"] == 42.5
+
flags_id = listed["Best feature flag tool?"]["id"]
self.client.delete(f"{self.url}{flags_id}/")
response = self.client.post(f"{self.url}bulk_import/", payload, format="json")
@@ -356,6 +363,32 @@ class TestAEOPromptAPI(APIBaseTest):
assert (latest["claude-web-search"]["cited"], latest["claude-web-search"]["check_failed"]) == (True, False)
assert listed["never checked?"]["latest_checks"] == []
+ def test_list_needs_improvement_keeps_answered_prompts_without_a_recent_citation(self) -> None:
+ texts = ["cited?", "never cited?", "only failed?", "cited long ago?", "never checked?"]
+ self.client.post(f"{self.url}bulk_import/", {"prompts": [{"prompt": t} for t in texts]}, format="json")
+ ids = {row["prompt"]: row["id"] for row in self.client.get(self.url).json()["results"]}
+ self._record_check(ids["cited?"], "exa-answer", minutes_ago=10, cited=False)
+ self._record_check(ids["cited?"], "claude-web-search", minutes_ago=10, cited=True)
+ self._record_check(ids["never cited?"], "exa-answer", minutes_ago=10, cited=False)
+ self._record_check(ids["only failed?"], "exa-answer", minutes_ago=10, check_failed=True)
+ self._record_check(ids["cited long ago?"], "exa-answer", minutes_ago=60 * 24 * 40, cited=True)
+ self._record_check(ids["cited long ago?"], "exa-answer", minutes_ago=10, cited=False)
+ # A citation on the old wording must not hide a current wording that no engine cites.
+ self.client.post(f"{self.url}bulk_import/", {"prompts": [{"prompt": "edited?"}]}, format="json")
+ edited_id = next(row["id"] for row in self.client.get(self.url).json()["results"] if row["prompt"] == "edited?")
+ self._record_check(edited_id, "exa-answer", minutes_ago=20, cited=True)
+ self.client.patch(f"{self.url}{edited_id}/", {"prompt": "edited again?"}, format="json")
+ self._record_check(edited_id, "exa-answer", minutes_ago=10, cited=False)
+
+ response = self.client.get(self.url, {"needs_improvement": "true"}).json()
+
+ assert sorted(row["prompt"] for row in response["results"]) == [
+ "cited long ago?",
+ "edited again?",
+ "never cited?",
+ ]
+ assert response["count"] == 3
+
def test_list_query_count_does_not_grow_with_page_size(self) -> None:
prompts = [{"prompt": f"q{i}?"} for i in range(4)]
self.client.post(f"{self.url}bulk_import/", {"prompts": prompts}, format="json")
diff --git a/products/web_analytics/backend/presentation/views/content_autopilot.py b/products/web_analytics/backend/presentation/views/content_autopilot.py
index a7e37c15b939..688fa31fe83f 100644
--- a/products/web_analytics/backend/presentation/views/content_autopilot.py
+++ b/products/web_analytics/backend/presentation/views/content_autopilot.py
@@ -515,6 +515,7 @@ class ContentAutopilotOpportunitySerializer(serializers.ModelSerializer):
"profile_id",
"run_id",
"proposal_id",
+ "aeo_prompt_id",
"kind",
"title",
"score",
@@ -532,6 +533,7 @@ class ContentAutopilotOpportunitySerializer(serializers.ModelSerializer):
"profile_id": {"help_text": "Site profile this opportunity belongs to."},
"run_id": {"help_text": "Latest run that drafted this opportunity."},
"proposal_id": {"help_text": "Latest proposal drafted for this opportunity."},
+ "aeo_prompt_id": {"help_text": "Tracked AI visibility prompt this opportunity came from."},
"kind": {"help_text": "Type of visibility gap."},
"title": {"help_text": "The prompt the site isn't cited for."},
"score": {"help_text": "Priority from 0 to 1. Higher means a clearer, more consistent gap."},
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx
index a5f4bc50256e..97aab35b9ea6 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx
@@ -13,13 +13,20 @@ import type {
ContentAutopilotSiteProfileApi,
} from '../generated/api.schemas'
import { ContentAutopilot } from './ContentAutopilot'
-import { type ContentAutopilotProposalTab, contentAutopilotLogic } from './contentAutopilotLogic'
+import {
+ type ContentAutopilotProposalTab,
+ type ContentAutopilotWorkspaceTab,
+ contentAutopilotLogic,
+} from './contentAutopilotLogic'
import { ContentAutopilotSetup } from './ContentAutopilotSetup'
import {
EXAMPLE_FAILED_DRAFT_OPPORTUNITY,
EXAMPLE_FAILED_PROPOSAL_LIST,
EXAMPLE_OPPORTUNITIES,
EXAMPLE_PROFILE,
+ EXAMPLE_PROMPT_SET_OVERVIEW,
+ EXAMPLE_PROMPT_TOPICS,
+ EXAMPLE_PROMPTS,
EXAMPLE_PROPOSAL,
EXAMPLE_PROPOSAL_LIST,
EXAMPLE_RUN,
@@ -55,6 +62,12 @@ const workspaceHandlers = ({
200,
EXAMPLE_PROPOSAL,
],
+ '/api/projects/:team_id/aeo_prompts/': () => [
+ 200,
+ { count: EXAMPLE_PROMPTS.length, next: null, previous: null, results: EXAMPLE_PROMPTS },
+ ],
+ '/api/projects/:team_id/aeo_prompts/topics/': () => [200, EXAMPLE_PROMPT_TOPICS],
+ '/api/projects/:team_id/aeo_prompts/overview/': () => [200, EXAMPLE_PROMPT_SET_OVERVIEW],
'/api/projects/:team_id/web_analytics_content_autopilot_opportunities/': () => [
200,
{ count: opportunities.length, next: null, previous: null, results: opportunities },
@@ -81,7 +94,7 @@ const meta: Meta<typeof ContentAutopilot> = {
component: ContentAutopilot,
parameters: {
layout: 'fullscreen',
- featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE, FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
+ featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
// The fixtures carry fixed dates and the UI shows them relative to now, so the clock is pinned near them.
mockDate: '2026-09-30',
},
@@ -89,18 +102,22 @@ const meta: Meta<typeof ContentAutopilot> = {
export default meta
-export const Onboarding: StoryFn<typeof ContentAutopilot> = () => (
- <div className="p-6">
- <ContentAutopilot />
- </div>
-)
+const WorkspaceTabStory = ({ tab }: { tab: ContentAutopilotWorkspaceTab }): JSX.Element => {
+ const { setWorkspaceTab } = useActions(contentAutopilotLogic)
+ useEffect(() => {
+ setWorkspaceTab(tab)
+ }, [setWorkspaceTab, tab])
+ return (
+ <div className="p-6">
+ <ContentAutopilot />
+ </div>
+ )
+}
+
+export const Onboarding: StoryFn<typeof ContentAutopilot> = () => <WorkspaceTabStory tab="opportunities" />
Onboarding.decorators = [workspaceHandlers({ profiles: [] })]
-export const MultipleSites: StoryFn<typeof ContentAutopilot> = () => (
- <div className="p-6">
- <ContentAutopilot />
- </div>
-)
+export const MultipleSites: StoryFn<typeof ContentAutopilot> = () => <WorkspaceTabStory tab="opportunities" />
MultipleSites.decorators = [workspaceHandlers({ profiles: [EXAMPLE_PROFILE, EXAMPLE_SECOND_PROFILE] })]
export const SiteSettings: StoryFn<typeof ContentAutopilotSetup> = () => (
@@ -110,11 +127,7 @@ export const SiteSettings: StoryFn<typeof ContentAutopilotSetup> = () => (
)
SiteSettings.decorators = [workspaceHandlers({ profiles: [EXAMPLE_PROFILE] })]
-export const ReadyForReview: StoryFn<typeof ContentAutopilot> = () => (
- <div className="p-6">
- <ContentAutopilot />
- </div>
-)
+export const ReadyForReview: StoryFn<typeof ContentAutopilot> = () => <WorkspaceTabStory tab="opportunities" />
ReadyForReview.decorators = [
workspaceHandlers({
profiles: [EXAMPLE_PROFILE],
@@ -124,11 +137,7 @@ ReadyForReview.decorators = [
}),
]
-export const FailedRun: StoryFn<typeof ContentAutopilot> = () => (
- <div className="p-6">
- <ContentAutopilot />
- </div>
-)
+export const FailedRun: StoryFn<typeof ContentAutopilot> = () => <WorkspaceTabStory tab="opportunities" />
FailedRun.decorators = [
workspaceHandlers({
profiles: [EXAMPLE_PROFILE],
@@ -175,22 +184,7 @@ ProposalReview.decorators = [
}),
]
-const DraftsTabStory = (): JSX.Element => {
- const { profileDataLoaded } = useValues(contentAutopilotLogic)
- const { setWorkspaceTab } = useActions(contentAutopilotLogic)
- useEffect(() => {
- if (profileDataLoaded) {
- setWorkspaceTab('drafts')
- }
- }, [profileDataLoaded, setWorkspaceTab])
- return (
- <div className="p-6">
- <ContentAutopilot />
- </div>
- )
-}
-
-export const ActiveRun: StoryFn<typeof ContentAutopilot> = () => <DraftsTabStory />
+export const ActiveRun: StoryFn<typeof ContentAutopilot> = () => <WorkspaceTabStory tab="drafts" />
ActiveRun.parameters = { testOptions: { waitForLoadersToDisappear: false } }
ActiveRun.decorators = [
workspaceHandlers({
@@ -201,7 +195,7 @@ ActiveRun.decorators = [
}),
]
-export const DraftsTab: StoryFn<typeof ContentAutopilot> = () => <DraftsTabStory />
+export const DraftsTab: StoryFn<typeof ContentAutopilot> = () => <WorkspaceTabStory tab="drafts" />
DraftsTab.decorators = [
workspaceHandlers({
profiles: [EXAMPLE_PROFILE],
@@ -223,3 +217,6 @@ DraftsTab.decorators = [
export const ProposalPreview: StoryFn<typeof ContentAutopilot> = () => <ProposalStory />
ProposalPreview.decorators = ProposalReview.decorators
+
+export const PromptsTab: StoryFn<typeof ContentAutopilot> = () => <WorkspaceTabStory tab="prompts" />
+PromptsTab.decorators = [workspaceHandlers({ profiles: [EXAMPLE_PROFILE], opportunities: EXAMPLE_OPPORTUNITIES })]
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.tsx
index f54016a03acf..68f07814b348 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.tsx
@@ -1,25 +1,28 @@
import { useActions, useValues } from 'kea'
import { IconPlusSmall } from '@posthog/icons'
-import {
- LemonBanner,
- LemonButton,
- LemonCard,
- LemonCollapse,
- LemonDialog,
- LemonSelect,
- LemonSkeleton,
- LemonTabs,
-} from '@posthog/lemon-ui'
+import { LemonBanner, LemonButton, LemonDialog, LemonSelect, LemonTabs } from '@posthog/lemon-ui'
import { ContentAutopilotDrafts } from './ContentAutopilotDrafts'
-import { contentAutopilotLogic } from './contentAutopilotLogic'
+import { type ContentAutopilotWorkspaceTab, contentAutopilotLogic } from './contentAutopilotLogic'
import { ContentAutopilotOpportunities } from './ContentAutopilotOpportunities'
+import { ContentAutopilotPromptAddModal } from './ContentAutopilotPromptAddModal'
import { ContentAutopilotPrompts } from './ContentAutopilotPrompts'
+import { ContentAutopilotPromptsOverview } from './ContentAutopilotPromptsOverview'
import { ContentAutopilotProposalDetail } from './ContentAutopilotProposalDetail'
import { ContentAutopilotSetup } from './ContentAutopilotSetup'
+import { ContentAutopilotSiteGate } from './ContentAutopilotSiteGate'
-export const ContentAutopilot = (): JSX.Element => {
+export interface ContentAutopilotBotsTab {
+ active: boolean
+ open: () => void
+ close: () => void
+ content: JSX.Element
+}
+
+type AiVisibilityTab = ContentAutopilotWorkspaceTab | 'bots'
+
+export const ContentAutopilot = ({ bots }: { bots?: ContentAutopilotBotsTab }): JSX.Element => {
const {
profile,
activeRun,
@@ -35,8 +38,6 @@ export const ContentAutopilot = (): JSX.Element => {
proposalsLoading,
runMutationLoading,
workspaceError,
- workspaceErrors,
- workspaceInitialized,
profileDataLoaded,
visibleOpportunities,
} = useValues(contentAutopilotLogic)
@@ -59,19 +60,25 @@ export const ContentAutopilot = (): JSX.Element => {
secondaryButton: { children: 'Keep drafting' },
})
}
-
- if (!workspaceInitialized) {
- return <LemonSkeleton className="h-72 w-full" />
+ const selectTab = (tab: AiVisibilityTab): void => {
+ if (tab === 'bots') {
+ bots?.open()
+ return
+ }
+ if (bots?.active) {
+ bots.close()
+ }
+ setWorkspaceTab(tab)
}
return (
<div className="flex flex-col gap-4">
<div className="flex flex-wrap items-start justify-between gap-3">
<div>
- <h1 className="m-0">Content autopilot</h1>
+ <h1 className="m-0">AI visibility</h1>
<p className="m-0 mt-1 text-muted max-w-3xl">
- Find questions AI assistants answer without citing your site, and draft the pages that fix it.
- Nothing is published until you download a draft and ship it yourself.
+ Track whether AI assistants mention and cite your site when they answer the prompts you care
+ about.
</p>
</div>
{profile && !onboardingOpen ? (
@@ -94,82 +101,89 @@ export const ContentAutopilot = (): JSX.Element => {
{workspaceError ? (
<LemonBanner type="error" action={{ children: 'Try again', onClick: loadWorkspace, loading }}>
- Some content autopilot data could not be loaded. {workspaceError}
+ Some AI visibility data could not be loaded. {workspaceError}
</LemonBanner>
) : null}
- {workspaceErrors.profiles && !profile ? (
- <LemonCard hoverEffect={false} className="p-8 text-center">
- <h2>Sites could not be loaded</h2>
- <p className="text-muted">Try again before adding or changing a site.</p>
- </LemonCard>
- ) : onboardingOpen || !profile ? (
+ {profile && onboardingOpen ? (
<ContentAutopilotSetup onboarding />
) : (
<>
- {!profileDataLoaded ? (
- <LemonSkeleton className="h-72 w-full" />
- ) : (
- <>
- {latestRunErrors.length > 0 ? (
- <LemonBanner type={lastRun?.run_status === 'failed' ? 'error' : 'warning'}>
- {latestRunErrors.join(' ')}
- </LemonBanner>
- ) : null}
-
- <LemonTabs
- activeKey={workspaceTab}
- onChange={setWorkspaceTab}
- data-attr="content-autopilot-workspace-tabs"
- rightSlot={
- activeRun ? (
- <LemonButton
- type="tertiary"
- status="danger"
- size="small"
- onClick={confirmCancelRun}
- loading={runMutationLoading}
- data-attr="content-autopilot-stop-drafting"
- >
- Stop drafting
- </LemonButton>
- ) : null
- }
- tabs={[
- {
- key: 'opportunities',
- label: `Opportunities (${visibleOpportunities.length})`,
- content: <ContentAutopilotOpportunities />,
- },
- {
- key: 'drafts',
- label: readyDraftCount
- ? `Drafts (${readyDraftCount} ready to review)`
- : `Drafts (${draftRows.length})`,
- content: <ContentAutopilotDrafts />,
- },
- {
- key: 'prompts',
- label: 'Prompts',
- content: <ContentAutopilotPrompts />,
- },
- ]}
- />
- </>
- )}
+ {profile && profileDataLoaded && latestRunErrors.length > 0 ? (
+ <LemonBanner type={lastRun?.run_status === 'failed' ? 'error' : 'warning'}>
+ {latestRunErrors.join(' ')}
+ </LemonBanner>
+ ) : null}
- <LemonCollapse
- panels={[
+ <LemonTabs<AiVisibilityTab>
+ activeKey={bots?.active ? 'bots' : workspaceTab}
+ onChange={selectTab}
+ data-attr="content-autopilot-workspace-tabs"
+ rightSlot={
+ activeRun ? (
+ <LemonButton
+ type="tertiary"
+ status="danger"
+ size="small"
+ onClick={confirmCancelRun}
+ loading={runMutationLoading}
+ data-attr="content-autopilot-stop-drafting"
+ >
+ Stop drafting
+ </LemonButton>
+ ) : null
+ }
+ tabs={[
+ {
+ key: 'overview',
+ label: 'Overview',
+ content: <ContentAutopilotPromptsOverview />,
+ },
+ {
+ key: 'prompts',
+ label: 'Prompts',
+ content: <ContentAutopilotPrompts />,
+ },
+ bots ? { key: 'bots', label: 'Bots', content: bots.content } : null,
{
- key: 'settings',
- header: `Settings for ${profile.name || profile.domain}`,
- content: <ContentAutopilotSetup />,
+ key: 'opportunities',
+ label: profile ? `Opportunities (${visibleOpportunities.length})` : 'Opportunities',
+ content: (
+ <ContentAutopilotSiteGate>
+ <ContentAutopilotOpportunities />
+ </ContentAutopilotSiteGate>
+ ),
},
+ profile
+ ? {
+ key: 'drafts',
+ label: readyDraftCount
+ ? `Drafts (${readyDraftCount} ready to review)`
+ : `Drafts (${draftRows.length})`,
+ content: (
+ <ContentAutopilotSiteGate>
+ <ContentAutopilotDrafts />
+ </ContentAutopilotSiteGate>
+ ),
+ }
+ : null,
+ profile
+ ? {
+ key: 'settings',
+ label: 'Settings',
+ content: (
+ <ContentAutopilotSiteGate>
+ <ContentAutopilotSetup />
+ </ContentAutopilotSiteGate>
+ ),
+ }
+ : null,
]}
/>
</>
)}
<ContentAutopilotProposalDetail />
+ <ContentAutopilotPromptAddModal />
</div>
)
}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.stories.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.stories.tsx
index 409ba3b992ab..cb851e777d2d 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.stories.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotBriefPanel.stories.tsx
@@ -9,7 +9,7 @@ const meta: Meta<typeof ContentAutopilotBriefPanel> = {
title: 'Products/Web Analytics/Content autopilot/Brief',
component: ContentAutopilotBriefPanel,
parameters: {
- featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE, FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
+ featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
},
}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDraftButton.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDraftButton.tsx
new file mode 100644
index 000000000000..7e533c839a37
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDraftButton.tsx
@@ -0,0 +1,57 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonButton } from '@posthog/lemon-ui'
+
+import type { ContentAutopilotOpportunityApi } from 'products/web_analytics/frontend/generated/api.schemas'
+
+import { contentAutopilotLogic } from './contentAutopilotLogic'
+
+export const ContentAutopilotDraftButton = ({
+ opportunity,
+ onReview,
+}: {
+ opportunity: ContentAutopilotOpportunityApi
+ onReview?: () => void
+}): JSX.Element | null => {
+ const { rowDraftDisabledReason, runMutationLoading, draftingOpportunityIds, opportunityProposals } =
+ useValues(contentAutopilotLogic)
+ const { draftOpportunities, selectProposal } = useActions(contentAutopilotLogic)
+
+ if (opportunity.status === 'new') {
+ return (
+ <LemonButton
+ size="small"
+ type="secondary"
+ onClick={() => draftOpportunities([opportunity.id])}
+ loading={runMutationLoading && draftingOpportunityIds.includes(opportunity.id)}
+ disabledReason={rowDraftDisabledReason}
+ data-attr="content-autopilot-draft-opportunity"
+ >
+ {opportunity.recommended_type === 'page_improvement' ? 'Draft changes' : 'Draft page'}
+ </LemonButton>
+ )
+ }
+
+ const proposalId = opportunity.proposal_id
+ if (
+ proposalId &&
+ opportunity.status === 'drafted' &&
+ opportunityProposals[opportunity.id]?.lifecycle_status !== 'generating'
+ ) {
+ return (
+ <LemonButton
+ size="small"
+ type="secondary"
+ onClick={() => {
+ onReview?.()
+ selectProposal(proposalId)
+ }}
+ data-attr="content-autopilot-review-opportunity-draft"
+ >
+ Review draft
+ </LemonButton>
+ )
+ }
+
+ return null
+}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDrafts.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDrafts.tsx
index fbfd31137f48..1b69747f22cd 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDrafts.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDrafts.tsx
@@ -20,7 +20,7 @@ export const ContentAutopilotDrafts = (): JSX.Element | null => {
<LemonCard hoverEffect={false} className="p-8 text-center">
<h3 className="m-0">No drafts yet</h3>
<p className="m-0 mt-2 text-muted max-w-xl mx-auto">
- Pick questions on the Opportunities tab and draft them. Drafts show up here for review.
+ Draft a page from the Opportunities tab. Drafts show up here for review.
</p>
<LemonButton
type="secondary"
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotOpportunities.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotOpportunities.tsx
index 0d6d34a143d1..c07418400eb5 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotOpportunities.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotOpportunities.tsx
@@ -19,6 +19,7 @@ import { faviconUrl } from 'scenes/web-analytics/common'
import type { ContentAutopilotOpportunityApi } from 'products/web_analytics/frontend/generated/api.schemas'
+import { ContentAutopilotDraftButton } from './ContentAutopilotDraftButton'
import { MAX_DRAFTS_PER_RUN, contentAutopilotLogic } from './contentAutopilotLogic'
import { ContentAutopilotPageToUpdate } from './ContentAutopilotPageToUpdate'
import { ContentAutopilotProposalStatusTag } from './ContentAutopilotProposalStatusTag'
@@ -62,13 +63,13 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
opportunitySearch,
opportunityProposals,
pagesToUpdate,
+ draftingOpportunityIds,
} = useValues(contentAutopilotLogic)
const {
refreshOpportunities,
toggleOpportunitySelection,
draftOpportunities,
dismissOpportunity,
- selectProposal,
setShowDismissedOpportunities,
setOpportunitySearch,
} = useActions(contentAutopilotLogic)
@@ -77,14 +78,16 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
return (
<section className="flex flex-col gap-3">
<p className="m-0 text-muted max-w-3xl">
- Questions AI assistants answered without citing {siteName}, most promising first. Pick up to{' '}
- {MAX_DRAFTS_PER_RUN} and draft them.
+ Prompts where AI assistants answered without citing {siteName}, clearest gaps first. Content autopilot
+ drafts a page that answers the prompt, or changes to a page you already have. Select up to{' '}
+ {MAX_DRAFTS_PER_RUN} to draft them together. You review and download each draft, and nothing is
+ published for you.
</p>
<div className="flex flex-wrap items-center justify-between gap-2">
<LemonInput
type="search"
size="small"
- placeholder="Search questions"
+ placeholder="Search prompts"
value={opportunitySearch}
onChange={setOpportunitySearch}
className="w-72"
@@ -113,8 +116,8 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
<LemonButton
type="primary"
size="small"
- onClick={draftOpportunities}
- loading={runMutationLoading}
+ onClick={() => draftOpportunities()}
+ loading={runMutationLoading && draftingOpportunityIds.length === 0}
disabledReason={draftDisabledReason}
data-attr="content-autopilot-draft-opportunities"
>
@@ -143,10 +146,10 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
) : visibleOpportunities.length === 0 ? (
<LemonCard hoverEffect={false} className="p-6 text-center">
{opportunitySearch.trim() ? (
- <p className="m-0 text-muted">No questions match your search.</p>
+ <p className="m-0 text-muted">No prompts match your search.</p>
) : dismissedOpportunityCount > 0 ? (
<>
- <h3 className="m-0">All questions are dismissed</h3>
+ <h3 className="m-0">All opportunities are dismissed</h3>
<p className="m-0 mt-2 text-muted max-w-xl mx-auto">
Turn on "Show dismissed" to see them again, or refresh to check for new citation gaps.
</p>
@@ -155,9 +158,8 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
<>
<h3 className="m-0">No citation gaps found</h3>
<p className="m-0 mt-2 text-muted max-w-xl mx-auto">
- Opportunities appear when AI citation checks show an assistant answering a tracked
- question without citing {siteName}. If checks haven't run for this project yet, there's
- nothing to show.
+ An opportunity appears when an AI assistant answers a tracked prompt without citing{' '}
+ {siteName}. Add prompts on the Prompts tab, and check back after the next daily run.
</p>
</>
)}
@@ -185,7 +187,7 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
),
},
{
- title: 'Question',
+ title: 'Prompt',
key: 'title',
render: (_, opportunity) => {
const proposal = opportunityProposals[opportunity.id]
@@ -250,18 +252,7 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
key: 'actions',
render: (_, opportunity) => (
<div className="flex flex-nowrap items-center justify-end gap-1 whitespace-nowrap">
- {opportunity.proposal_id &&
- opportunity.status === 'drafted' &&
- opportunityProposals[opportunity.id]?.lifecycle_status !== 'generating' ? (
- <LemonButton
- size="small"
- type="secondary"
- onClick={() => selectProposal(opportunity.proposal_id)}
- data-attr="content-autopilot-review-opportunity-draft"
- >
- Review draft
- </LemonButton>
- ) : null}
+ <ContentAutopilotDraftButton opportunity={opportunity} />
{opportunity.status !== 'dismissed' ? (
<LemonButton
size="small"
@@ -273,7 +264,7 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
? 'Wait for the draft to finish'
: dismissingOpportunityId &&
dismissingOpportunityId !== opportunity.id
- ? 'Wait for the other question to finish dismissing'
+ ? 'Wait for the other opportunity to finish dismissing'
: undefined
}
data-attr="content-autopilot-dismiss-opportunity"
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptAddModal.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptAddModal.tsx
new file mode 100644
index 000000000000..8f1e1566473a
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptAddModal.tsx
@@ -0,0 +1,91 @@
+import { useActions, useValues } from 'kea'
+import { useEffect, useState } from 'react'
+
+import { LemonButton, LemonInput, LemonModal, LemonTextArea } from '@posthog/lemon-ui'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+import { pluralize } from 'lib/utils/strings'
+
+import {
+ aeoPromptsBulkImportBodyPromptsItemTopicMax,
+ aeoPromptsBulkImportBodyPromptsMax,
+} from 'products/web_analytics/frontend/generated/api.zod'
+
+import { contentAutopilotPromptsLogic } from './contentAutopilotPromptsLogic'
+import { promptLines } from './utils'
+
+export const ContentAutopilotPromptAddModal = (): JSX.Element => {
+ const { addPromptsOpen, addPromptsSubmitting } = useValues(contentAutopilotPromptsLogic)
+ const { addPrompts, closeAddPrompts } = useActions(contentAutopilotPromptsLogic)
+ const [text, setText] = useState('')
+ const [topic, setTopic] = useState('')
+
+ useEffect(() => {
+ if (!addPromptsOpen) {
+ setText('')
+ setTopic('')
+ }
+ }, [addPromptsOpen])
+
+ const count = promptLines(text).length
+ const disabledReason =
+ count === 0
+ ? 'Enter at least one prompt'
+ : count > aeoPromptsBulkImportBodyPromptsMax
+ ? `Add up to ${aeoPromptsBulkImportBodyPromptsMax} prompts at a time`
+ : undefined
+
+ return (
+ <LemonModal
+ isOpen={addPromptsOpen}
+ onClose={addPromptsSubmitting ? undefined : closeAddPrompts}
+ title="Add prompts"
+ description="Write each prompt the way a person would ask an AI assistant."
+ width={640}
+ footer={
+ <>
+ <LemonButton
+ type="secondary"
+ onClick={closeAddPrompts}
+ disabledReason={addPromptsSubmitting ? 'Wait for the prompts to save' : undefined}
+ >
+ Cancel
+ </LemonButton>
+ <LemonButton
+ type="primary"
+ onClick={() => addPrompts(text, topic)}
+ loading={addPromptsSubmitting}
+ disabledReason={disabledReason}
+ data-attr="content-autopilot-prompts-add-submit"
+ >
+ {count > 0 ? `Add ${pluralize(count, 'prompt')}` : 'Add prompts'}
+ </LemonButton>
+ </>
+ }
+ >
+ <div className="flex flex-col gap-4">
+ <LemonField.Pure
+ label="Prompts"
+ help="One prompt per line. A prompt that is already tracked gets the topic below."
+ >
+ <LemonTextArea
+ value={text}
+ onChange={setText}
+ minRows={6}
+ placeholder="What's the best open source session replay tool?"
+ autoFocus
+ data-attr="content-autopilot-prompts-add-text"
+ />
+ </LemonField.Pure>
+ <LemonField.Pure label="Topic" help="Optional. Groups the prompts in the overview and the list.">
+ <LemonInput
+ value={topic}
+ onChange={setTopic}
+ maxLength={aeoPromptsBulkImportBodyPromptsItemTopicMax}
+ placeholder="Session replay"
+ />
+ </LemonField.Pure>
+ </div>
+ </LemonModal>
+ )
+}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptDetail.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptDetail.tsx
index a07b4b67e58e..71409b1521b1 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptDetail.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptDetail.tsx
@@ -5,18 +5,22 @@ import { LemonBanner, LemonButton, LemonModal, LemonSegmentedButton, LemonSkelet
import { TZLabel } from 'lib/components/TZLabel'
import { pluralize } from 'lib/utils/strings'
+import { ContentAutopilotDraftButton } from './ContentAutopilotDraftButton'
+import { contentAutopilotLogic } from './contentAutopilotLogic'
import { ContentAutopilotPromptActiveSwitch } from './ContentAutopilotPromptActiveSwitch'
import { ContentAutopilotPromptAnswer } from './ContentAutopilotPromptAnswer'
import { ContentAutopilotPromptArchiveBanner } from './ContentAutopilotPromptArchiveBanner'
import { ContentAutopilotPromptChecks } from './ContentAutopilotPromptChecks'
import { ContentAutopilotPromptConsensus } from './ContentAutopilotPromptConsensus'
import { contentAutopilotPromptDetailLogic } from './contentAutopilotPromptDetailLogic'
+import { ContentAutopilotPromptEditModal } from './ContentAutopilotPromptEditModal'
import { ContentAutopilotPromptKpiCard } from './ContentAutopilotPromptKpiCard'
import { ContentAutopilotPromptQueryTile } from './ContentAutopilotPromptQueryTile'
import { ContentAutopilotPromptSentiment } from './ContentAutopilotPromptSentiment'
import { ContentAutopilotPromptVersions } from './ContentAutopilotPromptVersions'
import { rateKpiCard } from './promptReport'
import { promptCitationsContext, promptSearchesContext, promptSourcesContext } from './promptReportColumns'
+import { draftableOpportunity } from './utils'
const Section = ({
title,
@@ -54,9 +58,10 @@ export const ContentAutopilotPromptDetail = (): JSX.Element | null => {
searchesQuery,
sentimentQuery,
} = useValues(contentAutopilotPromptDetailLogic)
- const { closePromptDetail, openPromptDetail, setArchiveConfirming, setVisibilityMetric } = useActions(
- contentAutopilotPromptDetailLogic
- )
+ const { closePromptDetail, openPromptDetail, setArchiveConfirming, setPromptEditing, setVisibilityMetric } =
+ useActions(contentAutopilotPromptDetailLogic)
+ const { opportunityByPromptId } = useValues(contentAutopilotLogic)
+ const draftOpportunity = prompt ? draftableOpportunity(opportunityByPromptId, prompt) : null
if (!promptId) {
return null
@@ -119,17 +124,32 @@ export const ContentAutopilotPromptDetail = (): JSX.Element | null => {
</span>
<span className="text-muted">{pluralize(stats.total_checks, 'check')} in total</span>
{prompt.archived_at ? null : (
- <LemonButton
- size="small"
- type="secondary"
- status="danger"
- className="ml-auto"
- onClick={() => setArchiveConfirming(true)}
- disabledReason={archiveConfirming ? 'Confirm or cancel below' : undefined}
- data-attr="content-autopilot-prompt-archive"
- >
- Archive
- </LemonButton>
+ <div className="ml-auto flex gap-2">
+ {draftOpportunity ? (
+ <ContentAutopilotDraftButton
+ opportunity={draftOpportunity}
+ onReview={closePromptDetail}
+ />
+ ) : null}
+ <LemonButton
+ size="small"
+ type="secondary"
+ onClick={() => setPromptEditing(true)}
+ data-attr="content-autopilot-prompt-edit"
+ >
+ Edit
+ </LemonButton>
+ <LemonButton
+ size="small"
+ type="secondary"
+ status="danger"
+ onClick={() => setArchiveConfirming(true)}
+ disabledReason={archiveConfirming ? 'Confirm or cancel below' : undefined}
+ data-attr="content-autopilot-prompt-archive"
+ >
+ Archive
+ </LemonButton>
+ </div>
)}
</div>
<ContentAutopilotPromptArchiveBanner />
@@ -155,13 +175,13 @@ export const ContentAutopilotPromptDetail = (): JSX.Element | null => {
<div className="grid grid-cols-1 @2xl/prompt-report:grid-cols-2 gap-3">
<ContentAutopilotPromptKpiCard
label="Mentioned in answers"
- description="Share of answers that name you. An answer that cites your site always counts."
+ description="Share of answers that name your brand, with or without a link. An answer that cites your site always counts as a mention."
{...rateKpiCard(reportKpis.visibility)}
data-attr="content-autopilot-prompt-kpi-mentioned"
/>
<ContentAutopilotPromptKpiCard
label="Cited as a source"
- description="Share of answers that link to a page on your site."
+ description="Share of answers that link to a page on your site as a source, so people can click through to it."
{...rateKpiCard(reportKpis.citation)}
data-attr="content-autopilot-prompt-kpi-cited"
/>
@@ -169,7 +189,7 @@ export const ContentAutopilotPromptDetail = (): JSX.Element | null => {
</Section>
<Section
- title="How often engines mention or cite you"
+ title="Mentions and citations over time"
description="One line per engine, one point per day it ran."
>
<ContentAutopilotPromptQueryTile
@@ -202,7 +222,7 @@ export const ContentAutopilotPromptDetail = (): JSX.Element | null => {
</Section>
<Section
- title="Where the answers come from"
+ title="Cited sources"
description="The sites and pages the engines link to when they answer this prompt."
>
<div className="grid grid-cols-1 @3xl/prompt-report:grid-cols-2 gap-4">
@@ -224,21 +244,21 @@ export const ContentAutopilotPromptDetail = (): JSX.Element | null => {
</Section>
<Section
- title="Which sites each engine relies on"
+ title="Cited sites by engine"
description="The share of each engine's answers that link to a site. A darker cell means the engine links to that site more often."
>
<ContentAutopilotPromptConsensus matrix={consensusMatrix} />
</Section>
<Section
- title="How answers talk about you"
+ title="Sentiment"
description="Scored on the sentences that name you, so praise of another tool does not count."
>
<ContentAutopilotPromptSentiment summary={sentimentSummary} query={sentimentQuery} />
</Section>
<Section
- title="What the engines searched for"
+ title="Engine searches"
description="The searches an engine ran before it answered. Engines that do not report their searches are left out."
>
<ContentAutopilotPromptQueryTile
@@ -269,6 +289,7 @@ export const ContentAutopilotPromptDetail = (): JSX.Element | null => {
)}
</div>
)}
+ <ContentAutopilotPromptEditModal />
</LemonModal>
)
}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptEditModal.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptEditModal.tsx
new file mode 100644
index 000000000000..6bc20541c942
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptEditModal.tsx
@@ -0,0 +1,78 @@
+import { useActions, useValues } from 'kea'
+import { useEffect, useState } from 'react'
+
+import { LemonButton, LemonInput, LemonModal, LemonTextArea } from '@posthog/lemon-ui'
+
+import { LemonField } from 'lib/lemon-ui/LemonField'
+
+import {
+ aeoPromptsPartialUpdateBodyPromptMax,
+ aeoPromptsPartialUpdateBodyTopicMax,
+} from 'products/web_analytics/frontend/generated/api.zod'
+
+import { contentAutopilotPromptDetailLogic } from './contentAutopilotPromptDetailLogic'
+
+export const ContentAutopilotPromptEditModal = (): JSX.Element | null => {
+ const { prompt, promptEditing, promptSaving } = useValues(contentAutopilotPromptDetailLogic)
+ const { savePromptEdit, setPromptEditing } = useActions(contentAutopilotPromptDetailLogic)
+ const [text, setText] = useState('')
+ const [topic, setTopic] = useState('')
+
+ useEffect(() => {
+ if (promptEditing && prompt) {
+ setText(prompt.prompt)
+ setTopic(prompt.topic)
+ }
+ }, [promptEditing, prompt])
+
+ if (!prompt) {
+ return null
+ }
+
+ const close = (): void => setPromptEditing(false)
+
+ return (
+ <LemonModal
+ isOpen={promptEditing}
+ onClose={promptSaving ? undefined : close}
+ title="Edit prompt"
+ description="A text change adds a new version. Past checks keep the version they ran with."
+ width={640}
+ footer={
+ <>
+ <LemonButton
+ type="secondary"
+ onClick={close}
+ disabledReason={promptSaving ? 'Wait for the prompt to save' : undefined}
+ >
+ Cancel
+ </LemonButton>
+ <LemonButton
+ type="primary"
+ onClick={() => savePromptEdit(text, topic)}
+ loading={promptSaving}
+ disabledReason={!text.trim() ? 'Enter the prompt text' : undefined}
+ data-attr="content-autopilot-prompt-edit-save"
+ >
+ Save
+ </LemonButton>
+ </>
+ }
+ >
+ <div className="flex flex-col gap-4">
+ <LemonField.Pure label="Prompt">
+ <LemonTextArea
+ value={text}
+ onChange={setText}
+ minRows={3}
+ maxLength={aeoPromptsPartialUpdateBodyPromptMax}
+ autoFocus
+ />
+ </LemonField.Pure>
+ <LemonField.Pure label="Topic" help="Leave empty to remove the topic.">
+ <LemonInput value={topic} onChange={setTopic} maxLength={aeoPromptsPartialUpdateBodyTopicMax} />
+ </LemonField.Pure>
+ </div>
+ </LemonModal>
+ )
+}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptKpiCard.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptKpiCard.tsx
index 4a4fe2b0826d..ce9155339372 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptKpiCard.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptKpiCard.tsx
@@ -1,4 +1,4 @@
-import { IconTrending } from '@posthog/icons'
+import { IconInfo, IconTrending } from '@posthog/icons'
import { LemonCard, LemonTag, Tooltip } from '@posthog/lemon-ui'
import { IconTrendingDown, IconTrendingFlat } from 'lib/lemon-ui/icons'
@@ -37,7 +37,10 @@ export const ContentAutopilotPromptKpiCard = ({
<LemonCard hoverEffect={false} className="p-3 flex flex-col gap-1 min-w-0" data-attr={dataAttr}>
<div className="flex items-center justify-between gap-2">
<Tooltip title={description}>
- <span className="text-muted text-xs font-semibold uppercase truncate">{label}</span>
+ <span className="flex items-center gap-1 min-w-0 text-muted text-xs font-semibold uppercase">
+ <span className="truncate">{label}</span>
+ <IconInfo className="shrink-0 text-sm" />
+ </span>
</Tooltip>
{delta ? <DeltaTag delta={delta} /> : null}
</div>
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPrompts.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPrompts.tsx
index 9d591c876526..a46a91c81707 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPrompts.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPrompts.tsx
@@ -1,9 +1,11 @@
import { useActions, useValues } from 'kea'
+import { IconPlusSmall } from '@posthog/icons'
import {
LemonBanner,
LemonButton,
LemonCard,
+ LemonSegmentedButton,
LemonSelect,
LemonSkeleton,
LemonSwitch,
@@ -17,12 +19,14 @@ import { TZLabel } from 'lib/components/TZLabel'
import type { AEOPromptApi } from 'products/web_analytics/frontend/generated/api.schemas'
import { ContentAutopilotCheckResultTag } from './ContentAutopilotCheckResultTag'
+import { ContentAutopilotDraftButton } from './ContentAutopilotDraftButton'
+import { contentAutopilotLogic } from './contentAutopilotLogic'
import { ContentAutopilotPromptActiveSwitch } from './ContentAutopilotPromptActiveSwitch'
import { ContentAutopilotPromptDetail } from './ContentAutopilotPromptDetail'
import { contentAutopilotPromptDetailLogic } from './contentAutopilotPromptDetailLogic'
+import { ContentAutopilotPromptsDisabled } from './ContentAutopilotPromptsDisabled'
import { PROMPTS_PAGE_SIZE, contentAutopilotPromptsLogic } from './contentAutopilotPromptsLogic'
-import { ContentAutopilotPromptsOverview } from './ContentAutopilotPromptsOverview'
-import { engineLabel } from './utils'
+import { draftableOpportunity, engineLabel } from './utils'
const checkTag = (prompt: AEOPromptApi, engine: string): JSX.Element => {
const check = prompt.latest_checks.find((latest) => latest.engine === engine)
@@ -44,21 +48,22 @@ export const ContentAutopilotPrompts = (): JSX.Element => {
promptTopicsLoading,
promptEngines,
showArchived,
+ needsImprovement,
} = useValues(contentAutopilotPromptsLogic)
- const { loadAeoPrompts, loadAeoPromptTopics, setPromptsPage, setPromptsTopic, setShowArchived } =
- useActions(contentAutopilotPromptsLogic)
+ const {
+ loadAeoPrompts,
+ loadAeoPromptTopics,
+ openAddPrompts,
+ setNeedsImprovement,
+ setPromptsPage,
+ setPromptsTopic,
+ setShowArchived,
+ } = useActions(contentAutopilotPromptsLogic)
+ const { opportunityByPromptId } = useValues(contentAutopilotLogic)
const { openPromptDetail } = useActions(contentAutopilotPromptDetailLogic)
if (promptsError === 'forbidden') {
- return (
- <LemonCard hoverEffect={false} className="p-6 text-center">
- <h3 className="m-0">AI citation tracking is not turned on</h3>
- <p className="m-0 mt-2 text-muted max-w-xl mx-auto">
- This project doesn't have access to prompt tracking yet. Ask PostHog support to turn on AI citation
- tracking for it.
- </p>
- </LemonCard>
- )
+ return <ContentAutopilotPromptsDisabled />
}
const count = prompts?.count ?? 0
@@ -66,16 +71,24 @@ export const ContentAutopilotPrompts = (): JSX.Element => {
return (
<section className="flex flex-col gap-3">
<p className="m-0 text-muted max-w-3xl">
- The questions PostHog asks AI assistants every day, and whether each one cited your site the last time
- it ran.
- </p>
- <p className="m-0 text-muted max-w-3xl">
- You can view tracked prompts, turn them on or off, and archive them here. To add prompts or change their
- text, use the API (<code>POST /api/projects/:project_id/aeo_prompts/bulk_import/</code>) or the PostHog
- MCP tools. A text change adds a new version of the prompt.
+ PostHog sends each active prompt to AI assistants once a day and records whether the answer cites your
+ site. Open a prompt to see the answers, edit it, or archive it.
</p>
- <ContentAutopilotPromptsOverview />
<div className="flex flex-wrap items-center gap-2">
+ <LemonSegmentedButton
+ size="small"
+ value={needsImprovement ? 'needs-improvement' : 'all'}
+ onChange={(value) => setNeedsImprovement(value === 'needs-improvement')}
+ options={[
+ { value: 'all', label: 'All prompts' },
+ {
+ value: 'needs-improvement',
+ label: 'Needs improvement',
+ tooltip: 'Prompts the AI assistants answered in the last 30 days without citing your site.',
+ },
+ ]}
+ data-attr="content-autopilot-prompts-needs-improvement"
+ />
<LemonSelect
size="small"
aria-label="Topic"
@@ -112,6 +125,16 @@ export const ContentAutopilotPrompts = (): JSX.Element => {
size="small"
data-attr="content-autopilot-prompts-show-archived"
/>
+ <LemonButton
+ type="primary"
+ size="small"
+ icon={<IconPlusSmall />}
+ className="ml-auto"
+ onClick={openAddPrompts}
+ data-attr="content-autopilot-prompts-add"
+ >
+ Add prompts
+ </LemonButton>
</div>
{promptsError === 'failed' ? (
@@ -127,12 +150,12 @@ export const ContentAutopilotPrompts = (): JSX.Element => {
promptsError ? null : (
<LemonSkeleton className="h-40 w-full" />
)
- ) : count === 0 && promptsTopic === null && !showArchived ? (
+ ) : count === 0 && promptsTopic === null && !showArchived && !needsImprovement ? (
<LemonCard hoverEffect={false} className="p-6 text-center">
<h3 className="m-0">No prompts yet</h3>
<p className="m-0 mt-2 text-muted max-w-xl mx-auto">
- Add prompts with the API (<code>POST /api/projects/:project_id/aeo_prompts/bulk_import/</code>)
- or the PostHog MCP tools. They're checked against AI assistants on the next daily run.
+ Add the questions your customers ask AI assistants. You can also import prompts with the API (
+ <code>POST /api/projects/:project_id/aeo_prompts/bulk_import/</code>) or the PostHog MCP tools.
</p>
</LemonCard>
) : (
@@ -140,7 +163,13 @@ export const ContentAutopilotPrompts = (): JSX.Element => {
dataSource={prompts.results}
rowKey="id"
loading={promptsLoading}
- emptyState={promptsTopic === null ? 'No prompts to show' : 'No prompts have this topic'}
+ emptyState={
+ needsImprovement
+ ? 'No prompts need improvement. A prompt shows here when an AI assistant answered it in the last 30 days without citing your site.'
+ : promptsTopic === null
+ ? 'No prompts to show'
+ : 'No prompts have this topic'
+ }
pagination={{
controlled: true,
pageSize: PROMPTS_PAGE_SIZE,
@@ -179,6 +208,7 @@ export const ContentAutopilotPrompts = (): JSX.Element => {
},
...promptEngines.map((engine) => ({
title: engineLabel(engine),
+ tooltip: `Whether ${engineLabel(engine)}'s last answer linked to a page on your site.`,
key: `engine-${engine}`,
render: (_: unknown, prompt: AEOPromptApi) => checkTag(prompt, engine),
})),
@@ -192,6 +222,17 @@ export const ContentAutopilotPrompts = (): JSX.Element => {
<span className="text-muted whitespace-nowrap">Never</span>
),
},
+ {
+ key: 'draft',
+ render: (_, prompt) => {
+ const opportunity = draftableOpportunity(opportunityByPromptId, prompt)
+ return opportunity ? (
+ <div className="whitespace-nowrap">
+ <ContentAutopilotDraftButton opportunity={opportunity} />
+ </div>
+ ) : null
+ },
+ },
{
title: 'Active',
key: 'active',
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsDisabled.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsDisabled.tsx
new file mode 100644
index 000000000000..b5758fabed7c
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsDisabled.tsx
@@ -0,0 +1,10 @@
+import { LemonCard } from '@posthog/lemon-ui'
+
+export const ContentAutopilotPromptsDisabled = (): JSX.Element => (
+ <LemonCard hoverEffect={false} className="p-6 text-center">
+ <h3 className="m-0">Prompt tracking is not turned on</h3>
+ <p className="m-0 mt-2 text-muted max-w-xl mx-auto">
+ This project doesn't have access to prompt tracking yet. Ask PostHog support to turn it on.
+ </p>
+ </LemonCard>
+)
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsOverview.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsOverview.tsx
index c257c0f01493..269638a80de7 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsOverview.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsOverview.tsx
@@ -1,6 +1,7 @@
import { useActions, useValues } from 'kea'
-import { LemonBanner, LemonCard, LemonSkeleton } from '@posthog/lemon-ui'
+import { IconPlusSmall } from '@posthog/icons'
+import { LemonBanner, LemonButton, LemonCard, LemonSkeleton } from '@posthog/lemon-ui'
import { percentage } from 'lib/utils/numbers'
import { pluralize } from 'lib/utils/strings'
@@ -9,21 +10,22 @@ import { PagePerformanceCardHeader } from 'scenes/web-analytics/PagePerformanceC
import { ContentAutopilotPromptKpiCard } from './ContentAutopilotPromptKpiCard'
import { ContentAutopilotPromptQueryTile } from './ContentAutopilotPromptQueryTile'
+import { ContentAutopilotPromptsDisabled } from './ContentAutopilotPromptsDisabled'
import { contentAutopilotPromptsLogic } from './contentAutopilotPromptsLogic'
import { OVERVIEW_DAYS, contentAutopilotPromptsOverviewLogic } from './contentAutopilotPromptsOverviewLogic'
import { ContentAutopilotPromptsTopicTable } from './ContentAutopilotPromptsTopicTable'
import { promptSourcesContext } from './promptReportColumns'
import { engineLabel } from './utils'
-export const ContentAutopilotPromptsOverview = (): JSX.Element | null => {
+export const ContentAutopilotPromptsOverview = (): JSX.Element => {
const { overview, overviewLoading, overviewError, overviewKpis, hasChecks, citationQuery, sourcesQuery } =
useValues(contentAutopilotPromptsOverviewLogic)
const { loadPromptSetOverview, selectOverviewTopic } = useActions(contentAutopilotPromptsOverviewLogic)
const { promptsTopic } = useValues(contentAutopilotPromptsLogic)
+ const { openAddPrompts } = useActions(contentAutopilotPromptsLogic)
- // The list below already explains that the feature is off, so the overview says nothing twice.
if (overviewError === 'forbidden') {
- return null
+ return <ContentAutopilotPromptsDisabled />
}
if (overviewError === 'failed') {
return (
@@ -39,8 +41,28 @@ export const ContentAutopilotPromptsOverview = (): JSX.Element | null => {
return <LemonSkeleton className="h-32 w-full" />
}
if (!hasChecks) {
- // Without prompts, the list below shows how to add some.
- return overview.prompts_tracked === 0 ? null : (
+ return overview.prompts_tracked === 0 ? (
+ <LemonCard
+ hoverEffect={false}
+ className="p-6 text-center"
+ data-attr="content-autopilot-prompts-overview-no-prompts"
+ >
+ <h3 className="m-0">No prompts yet</h3>
+ <p className="m-0 mt-2 text-muted max-w-xl mx-auto">
+ Add the questions your customers ask AI assistants. PostHog checks them once a day and shows the
+ results here.
+ </p>
+ <LemonButton
+ type="primary"
+ icon={<IconPlusSmall />}
+ className="mt-4 mx-auto"
+ onClick={openAddPrompts}
+ data-attr="content-autopilot-prompts-overview-add"
+ >
+ Add prompts
+ </LemonButton>
+ </LemonCard>
+ ) : (
<LemonCard hoverEffect={false} className="p-4" data-attr="content-autopilot-prompts-overview-empty">
<h4 className="m-0">No checks yet</h4>
<p className="m-0 mt-1 text-muted">The daily run fills this in.</p>
@@ -74,13 +96,13 @@ export const ContentAutopilotPromptsOverview = (): JSX.Element | null => {
/>
<ContentAutopilotPromptKpiCard
label="Mentioned in answers"
- description="Share of answers that name you. An answer that cites your site always counts."
+ description="Share of answers that name your brand, with or without a link. An answer that cites your site always counts as a mention."
{...overviewKpis.mentionRate}
data-attr="content-autopilot-prompts-overview-kpi-mentioned"
/>
<ContentAutopilotPromptKpiCard
label="Cited as a source"
- description="Share of answers that link to a page on your site."
+ description="Share of answers that link to a page on your site as a source, so people can click through to it."
{...overviewKpis.citationRate}
data-attr="content-autopilot-prompts-overview-kpi-cited"
/>
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsTopicTable.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsTopicTable.tsx
index 49537a1b0ec4..093b835ff229 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsTopicTable.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPromptsTopicTable.tsx
@@ -19,7 +19,7 @@ const RateCell = ({ rate, answers }: { rate: number | null; answers: number }):
</span>
)
-/** One row per topic. Picking a row filters the prompt list below to that topic. */
+/** One row per topic. Picking a row opens the prompt list filtered to that topic. */
export const ContentAutopilotPromptsTopicTable = ({
rows,
selectedTopic,
@@ -85,7 +85,7 @@ export const ContentAutopilotPromptsTopicTable = ({
emptyState="No topics yet"
footer={
<span className="px-3 py-2 text-xs text-muted">
- {pluralize(rows.length, 'topic')}. Pick one to filter the prompts below.
+ {pluralize(rows.length, 'topic')}. Pick one to see its prompts.
</span>
}
/>
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSiteGate.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSiteGate.tsx
new file mode 100644
index 000000000000..d71ac1913628
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSiteGate.tsx
@@ -0,0 +1,30 @@
+import { useValues } from 'kea'
+
+import { LemonCard, LemonSkeleton } from '@posthog/lemon-ui'
+
+import { contentAutopilotLogic } from './contentAutopilotLogic'
+import { ContentAutopilotSetup } from './ContentAutopilotSetup'
+
+// Prompt tracking and bots work without a site. Only content autopilot tabs need one.
+export const ContentAutopilotSiteGate = ({ children }: { children: JSX.Element }): JSX.Element => {
+ const { profile, profileDataLoaded, workspaceErrors, workspaceInitialized } = useValues(contentAutopilotLogic)
+
+ if (!workspaceInitialized) {
+ return <LemonSkeleton className="h-72 w-full" />
+ }
+ if (workspaceErrors.profiles && !profile) {
+ return (
+ <LemonCard hoverEffect={false} className="p-8 text-center">
+ <h2>Sites could not be loaded</h2>
+ <p className="text-muted">Try again before adding or changing a site.</p>
+ </LemonCard>
+ )
+ }
+ if (!profile) {
+ return <ContentAutopilotSetup onboarding />
+ }
+ if (!profileDataLoaded) {
+ return <LemonSkeleton className="h-72 w-full" />
+ }
+ return children
+}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.stories.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.stories.tsx
index 6049443d8d8f..4d1997acbe8b 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.stories.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceLedger.stories.tsx
@@ -9,7 +9,7 @@ const meta: Meta<typeof ContentAutopilotSourceLedger> = {
title: 'Products/Web Analytics/Content autopilot/Sources',
component: ContentAutopilotSourceLedger,
parameters: {
- featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE, FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
+ featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
},
}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.stories.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.stories.tsx
index cde84a59dc04..75b804d5cf7c 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.stories.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotValidationSummary.stories.tsx
@@ -8,7 +8,7 @@ const meta: Meta<typeof ContentAutopilotValidationSummary> = {
title: 'Products/Web Analytics/Content autopilot/Validation summary',
component: ContentAutopilotValidationSummary,
parameters: {
- featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_PAGE_PERFORMANCE, FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
+ featureFlags: [FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT],
},
}
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts
index c67c97e47f63..974ec9338da0 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts
@@ -206,6 +206,25 @@ describe('contentAutopilotLogic', () => {
})
expect(mountedLogic.values.selectedOpportunityIds).toEqual([])
expect(mountedLogic.values.workspaceTab).toBe('drafts')
+
+ // A row's draft button sends only that row, leaves the table selection alone,
+ // and blocks every other draft trigger until the request settles.
+ mountedLogic.actions.toggleOpportunitySelection(first.id)
+ mountedLogic.actions.setWorkspaceTab('prompts')
+ const rowDraft = deferred<ContentAutopilotRunApi>()
+ mockOpportunitiesDraft.mockReturnValueOnce(rowDraft.promise)
+ mountedLogic.actions.draftOpportunities([second.id])
+ expect(mountedLogic.values.rowDraftDisabledReason).toBe('Wait for the current run to finish')
+ expect(mountedLogic.values.draftDisabledReason).toBe('Wait for the current run to finish')
+ rowDraft.resolve({ ...EXAMPLE_RUN, run_status: 'pending', profile_id: EXAMPLE_PROFILE.id })
+ await expectLogic(mountedLogic).toFinishAllListeners()
+ expect(mockOpportunitiesDraft).toHaveBeenLastCalledWith(String(MOCK_DEFAULT_TEAM.id), {
+ profile_id: EXAMPLE_PROFILE.id,
+ opportunity_ids: [second.id],
+ })
+ expect(mountedLogic.values.selectedOpportunityIds).toEqual([first.id])
+ // Drafting from a prompt keeps the user on the Prompts tab.
+ expect(mountedLogic.values.workspaceTab).toBe('prompts')
})
it('sends typed run and profile payloads to the generated API clients', async () => {
@@ -371,13 +390,13 @@ describe('contentAutopilotLogic', () => {
'draftOpportunitiesSuccess',
])
expect(mountedLogic.values.opportunities).toBeNull()
- expect(mountedLogic.values.workspaceTab).toBe('opportunities')
+ expect(mountedLogic.values.workspaceTab).toBe('overview')
secondSiteLoad.resolve(paginated([secondSiteOpportunity]))
await expectLogic(mountedLogic).toFinishAllListeners()
expect(mountedLogic.values.opportunities).toEqual([secondSiteOpportunity])
expect(mountedLogic.values.selectedOpportunityIds).toEqual([secondSiteOpportunity.id])
- expect(mountedLogic.values.workspaceTab).toBe('opportunities')
+ expect(mountedLogic.values.workspaceTab).toBe('overview')
})
it('lists queued pages last only while their run is active, and keeps only run-level errors', async () => {
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts
index caa168b191e4..0397ded7528d 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts
@@ -24,7 +24,7 @@ import { ContentAutopilotPageTarget, opportunitiesNeedRefresh, pageToUpdate, pro
export type ContentAutopilotOnboardingStep = 'site' | 'sources'
export type ContentAutopilotProposalTab = 'preview' | 'draft' | 'changes' | 'brief' | 'sources'
-export type ContentAutopilotWorkspaceTab = 'opportunities' | 'drafts' | 'prompts'
+export type ContentAutopilotWorkspaceTab = 'overview' | 'prompts' | 'opportunities' | 'drafts' | 'settings'
export type ContentAutopilotWorkspaceResource = 'profiles' | 'runs' | 'proposals'
export type ContentAutopilotProfileResource = 'runs' | 'proposals'
export type ContentAutopilotWorkspaceErrors = Partial<Record<ContentAutopilotWorkspaceResource, string>>
@@ -169,6 +169,7 @@ export interface contentAutopilotLogicValues {
dismissingOpportunityId: string | null
draftDisabledReason: string | undefined
draftRows: ContentAutopilotDraftRow[]
+ draftingOpportunityIds: string[]
exportedProposal: ContentAutopilotExportResponseApi | null
exportedProposalLoading: boolean
latestRunErrors: string[]
@@ -177,6 +178,7 @@ export interface contentAutopilotLogicValues {
opportunities: ContentAutopilotOpportunityApi[] | null
opportunitiesError: string | null
opportunitiesLoading: boolean
+ opportunityByPromptId: Record<string, ContentAutopilotOpportunityApi>
opportunityProposals: Record<string, ContentAutopilotProposalListApi>
opportunitySearch: string
pagesToUpdate: Record<string, ContentAutopilotPageTarget | null>
@@ -195,6 +197,7 @@ export interface contentAutopilotLogicValues {
proposalsLoading: boolean
proposedMarkdown: string
readyDraftCount: number
+ rowDraftDisabledReason: string | undefined
runMutation: ContentAutopilotRunApi | null
runMutationLoading: boolean
runs: ContentAutopilotRunApi[]
@@ -289,7 +292,7 @@ export interface contentAutopilotLogicActions {
dismissedOpportunity: ContentAutopilotOpportunityApi
payload?: string
}
- draftOpportunities: () => any
+ draftOpportunities: (opportunityIds?: string[]) => string[]
draftOpportunitiesFailure: (
error: string,
errorObject?: any
@@ -299,10 +302,10 @@ export interface contentAutopilotLogicActions {
}
draftOpportunitiesSuccess: (
runMutation: ContentAutopilotRunApi,
- payload?: any
+ payload?: string[]
) => {
runMutation: ContentAutopilotRunApi
- payload?: any
+ payload?: string[]
}
exportProposal: (proposalId: string) => string
exportProposalFailure: (
@@ -594,16 +597,24 @@ export interface contentAutopilotLogicMeta {
proposalMutationLoading: boolean,
exportedProposalLoading: boolean
) => ContentAutopilotProposalActionReasons
+ opportunityByPromptId: (
+ opportunities: ContentAutopilotOpportunityApi[] | null,
+ profile: ContentAutopilotSiteProfileApi | null
+ ) => Record<string, ContentAutopilotOpportunityApi>
visibleOpportunities: (
opportunities: ContentAutopilotOpportunityApi[] | null,
showDismissedOpportunities: boolean,
opportunitySearch: string
) => ContentAutopilotOpportunityApi[]
dismissedOpportunityCount: (opportunities: ContentAutopilotOpportunityApi[] | null) => number
+ rowDraftDisabledReason: (
+ activeRun: ContentAutopilotRunApi | null,
+ profileDataLoaded: boolean,
+ runMutationLoading: boolean
+ ) => string | undefined
draftDisabledReason: (
selectedOpportunityIds: string[],
- activeRun: ContentAutopilotRunApi | null,
- profileDataLoaded: boolean
+ rowDraftDisabledReason: string | undefined
) => string | undefined
workspaceError: (workspaceErrors: Partial<Record<ContentAutopilotWorkspaceResource, string>>) => string | null
}
@@ -693,10 +704,18 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
},
],
workspaceTab: [
- 'opportunities' as ContentAutopilotWorkspaceTab,
+ 'overview' as ContentAutopilotWorkspaceTab,
{
setWorkspaceTab: (_, { workspaceTab }) => workspaceTab,
- selectProfile: () => 'opportunities',
+ deleteProfileSuccess: () => 'overview',
+ },
+ ],
+ draftingOpportunityIds: [
+ [] as string[],
+ {
+ draftOpportunities: (_, opportunityIds) => opportunityIds ?? [],
+ draftOpportunitiesSuccess: () => [],
+ draftOpportunitiesFailure: () => [],
},
],
opportunitySearch: [
@@ -960,7 +979,8 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
}
)
},
- draftOpportunities: async () => {
+ // Without ids, drafts the opportunities selected in the table.
+ draftOpportunities: async (opportunityIds?: string[]) => {
if (!values.profile) {
throw new Error('Select a site before drafting content')
}
@@ -968,7 +988,7 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
String(values.currentTeamIdStrict),
{
profile_id: values.profile.id,
- opportunity_ids: values.selectedOpportunityIds,
+ opportunity_ids: opportunityIds ?? values.selectedOpportunityIds,
}
)
},
@@ -1219,6 +1239,21 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
}
},
],
+ opportunityByPromptId: [
+ (selectors) => [selectors.opportunities, selectors.profile],
+ (
+ opportunities: ContentAutopilotOpportunityApi[] | null,
+ profile: ContentAutopilotSiteProfileApi | null
+ ): Record<string, ContentAutopilotOpportunityApi> =>
+ Object.fromEntries(
+ (opportunities ?? []).flatMap((opportunity) =>
+ // Opportunities of a deleted or unselected site must not offer drafts.
+ opportunity.aeo_prompt_id && opportunity.profile_id === profile?.id
+ ? [[opportunity.aeo_prompt_id, opportunity]]
+ : []
+ )
+ ),
+ ],
visibleOpportunities: [
(selectors) => [selectors.opportunities, selectors.showDismissedOpportunities, selectors.opportunitySearch],
(
@@ -1239,19 +1274,28 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
(opportunities: ContentAutopilotOpportunityApi[] | null): number =>
(opportunities ?? []).filter(({ status }) => status === 'dismissed').length,
],
- draftDisabledReason: [
- (selectors) => [selectors.selectedOpportunityIds, selectors.activeRun, selectors.profileDataLoaded],
+ rowDraftDisabledReason: [
+ (selectors) => [selectors.activeRun, selectors.profileDataLoaded, selectors.runMutationLoading],
(
- selectedOpportunityIds: string[],
activeRun: ContentAutopilotRunApi | null,
- profileDataLoaded: boolean
+ profileDataLoaded: boolean,
+ runMutationLoading: boolean
): string | undefined => {
if (!profileDataLoaded) {
return 'Wait for this site to finish loading'
}
- if (activeRun) {
+ if (activeRun || runMutationLoading) {
return 'Wait for the current run to finish'
}
+ return undefined
+ },
+ ],
+ draftDisabledReason: [
+ (selectors) => [selectors.selectedOpportunityIds, selectors.rowDraftDisabledReason],
+ (selectedOpportunityIds: string[], rowDraftDisabledReason: string | undefined): string | undefined => {
+ if (rowDraftDisabledReason) {
+ return rowDraftDisabledReason
+ }
if (selectedOpportunityIds.length === 0) {
return 'Select at least one opportunity'
}
@@ -1359,12 +1403,21 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
dismissOpportunityFailure: ({ errorObject }) => {
toastClientError(errorObject)
},
- draftOpportunitiesSuccess: ({ runMutation }) => {
+ draftOpportunitiesSuccess: ({ runMutation, payload }) => {
if (runMutation.profile_id !== values.profile?.id) {
return
}
- actions.clearOpportunitySelection()
- actions.setWorkspaceTab('drafts')
+ if (!payload) {
+ actions.clearOpportunitySelection()
+ }
+ if (!payload || values.workspaceTab === 'opportunities') {
+ actions.setWorkspaceTab('drafts')
+ } else {
+ // Drafting from a prompt keeps the user where they are.
+ lemonToast.success('Drafting started.', {
+ button: { label: 'View drafts', action: () => actions.setWorkspaceTab('drafts') },
+ })
+ }
actions.loadRuns()
actions.loadOpportunities()
},
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptDetailLogic.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptDetailLogic.ts
index 7c636837692b..621e1e33872b 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptDetailLogic.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptDetailLogic.ts
@@ -23,6 +23,7 @@ import type {
PaginatedAEOPromptCheckListApi,
} from 'products/web_analytics/frontend/generated/api.schemas'
+import { contentAutopilotLogic } from './contentAutopilotLogic'
import { contentAutopilotPromptsLogic } from './contentAutopilotPromptsLogic'
import {
PromptConsensusMatrix,
@@ -41,7 +42,7 @@ import {
promptSourcesQuery,
promptVisibilityQuery,
} from './promptReportQueries'
-import { sortEngines } from './utils'
+import { promptEditPatch, sortEngines } from './utils'
export const PROMPT_CHECKS_PAGE_SIZE = 10
@@ -66,8 +67,10 @@ export interface contentAutopilotPromptDetailLogicValues {
latestChecksLoading: boolean
prompt: AEOPromptApi | null
promptArchiving: boolean
+ promptEditing: boolean
promptId: string | null
promptLoading: boolean
+ promptSaving: boolean
reportKpis: PromptReportKpis | null
reportWindow: PromptReportWindow | null
searchesQuery: DataTableNode | null
@@ -203,6 +206,19 @@ export interface contentAutopilotPromptDetailLogicActions {
openPromptDetail: (promptId: string) => {
promptId: string
}
+ savePromptEdit: (
+ text: string,
+ topic: string
+ ) => {
+ text: string
+ topic: string
+ }
+ savePromptEditFailure: () => {
+ value: true
+ }
+ savePromptEditSuccess: (prompt: AEOPromptApi) => {
+ prompt: AEOPromptApi
+ }
selectCheck: (check: AEOPromptCheckApi) => {
check: AEOPromptCheckApi
}
@@ -224,6 +240,9 @@ export interface contentAutopilotPromptDetailLogicActions {
setPromptArchivedSuccess: (prompt: AEOPromptApi) => {
prompt: AEOPromptApi
}
+ setPromptEditing: (editing: boolean) => {
+ editing: boolean
+ }
setVisibilityMetric: (metric: PromptVisibilityMetric) => {
metric: PromptVisibilityMetric
}
@@ -284,6 +303,10 @@ export const contentAutopilotPromptDetailLogic = kea<contentAutopilotPromptDetai
setPromptArchived: (archived: boolean) => ({ archived }),
setPromptArchivedSuccess: (prompt: AEOPromptApi) => ({ prompt }),
setPromptArchivedFailure: true,
+ setPromptEditing: (editing: boolean) => ({ editing }),
+ savePromptEdit: (text: string, topic: string) => ({ text, topic }),
+ savePromptEditSuccess: (prompt: AEOPromptApi) => ({ prompt }),
+ savePromptEditFailure: true,
selectEngine: (engine: string) => ({ engine }),
selectCheck: (check: AEOPromptCheckApi) => ({ check }),
setChecksPage: (page: number) => ({ page }),
@@ -371,6 +394,7 @@ export const contentAutopilotPromptDetailLogic = kea<contentAutopilotPromptDetai
setPromptActiveFailure: (state, { promptId, active }) =>
state?.id === promptId ? { ...state, active: !active } : state,
setPromptArchivedSuccess: (state, { prompt }) => (state?.id === prompt.id ? prompt : state),
+ savePromptEditSuccess: (state, { prompt }) => (state?.id === prompt.id ? prompt : state),
},
versions: { openPromptDetail: () => null },
versionsFailed: [
@@ -388,6 +412,24 @@ export const contentAutopilotPromptDetailLogic = kea<contentAutopilotPromptDetai
setPromptArchivedSuccess: () => false,
},
],
+ promptEditing: [
+ false,
+ {
+ openPromptDetail: () => false,
+ closePromptDetail: () => false,
+ setPromptEditing: (_, { editing }) => editing,
+ savePromptEditSuccess: () => false,
+ },
+ ],
+ promptSaving: [
+ false,
+ {
+ savePromptEdit: () => true,
+ setPromptEditing: () => false,
+ savePromptEditSuccess: () => false,
+ savePromptEditFailure: () => false,
+ },
+ ],
promptArchiving: [
false,
{
@@ -548,6 +590,42 @@ export const contentAutopilotPromptDetailLogic = kea<contentAutopilotPromptDetai
}
},
setChecksPage: () => actions.loadAeoPromptChecks(),
+ savePromptEdit: async ({ text, topic }) => {
+ const prompt = values.prompt
+ if (!prompt) {
+ return
+ }
+ const patch = promptEditPatch(prompt, text, topic)
+ if (!patch) {
+ actions.setPromptEditing(false)
+ return
+ }
+ try {
+ const updated = await aeoPromptsPartialUpdate(String(values.currentTeamIdStrict), prompt.id, patch)
+ actions.savePromptEditSuccess(updated)
+ // pinned: analytics event name, renaming it breaks dashboards
+ posthog.capture('web analytics content autopilot prompt edited', {
+ text_changed: patch.prompt !== undefined,
+ topic_changed: patch.topic !== undefined,
+ })
+ // The user may have opened another prompt while this save was in flight.
+ if (updated.version_count > 1 && values.promptId === updated.id) {
+ actions.loadAeoPromptVersions(updated.id)
+ }
+ actions.loadAeoPrompts()
+ actions.loadAeoPromptTopics()
+ if (patch.prompt !== undefined) {
+ // Opportunities carry the old wording; a refresh rebuilds them for the new text.
+ contentAutopilotLogic.findMounted()?.actions.refreshOpportunities()
+ }
+ } catch (error) {
+ actions.savePromptEditFailure()
+ // A 400 or 409 says why the change was refused, for example a duplicate prompt text.
+ const detail =
+ error instanceof ApiError && (error.status === 400 || error.status === 409) ? error.detail : null
+ lemonToast.error(detail || "Couldn't save the prompt. Try again.")
+ }
+ },
setPromptArchived: async ({ archived }) => {
if (!values.promptId) {
return
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.test.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.test.ts
index 45a3cf389710..01796d46f627 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.test.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.test.ts
@@ -8,7 +8,7 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
import { initKeaTests } from '~/test/init'
-import { aeoPromptsList, aeoPromptsPartialUpdate, aeoPromptsTopics } from '../generated/api'
+import { aeoPromptsBulkImport, aeoPromptsList, aeoPromptsPartialUpdate, aeoPromptsTopics } from '../generated/api'
import type { AEOPromptApi } from '../generated/api.schemas'
import { PROMPTS_PAGE_SIZE, contentAutopilotPromptsLogic } from './contentAutopilotPromptsLogic'
import { EXAMPLE_PROMPT_TOPICS, EXAMPLE_PROMPTS } from './contentAutopilotStoryFixtures'
@@ -17,13 +17,15 @@ jest.mock('../generated/api', () => ({
aeoPromptsList: jest.fn(),
aeoPromptsTopics: jest.fn(),
aeoPromptsPartialUpdate: jest.fn(),
+ aeoPromptsBulkImport: jest.fn(),
}))
-jest.mock('lib/lemon-ui/LemonToast/LemonToast', () => ({ lemonToast: { error: jest.fn() } }))
+jest.mock('lib/lemon-ui/LemonToast/LemonToast', () => ({ lemonToast: { error: jest.fn(), success: jest.fn() } }))
const mockPromptsList = jest.mocked(aeoPromptsList)
const mockPromptsTopics = jest.mocked(aeoPromptsTopics)
const mockPromptsPartialUpdate = jest.mocked(aeoPromptsPartialUpdate)
+const mockPromptsBulkImport = jest.mocked(aeoPromptsBulkImport)
describe('contentAutopilotPromptsLogic', () => {
let logic: ReturnType<typeof contentAutopilotPromptsLogic.build>
@@ -39,7 +41,7 @@ describe('contentAutopilotPromptsLogic', () => {
logic?.unmount()
})
- it('resets to the first page and sends the filters when the topic or archived filter changes', async () => {
+ it('resets to the first page and sends the filters when the topic, archived or needs improvement filter changes', async () => {
logic = contentAutopilotPromptsLogic()
logic.mount()
await expectLogic(logic).toFinishAllListeners()
@@ -69,6 +71,17 @@ describe('contentAutopilotPromptsLogic', () => {
topic: '',
include_archived: true,
})
+
+ logic.actions.setPromptsPage(2)
+ logic.actions.setNeedsImprovement(true)
+ await expectLogic(logic).toFinishAllListeners().toMatchValues({ promptsPage: 1 })
+ expect(mockPromptsList).toHaveBeenLastCalledWith(String(MOCK_DEFAULT_TEAM.id), {
+ limit: PROMPTS_PAGE_SIZE,
+ offset: 0,
+ topic: '',
+ include_archived: true,
+ needs_improvement: true,
+ })
})
it.each([
@@ -159,4 +172,40 @@ describe('contentAutopilotPromptsLogic', () => {
expect(logic.values.promptActiveUpdating).toEqual({})
expect(lemonToast.error).toHaveBeenCalledTimes(succeeds ? 0 : 1)
})
+
+ it.each([
+ ['closes the dialog and reloads the list', true],
+ ['keeps the dialog open and shows why', false],
+ ])('sends one prompt per unique line, then %s', async (_name, succeeds) => {
+ if (succeeds) {
+ mockPromptsBulkImport.mockResolvedValue({ created: 2, updated: 0, skipped: 0 })
+ } else {
+ mockPromptsBulkImport.mockRejectedValue(
+ new ApiError('Bad request', 400, undefined, { detail: 'Prompt is too long' })
+ )
+ }
+ logic = contentAutopilotPromptsLogic()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+ mockPromptsList.mockClear()
+
+ logic.actions.openAddPrompts()
+ logic.actions.addPrompts(
+ ' Best session replay tool?\n\nbest session replay tool?\nHow do I track signups? ',
+ ' Replay '
+ )
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(mockPromptsBulkImport).toHaveBeenCalledWith(String(MOCK_DEFAULT_TEAM.id), {
+ prompts: [
+ { prompt: 'Best session replay tool?', topic: 'Replay' },
+ { prompt: 'How do I track signups?', topic: 'Replay' },
+ ],
+ })
+ expect(logic.values).toMatchObject({ addPromptsOpen: !succeeds, addPromptsSubmitting: false })
+ expect(mockPromptsList).toHaveBeenCalledTimes(succeeds ? 1 : 0)
+ expect(jest.mocked(lemonToast.error).mock.calls.map(([message]) => message)).toEqual(
+ succeeds ? [] : ['Prompt is too long']
+ )
+ })
})
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.ts
index ad261007c528..9b4431e75932 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsLogic.ts
@@ -7,17 +7,19 @@ import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { teamLogic } from 'scenes/teamLogic'
import {
+ aeoPromptsBulkImport,
aeoPromptsList,
aeoPromptsPartialUpdate,
aeoPromptsTopics,
} from 'products/web_analytics/frontend/generated/api'
import type {
AEOPromptApi,
+ AEOPromptImportResultApi,
AEOPromptTopicApi,
PaginatedAEOPromptListApi,
} from 'products/web_analytics/frontend/generated/api.schemas'
-import { sortEngines } from './utils'
+import { promptImportMessage, promptLines, sortEngines } from './utils'
export const PROMPTS_PAGE_SIZE = 50
@@ -44,6 +46,9 @@ const withPromptActive = (
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface contentAutopilotPromptsLogicValues {
currentTeamIdStrict: number | string // teamLogic
+ addPromptsOpen: boolean
+ addPromptsSubmitting: boolean
+ needsImprovement: boolean
promptActiveUpdating: Record<string, boolean>
promptEngines: string[]
promptTopics: AEOPromptTopicApi[]
@@ -59,6 +64,22 @@ export interface contentAutopilotPromptsLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface contentAutopilotPromptsLogicActions {
+ addPrompts: (
+ text: string,
+ topic: string
+ ) => {
+ text: string
+ topic: string
+ }
+ addPromptsFailure: () => {
+ value: true
+ }
+ addPromptsSuccess: (result: AEOPromptImportResultApi) => {
+ result: AEOPromptImportResultApi
+ }
+ closeAddPrompts: () => {
+ value: true
+ }
loadAeoPromptTopics: () => any
loadAeoPromptTopicsFailure: (
error: string,
@@ -95,6 +116,12 @@ export interface contentAutopilotPromptsLogicActions {
value: true
}
}
+ openAddPrompts: () => {
+ value: true
+ }
+ setNeedsImprovement: (needsImprovement: boolean) => {
+ needsImprovement: boolean
+ }
setPromptActive: (
promptId: string,
active: boolean
@@ -145,9 +172,15 @@ export const contentAutopilotPromptsLogic = kea<contentAutopilotPromptsLogicType
setPromptsPage: (page: number) => ({ page }),
setPromptsTopic: (topic: string | null) => ({ topic }),
setShowArchived: (showArchived: boolean) => ({ showArchived }),
+ setNeedsImprovement: (needsImprovement: boolean) => ({ needsImprovement }),
setPromptActive: (promptId: string, active: boolean) => ({ promptId, active }),
setPromptActiveSuccess: (prompt: AEOPromptApi) => ({ prompt }),
setPromptActiveFailure: (promptId: string, active: boolean) => ({ promptId, active }),
+ openAddPrompts: true,
+ closeAddPrompts: true,
+ addPrompts: (text: string, topic: string) => ({ text, topic }),
+ addPromptsSuccess: (result: AEOPromptImportResultApi) => ({ result }),
+ addPromptsFailure: true,
}),
loaders(({ values }) => ({
prompts: [
@@ -160,6 +193,7 @@ export const contentAutopilotPromptsLogic = kea<contentAutopilotPromptsLogicType
offset: (values.promptsPage - 1) * PROMPTS_PAGE_SIZE,
topic: values.promptsTopic ?? undefined,
include_archived: values.showArchived || undefined,
+ needs_improvement: values.needsImprovement || undefined,
})
breakpoint()
return response
@@ -192,12 +226,35 @@ export const contentAutopilotPromptsLogic = kea<contentAutopilotPromptsLogicType
setPromptActiveFailure: (state, { promptId }) => omitKey(state, promptId),
},
],
+ addPromptsOpen: [
+ false,
+ {
+ openAddPrompts: () => true,
+ closeAddPrompts: () => false,
+ addPromptsSuccess: () => false,
+ },
+ ],
+ addPromptsSubmitting: [
+ false,
+ {
+ addPrompts: () => true,
+ addPromptsSuccess: () => false,
+ addPromptsFailure: () => false,
+ },
+ ],
promptsPage: [
1,
{
setPromptsPage: (_, { page }) => page,
setPromptsTopic: () => 1,
setShowArchived: () => 1,
+ setNeedsImprovement: () => 1,
+ },
+ ],
+ needsImprovement: [
+ false,
+ {
+ setNeedsImprovement: (_, { needsImprovement }) => needsImprovement,
},
],
showArchived: [
@@ -250,12 +307,42 @@ export const contentAutopilotPromptsLogic = kea<contentAutopilotPromptsLogicType
)
}
},
+ addPrompts: async ({ text, topic }) => {
+ const prompts = promptLines(text).map((prompt) => ({ prompt, topic: topic.trim() || undefined }))
+ try {
+ const result = await aeoPromptsBulkImport(String(values.currentTeamIdStrict), { prompts })
+ actions.addPromptsSuccess(result)
+ } catch (error) {
+ actions.addPromptsFailure()
+ // A 400 explains why the prompts were refused, so show it rather than asking for a retry.
+ const detail = error instanceof ApiError && error.status === 400 ? error.detail : null
+ lemonToast.error(detail || "Couldn't add the prompts. Try again.")
+ }
+ },
+ addPromptsSuccess: ({ result }) => {
+ // pinned: analytics event name, renaming it breaks dashboards
+ posthog.capture('web analytics content autopilot prompts added', {
+ created: result.created,
+ updated: result.updated,
+ skipped: result.skipped,
+ })
+ lemonToast.success(promptImportMessage(result))
+ actions.loadAeoPrompts()
+ actions.loadAeoPromptTopics()
+ },
setPromptsPage: () => actions.loadAeoPrompts(),
setShowArchived: ({ showArchived }) => {
// pinned: analytics event name, renaming it breaks dashboards
posthog.capture('web analytics content autopilot prompts archived shown', { show_archived: showArchived })
actions.loadAeoPrompts()
},
+ setNeedsImprovement: ({ needsImprovement }) => {
+ // pinned: analytics event name, renaming it breaks dashboards
+ posthog.capture('web analytics content autopilot prompts needs improvement filtered', {
+ needs_improvement: needsImprovement,
+ })
+ actions.loadAeoPrompts()
+ },
setPromptsTopic: ({ topic }) => {
// pinned: analytics event name, renaming it breaks dashboards
posthog.capture('web analytics content autopilot prompts topic changed', {
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsOverviewLogic.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsOverviewLogic.ts
index 29ca68c05b9a..983641e4359c 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsOverviewLogic.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotPromptsOverviewLogic.ts
@@ -9,6 +9,7 @@ import type { DataTableNode, DataVisualizationNode } from '~/queries/schema/sche
import { aeoPromptsOverview } from 'products/web_analytics/frontend/generated/api'
import type { AEOPromptSetOverviewApi } from 'products/web_analytics/frontend/generated/api.schemas'
+import { ContentAutopilotWorkspaceTab, contentAutopilotLogic } from './contentAutopilotLogic'
import { contentAutopilotPromptDetailLogic } from './contentAutopilotPromptDetailLogic'
import {
ContentAutopilotPromptsError,
@@ -35,11 +36,22 @@ export interface contentAutopilotPromptsOverviewLogicValues {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface contentAutopilotPromptsOverviewLogicActions {
+ setWorkspaceTab: (workspaceTab: ContentAutopilotWorkspaceTab) => {
+ workspaceTab: ContentAutopilotWorkspaceTab
+ } // contentAutopilotLogic
+ savePromptEditSuccess: (prompt: import('products/web_analytics/frontend/generated/api.schemas').AEOPromptApi) => {
+ prompt: import('products/web_analytics/frontend/generated/api.schemas').AEOPromptApi
+ } // contentAutopilotPromptDetailLogic
setPromptArchivedSuccess: (
prompt: import('products/web_analytics/frontend/generated/api.schemas').AEOPromptApi
) => {
prompt: import('products/web_analytics/frontend/generated/api.schemas').AEOPromptApi
} // contentAutopilotPromptDetailLogic
+ addPromptsSuccess: (
+ result: import('products/web_analytics/frontend/generated/api.schemas').AEOPromptImportResultApi
+ ) => {
+ result: import('products/web_analytics/frontend/generated/api.schemas').AEOPromptImportResultApi
+ } // contentAutopilotPromptsLogic
setPromptActiveSuccess: (prompt: import('products/web_analytics/frontend/generated/api.schemas').AEOPromptApi) => {
prompt: import('products/web_analytics/frontend/generated/api.schemas').AEOPromptApi
} // contentAutopilotPromptsLogic
@@ -96,9 +108,11 @@ export const contentAutopilotPromptsOverviewLogic = kea<contentAutopilotPromptsO
values: [teamLogic, ['currentTeamIdStrict']],
actions: [
contentAutopilotPromptsLogic,
- ['setPromptsTopic', 'setPromptActiveSuccess'],
+ ['setPromptsTopic', 'setPromptActiveSuccess', 'addPromptsSuccess'],
contentAutopilotPromptDetailLogic,
- ['setPromptArchivedSuccess'],
+ ['setPromptArchivedSuccess', 'savePromptEditSuccess'],
+ contentAutopilotLogic,
+ ['setWorkspaceTab'],
],
})),
actions({
@@ -166,10 +180,13 @@ export const contentAutopilotPromptsOverviewLogic = kea<contentAutopilotPromptsO
// pinned: analytics event name, renaming it breaks dashboards
posthog.capture('web analytics content autopilot prompts overview topic selected')
actions.setPromptsTopic(topic)
+ actions.setWorkspaceTab('prompts')
},
- // Turning a prompt on or off, or archiving one, changes how many prompts are tracked.
+ // Adding, editing, turning on or off, or archiving a prompt changes the counts.
setPromptActiveSuccess: () => actions.loadPromptSetOverview(),
setPromptArchivedSuccess: () => actions.loadPromptSetOverview(),
+ addPromptsSuccess: () => actions.loadPromptSetOverview(),
+ savePromptEditSuccess: () => actions.loadPromptSetOverview(),
})),
afterMount(({ actions }) => {
actions.loadPromptSetOverview()
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts
index 20988a0efa8b..af6e2ee824b6 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts
@@ -175,6 +175,7 @@ export const EXAMPLE_OPPORTUNITIES: ContentAutopilotOpportunityApi[] = [
profile_id: EXAMPLE_PROFILE.id,
run_id: null,
proposal_id: null,
+ aeo_prompt_id: '00000000-0000-4000-8000-000000000302',
kind: 'ai_visibility_gap',
title: 'What is the best open source session replay tool?',
score: 1,
@@ -192,6 +193,7 @@ export const EXAMPLE_OPPORTUNITIES: ContentAutopilotOpportunityApi[] = [
profile_id: EXAMPLE_PROFILE.id,
run_id: EXAMPLE_RUN.id,
proposal_id: EXAMPLE_PROPOSAL.id,
+ aeo_prompt_id: null,
kind: 'ai_visibility_gap',
title: 'Does web analytics work without cookies?',
score: 0.64,
@@ -234,6 +236,7 @@ export const EXAMPLE_FAILED_DRAFT_OPPORTUNITY: ContentAutopilotOpportunityApi =
...EXAMPLE_OPPORTUNITIES[0],
id: '00000000-0000-4000-8000-000000000303',
proposal_id: EXAMPLE_FAILED_PROPOSAL_LIST.id,
+ aeo_prompt_id: null,
run_id: EXAMPLE_RUN.id,
title: 'How do I track AI crawler traffic on my website?',
status: 'drafted',
diff --git a/products/web_analytics/frontend/contentAutopilot/utils.test.ts b/products/web_analytics/frontend/contentAutopilot/utils.test.ts
new file mode 100644
index 000000000000..1fc94f28b296
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/utils.test.ts
@@ -0,0 +1,24 @@
+import type { ContentAutopilotOpportunityApi } from '../generated/api.schemas'
+import { EXAMPLE_OPPORTUNITIES } from './contentAutopilotStoryFixtures'
+import { draftableOpportunity } from './utils'
+
+describe('draftableOpportunity', () => {
+ const opportunity: ContentAutopilotOpportunityApi = {
+ ...EXAMPLE_OPPORTUNITIES[0],
+ aeo_prompt_id: 'prompt-1',
+ title: 'Best session replay tool?',
+ }
+ const byPrompt = { 'prompt-1': opportunity }
+
+ it.each([
+ ['the same text', 'Best session replay tool?', true],
+ ['the same text with other case and spacing', ' best session replay TOOL? ', true],
+ ['edited text', 'Best open source session replay tool?', false],
+ ])('offers the opportunity for %s', (_name, text, expected) => {
+ expect(draftableOpportunity(byPrompt, { id: 'prompt-1', prompt: text })).toBe(expected ? opportunity : null)
+ })
+
+ it('offers nothing for a prompt without an opportunity', () => {
+ expect(draftableOpportunity(byPrompt, { id: 'prompt-2', prompt: 'Best session replay tool?' })).toBeNull()
+ })
+})
diff --git a/products/web_analytics/frontend/contentAutopilot/utils.ts b/products/web_analytics/frontend/contentAutopilot/utils.ts
index 20b6b5738f9c..2c41cb00656d 100644
--- a/products/web_analytics/frontend/contentAutopilot/utils.ts
+++ b/products/web_analytics/frontend/contentAutopilot/utils.ts
@@ -1,9 +1,13 @@
+import { pluralize } from 'lib/utils/strings'
import { parseWebAnalyticsURL } from 'scenes/web-analytics/common'
import type {
AEOPromptCheckApi,
+ AEOPromptApi,
+ AEOPromptImportResultApi,
ContentAutopilotOpportunityApi,
ContentAutopilotProposalListApi,
+ PatchedAEOPromptUpdateRequestApi,
} from 'products/web_analytics/frontend/generated/api.schemas'
const OPPORTUNITIES_STALE_AFTER_MS = 60 * 60 * 1000
@@ -69,3 +73,53 @@ export const opportunitiesNeedRefresh = (
// before then, so those checks all ran the text that became version 1.
export const checkPromptVersion = (check: Pick<AEOPromptCheckApi, 'prompt_version'>): number =>
check.prompt_version ?? 1
+
+export const promptLines = (text: string): string[] => {
+ const seen = new Set<string>()
+ return text
+ .split('\n')
+ .map((line) => line.trim())
+ .filter((line) => {
+ const key = line.toLowerCase()
+ if (!line || seen.has(key)) {
+ return false
+ }
+ seen.add(key)
+ return true
+ })
+}
+
+export const promptImportMessage = ({ created, updated, skipped }: AEOPromptImportResultApi): string => {
+ const sentences = [
+ created ? `Added ${pluralize(created, 'prompt')}. The next daily run checks new prompts.` : null,
+ updated ? `Updated ${pluralize(updated, 'existing prompt')}.` : null,
+ skipped ? `Skipped ${pluralize(skipped, 'prompt')} (empty, too long, or archived).` : null,
+ ].filter(Boolean)
+ return sentences.join(' ') || 'No prompts changed.'
+}
+
+export const promptEditPatch = (
+ prompt: Pick<AEOPromptApi, 'prompt' | 'topic'>,
+ text: string,
+ topic: string
+): PatchedAEOPromptUpdateRequestApi | null => {
+ const patch: PatchedAEOPromptUpdateRequestApi = {}
+ if (text.trim() !== prompt.prompt) {
+ patch.prompt = text.trim()
+ }
+ if (topic.trim() !== prompt.topic) {
+ patch.topic = topic.trim()
+ }
+ return Object.keys(patch).length ? patch : null
+}
+
+const normalizedPrompt = (text: string): string => text.trim().replace(/\s+/g, ' ').toLowerCase()
+
+// An opportunity drafts from the text it was found for, so after an edit it stays hidden until a refresh matches it.
+export const draftableOpportunity = (
+ opportunityByPromptId: Record<string, ContentAutopilotOpportunityApi>,
+ prompt: Pick<AEOPromptApi, 'id' | 'prompt'>
+): ContentAutopilotOpportunityApi | null => {
+ const opportunity = opportunityByPromptId[prompt.id]
+ return opportunity && normalizedPrompt(opportunity.title) === normalizedPrompt(prompt.prompt) ? opportunity : null
+}
diff --git a/products/web_analytics/frontend/generated/api.schemas.ts b/products/web_analytics/frontend/generated/api.schemas.ts
index 4b0344909a00..42d73b66531d 100644
--- a/products/web_analytics/frontend/generated/api.schemas.ts
+++ b/products/web_analytics/frontend/generated/api.schemas.ts
@@ -83,7 +83,7 @@ export interface PatchedAEOPromptUpdateRequestApi {
topic?: string
/**
* New text for the prompt. A change adds the next version and makes it current; the prompt keeps its id and its check history, and each check records the version that ran. A change of case or whitespace only adds no version. Fails with 409 when another prompt in the set already has the text.
- * @maxLength 10000
+ * @maxLength 2000
*/
prompt?: string
/**
@@ -1542,6 +1542,11 @@ export interface ContentAutopilotOpportunityApi {
* @nullable
*/
readonly proposal_id: string | null
+ /**
+ * Tracked AI visibility prompt this opportunity came from.
+ * @nullable
+ */
+ readonly aeo_prompt_id: string | null
/** Type of visibility gap.
*
* * `ai_visibility_gap` - AI visibility gap */
@@ -2095,6 +2100,10 @@ export type AeoPromptsListParams = {
* @maximum 1000
*/
limit?: number
+ /**
+ * Only list prompts that the engines answered in the last 30 days without citing a target domain. Prompts with no answered check in that window are left out.
+ */
+ needs_improvement?: boolean
/**
* The initial index from which to return the results.
*/
diff --git a/products/web_analytics/frontend/generated/api.ts b/products/web_analytics/frontend/generated/api.ts
index fa9958457df0..ea5431fd5f35 100644
--- a/products/web_analytics/frontend/generated/api.ts
+++ b/products/web_analytics/frontend/generated/api.ts
@@ -122,7 +122,7 @@ export const getAeoPromptsListUrl = (projectId: string, params?: AeoPromptsListP
}
/**
- * Lists the project's AEO prompt set, ordered by topic and then rank, one page at a time. Filter by topic or by on/off state. Archived prompts are left out unless include_archived is true. Each prompt carries its latest check per answer engine.
+ * Lists the project's AEO prompt set, ordered by topic and then rank, one page at a time. Filter by topic, by on/off state, or to the prompts that need improvement. Archived prompts are left out unless include_archived is true. Each prompt carries its latest check per answer engine.
* @summary List AEO prompts
*/
export const aeoPromptsList = async (
diff --git a/products/web_analytics/frontend/generated/api.zod.ts b/products/web_analytics/frontend/generated/api.zod.ts
index 342798fb5863..89f7bf5b37df 100644
--- a/products/web_analytics/frontend/generated/api.zod.ts
+++ b/products/web_analytics/frontend/generated/api.zod.ts
@@ -15,7 +15,7 @@ import * as zod from 'zod'
*/
export const aeoPromptsPartialUpdateBodyTopicMax = 200
-export const aeoPromptsPartialUpdateBodyPromptMax = 10000
+export const aeoPromptsPartialUpdateBodyPromptMax = 2000
export const aeoPromptsPartialUpdateBodyVersionDescriptionMax = 400
diff --git a/products/web_analytics/manifest.tsx b/products/web_analytics/manifest.tsx
index 3334aef8677c..16e0b9e2bfb3 100644
--- a/products/web_analytics/manifest.tsx
+++ b/products/web_analytics/manifest.tsx
@@ -79,7 +79,16 @@ export const manifest: ProductManifest = {
{ name: 'Page reports', href: urls.webAnalyticsPageReports() },
{ name: 'Live', href: urls.webAnalyticsLive() },
{ name: 'Installation health', href: urls.webAnalyticsHealth() },
- { name: 'Bots', href: urls.webAnalyticsBotAnalytics(), flag: FEATURE_FLAGS.WEB_ANALYTICS_BOT_ANALYSIS },
+ {
+ name: 'AI visibility',
+ href: urls.webAnalyticsContentAutopilot(),
+ flag: FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT,
+ },
+ {
+ name: 'Bots',
+ href: urls.webAnalyticsBotAnalytics(),
+ flag: FEATURE_FLAGS.WEB_ANALYTICS_CONTENT_AUTOPILOT,
+ },
{
name: 'Search & AI',
href: urls.webAnalyticsPagePerformance(),
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 5b976d12c6b3..30d724973059 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -27566,6 +27566,11 @@ export namespace Schemas {
* @nullable
*/
readonly proposal_id: string | null;
+ /**
+ * Tracked AI visibility prompt this opportunity came from.
+ * @nullable
+ */
+ readonly aeo_prompt_id: string | null;
/** Type of visibility gap.
*
* * `ai_visibility_gap` - AI visibility gap */
@@ -79992,7 +79997,7 @@ export namespace Schemas {
topic?: string;
/**
* New text for the prompt. A change adds the next version and makes it current; the prompt keeps its id and its check history, and each check records the version that ran. A change of case or whitespace only adds no version. Fails with 409 when another prompt in the set already has the text.
- * @maxLength 10000
+ * @maxLength 2000
*/
prompt?: string;
/**
@@ -122744,6 +122749,10 @@ export namespace Schemas {
* @maximum 1000
*/
limit?: number;
+ /**
+ * Only list prompts that the engines answered in the last 30 days without citing a target domain. Prompts with no answered check in that window are left out.
+ */
+ needs_improvement?: boolean;
/**
* The initial index from which to return the results.
*/
diff --git a/services/mcp/src/generated/aeo/api.ts b/services/mcp/src/generated/aeo/api.ts
index de882ad09b3c..4d0bc332255a 100644
--- a/services/mcp/src/generated/aeo/api.ts
+++ b/services/mcp/src/generated/aeo/api.ts
@@ -9,7 +9,7 @@
import * as zod from 'zod'
/**
- * Lists the project's AEO prompt set, ordered by topic and then rank, one page at a time. Filter by topic or by on/off state. Archived prompts are left out unless include_archived is true. Each prompt carries its latest check per answer engine.
+ * Lists the project's AEO prompt set, ordered by topic and then rank, one page at a time. Filter by topic, by on/off state, or to the prompts that need improvement. Archived prompts are left out unless include_archived is true. Each prompt carries its latest check per answer engine.
* @summary List AEO prompts
*/
export const AeoPromptsListParams = () => zod.object({
@@ -23,6 +23,7 @@ export const AeoPromptsListParams = () => zod.object({
export const aeoPromptsListQueryIncludeArchivedDefault = false
export const aeoPromptsListQueryLimitMax = 1000
+export const aeoPromptsListQueryNeedsImprovementDefault = false
export const aeoPromptsListQueryTopicMax = 200
export const AeoPromptsListQueryParams = () => zod.object({
@@ -32,6 +33,12 @@ export const AeoPromptsListQueryParams = () => zod.object({
.default(aeoPromptsListQueryIncludeArchivedDefault)
.describe('Also list archived prompts. Archived prompts are left out by default.'),
limit: zod.number().max(aeoPromptsListQueryLimitMax).optional().describe('Number of results to return per page.'),
+ needs_improvement: zod
+ .boolean()
+ .default(aeoPromptsListQueryNeedsImprovementDefault)
+ .describe(
+ 'Only list prompts that the engines answered in the last 30 days without citing a target domain. Prompts with no answered check in that window are left out.'
+ ),
offset: zod.number().optional().describe('The initial index from which to return the results.'),
topic: zod
.string()
@@ -68,7 +75,7 @@ export const AeoPromptsPartialUpdateParams = () => zod.object({
export const aeoPromptsPartialUpdateBodyTopicMax = 200
-export const aeoPromptsPartialUpdateBodyPromptMax = 10000
+export const aeoPromptsPartialUpdateBodyPromptMax = 2000
export const aeoPromptsPartialUpdateBodyVersionDescriptionMax = 400
diff --git a/services/mcp/src/tools/generated/aeo.ts b/services/mcp/src/tools/generated/aeo.ts
index fa447d483840..efc41c0f3872 100644
--- a/services/mcp/src/tools/generated/aeo.ts
+++ b/services/mcp/src/tools/generated/aeo.ts
@@ -119,6 +119,7 @@ const aeoPromptsList = (): ToolBase<
active: params.active,
include_archived: params.include_archived,
limit: params.limit,
+ needs_improvement: params.needs_improvement,
offset: params.offset,
topic: params.topic,
},
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-list.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-list.json
index 9315c7a4098c..3e0bf431154d 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-list.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-list.json
@@ -22,6 +22,11 @@
"maximum": 1000,
"type": "number"
},
+ "needs_improvement": {
+ "default": false,
+ "description": "Only list prompts that the engines answered in the last 30 days without citing a target domain. Prompts with no answered check in that window are left out.",
+ "type": "boolean"
+ },
"offset": {
"description": "The initial index from which to return the results.",
"type": "number"
diff --git a/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-update.json b/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-update.json
index d04887950173..7066b5d9bf6f 100644
--- a/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-update.json
+++ b/services/mcp/tests/unit/__snapshots__/tool-schemas/aeo-prompts-update.json
@@ -41,7 +41,7 @@
},
"prompt": {
"description": "New text for the prompt. A change adds the next version and makes it current; the prompt keeps its id and its check history, and each check records the version that ran. A change of case or whitespace only adds no version. Fails with 409 when another prompt in the set already has the text.",
- "maxLength": 10000,
+ "maxLength": 2000,
"type": "string"
},
"topic": {