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.

fix(web-analytics): show real draft status in content autopilot (#122206)

Jordan Mryyan7bcbca46d7aa
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index e978a748dd03..f5c4592e76ef 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -8131,13 +8131,13 @@ snapshots:
products-web-analytics-content-autopilot-workspace--proposal-review--light:
hash: v1.k794b7964.2938125cbd36f0d51e7a4e7b950075b59aa92b0f97e43e63306203b8de2191d0.NCk1bEMPM1vhBXP28nupt9KUqiS0quEHSS_g9r2tVP0
products-web-analytics-content-autopilot-workspace--ready-for-review--dark:
- hash: v1.k794b7964.09962247e2a75af3c3a860dffa00b2147f64818d7ec9b239643ef148b74c2040.eAiKB6udmL05meYW4y7T5pyMlHlCVBtp7_gvGZzeRUc
+ hash: v1.k794b7964.9d67b5b685b1d4ced1845a09df5b3a89e17f4ae80f91971456cd174467e6aa9c.GQiQePjuNPhJQ8jjasQfa4zEZYuh0a2LAdnnJKTZsnw
products-web-analytics-content-autopilot-workspace--ready-for-review--light:
- hash: v1.k794b7964.1585d95a6cf144524c72dee9425e4192bd5a7f57ca1efdf90f493411446bd4c6.CXyy2bM9ZICsNRXcpZYV5Y36zVMZ1rUD1zlybNCNWeI
+ hash: v1.k794b7964.92a6d99472801cbf2964b844296986c59ab8e714169137d9c8840a779e519e9f.R7JiT8G2yDulVi35X7PA0UEk5hkE9cfJdf1P_f7RnqI
products-web-analytics-content-autopilot-workspace--site-settings--dark:
- hash: v1.k794b7964.fc4421d5eb2f507adff62378c528a85f0d2afda601f5c64c427c01f8be0017e6.CwCi0RyySiohuekOKlnZxKFInJdQLJTSVx3upnSWs_g
+ hash: v1.k794b7964.ef6a9704812bc76a12ca6b481ecef3e6b7b3d39e1d209acb6942cb02307ea0a3.dWi69rA8aBffIyTlnxQEkEsu0r1orX8DYTR62VXkTbg
products-web-analytics-content-autopilot-workspace--site-settings--light:
- hash: v1.k794b7964.db7571e09c46c966f50fb87b8b34511803d4aef56c41faa405c2db039f17fa43.PUpkT3j7DpGmhBztUzWMk0vKk_5cA4nMK6WztMyXBRE
+ hash: v1.k794b7964.0020f51589c9f1a5b4f14e50b33ba860d8c51e1ea6e7e8f650c7ed58cfa8662c.tRt5_28dokxfGdbahEK1gNaxWNp7kQe9AoKdhThnZXU
products-web-analytics-heatmaps-page-history-tile--captured--dark:
hash: v1.k794b7964.f413577b9b77e5609dfd55b0d14582561ff63365e2f0f2fcbe3d8ece4c13002a.3l1GQMU3xn1wph28KJq3vuY3Z0Lg-FEpiDNug82yI68
products-web-analytics-heatmaps-page-history-tile--captured--light:
diff --git a/products/web_analytics/backend/presentation/views/content_autopilot.py b/products/web_analytics/backend/presentation/views/content_autopilot.py
index ad4f11acbe72..a7e37c15b939 100644
--- a/products/web_analytics/backend/presentation/views/content_autopilot.py
+++ b/products/web_analytics/backend/presentation/views/content_autopilot.py
@@ -470,10 +470,12 @@ class ContentAutopilotProposalListSerializer(ContentAutopilotProposalBaseSeriali
"evidence",
"validation_report",
"file_path",
+ "target_url",
"created_at",
"updated_at",
]
read_only_fields = fields
+ extra_kwargs = {"target_url": {"help_text": "Existing or intended public URL."}}
@extend_schema_field(serializers.CharField)
def get_file_path(self, proposal: ContentAutopilotProposal) -> str:
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx
index 2bae6c6c65e6..a5f4bc50256e 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilot.stories.tsx
@@ -16,6 +16,8 @@ import { ContentAutopilot } from './ContentAutopilot'
import { type ContentAutopilotProposalTab, contentAutopilotLogic } from './contentAutopilotLogic'
import { ContentAutopilotSetup } from './ContentAutopilotSetup'
import {
+ EXAMPLE_FAILED_DRAFT_OPPORTUNITY,
+ EXAMPLE_FAILED_PROPOSAL_LIST,
EXAMPLE_OPPORTUNITIES,
EXAMPLE_PROFILE,
EXAMPLE_PROPOSAL,
@@ -117,8 +119,8 @@ ReadyForReview.decorators = [
workspaceHandlers({
profiles: [EXAMPLE_PROFILE],
runs: [EXAMPLE_RUN],
- proposals: [EXAMPLE_PROPOSAL_LIST],
- opportunities: EXAMPLE_OPPORTUNITIES,
+ proposals: [EXAMPLE_PROPOSAL_LIST, EXAMPLE_FAILED_PROPOSAL_LIST],
+ opportunities: [...EXAMPLE_OPPORTUNITIES, EXAMPLE_FAILED_DRAFT_OPPORTUNITY],
}),
]
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDrafts.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDrafts.tsx
index 311a294c9f81..fbfd31137f48 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDrafts.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotDrafts.tsx
@@ -1,37 +1,11 @@
import { useActions, useValues } from 'kea'
-import { LemonButton, LemonCard, LemonTable, LemonTag, Spinner } from '@posthog/lemon-ui'
+import { LemonButton, LemonCard, LemonTable, LemonTag } from '@posthog/lemon-ui'
import { TZLabel } from 'lib/components/TZLabel'
-import type { ContentAutopilotProposalListApi } from 'products/web_analytics/frontend/generated/api.schemas'
-
import { contentAutopilotLogic } from './contentAutopilotLogic'
-
-const proposalStatusTag = (proposal: ContentAutopilotProposalListApi): JSX.Element => {
- switch (proposal.lifecycle_status) {
- case 'ready_for_review':
- return <LemonTag type="success">Ready to review</LemonTag>
- case 'generating':
- return (
- <LemonTag type="completion" icon={<Spinner />}>
- Drafting
- </LemonTag>
- )
- case 'exported':
- return <LemonTag type="default">Downloaded</LemonTag>
- case 'rejected':
- return <LemonTag type="muted">Rejected</LemonTag>
- case 'failed':
- return proposal.validation_report.checks.some(
- ({ check_key, passed }) => check_key === 'generation' && !passed
- ) ? (
- <LemonTag type="danger">Couldn't draft</LemonTag>
- ) : (
- <LemonTag type="warning">Needs fixes</LemonTag>
- )
- }
-}
+import { ContentAutopilotProposalStatusTag } from './ContentAutopilotProposalStatusTag'
export const ContentAutopilotDrafts = (): JSX.Element | null => {
const { draftRows, workspaceErrors } = useValues(contentAutopilotLogic)
@@ -89,7 +63,11 @@ export const ContentAutopilotDrafts = (): JSX.Element | null => {
title: 'Status',
key: 'status',
render: (_, row) =>
- row.proposal ? proposalStatusTag(row.proposal) : <LemonTag type="muted">Queued</LemonTag>,
+ row.proposal ? (
+ <ContentAutopilotProposalStatusTag proposal={row.proposal} />
+ ) : (
+ <LemonTag type="muted">Queued</LemonTag>
+ ),
},
{
title: 'Updated',
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotOpportunities.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotOpportunities.tsx
index a156f59c0d38..c0b56977c6ed 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotOpportunities.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotOpportunities.tsx
@@ -11,16 +11,17 @@ import {
LemonSwitch,
LemonTable,
LemonTag,
- Link,
Spinner,
} from '@posthog/lemon-ui'
import { pluralize } from 'lib/utils/strings'
-import { faviconUrl, parseWebAnalyticsURL } from 'scenes/web-analytics/common'
+import { faviconUrl } from 'scenes/web-analytics/common'
import type { ContentAutopilotOpportunityApi } from 'products/web_analytics/frontend/generated/api.schemas'
import { MAX_DRAFTS_PER_RUN, contentAutopilotLogic } from './contentAutopilotLogic'
+import { ContentAutopilotPageToUpdate } from './ContentAutopilotPageToUpdate'
+import { ContentAutopilotProposalStatusTag } from './ContentAutopilotProposalStatusTag'
const ENGINE_LABELS: Record<string, string> = {
'claude-web-search': 'Claude',
@@ -66,6 +67,8 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
runMutationLoading,
dismissingOpportunityId,
opportunitySearch,
+ opportunityProposals,
+ pagesToUpdate,
} = useValues(contentAutopilotLogic)
const {
refreshOpportunities,
@@ -191,12 +194,19 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
{
title: 'Question',
key: 'title',
- render: (_, opportunity) => (
- <div className="flex flex-wrap items-center gap-2 py-2 min-w-60">
- <span className="font-semibold">{opportunity.title}</span>
- {STATUS_TAGS[opportunity.status]}
- </div>
- ),
+ render: (_, opportunity) => {
+ const proposal = opportunityProposals[opportunity.id]
+ return (
+ <div className="flex flex-wrap items-center gap-2 py-2 min-w-60">
+ <span className="font-semibold">{opportunity.title}</span>
+ {opportunity.status === 'drafted' && proposal ? (
+ <ContentAutopilotProposalStatusTag proposal={proposal} />
+ ) : (
+ STATUS_TAGS[opportunity.status]
+ )}
+ </div>
+ )
+ },
},
{
title: 'In AI answers',
@@ -239,22 +249,17 @@ export const ContentAutopilotOpportunities = (): JSX.Element => {
{
title: 'Page to update',
key: 'recommendation',
- render: (_, opportunity) =>
- opportunity.recommended_type === 'page_improvement' && opportunity.target_url ? (
- <span className="text-sm">
- Update{' '}
- <Link to={opportunity.target_url} target="_blank">
- {parseWebAnalyticsURL(opportunity.target_url).pathname ??
- opportunity.target_url}
- </Link>
- </span>
- ) : null,
+ render: (_, opportunity) => (
+ <ContentAutopilotPageToUpdate page={pagesToUpdate[opportunity.id] ?? null} />
+ ),
},
{
key: 'actions',
render: (_, opportunity) => (
- <div className="flex flex-wrap justify-end gap-1">
- {opportunity.proposal_id && opportunity.status === 'drafted' ? (
+ <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"
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPageToUpdate.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPageToUpdate.tsx
new file mode 100644
index 000000000000..e21dfd75e891
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotPageToUpdate.tsx
@@ -0,0 +1,29 @@
+import { Link } from '@posthog/lemon-ui'
+
+import stringWithWBR from 'lib/utils/stringWithWBR'
+
+import type { ContentAutopilotPageTarget } from './utils'
+
+const breakablePath = (path: string): JSX.Element =>
+ path.startsWith('/') && path.length > 1 ? <>/{stringWithWBR(path.slice(1))}</> : stringWithWBR(path)
+
+export const ContentAutopilotPageToUpdate = ({ page }: { page: ContentAutopilotPageTarget | null }): JSX.Element => {
+ if (!page) {
+ return <span className="text-sm text-muted">Picked when drafting</span>
+ }
+ if (page.isNewPage) {
+ return (
+ <span className="text-sm">
+ New page <span className="text-muted break-words">{breakablePath(page.path)}</span>
+ </span>
+ )
+ }
+ return (
+ <span className="text-sm">
+ Update{' '}
+ <Link to={page.url} target="_blank" className="break-words">
+ {breakablePath(page.path)}
+ </Link>
+ </span>
+ )
+}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotProposalStatusTag.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotProposalStatusTag.tsx
new file mode 100644
index 000000000000..b7885b3a45a7
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotProposalStatusTag.tsx
@@ -0,0 +1,32 @@
+import { LemonTag, Spinner } from '@posthog/lemon-ui'
+
+import type { ContentAutopilotProposalListApi } from 'products/web_analytics/frontend/generated/api.schemas'
+
+export const ContentAutopilotProposalStatusTag = ({
+ proposal,
+}: {
+ proposal: ContentAutopilotProposalListApi
+}): JSX.Element => {
+ switch (proposal.lifecycle_status) {
+ case 'ready_for_review':
+ return <LemonTag type="success">Ready to review</LemonTag>
+ case 'generating':
+ return (
+ <LemonTag type="completion" icon={<Spinner />}>
+ Drafting
+ </LemonTag>
+ )
+ case 'exported':
+ return <LemonTag type="default">Downloaded</LemonTag>
+ case 'rejected':
+ return <LemonTag type="muted">Rejected</LemonTag>
+ case 'failed':
+ return proposal.validation_report.checks.some(
+ ({ check_key, passed }) => check_key === 'generation' && !passed
+ ) ? (
+ <LemonTag type="danger">Couldn't draft</LemonTag>
+ ) : (
+ <LemonTag type="warning">Needs fixes</LemonTag>
+ )
+ }
+}
diff --git a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceFields.tsx b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceFields.tsx
index 2b5ffe36cf0b..fc18d4a5f9fe 100644
--- a/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceFields.tsx
+++ b/products/web_analytics/frontend/contentAutopilot/ContentAutopilotSourceFields.tsx
@@ -1,6 +1,6 @@
import { useActions } from 'kea'
-import { LemonCheckbox, LemonTextArea } from '@posthog/lemon-ui'
+import { LemonTextArea } from '@posthog/lemon-ui'
import { LemonField } from 'lib/lemon-ui/LemonField'
@@ -28,11 +28,6 @@ export const ContentAutopilotSourceFields = ({ draft }: { draft: ContentAutopilo
minRows={4}
/>
</LemonField.Pure>
- <LemonCheckbox
- checked={draft.searchConsoleEnabled}
- onChange={(searchConsoleEnabled) => setProfileDraft({ searchConsoleEnabled })}
- label="Use connected Google Search Console data"
- />
</div>
)
}
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts
index 32522fdb3eb3..c67c97e47f63 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.test.ts
@@ -159,6 +159,26 @@ describe('contentAutopilotLogic', () => {
expect(logic.values.opportunities).toEqual(EXAMPLE_OPPORTUNITIES)
})
+ it('skips the refresh on open when the citation data was read in the last hour, but not after a settings save', async () => {
+ const freshOpportunities = EXAMPLE_OPPORTUNITIES.map((opportunity) => ({
+ ...opportunity,
+ last_refreshed_at: new Date(Date.now() - 5 * 60 * 1000).toISOString(),
+ }))
+ jest.mocked(webAnalyticsContentAutopilotOpportunitiesList).mockResolvedValue(paginated(freshOpportunities))
+
+ const mountedLogic = await mountWorkspace()
+
+ expect(mountedLogic.values.opportunities).toEqual(freshOpportunities)
+ expect(mockOpportunitiesRefresh).not.toHaveBeenCalled()
+
+ await expectLogic(mountedLogic, () => mountedLogic.actions.saveProfile()).toDispatchActions([
+ 'saveProfileSuccess',
+ 'loadOpportunitiesSuccess',
+ 'refreshOpportunities',
+ ])
+ expect(mockOpportunitiesRefresh).toHaveBeenCalledTimes(1)
+ })
+
it('drafts only the selected opportunities for the current site and clears the selection', async () => {
const mountedLogic = await mountWorkspace()
const [first, second] = EXAMPLE_OPPORTUNITIES
@@ -215,7 +235,6 @@ describe('contentAutopilotLogic', () => {
sourceUrls: 'https://blog.example.com/sitemap.xml',
contentBoundaries: '/blog',
brandRules: 'Use sentence case',
- searchConsoleEnabled: false,
})
await expectLogic(mountedLogic, () => mountedLogic.actions.saveProfile()).toFinishAllListeners()
@@ -226,7 +245,6 @@ describe('contentAutopilotLogic', () => {
source_urls: ['https://blog.example.com/sitemap.xml'],
content_boundaries: ['/blog'],
brand_rules: ['Use sentence case'],
- search_console_enabled: false,
})
})
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts
index fd3cec7fb5c5..61a286c160f5 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotLogic.ts
@@ -19,6 +19,8 @@ import type {
} from 'products/web_analytics/frontend/generated/api.schemas'
import { webAnalyticsContentAutopilotOpportunitiesDraftBodyOpportunityIdsMax } from 'products/web_analytics/frontend/generated/api.zod'
+import { ContentAutopilotPageTarget, opportunitiesNeedRefresh, pageToUpdate, proposalPagePath } from './utils'
+
export type ContentAutopilotOnboardingStep = 'site' | 'sources'
export type ContentAutopilotProposalTab = 'preview' | 'draft' | 'changes' | 'brief' | 'sources'
@@ -61,7 +63,6 @@ export interface ContentAutopilotProfileDraft {
sourceUrls: string
contentBoundaries: string
brandRules: string
- searchConsoleEnabled: boolean
}
const EMPTY_PROFILE_DRAFT: ContentAutopilotProfileDraft = {
@@ -70,7 +71,6 @@ const EMPTY_PROFILE_DRAFT: ContentAutopilotProfileDraft = {
sourceUrls: '',
contentBoundaries: '/',
brandRules: '',
- searchConsoleEnabled: true,
}
const WORKSPACE_POLL_INTERVAL_MS = 10_000
@@ -137,7 +137,6 @@ const draftFromProfile = (profile: ContentAutopilotSiteProfileApi): ContentAutop
sourceUrls: profile.source_urls.join('\n'),
contentBoundaries: profile.content_boundaries.join('\n'),
brandRules: profile.brand_rules.join('\n'),
- searchConsoleEnabled: profile.search_console_enabled ?? true,
})
const getErrorMessage = (error: unknown): string => {
@@ -178,7 +177,9 @@ export interface contentAutopilotLogicValues {
opportunities: ContentAutopilotOpportunityApi[] | null
opportunitiesError: string | null
opportunitiesLoading: boolean
+ opportunityProposals: Record<string, ContentAutopilotProposalListApi>
opportunitySearch: string
+ pagesToUpdate: Record<string, ContentAutopilotPageTarget | null>
profile: ContentAutopilotSiteProfileApi | null
profileDataLoaded: boolean
profileDataSettled: ContentAutopilotProfileDataSettled
@@ -569,6 +570,14 @@ export interface contentAutopilotLogicMeta {
selectedProposal: ContentAutopilotProposalApi | null,
proposedMarkdown: string
) => boolean
+ opportunityProposals: (
+ opportunities: ContentAutopilotOpportunityApi[] | null,
+ siteProposals: ContentAutopilotProposalListApi[]
+ ) => Record<string, ContentAutopilotProposalListApi>
+ pagesToUpdate: (
+ opportunities: ContentAutopilotOpportunityApi[] | null,
+ opportunityProposals: Record<string, ContentAutopilotProposalListApi>
+ ) => Record<string, ContentAutopilotPageTarget | null>
readyDraftCount: (siteProposals: ContentAutopilotProposalListApi[]) => number
draftRows: (
siteProposals: ContentAutopilotProposalListApi[],
@@ -909,7 +918,6 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
source_urls: splitLines(values.profileDraft.sourceUrls),
content_boundaries: splitLines(values.profileDraft.contentBoundaries),
brand_rules: splitLines(values.profileDraft.brandRules),
- search_console_enabled: values.profileDraft.searchConsoleEnabled,
}
const profile = values.onboardingOpen ? null : values.profile
if (profile) {
@@ -1063,6 +1071,36 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
(selectedProposal: ContentAutopilotProposalApi | null, proposedMarkdown: string): boolean =>
selectedProposal !== null && proposedMarkdown !== selectedProposal.proposed_markdown,
],
+ opportunityProposals: [
+ (selectors) => [selectors.opportunities, selectors.siteProposals],
+ (
+ opportunities: ContentAutopilotOpportunityApi[] | null,
+ proposals: ContentAutopilotProposalListApi[]
+ ): Record<string, ContentAutopilotProposalListApi> => {
+ const proposalsById = new Map(proposals.map((proposal) => [proposal.id, proposal]))
+ return Object.fromEntries(
+ (opportunities ?? []).flatMap((opportunity) => {
+ const proposal = opportunity.proposal_id
+ ? proposalsById.get(opportunity.proposal_id)
+ : undefined
+ return proposal ? [[opportunity.id, proposal]] : []
+ })
+ )
+ },
+ ],
+ pagesToUpdate: [
+ (selectors) => [selectors.opportunities, selectors.opportunityProposals],
+ (
+ opportunities: ContentAutopilotOpportunityApi[] | null,
+ opportunityProposals: Record<string, ContentAutopilotProposalListApi>
+ ): Record<string, ContentAutopilotPageTarget | null> =>
+ Object.fromEntries(
+ (opportunities ?? []).map((opportunity) => [
+ opportunity.id,
+ pageToUpdate(opportunity, opportunityProposals[opportunity.id]),
+ ])
+ ),
+ ],
readyDraftCount: [
(selectors) => [selectors.siteProposals],
(proposals: ContentAutopilotProposalListApi[]): number =>
@@ -1083,7 +1121,7 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
title: proposal.title,
question: proposal.target_query,
isNewPage: proposal.proposal_type === 'new_content',
- path: proposal.file_path ? `/${proposal.file_path.replace(/\.mdx?$/, '')}` : '',
+ path: proposalPagePath(proposal),
updatedAt: proposal.updated_at,
proposal,
})
@@ -1252,10 +1290,14 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
cache.refreshOpportunitiesAfterLoad = true
actions.loadOpportunities()
},
- loadOpportunitiesSuccess: () => {
+ loadOpportunitiesSuccess: ({ opportunities }) => {
if (cache.refreshOpportunitiesAfterLoad) {
+ const profileChanged = cache.profileChanged
cache.refreshOpportunitiesAfterLoad = false
- actions.refreshOpportunities()
+ cache.profileChanged = false
+ if (profileChanged || opportunitiesNeedRefresh(opportunities, Date.now())) {
+ actions.refreshOpportunities()
+ }
}
},
loadSiteProfilesSuccess: () => {
@@ -1300,6 +1342,7 @@ export const contentAutopilotLogic = kea<contentAutopilotLogicType>([
saveProfileSuccess: ({ savedProfile }) => {
lemonToast.success('Site profile saved')
actions.resetProfileDraft(draftFromProfile(savedProfile))
+ cache.profileChanged = true
actions.loadSiteProfiles()
},
saveProfileFailure: ({ errorObject }) => {
diff --git a/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts b/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts
index d9c4ed680bdd..39df2dc83f73 100644
--- a/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts
+++ b/products/web_analytics/frontend/contentAutopilot/contentAutopilotStoryFixtures.ts
@@ -142,6 +142,7 @@ export const EXAMPLE_PROPOSAL_LIST: ContentAutopilotProposalListApi = {
evidence: EXAMPLE_PROPOSAL.evidence,
validation_report: EXAMPLE_PROPOSAL.validation_report,
file_path: EXAMPLE_PROPOSAL.content_package.file_path,
+ target_url: EXAMPLE_PROPOSAL.target_url,
created_at: EXAMPLE_PROPOSAL.created_at,
updated_at: EXAMPLE_PROPOSAL.updated_at,
}
@@ -197,3 +198,36 @@ export const EXAMPLE_OPPORTUNITIES: ContentAutopilotOpportunityApi[] = [
updated_at: '2026-08-26T12:00:00Z',
},
]
+
+export const EXAMPLE_FAILED_PROPOSAL_LIST: ContentAutopilotProposalListApi = {
+ ...EXAMPLE_PROPOSAL_LIST,
+ id: '00000000-0000-4000-8000-000000000213',
+ lifecycle_status: 'failed',
+ title: 'Track AI crawler traffic',
+ target_query: 'How do I track AI crawler traffic on my website?',
+ file_path: 'docs/web-analytics/ai-crawlers.md',
+ target_url: 'https://docs.example.com/docs/web-analytics/ai-crawlers',
+ validation_report: {
+ ...EXAMPLE_PROPOSAL.validation_report,
+ passed: false,
+ checks: [
+ ...EXAMPLE_PROPOSAL.validation_report.checks,
+ {
+ check_key: 'grounding',
+ label: 'Sourced facts',
+ passed: false,
+ message: 'These claims aren\'t backed by a source: "Crawler visits never count toward pageviews."',
+ blocking: true,
+ },
+ ],
+ },
+}
+
+export const EXAMPLE_FAILED_DRAFT_OPPORTUNITY: ContentAutopilotOpportunityApi = {
+ ...EXAMPLE_OPPORTUNITIES[0],
+ id: '00000000-0000-4000-8000-000000000303',
+ proposal_id: EXAMPLE_FAILED_PROPOSAL_LIST.id,
+ 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.ts b/products/web_analytics/frontend/contentAutopilot/utils.ts
new file mode 100644
index 000000000000..84e5e39d224f
--- /dev/null
+++ b/products/web_analytics/frontend/contentAutopilot/utils.ts
@@ -0,0 +1,49 @@
+import { parseWebAnalyticsURL } from 'scenes/web-analytics/common'
+
+import type {
+ ContentAutopilotOpportunityApi,
+ ContentAutopilotProposalListApi,
+} from 'products/web_analytics/frontend/generated/api.schemas'
+
+const OPPORTUNITIES_STALE_AFTER_MS = 60 * 60 * 1000
+
+export type ContentAutopilotPageTarget =
+ | { isNewPage: true; path: string }
+ | { isNewPage: false; path: string; url: string }
+
+export const proposalPagePath = (proposal: Pick<ContentAutopilotProposalListApi, 'file_path' | 'target_url'>): string =>
+ (proposal.target_url && parseWebAnalyticsURL(proposal.target_url).pathname) ||
+ (proposal.file_path ? `/${proposal.file_path.replace(/\.mdx?$/, '')}` : '')
+
+export const pageToUpdate = (
+ opportunity: Pick<ContentAutopilotOpportunityApi, 'recommended_type' | 'target_url'>,
+ proposal: ContentAutopilotProposalListApi | undefined
+): ContentAutopilotPageTarget | null => {
+ if (proposal && proposal.lifecycle_status !== 'generating') {
+ const path = proposalPagePath(proposal)
+ if (proposal.proposal_type === 'new_content' && path) {
+ return { isNewPage: true, path }
+ }
+ if (proposal.proposal_type !== 'new_content' && proposal.target_url) {
+ return { isNewPage: false, path, url: proposal.target_url }
+ }
+ }
+ if (opportunity.recommended_type === 'page_improvement' && opportunity.target_url) {
+ return {
+ isNewPage: false,
+ path: parseWebAnalyticsURL(opportunity.target_url).pathname ?? opportunity.target_url,
+ url: opportunity.target_url,
+ }
+ }
+ return null
+}
+
+export const opportunitiesNeedRefresh = (
+ opportunities: Pick<ContentAutopilotOpportunityApi, 'last_refreshed_at'>[],
+ now: number
+): boolean => {
+ const refreshedAt = opportunities
+ .map(({ last_refreshed_at }) => Date.parse(last_refreshed_at))
+ .filter((time) => !Number.isNaN(time))
+ return refreshedAt.length === 0 || now - Math.max(...refreshedAt) > OPPORTUNITIES_STALE_AFTER_MS
+}
diff --git a/products/web_analytics/frontend/generated/api.schemas.ts b/products/web_analytics/frontend/generated/api.schemas.ts
index 3b88492df61d..6b3736184a39 100644
--- a/products/web_analytics/frontend/generated/api.schemas.ts
+++ b/products/web_analytics/frontend/generated/api.schemas.ts
@@ -1450,6 +1450,8 @@ export interface ContentAutopilotProposalListApi {
validation_report: ContentAutopilotValidationReportApi
/** Repository-relative export path. */
readonly file_path: string
+ /** Existing or intended public URL. */
+ readonly target_url: string
readonly created_at: string
readonly updated_at: string
}
diff --git a/services/mcp/src/api/generated.ts b/services/mcp/src/api/generated.ts
index 72340f0c20a1..85398b7d1e9b 100644
--- a/services/mcp/src/api/generated.ts
+++ b/services/mcp/src/api/generated.ts
@@ -25289,6 +25289,8 @@ export namespace Schemas {
validation_report: ContentAutopilotValidationReport;
/** Repository-relative export path. */
readonly file_path: string;
+ /** Existing or intended public URL. */
+ readonly target_url: string;
readonly created_at: string;
readonly updated_at: string;
}