API integration

For publishers approved to integrate Carbon directly. Fetch the ad as JSON, render it in your own markup, and follow the rules below so every impression counts.

  1. 01Set upDemo zones and test mode
  2. 02FetchOne request per ad shown
  3. 03RenderYour markup, fixed rules
  4. 04TrackPixel, view, click
  5. 05Go liveCheck it, then send us staging

Must breaks tracking or the advertiser’s approval if skippedYours your design call

01Set up

Zone and test mode

  • MustSend ignore=yes on every request outside production.

You need a zone key, which we send when your site is approved for a direct integration. There is no script to load: you request the ad as JSON and render it in your own markup.

Build against our two demo zones first. Each always returns the same format, so you can get each renderer right against a fixed ad. To test the rest of your dispatch, an empty response and an unknown shape, save a real response and edit it.

ZoneReturns
CWYIC2QJCarbon Cover, every request
CVAIKKQMCarbon Classic, every request

With ignore=yes, ads still load but no impression is counted.

02Fetch

Make the request

  • MustFrom a server, pass the visitor’s forwardedip and useragent.
  • YoursFetch from the browser or your server.

Without the visitor’s details, every impression comes from your server’s address and is filtered out as invalid.

ParameterWhenWhat to send
forwardedipServer-sideThe visitor’s IPv4 address, from X-Forwarded-For. Not your server’s.
useragentServer-sideThe visitor’s user agent, URL-encoded.
placementRecommendedA fixed name for each spot on your site, such as sidebar, so results can be read per spot.
ignoreNot in productionyes serves an ad without counting the impression.
# from the browser
GET https://srv.buysellads.com/ads/{zonekey}.json?placement=sidebar

# from your server
curl -G https://srv.buysellads.com/ads/{zonekey}.json \
  -d forwardedip=198.51.100.123 \
  -d useragent=Mozilla%2F5.0... \
  -d placement=sidebar

One request, one impression

  • MustOne request per ad you will show. No retries, no cached responses.

The impression is counted when the request succeeds. There is nothing to fire when the ad renders, and the statimp field in the response isn’t used.

A cached response’s tracking links belong to the view it was served for. In a single-page app, check that a remount, a route change or a development double-render doesn’t send a second request.

Pick the shape

  • MustWith no statlink, show your own content, never another network’s ad.
  • MustCover when all six Cover fields are present and non-empty; Classic otherwise.

A response without statlink means no ad was served this time. A filled response that isn’t Cover is a Classic ad, which is a paid ad, not an empty slot.

const COVER = [
  'backgroundColor',
  'callToAction',
  'company',
  'companyTagline',
  'logo',
  'largeImage'
];

const ad = (await res.json()).ads?.[0];
if (!ad?.statlink)            return showOwnContent();
if (COVER.every(k => ad[k]))  return renderCover(ad);
if (classicImage(ad))         return renderClassic(ad);
return showOwnContent();      // a shape we don't know: log it

03Render

Carbon Cover

  • MustWhite sans-serif type over a blurred wash of backgroundColor.
  • MustThe description reachable on every device. The button never moves.
  • YoursBlur, wash strength, corners, shadow, timing, and how the description appears.

Advertisers approve their image, logo and color together, against that one treatment. Keep it and the rest of the design is yours.

FieldSupplied asHow to show it
largeImage500×500At 180×180px, up to 250×250px. Also the blurred background.
logo250×100At 125×50px. Never cropped or recolored.
companyTaglineUp to 45 charactersNext to the logo, from the start, in white.
descriptionUp to 100 charactersRevealed on hover, in white. Reachable on touch too.
callToActionUp to 20 charactersA white button with near-black text, visible from the start.
backgroundColorHexWashed over the blurred largeImage. 80% is a good start.
companyUp to 30 charactersThe image’s alt text.

When the description appears, reserve its space so the button doesn’t move. Below a 360px-wide container, stack the unit in one column and show the description all the time; the sample handles the description. Measure the container, not the screen, since the unit may sit in a sidebar.

.cover-text { display: flex; flex-direction: column; height: 100px; }
.cover-description {
  flex-grow: 1; overflow: hidden; opacity: 0;
  transition: opacity .1s ease-out;
}
.cover:is(:hover, :focus-visible) .cover-description {
  opacity: 1; transition: opacity .5s ease-in .25s;
}

/* no hover to reveal it: a touch screen, or a stacked unit */
@media (hover: none) { .cover-description { opacity: 1; } }
.cover-slot { container-type: inline-size; }
@container (width < 360px) { .cover-description { opacity: 1; } }

/* the image, under a blurred wash of its color */
.cover {
  position: relative; isolation: isolate; color: #fff;
  background: var(--art) center / cover;
}
.cover::before {
  content: ""; position: absolute; inset: 0; z-index: -1;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: blur(8px);
}

Carbon Classic

  • MustThe description always visible, at full length.
  • MustThe image whole, never cropped or recolored.
  • YoursLayout, type and spacing around them.

Classic carries one image and a description, nothing else: no tagline, no button. Reusing Cover’s hidden description renders a Classic ad with no words that still looks like it worked.

Image, in this orderSupplied asHow to show it
largeImage500×500At 100×100px.
smallImage260×200From 130×100px up to 260×200px. Never cropped.
logo on backgroundColor250×100100px wide, on that color.

Check all three: a renderer that only knows smallImage drops paid ads when the mix changes. Advertisers are asked for 100 characters, but a few run longer, so design for the long end.

const classicImage = ad =>
    ad.largeImage ? { src: ad.largeImage, size: [100, 100] }
  : ad.smallImage ? { src: ad.smallImage, size: [130, 100] }
  : ad.logo && ad.backgroundColor
      ? { src: ad.logo, width: 100, ground: ad.backgroundColor }
  : null;

Link and label it

  • MustOne link for the whole ad, new tab, rel="sponsored noopener".
  • Must“ads via Carbon” visible, outside that link.
  • MustEscape advertiser text. Check colors and URLs before they reach CSS.

The link goes to statlink, and “ads via Carbon” to ad_via_link. Treat every text field as untrusted input: escape it, or set it with textContent. A color or URL that goes into CSS can’t be escaped, so check its shape and set it from script.

<div class="cover-slot">
  <a class="cover" href="{statlink}" target="_blank"
     rel="sponsored noopener">
    <img class="cover-image" src="{largeImage}" alt="{company}">
    <div class="cover-logo">
      <img src="{logo}" alt="">
      <p>{companyTagline}</p>
    </div>
    <div class="cover-text">
      <p class="cover-description">{description}</p>
      <span class="cover-cta">{callToAction}</span>
    </div>
  </a>
  <a href="{ad_via_link}" target="_blank" rel="noopener">
    ads via Carbon
  </a>
</div>

<script>
  // colors and URLs go into CSS, which escaping doesn't protect
  const cover = slot.querySelector('.cover');
  const hex = /^#[0-9a-f]{3,8}$/i.test(ad.backgroundColor)
    ? ad.backgroundColor : '#333';
  cover.style.setProperty('--bg', hex);
  cover.style.setProperty('--art', `url("${encodeURI(ad.largeImage)}")`);
</script>

04Track

Pixel, view and click

  • MustFire every pixel URL as a hidden 1×1 image.
  • MustCall statview once, after a full second in view.
  • MustLink to statlink, unchanged.

Pixel. Without it, the advertiser’s own ad server sees no impressions from your site. It can hold several URLs separated by ||. Replace every [timestamp]in each, and load each as an image rather than with fetch. Whether a pixel comes depends on the ad, not the format.

Viewability. The second starts when 30% of an ad of 242,500px² or more is on screen, or 50% of a smaller one. If it scrolls away first, start again.

Click. statlink records the click and redirects to the advertiser.

function firePixels(pixel, mount) {
  if (!pixel) return;
  // 10-second steps, as carbon.js sends
  const ts = Math.round(Date.now() / 1e4);
  for (const url of pixel.split('||')) {
    const img = new Image(1, 1);
    img.alt = ''; img.hidden = true;
    img.src = url.replaceAll('[timestamp]', ts);
    mount.append(img);
  }
}

function watchView(el, statview) {
  let inView = false, counting = false, timer;
  // a hidden tab keeps its intersection, so it stops the second too
  const check = () => {
    const now = inView && !document.hidden;
    if (now === counting) return;
    counting = now;
    clearTimeout(timer);
    if (now) timer = setTimeout(() => {
      io.disconnect();
      document.removeEventListener('visibilitychange', check);
      fetch(statview, { mode: 'no-cors' });
    }, 1000);
  };
  const io = new IntersectionObserver(([e]) => {
    // measured here, once the ad has laid out
    const { width, height } = e.boundingClientRect;
    inView = e.intersectionRatio >= (width * height >= 242500 ? 0.3 : 0.5);
    check();
  }, { threshold: [0, 0.3, 0.5, 1] });
  io.observe(el);
  document.addEventListener('visibilitychange', check);
}

05Go live

What’s yours to design

AreaYoursFixed by the format
LayoutSize, shape, spacing, breakpoints.Every field shown; images never cropped.
TypeWhich sans-serif, its size and weight.Sans-serif, white on Cover; text never cut short.
ColorBlur, wash strength, corners, shadow.Cover’s blurred wash of backgroundColor; images never recolored.
InteractionHow and when the description appears.The description reachable on every device; the click goes through statlink.
TrackingNothing.The pixel, viewability and click, as above.

Check it before going live

  • Each demo zone renders its format, and an edited empty response shows your own content.
  • One request per ad shown, and none outside production without ignore=yes.
  • Pixels fire, statview waits a full second, and the click opens statlink in a new tab.
  • “ads via Carbon” is visible, and no required field drops at your narrowest width.

When it’s ready, send us your staging address. We’ll serve to it and confirm that impressions, viewability and pixels arrive before anything goes live.

Updated