---
# System prepended metadata

title: Live Visitor Tracking protocols

---

# Live Visitor Tracking protocols

## Schema
![](https://i.imgur.com/msEhEVE.png)
## Events description
| value | name |
| ----- | ---- |
| 0     | Visitor is online   |
| 1     | Visitor is offline  |
| 2     | Session was created |
| 3     | Visitor activity    |
| 4     | Session was closed  |
| 5     | Visitor disconnect  |

### Flow
| action | eventId |
| ------ | ------- |
| Visitor open web-site | 0, 3(page loaded)
| Visitor change browser tab | 3(tab not in focus)
| Visitor return on page | 3(tab in focus)
| Visitor close tab/browser | 5
| After 30 sec when visitor disconnect and not found new connecrtion for him | 1
## Examples
### Visitor is online
```
{
    eventId:0,
    clientId:"6cca795d-fd1b-4d22-97b7-ca827ddffcfc1572943354863/localhost:3500",
    workspaceId:40,
    platformConnectorId:"5d6fa7b26aac21000865d2e5",
    activity:null
}
```
### Visitor is offline
```
{
    event:1,
    clientId:"6cca795d-fd1b-4d22-97b7-ca827ddffcfc1572943354863/localhost:3500",
    workspaceId:40,
    platformConnectorId:"5d6fa7b26aac21000865d2e5",
    activity:null
}
```
### Session was created
```
{
    event:2,
    customerEntityId:329618,
    workspaceId:40,
    clientId:"6cca795d-fd1b-4d22-97b7-ca827ddffcfc1572943354863/localhost:3500",
    platformConnectorId:"5d6fa7b26aac21000865d2e5"
}
```
### Visitor activity
```
{
    event:3,
    clientId:"6cca795d-fd1b-4d22-97b7-ca827ddffcfc1572943354863/localhost:3500",
    workspaceId:40,
    platformConnectorId:"5d6fa7b26aac21000865d2e5",
    visitsCount:56,
    type:"Widget was opened",
    pageTitle:"Document",
    screenResolution:{"height":1040,"width":1920},
    url:"http://localhost:3500/",
    host:"localhost:8080",
    createdAt:"2019-12-09T12:09:40.843Z",
    duration:1565546,
    browserVersion:"5.0 (Windows NT 10.0  Win64  x64) AppleWebKit 537.36 (KHTML  like Gecko) Chrome 78.0.3904.108 Safari 537.36",
    osName:"Win32",
    pagesCount:2
}
```
### Session was closed
```
{
    event:4,
    customerEntityId:329618,
    workspaceId:40,
    clientId:"6cca795d-fd1b-4d22-97b7-ca827ddffcfc1572943354863/localhost:3500",
    platformConnectorId:"5d6fa7b26aac21000865d2e5"
}
```
## Structure

```
{
    event,
    customerEntityId,
    clientId,
    platformConnectorId,
    workspaceId,
    activity: {
        visitsCount,
        domain,
        pageTitle,
        location,
        ip,
        referralInformation,
        browserVersion,
        screenResolution,
        osName,
        pagesCount,
    }
}
```

## Subscription name for Stomp

```workspace:workspaceId_role:roleId_entity:entityId```

### Role description
| value | description |
| ----- | ----------- |
| 0     | Subscription with this role recieved all notifications

## Send invite to user

- [Create external session](/CXvj_AwCRDuq-E5jbhn0hA)

## Webhook for getting list of users on web-site

service: worker-service
method: GET
url: /bots/:botId/rake-live-chat/users/online
headers: standard hash

response: 
```
[
  { 
    "_id":"5dcbcef231e6d10007644e74",
    "clientId":"d207fa8f-6792-43d6-a277-11b7622cbda71571729286339/hook.io",
    "visitsCount":4,
    "customerEntityId":6581,
    "platformConnectorId":"5dc528ba31884e00076794c7",
    "domain":"hook.io",
    "pageTitle":"",
    "location":{ "latitude":48.464717, "longitude":35.046183 },
    "lastInteraction":"Widget was opened",
    "entity":{ "entityId":6581 },
    "workspaceId":13,
    "pagesCount":1,
    "sessionStatus":3,
    "duration":"Invalid date",
    "id":"5dc528ba31884e00076794c7:d207fa8f-6792-43d6-a277-11b7622cbda71571729286339/hook.io"
  },{
    "_id":"5dcbd20ded392900087d2158",
    "clientId":"9fc13f7c-5efe-4e94-835b-3e9b31f7969a1566490937755/hook.io",
    "visitsCount":2,
    "platformConnectorId":"5dc528ba31884e00076794c7",
    "domain":"hook.io",
    "pageTitle":"",
    "location":{ "latitude":48.464717, "longitude":35.046183 },
    "lastInteraction":"Tab was changed",
    "entity":{},
    "workspaceId":13,
    "pagesCount":1,
    "sessionStatus":3,
    "duration":"Invalid date",
    "id":"5dc528ba31884e00076794c7:9fc13f7c-5efe-4e94-835b-3e9b31f7969a1566490937755/hook.io"
  }
]
```
> sessionStatus: { 1: 'active', 2: 'sent', 3: 'available' }
> 
## Webhook for getting user on web-site
service: worker-service
method: GET
url: /bots/:botId/rake-live-chat/users/online
headers: standard hash

response: 
```
{
  "_id":"5dcd0b00228f13000703d095",
  "clientId":"be31ecff-68f7-432f-b64e-671a32a12a311549962999362/hook.io",
  "osName":"Win32",
  "browserVersion":"5.0 (Windows NT 10.0  Win64  x64) AppleWebKit 537.36 (KHTML  like Gecko) Chrome 78.0.3904.108 Safari 537.36",
  "language":"ru-RU",
  "currentBrowserSessionId":"efb57caf-a1e1-47d0-a6e2-cb51db4367301576230677585",
  "visitsCount":23,
  "customerEntityId":6589,
  "platformConnectorId":"5dcd0b00228f13000703d094",
  "firstVisitDate":"2019-12-13T09:51:18.915Z",
  "screenResolution":{"height":1080,"width":1920},
  "host":"rakesystem-test.rake.ai",
  "location":{"latitude":48.464717,"longitude":35.046183},
  "activities":["Tab was changed"],
  "workspaceId":13,
  "eventId":3,
  "duration":2511959491,
  "pagesCount":1
}
```