@adxact/adxact-js

0.14.0 • Public • Published

adxact-js

Quickstart

npm -i adxact-js

There are also sample applications available:

Contact your account manager to set-up your first placement and placementKey.

Examples

Run the player

The AdXact Player runs ads on the screen until cancelled or otherwise disabled. Ads can be a combination of videos, banners, and other creatives enabled for the placement. Internally, the player uses async/await and the fetch API to play ads and does not block.

import { Player } from "@adxact/adxact-js";

const player = new Player()
  .setMountElement(elem)
  .setPlacementKey("4650953b55a34a55bf18b88261fda713")
  .setAdServerUrl("https://ads.adxact.tech")
  .start();

Play during certain hours

The player handle can be used to restrict the times of day that ads are displayed in the element. Please note, the code is for example purposes only and does not consider edge cases like leap seconds, daylight savings, and so on.

import { Player } from "@adxact/adxact-js";

function playCertainHours(hourStart, hourEnd, player) {
  if (now.getHours() >= hourStart && now.getHours() < hourEnd) {
    player.start();
    let endTime = new Date().setHours(hourEnd);
    //developer.mozilla.org/en-US/docs/Web/API/setTimeout
    setTimeout(
      () => playCertainHours(hourStart, hourEnd, player),
      endTime - Date.now()
    );
  } else {
    player.stop();
    let startTime = new Date(Date.now() + 60 * 60 * 24 * 1000).setHours(
      hourStart
    );
    //developer.mozilla.org/en-US/docs/Web/API/setTimeout
    setTimeout(
      () => playCertainHours(hourStart, hourEnd, player),
      startTime - Date.now()
    );
  }
}

const player = new Player()
  .setMountElement(elem)
  .setPlacementKey("4650953b55a34a55bf18b88261fda713")
  .setAdServerUrl("https://ads.adxact.tech")
  .start();

playCertainHours(9, 15, player);

Block advertisement categories

const player = new Player()
  .setBlockedCategories(["IAB-24"]) // use IAB codes
  .setMountElement(elem)
  .setPlacementKey("4650953b55a34a55bf18b88261fda713")
  .setAdServerUrl("https://ads.adxact.tech")
  .start();

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in adxact-js by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

License: MIT OR Apache-2.0

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.14.02latest

Version History

VersionDownloads (Last 7 Days)Published
0.14.02
0.13.01
0.12.02
0.11.02
0.10.02
0.7.01
0.6.00
0.5.02
0.4.02
0.3.01
0.2.01
0.1.01

Package Sidebar

Install

npm i @adxact/adxact-js

Weekly Downloads

17

Version

0.14.0

License

(MIT OR Apache-2.0)

Unpacked Size

243 kB

Total Files

8

Last publish

Collaborators

  • estassen-adx
  • nkconnor