@sidebandai/sideband-web 1.4.1-rc.2 → 1.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,84 +1,69 @@
1
- # @sidebandai/sideband-web
1
+ # Sideband Web SDK
2
2
 
3
- Sideband event tracking and Pulse presentation for websites, with no framework
4
- dependency. Styles are isolated from your application using Shadow DOM.
3
+ Sideband adds in-app Pulse prompts and event tracking to websites, with no
4
+ framework dependency.
5
+
6
+ ## Requirements
7
+
8
+ - A Sideband API key
9
+ - Your application's version
5
10
 
6
11
  ## Install
7
12
 
8
13
  ```bash
9
- npm install @sidebandai/sideband-web@rc
14
+ npm install @sidebandai/sideband-web
10
15
  ```
11
16
 
12
- The `rc` tag selects the latest release candidate. Installation uses the public
13
- npm registry and requires no registry credentials. Core is installed automatically.
17
+ ## Configure
14
18
 
15
- ## Quick start
19
+ Configure Sideband once when your app starts in the browser:
16
20
 
17
21
  ```ts
18
22
  import { Sideband } from '@sidebandai/sideband-web'
19
23
 
20
- Sideband.configure({ apiKey: 'YOUR_API_KEY' })
21
- Sideband.tagUser('user-123')
22
- Sideband.track('checkout_completed', { plan: 'pro' })
23
- Sideband.untagUser()
24
- await Sideband.flush()
24
+ Sideband.configure({
25
+ apiKey: 'YOUR_API_KEY',
26
+ appVersion: '1.0.0',
27
+ })
25
28
  ```
26
29
 
27
- For script-tag use, self-host `dist/sideband.iife.js`. Its `Sideband` global
28
- exposes the same `configure`, `track`, `tagUser`, `untagUser`, and `flush` methods.
29
- Styles are bundled inside Shadow DOM; no stylesheet import is required.
30
+ Replace `1.0.0` with your application's version, not the SDK version.
31
+ `appVersion` must be a non-empty string of at most 64 characters.
30
32
 
31
- ## Configuration
33
+ Sideband presents available Pulses automatically. Styles are included; no
34
+ stylesheet import is required.
32
35
 
33
- `apiKey` identifies your Sideband application. Requests use the production
34
- endpoint by default. An explicit `baseUrl` overrides the endpoint for custom
35
- deployments and tests.
36
+ ## Identify users
36
37
 
37
- `appVersion` is optional and has no default.
38
+ Tag the signed-in user wherever your app knows who they are: after sign-up and
39
+ sign-in, and when your app restores a signed-in session. Clear the identity at
40
+ sign-out.
38
41
 
39
42
  ```ts
40
- Sideband.configure({
41
- apiKey: 'YOUR_API_KEY',
42
- shouldPresentPulse: async (pulse) => {
43
- // pulseId, version, title, and optional fab; no transport envelope.
44
- return pulse.title.includes('Survey') ? 'notNow' : 'showNow'
45
- },
46
- })
43
+ Sideband.tagUser('user-123') // sign-up, sign-in, restored session
44
+ Sideband.untagUser() // sign-out
47
45
  ```
48
46
 
49
- The presentation callback returns `showNow`, `notNow`, or `never`. Declines are
50
- reported to the server. `onError` receives background errors; `onRateApp` handles
51
- rating completion actions in the host website.
52
-
53
- Browser integrations may also supply `context`, `headers`, `fetch`, or `ui: false`
54
- for headless transport. Without `ui: false`, configuration during SSR is inert.
55
-
56
- ## API
57
-
58
- - `configure(config)` replaces the shared client and returns its instance.
59
- - `track(eventName, metadata?)` queues an event. Metadata is a string-to-string
60
- map; invalid values and empty event names are rejected.
61
- - `tagUser(userId)` persists the opaque identity exactly.
62
- - `untagUser()` clears runtime and persisted identity. An explicitly configured
63
- `context.user_id` is restored after the runtime override is cleared.
64
- - `flush()` forces queued delivery and returns a promise.
65
- - `presentSimulatedPulse({ pulse, sentimentPresentation? })` presents a canonical
66
- `Pulse` locally and returns whether it was accepted. It is also available on
67
- the configured instance and script-tag global.
68
- - `destroy()` tears down the shared client.
47
+ Pass your own stable user ID, not an email address or name. A user ID can have at most 256 characters (Unicode code points). A longer ID is
48
+ rejected without changing the current identity, and `onError` receives the reason. The SDK
49
+ keeps the ID in the browser's localStorage and restores it on the next page
50
+ load.
69
51
 
70
- The returned instance also exposes `sync`, `openSurvey`, `closeSurvey`,
71
- `getDeviceId`, and `destroy` for advanced browser integrations. Raw `sync` is a
72
- one-shot request; background queued delivery owns batching and retries.
52
+ ## Track events
73
53
 
74
- Device identity is persisted in localStorage; session identity is per-tab.
75
- Event queues are in memory. Background/pagehide delivery uses fetch keepalive.
76
- See `SidebandWebConfig` for delivery tuning options.
54
+ Call `track` once per user action, after the action succeeds:
77
55
 
78
- ## Event metadata and Pulse targeting
56
+ ```ts
57
+ Sideband.track('invoice_sent', {
58
+ source: 'invoice_list',
59
+ item_type: 'invoice',
60
+ count: '3',
61
+ invoice_id: 'inv-5530',
62
+ })
63
+ ```
79
64
 
80
- Pass metadata to `track` as string key-value pairs. Use metadata to describe an
81
- event without creating a separate event name for each source, item type, or mode.
65
+ Pass metadata as string key-value pairs. Use metadata to describe an event
66
+ without creating a separate event name for each source, item type, or mode.
82
67
  Only these six keys support Pulse trigger filters and event-history conditions:
83
68
 
84
69
  | Key | Value format | Example |
@@ -91,49 +76,53 @@ Only these six keys support Pulse trigger filters and event-history conditions:
91
76
  | `duration` | Seconds sent as a string; fractions allowed | `'12.5'` |
92
77
 
93
78
  Use the exact lowercase key names. The server trims and lowercases values for
94
- `source`, `item_type`, `mode`, and `variant`. These keys support equals and
95
- not-equals comparisons. It compares `count` and `duration` numerically, with
96
- equals, not-equals, greater-than, greater-than-or-equal, less-than, and
97
- less-than-or-equal comparisons. Send `duration` in seconds, not milliseconds.
98
-
99
- ```ts
100
- Sideband.track('content_created', {
101
- source: 'editor',
102
- item_type: 'article',
103
- count: '3',
104
- duration: '12.5',
105
- content_id: 'article-123',
106
- })
107
- ```
79
+ `source`, `item_type`, `mode`, and `variant`, and compares them with equals and
80
+ not-equals. It compares `count` and `duration` numerically. Send `duration` in
81
+ seconds, not milliseconds. `count: '3.5'` and `count: '3.0'` are invalid; use
82
+ `count: '3'`.
108
83
 
109
84
  Custom keys such as `content_id`, `screen`, or `plan` are stored unchanged, but
110
- cannot be used in Pulse targeting filters. A missing key does not match any
111
- filter, including not-equals.
112
-
113
- The server stores at most 20 metadata properties per event. It keeps valid
114
- targeting keys first, then fills the remaining slots with custom keys in sorted
115
- key order. It drops empty keys and invalid targeting values without rejecting
116
- the event. For example, `count: '3.5'` and `count: '3.0'` are invalid; use
117
- `count: '3'`. Normalization and numeric comparison happen on the server, not in
118
- the SDK. Script-tag integrations use the same metadata rules.
119
-
120
- ## Snackbar simulations
121
-
122
- ```ts
123
- Sideband.presentSimulatedPulse({
124
- pulse, // A canonical Pulse value, including its FAB configuration.
125
- sentimentPresentation: 'snackbar',
126
- })
127
- ```
128
-
129
- The local preference defaults to `'sheet'`, matching the native SDKs. Snackbar
130
- requires a FAB and a root `yes_no` question with exactly two answers and no
131
- `system_other` option; other pulses use their normal presentation. Server-delivered
132
- pulses use FAB/sheet presentation. This option only applies to local simulations.
133
-
134
- Simulations do not report impressions or responses, or invoke `onRateApp`.
135
- The configured runtime's normal event delivery continues independently.
136
- The snackbar uses the root question prompt, sheet-derived colors, and the FAB's
137
- artwork, placement, timeout, and `none`/`bar`/`fill` timer. Selecting an answer
138
- freezes the timer and retains the answer through the card acknowledgement and
139
- branch transition. Use `closeSurvey()` or the close control to dismiss it.
85
+ cannot be used in Pulse targeting. A missing key does not match any filter,
86
+ including not-equals. The server stores at most 20 metadata properties per
87
+ event: valid targeting keys first, then custom keys in sorted key order. It
88
+ drops empty keys and invalid targeting values without rejecting the event.
89
+
90
+ When the page is hidden or unloads, the SDK tries to send queued events with
91
+ `keepalive`. This is best effort: a send already in progress can delay it. For an
92
+ event tracked just before your code navigates away, await `Sideband.flush()` first.
93
+
94
+ ## Events the SDK sends itself
95
+
96
+ Do not track these yourself:
97
+
98
+ | Event | When |
99
+ | --- | --- |
100
+ | `system_app_launch` | The SDK starts, usually once per page load. |
101
+ | `system_app_background` | The page is hidden or unloaded: another tab, a minimized window, navigation away. |
102
+ | `system_app_foreground` | The page is visible again after `system_app_background`. |
103
+ | `system_login` | `tagUser` sets a new user ID. `metadata.user_id` is the new ID. |
104
+ | `system_logout` | `untagUser` clears the user ID, or `tagUser` replaces it. `metadata.user_id` is the previous ID. |
105
+ | `system_did_present_pulse` | A Pulse is shown to the user. |
106
+
107
+ Switching from user A to user B sends `system_logout` for A, then `system_login`
108
+ for B, with the same timestamp. Repeating the same ID, clearing an ID that is
109
+ not set, and restoring the stored ID on a page load send nothing.
110
+
111
+ ## Other options
112
+
113
+ The SDK sends events in batches, by default about once a second. Set
114
+ `flushIntervalSeconds` (seconds, at least 1) to change it. A pulse can show only
115
+ after the batch that holds its trigger event is sent, so a longer interval delays
116
+ pulses. The server can also ask the SDK to wait before its next send.
117
+
118
+ `SidebandWebConfig` in the package's type definitions lists the optional
119
+ settings, such as `shouldPresentPulse` to hold a Pulse back for a better
120
+ moment and `onError` for background errors. `Sideband.flush()` sends queued
121
+ events now and returns a promise.
122
+
123
+ ## Install Without a Bundler
124
+
125
+ Copy `node_modules/@sidebandai/sideband-web/dist/sideband.iife.js` to your
126
+ website's public assets and load it before your application script. The bundle
127
+ exposes `window.Sideband`; call `window.Sideband.configure` with the same
128
+ configuration shown above.
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { EventMetadata, SidebandCoreConfig, SidebandRuntime, SimulatedPulseDefinition, TrackOptions } from '@sidebandai/sideband-core';
2
2
  export { createSidebandClient, getDeviceId, getSessionId, SidebandApiError, SurveySessionStore, buildFabTitle, getChoiceValue, SyncEngine, } from '@sidebandai/sideband-core';
3
- export type { AnsweredInteraction, ApiErrorDetail, ClientContext, CompletionActionStyle, CompletionActionType, CompletionIconType, CompletionType, DismissedInteraction, EventMetadata, EventRecord, Fab, FabOffset, FabPlacement, FabPoint, FabState, Interaction, Platform, PendingPulse, SyncEndpoint, Pulse, PulseAnswer, PulseCompletion, PulseCompletionAction, PulseQuestion, QuestionType, SentimentPresentation, SimulatedPulseDefinition, SidebandClient, SidebandClientConfig, SidebandCoreConfig, SurveyAnswerDraft, SurveyAnswerMap, SurveyAnswerValue, SurveySessionState, SurveyStoreSnapshot, SurveyStoreUpdateReason, SyncEngineDeps, SyncEngineOptions, SyncErrorResponse, ServiceUnavailableError, SyncOptions, SyncRequest, SyncResponse, TrackedEvent, TrackOptions, Theme, ThemeColor, TimerStyle, SurveyPresentationDecision, SurveyPresentationKind, } from '@sidebandai/sideband-core';
3
+ export type { AnsweredInteraction, ApiErrorDetail, ClientContext, CompletionActionStyle, CompletionActionType, CompletionIconType, CompletionType, DismissedInteraction, EventMetadata, EventRecord, Fab, FabOffset, FabPlacement, FabPoint, FabState, Interaction, Platform, PendingPulse, SyncEndpoint, Pulse, PulseAnswer, PulseCompletion, PulseCompletionAction, PulseQuestion, QuestionType, SentimentPresentation, SentimentPresentationOptions, BarPosition, BarBehavior, SimulatedPulseDefinition, SidebandClient, SidebandClientConfig, SidebandCoreConfig, SurveyAnswerDraft, SurveyAnswerMap, SurveyAnswerValue, SurveySessionState, SurveyStoreSnapshot, SurveyStoreUpdateReason, SyncEngineDeps, SyncEngineOptions, SyncErrorResponse, ServiceUnavailableError, SyncOptions, SyncRequest, SyncResponse, TrackedEvent, TrackOptions, Theme, ThemeColor, TimerStyle, SurveyPresentationDecision, SurveyPresentationKind, } from '@sidebandai/sideband-core';
4
4
  export type SidebandWebConfig = SidebandCoreConfig & {
5
5
  ui?: boolean;
6
6
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,wBAAwB,EACxB,YAAY,EACb,MAAM,2BAA2B,CAAA;AAIlC,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,UAAU,GACX,MAAM,2BAA2B,CAAA;AAClC,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,GAAG,EACH,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY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AAM,EAAE,QAAQ,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,YAAY,QAExF;AAED,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,QAAkC;AACxE,wBAAgB,SAAS,SAA+B;AACxD,wBAAgB,KAAK,kBAAkC;AACvD,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,wBAAwB,WAA2D;AACrI,wBAAgB,OAAO,SAGtB;AAED,eAAO,MAAM,QAAQ;;;;;;;;CAAkF,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,aAAa,EACb,kBAAkB,EAClB,eAAe,EACf,wBAAwB,EACxB,YAAY,EACb,MAAM,2BAA2B,CAAA;AAIlC,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,EAClB,aAAa,EACb,cAAc,EACd,UAAU,GACX,MAAM,2BAA2B,CAAA;AAClC,YAAY,EACV,mBAAmB,EACnB,cAAc,EACd,aAAa,EACb,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,WAAW,EACX,GAAG,EACH,SAAS,EACT,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,KAAK,EACL,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,4BAA4B,EAC5B,WAAW,EACX,WAAW,EACX,wBAAwB,EACxB,cAAc,EACd,oBAAoB,EACpB,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,WAAW,EACX,WAAW,EACX,YAAY,EACZ,YAAY,EACZ,YAAY,E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