---
title: "Kenect Widget Event Configuration"
canonical: "https://resourcecenter.kenect.com/space/Messaging/236814393/Kenect%20Widget%20Event%20Configuration"
format: markdown
---
The Kenect Widget exposes events within the widget to the parent page with the postMessage browser API. You can listen to these events and push data to whatever metric and data collection software you would like.


Here is a full list of all events you can listen to. There are others, but it is not recommended to use those: Full descriptions with example events can be found below.

- EVENT_SEND_MESSAGE
- EVENT_WIDGET_OPENED
- EVENT_WIDGET_CLOSED
- EVENT_LOCATION_SELECTED
- EVENT_DEPARTMENT_SELECTED
- EVENT_PROMPT_CLOSED
- EVENT_WIDGET_ERROR

Using the the code below, we can listen for those events

| 1 <script>  
2 window.addEventListener('message', function (event) {  
3 var eventType = event && event.data && event.data.type  
4 switch(eventType) {  
5 case 'EVENT_SEND_MESSAGE':  
6 ...  
7 break  
8 case 'EVENT_WIDGET_OPENED':  
9 ...  
10 break  
11 case 'EVENT_WIDGET_CLOSED':  
12 ...  
13 break<br>14 case 'EVENT_LOCATION_SELECTED':  
15 ...  
16 break<br>17 case 'EVENT_DEPARTMENT_SELECTED':  
18 ...  
19 break<br>20 case 'EVENT_PROMPT_CLOSED':  
21 ...  
22 break  
23 default:  
24 break  
25 }  
26 })  
27 </script> |
| --- |

An example implementation of how you might implement it with Google Analytics would be as follows:

> ℹ️ Be advised, viewing tracked events could take up to, but is not limited to, 24hrs  
> ℹ️ before being displayed on the GA dashboard. Use the real-time tab for up to the  
> ℹ️ minute tracking on dev / prod environments.

> ❌ This snippet is meant as a visual guide, not a copy and paste solution.

| 1 <head>  
2 //...  
3 <script>  
4 // Once you've added the global snippet to a web page,  
5 // use the event command to send data to Google Analytics..  
6 window.addEventListener('message', function (event) {  
7 var eventType = event && event.data && event.data.type  
8 switch(eventType) {  
9 case 'EVENT_SEND_MESSAGE':  
10 // place your trackers here, for example:  
11 gtag('event', 'EVENT_SEND_MESSAGE', {  
12 'event_category': 'KenectWidget',  
13 'event_label': 'send_message'  
14 });  
15 break  
16 case 'EVENT_WIDGET_OPENED':  
17 // place your trackers here, for example:  
18 gtag('event', 'EVENT_WIDGET_OPENED', {  
19 'event_category': 'KenectWidget',  
20 'event_label': 'widget_opened'  
21 });  
22 break  
23 default:  
24 break  
25 }  
26 })  
27 </script>  
28 //...  
29 </head> |
| --- |

> ℹ️ Our Kenect Technical Support team is here to answer your general questions about the Kenect Widget and how it’s configured. However, our teams are **unable to set it up on behalf of your business**.
> ℹ️ 
> ℹ️ Please reach out to a website designer or developer if you need assistance adding the widget coding into your website.

#### **Events**

Below is a list of descriptions for each event and the data you can expect to receive when listening to these messages.

#### **EVENT_SEND_MESSAGE**

Summary: When the user sends a message and a response from the server is received.

- Clarifications:
  - The data will always include the 'message' and 'contact' fields.
  - If the widget is configured with no location/department routing, the data will not have the 'location' field. The department will have the default location ID as the ID.
  - If the widget is configured with one department, the data will not have the 'location'  
field. The department will have the only configured department's information.
  - If the widget is configured with multiple departments with location routing turned off,  
the data will not have the 'location' field.
  - If the widget is configured with multiple locations and there are more departments  
than locations, all fields specified below will be in the payload.
  - If the widget is configured with the same number of locations and departments and  
location routing is turned on, the data will not have the 'department' field.
  - If the page is closed before receiving a response from the server, this event will not be  
triggered.

| 1 {  
2 "type": "EVENT_SEND_MESSAGE",  
3 "data": {  
4 "message": "Hello World",  
5 "messageId": 1234  
6 "contact": {  
7 "name": "John Snow",  
8 "phoneNumber": "(555) 555-1234"  
9 },  
10 "location": {  
11 "id": 1,  
12 "name": "Location 1"  
13 },  
14 "department": {  
15 "id": 1,  
16 "name": "Department 1"  
17 }  
18 }  
19 } |
| --- |

#### **EVENT_LOCATION_SELECTED**

Summary: This event is fired whenever a location is selected

| 1 {  
2 "type": "EVENT_LOCATION_SELECTED",  
3 "data": {  
4 "location": {  
5 "id": 1,  
6 "name": "Kenect-Dev"  
7 }  
8 }  
9 } |
| --- |

#### **EVENT_DEPARTMENT_SELECTED**

Summary: This event is fired whenever a department is selected

- Clarifications:
  - If the widget is configured with multiple locations and there are more departments  
than locations, and the user selects a location with only one department, you will see  
this event fire immediately with the one department's information.

| 1 {  
2 "type": "EVENT_DEPARTMENT_SELECTED",  
3 "data": {  
4 "department": {  
5 "id": 1,  
6 "name": "Department 1"  
7 }  
8 }  
9 } |
| --- |

#### **EVENT_WIDGET_OPENED**

Summary: This event is triggered when the main “Text Us” button is clicked.

| 1 {  
2 "type": "EVENT_WIDGET_OPENED"  
3 } |
| --- |

#### **EVENT_WIDGET_CLOSED**

Summary: Whenever the user closes the widget. Both closing from the main button on larger screens, or closing from the icon in the header on smaller screens, will trigger this event.

| 1 {  
2 "type": "EVENT_WIDGET_CLOSED"  
3 } |
| --- |

#### **EVENT_PROMPT_CLOSED**

Summary: The prompt is the message that appears above the main “Text Us” button in the corner of your webpage. This event fires whenever anyone clicks the close icon dismissing the prompt for 30 minutes.

| 1 {  
2 "type": "EVENT_PROMPT_CLOSED"  
3 } |
| --- |

#### **EVENT_WIDGET_ERROR**

Summary: This event fires whenever an error occurs within the marketing widget.

| 1 {  
2 "type": "EVENT_WIDGET_ERROR",  
3 "data": "error message"  
4 } |
| --- |

# **Frequently Asked Questions (FAQs)**

- **Does this document help with Google Tag Analytics?**
  - Yes, the above events have worked when configured with Google Tags in tracking particular Text Widget Events.