SDKsJavaScript

JavaScript SDK (Legacy v1)

Install via script tag, configure with CSS selectors or DOM targets, and customize with design tokens.

Prerequisites

Install the SDK

Copy the snippet below and replace <YOUR_PUBLISHER_ID> with your actual publisher ID. Add it within the <head> tags of your HTML file.

<script async src="https://app.koah.ai/js?token=<YOUR_PUBLISHER_ID>"></script>

Specify Ad Placement

Tell Koah where ads should appear. You have two options:

Option A: CSS selectors (recommended) — Register selectors in your dashboard and Koah scans the DOM automatically.

  1. Add an empty <div> at the desired placement
  2. Give it a unique CSS selector
  3. Register the selector + ad type pair in your dashboard
<div class="koah-ad-slot"></div>

Option B: Target element — Pass a DOM element directly. No dashboard registration required.

window.koah.process(userMessage, aiResponse, 'suffix', {
  target: document.getElementById('ad-slot'),
})

Send Chat Data

Send chat interaction data to Koah to receive contextually relevant ads.

// userMessage  — the user's query to the LLM
// aiResponse   — the LLM's generated response
// adType       — where/how the ad appears: 'suffix', 'prefix', 'followup', etc.
window.koah.process(userMessage, aiResponse, adType)

Available ad types: 'suffix', 'prefix', 'followup', 'inline'


Migrate to v2

The legacy process / processStaticAd / generateTextAd methods are deprecated as of September 1, 2026. They continue to work, but precise sizing, new surfaces, and every new format ship only on the unified requestAd API. Read the migration guide for instructions for each method. You can also give that page to a coding agent with the prompt card at the top.

Was this helpful?