SDK Reference/Svelte / SvelteKit
Framework
@swake/web

Svelte / SvelteKit

Integration guide for Svelte / SvelteKit. Uses the @swake/web SDK, which works with any JavaScript framework or vanilla JS.

Overview

@swake/web is a framework-agnostic feedback SDK — one core client plus an optional UI widget layer (@swake/web/ui) that renders a trigger button, feedback form, history panel, and survey modals inside a Shadow DOM. In Svelte apps, wrap the SDK lifecycle in a store (see the Svelte Store Pattern below) to get reactive identity and unread-count state throughout your components.

A few concepts come up throughout this guide:

ConceptWhat it is
apiKeyYour project's key, the only required option to Swake.init().
identify()Links feedback, surveys, and notifications to a user. Almost everything downstream depends on it.
Offline queueSubmissions are queued in localStorage and retried automatically — this happens for every call, with no extra code.
ThemeA single theme object, referenced by nearly every widget, applied as CSS custom properties.

Getting Started

Requirements

Svelte4.0 or later (Svelte 5 supported)
SvelteKit2.0 or later (optional — for SSR apps)
BundlerVite (recommended)
BrowserChrome 80+, Firefox 78+, Safari 14+, Edge 80+
Node.js18+ (for build tooling only — SDK runs in browser)

Installation

bash
npm install @swake/web-swake-sdk
# or
yarn add @swake/web-swake-sdk
# or
pnpm add @swake/web-swake-sdk

The package exports two entry points:

ImportPurpose
@swake/webCore SDK — init, identify, submit, notifications, surveys, breadcrumbs
@swake/web/uiVisual widgets — trigger FAB, feedback form, feedback history panel, survey modals (rendered in Shadow DOM)

The @swake/web/ui import is a side-effect — just import it once and it automatically hooks into the SDK. No extra setup required.


Svelte + Vite

For a plain Svelte app (no SvelteKit), initialise the SDK in your entry point. This is the minimal setup to get a working trigger button and feedback form.

src/main.ts
import Swake from '@swake/web';
import '@swake/web/ui';
import App from './App.svelte';

Swake.init({
  apiKey: import.meta.env.VITE_SWAKE_API_KEY,
  appVersion: import.meta.env.VITE_APP_VERSION || '1.0.0',
});

const app = new App({ target: document.getElementById('app')! });
export default app;

That's it — a floating trigger button appears in the bottom-right corner. Clicking it opens the feedback form.

Full init options

Swake.init() accepts a single configuration object. Every property except apiKey is optional.

typescript
Swake.init({
  apiKey: import.meta.env.VITE_SWAKE_API_KEY, // required
  baseUrl: 'https://api.swake.io',       // optional — override for self-hosted or a proxy
  debug: false,                          // enable verbose console logs
  appVersion: '1.0.0',                   // shown in the portal per submission
  autoCapture: {
    browserInfo: true,                   // attach browser/OS info to submissions
  },
  surveys: {
    enabled: true,                       // fetch & show eligible surveys
    autoShow: true,                      // auto-show after identify()
    delay: 3000,                         // ms before auto-show
    cooldown: 86_400_000,                // ms between surveys (default: 24h)
  },
  breadcrumbs: {
    enabled: true,                       // attach breadcrumb trail to submissions
    maxEntries: 50,                      // ring buffer size (max 100)
    captureNavigation: true,             // History API pushState/popstate
    captureNetwork: true,                // fetch() and XMLHttpRequest
    captureConsole: true,                // console.warn / console.error
    captureClicks: true,                 // element click events
  },
  trigger: {
    position: 'bottom-right',            // 'bottom-left' | 'top-right' | 'top-left'
    icon: 'chat',                        // 'feedback' | 'bug' | 'idea'
    label: 'Feedback',                   // tooltip text
    hidden: false,                       // start hidden, show later
    zIndex: 999999,
    style: {
      backgroundColor: '#059669',
      size: 56,                          // px
      borderRadius: 28,                  // px
      shadow: true,
    },
  },
  theme: { /* see Theme Customization section */ },
  onLimitReachedMode: 'default_ui',      // 'silent' | 'callback_only'
  onLimitReached: (event) => {
    console.warn(event.limitKey, event.message);
  },
});
Full reference:

SvelteKit Setup

Swake is browser-only. In SvelteKit, use the client hooks file to initialise the SDK so it never runs during SSR.

src/hooks.client.ts
import Swake from '@swake/web';

async function initSwake() {
  await import('@swake/web/ui');

  Swake.init({
    apiKey: import.meta.env.PUBLIC_SWAKE_API_KEY,
    appVersion: import.meta.env.PUBLIC_APP_VERSION || '1.0.0',
    surveys: {
      enabled: true,
      autoShow: true,
      delay: 3000,
      cooldown: 86_400_000,
    },
    breadcrumbs: {
      captureNavigation: true,
      captureNetwork: true,
      captureConsole: true,
      captureClicks: true,
    },
    trigger: { position: 'bottom-right' },
  });
}

initSwake();

Identify users in the root layout

src/routes/+layout.svelte
<script lang="ts">
  import { page } from '$app/stores';
  import Swake from '@swake/web';

  $: if ($page.data.user) {
    Swake.identify({
      userId: $page.data.user.id,
      email: $page.data.user.email,
      name: $page.data.user.name,
    });
  } else {
    Swake.clearIdentity();
  }
</script>

<slot />

The hooks.client.ts file only runs in the browser — no if (browser) guards needed. The SDK never accesses window or document at import time, so SSR builds won't error even if it's accidentally imported server-side.


Svelte Store Pattern

For production apps, wrap the SDK lifecycle in a Svelte store. This gives you reactive state for the identified user and unread notification count, and handles notification polling automatically.

src/lib/stores/swake.ts
import { writable, readonly } from 'svelte/store';
import Swake from '@swake/web';

const _userId = writable<string | null>(null);
const _unreadCount = writable(0);
let pollTimer: ReturnType<typeof setInterval> | null = null;

async function refreshUnread() {
  let uid: string | null = null;
  _userId.subscribe((v) => (uid = v))();
  if (!uid) return;
  try {
    const count = await Swake.getUnreadCount();
    _unreadCount.set(count);
  } catch { /* non-fatal */ }
}

function startPolling() {
  stopPolling();
  void refreshUnread();
  pollTimer = setInterval(() => void refreshUnread(), 60_000);
}

function stopPolling() {
  if (pollTimer) {
    clearInterval(pollTimer);
    pollTimer = null;
  }
}

export const userId = readonly(_userId);
export const unreadCount = readonly(_unreadCount);

export async function identify(
  uid: string,
  email?: string,
  name?: string,
  metadata?: Record<string, string>,
) {
  await Swake.identify({ userId: uid, email, name, metadata });
  _userId.set(uid);
  startPolling();
}

export function clearIdentity() {
  Swake.clearIdentity();
  _userId.set(null);
  _unreadCount.set(0);
  stopPolling();
}

Use the store in any component

src/lib/components/Header.svelte
<script lang="ts">
  import Swake from '@swake/web';
  import { userId, unreadCount, clearIdentity } from '$lib/stores/swake';
</script>

<header>
  {#if $userId}
    <span>Notifications: {$unreadCount}</span>
    <button on:click={() => Swake.showFeedbackForm()}>Feedback</button>
    <button on:click={clearIdentity}>Log out</button>
  {/if}
</header>

Identifying Users

Call Swake.identify() after your user logs in. This links all feedback, survey responses, and notifications to that user in the Swake portal.

typescript
await Swake.identify({
  userId: 'user_123',         // required — your app's user ID
  email: 'jane@example.com',  // optional
  name: 'Jane Smith',         // optional
  metadata: {                 // optional — arbitrary key-value pairs
    plan: 'pro',
    company: 'Acme Corp',
  },
});
ParameterTypeDescription
userIdstringYour app's unique user ID (required)
emailstringUser's email. Preserved if omitted on subsequent calls.
namestringUser's display name. Preserved if omitted on subsequent calls.
metadataRecord<string, string>Custom key-value pairs. Fully replaced on each call — send the complete set.

Clearing identity on logout

typescript
Swake.clearIdentity();

This wipes the stored user ID and clears the offline queue. Always call this when the user logs out.


Feedback

Feedback Form

Open the built-in feedback form widget. Requires the @swake/web/ui import. The form includes a type selector (Bug / Idea / Help), title and description fields, and a drag-and-drop file upload zone.

typescript
import Swake from '@swake/web';

// Default form
Swake.showFeedbackForm();

// With options
Swake.showFeedbackForm({
  defaultType: 'feature',           // pre-select type: 'bug' | 'feature' | 'question'
  showTypeSelector: true,           // show/hide the Bug/Idea/Help toggle (default: true)
  title: "What's on your mind?",    // header text
  placeholder: 'Tell us more...',   // textarea placeholder
  theme: { primaryColor: '#8B5CF6' }, // per-call theme override
});
OptionTypeDefaultDescription
defaultType'bug' | 'feature' | 'question''bug'Pre-selected feedback type
showTypeSelectorbooleantrueShow the type toggle buttons
titlestring"What's on your mind?"Header text above the form
placeholderstring'Tell us more...'Description textarea placeholder
themeSwakeWebThemeglobal themeOverride theme for this widget only

Example: custom trigger button

Hide the built-in FAB and wire the form to your own button:

src/lib/components/FeedbackButton.svelte
<script lang="ts">
  import Swake from '@swake/web';

  function openBugReport() {
    Swake.showFeedbackForm({ defaultType: 'bug' });
  }

  function openFeatureRequest() {
    Swake.showFeedbackForm({
      defaultType: 'feature',
      title: 'What would you like to see?',
      placeholder: 'Describe the feature...',
    });
  }
</script>

<button on:click={openBugReport}>Report a Bug</button>
<button on:click={openFeatureRequest}>Request a Feature</button>

<!-- In your init config, hide the built-in trigger: -->
<!-- trigger: { hidden: true } -->

Submitting Feedback

Submit feedback programmatically without showing any UI. Browser info and breadcrumbs are automatically attached.

typescript
import Swake from '@swake/web';

const submission = await Swake.submitFeedback({
  type: 'bug',                                      // 'bug' | 'feature' | 'question'
  title: 'Search returns no results',                // required
  description: 'Reproducible on Safari + macOS 14.', // optional
  attachments: [                                      // optional — File objects
    { file: screenshotFile },
  ],
});

console.log('Created:', submission.id);
ParameterTypeDescription
type'bug' | 'feature' | 'question'Submission category (required)
titlestringBrief summary (required)
descriptionstringDetailed description
attachments{ file: File }[]File objects from <input type="file">, drag-and-drop, or clipboard
customFieldsRecord<string, string>Project custom field values as a { fieldId: value } map — fetch definitions with getCustomFields(); required fields enforced

Example: feedback form component

src/lib/components/BugReportForm.svelte
<script lang="ts">
  import Swake from '@swake/web';

  let title = '';
  let description = '';
  let file: File | null = null;
  let submitting = false;

  function onFileChange(event: Event) {
    const input = event.target as HTMLInputElement;
    file = input.files?.[0] ?? null;
  }

  async function onSubmit() {
    submitting = true;
    try {
      await Swake.submitFeedback({
        type: 'bug',
        title,
        description,
        attachments: file ? [{ file }] : undefined,
      });
      title = '';
      description = '';
      file = null;
    } finally {
      submitting = false;
    }
  }
</script>

<form on:submit|preventDefault={onSubmit}>
  <input bind:value={title} placeholder="What went wrong?" required />
  <textarea bind:value={description} placeholder="Steps to reproduce..." />
  <input type="file" accept="image/*,.pdf" on:change={onFileChange} />
  <button type="submit" disabled={submitting}>Submit Bug Report</button>
</form>

Feedback History

Show a panel listing the current user's past submissions with status badges and a detail view with replies (including auto-translated team responses). Requires the user to be identified.

typescript
// Open the feedback history panel
Swake.showFeedbackHistory();

Programmatic access

You can also fetch history data directly to build your own UI:

typescript
// Lightweight list (id, title, status, type, createdAt)
const { submissions, hasMore, cursor } = await Swake.getHistory({ limit: 20 });

// Full submission detail with comments + attachments
const submission = await Swake.getSubmission('submission_id');

// Paginated submission list with more fields
const result = await Swake.listSubmissions({ limit: 10 });

Trigger Button (FAB)

When you import @swake/web/ui, a floating action button appears in the corner of your page. Clicking it opens the feedback form. Configure it via the trigger option in Swake.init().

typescript
Swake.init({
  apiKey: 'ep_live_...',
  trigger: {
    position: 'bottom-right',     // 'bottom-left' | 'top-right' | 'top-left'
    icon: 'chat',                 // 'feedback' | 'bug' | 'idea'
    label: 'Feedback',            // tooltip text
    hidden: false,                // start hidden
    zIndex: 999999,               // container z-index
    style: {
      backgroundColor: '#059669', // FAB background color
      size: 56,                   // diameter in px
      borderRadius: 28,           // px
      shadow: true,               // drop shadow
    },
  },
});

Show / hide at runtime

typescript
// Hide the FAB (e.g. during checkout)
Swake.setTriggerVisible(false);

// Show it again
Swake.setTriggerVisible(true);

Programmatic open / close

typescript
// Open the feedback form
Swake.open();

// Close any open widget (form, history, survey)
Swake.close();

Example: hiding during SvelteKit navigation

src/routes/+layout.svelte
<script lang="ts">
  import { page } from '$app/stores';
  import Swake from '@swake/web';

  const hiddenRoutes = ['/checkout', '/onboarding'];

  $: {
    const hide = hiddenRoutes.some((r) => $page.url.pathname.startsWith(r));
    Swake.setTriggerVisible(!hide);
  }
</script>

<slot />

All widgets are rendered inside a closed Shadow DOM container. Your app's CSS never leaks in, and widget styles never leak out.


Engagement

Surveys & NPS

Swake can show surveys, NPS polls, and multiple-choice polls to your users. Surveys are created in the Swake portal, and the SDK handles targeting, display, and response submission.

Configuration

typescript
Swake.init({
  apiKey: 'ep_live_...',
  surveys: {
    enabled: true,        // fetch eligible surveys (default: true)
    autoShow: true,       // auto-show after identify() (default: true)
    delay: 3000,          // ms before auto-show (default: 3000)
    cooldown: 86_400_000, // ms between surveys (default: 24h)
  },
});

Manual control

typescript
// Re-check eligibility and show the first match
await Swake.checkSurveys();

// Show a specific survey by ID (ignores cooldown)
await Swake.showSurvey('survey_abc123');

Event listeners

typescript
Swake.onSurveyShown((event) => {
  console.log('Survey shown:', event.id, event.type);
});

Swake.onSurveyCompleted((event) => {
  console.log('Completed:', event.survey.id, 'answers:', event.response.answers);
});

Swake.onSurveyDismissed((event) => {
  console.log('Dismissed:', event.id);
});

Example: tracking survey events

src/hooks.client.ts
import Swake from '@swake/web';

// Register survey event listeners alongside init
Swake.onSurveyCompleted((event) => {
  // Send to your analytics provider
  analytics.track('survey_completed', {
    surveyId: event.survey.id,
    surveyType: event.survey.type,
    answerCount: event.response.answers.length,
  });
});

Swake.onSurveyDismissed((event) => {
  analytics.track('survey_dismissed', { surveyId: event.id });
});

Survey targeting (user traits, segments, days active) is evaluated server-side. The SDK caches eligible surveys per project for 5 minutes.


Voting Board

Let users browse and vote on public board items (feature requests, roadmap items). Fetching items does not require identification, but voting does.

typescript
import Swake from '@swake/web';

// Fetch board items
const { items, hasMore } = await Swake.getBoardItems('public-roadmap', {
  sort: 'votes',      // 'votes' | 'recent'
  status: 'open',     // 'open' | 'in_progress' | 'resolved' | 'closed'
  page: 1,            // 1-based pagination
});

// Cast a vote (requires identify)
const { status, voteCount } = await Swake.vote('public-roadmap', 'item_id');
// status: 'voted' | 'already_voted' | 'error'

// Remove a vote
const result = await Swake.removeVote('public-roadmap', 'item_id');
// result.status: 'removed' | 'not_voted' | 'error'

Example: voting board component

src/lib/components/RoadmapBoard.svelte
<script lang="ts">
  import { onMount } from 'svelte';
  import Swake from '@swake/web';

  let items: any[] = [];

  onMount(async () => {
    const result = await Swake.getBoardItems('public-roadmap', { sort: 'votes' });
    items = result.items;
  });

  async function toggleVote(item: any) {
    if (item.hasVoted) {
      await Swake.removeVote('public-roadmap', item.id);
      item.hasVoted = false;
      item.voteCount--;
    } else {
      await Swake.vote('public-roadmap', item.id);
      item.hasVoted = true;
      item.voteCount++;
    }
    items = items; // trigger reactivity
  }
</script>

{#each items as item (item.id)}
  <div class="roadmap-item">
    <button on:click={() => toggleVote(item)}>
      {item.hasVoted ? 'Voted' : 'Vote'} ({item.voteCount})
    </button>
    <h3>{item.title}</h3>
    <span>{item.status}</span>
  </div>
{/each}

Notifications

Notifications

The SDK provides in-app notifications for status changes and team replies. When using @swake/web/ui, the trigger FAB shows an unread badge automatically (polled every 60 seconds).

Programmatic API

typescript
// Get unread count
const count = await Swake.getUnreadCount();

// List notifications
const { notifications, pagination } = await Swake.listNotifications({
  unreadOnly: true,  // only unread (default: false)
  limit: 20,
  cursor: undefined, // for pagination
});

// Mark as read
await Swake.markNotificationRead('notification_id');

// Mark all as read
await Swake.markAllNotificationsRead();

Polling in Svelte

The Svelte Store pattern above handles polling via unreadCount. If you're not using the store, poll manually:

src/lib/components/NotificationBadge.svelte
<script lang="ts">
  import { onMount, onDestroy } from 'svelte';
  import Swake from '@swake/web';

  let count = 0;
  let timer: ReturnType<typeof setInterval> | null = null;

  async function poll() {
    try {
      count = await Swake.getUnreadCount();
    } catch { /* non-fatal */ }
  }

  onMount(() => {
    void poll();
    timer = setInterval(() => void poll(), 60_000);
  });

  onDestroy(() => {
    if (timer) clearInterval(timer);
  });
</script>

{#if count > 0}
  <span class="badge">{count}</span>
{/if}

Customization

Theme Customization

Pass a theme object in Swake.init() to brand the trigger button, feedback form, survey modal, and feedback history panel. Theme tokens are applied as CSS custom properties on the Shadow DOM root — works identically in both Svelte + Vite and SvelteKit.

typescript
Swake.init({
  apiKey: import.meta.env.VITE_SWAKE_API_KEY,
  theme: {
    primaryColor: '#8B5CF6',       // buttons, active states, FAB
    successColor: '#10B981',       // success states
    dangerColor: '#EF4444',        // error states, destructive actions
    backgroundColor: '#FFFFFF',    // panel backgrounds
    surfaceColor: '#F8FAFC',       // cards, input backgrounds
    overlayColor: 'rgba(15,23,42,0.4)', // backdrop
    textColor: '#0F172A',          // primary text
    textSecondary: '#64748B',      // muted text, labels
    borderColor: '#E2E8F0',        // input borders, dividers
    borderRadius: 12,              // px — applied to panels, inputs, buttons
    fontFamily: 'Inter, sans-serif',
  },
});

Available tokens

TokenDefaultDescription
primaryColor#6366F1Buttons, active states, FAB background
successColor#10B981Success checkmark, resolved badges
dangerColor#EF4444Error borders, destructive actions
backgroundColor#FFFFFFModal / panel background
surfaceColor#F9FAFBInput fields, secondary surfaces
overlayColorrgba(0,0,0,0.45)Backdrop behind modals
textColor#111827Primary text
textSecondary#6B7280Labels, placeholders, metadata
borderColor#E5E7EBInput borders, dividers
borderRadius8Corner radius for inputs and buttons
fontFamilySystem defaultFont family applied to all text

Per-call overrides

showFeedbackForm() accepts an optional theme that merges on top of the global theme for that widget instance only.

typescript
Swake.showFeedbackForm({
  theme: { primaryColor: '#0EA5E9' },
});

Shadow DOM isolation: theme tokens are scoped to the Swake widget root via CSS custom properties (--swake-primary, --swake-bg, etc.) and never leak into your application styles.



Offline

Offline Queue

When the user is offline, submissions are queued in localStorage and automatically retried when connectivity returns. The queue starts processing on Swake.init() and stops on Swake.destroy().

typescript
import { offlineQueue } from '@swake/web';

// Check queue size (e.g. show a badge)
const pending = offlineQueue.size();

// Force a flush attempt
await offlineQueue.flush();

Swake.clearIdentity() clears the offline queue. Always call it on logout to prevent queued items from being sent after a different user logs in.


AI Setup

Using Claude Code

Prefer to let an AI coding agent do the wiring? Run Claude Code from the root of your Svelte or SvelteKit project and paste the prompt below. It reads this page as the source of truth, detects your stack, asks you for your API key and anything else it needs, then wires up @swake/web, init(), identify(), the widgets, and theming — in one shot.

Prerequisites

Before you run the prompt, set up your project in the Swake portal and grab the values the agent will ask for — it only writes placeholders to your env files, so you supply the real values yourself.

  1. Sign in to the Swake portal and create a project (or open an existing one).
  2. In Project settings → API keys, get existing or create a key and copy it — it's shown once and starts with ep_live_.
  3. If you want the voting board, create a board and copy its slug from the board's URL / settings.

Have these ready when the agent prompts you — the same values you'd otherwise wire up by hand:

ValueWhere to find itExample
apiKeyProject settings → API keysep_live_…
baseUrlAPI endpoint — optional, only needed when self-hosting or routing through your own backendhttps://api.swake.io
boardSlugVoting board settings — optional; passed to getBoardItems() / vote(), not init()public-roadmap

The prompt is additive and safe: a Swake or network error must never break your app's boot or existing behavior. The agent pauses and asks before installing packages or writing secrets, and it never guesses APIs that aren't in these docs. It also asks whether to keep your ep_live_ key server-side behind your own backend — the recommended setup for any app that has one, since the key never reaches the browser and the submitting user can't be spoofed.

The prompt

Run Claude Code from your project root and paste this. It targets Svelte / SvelteKit specifically, and re-reads this guide before it writes anything, so it stays correct as the SDK evolves.

Claude prompt
Fully integrate the Swake feedback SDK (feedback forms, bug reports, surveys/NPS, in-app notifications, voting boards) into this Svelte app. Treat it as additive: a Swake or network failure must NEVER break boot or any existing behavior. Never invent or fake an API that is not in the docs.

1. READ THE DOCS FIRST — they are the source of truth for the package, init/identify, the widget layer and every option. Fetch with a browser User-Agent (a plain fetch returns 403): curl -sL -A "Mozilla/5.0" "https://swake.io/docs/sdk?framework=svelte". Determine whether this is SvelteKit or plain Svelte + Vite and say which you found — the entry point and the env prefix both differ.
2. ASK BEFORE DECIDING ANYTHING (AskUserQuestion): (a) integration mode — DIRECT, meaning the ep_live_ key ships in the browser via PUBLIC_SWAKE_API_KEY for SvelteKit or VITE_SWAKE_API_KEY for plain Vite (fine for a static or SPA-only app), or PROXY, meaning the key stays server-side in a backend you control (recommended whenever a backend exists — see step 4); (b) the API key or proxy path, an optional baseUrl, and a voting-board slug if they want the board. Write PLACEHOLDERS ONLY into env files (and the .example alongside) — never commit a real key. ASK again before installing any package.
3. INSTALL AT THE CLIENT ENTRY — add @swake/web. In SvelteKit put the wiring in src/hooks.client.ts, which only ever runs in the browser; in plain Svelte + Vite put it in src/main.ts. Read config from $env/static/public (SvelteKit) or import.meta.env (Vite). Load the widgets with await import('@swake/web/ui') so they stay out of the initial bundle, and never import them from a module that also runs on the server.
4. INIT EXACTLY ONCE, IDEMPOTENTLY — keep a module-level "let initPromise: Promise<void> | null" and have every caller await the SAME promise. This is required, not stylistic: the SDK exposes no isInitialized(), every method throws "[Swake] SDK not initialized" before init(), and a second init() starts a second offline-queue flush interval without clearing the first. Swake.init() itself is synchronous. PROXY mode: pass any non-empty placeholder as apiKey, point baseUrl at a SvelteKit endpoint you add at src/routes/api/swake/[...path]/+server.ts, which forwards method, path, query and body to the Swake API, and set credentials: 'include'. That backend attaches the real X-API-Key server-side, overrides any client-supplied externalUserId with the session user so identity cannot be spoofed, and must allow X-API-Key and Idempotency-Key through CORS. Set trigger: { hidden: true } if the app will open feedback from its own button instead of the floating one.
5. IDENTITY — after init resolves, call Swake.identify({ userId, email, name, metadata }) on EVERY load that has a session, not just on the login event: identity is held in memory only, so a page refresh loses it. userId must be your stable internal id, and every metadata value must be a string. On logout call Swake.clearIdentity() inside a try/catch — it throws if init never ran. Drive it from a store subscription or a reactive statement on the session in +layout.svelte, so a session restored during hydration identifies as well as a fresh login.
6. POLISH — drive Swake.setTheme() from the app's light/dark toggle (widgets otherwise keep the theme captured at init); gate init/identify by route so an auto-shown survey can never land on login, signup, or onboarding; add Swake.addBreadcrumb() at meaningful domain events so bug reports arrive with context.
7. VERIFY & REPORT — funnel every SDK call through one wrapper with try/catch, then prove it end to end: the trigger opens the form, a real submission appears in the Swake dashboard, and no survey shows on an auth or onboarding route. Report the files you changed, any manual steps left for me, and every assumption you made. Confirm it against a real build (vite build && vite preview), not just dev, so any server-side evaluation of the widget layer surfaces.

Reference

Full API Reference

Click any method for its full signature, parameters, and an example.

MethodDescription
Initialise the SDK. Must be called once before any other method.
Link the current user. Returns a Promise.
Clear user identity and offline queue.
Replace the global UI theme at runtime.
Submit feedback programmatically (with optional customFields). Returns the created Submission.
Fetch the project's custom field definitions for a custom feedback UI.
Open the built-in feedback form widget.
Open the feedback history panel.
Open the feedback form (alias).
Close any open widget (form, history, survey).
Show or hide the trigger FAB.
List the current user's submissions.
Get full submission detail with comments + attachments.
Edit a submission you own.
Unpublish a submission you own (one-way).
Lightweight submission history (id, title, status, type, createdAt).
Get unread notification count.
List notifications with pagination.
Mark a single notification as read.
Mark all notifications as read.
Re-check survey eligibility and show the first match.
Show a specific survey (ignores cooldown).
Register survey-shown event listener.
Register survey-completed event listener.
Register survey-dismissed event listener.
Fetch voting board items.
Cast a vote on a board item.
Remove a vote from a board item.
Add a custom breadcrumb to the trail.
Return a snapshot of the breadcrumb trail.
Clear the breadcrumb ring buffer.
Register plan-limit event listener.
Tear down all listeners, timers, and UI.