Skip to content
Documentation menu
SDKWebJavaScript SDK

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)
});
ParameterTypeDescription
platformIdrequiredstringPublic platform ID.
baseUrlstringHTTPS API origin without a path. Defaults to https://sidekick-ads.com.
visitorIdstringVisitor ID, 16-128 characters. The SDK generates and persists it when omitted.
storagestringlocal persists the ID in the browser; memory retains it for the client lifetime. Defaults to local.
timeoutMsnumberRequest timeout, 100-30,000 ms. Defaults to 8,000.
allowInsecureLocalhostbooleanDefaults to false. Allows an HTTP baseUrl for a local development API. Not needed for a localhost page calling Sidekick over HTTPS.
appearanceobjectAppearance for all cards
onErrorfunctionRequest and media error callback.

Required fields.

Methods

MethodDescription
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.
visitorIdCurrent visitor ID; corresponds to visitor_id in the API.
baseUrlAPI origin chosen when the client was created.

Request options

ParameterTypeDescription
targetrequiredHTMLElementCard container. Required for requestAd().
requestIdrequiredstringAd slot ID within a message, 1-128 characters: A-Z, a-z, 0-9, _, ., :, -. Reuse it on rerenders.
placementstringRegistered placement, 1-64 Latin letters, digits, _ or -. Defaults to chat.
languageCodestringAd language. Defaults to the page language or en.
acceptFormatsstring[]Accepted formats; defaults to all six.
contextobjectContext: conversation, article, feed or static.
test / testFormatboolean / stringTest mode and test ad format.
appearanceobjectPer-card appearance in requestAd().
onFill / onNoFill() => voidrequestAd() callbacks without arguments. onFill means accepted for rendering, not a confirmed view.

Required fields.

Context fields and examples →

Context

context: optional object. Text fields: plain text, no HTML. No automatic page extraction.

Type and useFieldsLimits
conversation
Assistant conversation
question: user question; answer: app answer.Both optional: 0-4,096 and 0-16,384 characters. Default when type is omitted.
article
Article
title: title; content: relevant excerpt.Both required and nonempty: 1-4,096 and 1-16,384 characters.
feed
Feed item
textRequired nonempty text: 1-16,384 characters.
static
Slot without text
-Only type. Do not add question, answer or other text fields.
Four context examples: choose one
// Chat
const 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

StepMethod
Fetch adfetchAd(options)
RenderingAll ad.blocks and disclosure; removal at expires_at.
ViewtrackView(ad)
Actioninteract(ad, action)

Ad block structure · Ready-made card for API responses

Results and errors

Field / eventBehavior
filledtrue: accepted for rendering; false: no fill or error.
fromCachetrue: client-cached result.
Cacheplacement + requestId; until expires_at. No fill / error: 15 s. Up to 64 entries.
Repeated requestIdParameters must match. Mismatch: onError.
onErrorRequest and media errors. fetchAd/interact: null; create: throws.
RetryNo automatic retry. A new HTTP request creates a new delivery.