Billbits

Developer docs

Billbits gives your game the ad itself (an image, a click link and the counting) so you can draw it anywhere: on a billboard in your world, on a loading screen, or in a normal banner box.

Quick start

  1. Create an account and add your game with the domain it runs on.
  2. Create a slot with the size you want (for example 400×80) and copy its id.
  3. On the slot page, look through the ads available for that size and allow or block them.
  4. Add the SDK and draw the slot in your game.
<script src="https://ads.billbits.dev/sdk.js"></script>

The script is about 6 KB, has no dependencies and sets no cookies. It defines a global Billbits.

Canvas games

Create the slot once, then draw it every frame it is on screen. draw() returns false when there is no ad (none available, still loading, or offline), so draw your own art instead.

const ads = Billbits.init();
const board = ads.slot('slot_XXXXXXXXXXXXXXXX');

function render() {
  // …draw your world…
  if (!board.draw(ctx, x, y, 400, 80)) {
    drawMyOwnBillboard(ctx, x, y);
  }
}

canvas.addEventListener('pointerdown', (e) => {
  // same coordinate space you used for draw()
  const r = canvas.getBoundingClientRect();
  const px = (e.clientX - r.left) * (canvas.width / r.width);
  const py = (e.clientY - r.top) * (canvas.height / r.height);
  if (board.hit(px, py)) board.click();   // opens the advertiser's page in a new tab
});

Several billboards with the same size? Create one slot object per billboard you show at the same time (each one loads its own ad), or reuse one slot for a billboard the player passes repeatedly.

Sharp screens: advertisers may upload images at 2× the slot size. draw() scales them to the width and height you pass, so they stay crisp on high-DPI canvases.

The “Ad” label: the SDK draws a small “Ad” tag in the corner, which advertising law in many countries requires. If your game labels ads another way (for example a “Sponsor” sign on the billboard frame), turn it off with Billbits.init({ badge: false }).

Phaser, PixiJS, three.js

Load an ad and use its preloaded image (an HTMLImageElement with CORS enabled) as a texture. Tell the SDK when it is visible with markVisible() every frame.

const ads = Billbits.init();
const ad = await ads.load('slot_XXXXXXXXXXXXXXXX');   // Ad or null
if (ad) {
  // Phaser 3
  this.textures.addImage('sponsor', ad.image);
  const sprite = this.add.image(x, y, 'sponsor').setInteractive();
  sprite.on('pointerdown', () => ad.click());
  // every frame: is at least half of it on screen?
  this.events.on('update', () => ad.markVisible(this.cameras.main.worldView.contains(sprite.x, sprite.y)));
}

// three.js
const texture = new THREE.Texture(ad.image); texture.needsUpdate = true;
// PixiJS
const sprite = PIXI.Sprite.from(ad.image);

Ads expire 30 minutes after loading if they were never shown (ad.expired). Load a fresh one when you need it, or use ads.slot(), which handles this for you.

HTML banners

For a regular web page, the SDK can fill an element with a linked image and count it when it scrolls into view:

<div id="sponsor"></div>
<script src="https://ads.billbits.dev/sdk.js"></script>
<script>
  Billbits.init().banner(document.getElementById('sponsor'), 'slot_XXXXXXXXXXXXXXXX');
</script>

How views are counted

Testing

On localhost ads load in test mode: you see real ads and can click them, but nothing is billed or earned. Turn on logging with Billbits.init({ debug: true }) to see what the SDK is doing. Each slot page in the dashboard has a live preview too.

SDK reference

Billbits.init({ server?, badge = true, debug = false }) → client

client.slot(slotId, { refreshMs = 60000 }) → Slot   // keeps an ad loaded
  slot.draw(ctx, x, y, w?, h?) → boolean             // false = draw your fallback
  slot.hit(x, y) → boolean
  slot.click()
  slot.current → Ad | null

client.load(slotId) → Promise<Ad | null>              // one ad, image preloaded
  ad.image   ad.width   ad.height   ad.alt   ad.advertiser   ad.test
  ad.draw(ctx, x, y, w?, h?)        ad.markVisible(visible = true)
  ad.hit(x, y)   ad.click()   ad.counted   ad.expired

client.banner(element, slotId) → Promise<Ad | null>

HTTP API

If you are not in a browser, or want to write your own client:

GET  https://ads.billbits.dev/v1/ad?slot=slot_…
     200 { id, width, height, image, imageWidth, imageHeight, alt, advertiser,
           token, impressionUrl, clickUrl, expiresAt, test }
     204 no ad available        403 wrong domain        404 unknown slot

POST https://ads.billbits.dev/v1/imp      body: the token (text/plain)   → 204, X-Outcome header
GET  https://ads.billbits.dev/v1/c?t=…    redirects to the advertiser (this is ad.clickUrl)

Requests must come from a page on your domain for impressions to count, and from the same visitor that requested the ad.

For advertisers