Functions
All exported functions from @kelpclick/client - signatures, return types, and purpose.
createKelpClient
function createKelpClient(config: KelpClientConfig): KelpClientCreates the umbrella client composing search and analytics transport. Throws immediately if apiKey, searchUrl, or analyticsUrl are missing.
Returns { search, browse, suggest, trackEvents, identify }.
import { createKelpClient } from '@kelpclick/client';
const kelp = createKelpClient({
searchUrl: 'https://{TENANT_ID}-search.kelp.click',
analyticsUrl: 'https://{TENANT_ID}-events.kelp.click',
apiKey: 'kelp_...',
});Client methods
The object returned by createKelpClient exposes:
| Method | Signature | Purpose |
|---|---|---|
search | <TDoc>(collection, params: SearchParams, opts?) => Promise<KelpSearchResponse<TDoc>> | Full-text search a collection. q is required. Optional semanticWeight opts into semantic ranking when the collection flag is on. |
browse | <TDoc>(collection, params?: BrowseParams, opts?) => Promise<KelpSearchResponse<TDoc>> | Filter/sort a collection without a query (category pages). |
suggest | <TDoc>(collection, params: SuggestParams, opts?) => Promise<KelpSearchResponse<TDoc>> | Autocomplete suggestions. Throws KelpNotImplementedError until the endpoint ships. |
trackEvents | (events: KelpAnalyticsEvent[], opts?) => Promise<void> | Low-level: POST a batch of fully-formed events. The SDK generates the batch id automatically. |
identify | (traits: IdentifyTraits) => Promise<void> | Record a known user server-side. Throws KelpNotImplementedError until the endpoint ships. Use createIdentity().identify() for local identity now. |
createKelpSearch
function createKelpSearch(config: KelpClientConfig): KelpSearchLightweight search-only client. Use when you need search without analytics. Accepts the same KelpClientConfig but only searchUrl and apiKey are used.
Returns { search, browse, suggest }.
import { createKelpSearch } from '@kelpclick/client/search';
const kelpSearch = createKelpSearch({
searchUrl: 'https://{TENANT_ID}-search.kelp.click',
apiKey: 'kelp_pk_...',
});createAnalytics
function createAnalytics(options: CreateAnalyticsOptions): KelpAnalyticsCreates a buffering analytics tracker. Auto-fills occurredAt, sessionId, and userId on every event. Buffers events and flushes on batch size, interval, and pagehide.
Returns { track, trackSearch, trackProductViewed, trackProductClicked, trackProductWishlisted, trackProductAddedToCart, trackCollectionViewed, trackPurchase, startSession, trackSessionStarted, flush, close, isClosed }. track() accepts a named KelpEventKind only - not a custom string.
import { createKelpClient, createIdentity, createAnalytics } from '@kelpclick/client';
const kelp = createKelpClient({ /* ... */ });
const identity = createIdentity();
const analytics = createAnalytics({ client: kelp, identity });See CreateAnalyticsOptions in Types.
defaultSerializeFilterBy
function defaultSerializeFilterBy(filters: KelpFilters): stringSerializes KelpFilter[] to the backend filterBy string, e.g. brand:=[globex] && price:>0. Exported for reuse or override when building a custom serializeFilterBy.
createIdentity
function createIdentity(options?: KelpStorage | KelpIdentityOptions): KelpIdentityCreates an identity: a persistent anonymous id, a rolling session id, and known-user tracking. SSR-safe - falls back to in-memory storage when localStorage is unavailable.
Returns { getAnonymousId, getSessionId, getUserId, identify, reset }.
import { createIdentity } from '@kelpclick/client';
const identity = createIdentity({
sessionTtlMs: 30 * 60 * 1000, // 30 min
keyPrefix: 'kelp',
});
identity.getAnonymousId(); // stable per-browser id
identity.getSessionId(); // rolling session id
identity.getUserId(); // string | null
identity.identify({ userId: 'user_123', email: 'a@b.com' });
identity.reset(); // clears known user, keeps anonymous idcreateKelpEmail
function createKelpEmail(options: CreateKelpEmailOptions): KelpEmailCapture-only email. subscribe emits email_subscribed and calls identity.identify({ email }); unsubscribe emits email_unsubscribed.
Returns { subscribe, unsubscribe, flush, close, isClosed }. See Email capture.
import { createKelpEmail } from '@kelpclick/client/email';
const email = createKelpEmail({ identity, tracker: analytics });
email.subscribe({
email: 'shopper@example.com',
source: 'footer-form',
listId: 'newsletter',
meta: { formId: 'footer-form' },
});Storage utilities
function memoryStorage(): KelpStorageReturns a simple in-memory KelpStorage implementation. Useful for SSR or testing.
function localStorageAdapter(): KelpStorageReturns a localStorage-backed KelpStorage. Browser-only; all methods are wrapped in try/catch so quota or security errors do not propagate.
function resolveStorage(explicit?: KelpStorage): KelpStorageReturns explicit if provided, localStorageAdapter() in the browser, or memoryStorage() on the server. This is the SSR-safe entry point.
React exports (@kelpclick/client/react)
| Export | Kind | Purpose |
|---|---|---|
KelpProvider | Component | Wraps the app. Accepts client, optional identity and analytics. All hooks require a KelpProvider ancestor. |
useSearch | Hook | Debounced search with pagination, facets, filters, and auto analytics. Returns { query, setQuery, hits, facetCounts, ... }. |
useBrowse | Hook | Same return shape as useSearch minus query fields. For category/collection pages. |
useKelpClient | Hook | Returns the KelpClient from context. |
useKelpIdentity | Hook | Returns the KelpIdentity from context. |
useKelpAnalytics | Hook | Returns the KelpAnalytics tracker from context. |
useKelpQuery | Hook | Lower-level query runner used internally by useSearch and useBrowse. |
useDebouncedValue | Hook | Debounces a value. Used internally by useSearch. |
All hooks throw if called outside a <KelpProvider>.
Related
- Types - all exported types and interfaces
- Client configuration -
KelpClientConfigoptions - Error handling - errors thrown by these functions