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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ilyashik/ai-ad-sdk

v3.0.0

Published

Contextual advertising SDK for AI applications

Downloads

209

Readme

AI Ad SDK

Contextual advertising SDK for AI applications. Show relevant ads based on conversation context.

Quick Start

npm install @ilyashik/ai-ad-sdk

One-line widget (zero UI code)

import { createAdNetwork } from '@ilyashik/ai-ad-sdk';

const ads = createAdNetwork({ apiKey: 'your-api-key' });

// After each AI response — renders ad automatically:
await ads.mount('#ad-container', { userMessage, aiResponse });
<div id="ad-container"></div>

That's it. The SDK fetches the ad, renders a styled block with "Sponsored" label, and tracks impressions and clicks automatically.

Manual control (custom UI)

const ad = await ads.getAd(userMessage, aiResponse);
if (ad) {
  console.log(ad.title, ad.text, ad.url);
  ads.trackClick(ad); // call when user clicks
}

Via script tag

<script src="https://api.kontezza.com/static/ai-ad-sdk.umd.js"></script>
<script>
  const ads = createAdNetwork({ apiKey: 'your-api-key' });
  ads.mount('#ad-container', { userMessage, aiResponse });
</script>

API

createAdNetwork(options)

| Option | Type | Required | Description | |-----------|---------|----------|--------------------------------| | apiKey | string | yes | Your API key | | baseUrl | string | no | Custom backend URL | | debug | boolean | no | Enable console logging |

ads.mount(container, context, options)

All-in-one: fetches an ad and renders it into the container. Returns the ad object or null.

await ads.mount('#ad-slot', {
  userMessage: 'Помоги с презентацией',
  aiResponse: 'Рекомендую использовать шаблоны...'
}, {
  type: 'relevant',  // "relevant" | "banner"
  lang: 'ru',        // "ru" | "en"
  linkText: 'Подробнее →'
});

ads.renderAd(container, ad, options)

Render a previously fetched ad object into a container. Useful when you want to control when/how the ad is fetched.

const ad = await ads.getAd(userMessage, aiResponse);
if (ad) {
  ads.renderAd('#ad-slot', ad, { lang: 'en', linkText: 'Learn more →' });
}

ads.getAd(userMessage, aiResponse) / ads.getRelevantAd(userMessage, aiResponse)

Returns a relevant ad based on conversation context, or null. Impression is tracked automatically. Both names are equivalent.

ads.getBanner()

Returns a random banner ad from the active banner campaign, or null.

ads.trackClick(ad)

Track a click event. Called automatically when using renderAd/mount and user clicks the link. Call manually if using custom UI.

Ad Object

{
  id: string;
  campaignId: string;
  title: string;
  text: string;
  url: string;
  imageUrl: string;
  category: string;
  adType: 'relevant' | 'banner';
  design: {
    bgColor: string;     // publisher's bg color
    borderColor: string;  // publisher's accent color
  };
}

Design Customization

Ad colors are controlled by the publisher in the Kontezza dashboard. The renderAd/mount methods automatically apply design.bgColor and design.borderColor. Text color adapts to light/dark backgrounds.

What the SDK Handles Automatically

  • Sessions & anti-fraud. A stable session identifier is generated on first use and persisted in localStorage; it is attached to every request transparently.
  • Geo targeting. Resolved on the server from the client IP — no location data needs to be collected.
  • Frequency capping. The backend limits how often the same ad is shown to the same user. Fetch methods may return null — this is expected behavior, not an error.
  • Impression tracking. Fired automatically when an ad is received.
  • Retries. Transient network errors, 429 Too Many Requests, and 502/503/504 upstream errors are retried with exponential backoff. Each request has a 15-second AbortController timeout so a stalled connection cannot hang the page.
  • Active-campaign state. Refreshed in the background every 30 seconds; calls short-circuit instantly when no campaigns are active. On a refresh failure the SDK keeps the cached state and backs off for the same window — it does not retry on every render.

Impression accounting

The SDK fires the impression event the moment getAd/getBanner/mount returns an ad object. This matches industry "impression on serve" semantics and is how every billing model in the Kontezza dashboard is calibrated.

If you want belt-and-braces tracking — for example, you prefetch ads but only paint them on screen later — you can additionally call ads.trackImpression(ad) when the ad becomes visible. The backend de-duplicates impressions per (session_id, ad_id) within the configured frequency-cap window, so this will not double-bill the advertiser.

const ad = await ads.getAd(userMessage, aiResponse);
if (ad && weDecidedToShowIt) {
  ads.trackImpression(ad); // optional — already fired by getAd()
  ads.trackClick(ad);      // when the user clicks
}

For genuinely lazy UIs (where the ad object is created but may never be painted), reach out — we can ship a build with getAd({ autoTrack: false }) for your tenant. Out of the box, every fetch counts as one impression.

TypeScript

Full TypeScript definitions included (index.d.ts).

import { createAdNetwork, Ad, RenderOptions } from '@ilyashik/ai-ad-sdk';