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.

fix(prompts): let long-tail Search Console queries reach suggestion candidates (#937)

Gökhan Geyik562301cc54a5
diff --git a/server/src/lib/gsc-suggestions.js b/server/src/lib/gsc-suggestions.js
index 5b720b695..5177d9c49 100644
--- a/server/src/lib/gsc-suggestions.js
+++ b/server/src/lib/gsc-suggestions.js
@@ -113,7 +113,10 @@ export function composeCandidates(rows, existingPromptTexts, excludedQueries = n
avgPosition: r.avg_position != null ? Math.round(r.avg_position * 10) / 10 : null,
}));
- const head = open.slice(0, HEAD_SLOTS);
+ // The RPC returns everything down to the long-tail floor, so the head's own
+ // floor is applied here — otherwise a quiet site's top slots fill with
+ // queries that are neither head demand nor long-tail.
+ const head = open.filter((c) => c.impressions >= MIN_IMPRESSIONS).slice(0, HEAD_SLOTS);
const inHead = new Set(head.map((c) => c.query));
const longtail = open
.filter(
@@ -191,7 +194,9 @@ export async function getGscSuggestionCandidates(brandId, brand, existingPromptT
const { data: rows, error } = await supabaseAdmin.rpc('gsc_candidate_queries', {
p_brand_id: brandId,
p_since: since,
- p_min_impressions: MIN_IMPRESSIONS,
+ // The long-tail floor, not the head's: anything the RPC drops never
+ // reaches composeCandidates, so the lower long-tail threshold was dead.
+ p_min_impressions: LONGTAIL_MIN_IMPRESSIONS,
});
if (error) throw new Error(error.message);
if (!rows || rows.length === 0) return [];
diff --git a/server/src/lib/gsc-suggestions.test.js b/server/src/lib/gsc-suggestions.test.js
index e16d02c80..adc2e9fca 100644
--- a/server/src/lib/gsc-suggestions.test.js
+++ b/server/src/lib/gsc-suggestions.test.js
@@ -105,4 +105,20 @@ describe('composeCandidates', () => {
const out2 = composeCandidates([...rows, row('tiny query', 15)], []);
expect(out2.some((c) => c.query === 'tiny query')).toBe(false);
});
+
+ it('keeps quiet rows out of the head but lets long-tail ones through', () => {
+ // A small site: one head query, everything else between the long-tail
+ // floor (10) and the head floor (30) — what the RPC now returns.
+ const rows = [
+ row('consultancy official website', 2900),
+ row('who to hire first for go to market', 22),
+ row('outbound stopped working', 18), // 3 words → not long-tail
+ row('gtm diagnostic', 12), // 2 words, below head floor → dropped
+ ];
+ const out = composeCandidates(rows, []);
+ expect(out.map((c) => c.query)).toEqual([
+ 'consultancy official website',
+ 'who to hire first for go to market',
+ ]);
+ });
});