Skip to content

contextual: expose page emotions via ctxEmotions() and the ctx_emotion key-value - #381

Merged
pierluc-codes merged 3 commits into
masterfrom
feat/ctx-emotion
Nov 3, 2026
Merged

pierluc-codes merged 3 commits into
masterfrom
feat/ctx-emotion

Conversation

@pierluc-codes

Copy link
Copy Markdown
Contributor

Why

/v1beta1/contextual now returns classifications.emotions, but the SDK doesn't surface it. Publishers have no way to read it or target on it.

What Changed

  • contextual_segments: new ContextualEmotion type and emotions field on ContextualClassifications.
  • sdk: new ctxEmotions() accessor. It reads the cached ctxSegments() response and returns [] when the page has no emotions.
  • ctxTargetingKeyValues: emits the multi-value key ctx_emotion with the emotion ids. Scores aren't sent and the SDK applies no cutoff. The key is omitted when the page has no emotions. options.emotionKey renames the key, and "" opts out.
  • Docs: README and lib/addons/gpt.md.
  • Demos: both ctx_segments pages show the emotions.

How to Test

  • Tested
  • Docs updated — if this adds, changes or removes anything a consumer calls, update the module's .md alongside the code (for example lib/addons/<addon>.md) and the matching README section. New addons ship with a new .md.

Notes

  • Breaking change
  • Requires release

🤖 Generated with Claude Code

…n key-value

Add ContextualEmotion and classifications.emotions, a ctxEmotions()
accessor, and the multi-value ctx_emotion GAM key-value (ids only,
omitted when empty). options.emotionKey renames the key, and "" opts
out. Update the README, gpt.md and the ctx_segments demos.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pierluc-codes pierluc-codes self-assigned this Nov 3, 2026
@pierluc-codes
pierluc-codes requested review from a team as code owners November 3, 2026 13:45

@hashibit hashibit left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review notes below. Items on contextual_segments.ts:179/373 and the README note are the ones I would fix before merge. The others are smaller.

Not from this PR, for a follow-up: setContextualTargetingInGAM (lib/addons/gpt.ts) never clears keys it set before. On an SPA route change to a page with no emotions, the old ctx_emotion value stays on GAM page targeting. ctx_kw and ctx_sentiment have the same gap today.

Comment thread lib/edge/contextual_segments.ts Resolved
Comment thread lib/edge/contextual_segments.ts Resolved
Comment thread lib/sdk.ts Resolved
Comment thread README.md Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread lib/edge/contextual_segments.ts Resolved
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pierluc-codes
pierluc-codes merged commit 93d8b0e into master Nov 3, 2026
7 checks passed
@pierluc-codes
pierluc-codes deleted the feat/ctx-emotion branch November 3, 2026 20:37
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.

4 participants