@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 +89 -100
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +158 -95
- package/dist/sideband.iife.js +1 -1
- package/dist/ui/snackbar-ui.d.ts +6 -0
- package/dist/ui/snackbar-ui.d.ts.map +1 -1
- package/dist/ui/survey-ui.d.ts +2 -0
- package/dist/ui/survey-ui.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,84 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Sideband Web SDK
|
|
2
2
|
|
|
3
|
-
Sideband
|
|
4
|
-
dependency.
|
|
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
|
|
14
|
+
npm install @sidebandai/sideband-web
|
|
10
15
|
```
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
npm registry and requires no registry credentials. Core is installed automatically.
|
|
17
|
+
## Configure
|
|
14
18
|
|
|
15
|
-
|
|
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({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
await Sideband.flush()
|
|
24
|
+
Sideband.configure({
|
|
25
|
+
apiKey: 'YOUR_API_KEY',
|
|
26
|
+
appVersion: '1.0.0',
|
|
27
|
+
})
|
|
25
28
|
```
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
33
|
+
Sideband presents available Pulses automatically. Styles are included; no
|
|
34
|
+
stylesheet import is required.
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
endpoint by default. An explicit `baseUrl` overrides the endpoint for custom
|
|
35
|
-
deployments and tests.
|
|
36
|
+
## Identify users
|
|
36
37
|
|
|
37
|
-
|
|
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.
|
|
41
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
81
|
-
|
|
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
|
|
95
|
-
not-equals
|
|
96
|
-
|
|
97
|
-
|
|
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
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
};
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,EACZ,YAAY,EACZ,KAAK,EACL,WAAW,EACX,eAAe,EACf,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,qBAAqB,EACrB,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,EACZ,KAAK,EACL,UAAU,EACV,UAAU,EACV,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,2BAA2B,CAAA;AAElC,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG;IACnD,EAAE,CAAC,EAAE,OAAO,CAAA;CACb,CAAA;AAED,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EA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