Solid

Identify visitors in Solid or SolidStart with signals from @trace-id/sdk-solid.

10 minutes

This quickstart adds Trace to a SolidJS or SolidStart app with @trace-id/sdk-solid. You wrap the app in a provider once, read signals in a component, and send the eventId to your backend for verification.

Before you start

You need a running Trace server and a public key (pk_...) whose allowed origins include your app. The quick start guide covers both.

  1. 1

    Install the SDK

    npm install @trace-id/sdk-solid
  2. 2

    Add the provider

    TSX
    // src/index.tsx
    import { render } from 'solid-js/web';
    import { IdentifyProvider } from '@trace-id/sdk-solid';
    import App from './App';
    
    render(
      () => (
        <IdentifyProvider apiKey={import.meta.env.VITE_TRACE_PUBLIC_KEY} endpoint={import.meta.env.VITE_TRACE_ENDPOINT}>
          <App />
        </IdentifyProvider>
      ),
      document.getElementById('root')!,
    );

    In SolidStart, put the provider in app.tsx. Nothing runs during server rendering; collection starts in the browser.

  3. 3

    Identify on submit

    createVisitorData returns data, error and isLoading as signals, and getData() to identify on demand. Call it in a component body.

    TSX
    // SignupForm.tsx
    import { createSignal } from 'solid-js';
    import { createVisitorData } from '@trace-id/sdk-solid';
    
    export function SignupForm() {
      const [email, setEmail] = createSignal('');
      const visitor = createVisitorData({ immediate: false });
    
      async function submit(e: SubmitEvent) {
        e.preventDefault();
        const result = await visitor.getData({ tags: { action: 'signup' } }); // null if Trace is unavailable
        await fetch('/api/signup', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ email: email(), eventId: result?.eventId }),
        });
      }
    
      return (
        <form onSubmit={submit}>
          <input type="email" required value={email()} onInput={(e) => setEmail(e.currentTarget.value)} />
          <button disabled={visitor.isLoading()}>Create account</button>
        </form>
      );
    }

    getData never throws. On failure it resolves null and error() holds an IdentifyError with a code. Use useIdentifyClient() for consent toggles (enable(), disable(true)).

  4. 4

    Verify on your server

Next steps

Suggest an edit

Spotted something wrong or unclear? Tell us on GitHub and we will fix it.