@sensiblestats/widget-react 0.108.3 → 0.109.0
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/CHANGELOG.md +17 -0
- package/README.md +92 -0
- package/dist/index.cjs +3665 -3067
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +3446 -2848
- package/dist/index.js.map +1 -1
- package/dist/styles.css +14 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @sensiblestats/widget-react
|
|
2
2
|
|
|
3
|
+
## 0.109.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- Add tracking events. `onEvent` on the React config, or a `sensiblestats:event` DOM event on `window` for the embed, reports widget activity to the operator's own tracker. Questions report their length; `eventText` (`data-event-text="true"`) adds the full text.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
- @sensiblestats/widget-sdk@0.76.0
|
|
13
|
+
|
|
14
|
+
## 0.108.4
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Rename the widget's internal Odds tab id, dot, count and panel to Trends. No visible change.
|
|
19
|
+
|
|
3
20
|
## 0.108.3
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -145,6 +145,98 @@ Rules for the three host methods:
|
|
|
145
145
|
queue lives in the page, so it does not survive a full page load.
|
|
146
146
|
- Use one host for one mounted widget.
|
|
147
147
|
|
|
148
|
+
## Tracking events
|
|
149
|
+
|
|
150
|
+
The widget reports what visitors do to one callback, so you can send it to your own tracker
|
|
151
|
+
(Google Analytics, Mixpanel, a data layer). Nothing leaves the page until your callback sends it.
|
|
152
|
+
The widget does not check consent. Gate your own sending on your consent state.
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
// Module scope, or memoised. A new function each render is fine: the widget reads the latest one.
|
|
156
|
+
const track = (event: WidgetTrackingEvent) => {
|
|
157
|
+
const { name, text, operatorUserId, anonymousUserId, page, cardTypes, ...params } = event as WidgetTrackingEvent & { text?: string; cardTypes?: string[] }
|
|
158
|
+
gtag('event', `widget_${name}`, params)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
<StatsWidget config={{ ...config, onEvent: track }} />
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Mixpanel:
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
const track = ({ name, ...props }: WidgetTrackingEvent) => mixpanel.track(`widget_${name}`, props)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
This Mixpanel example forwards every field, including the user ids, `page` and, when `eventText`
|
|
171
|
+
is on, `text`. Strip what your policy does not allow before you send.
|
|
172
|
+
|
|
173
|
+
Rules:
|
|
174
|
+
|
|
175
|
+
- `onEvent` runs in a microtask inside a try/catch, and a rejected promise is swallowed. A
|
|
176
|
+
faulty callback cannot break a click or a render. A microtask does not protect against a slow
|
|
177
|
+
callback, so keep it short and hand the work to your tracker's own queue.
|
|
178
|
+
- Every event carries `name` and the envelope: `at` (epoch ms, taken when the event happened),
|
|
179
|
+
`operatorId`, `widgetVersion`, and when known `language`, `conversationId`, `operatorUserId`,
|
|
180
|
+
`anonymousUserId` and `page`. With an injected `client`, `operatorId` is empty and the user ids
|
|
181
|
+
and `language` are absent.
|
|
182
|
+
- By default a question reports only its `length`. Set `eventText: true` in `config` to add
|
|
183
|
+
`text`, the full question. It can hold personal data, so do not forward it to any destination
|
|
184
|
+
that is not cleared for it. Answer text is never sent.
|
|
185
|
+
- `source` on `question_asked` is one of `typed`, `starter`, `action`, `tile`, `preset`,
|
|
186
|
+
`live_fact`, `bubble_ask`, `retry`.
|
|
187
|
+
- A turn fires at most one of `answer_received`, `answer_failed` and `answer_stopped`. A turn
|
|
188
|
+
replaced by a new question, or cut off by closing the panel, starting a New conversation, or a
|
|
189
|
+
language or storage-key change, fires none. A limit refusal fires `answer_failed` with the limit
|
|
190
|
+
code.
|
|
191
|
+
- Greeting turns fire no `question_asked` or answer event.
|
|
192
|
+
- `answer_received.cardTypes` lists the card events received for the answer. A dashboard answer
|
|
193
|
+
reports `[]`. The supported values are `entity_card`, `betting_insight`, `nba_insight`,
|
|
194
|
+
`nfl_insight`, `market_odds`, `combo_card` and `odds_movement`.
|
|
195
|
+
- `answer_failed.code` is the server's error code for a stream error, or one of `timeout`,
|
|
196
|
+
`network_error` (the connection dropped, mid-answer included), `unauthorized`, `forbidden`,
|
|
197
|
+
`rate_limited`, `upstream_error`, `parse_error`, or a limit code (`daily_cap`,
|
|
198
|
+
`quota_exhausted`, `assistant_paused`).
|
|
199
|
+
- `favourite_change.kind` is `competition`, `team` or `player`. `outcome` is `starred`,
|
|
200
|
+
`unstarred`, `at_cap` or `failed`.
|
|
201
|
+
- `handle.open()` still fires `widget_open`. `handle.close()` fires no click event: `widget_close`
|
|
202
|
+
means the visitor closed the panel with the button or Escape. An answer in progress when you call
|
|
203
|
+
`handle.close()` fires no terminal event.
|
|
204
|
+
- Tab moves the widget makes itself fire nothing. Tapping the Games tab fires `tab_change`.
|
|
205
|
+
Tapping an individual game fires nothing.
|
|
206
|
+
- Slip events (`add_to_slip_click`, `add_to_slip_result`, `combo_add_click`) need `onAddToSlip`.
|
|
207
|
+
Without it the price is plain text and none fire.
|
|
208
|
+
- Tapping a question in the popup fires `bubble_ask_click` and also `dashboard_tile_click`. A static
|
|
209
|
+
`greeting` bubble fires `bubble_click` when tapped but never `bubble_shown`.
|
|
210
|
+
|
|
211
|
+
| Event | Fields | When |
|
|
212
|
+
| --- | --- | --- |
|
|
213
|
+
| `bubble_shown` | | The launcher popup appears |
|
|
214
|
+
| `bubble_click` | | The visitor taps the popup |
|
|
215
|
+
| `bubble_ask_click` | `position` | The visitor taps a question in the popup |
|
|
216
|
+
| `bubble_dismiss` | | The visitor dismisses the popup |
|
|
217
|
+
| `launcher_click` | | The visitor taps the launcher |
|
|
218
|
+
| `widget_open` | | The panel opens |
|
|
219
|
+
| `widget_close` | `method` (`button`, `escape`), `tab`, `answering` | The visitor closes the panel |
|
|
220
|
+
| `tab_change` | `from`, `to` | The visitor changes tab. Ids: `chat`, `today`, `following`, `trends`, `games`, `fixtures`, `standings`, `squad`, `records`, `favourites` |
|
|
221
|
+
| `question_asked` | `turnId`, `source`, `length`, `text?` | A question is sent |
|
|
222
|
+
| `answer_received` | `turnId`, `conversationId`, `latencyMs`, `cardTypes` | An answer finishes |
|
|
223
|
+
| `answer_failed` | `turnId`, `code` | An answer fails or is refused |
|
|
224
|
+
| `answer_stopped` | `turnId` | The visitor stops an answer |
|
|
225
|
+
| `pin_click` | `action` (`add`, `remove`), `target` (`match`, `market`), `matchId?`, `market?`, `sport?` | A pin is tapped |
|
|
226
|
+
| `add_to_slip_click` | `matchOddsId`, `matchId`, `odds`, `market?`, `sport?` | "Add to slip" is tapped |
|
|
227
|
+
| `add_to_slip_result` | as above, plus `outcome` | Your `onAddToSlip` has answered |
|
|
228
|
+
| `combo_add_click` | `sport`, `legs`, `total` | The bet builder's "Add all" has added every leg. A combo card in chat, a partial add or a refused leg fires none. Each leg also fires its own `add_to_slip_click` and `add_to_slip_result` |
|
|
229
|
+
| `all_markets_click` | `matchId`, `market?`, `surface` | "All markets" is tapped |
|
|
230
|
+
| `dashboard_tile_click` | `entityType`, `entityId` | A dashboard tile is tapped |
|
|
231
|
+
| `sport_switch` | `sport` | The visitor switches sport on the dashboard |
|
|
232
|
+
| `new_conversation` | | The visitor starts a new conversation |
|
|
233
|
+
| `league_star` | `competitionId`, `starred` | A league star changes and the request succeeds. A failed star is silent |
|
|
234
|
+
| `favourite_change` | `kind`, `id`, `outcome` | A favourite is added or removed. Failures show in `outcome` |
|
|
235
|
+
|
|
236
|
+
`add_to_slip_result.outcome` is `added`, `duplicate`, `price_changed`, `timeout`, or the
|
|
237
|
+
`reason` your handler rejected with. `added` also covers an accepted price change. `timeout`
|
|
238
|
+
covers any failure of the add, not only a real timeout.
|
|
239
|
+
|
|
148
240
|
## Integration: persisting the conversation across SPA navigation
|
|
149
241
|
|
|
150
242
|
The conversation (messages, conversation id, open/closed state) lives in the
|