π΅ POST - Store Visibility Score
Store Visibility Score
Store visibility results and calculate final score for an entity
POST
Internal endpoint for the Cron service to store visibility results and calculate the overall visibility score.
Called ONCE per entity after all sampled prompts have been checked.
Where
This ensures the visibility score trends upward over time and doesnβt regress due to temporary API failures or platform changes.
What It Does
- Receives prompt results from Cron (10 sampled prompts per day)
- Calculates overall score:
total_true / (num_prompts * 8) * 100 - Updates TWO database tables:
entity_prompts_tracker- Per-prompt visibility resultsvisibility_score_history- Single row per entity with recent_score and history_scores JSONB
Score Algorithm
total_true_values is the count of True across all checks (e.g., 10 prompts Γ 8 platforms = 80 checks).
Example: If 40 out of 80 are True β raw_score = 50
Floor Protection
The score cannot regress below the historical minimum (ignoring 0s):Request Body
Business identifier (org_slug)
Optional product/item ID
Array of prompt results. Each item contains:
prompt(string): The prompt textchatgpt(boolean): Visibility on ChatGPTclaude(boolean): Visibility on Claudegemini(boolean): Visibility on Geminiperplexity(boolean): Visibility on Perplexitycopilot(boolean): Visibility on Copilotdeepseek(boolean): Visibility on DeepSeekgrok(boolean): Visibility on Grokgoogle_ai(boolean): Visibility on Google AI
Optional ISO date string (e.g., β2025-12-13β) to backdate the score entry
Response
"success" or "error"Calculated visibility score (0-100)
Number of prompts processed
Total number of True values across all platforms
Per-platform scores (0-100 each)
Database Updates
entity_prompts_tracker
Updates prompts with their visibility results across 8 platforms (pass/fail per platform).visibility_score_history
UPSERT single row per entity:- Updates
recent_scorewith latest score - Appends new entry to
history_scoresJSONB array - History format:
[{"date": "2025-12-15", "score": 41, "platforms": {...}}] - Keeps last 365 days of history
History Seeding
On first score calculation, the system seeds 2 days of fake history:- Day -2: Score 0 (baseline)
- Day -1: Score 35 (simulated signup day)
Notes
- Called by Cron ONCE per entity after sampled prompts are analyzed
- Each platform uses native search + Gemini 3 Flash provides unified evaluation
- JSONB history enables the βVisibility Over Timeβ chart on the dashboard
- Single row per entity = faster queries
- Floor protection ensures scores trend upward over time