JavaScript SDK
Install via script tag and request ads with a single unified
requestAd method. No dashboard configuration required.
I want to set up Koah's JavaScript SDK. Read https://docs.koahlabs.com/SKILL.md and follow its instructions.
Prerequisites
- A Koah account — if you don't have one, apply for access
- Your publisher ID from the dashboard
Install
Add the script tag
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>
Because the script is async, it may finish loading after your app boots. Gate your first requestAd call on window.koah being defined, or swap async for defer so the script evaluates after your bundle parses.
Add a target element
Add an empty <div> (or any element) where you want the ad to render:
<div id="ad-slot"></div>
Request an ad
Call window.koah.requestAd with the target element and a context describing the content on the page. Koah ranks, selects, and renders the ad directly into the target.
await window.koah.requestAd({
target: document.getElementById('ad-slot'),
context: {
type: 'conversation',
question: userMessage,
answer: aiResponse,
},
})
It returns a Promise<AdResult> describing the outcome — { filled: boolean; fromCache?: boolean }.
Next Steps
- Appearance — Customize ad appearance
- Use Cases — How to request ads for a variety of application types and contexts
- Ad Mediation — Waterfall between Koah and fallback ad networks
- Visitor Attributes — Share anonymous signals like age range, gender, and income bracket