Specify docs

React

Track conversions in a React app.

Set up with the wizard

Make sure your coding agent (such as Claude Code or Codex) is installed and signed in, then run this from your project directory:

npx @specify-sh/wizard --advertiser

The wizard uses your coding agent to inspect the project and plan the SDK integration. Review the plan and choose which events to capture before it makes changes.

After it finishes, review the uncommitted changes and replace sak_your_key_here with your advertiser key in the env file it names. Then follow the verification steps below.

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/advertiser-sdk

2. Create the client

You will need an advertiser key. See Advertiser keys.

Create the client in its own module, outside any component, so the whole app shares one client.

lib/specify.ts
import Specify from '@specify-sh/advertiser-sdk';

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

Wire your consent manager to the SDK high in the component tree. Pass the answer it already has, then every change. It decides only whether Specify's cookie is used.

The SDK can still send events without cookies for visitors identified by a user ID, wallet address or ad click. See how consent works.

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

// Adapt this to your consent manager
export function ConsentBridge() {
  useEffect(() => {
    specify.setCookieConsent(cmp.getConsent().advertising);

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

  return null;
}

4. Identify the visitor

Identify the signed-in user and any connected wallet, on every page load.

components/IdentityBridge.tsx
import { useEffect } from 'react';
import { useAccount } from 'wagmi';
import { useUser } from '../auth';
import { specify } from '../lib/specify';

export function IdentityBridge() {
  const user = useUser();
  const { address } = useAccount();

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

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

  return null;
}

Use your own user ID, not an email address, and give each person their own. Call specify.reset() in your sign-out handler.

5. Capture conversions

Capture an event once the action has succeeded.

components/SignupForm.tsx
import { specify } from '../lib/specify';

async function onSubmit(form: SignupForm) {
  await createAccount(form);
  specify.capture('signup');
}

If your server confirms the conversion, capture it there instead.

6. Check it works

Use a development key and open your browser's network panel. Requests to spfsrv.com/v1/identify and spfsrv.com/v1/events should return 200, and each event you capture appears in the event log on the Integration page within a few seconds. Development events never count towards your results.

Once your organization is approved, switch to a production key, run one test conversion yourself and confirm the Integration page shows it as your last production event.

Next steps

On this page