# Device Groups

import DocButton from '~/components/webkit/DocButton.vue';

**Device Groups** is an **Applications** capability that allows you to identify the devices that will send requests to your application and categorize them into groups. You can use Device Groups to set custom application behaviors and cache policies based on the groups you create. Once you've created a device group, you can configure a rule or a cache policy specifically for the devices within the group.

Users that access applications created in [Azion Console](https://console.azion.com) send Azion data via HTTP request headers. The `User-Agent` header stores information on the user's browser, operating system, version, and manufacturer. This header follows the syntax:

```yaml
User-Agent: <product>/<product-version> <comment>
```

Where:

- `product`: product identifier.
- `product-version`: version number of the product.
- `comment`: system information, platform name and details, and extensions.

For instance, the following `User-Agent` header indicates that a Windows machine has accessed the application using Mozilla Firefox:

```yaml
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0
```

Device Groups works by matching the contents of the `User-Agent` header to the regular expression you set for the device group.

For example, you can create a device group called *Mobile* whose regular expression must match the contents within the `User-Agent` header that identifies mobile devices. The following expression can be used to identify most of the existing mobile devices:

```
(Mobile|iP(hone|od)|BlackBerry|IEMobile)
```

## Implementation

| Scope | Resource |
| --- | --- |
| Applications first steps | [First steps](/en/documentation/products/build/applications/first-steps/) |
| About Rules Engine | [Rules Engine](/en/documentation/products/build/applications/rules-engine/) |
| About Adaptive Delivery | [Adaptive Delivery](/en/documentation/products/build/applications/cache-settings/#adaptive-delivery) |

---

## Rules Engine

When you create a rule, you can use the variable `${device_group}` to define which behaviors your application should perform for the device groups you've created. To reference a device group, you can add its name to the argument section after you select the desired comparison operator.

> To use this variable, you must enable [Application Accelerator](/en/documentation/products/build/applications/application-accelerator/).

The following criteria identifies whether the user request comes from a device that matches a device group named *Mobile*:

|  | Variable | Comparison Operator | Argument |
| --- | --- | --- | --- |
| If | `${device_group}` | is equal to | Mobile |

Rules Engine can also identify devices using the `${http_user_agent}` variable directly by adding a string or regular expression as an argument. That way, you can identify specific devices without having to dedicate a device group to them.

The following criteria identifies whether the user request comes from an iPhone device:

|  | Variable | Comparison Operator | Argument |
| --- | --- | --- | --- |
| If | `${http_user_agent}` | matches | `(?i)iPhone` |

---

## Adaptive Delivery

You can reference an existing device group for **Adaptive Delivery**. You can choose one or more device groups to apply the same Adaptive Delivery policies.

<DocButton href="/en/documentation/products/build/applications/cache-settings/#adaptive-delivery" label="Learn more about Adaptive Delivery" size="medium" />

---

## Prioritization

**Device Groups** will prioritize matches first-to-last, regardless of the order within the `User-Agent` header from the request. Given the following list of device groups:

| Device group | Regular expression |
| --- | --- |
| Mobile | `(Mobile\|Android)` |
| Tablet | `(iPad\|Android)` |
| Desktop | `(Chrome\|Mozilla)` |

If the request is made by a device that contains `Android Tablet Mobile (Mozilla Firefox)` in its header, the words `Android` and `Mobile` will match the *Mobile* group.

However, for a request from `iPad Apple Webkit Mobile`, the device will be identified as *Mobile* owing to the presence of `Mobile` within the request, despite `iPad` matching the *Tablet* device group.

When setting up your rules, keep in mind that `User-Agent` headers for different devices can sometimes contain the same words. For instance: `Google Chrome Android` likely came from a mobile device while `Google Chrome Symbian` likely belongs to a desktop; both used the same Google Chrome application to access the application. Make sure to use precise wording when grouping devices.