---
# System prepended metadata

title: Widget

---

# Widget

## With this new user?
We will check the messages collection. If it includes a message sent from this entity than we decide it is not a new user.


## Counting opened tabs with widget

> widgetUUID(WUUID) - widget uuid value per tab

![](https://i.imgur.com/EDcLPGj.png)

This value refreshed each second. If we need know how many tabs with current widget is opened, we check how many keys: WUUID/hash with actual time we have.

![](https://i.imgur.com/Xjq91hv.png)


## Saving current widget state

> currentWidgetState-{domain} - value that indicates current widget state. Saves to localStorage and sessionStorage

### Rule 1. When we have only one tab with widget: 
    we get current widget state from sessionStorage
### Rule 2. When we have more than one tab with widget:
    we get current widget state from localStorage

### Case when we have for example currentWidgetState 'opened' in localStorage and close all tabs with widget. 
When we open tab with widget it should be closed and it is closed because value in sessionStorage was null. But when we duplicate tab it is going to open widget because it took value from localStorage as said above. In order to avoid such situation we decided to clear value from localStorage when we closed all tabs with widget and when we open first tab with widget , if there was no value in sessionStorage, we save state 'closed' to sessionStorage and localStorage. 