@adxact/adxact-js
v0.14.0
Published
## Quickstart
Downloads
25
Readme
adxact-js
Quickstart
npm -i adxact-js
There are also sample applications available:
- https://github.com/AdXcelerant/sample-cra-app (React)
- https://github.com/AdXcelerant/sample-html-app (HTML/JS)
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