Skip to content

Browser

On a website, the SDK connects as a script and plays the ad itself inside the given container — no player is needed on the site's side.

Include the script and styles

html
<link rel="stylesheet" href="https://cdn.adsdk.ru/web/v3/style.css" />
<script src="https://cdn.adsdk.ru/web/v3/ad-sdk.js"></script>

Once it loads, the global window.adSDK object becomes available. TypeScript types are in the ad-sdk.d.ts file included in the package.

Prepare the container

The player fills the whole container, so the container must have dimensions before the ad starts loading:

html
<div id="ad-player-slot" style="width: 640px; height: 360px"></div>

Dimensions

The SDK starts loading only once the page has dimensions. If it doesn't get them within 3 seconds, AdError arrives with the code viewport_unavailable.

Create the player and subscribe to events

js
const controller = await window.adSDK.init({
  refWrapper: document.getElementById('ad-player-slot'),
  lang: 'ru',
  settings: { controls: ['ad-skip-btn'], volume: 0.3 },
});

const { loader } = controller;

loader.on('AdLoaded', ({ ad_creative_duration_sec }) => {
  console.log('Duration', ad_creative_duration_sec);
  loader.playAd();
});

loader.on('AdClick', ({ url }) => window.open(url, '_blank'));
loader.on('AdError', ({ code, message }) => console.warn(code, message));
loader.on('AdsEnded', () => controller.destroy());

Load the ad

js
loader.loadAd('https://ads.example.com/vast.xml', {
  adMediaFileWidth: -1,
  adMediaMaxDurationSec: -1,
  autoplay: false,
  controls: ['ad-skip-btn'],
  os: 'web',
  volume: 0.3,
});

adSDK.init(options)

FieldTypeDescription
refWrapperHTMLDivElementThe container for the player. If not given, #ad-player-slot is used.
langstringUI language, default en. See Parameters.
settingsobjectPlayer settings; all fields are optional.

Returns Promise<AdController>:

FieldDescription
loaderControls the ad: methods and events.
destroy()Stops the ad, unsubscribes handlers, and removes the player from the container.

settings options

FieldTypeDefaultDescription
controlsstring[][]Controls.
volumenumber0.3Volume from 0 to 1.
autoplaybooleanfalseStart playback immediately after loading.
adMediaFileWidthnumber-1Desired video width in pixels; -1 — automatic.
adMediaMaxDurationSecnumber-1Maximum duration in seconds; -1 — no limit.

The same fields, plus os: 'web', are passed as the second argument to loader.loadAd(url, settings).

Player UI

In the browser, the play button, volume, progress bar, remaining time, and ERID are always visible. The ad-skip-btn control enables the skip button. See the UI live in the Playground with the Browser platform.

Subscribing and unsubscribing

js
const subscription = loader.on('AdStarted', payload => { /* … */ });

subscription.unsubscribe();

The handler receives an object with the event's data, with keys in snake_case.

Multiple players

Each call to adSDK.init() creates an independent player with its own controller. To remove all players at once, call window.adSDK.destroyAll().

Autoplay in the browser

Browsers block autoplay with sound. Start playback after a user action, or without sound. If playback is blocked, AdError arrives with the code permission_denied.