feat(elements): add brand-presence market-tracking-trends endpoint#2827
Open
jjenscodee wants to merge 1 commit into
Open
feat(elements): add brand-presence market-tracking-trends endpoint#2827jjenscodee wants to merge 1 commit into
jjenscodee wants to merge 1 commit into
Conversation
Add GET /v2/orgs/:spaceCatId/brands/:brandId/serenity/brand-presence/market-tracking-trends, a Semrush Elements wrapper returning weekly per-competitor mentions + citations for the brand-presence-sr-ui Competitor Comparison chart (CitationsMentionsTrendChart). Mentions come from TRENDS_MV (b5281393); citations from the market-tracking citations element (2e5a6f4e, new MARKET_CITATIONS_TREND constant). Both are weekly line elements that return one series per market participant keyed by legend=name, so competitors arrive natively as tracked benchmarks with no fan-out. The contract was ground-truthed against the live Brand Presence MFE. See docs/elements/market-tracking-trends-plan.md. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
This PR will trigger a minor release when merged. |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
New endpoint:
GET /v2/orgs/:spaceCatId/brands/:brandId/serenity/brand-presence/market-tracking-trendsSummary
Adds a Semrush Elements-backed endpoint returning weekly per-competitor mentions + citations for the tracked brand and its competitors — the data behind the Competitor Comparison chart (
CitationsMentionsTrendChart) on thebrand-presence-sr-uidashboard.Full design notes, the confirmed Semrush payload/response shapes, and resolved decisions are in
docs/elements/market-tracking-trends-plan.md(modeled onbrand-presence-stats-plan.mdfrom #2823). All brand names and metrics in the docs/tests are synthetic.Element mapping
Both are
type: "line",auto_bucketing: "week", no brand filter (so competitors come back natively as tracked-benchmarklegends):b5281393TRENDS_MV(existing)CBF_project(singular)y__mentions2e5a6f4eMARKET_CITATIONS_TREND(new)CBF_projects(plural)y__mentionsy__mentions; in the citations element that number is the citation count (Semrush reuses the generic key). The transform maps each to the right metric.What changed
routes/index.js,routes/facs-capabilities.js→llmo/can_view,routes/required-capabilities.js→brand:read): registers the route under the existing brand-scopedauthorizeOrgpattern;brandIdreuses the existing LLMO FACS brand alias.getMarketTrackingTrends(controllers/elements.js): mirrors the URL-inspector handlers —authorizeOrg,siteIdcross-check, optional dates with a 28-day trailing default + validation, region→projectIdresolution (else aggregate across all the brand's projects),cachedOk.support/elements/definitions/market-tracking-trends.js, new): weekly payload builders (CBF_projectvsCBF_projects, no brand filter, nocomparison_data_formatting) +transformMarketTrackingTrends— groups bothblocks.lines[]by ISO week, splits the brand line from competitor lines, defaults a missing metric to 0.getMarketTrackingTrends(support/elements/elements-service.js): fetches the two elements in parallel; no per-week fan-out (elements are pre-bucketed) and no per-competitor fan-out (legendcarries them).projectId(single region) takes precedence overprojectIds(aggregate).support/elements/element-ids.js): newMARKET_CITATIONS_TREND.docs/elements/market-tracking-trends-plan.md, new).Response shape
{ "weeklyTrends": [ { "week": "2026-07-05", "weekNumber": 27, "year": 2026, "mentions": 900, "citations": 5000, "competitors": [ { "name": "Rival One", "mentions": 150, "citations": 300 } ] } ] }Testing
getMarketTrackingTrends), controller (auth, date defaulting/validation, region resolution + 404,siteIdcross-check, error mapping), and route registration.Out of scope
UI wiring (DAL service + hook +
SRCompetitorComparisonSection); Competitor Summary / Share of Voice / Sentiment endpoints; day/month bucketing.🤖 Generated with Claude Code