npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@adzerk/decision-sdk

v1.0.0-beta.25

Published

SDK for interacting with Adzerk's Decision API

Downloads

22,909

Readme

Adzerk JavaScript/Typescript Decision SDK

JavaScript Software Development Kit for Adzerk Decision & UserDB APIs

Usable client or server-side as TypeScript or JavaScript!

Installation

NPM Package

Server-Side via NPM

Requires Node.js v10 or higher.

npm install --save @adzerk/decision-sdk

Client-Side via CDN

Always fetches the latest version:

<script src="https://unpkg.com/@adzerk/decision-sdk/dist/adzerk-decision-sdk.js"></script>

Using a fixed version:

<script src="https://unpkg.com/@adzerk/[email protected]/dist/adzerk-decision-sdk.js"></script>

Examples

API Credentials & Required IDs

  • Network ID: Log into Adzerk UI & use the "circle-i" help menu in upper right corner to find Network ID. Required for all SDK operations.
  • Site ID: Go to Manage Sites page to find site IDs. Required when fetching an ad decision.
  • Ad Type ID: Go to Ad Sizes page to find Ad Type IDs. Required when fetching an ad decision.
  • API Key: Go to API Keys page find active API keys. Required when writing to UserDB.
  • User Key: UserDB IDs are specified or generated for each user.

Fetching an Ad Decision

import { Client } from "@adzerk/decision-sdk";

// Demo network, site, and ad type IDs; find your own via the Adzerk UI!
let client = new Client({ networkId: 23, siteId: 667480 });

let request = {
  placements: [{ adTypes: [5] }],
  user: { key: "abc" },
  keywords: ["keyword1", "keyword2"]
};

client.decisions.get(request).then(response => {
  console.dir(response, { depth: null });
});

Recording Impression & Clicks

Use with the fetch ad example above.

// Impression pixel; fire when user sees the ad
client.pixels.fire({ url: decision.impressionUrl });

// Click pixel; fire when user clicks on the ad
// status: HTTP status code
// location: click target URL
client.pixels.fire({ url: decision.clickUrl }).then(r => {
  console.log(`status ${r["status"]}; location: ${r["location"]}`);
});

UserDB: Reading User Record

import { Client } from "@adzerk/decision-sdk";

// Demo network ID; find your own via the Adzerk UI!
let client = new Client({ networkId: 23 });
client.userDb.read("abc").then(response => console.log(response));

UserDB: Setting Custom Properties

import { Client } from "@adzerk/decision-sdk";

// Demo network ID; find your own via the Adzerk UI!
let client = new Client({ networkId: 23 });

let props = {
  favoriteColor: "blue",
  favoriteNumber: 42,
  favoriteFoods: ["strawberries", "chocolate"]
};

client.userDb.setCustomProperties("abc", props);

UserDB: Forgetting User Record

import { Client } from "@adzerk/decision-sdk";

const apiKey = process.env.ADZERK_API_KEY;

// Demo network ID and API key; find your own via the Adzerk UI!
let client = new Client({ networkId: 23, apiKey });
client.userDb.forget("abc");

Decision Explainer

The Decision Explainer returns information on a Decision API request explaining why each candidate ad was or was not chosen.

import { Client } from "@adzerk/decision-sdk";

const apiKey = process.env.ADZERK_API_KEY;

// Demo network, site, and ad type IDs; find your own via the Adzerk UI!
let client = new Client({ networkId: 23, siteId: 667480 });

let request = {
  placements: [{ adTypes: [5] }],
  user: { key: "abc" },
  keywords: ["keyword1", "keyword2"]
};

const options = {
  includeExplanation: true,
  apiKey
};

client.decisions.get(request, options).then(response => {
  console.dir(response, { depth: null });
});

The response returns a decision object with placement, buckets, rtb logs, and result information.

{
  "div0": {
    "placement": {},
    "buckets": [],
    "rtb_log": [],
    "results": []
  }
}

The "placement" object represents a decision in which an ad may be served. A Explainer Request can have multiple placements in the request. The "buckets" array contains channel and priority information. The "rtb_logs" array contains information about Real Time Bidding. The "results" array contains the list of candidate ads that did and did not serve, along with a brief explanation. |

Logging

Our logging implementation is meant to be flexible enough to fit into any common NodeJS logging framework.

When constructing a client instance, the logger is passed in as an anonymous function with three parameters:

  • level: Any one of debug, info, warn, or error
  • message: The message to log
  • metadata: Any additional metadata related to the logging call

If no logger is provided as an argument, the debug library will be used by default.

The easiest way to integrate is to write a function that handles translating the data from the Adzerk SDK Logger into whatever logging framework you're using in the rest of your application:

import { Client } from "@adzerk/decision-sdk";

const logger = (lvl, msg, meta) =>
  console.log(`[${lvl}] ${msg} [${JSON.stringify(meta)}]\n`);

let client = new Client({ logger });

Documentation

Contributing

Reporting Issues

Building / Running Tests

To install dependencies and run the builds associated with this SDK, please use:

npm install
npm run build
npm run test