Skip to main content

Framework-agnostic wiring (no adapter package)

Used when the target is neither Next.js (next.config.*) nor Angular (angular.json) — install identity-core only, no adapter:

npm install @idhub/identity-core \
@idhub/identity-provider-segment @idhub/identity-provider-launchdarkly @idhub/identity-provider-fullstory

Drop any provider line the user did not select in step 2; providers: [] is valid.

Anonymous id, before any vendor loads

Pick exactly one of these two — never both, and never guess which fits: the Request-mode function is for a server/edge context with a Web Standard Request (any Node/Bun/Deno HTTP framework, Cloudflare Workers, etc.); the browser-mode function is for a pure client-side app with no server framework at all.

// Request-mode: any server/edge context with a Web Standard `Request`
import {
getOrCreateAnonymousIdFromRequest,
applyAnonymousIdCookie,
} from '@idhub/identity-core'

function handleRequest(request: Request) {
const { anonymousId, setCookieHeader } = getOrCreateAnonymousIdFromRequest(request)
const response = /* the target's own response object */
return applyAnonymousIdCookie(response, setCookieHeader)
}
// Browser-mode: pure client-side, no server framework
import { getOrCreateAnonymousIdBrowser } from '@idhub/identity-core'

const anonymousId = getOrCreateAnonymousIdBrowser()

Client + provider fan-out

import { createIdentityClient } from '@idhub/identity-core'
// Import only the providers the user selected in step 2:
import { segmentProvider } from '@idhub/identity-provider-segment'
import { launchDarklyProvider } from '@idhub/identity-provider-launchdarkly'
import { fullStoryProvider } from '@idhub/identity-provider-fullstory'

const identity = createIdentityClient({
providers: [
// one entry per selected provider only — see references/provider-env-vars.md
segmentProvider({ client: analytics, writeKey: process.env.SEGMENT_WRITE_KEY! }),
launchDarklyProvider({ clientSideId: process.env.LD_CLIENT_ID! }),
fullStoryProvider({ orgId: process.env.FULLSTORY_ORG_ID! }),
],
cookie: { /* domain: <value chosen in step 3, or omit entirely for host-only> */ },
})

segmentProvider needs a caller-supplied analytics/analytics-node client instance (client: analytics above) — this skill does not create that instance; the target repo must already have (or add) its own Segment client module and import it here.

Where identify()/reset() go (surface only — do not auto-edit)

// identity.identify(userId, traits) belongs at the login handler found in step 4
// identity.reset() belongs at the logout handler found in step 4
// identity.track(event, properties) / identity.page(name) — anywhere else, no restriction