# Session metrics

Whilst in an active Cobrowse session there may be external factors that affect the quality of the session. Most notably varying network connectivity. Session metrics can be used to notify the user of the poor connection allowing for them to make adjustments to improve the connection.

The available metrics are:

<table><thead><tr><th width="146.51953125">Metric</th><th>Description</th></tr></thead><tbody><tr><td>Latency</td><td>Round-trip time taken to respond to a ping from the device to the server.</td></tr><tr><td>Last alive</td><td>The timestamp when the device last successfully pinged the server.</td></tr></tbody></table>

With these it is possible to understand when the device last successfully responded and how long that message took to be acknowledged.

A latency of **200ms** or below is a good connection.

{% tabs %}
{% tab title="Web" %}

```javascript
CobrowseIO.on('session.metrics.updated', session => {
    console.log('Latency:', session.metrics.latency)
    console.log('Last alive:', session.metrics.last_alive)
});
```

{% endtab %}

{% tab title="iOS" %}

```swift
class CobrowseSession: NSObject, CobrowseIODelegate {
    func cobrowseSessionMetricsDidUpdate(_ session: CBIOSession) {
        let metrics = session.metrics()
        
        print("Latency:", metrics.latency())
        print("Last alive:", metrics.lastAlive())
    }
}
```

{% endtab %}

{% tab title="Android" %}

```kotlin
class CobrowseSession : CobrowseIO.SessionMetricsDelegate {
    override fun sessionMetricsDidUpdate(session: Session) {
        val metrics: Session.Metrics = session.metrics()
        
        println("Latency: ${metrics.latency()}")
        println("Last alive: ${metrics.lastAlive()}")
    }
}
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.cobrowse.io/sdk-features/advanced-features/session-metrics.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
