# Experiments and analytics

Engagement analytics counts how users engage with your `foryou` feed: feed opens, users, impressions, clicks, dwell time and hides, per [feed view](https://getstream.io/activity-feeds/docs/ruby/feed-views/) and per day. Experiments split users across 2 to 4 feed views, so you can compare ranking or selector changes on real traffic before rolling one out.

>
> **Info:** Engagement analytics and experiments require a **paid Feeds plan**. Both are opt-in.
>

## Turning on analytics

Set `for_you.analytics` on the `foryou` feed group. It needs `for_you.enabled`; see [For You ranking](https://getstream.io/activity-feeds/docs/ruby/for-you-ranking/) for the full update call.

```json
{
  "ranking": {
    "type": "expression",
    "for_you": { "enabled": true, "preset": "for_you_v2", "analytics": true }
  }
}
```

Turning it off stops counting. The numbers already collected stay available.

## Running an experiment

Create one feed view per variant, then reference them from `for_you.experiment`. Each user is assigned one variant by weight and keeps it for the whole experiment.

```json
{
  "ranking": {
    "type": "expression",
    "for_you": {
      "enabled": true,
      "preset": "for_you_v2",
      "analytics": true,
      "experiment": {
        "id": "ranking-test-1",
        "variants": [
          { "view": "foryou_control", "weight": 50 },
          { "view": "foryou_affinity", "weight": 50 }
        ]
      }
    }
  }
}
```

| Field               | Description                                                             |
| ------------------- | ----------------------------------------------------------------------- |
| `id`                | 1 to 64 letters, digits, dashes or underscores                          |
| `variants`          | 2 to 4 variants, each a different existing feed view                    |
| `variants[].view`   | The ID of the feed view users in this variant read                      |
| `variants[].weight` | The share of users in percent, 1 to 100. The weights must add up to 100 |

- An experiment needs `analytics`. Both are set on the feed group, never on a view.
- A variant view can't be deleted while an experiment uses it.
- A variant can use any ranking or selectors, including a different `for_you` preset or `score`. Give every variant the same location requirement: a variant with a `proximity` selector fails for its users when the read sends no location.
- A read that names a `view` explicitly gets that view. It is not counted in the experiment.
- Changing the experiment `id` or the weights reassigns users. A user whose variant changes while paging through the feed gets a 400 on the next page and has to read the first page again.
- Reads without a user (anonymous reads) are not assigned and use the group's own configuration.

## What is counted

| Metric        | Counted when                                                                                                                           |
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------- |
| `reads`       | A user opens the feed: a read without `next`, `prev` or `id_around`. Later pages don't count.                                          |
| `users`       | Unique users per day, approximate (about 1%). No user IDs are stored.                                                                  |
| `impressions` | An `impressions` event with the feed's `request_id`.                                                                                   |
| `clicks`      | A `clicks` event with the feed's `request_id`.                                                                                         |
| `dwell_ms`    | The `dwell_ms` of `dwell` events with the feed's `request_id`, at most 10 minutes per event.                                           |
| `dwell_count` | The number of those `dwell` events.                                                                                                    |
| `hides`       | A user hides an activity through [activity feedback](https://getstream.io/activity-feeds/docs/ruby/activity-feedback/) with the feed's `request_id`. |

With analytics on, every feed read by an authenticated user returns a `request_id`. Send it with the events of activities from that read, as shown in [Activity metrics](https://getstream.io/activity-feeds/docs/ruby/activity-metrics/#tracking-feed-impressions) and [Activity feedback](https://getstream.io/activity-feeds/docs/ruby/activity-feedback/). Events without a `request_id` are not counted in analytics.

- Days are UTC. An event counts on the day it arrives, so a click shortly after midnight on a feed opened before it counts toward the new day.
- Counts are updated every 10 minutes.
- Daily numbers are kept for 13 months.
- Only totals per day are stored: no activity IDs, user IDs or raw events.

## Querying the numbers

```ruby label="Ruby"
response = client.feeds.query_feeds_engagement_stats(
  GetStream::Generated::Models::QueryFeedsEngagementStatsRequest.new(
    group_id: 'foryou',
    experiment_id: 'ranking-test-1',
    from: '2026-11-01',
    to: '2026-11-30'
  )
)

response.results.each do |result|
  puts "#{result.view_id} #{result.metrics['reads'].total} #{result.rates.ctr}"
end
```

| Field           | Description                                                                                       | Default                                        |
| --------------- | ------------------------------------------------------------------------------------------------- | ---------------------------------------------- |
| `group_id`      | The feed group to report on                                                                       | required                                       |
| `from`, `to`    | Dates as `YYYY-MM-DD`, UTC. At most 396 days apart                                                | the last 30 days                               |
| `view_id`       | Only this feed view                                                                               | all views                                      |
| `experiment_id` | Only this experiment                                                                              | all                                            |
| `limit`         | The number of series to return, 1 to 100. `limit` times the number of days must not exceed 10,000 | 100, or 10,000 / days for ranges over 100 days |

The response has one result per series: a combination of feed group, view and experiment (`experiment_id` is empty outside an experiment). Each result has:

- `metrics`: every metric from the table above, each with `daily` values (`{ date, value }`, days without events left out) and a `total` for the range.
- `rates`: `ctr` (clicks / impressions), `avg_dwell_ms` (dwell_ms / dwell_count), `hide_rate` (hides / impressions), `impressions_per_user` and `clicks_per_user`. A rate is null when its denominator is 0.

`users.total` adds up the daily unique users, so it counts user-days, not unique users over the range. The per-user rates are per user-day.

The endpoint is server-side only and not paginated.

## Comparing variants

Compare variants on the rates, not on totals: weights decide how many users each variant gets. Run an experiment for at least a week, so every weekday is in both variants, and change one thing per experiment. When a variant wins, copy its configuration to the feed group and remove the experiment.

---

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/ruby/for-you-experiments/](https://getstream.io/activity-feeds/docs/ruby/for-you-experiments/).