Skip to content

feat: add initContextual flag for automatic pageview tracking with page context#277

Merged
mosherBT merged 2 commits intoOptable:masterfrom
MO-Thibault:mo/init-contextual-pageview
May 8, 2026
Merged

feat: add initContextual flag for automatic pageview tracking with page context#277
mosherBT merged 2 commits intoOptable:masterfrom
MO-Thibault:mo/init-contextual-pageview

Conversation

@MO-Thibault
Copy link
Copy Markdown
Contributor

Summary

  • Adds initContextual?: boolean to InitConfig — when true, the SDK automatically fires a pageview witness event with full page context during initialization (after passport init)
  • Implies pageContext: true when no pageContext is explicitly configured, so callers only need one flag
  • Follows the same non-blocking fire-and-forget pattern as initTargeting
  • Documents both the flag and the manual witness(..., { includeContext: true }) approach in README

Motivation

Publishers integrating Optable for contextual audience assembly need to send page context on load. Previously this required custom integration code in each SDK bundle (e.g. the Playwire solution bundle). This flag makes it a first-class SDK feature with a single line of config.

Usage

const sdk = new OptableSDK({
  host: "dcn.customer.com",
  site: "my-site",
  initContextual: true,          // fire pageview + context on init
  // pageContext: { contentSelector: "article" }  // optional customization
});

Changes

  • lib/config.tsinitContextual added to InitConfig, ResolvedConfig, and getConfig
  • lib/sdk.ts — constructor defaults contextConfig to {} when initContextual is set without pageContext; initialize() fires the witness call
  • README.md — new initContextual and pageContext entries in Optional Keys; new "Contextual Pageview Tracking" section under Witness API with automatic and manual usage examples

🤖 Generated with Claude Code

MO-Thibault and others added 2 commits May 8, 2026 10:17
…ge context

When initContextual: true, the SDK fires a 'pageview' witness event with
full page context during initialization, after passport init. Implies
pageContext: true when no pageContext is explicitly configured.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Match the Playwire solution bundle pattern — hostname + pathname as an
explicit witness property alongside the page context payload.

Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@jplaroche jplaroche left a comment

Choose a reason for hiding this comment

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

I believe URL is optional but we can keep it.
LGTM

@mosherBT mosherBT merged commit 7b0d27e into Optable:master May 8, 2026
7 checks passed
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.

3 participants