Methods and options
Methods and options of the Sidekick browser client.
Client options
create()
const ads = Sidekick.create({platformId: "plt_example",onError: (error) => console.error(error.message)});
| Parameter | Type | Description |
|---|---|---|
platformIdrequired | string | Public platform ID. |
baseUrl | string | HTTPS API origin without a path. Defaults to https://sidekick-ads.com. |
visitorId | string | Visitor ID, 16-128 characters. The SDK generates and persists it when omitted. |
storage | string | local persists the ID in the browser; memory retains it for the client lifetime. Defaults to local. |
timeoutMs | number | Request timeout, 100-30,000 ms. Defaults to 8,000. |
allowInsecureLocalhost | boolean | Defaults to false. Allows an HTTP baseUrl for a local development API. Not needed for a localhost page calling Sidekick over HTTPS. |
appearance | object | Appearance for all cards |
onError | function | Request and media error callback. |
Required fields.
Methods
| Method | Description |
|---|---|
create({ platformId, … }) | Creates a client. |
requestAd({ target, requestId, … }) | Requests and renders an ad. Returns Promise<{filled, fromCache?}>. |
fetchAd({ requestId, … }) | Returns Promise<ad | null> for custom rendering. |
trackView(ad) | Promise<boolean>. View confirmation: ≥50% visible for ≥1 continuous second; active tab and screen. |
interact(ad, action) | Returns Promise<ad | null> with the next consent or quiz scene. |
setAppearance(options) | Updates appearance without requesting a new ad. |
setScreenActive(active) | false pauses media and view timing on a hidden app screen; true resumes them. |
unmount(target) | Removes the card from its container, retaining the client cache. |
dispose() | Cancels requests and releases client resources. |
visitorId | Current visitor ID; corresponds to visitor_id in the API. |
baseUrl | API origin chosen when the client was created. |
Request options
| Parameter | Type | Description |
|---|---|---|
targetrequired | HTMLElement | Card container. Required for requestAd(). |
requestIdrequired | string | Ad slot ID within a message, 1-128 characters: A-Z, a-z, 0-9, _, ., :, -. Reuse it on rerenders. |
placement | string | Registered placement, 1-64 Latin letters, digits, _ or -. Defaults to chat. |
languageCode | string | Ad language. Defaults to the page language or en. |
acceptFormats | string[] | Accepted formats; defaults to all six. |
context | object | Context: conversation, article, feed or static. |
test / testFormat | boolean / string | Test mode and test ad format. |
appearance | object | Per-card appearance in requestAd(). |
onFill / onNoFill | () => void | requestAd() callbacks without arguments. onFill means accepted for rendering, not a confirmed view. |
Required fields.
Context
context: optional object. Text fields: plain text, no HTML. No automatic page extraction.
| Type and use | Fields | Limits |
|---|---|---|
conversationAssistant conversation | question: user question; answer: app answer. | Both optional: 0-4,096 and 0-16,384 characters. Default when type is omitted. |
articleArticle | title: title; content: relevant excerpt. | Both required and nonempty: 1-4,096 and 1-16,384 characters. |
feedFeed item | text | Required nonempty text: 1-16,384 characters. |
staticSlot without text | - | Only type. Do not add question, answer or other text fields. |
Four context examples: choose one
// Chatconst context = {type: "conversation",question: "Which headphones suit travel?",answer: "Look for noise cancellation and a compact case."};// Article// context: { type: "article", title: "Travel audio", content: "A relevant excerpt…" }// Feed// context: { type: "feed", text: "Text of the current feed item…" }// No surrounding text// context: { type: "static" }
Custom rendering
| Step | Method |
|---|---|
| Fetch ad | fetchAd(options) |
| Rendering | All ad.blocks and disclosure; removal at expires_at. |
| View | trackView(ad) |
| Action | interact(ad, action) |
Results and errors
| Field / event | Behavior |
|---|---|
filled | true: accepted for rendering; false: no fill or error. |
fromCache | true: client-cached result. |
| Cache | placement + requestId; until expires_at. No fill / error: 15 s. Up to 64 entries. |
| Repeated requestId | Parameters must match. Mismatch: onError. |
onError | Request and media errors. fetchAd/interact: null; create: throws. |
| Retry | No automatic retry. A new HTTP request creates a new delivery. |