@developer.notchatbot/webchat 1.2.9 → 1.2.10

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
@@ -337,6 +337,64 @@ window.mountEmbedChat('embed-small'); // Remounts the chat in the same element
337
337
 
338
338
  ---
339
339
 
340
+ ### Listen to lifecycle & message events (🆕)
341
+
342
+ We emit **custom browser events** so you can capture interactions and feed them into Google Tag Manager, Google Analytics, Meta Pixel, or any other analytics tool.
343
+
344
+ | Widget | Event name | Fired when | `detail` payload |
345
+ |--------|------------|------------|------------------|
346
+ | WebChat | `WebChatOpened` | The floating chat is opened | `{ conversationId }` |
347
+ | WebChat | `WebChatClosed` | The floating chat is closed | `{ conversationId }` |
348
+ | WebChat | `WebChatMessageSent` | The user sends one or more messages | `{ messages: Message[] }` |
349
+ | WebChat | `WebChatMessageReceived` | A message is received from the server | `{ message: Message, role: 'assistant' \| 'employee' }` |
350
+ | EmbedChat | `EmbedChatMessageSent` | The user sends a message | `{ message: Message }` |
351
+ | EmbedChat | `EmbedChatMessageReceived` | A message is received | `{ message: Message, role: 'assistant' \| 'employee' }` |
352
+
353
+ `Message` follows the same interface used internally by the widget (id, text, sender, timestamp, etc.).
354
+
355
+ #### Quick example
356
+ ```js
357
+ window.addEventListener('WebChatOpened', e => console.log('WebChat opened', e.detail));
358
+ window.addEventListener('WebChatClosed', e => console.log('WebChat closed', e.detail));
359
+ window.addEventListener('WebChatMessageSent', e => console.log('Sent', e.detail.messages));
360
+ window.addEventListener('WebChatMessageReceived', e => {
361
+ const { role, message } = e.detail;
362
+ console.log('Received', role, message);
363
+ });
364
+ ```
365
+
366
+ #### Google Tag Manager / Google Analytics (GA4)
367
+ Push data directly to the **dataLayer** and create a trigger in GTM:
368
+ ```js
369
+ window.addEventListener('WebChatMessageSent', e => {
370
+ window.dataLayer = window.dataLayer || [];
371
+ window.dataLayer.push({
372
+ event: 'webchat_message_sent',
373
+ messages: e.detail.messages,
374
+ conversationId: e.detail.messages[0]?.conversationId || null
375
+ });
376
+ });
377
+ ```
378
+ Then in GTM, add a **Custom Event** trigger called `webchat_message_sent` and link it to a GA4 event tag.
379
+
380
+ #### Meta / Facebook Pixel
381
+ ```js
382
+ window.addEventListener('WebChatOpened', () => {
383
+ if (window.fbq) {
384
+ fbq('trackCustom', 'WebChatOpened');
385
+ }
386
+ });
387
+
388
+ window.addEventListener('WebChatMessageReceived', e => {
389
+ if (window.fbq) {
390
+ fbq('trackCustom', 'WebChatMessageReceived', {
391
+ role: e.detail.role
392
+ });
393
+ }
394
+ });
395
+ ```
396
+ These events make it easy to measure engagement and conversions driven by the chat widget without modifying its source code.
397
+
340
398
  ### Change position and padding dynamically (WebChat)
341
399
 
342
400
  #### 1. Change position and margin globally (flat)