Skip to main content

@idhub/identity-provider-segment

Interfaces

SegmentAliasMessage

Defined in: types.ts:33

Properties

previousId

previousId: string

Defined in: types.ts:35

userId

userId: string

Defined in: types.ts:34


SegmentAnalyticsClient

Defined in: types.ts:38

Methods

alias()?

optional alias(message): unknown

Defined in: types.ts:52

Only invoked when SegmentProviderConfig.useAlias === true.

Parameters
message

SegmentAliasMessage

Returns

unknown

identify()

identify(message): unknown

Defined in: types.ts:48

Parameters
message

SegmentIdentifyMessage

Returns

unknown

page()

page(message): unknown

Defined in: types.ts:50

Parameters
message

SegmentPageMessage

Returns

unknown

setAnonymousId()?

optional setAnonymousId(anonymousId): void

Defined in: types.ts:47

Present on browser analytics.js clients (window.analytics / AnalyticsBrowser). analytics-node and other server SDKs have no such method — they take anonymousId per call instead, which is why every message type above carries its own anonymousId field. When absent, segmentProvider falls back to threading the anonymous id through each subsequent call itself (see onAnonymous in provider.ts).

Parameters
anonymousId

string

Returns

void

track()

track(message): unknown

Defined in: types.ts:49

Parameters
message

SegmentTrackMessage

Returns

unknown


SegmentIdentifyMessage

Defined in: types.ts:13

Properties

anonymousId?

optional anonymousId?: string

Defined in: types.ts:15

traits?

optional traits?: Record<string, unknown>

Defined in: types.ts:16

userId?

optional userId?: string

Defined in: types.ts:14


SegmentPageMessage

Defined in: types.ts:26

Properties

anonymousId?

optional anonymousId?: string

Defined in: types.ts:29

name?

optional name?: string

Defined in: types.ts:27

properties?

optional properties?: Record<string, unknown>

Defined in: types.ts:30

userId?

optional userId?: string

Defined in: types.ts:28


SegmentProviderConfig

Defined in: types.ts:57

Properties

client

client: SegmentAnalyticsClient

Defined in: types.ts:66

An already-constructed Segment analytics client instance (a real analytics-node Analytics, a browser analytics.js client, or a test double satisfying SegmentAnalyticsClient). This package never constructs an SDK instance itself — app code owns SDK initialization, since the SDK is a peerDependency the app controls the version/loading strategy for.

useAlias?

optional useAlias?: boolean

Defined in: types.ts:81

Opt-in only. Segment's current best-practices guidance treats alias() as an advanced/exception call, not the default — identify(userId, traits) alone is sufficient because the anonymousId already travels with every call from the same client. Default: false.

writeKey

writeKey: string

Defined in: types.ts:74

Segment write key. Not used to construct client (the caller already did that) — retained here per the plan's Appendix A SegmentProviderConfig shape ({ writeKey, useAlias }) so callers can keep one place that documents which Segment source a given provider instance is wired to.


SegmentTrackMessage

Defined in: types.ts:19

Properties

anonymousId?

optional anonymousId?: string

Defined in: types.ts:22

event

event: string

Defined in: types.ts:20

properties?

optional properties?: Record<string, unknown>

Defined in: types.ts:23

userId?

optional userId?: string

Defined in: types.ts:21

Functions

segmentProvider()

segmentProvider(config): IdentityProvider

Defined in: provider.ts:19

identity-core IdentityProvider implementation for Segment.

  • onAnonymous: sets the anonymous id on the client (setAnonymousId, browser-style) before any track/identify fires, or — when the client has no such method (analytics-node and other server SDKs) — remembers it so every subsequent identify/track/page call threads it through explicitly, which is the correct pattern for those SDKs.
  • onIdentify: calls client.identify(...) only. client.alias(...) is never called unless config.useAlias === true (see Segment research: alias() is an advanced/exception call, not the default).
  • onTrack / onPage: forward to the client's track/page methods, carrying the current anonymous id (and userId, once identified).
  • onReset: adopts the new anonymous id the same way onAnonymous does.

Parameters

config

SegmentProviderConfig

Returns

IdentityProvider