Specify docs

Browser SDK

Reference for the Advertiser browser SDK.

npm i @specify-sh/advertiser-sdk
import Specify from '@specify-sh/advertiser-sdk';

new Specify(config)

OptionRequiredDescription
advertiserKeyyesYour key, which starts with sak_
apiUrlnoLeave unset unless Specify gives you another API URL

Create one client and load it on every page, including the pages your ads link to. With a malformed key, every method does nothing.

Keep the spclk tracking parameter in the URL until the SDK has loaded, including through redirects. The SDK uses it to connect the visit to an ad click.

setCookieConsent(granted)

Passes on the visitor's consent for advertising. Call it on every page load once your consent manager knows the answer, and again whenever it changes.

It controls whether Specify uses its cookie. The SDK can still send events without cookies for visitors identified by a user ID, wallet address or ad click. For other visitors, the SDK waits for consent before sending events and drops them if consent is declined.

If your app requires consent before sending any data to Specify, wait for consent before calling identify() or capture().

identify(walletOrUserId)

Identifies the visitor. Call it when they sign in or connect a wallet, and on every page load while they're signed in.

  • A string starting with 0x is a wallet address. Anything else is your user ID.
  • A new user ID replaces the previous one. Wallets add up, and the 50 most recent are kept. Pass an array to add several at once. Anything in it that isn't an EVM wallet address, such as a Solana address, is skipped.
  • Use the same user ID your server passes to capture().
  • A user ID can't be blank, contain @ or be longer than 256 bytes. Invalid input is ignored.

reset()

Forgets the visitor. Call it when they sign out.

capture(event)

Records an event, such as signup, once the action has succeeded.

The SDK includes the current page URL with each event. It doesn't track page views or other events automatically.

Behaviour

  • Every method returns nothing and never throws, so a problem on Specify's side can't break your page.
  • Outside a browser, such as during a server render, every method does nothing. Use server events there.
  • Importing the client from a React Server Component fails the build, with a message pointing to the server entry.

Requests go to https://spfsrv.com. Add it to connect-src if your site has a Content Security Policy.

On this page