Skip to content
Documentation menu
SDKWebJavaScript SDK

Appearance and SPA

Card appearance and component lifecycle integration.

Appearance

setAppearance()
ads.setAppearance({
colorScheme: "dark",
surface: "inline",
bodyFontSize: 14,
mediaHeight: 130
});
ParameterValuesDefault
colorSchemeauto, light, darkauto
surfacecard / inlinecard

Dimensions, px

ParameterDefaultRangeDescription
bodyFontSize1413–16Body font size
bodyLineHeight2018–26Body line height
brandFontSize1413–16Brand font size
metaFontSize1111–12Disclosure font size
mediaHeight130100–200Media height
buttonFontSize1413–15Button font size
buttonMinHeight3232–40Minimum button height
buttonHorizontalPadding1210–16Horizontal button padding
contentPadding86–16Card padding
cornerRadius128–20Card corner radius
blockSpacing64–10Block spacing
logoSize1816–24Logo size

Out-of-range values are clamped. In inline mode, corner radius is 0 and padding ranges from 0 to 16 px. Line height is at least 1.35 times the body font size; brand font size is at least bodyFontSize − 1.

The app container sets width; height follows the content. Card styles are isolated from page CSS.

React

Pass the existing ads client to the component. Call unmount() when removing its container.

Request an ad after the response is complete and question and answer no longer change. Repeated calls with the same requestId must use the same parameters.

AdSlot.jsx
function AdSlot({ ads, messageId, question, answer }) {
const ref = React.useRef(null);
React.useEffect(() => {
const target = ref.current;
void ads.requestAd({
target,
requestId: messageId,
context: { question, answer }
});
return () => ads.unmount(target);
}, [ads, messageId, question, answer]);
return <div ref={ref} style={{ maxWidth: 480 }} />;
}

Lifecycle

EventAction
Message rerenderKeep the client, requestId and request parameters.
Screen hiddenads.setScreenActive(false)
Screen shownads.setScreenActive(true)
Container removedads.unmount(target)
App shutdownads.dispose()