# Track tenant metrics

Your platform can often seem like a black box when it comes to what tenants are doing with your application. It can be very useful to see when someone has last logged in, how many users there are in the tenant and how much of the functionality has been activated.

Bunny can track some of these metics, so you have more insight into tenant activity via Bunny's user interface.

* Last login
* User count
* Utilization metics

Utilization metrics is a hash of values that you deem important signals to a customer's engagement with your app. For example, if your app is a learning-management solution, you could track number of courses defined, courses attended and students.

### Prerequisites

Before you can start tracking metrics from your application, you need to complete the following steps on the Bunny side first.

1. [Create an API client & install a Bunny SDK](https://docs.bunny.com/developer/using-the-graphql-api/api)
2. Create an tenant in Bunny to represent a tenant in your SaaS application. If you've already [enabled tenant provisioning](https://docs.bunny.com/developer/webhooks/webhooks) then you wont need to do this step as Bunny will assign a tenant to each new subscription for you.

### Report tenant metrics

Metrics are tracked via the [tenantMetricsUpdate](https://docs.bunny.com/developer/using-the-graphql-api/mutations/tenantmetricsupdate) mutation.

{% tabs %}
{% tab title="GraphQL" %}
**TenantMetricsAttributes**

```json
{
  "code": "10012032",
  "attributes": {
    "lastLogin": "2023-10-20",
    "userCount": 10,
    "utilizationMetrics": { 
      "coursesCreated": 10, 
      "coursesAttended": 50 
    }
  }
}
```

**Mutation**

<pre class="language-graphql" data-overflow="wrap"><code class="lang-graphql"><strong>mutation tenantMetricsUpdate ($code: String!, $attributes:   TenantMetricsAttributes!){
</strong>  tenantMetricsUpdate (code: $code, attributes: $attributes) {
    errors
  }
}
</code></pre>

{% endtab %}

{% tab title="Ruby" %}

```ruby
res = BunnyApp::TenantMetrics.update(
  code: '54681cba-8509-4c81-b170-b1debd73dbfd',
  last_login: '2023-12-17',
  user_count: 900,
  utilization_metrics: {
    coursesCreated: 25,
  }
)
```

{% endtab %}

{% tab title="Node.js" %}
{% code overflow="wrap" %}

```javascript
let tenantCode = '10012032'
let lastLogin = '2023-10-20'
let userCount = 413
let metrics = { 
    "coursesCreated": 10, 
    "coursesAttended": 50 
}

res = await bunny.tenantMetricsUpdate(tenantCode, lastLogin, userCount, metrics)
```

{% endcode %}
{% endtab %}
{% endtabs %}

### View metrics

You can see all the metrics on the tenant form.

<figure><img src="https://386337055-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuulYgSMMvPL7hiTgkFyZ%2Fuploads%2Fgit-blob-fa745e6725da1cd801731bc1450942a733966ddb%2Ftenant.jpg?alt=media" alt=""><figcaption><p>Tenant</p></figcaption></figure>
