@snf/access-qa-bot 3.0.4 → 3.1.0-rc.1
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 +96 -0
- package/dist/access-qa-bot.js +8781 -8352
- package/dist/access-qa-bot.js.map +1 -1
- package/dist/access-qa-bot.standalone.js +62 -58
- package/dist/access-qa-bot.standalone.js.map +1 -1
- package/dist/access-qa-bot.umd.cjs +116 -112
- package/dist/access-qa-bot.umd.cjs.map +1 -1
- package/dist/index.d.ts +17 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -106,6 +106,7 @@ function MyApp() {
|
|
|
106
106
|
| `loginUrl` | string | `"/login"` | Login redirect URL |
|
|
107
107
|
| `open` | boolean | - | Control chat window (floating mode) |
|
|
108
108
|
| `onOpenChange` | function | - | Chat window state callback |
|
|
109
|
+
| `onAnalyticsEvent` | function | - | Analytics event callback (receives core + wrapper events) |
|
|
109
110
|
| `welcome` | string | - | Custom welcome message |
|
|
110
111
|
| `userEmail` | string | - | Pre-populate email in forms |
|
|
111
112
|
| `userName` | string | - | Pre-populate name in forms |
|
|
@@ -177,6 +178,7 @@ bot.destroy();
|
|
|
177
178
|
| `embedded` | boolean | `false` | Embedded or floating mode |
|
|
178
179
|
| `isLoggedIn` | boolean | `false` | User login state |
|
|
179
180
|
| `loginUrl` | string | `"/login"` | Login redirect URL |
|
|
181
|
+
| `onAnalyticsEvent` | function | - | Analytics event callback |
|
|
180
182
|
| `welcome` | string | - | Welcome message |
|
|
181
183
|
| `userEmail` | string | - | Pre-populate email |
|
|
182
184
|
| `userName` | string | - | Pre-populate name |
|
|
@@ -291,6 +293,100 @@ return (
|
|
|
291
293
|
);
|
|
292
294
|
```
|
|
293
295
|
|
|
296
|
+
### Analytics Integration
|
|
297
|
+
|
|
298
|
+
qa-bot-core fires analytics events for core functionality (Q&A, ratings, open/close). Your wrapper can add its own events and forward everything to consumers.
|
|
299
|
+
|
|
300
|
+
**1. Define a tracking function type:**
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
// src/utils/analytics.ts
|
|
304
|
+
export interface TrackEventInput {
|
|
305
|
+
type: string;
|
|
306
|
+
sessionId?: string;
|
|
307
|
+
timestamp?: number;
|
|
308
|
+
[key: string]: unknown;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export type TrackEventFn = (event: TrackEventInput) => void;
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
**2. Accept `onAnalyticsEvent` prop and create trackers:**
|
|
315
|
+
|
|
316
|
+
```tsx
|
|
317
|
+
// In your wrapper component
|
|
318
|
+
const trackEvent: TrackEventFn = useCallback((event) => {
|
|
319
|
+
if (onAnalyticsEvent) {
|
|
320
|
+
onAnalyticsEvent({
|
|
321
|
+
...event,
|
|
322
|
+
timestamp: event.timestamp ?? Date.now(),
|
|
323
|
+
sessionId: event.sessionId ?? sessionId,
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
}, [onAnalyticsEvent, sessionId]);
|
|
327
|
+
|
|
328
|
+
// Handler for core events from qa-bot-core
|
|
329
|
+
const handleCoreAnalyticsEvent = useCallback((event) => {
|
|
330
|
+
if (onAnalyticsEvent) {
|
|
331
|
+
onAnalyticsEvent({
|
|
332
|
+
...event,
|
|
333
|
+
timestamp: typeof event.timestamp === 'number' ? event.timestamp : Date.now(),
|
|
334
|
+
sessionId: typeof event.sessionId === 'string' ? event.sessionId : sessionId,
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
}, [onAnalyticsEvent, sessionId]);
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**3. Pass `trackEvent` to your flow creators:**
|
|
341
|
+
|
|
342
|
+
```tsx
|
|
343
|
+
const customFlow = useMemo(() => {
|
|
344
|
+
const menuFlow = createMenuFlow({ trackEvent });
|
|
345
|
+
const ticketFlow = createTicketFlow({ trackEvent });
|
|
346
|
+
// ...
|
|
347
|
+
}, [trackEvent]);
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
**4. Wire up core analytics:**
|
|
351
|
+
|
|
352
|
+
```tsx
|
|
353
|
+
<QABot
|
|
354
|
+
onAnalyticsEvent={handleCoreAnalyticsEvent}
|
|
355
|
+
customFlow={customFlow}
|
|
356
|
+
// ...
|
|
357
|
+
/>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
**5. Fire events in your flows:**
|
|
361
|
+
|
|
362
|
+
```typescript
|
|
363
|
+
export function createTicketFlow({ trackEvent }: FlowParams) {
|
|
364
|
+
return {
|
|
365
|
+
ticket_submit: {
|
|
366
|
+
function: async (chatState) => {
|
|
367
|
+
const result = await submitTicket(data);
|
|
368
|
+
trackEvent({
|
|
369
|
+
type: 'ticket_submitted',
|
|
370
|
+
ticketType: 'general',
|
|
371
|
+
success: result.success,
|
|
372
|
+
});
|
|
373
|
+
},
|
|
374
|
+
// ...
|
|
375
|
+
},
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
Consumers can then wire events to their analytics platform:
|
|
381
|
+
|
|
382
|
+
```tsx
|
|
383
|
+
<YourWrapper
|
|
384
|
+
onAnalyticsEvent={(event) => {
|
|
385
|
+
window.dataLayer?.push({ event: event.type, ...event });
|
|
386
|
+
}}
|
|
387
|
+
/>
|
|
388
|
+
```
|
|
389
|
+
|
|
294
390
|
---
|
|
295
391
|
|
|
296
392
|
## Environment Variables
|