JavaScript API
Programmatic control of the Adkit SDK via window.__adkit. Primarily used for SPA navigation and slot refresh.
The window.__adkit object
Once the script loads, window.__adkit is available globally. The SDK is idempotent — if the script loads twice, the second load exits without re-initializing.
load event or place your script calls after the page body before accessing window.__adkit. The object is not available before the SDK initializes.API reference
| Property | Type | Description |
|---|---|---|
| window.__adkit.version | string | SDK version string (e.g. "1.1.0") |
| window.__adkit.refresh() | async () => Promise<void> | Resets all tracking state, re-scans the DOM, and re-initializes all slot elements found |
refresh()
refresh() is an async function that:
- Clears the event tracking Sets (so impressions and mounts are counted fresh)
- Clears the duplicate-slot detection Set
- Resets all slot state
- Marks all
[data-adkit-slot]elements as uninitialized - Runs
initializeAllSlots()to discover and render every slot in the DOM
The primary use case is after client-side navigation in single-page apps, where the DOM changes but the page doesn't fully reload.
SPA navigation example
Dynamically inserted slots
The SDK uses a MutationObserver to pick up new slot elements automatically within 100ms. Calling refresh() immediately after inserting slots skips the debounce and initializes them right away.
version
Read the loaded SDK version for debugging or conditional behavior.
Automatic event tracking
The SDK tracks these events automatically. You don't need to wire up any calls — they fire as part of the slot lifecycle.
| Event | When it fires |
|---|---|
| slot_mount | Once per slot identity per page load, when the slot initializes |
| slot_view | When ≥50% of the slot enters the viewport (fires for both active ads and empty placeholders) |
| slot_click | When a visitor clicks a live ad creative (not a placeholder click) |
| slot_duplicate | When the same slot identity appears twice on the same page |
Events are sent via fetch with keepalive: true and credentials: "omit". They never block rendering and silently swallow errors. Disable tracking per-slot with data-adkit-silent="true".