feat(demos): render keyword classifications in ctxSegments demo - #313
Merged
Conversation
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
approved these changes
Aug 11, 2026
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.
Why
The contextual segments API now returns free-form keyword classifications in
classifications.keywords, alongsideclassifications.categories. The vanillactxSegments()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/vanilla/targeting/ctx_segments.html.tplanddemos/vanilla/nocookies/targeting/ctx_segments.html.tpl, identical change to both):renderClassifications()now readsclassifications.keywordsand renders a flat keyword table (Keyword, Prominence).prominenceis 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).categoriesandkeywordsbefore showing the "no classifications" message, so a keyword-only node renders its keywords instead of a false "nothing found".How to Test
null/ missing-key responses. Keyword-only now shows the keyword table (previously the empty message); legacynull/missing do not throw; keyword text is HTML-escaped.Notes
ContextualSegmentsResponsetype are intentionally left unchanged, to be handled in a follow-up once the SDK's keyword handling inctxTargetingKeyValues()is decided.