How to create device groups
Group end-users based on their devices, operating systems, or browsers with information provided by the User-Agent
HTTP request header. By using Device Groups to categorize requests, you can make your application more responsive.
With this guide, you’ll create and activate a new device group to identify mobile devices that access your application.
- Access Real-Time Manager (RTM).
- On the upper-left corner of the page, open the Products menu, represented by three horizontal lines, and then select Edge Application.
- Click the edge application to which you want to create a new device group.
- Select the Device Groups tab.
- Click the Add Device Group button.
- Name your device group. The name of your device group can’t contain spaces and must have only alphanumeric characters. For example:
Mobile
. - In the User Agent field, specify a regular expression that will meet the desired criteria. For example:
(Mobile|iPhone|Android)
. - Click the Save button.
Now that your device group is set, you can use Rules Engine to determine what action must be taken if the expression is matched to a User-Agent
header. In this case, a custom Device-Is
header will be received in the response:
- Navigate to the Rules Engine tab.
- Click Add Rule > select Response Phase.
- Give your rule a name. For example:
Device Group: Mobile
. - In the Criteria section, select the variable
${device_group}
. - Select the operator is equal.
- Add the name of the device group as configured in the previous instructions. For example:
Mobile
. - In the Behavior section, select the behavior Add Response Header.
- As an argument, add
Device-Is: Mobile device
. - Click the Save button.
- Wait a few minutes for the changes to propagate through the edge.
If your current browser sends a User-Agent
header similar to the example, you can test whether the request went through by accessing your application from a mobile device or artificially adding the header and its value to the request using the following command:
You should receive a list of headers including the custom header added by the rule: device-is: Mobile device
. Now that you’ve verified that the devices are being correctly categorized, you can customize the desired behavior using the same rule.
- Access Azion Console > Edge Application.
- Click the edge application to which you want to create a new device group.
- Select the Device Groups tab.
- Click the + Device Group button.
- Name your device group. The name of your device group can’t contain spaces and must have only alphanumeric characters. For example:
Mobile
. - In the Match to User-Agent field, specify a regular expression that will meet the desired criteria. For example:
(Mobile|iPhone|Android)
. - Click the Save button.
Now that your device group is set, you can use Rules Engine to determine what action must be taken if the expression is matched to a User-Agent
header. In this case, a custom Device-Is
header will be received in the response:
- Navigate to the Rules Engine tab.
- Click + Rule.
- Give your rule a name. For example:
Device Group: Mobile
. - Select Response Phase.
- In the Criteria section, select the variable
${device_group}
. - Select the operator is equal.
- Add the name of the device group as configured in the previous instructions. For example:
Mobile
. - In the Behavior section, select the behavior Add Response Header.
- As an argument, add
Device-Is: Mobile device
. - Click the Save button.
- Wait a few minutes for the changes to propagate through the edge.
If your current browser sends a User-Agent
header similar to the example, you can test whether the request went through by accessing your application from a mobile device or artificially adding the header and its value to the request using the following command:
You should receive a list of headers including the custom header added by the rule: device-is: Mobile device
. Now that you’ve verified that the devices are being correctly categorized, you can customize the desired behavior using the same rule.
- Run the following
POST
request in your terminal, replacing[TOKEN VALUE]
with your personal token and the<edge_application_id>
variable with your edge application ID:
Key | Description |
---|---|
name | The name of the device group. Must be alphanumeric. |
user_agent | The regular expression that should be matched to the contents of the User-Agent header from the request. |
- You’ll receive a response similar to this:
- Run the following
POST
request in your terminal, replacing[TOKEN VALUE]
with your personal token, the<edge_application_id>
variable with your edge application ID, and theinput_value
variable with the name of your device group:
- You’ll receive a response similar to this:
- Wait a few minutes for the changes to propagate to the edge nodes.
- Run the following cURL request manipulating the
User-Agent
header to match the device group:
- If you receive a response similar to the following, your device group has been successfully categorized:
You may now deactivate the rule or create a different rule to fit the application’s settings to your needs.