Checking service

The Swoop SDK (@swoopads/sdk)

Units in code, for React and plain JavaScript.

@swoopads/sdk is the same unit as typed functions, plus a React component, a web component and a small server helper. It replaces @gullylabs/ads, which stays as a thin copy that re-exports it.

A unit without a backend#

JavaScript
ts
import { mountUnit } from '@swoopads/sdk'

const unit = mountUnit(document.getElementById('sponsor'), {
  spot: 'pk_YOUR_SPOT_KEY',
  unit: 'native',   // banner | text | native
  size: '480x160',  // one listed size, exactly (or the biggest that fits)
  theme: 'auto',    // light | dark | auto
  onState: (state, { reason }) => console.log(state, reason),
})
// unit.refresh(), unit.destroy()
React
tsx
import { SwoopUnit } from '@swoopads/sdk/react'

export function Sponsor() {
  return <SwoopUnit spot="pk_YOUR_SPOT_KEY" unit="banner" size="728x90" theme="dark" />
}
Load the hosted tag
ts
import { loadTag } from '@swoopads/sdk'

// optional integrity pin: see the tag page for the current hash
const Swoop = await loadTag({ src: 'https://swoopads.xyz/t/1.1.0.js', integrity: 'sha384-TdTzA4ueOm72L7h6secO0fNlEegFSFA6ea7adoYFg4zAQ2203PAUwP1b2Kw0DCsg' })

mountUnit returns null and does nothing on a server, so it is safe in server-rendered code. In React, the component draws an empty box and fills it in the browser. It never throws; a callback of yours that throws is caught.

Options#

OptionValuesDefault
spotyour public Spot keynone
unitbanner, text, nativenative
themelight, dark, autoauto
slota spot idby kind
sizea listed size such as 728x90the biggest that fits
widthwidest size it may takethe element width
blocka CSS selector that keeps ads off the pagenone
page, creator, content, topictextnone
baseUrlthe API addressoffers.kre8.fun
onStatecallback (state, { reason })none

The signed client and the web component#

If you draw the ad yourself, the client asks for the ad, counts the view and click, and signs requests on your server so the Spot secret never reaches the browser. The element <swoop-ad-slot> (also <gully-ad-slot>) does this for you.

Your server
ts
import { createServeSigner } from '@swoopads/sdk/server'

const sign = createServeSigner({
  siteId: process.env.SWOOP_SPOT_KEY!,   // pk_…
  siteKey: process.env.SWOOP_SPOT_SECRET!, // sk_…  never in the browser
})
// POST /api/swoop/sign -> return await sign(req.body)
Your page
html
<script type="module">import '@swoopads/sdk/define'</script>
<swoop-ad-slot slot="home_feed" size="480x160" site="pk_YOUR_SPOT_KEY" sign-url="/api/swoop/sign"></swoop-ad-slot>

Moving from @gullylabs/ads#

  • Nothing breaks: @gullylabs/ads keeps working and re-exports everything from @swoopads/sdk.
  • New code should import from @swoopads/sdk (same names, plus SwoopAds for GullyAds).

The source and tests are in the open Gully Labs SDK repository, MIT licensed.