Browser SDK
Reference for the Advertiser browser SDK.
npm i @specify-sh/advertiser-sdkimport Specify from '@specify-sh/advertiser-sdk';new Specify(config)
| Option | Required | Description |
|---|---|---|
advertiserKey | yes | Your key, which starts with sak_ |
Create one client and load it on every page, including the pages your ads link to. With a malformed key, every method does nothing.
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.
Nothing is sent until the first call. After that, events are sent whether the visitor consented or not.
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
0xis 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.
- 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. Events captured before the first setCookieConsent() call are sent once it's made.
Behaviour
- Every method returns nothing and never throws, so a problem on Specify's side can't break your page.
- Failed requests are retried.
- 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.