Skip to content

Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.

feat(content): weigh a page's conversions from AI journeys in the Content Plan's Priority Score (00291) (#1557)

Cihan2e8e8f12473b
diff --git a/docs/guides/content-editor.mdx b/docs/guides/content-editor.mdx
index c1508f695..034a4bd66 100644
--- a/docs/guides/content-editor.mdx
+++ b/docs/guides/content-editor.mdx
@@ -50,7 +50,7 @@ The score runs from 0 to 100 and is built from four factors:
- **Severity**: how urgent the row is. A page losing citations counts most, more so the bigger the drop or the more citations it lost. Then come a new page AI needs, an existing page to improve, and a page to protect.
- **Opportunity**: the score of the content opportunity behind the row. A row without one counts as neutral.
-- **Page value**: the page's AI visits in the period. A new page, or a brand with no AI traffic data, counts as neutral rather than zero.
+- **Page value**: the page's AI visits in the period. With conversions on, once the listed pages have some, it also weighs the conversions from AI journeys through the page, more as they come in. A new page, or a brand with no AI traffic data, counts as neutral rather than zero.
- **Citations**: how often AI answers cited the page in the period. A new page has none yet.
Hover over the score, or focus it, to see **How this score is worked out**: each factor with the points it gave, and the total. The badge's level (critical, high, medium or low) uses the Plan's own cut-offs, and only a page losing citations can reach critical.
diff --git a/supabase/migrations/00291_content_plan_pages_conversions.sql b/supabase/migrations/00291_content_plan_pages_conversions.sql
new file mode 100644
index 000000000..207c48ec2
--- /dev/null
+++ b/supabase/migrations/00291_content_plan_pages_conversions.sql
@@ -0,0 +1,268 @@
+-- ============================================================================
+-- 00291: content_plan_pages with each page's conversions from AI journeys
+-- ============================================================================
+-- The Content Plan's Priority Score weighs a page's value by its AI visits
+-- (#1356). With conversions on (CE-017, 00286), it weighs the conversions
+-- the page took part in too, as the editor's Live page tab counts them
+-- (00287): a conversion whose AI journey landed on the page, went through
+-- it, or converted on it, in the window, of the latest 2,000.
+--
+-- Each page of the list gets 'conversions': that count, or null for a brand
+-- with conversions off (unknown, never zero). Everything else is 00238's,
+-- with the same signature, so its grants carry over (create or replace); its
+-- comment is brought up to date below. The conversions are read only with
+-- conversions on: through 00287's partial index, then, as 00287 reads them,
+-- when each visitor id first saw each listed page, once per visitor and page
+-- on the journey index (00286), so a sender's many pageviews can't multiply
+-- the rows.
+
+create or replace function public.content_plan_pages(
+ p_brand_id uuid,
+ p_days integer default 30
+)
+returns jsonb
+language plpgsql
+stable
+security definer
+set search_path to 'public'
+-- A cached generic plan can't see the brand's size (00207).
+set plan_cache_mode to 'force_custom_plan'
+as $$
+declare
+ v_last date := (now() at time zone 'utc')::date - 1;
+ v_cur_day date;
+ v_prev_day date;
+ v_cur timestamptz;
+ v_until timestamptz;
+ v_conversions_on boolean;
+ v_result jsonb;
+begin
+ if not exists (
+ select 1 from public.brands b
+ join public.profiles pf on pf.organization_id = b.organization_id
+ where b.id = p_brand_id and pf.id = auth.uid()
+ ) and auth.role() is distinct from 'service_role' then
+ return null;
+ end if;
+ if p_days not in (7, 30, 90) then
+ raise exception 'p_days must be 7, 30 or 90';
+ end if;
+
+ v_cur_day := v_last - p_days + 1;
+ v_prev_day := v_cur_day - p_days;
+ v_cur := v_cur_day::timestamp at time zone 'utc';
+ v_until := (v_last + 1)::timestamp at time zone 'utc';
+ v_conversions_on := coalesce(
+ (select b.conversions_enabled from public.brands b where b.id = p_brand_id), false);
+
+ with own_domains as (
+ select lower(regexp_replace(bd.domain, '^www\.', '')) as domain
+ from public.brand_domains bd
+ where bd.brand_id = p_brand_id
+ ),
+ own_urls as materialized (
+ select cu.id, cu.url, cu.title, lower(public.normalize_page_path(cu.url)) as page_key
+ from public.citation_urls cu
+ where cu.domain in (select domain from own_domains)
+ ),
+ url_counts as materialized (
+ select d.url_id, d.platform, d.day >= v_cur_day as is_cur, sum(d.citations)::bigint as n
+ from public.citation_url_daily d
+ where d.brand_id = p_brand_id
+ and d.day >= v_prev_day
+ and d.day <= v_last
+ and d.url_id in (select id from own_urls)
+ and d.platform is distinct from 'chatgpt-shopping'
+ group by d.url_id, d.platform, d.day >= v_cur_day
+ ),
+ url_totals as (
+ select
+ u.page_key,
+ u.url,
+ u.title,
+ coalesce(sum(c.n) filter (where c.is_cur), 0) as cur,
+ coalesce(sum(c.n) filter (where not c.is_cur), 0) as prev
+ from url_counts c
+ join own_urls u on u.id = c.url_id
+ group by u.page_key, u.url, u.title
+ ),
+ pages as materialized (
+ select
+ t.page_key,
+ -- The address cited most often stands for the page.
+ (array_agg(t.url order by t.cur + t.prev desc, t.url))[1] as page,
+ max(t.title) as title,
+ sum(t.cur)::bigint as cur,
+ sum(t.prev)::bigint as prev
+ from url_totals t
+ group by t.page_key
+ order by sum(t.cur + t.prev) desc, t.page_key
+ limit 100
+ ),
+ answers as (
+ select
+ r.platform,
+ coalesce(sum(r.answers) filter (where r.day >= v_cur_day), 0)::bigint as cur,
+ coalesce(sum(r.answers) filter (where r.day < v_cur_day), 0)::bigint as prev
+ from public.citation_result_daily r
+ where r.brand_id = p_brand_id
+ and r.day >= v_prev_day
+ and r.day <= v_last
+ and r.platform is distinct from 'chatgpt-shopping'
+ group by r.platform
+ ),
+ per_platform as (
+ select
+ u.page_key,
+ c.platform,
+ coalesce(sum(c.n) filter (where c.is_cur), 0) as cur,
+ coalesce(sum(c.n) filter (where not c.is_cur), 0) as prev
+ from url_counts c
+ join own_urls u on u.id = c.url_id
+ where u.page_key in (select p.page_key from pages p)
+ and c.platform is not null
+ group by u.page_key, c.platform
+ ),
+ down as (
+ -- A platform tracked in both windows, citing the page at a lower rate.
+ select
+ pp.page_key,
+ array_agg(
+ pp.platform
+ order by pp.prev::numeric / a.prev - pp.cur::numeric / a.cur desc, pp.platform
+ ) as platforms
+ from per_platform pp
+ join answers a on a.platform = pp.platform
+ where a.prev > 0
+ and a.cur > 0
+ and pp.prev::numeric / a.prev > pp.cur::numeric / a.cur
+ group by pp.page_key
+ ),
+ snippet_days as (
+ select distinct (l.created_at at time zone 'utc')::date as day
+ from public.ai_traffic_logs l
+ where l.brand_id = p_brand_id
+ and l.visit_of is null
+ and l.created_at >= v_cur
+ and l.created_at < v_until
+ ),
+ visits as (
+ select lower(public.normalize_page_path(l.url)) as page_key, 1::bigint as n
+ from public.ai_traffic_logs l
+ where l.brand_id = p_brand_id
+ and l.visit_of is null
+ and l.created_at >= v_cur
+ and l.created_at < v_until
+ union all
+ select lower(public.normalize_page_path(g.landing_page)), g.sessions::bigint
+ from public.ga_ai_traffic_stats g
+ where g.brand_id = p_brand_id
+ and g.sessions > 0
+ -- A session without a landing page would read as the home page.
+ and g.landing_page <> ''
+ and g.date >= v_cur_day
+ and g.date <= v_last
+ and not exists (select 1 from snippet_days s where s.day = g.date)
+ ),
+ page_visits as (
+ select v.page_key, sum(v.n) as visits
+ from visits v
+ where v.page_key in (select p.page_key from pages p)
+ group by v.page_key
+ ),
+ -- Conversions from AI journeys in the window, with conversions on (00286):
+ -- the latest 2,000, as 00287 and 00288 bound their journeys, through 00287's
+ -- partial index (brand_id, occurred_at desc), so the read stops there. The
+ -- score counts 20 in full; past 2,000, a page's count is of the latest.
+ conversions as materialized (
+ select c.id, c.visitor_id, c.first_key, c.page_key, c.first_at, c.occurred_at
+ from public.ai_traffic_events c
+ where v_conversions_on
+ and c.brand_id = p_brand_id
+ and c.kind = 'conversion'
+ and c.occurred_at >= v_cur
+ and c.occurred_at < v_until
+ order by c.occurred_at desc
+ limit 2000
+ ),
+ -- When each visitor id first saw each listed page, from a day before its
+ -- first AI visit to its last conversion: 00287's `seen`, for every listed
+ -- page at once (the journey index), one row per visitor and page.
+ seen as (
+ select e.visitor_id, e.page_key, min(e.occurred_at) as at
+ from (
+ select visitor_id, min(first_at) - interval '1 day' as since, max(occurred_at) as last_at
+ from conversions
+ group by visitor_id
+ ) v
+ join public.ai_traffic_events e
+ on e.brand_id = p_brand_id
+ and e.visitor_id = v.visitor_id
+ and e.kind = 'page'
+ and e.occurred_at >= v.since
+ and e.occurred_at <= v.last_at
+ where e.page_key in (select p.page_key from pages p)
+ group by e.visitor_id, e.page_key
+ ),
+ -- A conversion counts for each page its journey landed on, went through
+ -- or converted on: the Live page tab's count (00287), once per page.
+ touched as (
+ select c.id, c.first_key as page_key from conversions c
+ union
+ select c.id, c.page_key from conversions c
+ union
+ select c.id, s.page_key
+ from conversions c
+ join seen s
+ on s.visitor_id = c.visitor_id
+ and s.at <= c.occurred_at
+ and s.at >= c.first_at - interval '1 day'
+ ),
+ page_conversions as (
+ select t.page_key, count(*)::bigint as n
+ from touched t
+ where t.page_key in (select p.page_key from pages p)
+ group by t.page_key
+ )
+ select jsonb_build_object(
+ 'days', p_days,
+ -- The earlier window's first day, and the brand's first tracked day: a
+ -- window before it is only partly tracked, or not at all.
+ 'prevFrom', v_prev_day,
+ 'trackedSince', (
+ select min(r.day) from public.citation_result_daily r where r.brand_id = p_brand_id
+ ),
+ 'answers', (
+ select jsonb_build_object(
+ 'cur', coalesce(sum(a.cur), 0),
+ 'prev', coalesce(sum(a.prev), 0)
+ )
+ from answers a
+ ),
+ 'pages', coalesce((
+ select jsonb_agg(
+ jsonb_build_object(
+ 'page', p.page,
+ 'title', p.title,
+ 'citations', jsonb_build_object('cur', p.cur, 'prev', p.prev),
+ 'platformsDown', coalesce(to_jsonb(d.platforms[1:3]), '[]'::jsonb),
+ 'aiVisits', coalesce(pv.visits, 0),
+ -- Null with conversions off: unknown, never zero.
+ 'conversions', case when v_conversions_on then coalesce(pc.n, 0) end
+ )
+ order by p.cur + p.prev desc, p.page
+ )
+ from pages p
+ left join down d on d.page_key = p.page_key
+ left join page_visits pv on pv.page_key = p.page_key
+ left join page_conversions pc on pc.page_key = p.page_key
+ ), '[]'::jsonb)
+ )
+ into v_result;
+
+ return v_result;
+end;
+$$;
+
+comment on function public.content_plan_pages(uuid, integer) is
+ 'Content Editor (CE-014): the brand''s 100 most cited pages over the last N (7, 30 or 90) whole UTC days to yesterday and the N before, from the daily rollups: citations, the brand''s answers in each window, platforms citing at a lower rate, AI visits and, with conversions on (00291), the conversions from AI journeys that landed on, went through or converted on each page, of the latest 2,000 (null with conversions off); with the earlier window''s first day and the brand''s first tracked day. Security definer with an organization check.';
diff --git a/supabase/schema.sql b/supabase/schema.sql
index edd276cca..8ac90b4ae 100644
--- a/supabase/schema.sql
+++ b/supabase/schema.sql
@@ -41159,3 +41159,275 @@ revoke all on function public.mentions_perception_live(uuid, timestamptz, timest
grant execute on function public.mentions_perception_live(uuid, timestamptz, timestamptz, text, text, uuid, text)
to service_role;
+-- ─────────────────────────────────────────────────────────────────────────
+-- migrations/00291_content_plan_pages_conversions.sql
+-- ─────────────────────────────────────────────────────────────────────────
+-- ============================================================================
+-- 00291: content_plan_pages with each page's conversions from AI journeys
+-- ============================================================================
+-- The Content Plan's Priority Score weighs a page's value by its AI visits
+-- (#1356). With conversions on (CE-017, 00286), it weighs the conversions
+-- the page took part in too, as the editor's Live page tab counts them
+-- (00287): a conversion whose AI journey landed on the page, went through
+-- it, or converted on it, in the window, of the latest 2,000.
+--
+-- Each page of the list gets 'conversions': that count, or null for a brand
+-- with conversions off (unknown, never zero). Everything else is 00238's,
+-- with the same signature, so its grants carry over (create or replace); its
+-- comment is brought up to date below. The conversions are read only with
+-- conversions on: through 00287's partial index, then, as 00287 reads them,
+-- when each visitor id first saw each listed page, once per visitor and page
+-- on the journey index (00286), so a sender's many pageviews can't multiply
+-- the rows.
+
+create or replace function public.content_plan_pages(
+ p_brand_id uuid,
+ p_days integer default 30
+)
+returns jsonb
+language plpgsql
+stable
+security definer
+set search_path to 'public'
+-- A cached generic plan can't see the brand's size (00207).
+set plan_cache_mode to 'force_custom_plan'
+as $$
+declare
+ v_last date := (now() at time zone 'utc')::date - 1;
+ v_cur_day date;
+ v_prev_day date;
+ v_cur timestamptz;
+ v_until timestamptz;
+ v_conversions_on boolean;
+ v_result jsonb;
+begin
+ if not exists (
+ select 1 from public.brands b
+ join public.profiles pf on pf.organization_id = b.organization_id
+ where b.id = p_brand_id and pf.id = auth.uid()
+ ) and auth.role() is distinct from 'service_role' then
+ return null;
+ end if;
+ if p_days not in (7, 30, 90) then
+ raise exception 'p_days must be 7, 30 or 90';
+ end if;
+
+ v_cur_day := v_last - p_days + 1;
+ v_prev_day := v_cur_day - p_days;
+ v_cur := v_cur_day::timestamp at time zone 'utc';
+ v_until := (v_last + 1)::timestamp at time zone 'utc';
+ v_conversions_on := coalesce(
+ (select b.conversions_enabled from public.brands b where b.id = p_brand_id), false);
+
+ with own_domains as (
+ select lower(regexp_replace(bd.domain, '^www\.', '')) as domain
+ from public.brand_domains bd
+ where bd.brand_id = p_brand_id
+ ),
+ own_urls as materialized (
+ select cu.id, cu.url, cu.title, lower(public.normalize_page_path(cu.url)) as page_key
+ from public.citation_urls cu
+ where cu.domain in (select domain from own_domains)
+ ),
+ url_counts as materialized (
+ select d.url_id, d.platform, d.day >= v_cur_day as is_cur, sum(d.citations)::bigint as n
+ from public.citation_url_daily d
+ where d.brand_id = p_brand_id
+ and d.day >= v_prev_day
+ and d.day <= v_last
+ and d.url_id in (select id from own_urls)
+ and d.platform is distinct from 'chatgpt-shopping'
+ group by d.url_id, d.platform, d.day >= v_cur_day
+ ),
+ url_totals as (
+ select
+ u.page_key,
+ u.url,
+ u.title,
+ coalesce(sum(c.n) filter (where c.is_cur), 0) as cur,
+ coalesce(sum(c.n) filter (where not c.is_cur), 0) as prev
+ from url_counts c
+ join own_urls u on u.id = c.url_id
+ group by u.page_key, u.url, u.title
+ ),
+ pages as materialized (
+ select
+ t.page_key,
+ -- The address cited most often stands for the page.
+ (array_agg(t.url order by t.cur + t.prev desc, t.url))[1] as page,
+ max(t.title) as title,
+ sum(t.cur)::bigint as cur,
+ sum(t.prev)::bigint as prev
+ from url_totals t
+ group by t.page_key
+ order by sum(t.cur + t.prev) desc, t.page_key
+ limit 100
+ ),
+ answers as (
+ select
+ r.platform,
+ coalesce(sum(r.answers) filter (where r.day >= v_cur_day), 0)::bigint as cur,
+ coalesce(sum(r.answers) filter (where r.day < v_cur_day), 0)::bigint as prev
+ from public.citation_result_daily r
+ where r.brand_id = p_brand_id
+ and r.day >= v_prev_day
+ and r.day <= v_last
+ and r.platform is distinct from 'chatgpt-shopping'
+ group by r.platform
+ ),
+ per_platform as (
+ select
+ u.page_key,
+ c.platform,
+ coalesce(sum(c.n) filter (where c.is_cur), 0) as cur,
+ coalesce(sum(c.n) filter (where not c.is_cur), 0) as prev
+ from url_counts c
+ join own_urls u on u.id = c.url_id
+ where u.page_key in (select p.page_key from pages p)
+ and c.platform is not null
+ group by u.page_key, c.platform
+ ),
+ down as (
+ -- A platform tracked in both windows, citing the page at a lower rate.
+ select
+ pp.page_key,
+ array_agg(
+ pp.platform
+ order by pp.prev::numeric / a.prev - pp.cur::numeric / a.cur desc, pp.platform
+ ) as platforms
+ from per_platform pp
+ join answers a on a.platform = pp.platform
+ where a.prev > 0
+ and a.cur > 0
+ and pp.prev::numeric / a.prev > pp.cur::numeric / a.cur
+ group by pp.page_key
+ ),
+ snippet_days as (
+ select distinct (l.created_at at time zone 'utc')::date as day
+ from public.ai_traffic_logs l
+ where l.brand_id = p_brand_id
+ and l.visit_of is null
+ and l.created_at >= v_cur
+ and l.created_at < v_until
+ ),
+ visits as (
+ select lower(public.normalize_page_path(l.url)) as page_key, 1::bigint as n
+ from public.ai_traffic_logs l
+ where l.brand_id = p_brand_id
+ and l.visit_of is null
+ and l.created_at >= v_cur
+ and l.created_at < v_until
+ union all
+ select lower(public.normalize_page_path(g.landing_page)), g.sessions::bigint
+ from public.ga_ai_traffic_stats g
+ where g.brand_id = p_brand_id
+ and g.sessions > 0
+ -- A session without a landing page would read as the home page.
+ and g.landing_page <> ''
+ and g.date >= v_cur_day
+ and g.date <= v_last
+ and not exists (select 1 from snippet_days s where s.day = g.date)
+ ),
+ page_visits as (
+ select v.page_key, sum(v.n) as visits
+ from visits v
+ where v.page_key in (select p.page_key from pages p)
+ group by v.page_key
+ ),
+ -- Conversions from AI journeys in the window, with conversions on (00286):
+ -- the latest 2,000, as 00287 and 00288 bound their journeys, through 00287's
+ -- partial index (brand_id, occurred_at desc), so the read stops there. The
+ -- score counts 20 in full; past 2,000, a page's count is of the latest.
+ conversions as materialized (
+ select c.id, c.visitor_id, c.first_key, c.page_key, c.first_at, c.occurred_at
+ from public.ai_traffic_events c
+ where v_conversions_on
+ and c.brand_id = p_brand_id
+ and c.kind = 'conversion'
+ and c.occurred_at >= v_cur
+ and c.occurred_at < v_until
+ order by c.occurred_at desc
+ limit 2000
+ ),
+ -- When each visitor id first saw each listed page, from a day before its
+ -- first AI visit to its last conversion: 00287's `seen`, for every listed
+ -- page at once (the journey index), one row per visitor and page.
+ seen as (
+ select e.visitor_id, e.page_key, min(e.occurred_at) as at
+ from (
+ select visitor_id, min(first_at) - interval '1 day' as since, max(occurred_at) as last_at
+ from conversions
+ group by visitor_id
+ ) v
+ join public.ai_traffic_events e
+ on e.brand_id = p_brand_id
+ and e.visitor_id = v.visitor_id
+ and e.kind = 'page'
+ and e.occurred_at >= v.since
+ and e.occurred_at <= v.last_at
+ where e.page_key in (select p.page_key from pages p)
+ group by e.visitor_id, e.page_key
+ ),
+ -- A conversion counts for each page its journey landed on, went through
+ -- or converted on: the Live page tab's count (00287), once per page.
+ touched as (
+ select c.id, c.first_key as page_key from conversions c
+ union
+ select c.id, c.page_key from conversions c
+ union
+ select c.id, s.page_key
+ from conversions c
+ join seen s
+ on s.visitor_id = c.visitor_id
+ and s.at <= c.occurred_at
+ and s.at >= c.first_at - interval '1 day'
+ ),
+ page_conversions as (
+ select t.page_key, count(*)::bigint as n
+ from touched t
+ where t.page_key in (select p.page_key from pages p)
+ group by t.page_key
+ )
+ select jsonb_build_object(
+ 'days', p_days,
+ -- The earlier window's first day, and the brand's first tracked day: a
+ -- window before it is only partly tracked, or not at all.
+ 'prevFrom', v_prev_day,
+ 'trackedSince', (
+ select min(r.day) from public.citation_result_daily r where r.brand_id = p_brand_id
+ ),
+ 'answers', (
+ select jsonb_build_object(
+ 'cur', coalesce(sum(a.cur), 0),
+ 'prev', coalesce(sum(a.prev), 0)
+ )
+ from answers a
+ ),
+ 'pages', coalesce((
+ select jsonb_agg(
+ jsonb_build_object(
+ 'page', p.page,
+ 'title', p.title,
+ 'citations', jsonb_build_object('cur', p.cur, 'prev', p.prev),
+ 'platformsDown', coalesce(to_jsonb(d.platforms[1:3]), '[]'::jsonb),
+ 'aiVisits', coalesce(pv.visits, 0),
+ -- Null with conversions off: unknown, never zero.
+ 'conversions', case when v_conversions_on then coalesce(pc.n, 0) end
+ )
+ order by p.cur + p.prev desc, p.page
+ )
+ from pages p
+ left join down d on d.page_key = p.page_key
+ left join page_visits pv on pv.page_key = p.page_key
+ left join page_conversions pc on pc.page_key = p.page_key
+ ), '[]'::jsonb)
+ )
+ into v_result;
+
+ return v_result;
+end;
+$$;
+
+comment on function public.content_plan_pages(uuid, integer) is
+ 'Content Editor (CE-014): the brand''s 100 most cited pages over the last N (7, 30 or 90) whole UTC days to yesterday and the N before, from the daily rollups: citations, the brand''s answers in each window, platforms citing at a lower rate, AI visits and, with conversions on (00291), the conversions from AI journeys that landed on, went through or converted on each page, of the latest 2,000 (null with conversions off); with the earlier window''s first day and the brand''s first tracked day. Security definer with an organization check.';
+
diff --git a/web/messages/en.json b/web/messages/en.json
index 37f05092e..63908c036 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -3328,6 +3328,7 @@
"opportunityNone": "No content opportunity behind it (neutral)",
"pageValue": {
"visits": "{visits, plural, one {# AI visit} other {# AI visits}} this period",
+ "visitsConversions": "{visits, plural, one {# AI visit} other {# AI visits}} and {conversions, plural, one {# conversion} other {# conversions}} this period",
"newPage": "A new page, no visits yet (neutral)",
"unknown": "No AI traffic data (neutral)"
},
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsx
index 2cb170ed5..2f78a940e 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-table.tsx
@@ -293,9 +293,14 @@ function ScorePartText({ part }: { part: PlanScorePart }) {
case 'opportunity':
return part.score === null ? t('opportunityNone') : t('opportunity', { score: part.score });
case 'pageValue':
- return part.reason === 'visits'
- ? t('pageValue.visits', { visits: part.visits })
- : t(`pageValue.${part.reason}`);
+ return part.reason !== 'visits'
+ ? t(`pageValue.${part.reason}`)
+ : part.conversions === null
+ ? t('pageValue.visits', { visits: part.visits })
+ : t('pageValue.visitsConversions', {
+ visits: part.visits,
+ conversions: part.conversions,
+ });
case 'citations':
return t('citations', { citations: part.citations });
}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx
index 1623c1023..e0c91ed29 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx
@@ -68,6 +68,7 @@ const page = (path: string, over: Partial<PlanPage> = {}): PlanPage => ({
citations: { cur: 2, prev: 2 },
platformsDown: [],
aiVisits: 0,
+ conversions: null,
...over,
});
const opportunity: PlanOpportunity = {
@@ -230,6 +231,21 @@ describe('the Content plan', () => {
);
});
+ it('says the conversions a page took part in, with conversions on (00291)', async () => {
+ getContentPlan.mockResolvedValue({
+ ...PLAN,
+ pages: PLAN.pages.map((p) => ({ ...p, conversions: p.aiVisits ? 3 : 0 })),
+ });
+ await renderPage();
+ const scores = [...container.querySelectorAll('tbody tr')].map((tr) => tr.children[1]);
+ // The top page, with its 42 AI visits: the third row.
+ act(() => scores[2].querySelector('button')!.focus());
+ await act(() => new Promise((resolve) => setTimeout(resolve, 400)));
+ expect(document.querySelector('[data-slot="tooltip-content"]')?.textContent).toContain(
+ '42 AI visits and 3 conversions this period',
+ );
+ });
+
it('filters the list by a card, and clears it on a second click', async () => {
await renderPage();
await act(async () => button('Protect').click());
diff --git a/web/src/lib/actions/content-plan.test.ts b/web/src/lib/actions/content-plan.test.ts
index cbceca611..b31952602 100644
--- a/web/src/lib/actions/content-plan.test.ts
+++ b/web/src/lib/actions/content-plan.test.ts
@@ -109,6 +109,8 @@ describe('getContentPlan', () => {
aiVisits: 12,
// Still in the RPC (00220); the plan no longer reads it.
overlaps: 1,
+ // With conversions on (00291).
+ conversions: 3,
},
],
};
@@ -161,6 +163,7 @@ describe('getContentPlan', () => {
citations: { cur: 4, prev: 9 },
platformsDown: ['chatgpt-web'],
aiVisits: 12,
+ conversions: 3,
},
],
answers: { cur: 120, prev: 140 },
@@ -214,6 +217,24 @@ describe('getContentPlan', () => {
]);
});
+ it('reads a page’s conversions as none with conversions off, or from a database before 00291', async () => {
+ const pageOf = (over: Record<string, unknown>) => ({
+ page: 'https://acme.example/a',
+ title: null,
+ citations: { cur: 1, prev: 1 },
+ platformsDown: [],
+ aiVisits: 2,
+ ...over,
+ });
+ rpcResult = {
+ days: 30,
+ answers: { cur: 1, prev: 1 },
+ pages: [pageOf({ conversions: null }), pageOf({}), pageOf({ conversions: 0 })],
+ };
+ const plan = await getContentPlan(BRAND, 30);
+ expect(plan!.pages.map((p) => p.conversions)).toEqual([null, null, 0]);
+ });
+
it('reads nothing of another organization’s brand, and refuses another period', async () => {
rpcResult = null;
await expect(getContentPlan(BRAND, 30)).resolves.toBeNull();
diff --git a/web/src/lib/actions/content-plan.ts b/web/src/lib/actions/content-plan.ts
index 23b5a03a0..837c8bcc2 100644
--- a/web/src/lib/actions/content-plan.ts
+++ b/web/src/lib/actions/content-plan.ts
@@ -123,6 +123,9 @@ export async function getContentPlan(
citations: { cur: Number(p.citations?.cur ?? 0), prev: Number(p.citations?.prev ?? 0) },
platformsDown: Array.isArray(p.platformsDown) ? p.platformsDown : [],
aiVisits: Number(p.aiVisits ?? 0),
+ // Null with conversions off (00291), or from a database before it.
+ conversions:
+ p.conversions === null || p.conversions === undefined ? null : Number(p.conversions),
}));
const marks = (marksRes.data ?? []).map(
diff --git a/web/src/lib/content/plan.test.ts b/web/src/lib/content/plan.test.ts
index 1dac89b2a..156f2d0cc 100644
--- a/web/src/lib/content/plan.test.ts
+++ b/web/src/lib/content/plan.test.ts
@@ -2,9 +2,13 @@ import { describe, expect, it } from 'vitest';
import {
MAX_ROWS,
buildPlan,
+ conversionsShareOf,
+ conversionsValue,
dropSeverity,
+ pageValueOf,
planPriorityLevel,
rowsFor,
+ visitsValue,
type PlanAnswers,
type PlanDraft,
type PlanMark,
@@ -24,6 +28,7 @@ const page = (path: string, over: Partial<PlanPage> = {}): PlanPage => ({
citations: { cur: 2, prev: 2 },
platformsDown: [],
aiVisits: 0,
+ conversions: null,
...over,
});
const opportunity = (id: string, over: Partial<PlanOpportunity> = {}): PlanOpportunity => ({
@@ -360,11 +365,91 @@ describe("a row's score breakdown", () => {
expect(rows.map((r) => [r.title, r.scoreParts[2], r.score])).toEqual([
[
'a',
- { kind: 'pageValue', reason: 'visits', visits: 1000, value: 1, points: 20, max: 20 },
+ {
+ kind: 'pageValue',
+ reason: 'visits',
+ visits: 1000,
+ conversions: null,
+ value: 1,
+ points: 20,
+ max: 20,
+ },
46,
],
- ['b', { kind: 'pageValue', reason: 'visits', visits: 0, value: 0, points: 0, max: 20 }, 30],
+ [
+ 'b',
+ {
+ kind: 'pageValue',
+ reason: 'visits',
+ visits: 0,
+ conversions: null,
+ value: 0,
+ points: 0,
+ max: 20,
+ },
+ 30,
+ ],
+ ]);
+ });
+
+ it('weighs the conversions a page took part in, with conversions on: 60% visits, 40% conversions once the pages have 20', () => {
+ const { rows } = plan([
+ page('/a', { citations: { cur: 18, prev: 18 }, aiVisits: 1000, conversions: 20 }),
+ page('/b', { citations: { cur: 18, prev: 18 }, aiVisits: 1000, conversions: 0 }),
+ page('/c', { citations: { cur: 18, prev: 18 }, aiVisits: 10, conversions: 20 }),
+ ]);
+ const parts = Object.fromEntries(rows.map((r) => [r.title, r.scoreParts[2]]));
+ // Visits and 20 conversions in full: the whole 20 points.
+ expect(parts.a).toEqual({
+ kind: 'pageValue',
+ reason: 'visits',
+ visits: 1000,
+ conversions: 20,
+ value: 1,
+ points: 20,
+ max: 20,
+ });
+ // The same visits, none converting: 60% of the value.
+ expect(parts.b).toMatchObject({ conversions: 0, value: 0.6, points: 12 });
+ // Few visits, many conversions: the conversions lift it.
+ expect(parts.c.points).toBe(12.2);
+ expect(pageValueOf(10, null)).toBeCloseTo(visitsValue(10));
+ expect(conversionsValue(20)).toBe(1);
+ expect(conversionsValue(0)).toBe(0);
+ });
+
+ it('weighs conversions only once some page has any, and reads them as traffic data', () => {
+ // Turned on, none yet in the window: visits alone, as before.
+ const none = plan([
+ page('/a', { citations: { cur: 18, prev: 18 }, aiVisits: 1000, conversions: 0 }),
+ ]);
+ expect(none.rows[0].scoreParts[2]).toMatchObject({ conversions: null, value: 1, points: 20 });
+ // Conversions but no AI visit on any page: still data, not unknown.
+ const converting = plan([
+ page('/a', { citations: { cur: 18, prev: 18 }, aiVisits: 0, conversions: 5 }),
+ ]);
+ expect(converting.rows[0].scoreParts[2]).toMatchObject({
+ reason: 'visits',
+ visits: 0,
+ conversions: 5,
+ });
+ });
+
+ it('weighs conversions more as the listed pages have more, in full at 20', () => {
+ // One conversion: a 2% share, so no row moves by more than 0.4 points.
+ const one = plan([
+ page('/a', { citations: { cur: 18, prev: 18 }, aiVisits: 1000, conversions: 0 }),
+ page('/b', { citations: { cur: 18, prev: 18 }, aiVisits: 1000, conversions: 1 }),
]);
+ const parts = Object.fromEntries(one.rows.map((r) => [r.title, r.scoreParts[2]]));
+ expect(parts.a).toMatchObject({ conversions: 0, points: 19.6 });
+ expect(parts.b).toMatchObject({ conversions: 1, points: 19.7 });
+ expect(conversionsShareOf([page('/a')])).toBe(0);
+ expect(conversionsShareOf([page('/a', { conversions: 1 })])).toBeCloseTo(0.02);
+ expect(
+ conversionsShareOf([page('/a', { conversions: 4 }), page('/b', { conversions: 6 })]),
+ ).toBeCloseTo(0.2);
+ expect(conversionsShareOf([page('/a', { conversions: 40 })])).toBe(0.4);
});
it('gives an opportunity on a page losing ground the drop and the opportunity both', () => {
diff --git a/web/src/lib/content/plan.ts b/web/src/lib/content/plan.ts
index 2cf700859..6de70e45e 100644
--- a/web/src/lib/content/plan.ts
+++ b/web/src/lib/content/plan.ts
@@ -50,6 +50,12 @@ export interface PlanPage {
/** Platform keys citing it at a lower rate than before, the biggest drop first. */
platformsDown: string[];
aiVisits: number;
+ /**
+ * Conversions from AI journeys that landed on, went through or converted
+ * on the page (CE-017, 00291), as the Live page tab counts them; null for a
+ * brand with conversions off.
+ */
+ conversions: number | null;
}
/** An open opportunity for one of the brand's own pages. */
@@ -160,6 +166,15 @@ const NO_OPPORTUNITY = 0.4;
const NEUTRAL_PAGE_VALUE = 0.5;
/** AI visits in the period that count in full (on a log scale), and citations. */
const FULL_VISITS = 1000;
+/** Conversions in the period that count in full (on a log scale). */
+const FULL_CONVERSIONS = 20;
+/**
+ * The conversions' share of a page's value, with its AI visits the rest (spec
+ * v2: page value is visits and conversions), once FULL_CONVERSIONS are counted
+ * on the listed pages; it grows to it with the data, so one conversion doesn't
+ * re-weigh every page.
+ */
+const CONVERSIONS_SHARE = 0.4;
const FULL_CITATIONS = 30;
/** Citations lost that make a drop as bad as losing them all. */
const FULL_LOST = 20;
@@ -172,6 +187,29 @@ export function dropSeverity(pct: number, lost: number): number {
export function visitsValue(visits: number): number {
return Math.min(1, Math.log10(1 + Math.max(0, visits)) / Math.log10(1 + FULL_VISITS));
}
+/** A page's conversions as value: log10(1 + conversions) against FULL_CONVERSIONS'. */
+export function conversionsValue(conversions: number): number {
+ return Math.min(1, Math.log10(1 + Math.max(0, conversions)) / Math.log10(1 + FULL_CONVERSIONS));
+}
+/**
+ * A page's value: its AI visits, and with conversions weighed (a count, not
+ * null) the conversions' `share`, 40% once the listed pages have 20.
+ */
+export function pageValueOf(
+ visits: number,
+ conversions: number | null,
+ share: number = CONVERSIONS_SHARE,
+): number {
+ return conversions === null
+ ? visitsValue(visits)
+ : (1 - share) * visitsValue(visits) + share * conversionsValue(conversions);
+}
+
+/** The conversions' share of page value: up to 40%, by the conversions counted on the listed pages. */
+export function conversionsShareOf(pages: PlanPage[]): number {
+ const seen = pages.reduce((n, p) => n + (p.conversions ?? 0), 0);
+ return CONVERSIONS_SHARE * Math.min(1, seen / FULL_CONVERSIONS);
+}
/**
* What a row's score is made of, for the Priority Score's breakdown: each
@@ -182,7 +220,7 @@ export type PlanScorePart = { value: number; points: number; max: number } & (
| { kind: 'severity'; reason: 'drop'; pct: number; lost: number }
| { kind: 'severity'; reason: 'create' | 'opportunity' | 'protect' }
| { kind: 'opportunity'; score: number | null }
- | { kind: 'pageValue'; reason: 'visits'; visits: number }
+ | { kind: 'pageValue'; reason: 'visits'; visits: number; conversions: number | null }
| { kind: 'pageValue'; reason: 'newPage' | 'unknown' }
| { kind: 'citations'; citations: number }
);
@@ -217,6 +255,7 @@ function scoreParts({
opportunityScore,
page,
trafficKnown,
+ conversionsShare,
}: {
action: PlanAction;
drop: { pct: number; lost: number } | null;
@@ -226,6 +265,8 @@ function scoreParts({
page: PlanPage | undefined;
/** Whether the brand has AI traffic data at all. */
trafficKnown: boolean;
+ /** The conversions' share of page value (conversionsShareOf): 0 until a listed page has any. */
+ conversionsShare: number;
}): PlanScorePart[] {
const create = action === 'create';
return [
@@ -254,7 +295,12 @@ function scoreParts({
kind: 'pageValue',
reason: 'visits',
visits: page.aiVisits,
- value: visitsValue(page.aiVisits),
+ conversions: conversionsShare > 0 ? page.conversions : null,
+ value: pageValueOf(
+ page.aiVisits,
+ conversionsShare > 0 ? page.conversions : null,
+ conversionsShare,
+ ),
})
: part({ kind: 'pageValue', reason: 'unknown', value: NEUTRAL_PAGE_VALUE }),
part({
@@ -311,9 +357,14 @@ export function buildPlan({
const rows: PlanRow[] = [];
const pagesTaken = new Set<string>();
- // No page with an AI visit: the brand has no AI traffic data (no
- // Analytics, no snippet), so a page's value is unknown, not nothing.
- const trafficKnown = pages.some((p) => p.aiVisits > 0);
+ // No page with an AI visit or a conversion: the brand has no AI traffic
+ // data (no Analytics, no snippet), so a page's value is unknown, not nothing.
+ const trafficKnown = pages.some((p) => p.aiVisits > 0 || (p.conversions ?? 0) > 0);
+ // Conversions weigh once some listed page has any, and more as they come:
+ // turned on with none yet in the window, they'd cut every visited page's
+ // value before any data. Each conversion a listed page counts adds 2%, so
+ // the first, on one page, moves a row by 0.4 points at most.
+ const conversionsShare = conversionsShareOf(pages);
for (const o of opportunities) {
const create = !o.decision || CREATE_DECISIONS.has(o.decision) || !o.targetPage;
@@ -333,6 +384,7 @@ export function buildPlan({
opportunityScore: Math.round(o.score),
page,
trafficKnown,
+ conversionsShare,
});
rows.push({
key: `opportunity:${o.id}`,
@@ -381,6 +433,7 @@ export function buildPlan({
opportunityScore: null,
page,
trafficKnown,
+ conversionsShare,
});
rows.push({
...base,
@@ -398,6 +451,7 @@ export function buildPlan({
opportunityScore: null,
page,
trafficKnown,
+ conversionsShare,
});
protect.push({
...base,