adtoniq-express

1.1.1 • Public • Published

adtoniq-express

Adtoniq for Node.js implements the server-to-server communications required between your webserver and Adtoniq.

Install

npm i adtoniq-express

Usage

Get your API key.

const apiKey = "Your-API-Key-Here";

Initialize the API with your key.

const adtoniq = new Adtoniq(apiKey);

Optionaly, use this consructor to add functionality to manually update your cache / CDN when the JavaScript is updated. You will need to implement the following two functions and pass them to the constructor

saveScript = function(script, callback) {
  // save script
  callback()
}
loadScript = function(callback) {
  callback(<saved script or null if none saved>)
}
const adtoniq = new Adtoniq(apiKey, saveScript, loadScript);

Implement functionality

Implement the following on every page handler where you want to integrate Adtoniq functionality.

adtoniq.getHeadCode({}, (headCode) => {
    // Inject headCode to the `<head>` section.
})

Process server refresh

You must provide a handler for Adtoniq to transmit the latest JavaScript required to ensure Adtoniq continues functioning as new ad block rules are added, or ad blockers are enhanced with new capabilities. That handler will have to perform the following:

adtoniq.processRequest(request.body, (headCode) => {
})

Process external cache refresh

When using exernal caching of the script and the cache is updated you must update adtoniq by calling:

adtoniq.setJavaScript(<updated script>)

For details and examples visit https://github.com/adtoniq/adtoniq-for-nodejs

License

This project is licensed under the MIT License

Package Sidebar

Install

npm i adtoniq-express

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

7.5 kB

Total Files

3

Last publish

Collaborators

  • adtoniq