Specify docs

React

Add Specify to a React app.

Set up with the wizard

npx @specify-sh/wizard --publisher

The wizard runs through the coding agent you already use (Claude Code, Codex etc.). It inspects your codebase, proposes an integration plan and implements it as a reviewable diff.

Prefer to do it by hand? The manual steps below are the same setup.

Manual setup

Runnable example

react-typescript is this guide as a working Vite and wagmi app.

1. Install the SDK

npm i @specify-sh/publisher-sdk

2. Initialize the client

You will need a publisher key. See Publisher keys.

Create the client once and import it wherever you serve an ad. Read the publisher key from your environment, here a Vite variable in .env.

lib/specify.js
import Specify from '@specify-sh/publisher-sdk';

export const specify = new Specify({
  publisherKey: import.meta.env.VITE_SPECIFY_PUBLISHER_KEY
});

Wire your consent platform to the SDK, high in the component tree. The SDK never stores consent, so pass it on every page load.

components/ConsentBridge.jsx
import { useEffect } from 'react';
import { specify } from '../lib/specify';

// Adapt this code to your cookie consent management tool
export function ConsentBridge() {
  useEffect(() => {
    specify.setCookieConsent(cmp.getConsent().targetedAdvertising);

    return cmp.onConsentChange((consent) => {
      specify.setCookieConsent(consent.targetedAdvertising);
    });
  }, []);

  return null;
}

With consent, Specify recognises visitors across its network, so a placement can fill even for a visitor who hasn't connected a wallet to your app.

4. Register connected wallets

If your app has a wallet connection flow, notify the SDK when a wallet is connected. Every later serve() includes it, so components deeper in the tree do not need the address passed down.

components/WalletBridge.jsx
import { useEffect } from 'react';
import { useAccount } from 'wagmi';
import { specify } from '../lib/specify';

export function WalletBridge() {
  const { address } = useAccount();

  useEffect(() => {
    if (address) specify.identify(address);
  }, [address]);

  return null;
}

5. Build an ad component

useSpecifyAd() serves on mount, tries again when the identity improves, and keeps the first ad it gets.

components/AdSlot.jsx
import { ImageFormat } from '@specify-sh/publisher-sdk';
import { useSpecifyAd } from '@specify-sh/publisher-sdk/react';
import { specify } from '../lib/specify';

export function AdSlot() {
  const ad = useSpecifyAd({
    specify,
    imageFormat: ImageFormat.LANDSCAPE,
    adUnitId: 'sidebar'
  });

  if (!ad) return null;

  return (
    <a href={ad.ctaUrl} target="_blank" rel="noopener noreferrer">
      {ad.imageUrl && <img src={ad.imageUrl} alt="" />}
      <h3>{ad.headline}</h3>
      <p>{ad.content}</p>
      <span>{ad.ctaLabel}</span>
    </a>
  );
}

To serve against an address you hold in the component, pass it first:

const ad = useSpecifyAd(address, { specify, imageFormat: ImageFormat.LANDSCAPE });

Pass every address the visitor controls, not just the active one. Anything that isn't an EVM address, such as a Solana address, is skipped. More wallets means better targeting.

const ad = useSpecifyAd([address, ...linkedAddresses], {
  specify,
  imageFormat: ImageFormat.LANDSCAPE
});

Available image formats and the fields returned in the ad can be found in the Browser SDK reference.

Check it works

With a development key you get rotating sample ads, and nothing reaches your reporting.

  1. Load a page with a slot and confirm a sample ad renders, labelled as sponsored. See Label every ad.
  2. Click the call to action and confirm it opens ctaUrl.
  3. Check what happens when serve() returns null: the slot should render nothing, not an empty box.

How impressions and clicks count

  • An impression counts when Specify serves the ad, so only ask for one when the slot is on the page and about to be shown.
  • Repeats don't add up. The same visitor gets the same ad for a day in each image format, and counts once. See Payments.
  • A click counts when the visitor follows ctaUrl. Link your call to action to it exactly as given, without rewriting it.

Next steps

On this page