Skip to main content

Methods

MethodSignatureDescription
render(options?) → Promise<void>Render a contextual ad into a placement
destroy(target?) → voidRemove one placement or all placements
debug(enabled: boolean) → voidToggle console logging
versionstringCurrent SDK version

render() options

{
  query: string                   // user's message — required
  response: string                // AI's response — required
  target?: string | HTMLElement   // CSS selector or element — omit for auto-discovery
  turnId?: string                 // pairs contextual with opener across pages (SPA)
}

Placement attributes

AttributePurposeValues
data-thrad-typeWhen the ad triggersopener, contextual
data-thrad-formatHow the ad looksmessage, prompt, carousel, poll

Script tag

<script src="https://sdk.thrad.ai/sdk.js?token=YOUR_PUBLISHER_ID"></script>

window.thrad_config

Set before the SDK script tag to configure identity and theming. All fields are optional.
{
  userId?: string
  userMeta?: {
    age?: number
    gender?: string
  }
  theme?: {
    colorScheme?: 'light' | 'dark'
    accentColor?: string     // hex color
    maxWidth?: string        // CSS value, e.g. '500px'
  }
  turnId?: string            // for SPA cross-page pairing
}