Skip to content

feat(demos): render keyword classifications in ctxSegments demo - #313

Merged
mosherBT merged 1 commit into
masterfrom
feat/demo-display-contextual-keywords
Aug 11, 2026
Merged

feat(demos): render keyword classifications in ctxSegments demo#313
mosherBT merged 1 commit into
masterfrom
feat/demo-display-contextual-keywords

Conversation

@pierluc-codes

Copy link
Copy Markdown
Contributor

Why

The contextual segments API now returns free-form keyword classifications in classifications.keywords, alongside classifications.categories. The vanilla ctxSegments() demos only rendered categories, so keywords never appeared, and a keyword-only node rendered the misleading message "No contextual classifications were returned for this URL" even though keywords were present in the raw response shown directly below it.

What Changed

  • demos (demos/vanilla/targeting/ctx_segments.html.tpl and demos/vanilla/nocookies/targeting/ctx_segments.html.tpl, identical change to both): renderClassifications() now reads classifications.keywords and renders a flat keyword table (Keyword, Prominence).
  • prominence is displayed as an ordinal rank (1 = most prominent), not a score bar, per the API contract (it is a per-page rank, not a comparable score).
  • The empty-state guard now checks both categories and keywords before showing the "no classifications" message, so a keyword-only node renders its keywords instead of a false "nothing found".

How to Test

  • Tested — render logic exercised against categories-only, keyword-only, both, and empty / legacy-null / missing-key responses. Keyword-only now shows the keyword table (previously the empty message); legacy null/missing do not throw; keyword text is HTML-escaped.

Notes

  • Rendering only. The page's prose/API-shape documentation (the response-shape blurb and the GAM key-values section) and the SDK ContextualSegmentsResponse type are intentionally left unchanged, to be handled in a follow-up once the SDK's keyword handling in ctxTargetingKeyValues() is decided.
  • Breaking change
  • Requires release

The contextual segments API now returns free-form keyword classifications
in classifications.keywords alongside classifications.categories. The vanilla
ctxSegments() demos only rendered categories, so keywords were invisible and a
keyword-only node incorrectly showed "No contextual classifications were
returned" even though keywords were present in the raw response shown below.

renderClassifications() now also reads classifications.keywords and renders a
flat keyword table. prominence is shown as an ordinal rank (1 = most prominent),
not a score bar, matching the API contract. The empty-state guard now checks
both arrays. Applied identically to the cookies and nocookies variants.

Prose/API-shape docs on the page are intentionally left unchanged for a follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mosherBT
mosherBT merged commit 7d84faf into master Aug 11, 2026
7 checks passed
@mosherBT
mosherBT deleted the feat/demo-display-contextual-keywords branch August 11, 2026 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants